opensips-js 0.1.31 → 0.1.33
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/index.d.ts +28 -1
- package/dist/opensips-js.cjs.js +100 -100
- package/dist/opensips-js.es.js +7175 -6901
- package/dist/opensips-js.iife.js +105 -105
- package/dist/opensips-js.umd.js +105 -105
- package/package.json +1 -1
package/dist/opensips-js.cjs.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";var $h=Object.defineProperty;var Hh=(c,t,n)=>t in c?$h(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var Kt=(c,t,n)=>(Hh(c,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Fh=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 Vh="jssip",jh="JsSIP",qh="the Javascript SIP library",Bh="3.10.0",Gh="https://jssip.net",Wh=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],Kh="lib/JsSIP.d.ts",Yh="lib-es5/JsSIP.js",Jh=["sip","websocket","webrtc","node","browser","library"],zh="MIT",Xh={type:"git",url:"https://github.com/versatica/JsSIP.git"},Qh={url:"https://github.com/versatica/JsSIP/issues"},Zh={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},ed={"@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"},td={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Ha={name:Vh,title:jh,description:qh,version:Bh,homepage:Gh,contributors:Wh,types:Kh,main:Yh,keywords:Jh,license:zh,repository:Xh,bugs:Qh,dependencies:Zh,devDependencies:ed,scripts:td};var Gu=Ha,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 pa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?pa=function(n){return typeof n}:pa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},pa(c)}function Fa(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Va(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&&Qi(c,t)}function ja(c){var t=Vf();return function(){var a=Zi(c),o;if(t){var s=Zi(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return sd(this,o)}}function sd(c,t){return t&&(pa(t)==="object"||typeof t=="function")?t:nd(c)}function nd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function pr(c){var t=typeof Map=="function"?new Map:void 0;return pr=function(a){if(a===null||!rd(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 ma(a,arguments,Zi(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),Qi(o,a)},pr(c)}function ma(c,t,n){return Vf()?ma=Reflect.construct:ma=function(o,s,r){var _=[null];_.push.apply(_,s);var h=Function.bind.apply(o,_),d=new h;return r&&Qi(d,r.prototype),d},ma.apply(null,arguments)}function Vf(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function rd(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function Qi(c,t){return Qi=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Qi(c,t)}function Zi(c){return Zi=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Zi(c)}var id=function(c){Va(n,c);var t=ja(n);function n(a,o){var s;return Fa(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}(pr(Error)),ld=function(c){Va(n,c);var t=ja(n);function n(a){var o;return Fa(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}(pr(Error)),ad=function(c){Va(n,c);var t=ja(n);function n(a){var o;return Fa(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(pr(Error)),od=function(c){Va(n,c);var t=ja(n);function n(a){var o;return Fa(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(pr(Error)),Ws={ConfigurationError:id,InvalidStateError:ld,NotSupportedError:ad,NotReadyError:od},Ze={},co,Wu;function Ou(){if(Wu)return co;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 _=0;_<r.length;_++){var h=r[_];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,_){return r&&t(s.prototype,r),_&&t(s,_),s}var a=Ks(),o=os();return co=function(){n(s,null,[{key:"parse",value:function(_){if(_=o.parse(_,"Name_Addr_Header"),_!==-1)return _}}]);function s(r,_,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=_;for(var d in h)Object.prototype.hasOwnProperty.call(h,d)&&this.setParam(d,h[d])}return n(s,[{key:"setParam",value:function(_,h){_&&(this._parameters[_.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(_){if(_)return this._parameters[_.toLowerCase()]}},{key:"hasParam",value:function(_){if(_)return this._parameters.hasOwnProperty(_.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(_){if(_=_.toLowerCase(),this._parameters.hasOwnProperty(_)){var h=this._parameters[_];return delete this._parameters[_],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(_){return _.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var _=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";_+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(_+=";".concat(h),this._parameters[h]!==null&&(_+="=".concat(this._parameters[h])));return _}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(_){this._display_name=_===0?"0":_}}]),s}(),co}var fo,Ku;function os(){return Ku||(Ku=1,fo=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:S,HEXDIG:E,WSP:A,OCTET:C,DQUOTE:R,SP:k,HTAB:M,alphanum:ie,reserved:N,unreserved:V,mark:Ee,escaped:ve,LWS:L,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:q,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:X,LHEX:U,token:x,token_nodot:se,separators:st,word:ee,STAR:W,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:Pe,LAQUOT:Ce,COMMA:ae,SEMI:ye,COLON:nt,LDQUOT:at,RDQUOT:Se,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:bn,user_unreserved:wn,password:Ys,hostport:es,host:us,hostname:Js,domainlabel:On,toplabel:Dn,IPv6reference:zs,IPv6address:me,h16:oe,ls32:ot,IPv4address:Wt,dec_octet:Cs,port:vr,uri_parameters:Nn,uri_parameter:Un,transport_param:Sr,user_param:Er,method_param:yr,ttl_param:Ar,maddr_param:Cr,lr_param:Rr,other_param:Ir,pname:br,pvalue:Rs,paramchar:Is,param_unreserved:wr,headers:Xs,header:Qs,hname:Or,hvalue:bs,hnv_unreserved:Zs,Request_Response:ml,Request_Line:Dr,Request_URI:xn,absoluteURI:Pn,hier_part:Nr,net_path:en,abs_path:tn,opaque_part:ws,uric:Os,uric_no_slash:Ur,path_segments:sn,segment:Ds,param:cs,pchar:Ns,scheme:xr,authority:Pr,srvr:kr,reg_name:Mr,query:kn,SIP_Version:Mn,INVITEm:Lr,ACKm:$r,OPTIONSm:Hr,BYEm:Fr,CANCELm:Vr,REGISTERm:jr,SUBSCRIBEm:qr,NOTIFYm:Br,REFERm:nn,Method:rn,Status_Line:Gr,Status_Code:Wr,extension_code:Kr,Reason_Phrase:gl,Allow_Events:Ya,Call_ID:Ja,Contact:Ln,contact_param:$t,name_addr:Ht,display_name:Us,contact_params:$n,c_p_q:Yr,c_p_expires:ts,delta_seconds:ss,qvalue:Ge,generic_param:We,gen_value:Tl,Content_Disposition:vl,disp_type:Hn,disp_param:Fn,handling_param:Sl,Content_Encoding:za,Content_Length:Xa,Content_Type:El,media_type:Jr,m_type:zr,discrete_type:Xr,composite_type:ln,extension_token:an,x_token:Qr,m_subtype:Vn,m_parameter:jn,m_value:yl,CSeq:Al,CSeq_value:Cl,Expires:Qa,Event:on,event_type:un,From:Zr,from_param:cn,tag_param:ei,Max_Forwards:Za,Min_Expires:eo,Name_Addr_Header:to,Proxy_Authenticate:ti,challenge:qn,other_challenge:xs,auth_param:ns,digest_cln:fn,realm:si,realm_value:ni,domain:hn,URI:dn,nonce:ri,nonce_value:ii,opaque:li,stale:ai,algorithm:oi,qop_options:_n,qop_value:Bn,Proxy_Require:so,Record_Route:Gn,rec_route:Wn,Reason:ui,reason_param:Kn,reason_cause:Rl,Require:no,Route:Yn,route_param:Jn,Subscription_State:Il,substate_value:zn,subexp_params:Xn,event_reason_value:bl,Subject:ro,Supported:io,To:ci,to_param:fi,Via:Qn,via_param:Ps,via_params:Zn,via_ttl:hi,via_maddr:di,via_received:_i,via_branch:pi,response_port:mi,rport:gi,sent_protocol:Ti,protocol_name:vi,transport:Si,sent_by:Ei,via_host:yi,via_port:er,ttl:Ai,WWW_Authenticate:lo,Session_Expires:wl,s_e_expires:tr,s_e_params:sr,s_e_refresher:Ol,extension_header:Dl,header_value:Nl,message_body:ao,uuid_URI:Ul,uuid:Ft,hex4:Vt,hex8:Ci,hex12:xl,Refer_To:oo,Replaces:Pl,call_id:nr,replaces_param:rr,to_tag:Ri,from_tag:Ii,early_flag:kl};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,_=0,h=[];function d(e){r<_||(r>_&&(_=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
|
|
1
|
+
"use strict";var Hd=Object.defineProperty;var Fd=(c,t,n)=>t in c?Hd(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var Kt=(c,t,n)=>(Fd(c,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Vd=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xe(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const jd="jssip",qd="JsSIP",Bd="the Javascript SIP library",Gd="3.10.0",Wd="https://jssip.net",Kd=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],Yd="lib/JsSIP.d.ts",Jd="lib-es5/JsSIP.js",zd=["sip","websocket","webrtc","node","browser","library"],Xd="MIT",Qd={type:"git",url:"https://github.com/versatica/JsSIP.git"},Zd={url:"https://github.com/versatica/JsSIP/issues"},eh={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},th={"@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"},sh={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Vo={name:jd,title:qd,description:Bd,version:Gd,homepage:Wd,contributors:Kd,types:Yd,main:Jd,keywords:zd,license:Xd,repository:Qd,bugs:Zd,dependencies:eh,devDependencies:th,scripts:sh};var Wu=Vo,lt={USER_AGENT:"".concat(Wu.title," ").concat(Wu.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 go(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?go=function(n){return typeof n}:go=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},go(c)}function jo(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function qo(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&&Qi(c,t)}function Bo(c){var t=jf();return function(){var o=Zi(c),a;if(t){var s=Zi(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return nh(this,a)}}function nh(c,t){return t&&(go(t)==="object"||typeof t=="function")?t:rh(c)}function rh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function pr(c){var t=typeof Map=="function"?new Map:void 0;return pr=function(o){if(o===null||!ih(o))return o;if(typeof o!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(o))return t.get(o);t.set(o,a)}function a(){return To(o,arguments,Zi(this).constructor)}return a.prototype=Object.create(o.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),Qi(a,o)},pr(c)}function To(c,t,n){return jf()?To=Reflect.construct:To=function(a,s,r){var _=[null];_.push.apply(_,s);var d=Function.bind.apply(a,_),h=new d;return r&&Qi(h,r.prototype),h},To.apply(null,arguments)}function jf(){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 ih(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function Qi(c,t){return Qi=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},Qi(c,t)}function Zi(c){return Zi=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Zi(c)}var lh=function(c){qo(n,c);var t=Bo(n);function n(o,a){var s;return jo(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=o,s.value=a,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(pr(Error)),oh=function(c){qo(n,c);var t=Bo(n);function n(o){var a;return jo(this,n),a=t.call(this),a.code=2,a.name="INVALID_STATE_ERROR",a.status=o,a.message="Invalid status: ".concat(o),a}return n}(pr(Error)),ah=function(c){qo(n,c);var t=Bo(n);function n(o){var a;return jo(this,n),a=t.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=o,a}return n}(pr(Error)),uh=function(c){qo(n,c);var t=Bo(n);function n(o){var a;return jo(this,n),a=t.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=o,a}return n}(pr(Error)),Ws={ConfigurationError:lh,InvalidStateError:oh,NotSupportedError:ah,NotReadyError:uh},et={},da,Ku;function Du(){if(Ku)return da;Ku=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 _=0;_<r.length;_++){var d=r[_];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(s,d.key,d)}}function n(s,r,_){return r&&t(s.prototype,r),_&&t(s,_),s}var o=Ks(),a=as();return da=function(){n(s,null,[{key:"parse",value:function(_){if(_=a.parse(_,"Name_Addr_Header"),_!==-1)return _}}]);function s(r,_,d){if(c(this,s),!r||!(r instanceof o))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=_;for(var h in d)Object.prototype.hasOwnProperty.call(d,h)&&this.setParam(h,d[h])}return n(s,[{key:"setParam",value:function(_,d){_&&(this._parameters[_.toLowerCase()]=typeof d>"u"||d===null?null:d.toString())}},{key:"getParam",value:function(_){if(_)return this._parameters[_.toLowerCase()]}},{key:"hasParam",value:function(_){if(_)return this._parameters.hasOwnProperty(_.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(_){if(_=_.toLowerCase(),this._parameters.hasOwnProperty(_)){var d=this._parameters[_];return delete this._parameters[_],d}}},{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(_){return _.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var _=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";_+="<".concat(this._uri.toString(),">");for(var d in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,d)&&(_+=";".concat(d),this._parameters[d]!==null&&(_+="=".concat(this._parameters[d])));return _}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(_){this._display_name=_===0?"0":_}}]),s}(),da}var ha,Yu;function as(){return Yu||(Yu=1,ha=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(o,a){var s={CRLF:g,DIGIT:T,ALPHA:S,HEXDIG:E,WSP:A,OCTET:R,DQUOTE:C,SP:$,HTAB:k,alphanum:re,reserved:x,unreserved:F,mark:_e,escaped:pe,LWS:P,SWS:N,HCOLON:q,TEXT_UTF8_TRIM:j,TEXT_UTF8char:K,UTF8_NONASCII:V,UTF8_CONT:z,LHEX:D,token:U,token_nodot:X,separators:He,word:Q,STAR:W,SLASH:B,EQUAL:ie,LPAREN:ve,RPAREN:Ie,RAQUOT:ke,LAQUOT:Ae,COMMA:oe,SEMI:ye,COLON:nt,LDQUOT:ot,RDQUOT:Ee,comment:Ce,ctext:be,quoted_string:Oe,quoted_string_clean:ge,qdtext:ue,quoted_pair:me,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:Ze,uri_scheme_sips:Le,uri_scheme_sip:Lt,userinfo:ht,user:In,user_unreserved:wn,password:Ys,hostport:es,host:us,hostname:Js,domainlabel:On,toplabel:Dn,IPv6reference:zs,IPv6address:Te,h16:ae,ls32:at,IPv4address:Wt,dec_octet:As,port:vr,uri_parameters:Nn,uri_parameter:xn,transport_param:Sr,user_param:Er,method_param:yr,ttl_param:Cr,maddr_param:Ar,lr_param:Rr,other_param:br,pname:Ir,pvalue:Rs,paramchar:bs,param_unreserved:wr,headers:Xs,header:Qs,hname:Or,hvalue:Is,hnv_unreserved:Zs,Request_Response:ml,Request_Line:Dr,Request_URI:Un,absoluteURI:kn,hier_part:Nr,net_path:en,abs_path:tn,opaque_part:ws,uric:Os,uric_no_slash:xr,path_segments:sn,segment:Ds,param:cs,pchar:Ns,scheme:Ur,authority:kr,srvr:Pr,reg_name:Mr,query:Pn,SIP_Version:Mn,INVITEm:Lr,ACKm:$r,OPTIONSm:Hr,BYEm:Fr,CANCELm:Vr,REGISTERm:jr,SUBSCRIBEm:qr,NOTIFYm:Br,REFERm:nn,Method:rn,Status_Line:Gr,Status_Code:Wr,extension_code:Kr,Reason_Phrase:gl,Allow_Events:zo,Call_ID:Xo,Contact:Ln,contact_param:$t,name_addr:Ht,display_name:xs,contact_params:$n,c_p_q:Yr,c_p_expires:ts,delta_seconds:ss,qvalue:We,generic_param:Ke,gen_value:Tl,Content_Disposition:vl,disp_type:Hn,disp_param:Fn,handling_param:Sl,Content_Encoding:Qo,Content_Length:Zo,Content_Type:El,media_type:Jr,m_type:zr,discrete_type:Xr,composite_type:ln,extension_token:on,x_token:Qr,m_subtype:Vn,m_parameter:jn,m_value:yl,CSeq:Cl,CSeq_value:Al,Expires:ea,Event:an,event_type:un,From:Zr,from_param:cn,tag_param:ei,Max_Forwards:ta,Min_Expires:sa,Name_Addr_Header:na,Proxy_Authenticate:ti,challenge:qn,other_challenge:Us,auth_param:ns,digest_cln:fn,realm:si,realm_value:ni,domain:dn,URI:hn,nonce:ri,nonce_value:ii,opaque:li,stale:oi,algorithm:ai,qop_options:_n,qop_value:Bn,Proxy_Require:ra,Record_Route:Gn,rec_route:Wn,Reason:ui,reason_param:Kn,reason_cause:Rl,Require:ia,Route:Yn,route_param:Jn,Subscription_State:bl,substate_value:zn,subexp_params:Xn,event_reason_value:Il,Subject:la,Supported:oa,To:ci,to_param:fi,Via:Qn,via_param:ks,via_params:Zn,via_ttl:di,via_maddr:hi,via_received:_i,via_branch:pi,response_port:mi,rport:gi,sent_protocol:Ti,protocol_name:vi,transport:Si,sent_by:Ei,via_host:yi,via_port:er,ttl:Ci,WWW_Authenticate:aa,Session_Expires:wl,s_e_expires:tr,s_e_params:sr,s_e_refresher:Ol,extension_header:Dl,header_value:Nl,message_body:ua,uuid_URI:xl,uuid:Ft,hex4:Vt,hex8:Ai,hex12:Ul,Refer_To:ca,Replaces:kl,call_id:nr,replaces_param:rr,to_tag:Ri,from_tag:bi,early_flag:Pl};if(a!==void 0){if(s[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var r=0,_=0,d=[];function h(e){r<_||(r>_&&(_=r,d=[]),d.push(e))}function g(){var e;return o.substr(r,2)===`\r
|
|
2
2
|
`?(e=`\r
|
|
3
|
-
`,r+=2):(e=null,d('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[0-9]")),e}function S(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[a-zA-Z]")),e}function E(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[0-9a-fA-F]")),e}function A(){var e;return e=k(),e===null&&(e=M()),e}function C(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[\\0-\\xFF]")),e}function R(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d('["]')),e}function k(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,d('" "')),e}function M(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,d('"\\t"')),e}function ie(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,d('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,d('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,d('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,d('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,d('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,d('","'))))))))))),e}function V(){var e;return e=ie(),e===null&&(e=Ee()),e}function Ee(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,d('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,d('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,d('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,d('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,d('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,d('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,d(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,d('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,d('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,d('"%"')),e!==null?(l=E(),l!==null?(u=E(),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 L(){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=L(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=k(),l===null&&(l=M());l!==null;)e.push(l),l=k(),l===null&&(l=M());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),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 q(){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=L();f!==null;)u.push(f),f=L();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=L();f!==null;)u.push(f),f=L();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(y){return a.substring(r,y)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[\\x80-\\uFFFF]")),e}function X(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[\\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,d("[a-f]"))),e}function x(){var e,l,u;if(u=r,l=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"'))))))))))));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=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"')))))))))));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,d('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,d('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,d('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,d('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,d('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,d('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,d('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,d('"\\\\"')),e===null&&(e=R(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,d('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,d('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,d('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,d('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,d('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,d('"}"')),e===null&&(e=k(),e===null&&(e=M())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,d('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,d('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,d('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,d('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,d('"\\\\"')),l===null&&(l=R(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,d('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,d('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,d('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,d('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,d('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,d('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ie(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,d('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,d('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,d('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,d('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,d('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,d(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,d('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,d('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,d('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,d('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,d('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,d('"\\\\"')),l===null&&(l=R(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,d('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,d('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,d('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,d('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,d('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,d('"}"')))))))))))))))))))))))));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,d('"*"')),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,d('"/"')),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,d('"="')),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,d('"("')),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,d('")"')),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 Pe(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,d('">"')),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,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,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,d('","')),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,d('";"')),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,d('":"')),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=R(),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 Se(){var e,l,u,f;return u=r,f=r,e=R(),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,d("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[\\]-~]")),e===null&&(e=F(),e===null&&(e=L())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=R(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=R(),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=R(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=R(),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 y=a.substring(r,v).trim();return y.substring(1,y.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function ue(){var e;return e=L(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,d('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,d("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,d('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,d("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,d("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,d("[\\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,d('":"')),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,y;return v=r,y=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?(p=Nn(),p!==null?(m=Xs(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y),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,d('"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,d('"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=bn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),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,d('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function bn(){var e,l;if(l=V(),l===null&&(l=ve(),l===null&&(l=wn())),l!==null)for(e=[];l!==null;)e.push(l),l=V(),l===null&&(l=ve(),l===null&&(l=wn()));else e=null;return e}function wn(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,d('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,d('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,d('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,d('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,d('"/"'))))))))),e}function Ys(){var e,l,u;for(u=r,e=[],l=V(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,d('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,d('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,d('","'))))))));l!==null;)e.push(l),l=V(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,d('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,d('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,d('","'))))))));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,d('":"')),l!==null?(u=vr(),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=On(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,d('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=On(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,d('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,d('"."')),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 On(){var e,l,u,f;if(f=r,e=ie(),e!==null){for(l=[],u=ie(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,d('"_"'))));u!==null;)l.push(u),u=ie(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,d('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Dn(){var e,l,u,f;if(f=r,e=S(),e!==null){for(l=[],u=ie(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,d('"_"'))));u!==null;)l.push(u),u=ie(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,d('"_"'))));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,d('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,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 w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,y,O,le,Ue,wt,ks,$,I,Te;return $=r,I=r,e=oe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,d('":"')),f!==null?(p=oe(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,d('":"')),m!==null?(v=oe(),v!==null?(a.charCodeAt(r)===58?(y=":",r++):(y=null,d('":"')),y!==null?(O=oe(),O!==null?(a.charCodeAt(r)===58?(le=":",r++):(le=null,d('":"')),le!==null?(Ue=oe(),Ue!==null?(a.charCodeAt(r)===58?(wt=":",r++):(wt=null,d('":"')),wt!==null?(ks=ot(),ks!==null?e=[e,l,u,f,p,m,v,y,O,le,Ue,wt,ks]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,d('":"')),u!==null?(f=oe(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,d('":"')),p!==null?(m=oe(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,d('":"')),v!==null?(y=oe(),y!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,d('":"')),O!==null?(le=oe(),le!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,d('":"')),Ue!==null?(wt=ot(),wt!==null?e=[e,l,u,f,p,m,v,y,O,le,Ue,wt]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,d('":"')),u!==null?(f=oe(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,d('":"')),p!==null?(m=oe(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,d('":"')),v!==null?(y=oe(),y!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,d('":"')),O!==null?(le=ot(),le!==null?e=[e,l,u,f,p,m,v,y,O,le]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,d('":"')),u!==null?(f=oe(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,d('":"')),p!==null?(m=oe(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,d('":"')),v!==null?(y=ot(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,d('":"')),u!==null?(f=oe(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,d('":"')),p!==null?(m=ot(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,d('":"')),u!==null?(f=ot(),f!==null?e=[e,l,u,f]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=ot(),l!==null?e=[e,l]:(e=null,r=I)):(e=null,r=I),e===null&&(I=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,d('"::"')),e!==null?(l=oe(),l!==null?e=[e,l]:(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,d('"::"')),l!==null?(u=oe(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,d('":"')),f!==null?(p=oe(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,d('":"')),m!==null?(v=oe(),v!==null?(a.charCodeAt(r)===58?(y=":",r++):(y=null,d('":"')),y!==null?(O=oe(),O!==null?(a.charCodeAt(r)===58?(le=":",r++):(le=null,d('":"')),le!==null?(Ue=ot(),Ue!==null?e=[e,l,u,f,p,m,v,y,O,le,Ue]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('"::"')),u!==null?(f=oe(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,d('":"')),p!==null?(m=oe(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,d('":"')),v!==null?(y=oe(),y!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,d('":"')),O!==null?(le=ot(),le!==null?e=[e,l,u,f,p,m,v,y,O,le]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('":"')),u!==null?(f=oe(),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,d('"::"')),f!==null?(p=oe(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,d('":"')),m!==null?(v=oe(),v!==null?(a.charCodeAt(r)===58?(y=":",r++):(y=null,d('":"')),y!==null?(O=ot(),O!==null?e=[e,l,u,f,p,m,v,y,O]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('":"')),u!==null?(f=oe(),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,d('":"')),f!==null?(p=oe(),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,d('"::"')),p!==null?(m=oe(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,d('":"')),v!==null?(y=ot(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('":"')),u!==null?(f=oe(),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,d('":"')),f!==null?(p=oe(),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,d('":"')),p!==null?(m=oe(),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,d('"::"')),m!==null?(v=ot(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('":"')),u!==null?(f=oe(),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,d('":"')),f!==null?(p=oe(),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,d('":"')),p!==null?(m=oe(),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,d('":"')),m!==null?(v=oe(),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,d('"::"')),v!==null?(y=oe(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I),e===null&&(I=r,e=oe(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,d('":"')),u!==null?(f=oe(),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,d('":"')),f!==null?(p=oe(),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,d('":"')),p!==null?(m=oe(),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,d('":"')),m!==null?(v=oe(),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,d('":"')),v!==null?(y=oe(),y!==null?v=[v,y]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(y="::",r+=2):(y=null,d('"::"')),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I)):(e=null,r=I))))))))))))))),e!==null&&(e=function(Lh){return w.host_type="IPv6",a.substring(r,Lh)}($)),e===null&&(r=$),e}function oe(){var e,l,u,f,p;return p=r,e=E(),e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?(f=E(),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=oe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=oe(),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,y,O;return y=r,O=r,e=Cs(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),l!==null?(u=Cs(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,d('"."')),f!==null?(p=Cs(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,d('"."')),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(le){return w.host_type="IPv4",a.substring(r,le)}(y)),e===null&&(r=y),e}function Cs(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,d('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,d("[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,d('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,d("[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,d('"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,d("[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 vr(){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(y,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Nn(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,d('";"')),l!==null?(u=Un(),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,d('";"')),l!==null?(u=Un(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Un(){var e;return e=Sr(),e===null&&(e=Er(),e===null&&(e=yr(),e===null&&(e=Ar(),e===null&&(e=Cr(),e===null&&(e=Rr(),e===null&&(e=Ir())))))),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,d('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,d('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,d('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,d('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,d('"tls"')),l===null&&(l=x())))),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 Er(){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,d('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,d('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,d('"ip"')),l===null&&(l=x())),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 yr(){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,d('"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,d('"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 Cr(){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,d('"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 Rr(){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,d('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),l!==null?(u=x(),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 Ir(){var e,l,u,f,p,m;return f=r,p=r,e=br(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),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,y,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[y.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function br(){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=wr(),e===null&&(e=V(),e===null&&(e=ve())),e}function wr(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,d('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,d('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,d('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,d('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')))))))),e}function Xs(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e!==null)if(l=Qs(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,d('"&"')),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,d('"&"')),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=Or(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),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,y){v=v.join("").toLowerCase(),y=y.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(y):w.uri_headers[v]=[y]}(f,e[0],e[2])),e===null&&(r=f),e}function Or(){var e,l;if(l=Zs(),l===null&&(l=V(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=Zs(),l===null&&(l=V(),l===null&&(l=ve()));else e=null;return e}function bs(){var e,l;for(e=[],l=Zs(),l===null&&(l=V(),l===null&&(l=ve()));l!==null;)e.push(l),l=Zs(),l===null&&(l=V(),l===null&&(l=ve()));return e}function Zs(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,d('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,d('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,d('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')))))))),e}function ml(){var e;return e=Gr(),e===null&&(e=Dr()),e}function Dr(){var e,l,u,f,p,m;return m=r,e=rn(),e!==null?(l=k(),l!==null?(u=xn(),u!==null?(f=k(),f!==null?(p=Mn(),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=Pn()),e}function Pn(){var e,l,u,f;return f=r,e=xr(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l!==null?(u=Nr(),u===null&&(u=ws()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Nr(){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,d('"?"')),l!==null?(u=kn(),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,d('"//"')),e!==null?(l=Pr(),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,d('"/"')),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=Ur(),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=V(),e===null&&(e=ve())),e}function Ur(){var e;return e=V(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,d('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,d('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,d('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,d('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,d('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,d('","')))))))))))),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,d('"/"')),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,d('"/"')),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,d('";"')),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,d('";"')),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=V(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,d('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,d('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,d('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,d('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,d('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,d('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,d('","')))))))))),e}function xr(){var e,l,u,f,p;if(f=r,p=r,e=S(),e!==null){for(l=[],u=S(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,d('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,d('"."'))))));u!==null;)l.push(u),u=S(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,d('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,d('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,d('"."'))))));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 Pr(){var e;return e=kr(),e===null&&(e=Mr()),e}function kr(){var e,l,u,f;return u=r,f=r,e=dt(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,d('"@"')),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 Mr(){var e,l;if(l=V(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,d('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,d('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,d('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,d('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,d('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=V(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,d('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,d('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,d('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,d('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,d('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,d('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,d('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,d('"+"')))))))))));else e=null;return e}function kn(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Mn(){var e,l,u,f,p,m,v,y;if(v=r,y=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,d('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,d('"/"')),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,d('"."')),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=y)}else e=null,r=y;else e=null,r=y}else e=null,r=y;else e=null,r=y;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function Lr(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,d('"INVITE"')),e}function $r(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,d('"ACK"')),e}function Hr(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,d('"OPTIONS"')),e}function Fr(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,d('"BYE"')),e}function Vr(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,d('"CANCEL"')),e}function jr(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,d('"REGISTER"')),e}function qr(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,d('"SUBSCRIBE"')),e}function Br(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,d('"NOTIFY"')),e}function nn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,d('"REFER"')),e}function rn(){var e,l;return l=r,e=Lr(),e===null&&(e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=Vr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=Br(),e===null&&(e=nn(),e===null&&(e=x()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function Gr(){var e,l,u,f,p,m;return m=r,e=Mn(),e!==null?(l=k(),l!==null?(u=Wr(),u!==null?(f=k(),f!==null?(p=gl(),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 Wr(){var e,l;return l=r,e=Kr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Kr(){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 gl(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=V(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=k(),l===null&&(l=M()))))));l!==null;)e.push(l),l=N(),l===null&&(l=V(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=k(),l===null&&(l=M()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Ya(){var e,l,u,f,p,m;if(p=r,e=un(),e!==null){for(l=[],m=r,u=ae(),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=ae(),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 Ja(){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,d('"@"')),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 Ln(){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=ae(),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=ae(),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(y){var O,le;for(le=w.multi_header.length,O=0;O<le;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=$n(),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=$n(),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(y){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:y,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=Pe(),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=x(),e!==null){for(l=[],v=r,u=L(),u!==null?(f=x(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=L(),u!==null?(f=x(),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(y,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(le,Ue){return le+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function $n(){var e;return e=Yr(),e===null&&(e=ts(),e===null&&(e=We())),e}function Yr(){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,d('"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,d('"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,y;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,d('"0"')),e!==null?(y=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,d('"."')),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=y)):(l=null,r=y)):(l=null,r=y)):(l=null,r=y),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=x(),e!==null?(m=r,l=re(),l!==null?(u=Tl(),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,y,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[y.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function Tl(){var e;return e=x(),e===null&&(e=us(),e===null&&(e=Oe())),e}function vl(){var e,l,u,f,p,m;if(p=r,e=Hn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Fn(),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=Fn(),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 Hn(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,d('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,d('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,d('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,d('"alert"')),e===null&&(e=x())))),e}function Fn(){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,d('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,d('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,d('"required"')),u===null&&(u=x())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function za(){var e,l,u,f,p,m;if(p=r,e=x(),e!==null){for(l=[],m=r,u=ae(),u!==null?(f=x(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ae(),u!==null?(f=x(),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 Xa(){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 El(){var e,l;return l=r,e=Jr(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function Jr(){var e,l,u,f,p,m,v,y;if(v=r,e=zr(),e!==null)if(l=G(),l!==null)if(u=Vn(),u!==null){for(f=[],y=r,p=ye(),p!==null?(m=jn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ye(),p!==null?(m=jn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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 zr(){var e;return e=Xr(),e===null&&(e=ln()),e}function Xr(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,d('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,d('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,d('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,d('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,d('"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,d('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,d('"multipart"')),e===null&&(e=an())),e}function an(){var e;return e=x(),e===null&&(e=Qr()),e}function Qr(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,d('"x-"')),e!==null?(l=x(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Vn(){var e;return e=an(),e===null&&(e=x()),e}function jn(){var e,l,u,f;return f=r,e=x(),e!==null?(l=re(),l!==null?(u=yl(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function yl(){var e;return e=x(),e===null&&(e=Oe()),e}function Al(){var e,l,u,f;return f=r,e=Cl(),e!==null?(l=L(),l!==null?(u=rn(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Cl(){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 Qa(){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(y,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,d('"."')),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,d('"."')),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 Zr(){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(y){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=ei(),e===null&&(e=We()),e}function ei(){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,d('"tag"')),e!==null?(l=re(),l!==null?(u=x(),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 Za(){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 eo(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function to(){var e,l,u,f,p,m,v,y,O,le;for(y=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=Pe(),f!==null){for(p=[],le=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);m!==null;)p.push(m),le=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);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=y),e}function ti(){var e;return e=qn(),e}function qn(){var e,l,u,f,p,m,v,y;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,d('"Digest"')),e!==null)if(l=L(),l!==null)if(u=fn(),u!==null){for(f=[],y=r,p=ae(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ae(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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=xs()),e}function xs(){var e,l,u,f,p,m,v,y;if(v=r,e=x(),e!==null)if(l=L(),l!==null)if(u=ns(),u!==null){for(f=[],y=r,p=ae(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ae(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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=x(),e!==null?(l=re(),l!==null?(u=x(),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=si(),e===null&&(e=hn(),e===null&&(e=ri(),e===null&&(e=li(),e===null&&(e=ai(),e===null&&(e=oi(),e===null&&(e=_n(),e===null&&(e=ns()))))))),e}function si(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,d('"realm"')),e!==null?(l=re(),l!==null?(u=ni(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ni(){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,y,O;if(y=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,d('"domain"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null)if(f=dn(),f!==null){if(p=[],O=r,v=k(),v!==null)for(m=[];v!==null;)m.push(v),v=k();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=k(),v!==null)for(m=[];v!==null;)m.push(v),v=k();else m=null;m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Se(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=y)):(e=null,r=y)}else e=null,r=y;else e=null,r=y;else e=null,r=y;else e=null,r=y;return e}function dn(){var e;return e=Pn(),e===null&&(e=tn()),e}function ri(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,d('"nonce"')),e!==null?(l=re(),l!==null?(u=ii(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ii(){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 li(){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,d('"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 ai(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,d('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,d('"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,d('"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 oi(){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,d('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,d('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,d('"MD5-sess"')),u===null&&(u=x())),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,y,O,le;if(y=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,d('"qop"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null){if(O=r,f=Bn(),f!==null){for(p=[],le=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,d('","')),m!==null?(v=Bn(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);m!==null;)p.push(m),le=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,d('","')),m!==null?(v=Bn(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Se(),p!==null?e=[e,l,u,f,p]:(e=null,r=y)):(e=null,r=y)}else e=null,r=y;else e=null,r=y;else e=null,r=y;return e}function Bn(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,d('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,d('"auth"')),e===null&&(e=x())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function so(){var e,l,u,f,p,m;if(p=r,e=x(),e!==null){for(l=[],m=r,u=ae(),u!==null?(f=x(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ae(),u!==null?(f=x(),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 Gn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Wn(),e!==null){for(l=[],v=r,u=ae(),u!==null?(f=Wn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ae(),u!==null?(f=Wn(),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(y){var O,le;for(le=w.multi_header.length,O=0;O<le;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 Wn(){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(y){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:y,parsed:O})}(p)),e===null&&(r=p),e}function ui(){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,d('"SIP"')),e===null&&(e=x()),e!==null){for(l=[],v=r,u=ye(),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=ye(),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(y,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var le=w.params.text;w.text=le.substring(1,le.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function Kn(){var e;return e=Rl(),e===null&&(e=We()),e}function Rl(){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,d('"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,y){w.cause=parseInt(y.join(""))}(p,e[2])),e===null&&(r=p),e}function no(){var e,l,u,f,p,m;if(p=r,e=x(),e!==null){for(l=[],m=r,u=ae(),u!==null?(f=x(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ae(),u!==null?(f=x(),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 Yn(){var e,l,u,f,p,m;if(p=r,e=Jn(),e!==null){for(l=[],m=r,u=ae(),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=ae(),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 Jn(){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 Il(){var e,l,u,f,p,m;if(p=r,e=zn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Xn(),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=Xn(),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;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,d('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,d('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,d('"terminated"')),e===null&&(e=x()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function Xn(){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,d('"reason"')),e!==null?(l=re(),l!==null?(u=bl(),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,d('"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,d('"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 bl(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,d('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,d('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,d('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,d('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,d('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,d('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,d('"invariant"')),e===null&&(e=x()))))))),e}function ro(){var e;return e=q(),e=e!==null?e:"",e}function io(){var e,l,u,f,p,m;if(p=r,e=x(),e!==null){for(l=[],m=r,u=ae(),u!==null?(f=x(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ae(),u!==null?(f=x(),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 ci(){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=fi(),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=fi(),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(y){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 fi(){var e;return e=ei(),e===null&&(e=We()),e}function Qn(){var e,l,u,f,p,m;if(p=r,e=Ps(),e!==null){for(l=[],m=r,u=ae(),u!==null?(f=Ps(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ae(),u!==null?(f=Ps(),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 Ps(){var e,l,u,f,p,m,v,y;if(v=r,e=Ti(),e!==null)if(l=L(),l!==null)if(u=Ei(),u!==null){for(f=[],y=r,p=ye(),p!==null?(m=Zn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ye(),p!==null?(m=Zn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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 Zn(){var e;return e=hi(),e===null&&(e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi(),e===null&&(e=We()))))),e}function hi(){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,d('"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 di(){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,d('"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 _i(){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,d('"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 pi(){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,d('"branch"')),e!==null?(l=re(),l!==null?(u=x(),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 mi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,d('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=gi(),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 gi(){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(y,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function Ti(){var e,l,u,f,p,m;return m=r,e=vi(),e!==null?(l=G(),l!==null?(u=x(),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 vi(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,d('"SIP"')),e===null&&(e=x()),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,d('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,d('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,d('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,d('"SCTP"')),e===null&&(e=x())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function Ei(){var e,l,u,f,p;return f=r,e=yi(),e!==null?(p=r,l=nt(),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 yi(){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 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(y,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 lo(){var e;return e=qn(),e}function wl(){var e,l,u,f,p,m;if(p=r,e=tr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function tr(){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 sr(){var e;return e=Ol(),e===null&&(e=We()),e}function Ol(){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,d('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,d('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,d('"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 Dl(){var e,l,u,f;return f=r,e=x(),e!==null?(l=B(),l!==null?(u=Nl(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Nl(){var e,l;for(e=[],l=J(),l===null&&(l=X(),l===null&&(l=L()));l!==null;)e.push(l),l=J(),l===null&&(l=X(),l===null&&(l=L()));return e}function ao(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Ul(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,d('"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,y,O,le,Ue;return le=r,Ue=r,e=Ci(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,d('"-"')),l!==null?(u=Vt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,d('"-"')),f!==null?(p=Vt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,d('"-"')),m!==null?(v=Vt(),v!==null?(a.charCodeAt(r)===45?(y="-",r++):(y=null,d('"-"')),y!==null?(O=xl(),O!==null?e=[e,l,u,f,p,m,v,y,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)}(le,e[0])),e===null&&(r=le),e}function Vt(){var e,l,u,f,p;return p=r,e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?(f=E(),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 Ci(){var e,l,u;return u=r,e=Vt(),e!==null?(l=Vt(),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=Vt(),e!==null?(l=Vt(),l!==null?(u=Vt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function oo(){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(y){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function Pl(){var e,l,u,f,p,m;if(p=r,e=nr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=rr(),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=rr(),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 nr(){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,d('"@"')),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 rr(){var e;return e=Ri(),e===null&&(e=Ii(),e===null&&(e=kl(),e===null&&(e=We()))),e}function Ri(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,d('"to-tag"')),e!==null?(l=re(),l!==null?(u=x(),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 Ii(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,d('"from-tag"')),e!==null?(l=re(),l!==null?(u=x(),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 kl(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,d('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function uo(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 Ml(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,_);f++){var p=a.charAt(f);p===`
|
|
4
|
-
`?(u||e++,l=1,u=!1):p==="\r"||p==="\u2028"||p==="\u2029"?(e++,l=1,u=!0):(l++,u=!1)}return{line:e,column:l}}var fs=Ks(),
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,
|
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,R=!1,k;return{s:function(){S=g[Symbol.iterator]()},n:function(){var ie=S.next();return C=ie.done,ie},e:function(ie){R=!0,k=ie},f:function(){try{!C&&S.return!=null&&S.return()}finally{if(R)throw k}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var S=Object.prototype.toString.call(g).slice(8,-1);if(S==="Object"&&g.constructor&&(S=g.constructor.name),S==="Map"||S==="Set")return Array.from(g);if(S==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(S))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var S=0,E=new Array(T);S<T;S++)E[S]=g[S];return E}var o=lt,s=Ks(),r=os();Ze.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var _=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,S=new Array(T>1?T-1:0),E=1;E<T;E++)S[E-1]=arguments[E];for(var A=0,C=S;A<C.length;A++){var R=C[A];if(_(g[R]))return!1}return!0};var h=Ze.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,S,E,A="";for(S=0;S<g;S++)E=Math.random()*T|0,A+=E.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 S=Math.random()*16|0,E=T==="x"?S:S&3|8;return E.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 d=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 S=g.split("@"),E,A;switch(S.length){case 1:if(!T)return;E=g,A=T;break;case 2:E=S[0],A=S[1];break;default:E=S.slice(0,S.length-1).join("@"),A=S[S.length-1]}E=E.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(E)&&(E=E.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(d(E),"@").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"},S=g.toLowerCase().replace(/_/g,"-").split("-"),E="",A=S.length,C;for(C=0;C<A;C++)C!==0&&(E+="-"),E+=S[C].charAt(0).toUpperCase()+S[C].substring(1);return T[E]&&(E=T[E]),E},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,S){return Math.floor(Math.random()*(S-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 S(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 E(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 R(pe,ue,_e){return ue^(pe|~_e)}function k(pe,ue,_e,we,Ne,Qe,Le){return pe=S(pe,S(S(E(ue,_e,we),Ne),Le)),S(T(pe,Qe),ue)}function M(pe,ue,_e,we,Ne,Qe,Le){return pe=S(pe,S(S(A(ue,_e,we),Ne),Le)),S(T(pe,Qe),ue)}function ie(pe,ue,_e,we,Ne,Qe,Le){return pe=S(pe,S(S(C(ue,_e,we),Ne),Le)),S(T(pe,Qe),ue)}function N(pe,ue,_e,we,Ne,Qe,Le){return pe=S(pe,S(S(R(ue,_e,we),Ne),Le)),S(T(pe,Qe),ue)}function V(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 Ee(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 L=[],D,B,q,J,F,X,U,x,se,st=7,ee=12,W=17,G=22,re=5,ge=9,be=14,Pe=20,Ce=4,ae=11,ye=16,nt=23,at=6,Se=10,Ae=15,Ie=21;for(g=ve(g),L=V(g),X=1732584193,U=4023233417,x=2562383102,se=271733878,D=0;D<L.length;D+=16)B=X,q=U,J=x,F=se,X=k(X,U,x,se,L[D+0],st,3614090360),se=k(se,X,U,x,L[D+1],ee,3905402710),x=k(x,se,X,U,L[D+2],W,606105819),U=k(U,x,se,X,L[D+3],G,3250441966),X=k(X,U,x,se,L[D+4],st,4118548399),se=k(se,X,U,x,L[D+5],ee,1200080426),x=k(x,se,X,U,L[D+6],W,2821735955),U=k(U,x,se,X,L[D+7],G,4249261313),X=k(X,U,x,se,L[D+8],st,1770035416),se=k(se,X,U,x,L[D+9],ee,2336552879),x=k(x,se,X,U,L[D+10],W,4294925233),U=k(U,x,se,X,L[D+11],G,2304563134),X=k(X,U,x,se,L[D+12],st,1804603682),se=k(se,X,U,x,L[D+13],ee,4254626195),x=k(x,se,X,U,L[D+14],W,2792965006),U=k(U,x,se,X,L[D+15],G,1236535329),X=M(X,U,x,se,L[D+1],re,4129170786),se=M(se,X,U,x,L[D+6],ge,3225465664),x=M(x,se,X,U,L[D+11],be,643717713),U=M(U,x,se,X,L[D+0],Pe,3921069994),X=M(X,U,x,se,L[D+5],re,3593408605),se=M(se,X,U,x,L[D+10],ge,38016083),x=M(x,se,X,U,L[D+15],be,3634488961),U=M(U,x,se,X,L[D+4],Pe,3889429448),X=M(X,U,x,se,L[D+9],re,568446438),se=M(se,X,U,x,L[D+14],ge,3275163606),x=M(x,se,X,U,L[D+3],be,4107603335),U=M(U,x,se,X,L[D+8],Pe,1163531501),X=M(X,U,x,se,L[D+13],re,2850285829),se=M(se,X,U,x,L[D+2],ge,4243563512),x=M(x,se,X,U,L[D+7],be,1735328473),U=M(U,x,se,X,L[D+12],Pe,2368359562),X=ie(X,U,x,se,L[D+5],Ce,4294588738),se=ie(se,X,U,x,L[D+8],ae,2272392833),x=ie(x,se,X,U,L[D+11],ye,1839030562),U=ie(U,x,se,X,L[D+14],nt,4259657740),X=ie(X,U,x,se,L[D+1],Ce,2763975236),se=ie(se,X,U,x,L[D+4],ae,1272893353),x=ie(x,se,X,U,L[D+7],ye,4139469664),U=ie(U,x,se,X,L[D+10],nt,3200236656),X=ie(X,U,x,se,L[D+13],Ce,681279174),se=ie(se,X,U,x,L[D+0],ae,3936430074),x=ie(x,se,X,U,L[D+3],ye,3572445317),U=ie(U,x,se,X,L[D+6],nt,76029189),X=ie(X,U,x,se,L[D+9],Ce,3654602809),se=ie(se,X,U,x,L[D+12],ae,3873151461),x=ie(x,se,X,U,L[D+15],ye,530742520),U=ie(U,x,se,X,L[D+2],nt,3299628645),X=N(X,U,x,se,L[D+0],at,4096336452),se=N(se,X,U,x,L[D+7],Se,1126891415),x=N(x,se,X,U,L[D+14],Ae,2878612391),U=N(U,x,se,X,L[D+5],Ie,4237533241),X=N(X,U,x,se,L[D+12],at,1700485571),se=N(se,X,U,x,L[D+3],Se,2399980690),x=N(x,se,X,U,L[D+10],Ae,4293915773),U=N(U,x,se,X,L[D+1],Ie,2240044497),X=N(X,U,x,se,L[D+8],at,1873313359),se=N(se,X,U,x,L[D+15],Se,4264355552),x=N(x,se,X,U,L[D+6],Ae,2734768916),U=N(U,x,se,X,L[D+13],Ie,1309151649),X=N(X,U,x,se,L[D+4],at,4149444226),se=N(se,X,U,x,L[D+11],Se,3174756917),x=N(x,se,X,U,L[D+2],Ae,718787259),U=N(U,x,se,X,L[D+9],Ie,3951481745),X=S(X,B),U=S(U,q),x=S(x,J),se=S(se,F);var Oe=Ee(X)+Ee(U)+Ee(x)+Ee(se);return Oe.toLowerCase()},Ze.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var S=t(T),E;try{for(S.s();!(E=S.n()).done;){var A=E.value;A.stop()}}catch(V){S.e(V)}finally{S.f()}}else{T=g.getAudioTracks();var C=t(T),R;try{for(C.s();!(R=C.n()).done;){var k=R.value;k.stop()}}catch(V){C.e(V)}finally{C.f()}T=g.getVideoTracks();var M=t(T),ie;try{for(M.s();!(ie=M.n()).done;){var N=ie.value;N.stop()}}catch(V){M.e(V)}finally{M.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:{}},dr=typeof Reflect=="object"?Reflect:null,zu=dr&&typeof dr.apply=="function"?dr.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},ga;dr&&typeof dr.ownKeys=="function"?ga=dr.ownKeys:Object.getOwnPropertySymbols?ga=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ga=function(t){return Object.getOwnPropertyNames(t)};function ud(c){console&&console.warn&&console.warn(c)}var jf=Number.isNaN||function(t){return t!==t};function Me(){Me.init.call(this)}Du.exports=Me;Du.exports.once=dd;Me.EventEmitter=Me;Me.prototype._events=void 0;Me.prototype._eventsCount=0;Me.prototype._maxListeners=void 0;var Xu=10;function qa(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||jf(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||jf(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 qf(c){return c._maxListeners===void 0?Me.defaultMaxListeners:c._maxListeners}Me.prototype.getMaxListeners=function(){return qf(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 _=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw _.context=r,_}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")zu(h,this,n);else for(var d=h.length,g=Yf(h,d),a=0;a<d;++a)zu(g[a],this,n);return!0};function Bf(c,t,n,a){var o,s,r;if(qa(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=qf(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=c,_.type=t,_.count=r.length,ud(_)}return c}Me.prototype.addListener=function(t,n){return Bf(this,t,n,!1)};Me.prototype.on=Me.prototype.addListener;Me.prototype.prependListener=function(t,n){return Bf(this,t,n,!0)};function cd(){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 Gf(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=cd.bind(a);return o.listener=n,a.wrapFn=o,o}Me.prototype.once=function(t,n){return qa(n),this.on(t,Gf(this,t,n)),this};Me.prototype.prependOnceListener=function(t,n){return qa(n),this.prependListener(t,Gf(this,t,n)),this};Me.prototype.removeListener=function(t,n){var a,o,s,r,_;if(qa(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){_=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():fd(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,_||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 Wf(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?hd(o):Yf(o,o.length)}Me.prototype.listeners=function(t){return Wf(this,t,!0)};Me.prototype.rawListeners=function(t){return Wf(this,t,!1)};Me.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):Kf.call(c,t)};Me.prototype.listenerCount=Kf;function Kf(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?ga(this._events):[]};function Yf(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function fd(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function hd(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function dd(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))}Jf(c,t,s,{once:!0}),t!=="error"&&_d(c,o,{once:!0})})}function _d(c,t,n){typeof c.on=="function"&&Jf(c,"error",t,n)}function Jf(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:{}},_o,Qu;function pd(){if(Qu)return _o;Qu=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;_o=function(g,T){T=T||{};var S=typeof g;if(S==="string"&&g.length>0)return r(g);if(S==="number"&&isFinite(g))return T.long?h(g):_(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 S=parseFloat(T[1]),E=(T[2]||"ms").toLowerCase();switch(E){case"years":case"year":case"yrs":case"yr":case"y":return S*s;case"weeks":case"week":case"w":return S*o;case"days":case"day":case"d":return S*a;case"hours":case"hour":case"hrs":case"hr":case"h":return S*n;case"minutes":case"minute":case"mins":case"min":case"m":return S*t;case"seconds":case"second":case"secs":case"sec":case"s":return S*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return S;default:return}}}}function _(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?d(g,T,a,"day"):T>=n?d(g,T,n,"hour"):T>=t?d(g,T,t,"minute"):T>=c?d(g,T,c,"second"):g+" ms"}function d(g,T,S,E){var A=T>=S*1.5;return Math.round(g/S)+" "+E+(A?"s":"")}return _o}function md(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=pd(),n.destroy=d,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let S=0;S<g.length;S++)T=(T<<5)-T+g.charCodeAt(S),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,S=null,E,A;function C(...R){if(!C.enabled)return;const k=C,M=Number(new Date),ie=M-(T||M);k.diff=ie,k.prev=T,k.curr=M,T=M,R[0]=n.coerce(R[0]),typeof R[0]!="string"&&R.unshift("%O");let N=0;R[0]=R[0].replace(/%([a-zA-Z%])/g,(Ee,ve)=>{if(Ee==="%%")return"%";N++;const L=n.formatters[ve];if(typeof L=="function"){const D=R[N];Ee=L.call(k,D),R.splice(N,1),N--}return Ee}),n.formatArgs.call(k,R),(k.log||n.log).apply(k,R)}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:()=>S!==null?S:(E!==n.namespaces&&(E=n.namespaces,A=n.enabled(g)),A),set:R=>{S=R}}),typeof n.init=="function"&&n.init(C),C}function a(g,T){const S=n(this.namespace+(typeof T>"u"?":":T)+g);return S.log=this.log,S}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const S=(typeof g=="string"?g:"").split(/[\s,]+/),E=S.length;for(T=0;T<E;T++)S[T]&&(g=S[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(_),...n.skips.map(_).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,S;for(T=0,S=n.skips.length;T<S;T++)if(n.skips[T].test(g))return!1;for(T=0,S=n.names.length;T<S;T++)if(n.names[T].test(g))return!0;return!1}function _(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function d(){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 gd=md;(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 d="color: "+this.color;h.splice(1,0,d,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,S=>{S!=="%%"&&(g++,S==="%c"&&(T=g))}),h.splice(T,0,d)}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=gd(t);const{formatters:_}=c.exports;_.j=function(h){try{return JSON.stringify(h)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}})(uu,uu.exports);var mr=uu.exports;function Td(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 vd(c,t,n){return t&&Zu(c.prototype,t),n&&Zu(c,n),c}var ir=mr,lr="JsSIP",ht=function(){function c(t){Td(this,c),t?(this._debug=ir.default("".concat(lr,":").concat(t)),this._warn=ir.default("".concat(lr,":WARN:").concat(t)),this._error=ir.default("".concat(lr,":ERROR:").concat(t))):(this._debug=ir.default(lr),this._warn=ir.default("".concat(lr,":WARN")),this._error=ir.default("".concat(lr,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return vd(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),Pt={},zf={},Xf={exports:{}},ec=Xf.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 Qf=Xf.exports;(function(c){var t=function(_){return String(Number(_))===_?Number(_):_},n=function(_,h,d,g){if(g&&!d)h[g]=t(_[1]);else for(var T=0;T<d.length;T+=1)_[T+1]!=null&&(h[d[T]]=t(_[T+1]))},a=function(_,h,d){var g=_.name&&_.names;_.push&&!h[_.push]?h[_.push]=[]:g&&!h[_.name]&&(h[_.name]={});var T=_.push?{}:g?h[_.name]:h;n(d.match(_.reg),T,_.names,_.name),_.push&&h[_.push].push(T)},o=Qf,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(_){var h={},d=[],g=h;return _.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var S=T[0],E=T.slice(2);S==="m"&&(d.push({rtp:[],fmtp:[]}),g=d[d.length-1]);for(var A=0;A<(o[S]||[]).length;A+=1){var C=o[S][A];if(C.reg.test(E))return a(C,g,E)}}),h.media=d,h};var r=function(_,h){var d=h.split(/=(.+)/,2);return d.length===2?_[d[0]]=t(d[1]):d.length===1&&h.length>1&&(_[d[0]]=void 0),_};c.parseParams=function(_){return _.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(_){return _.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(_){for(var h=[],d=_.split(" ").map(t),g=0;g<d.length;g+=3)h.push({component:d[g],ip:d[g+1],port:d[g+2]});return h},c.parseImageAttributes=function(_){return _.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(_){return _.split(";").map(function(h){return h.split(",").map(function(d){var g,T=!1;return d[0]!=="~"?g=t(d):(g=t(d.substring(1,d.length)),T=!0),{scid:g,paused:T}})})}})(zf);var po=Qf,Sd=/%[sdv%]/g,Ed=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""}})},Oi=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 Ed.apply(null,o)},yd=["v","o","s","i","u","e","p","c","b","t","r","z","a"],Ad=["i","c","b","a"],Cd=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||yd,a=t.innerOrder||Ad,o=[];return n.forEach(function(s){po[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Oi(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(_){o.push(Oi(s,r,_))})})}),c.media.forEach(function(s){o.push(Oi("m",po.m[0],s)),a.forEach(function(r){po[r].forEach(function(_){_.name in s&&s[_.name]!=null?o.push(Oi(r,_,s)):_.push in s&&s[_.push]!=null&&s[_.push].forEach(function(h){o.push(Oi(r,_,h))})})})}),o.join(`\r
|
|
3
|
+
`,r+=2):(e=null,h('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[0-9]")),e}function S(){var e;return/^[a-zA-Z]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[a-zA-Z]")),e}function E(){var e;return/^[0-9a-fA-F]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[0-9a-fA-F]")),e}function A(){var e;return e=$(),e===null&&(e=k()),e}function R(){var e;return/^[\0-\xFF]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[\\0-\\xFF]")),e}function C(){var e;return/^["]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h('["]')),e}function $(){var e;return o.charCodeAt(r)===32?(e=" ",r++):(e=null,h('" "')),e}function k(){var e;return o.charCodeAt(r)===9?(e=" ",r++):(e=null,h('"\\t"')),e}function re(){var e;return/^[a-zA-Z0-9]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[a-zA-Z0-9]")),e}function x(){var e;return o.charCodeAt(r)===59?(e=";",r++):(e=null,h('";"')),e===null&&(o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"')),e===null&&(o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===64?(e="@",r++):(e=null,h('"@"')),e===null&&(o.charCodeAt(r)===38?(e="&",r++):(e=null,h('"&"')),e===null&&(o.charCodeAt(r)===61?(e="=",r++):(e=null,h('"="')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')),e===null&&(o.charCodeAt(r)===44?(e=",",r++):(e=null,h('","'))))))))))),e}function F(){var e;return e=re(),e===null&&(e=_e()),e}function _e(){var e;return o.charCodeAt(r)===45?(e="-",r++):(e=null,h('"-"')),e===null&&(o.charCodeAt(r)===95?(e="_",r++):(e=null,h('"_"')),e===null&&(o.charCodeAt(r)===46?(e=".",r++):(e=null,h('"."')),e===null&&(o.charCodeAt(r)===33?(e="!",r++):(e=null,h('"!"')),e===null&&(o.charCodeAt(r)===126?(e="~",r++):(e=null,h('"~"')),e===null&&(o.charCodeAt(r)===42?(e="*",r++):(e=null,h('"*"')),e===null&&(o.charCodeAt(r)===39?(e="'",r++):(e=null,h(`"'"`)),e===null&&(o.charCodeAt(r)===40?(e="(",r++):(e=null,h('"("')),e===null&&(o.charCodeAt(r)===41?(e=")",r++):(e=null,h('")"')))))))))),e}function pe(){var e,l,u,f,p;return f=r,p=r,o.charCodeAt(r)===37?(e="%",r++):(e=null,h('"%"')),e!==null?(l=E(),l!==null?(u=E(),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 P(){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 N(){var e;return e=P(),e=e!==null?e:"",e}function q(){var e,l,u,f,p;for(f=r,p=r,e=[],l=$(),l===null&&(l=k());l!==null;)e.push(l),l=$(),l===null&&(l=k());return e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=N(),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 j(){var e,l,u,f,p,m,v;if(p=r,m=r,l=K(),l!==null)for(e=[];l!==null;)e.push(l),l=K();else e=null;if(e!==null){for(l=[],v=r,u=[],f=P();f!==null;)u.push(f),f=P();for(u!==null?(f=K(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=P();f!==null;)u.push(f),f=P();u!==null?(f=K(),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(y){return o.substring(r,y)}(p)),e===null&&(r=p),e}function K(){var e;return/^[!-~]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[!-~]")),e===null&&(e=V()),e}function V(){var e;return/^[\x80-\uFFFF]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[\\x80-\\uFFFF]")),e}function z(){var e;return/^[\x80-\xBF]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[\\x80-\\xBF]")),e}function D(){var e;return e=T(),e===null&&(/^[a-f]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[a-f]"))),e}function U(){var e,l,u;if(u=r,l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(r,f)}(u)),e===null&&(r=u),e}function X(){var e,l,u;if(u=r,l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(r,f)}(u)),e===null&&(r=u),e}function He(){var e;return o.charCodeAt(r)===40?(e="(",r++):(e=null,h('"("')),e===null&&(o.charCodeAt(r)===41?(e=")",r++):(e=null,h('")"')),e===null&&(o.charCodeAt(r)===60?(e="<",r++):(e=null,h('"<"')),e===null&&(o.charCodeAt(r)===62?(e=">",r++):(e=null,h('">"')),e===null&&(o.charCodeAt(r)===64?(e="@",r++):(e=null,h('"@"')),e===null&&(o.charCodeAt(r)===44?(e=",",r++):(e=null,h('","')),e===null&&(o.charCodeAt(r)===59?(e=";",r++):(e=null,h('";"')),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===92?(e="\\",r++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"')),e===null&&(o.charCodeAt(r)===91?(e="[",r++):(e=null,h('"["')),e===null&&(o.charCodeAt(r)===93?(e="]",r++):(e=null,h('"]"')),e===null&&(o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e===null&&(o.charCodeAt(r)===61?(e="=",r++):(e=null,h('"="')),e===null&&(o.charCodeAt(r)===123?(e="{",r++):(e=null,h('"{"')),e===null&&(o.charCodeAt(r)===125?(e="}",r++):(e=null,h('"}"')),e===null&&(e=$(),e===null&&(e=k())))))))))))))))))),e}function Q(){var e,l,u;if(u=r,l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"')),l===null&&(o.charCodeAt(r)===40?(l="(",r++):(l=null,h('"("')),l===null&&(o.charCodeAt(r)===41?(l=")",r++):(l=null,h('")"')),l===null&&(o.charCodeAt(r)===60?(l="<",r++):(l=null,h('"<"')),l===null&&(o.charCodeAt(r)===62?(l=">",r++):(l=null,h('">"')),l===null&&(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l===null&&(o.charCodeAt(r)===92?(l="\\",r++):(l=null,h('"\\\\"')),l===null&&(l=C(),l===null&&(o.charCodeAt(r)===47?(l="/",r++):(l=null,h('"/"')),l===null&&(o.charCodeAt(r)===91?(l="[",r++):(l=null,h('"["')),l===null&&(o.charCodeAt(r)===93?(l="]",r++):(l=null,h('"]"')),l===null&&(o.charCodeAt(r)===63?(l="?",r++):(l=null,h('"?"')),l===null&&(o.charCodeAt(r)===123?(l="{",r++):(l=null,h('"{"')),l===null&&(o.charCodeAt(r)===125?(l="}",r++):(l=null,h('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=re(),l===null&&(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l===null&&(o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l===null&&(o.charCodeAt(r)===33?(l="!",r++):(l=null,h('"!"')),l===null&&(o.charCodeAt(r)===37?(l="%",r++):(l=null,h('"%"')),l===null&&(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l===null&&(o.charCodeAt(r)===95?(l="_",r++):(l=null,h('"_"')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===96?(l="`",r++):(l=null,h('"`"')),l===null&&(o.charCodeAt(r)===39?(l="'",r++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(r)===126?(l="~",r++):(l=null,h('"~"')),l===null&&(o.charCodeAt(r)===40?(l="(",r++):(l=null,h('"("')),l===null&&(o.charCodeAt(r)===41?(l=")",r++):(l=null,h('")"')),l===null&&(o.charCodeAt(r)===60?(l="<",r++):(l=null,h('"<"')),l===null&&(o.charCodeAt(r)===62?(l=">",r++):(l=null,h('">"')),l===null&&(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l===null&&(o.charCodeAt(r)===92?(l="\\",r++):(l=null,h('"\\\\"')),l===null&&(l=C(),l===null&&(o.charCodeAt(r)===47?(l="/",r++):(l=null,h('"/"')),l===null&&(o.charCodeAt(r)===91?(l="[",r++):(l=null,h('"["')),l===null&&(o.charCodeAt(r)===93?(l="]",r++):(l=null,h('"]"')),l===null&&(o.charCodeAt(r)===63?(l="?",r++):(l=null,h('"?"')),l===null&&(o.charCodeAt(r)===123?(l="{",r++):(l=null,h('"{"')),l===null&&(o.charCodeAt(r)===125?(l="}",r++):(l=null,h('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(r,f)}(u)),e===null&&(r=u),e}function W(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===42?(l="*",r++):(l=null,h('"*"')),l!==null?(u=N(),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 B(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===47?(l="/",r++):(l=null,h('"/"')),l!==null?(u=N(),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 ie(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l!==null?(u=N(),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 ve(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===40?(l="(",r++):(l=null,h('"("')),l!==null?(u=N(),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 Ie(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===41?(l=")",r++):(l=null,h('")"')),l!==null?(u=N(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function ke(){var e,l,u,f;return u=r,f=r,o.charCodeAt(r)===62?(e=">",r++):(e=null,h('">"')),e!==null?(l=N(),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=N(),e!==null?(o.charCodeAt(r)===60?(l="<",r++):(l=null,h('"<"')),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 oe(){var e,l,u,f,p;return f=r,p=r,e=N(),e!==null?(o.charCodeAt(r)===44?(l=",",r++):(l=null,h('","')),l!==null?(u=N(),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=N(),e!==null?(o.charCodeAt(r)===59?(l=";",r++):(l=null,h('";"')),l!==null?(u=N(),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=N(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=N(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function ot(){var e,l,u,f;return u=r,f=r,e=N(),e!==null?(l=C(),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=C(),e!==null?(l=N(),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=ve(),e!==null){for(l=[],u=be(),u===null&&(u=me(),u===null&&(u=Ce()));u!==null;)l.push(u),u=be(),u===null&&(u=me(),u===null&&(u=Ce()));l!==null?(u=Ie(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function be(){var e;return/^[!-']/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[!-']")),e===null&&(/^[*-[]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[*-[]")),e===null&&(/^[\]-~]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[\\]-~]")),e===null&&(e=V(),e===null&&(e=P())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=N(),e!==null)if(l=C(),l!==null){for(u=[],f=ue(),f===null&&(f=me());f!==null;)u.push(f),f=ue(),f===null&&(f=me());u!==null?(f=C(),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 o.substring(r,v)}(p)),e===null&&(r=p),e}function ge(){var e,l,u,f,p,m;if(p=r,m=r,e=N(),e!==null)if(l=C(),l!==null){for(u=[],f=ue(),f===null&&(f=me());f!==null;)u.push(f),f=ue(),f===null&&(f=me());u!==null?(f=C(),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 y=o.substring(r,v).trim();return y.substring(1,y.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function ue(){var e;return e=P(),e===null&&(o.charCodeAt(r)===33?(e="!",r++):(e=null,h('"!"')),e===null&&(/^[#-[]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[#-[]")),e===null&&(/^[\]-~]/.test(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[\\]-~]")),e===null&&(e=V())))),e}function me(){var e,l,u;return u=r,o.charCodeAt(r)===92?(e="\\",r++):(e=null,h('"\\\\"')),e!==null?(/^[\0-\t]/.test(o.charAt(r))?(l=o.charAt(r),r++):(l=null,h("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(o.charAt(r))?(l=o.charAt(r),r++):(l=null,h("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(o.charAt(r))?(l=o.charAt(r),r++):(l=null,h("[\\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=Ze(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ht(),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,y;return v=r,y=r,e=Ze(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ht(),u=u!==null?u:"",u!==null?(f=es(),f!==null?(p=Nn(),p!==null?(m=Xs(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y)):(e=null,r=y),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,a==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function Ze(){var e;return e=Le(),e===null&&(e=Lt()),e}function Le(){var e,l;return l=r,o.substr(r,4).toLowerCase()==="sips"?(e=o.substr(r,4),r+=4):(e=null,h('"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,o.substr(r,3).toLowerCase()==="sip"?(e=o.substr(r,3),r+=3):(e=null,h('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function ht(){var e,l,u,f,p,m;return f=r,p=r,e=In(),e!==null?(m=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=Ys(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(o.charCodeAt(r)===64?(u="@",r++):(u=null,h('"@"')),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(o.substring(r-1,v))}(f)),e===null&&(r=f),e}function In(){var e,l;if(l=F(),l===null&&(l=pe(),l===null&&(l=wn())),l!==null)for(e=[];l!==null;)e.push(l),l=F(),l===null&&(l=pe(),l===null&&(l=wn()));else e=null;return e}function wn(){var e;return o.charCodeAt(r)===38?(e="&",r++):(e=null,h('"&"')),e===null&&(o.charCodeAt(r)===61?(e="=",r++):(e=null,h('"="')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')),e===null&&(o.charCodeAt(r)===44?(e=",",r++):(e=null,h('","')),e===null&&(o.charCodeAt(r)===59?(e=";",r++):(e=null,h('";"')),e===null&&(o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e===null&&(o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"'))))))))),e}function Ys(){var e,l,u;for(u=r,e=[],l=F(),l===null&&(l=pe(),l===null&&(o.charCodeAt(r)===38?(l="&",r++):(l=null,h('"&"')),l===null&&(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===36?(l="$",r++):(l=null,h('"$"')),l===null&&(o.charCodeAt(r)===44?(l=",",r++):(l=null,h('","'))))))));l!==null;)e.push(l),l=F(),l===null&&(l=pe(),l===null&&(o.charCodeAt(r)===38?(l="&",r++):(l=null,h('"&"')),l===null&&(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')),l===null&&(o.charCodeAt(r)===36?(l="$",r++):(l=null,h('"$"')),l===null&&(o.charCodeAt(r)===44?(l=",",r++):(l=null,h('","'))))))));return e!==null&&(e=function(f){w.password=o.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,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=vr(),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=o.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=On(),l!==null?(o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=On(),l!==null?(o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Dn(),l!==null?(o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."')),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",o.substring(r,v)}(f)),e===null&&(r=f),e}function On(){var e,l,u,f;if(f=r,e=re(),e!==null){for(l=[],u=re(),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===95?(u="_",r++):(u=null,h('"_"'))));u!==null;)l.push(u),u=re(),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===95?(u="_",r++):(u=null,h('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Dn(){var e,l,u,f;if(f=r,e=S(),e!==null){for(l=[],u=re(),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===95?(u="_",r++):(u=null,h('"_"'))));u!==null;)l.push(u),u=re(),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===95?(u="_",r++):(u=null,h('"_"'))));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,o.charCodeAt(r)===91?(e="[",r++):(e=null,h('"["')),e!==null?(l=Te(),l!==null?(o.charCodeAt(r)===93?(u="]",r++):(u=null,h('"]"')),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",o.substring(r,m)}(f)),e===null&&(r=f),e}function Te(){var e,l,u,f,p,m,v,y,O,le,xe,wt,Ps,L,b,Se;return L=r,b=r,e=ae(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?(o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?(o.charCodeAt(r)===58?(m=":",r++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?(o.charCodeAt(r)===58?(y=":",r++):(y=null,h('":"')),y!==null?(O=ae(),O!==null?(o.charCodeAt(r)===58?(le=":",r++):(le=null,h('":"')),le!==null?(xe=ae(),xe!==null?(o.charCodeAt(r)===58?(wt=":",r++):(wt=null,h('":"')),wt!==null?(Ps=at(),Ps!==null?e=[e,l,u,f,p,m,v,y,O,le,xe,wt,Ps]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?(o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?(o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?(o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=ae(),y!==null?(o.charCodeAt(r)===58?(O=":",r++):(O=null,h('":"')),O!==null?(le=ae(),le!==null?(o.charCodeAt(r)===58?(xe=":",r++):(xe=null,h('":"')),xe!==null?(wt=at(),wt!==null?e=[e,l,u,f,p,m,v,y,O,le,xe,wt]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?(o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?(o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?(o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=ae(),y!==null?(o.charCodeAt(r)===58?(O=":",r++):(O=null,h('":"')),O!==null?(le=at(),le!==null?e=[e,l,u,f,p,m,v,y,O,le]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?(o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?(o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?(o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=at(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?(o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?(o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=at(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?(o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=at(),f!==null?e=[e,l,u,f]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=at(),l!==null?e=[e,l]:(e=null,r=b)):(e=null,r=b),e===null&&(b=r,o.substr(r,2)==="::"?(e="::",r+=2):(e=null,h('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(o.substr(r,2)==="::"?(l="::",r+=2):(l=null,h('"::"')),l!==null?(u=ae(),u!==null?(o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?(o.charCodeAt(r)===58?(m=":",r++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?(o.charCodeAt(r)===58?(y=":",r++):(y=null,h('":"')),y!==null?(O=ae(),O!==null?(o.charCodeAt(r)===58?(le=":",r++):(le=null,h('":"')),le!==null?(xe=at(),xe!==null?e=[e,l,u,f,p,m,v,y,O,le,xe]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(o.substr(r,2)==="::"?(u="::",r+=2):(u=null,h('"::"')),u!==null?(f=ae(),f!==null?(o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?(o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=ae(),y!==null?(o.charCodeAt(r)===58?(O=":",r++):(O=null,h('":"')),O!==null?(le=at(),le!==null?e=[e,l,u,f,p,m,v,y,O,le]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(Se=r,o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Se)):(u=null,r=Se),u=u!==null?u:"",u!==null?(o.substr(r,2)==="::"?(f="::",r+=2):(f=null,h('"::"')),f!==null?(p=ae(),p!==null?(o.charCodeAt(r)===58?(m=":",r++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?(o.charCodeAt(r)===58?(y=":",r++):(y=null,h('":"')),y!==null?(O=at(),O!==null?e=[e,l,u,f,p,m,v,y,O]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(Se=r,o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Se)):(u=null,r=Se),u=u!==null?u:"",u!==null?(Se=r,o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Se)):(f=null,r=Se),f=f!==null?f:"",f!==null?(o.substr(r,2)==="::"?(p="::",r+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?(o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=at(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(Se=r,o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Se)):(u=null,r=Se),u=u!==null?u:"",u!==null?(Se=r,o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Se)):(f=null,r=Se),f=f!==null?f:"",f!==null?(Se=r,o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Se)):(p=null,r=Se),p=p!==null?p:"",p!==null?(o.substr(r,2)==="::"?(m="::",r+=2):(m=null,h('"::"')),m!==null?(v=at(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(Se=r,o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Se)):(u=null,r=Se),u=u!==null?u:"",u!==null?(Se=r,o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Se)):(f=null,r=Se),f=f!==null?f:"",f!==null?(Se=r,o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Se)):(p=null,r=Se),p=p!==null?p:"",p!==null?(Se=r,o.charCodeAt(r)===58?(m=":",r++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Se)):(m=null,r=Se),m=m!==null?m:"",m!==null?(o.substr(r,2)==="::"?(v="::",r+=2):(v=null,h('"::"')),v!==null?(y=ae(),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b),e===null&&(b=r,e=ae(),e!==null?(Se=r,o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Se)):(l=null,r=Se),l=l!==null?l:"",l!==null?(Se=r,o.charCodeAt(r)===58?(u=":",r++):(u=null,h('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Se)):(u=null,r=Se),u=u!==null?u:"",u!==null?(Se=r,o.charCodeAt(r)===58?(f=":",r++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Se)):(f=null,r=Se),f=f!==null?f:"",f!==null?(Se=r,o.charCodeAt(r)===58?(p=":",r++):(p=null,h('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Se)):(p=null,r=Se),p=p!==null?p:"",p!==null?(Se=r,o.charCodeAt(r)===58?(m=":",r++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Se)):(m=null,r=Se),m=m!==null?m:"",m!==null?(Se=r,o.charCodeAt(r)===58?(v=":",r++):(v=null,h('":"')),v!==null?(y=ae(),y!==null?v=[v,y]:(v=null,r=Se)):(v=null,r=Se),v=v!==null?v:"",v!==null?(o.substr(r,2)==="::"?(y="::",r+=2):(y=null,h('"::"')),y!==null?e=[e,l,u,f,p,m,v,y]:(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b)):(e=null,r=b))))))))))))))),e!==null&&(e=function($d){return w.host_type="IPv6",o.substring(r,$d)}(L)),e===null&&(r=L),e}function ae(){var e,l,u,f,p;return p=r,e=E(),e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?(f=E(),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 at(){var e,l,u,f;return f=r,e=ae(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),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,y,O;return y=r,O=r,e=As(),e!==null?(o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l!==null?(u=As(),u!==null?(o.charCodeAt(r)===46?(f=".",r++):(f=null,h('"."')),f!==null?(p=As(),p!==null?(o.charCodeAt(r)===46?(m=".",r++):(m=null,h('"."')),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(le){return w.host_type="IPv4",o.substring(r,le)}(y)),e===null&&(r=y),e}function As(){var e,l,u,f;return f=r,o.substr(r,2)==="25"?(e="25",r+=2):(e=null,h('"25"')),e!==null?(/^[0-5]/.test(o.charAt(r))?(l=o.charAt(r),r++):(l=null,h("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,o.charCodeAt(r)===50?(e="2",r++):(e=null,h('"2"')),e!==null?(/^[0-4]/.test(o.charAt(r))?(l=o.charAt(r),r++):(l=null,h("[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,o.charCodeAt(r)===49?(e="1",r++):(e=null,h('"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(o.charAt(r))?(e=o.charAt(r),r++):(e=null,h("[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 vr(){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(y,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Nn(){var e,l,u,f;for(e=[],f=r,o.charCodeAt(r)===59?(l=";",r++):(l=null,h('";"')),l!==null?(u=xn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,o.charCodeAt(r)===59?(l=";",r++):(l=null,h('";"')),l!==null?(u=xn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function xn(){var e;return e=Sr(),e===null&&(e=Er(),e===null&&(e=yr(),e===null&&(e=Cr(),e===null&&(e=Ar(),e===null&&(e=Rr(),e===null&&(e=br())))))),e}function Sr(){var e,l,u,f;return u=r,f=r,o.substr(r,10).toLowerCase()==="transport="?(e=o.substr(r,10),r+=10):(e=null,h('"transport="')),e!==null?(o.substr(r,3).toLowerCase()==="udp"?(l=o.substr(r,3),r+=3):(l=null,h('"udp"')),l===null&&(o.substr(r,3).toLowerCase()==="tcp"?(l=o.substr(r,3),r+=3):(l=null,h('"tcp"')),l===null&&(o.substr(r,4).toLowerCase()==="sctp"?(l=o.substr(r,4),r+=4):(l=null,h('"sctp"')),l===null&&(o.substr(r,3).toLowerCase()==="tls"?(l=o.substr(r,3),r+=3):(l=null,h('"tls"')),l===null&&(l=U())))),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 Er(){var e,l,u,f;return u=r,f=r,o.substr(r,5).toLowerCase()==="user="?(e=o.substr(r,5),r+=5):(e=null,h('"user="')),e!==null?(o.substr(r,5).toLowerCase()==="phone"?(l=o.substr(r,5),r+=5):(l=null,h('"phone"')),l===null&&(o.substr(r,2).toLowerCase()==="ip"?(l=o.substr(r,2),r+=2):(l=null,h('"ip"')),l===null&&(l=U())),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 yr(){var e,l,u,f;return u=r,f=r,o.substr(r,7).toLowerCase()==="method="?(e=o.substr(r,7),r+=7):(e=null,h('"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,o.substr(r,4).toLowerCase()==="ttl="?(e=o.substr(r,4),r+=4):(e=null,h('"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 Ar(){var e,l,u,f;return u=r,f=r,o.substr(r,6).toLowerCase()==="maddr="?(e=o.substr(r,6),r+=6):(e=null,h('"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 Rr(){var e,l,u,f,p,m;return f=r,p=r,o.substr(r,2).toLowerCase()==="lr"?(e=o.substr(r,2),r+=2):(e=null,h('"lr"')),e!==null?(m=r,o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l!==null?(u=U(),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=Ir(),e!==null?(m=r,o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),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,y,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[y.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function Ir(){var e,l,u;if(u=r,l=bs(),l!==null)for(e=[];l!==null;)e.push(l),l=bs();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=bs(),l!==null)for(e=[];l!==null;)e.push(l),l=bs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function bs(){var e;return e=wr(),e===null&&(e=F(),e===null&&(e=pe())),e}function wr(){var e;return o.charCodeAt(r)===91?(e="[",r++):(e=null,h('"["')),e===null&&(o.charCodeAt(r)===93?(e="]",r++):(e=null,h('"]"')),e===null&&(o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"')),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===38?(e="&",r++):(e=null,h('"&"')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')))))))),e}function Xs(){var e,l,u,f,p,m,v;if(m=r,o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e!==null)if(l=Qs(),l!==null){for(u=[],v=r,o.charCodeAt(r)===38?(f="&",r++):(f=null,h('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,o.charCodeAt(r)===38?(f="&",r++):(f=null,h('"&"')),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=Or(),e!==null?(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l!==null?(u=Is(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,y){v=v.join("").toLowerCase(),y=y.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(y):w.uri_headers[v]=[y]}(f,e[0],e[2])),e===null&&(r=f),e}function Or(){var e,l;if(l=Zs(),l===null&&(l=F(),l===null&&(l=pe())),l!==null)for(e=[];l!==null;)e.push(l),l=Zs(),l===null&&(l=F(),l===null&&(l=pe()));else e=null;return e}function Is(){var e,l;for(e=[],l=Zs(),l===null&&(l=F(),l===null&&(l=pe()));l!==null;)e.push(l),l=Zs(),l===null&&(l=F(),l===null&&(l=pe()));return e}function Zs(){var e;return o.charCodeAt(r)===91?(e="[",r++):(e=null,h('"["')),e===null&&(o.charCodeAt(r)===93?(e="]",r++):(e=null,h('"]"')),e===null&&(o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"')),e===null&&(o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')))))))),e}function ml(){var e;return e=Gr(),e===null&&(e=Dr()),e}function Dr(){var e,l,u,f,p,m;return m=r,e=rn(),e!==null?(l=$(),l!==null?(u=Un(),u!==null?(f=$(),f!==null?(p=Mn(),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 Un(){var e;return e=Ne(),e===null&&(e=kn()),e}function kn(){var e,l,u,f;return f=r,e=Ur(),e!==null?(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l!==null?(u=Nr(),u===null&&(u=ws()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Nr(){var e,l,u,f,p;return f=r,e=en(),e===null&&(e=tn()),e!==null?(p=r,o.charCodeAt(r)===63?(l="?",r++):(l=null,h('"?"')),l!==null?(u=Pn(),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,o.substr(r,2)==="//"?(e="//",r+=2):(e=null,h('"//"')),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,o.charCodeAt(r)===47?(e="/",r++):(e=null,h('"/"')),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=xr(),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=x(),e===null&&(e=F(),e===null&&(e=pe())),e}function xr(){var e;return e=F(),e===null&&(e=pe(),e===null&&(o.charCodeAt(r)===59?(e=";",r++):(e=null,h('";"')),e===null&&(o.charCodeAt(r)===63?(e="?",r++):(e=null,h('"?"')),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===64?(e="@",r++):(e=null,h('"@"')),e===null&&(o.charCodeAt(r)===38?(e="&",r++):(e=null,h('"&"')),e===null&&(o.charCodeAt(r)===61?(e="=",r++):(e=null,h('"="')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')),e===null&&(o.charCodeAt(r)===44?(e=",",r++):(e=null,h('","')))))))))))),e}function sn(){var e,l,u,f,p,m;if(p=r,e=Ds(),e!==null){for(l=[],m=r,o.charCodeAt(r)===47?(u="/",r++):(u=null,h('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,o.charCodeAt(r)===47?(u="/",r++):(u=null,h('"/"')),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,o.charCodeAt(r)===59?(u=";",r++):(u=null,h('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,o.charCodeAt(r)===59?(u=";",r++):(u=null,h('";"')),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=F(),e===null&&(e=pe(),e===null&&(o.charCodeAt(r)===58?(e=":",r++):(e=null,h('":"')),e===null&&(o.charCodeAt(r)===64?(e="@",r++):(e=null,h('"@"')),e===null&&(o.charCodeAt(r)===38?(e="&",r++):(e=null,h('"&"')),e===null&&(o.charCodeAt(r)===61?(e="=",r++):(e=null,h('"="')),e===null&&(o.charCodeAt(r)===43?(e="+",r++):(e=null,h('"+"')),e===null&&(o.charCodeAt(r)===36?(e="$",r++):(e=null,h('"$"')),e===null&&(o.charCodeAt(r)===44?(e=",",r++):(e=null,h('","')))))))))),e}function Ur(){var e,l,u,f,p;if(f=r,p=r,e=S(),e!==null){for(l=[],u=S(),u===null&&(u=T(),u===null&&(o.charCodeAt(r)===43?(u="+",r++):(u=null,h('"+"')),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."'))))));u!==null;)l.push(u),u=S(),u===null&&(u=T(),u===null&&(o.charCodeAt(r)===43?(u="+",r++):(u=null,h('"+"')),u===null&&(o.charCodeAt(r)===45?(u="-",r++):(u=null,h('"-"')),u===null&&(o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=o.substring(r,m)}(f)),e===null&&(r=f),e}function kr(){var e;return e=Pr(),e===null&&(e=Mr()),e}function Pr(){var e,l,u,f;return u=r,f=r,e=ht(),e!==null?(o.charCodeAt(r)===64?(l="@",r++):(l=null,h('"@"')),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 Mr(){var e,l;if(l=F(),l===null&&(l=pe(),l===null&&(o.charCodeAt(r)===36?(l="$",r++):(l=null,h('"$"')),l===null&&(o.charCodeAt(r)===44?(l=",",r++):(l=null,h('","')),l===null&&(o.charCodeAt(r)===59?(l=";",r++):(l=null,h('";"')),l===null&&(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l===null&&(o.charCodeAt(r)===64?(l="@",r++):(l=null,h('"@"')),l===null&&(o.charCodeAt(r)===38?(l="&",r++):(l=null,h('"&"')),l===null&&(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=F(),l===null&&(l=pe(),l===null&&(o.charCodeAt(r)===36?(l="$",r++):(l=null,h('"$"')),l===null&&(o.charCodeAt(r)===44?(l=",",r++):(l=null,h('","')),l===null&&(o.charCodeAt(r)===59?(l=";",r++):(l=null,h('";"')),l===null&&(o.charCodeAt(r)===58?(l=":",r++):(l=null,h('":"')),l===null&&(o.charCodeAt(r)===64?(l="@",r++):(l=null,h('"@"')),l===null&&(o.charCodeAt(r)===38?(l="&",r++):(l=null,h('"&"')),l===null&&(o.charCodeAt(r)===61?(l="=",r++):(l=null,h('"="')),l===null&&(o.charCodeAt(r)===43?(l="+",r++):(l=null,h('"+"')))))))))));else e=null;return e}function Pn(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Mn(){var e,l,u,f,p,m,v,y;if(v=r,y=r,o.substr(r,3).toLowerCase()==="sip"?(e=o.substr(r,3),r+=3):(e=null,h('"SIP"')),e!==null)if(o.charCodeAt(r)===47?(l="/",r++):(l=null,h('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(o.charCodeAt(r)===46?(f=".",r++):(f=null,h('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=y)}else e=null,r=y;else e=null,r=y}else e=null,r=y;else e=null,r=y;return e!==null&&(e=function(O){w.sip_version=o.substring(r,O)}(v)),e===null&&(r=v),e}function Lr(){var e;return o.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,h('"INVITE"')),e}function $r(){var e;return o.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,h('"ACK"')),e}function Hr(){var e;return o.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,h('"OPTIONS"')),e}function Fr(){var e;return o.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,h('"BYE"')),e}function Vr(){var e;return o.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,h('"CANCEL"')),e}function jr(){var e;return o.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,h('"REGISTER"')),e}function qr(){var e;return o.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,h('"SUBSCRIBE"')),e}function Br(){var e;return o.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,h('"NOTIFY"')),e}function nn(){var e;return o.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,h('"REFER"')),e}function rn(){var e,l;return l=r,e=Lr(),e===null&&(e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=Vr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=Br(),e===null&&(e=nn(),e===null&&(e=U()))))))))),e!==null&&(e=function(u){return w.method=o.substring(r,u),w.method}(l)),e===null&&(r=l),e}function Gr(){var e,l,u,f,p,m;return m=r,e=Mn(),e!==null?(l=$(),l!==null?(u=Wr(),u!==null?(f=$(),f!==null?(p=gl(),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 Wr(){var e,l;return l=r,e=Kr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Kr(){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 gl(){var e,l,u;for(u=r,e=[],l=x(),l===null&&(l=F(),l===null&&(l=pe(),l===null&&(l=V(),l===null&&(l=z(),l===null&&(l=$(),l===null&&(l=k()))))));l!==null;)e.push(l),l=x(),l===null&&(l=F(),l===null&&(l=pe(),l===null&&(l=V(),l===null&&(l=z(),l===null&&(l=$(),l===null&&(l=k()))))));return e!==null&&(e=function(f){w.reason_phrase=o.substring(r,f)}(u)),e===null&&(r=u),e}function zo(){var e,l,u,f,p,m;if(p=r,e=un(),e!==null){for(l=[],m=r,u=oe(),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=oe(),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 Xo(){var e,l,u,f,p,m;return f=r,p=r,e=Q(),e!==null?(m=r,o.charCodeAt(r)===64?(l="@",r++):(l=null,h('"@"')),l!==null?(u=Q(),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=o.substring(r,v)}(f)),e===null&&(r=f),e}function Ln(){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=oe(),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=oe(),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(y){var O,le;for(le=w.multi_header.length,O=0;O<le;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=$n(),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=$n(),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(y){var O;w.multi_header||(w.multi_header=[]);try{O=new I(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:y,parsed:O})}(p)),e===null&&(r=p),e}function Ht(){var e,l,u,f,p;return p=r,e=xs(),e=e!==null?e:"",e!==null?(l=Ae(),l!==null?(u=Ne(),u!==null?(f=ke(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function xs(){var e,l,u,f,p,m,v;if(p=r,m=r,e=U(),e!==null){for(l=[],v=r,u=P(),u!==null?(f=U(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=P(),u!==null?(f=U(),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=ge()),e!==null&&(e=function(y,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(le,xe){return le+xe[0]+xe[1]},O[0])}(p,e)),e===null&&(r=p),e}function $n(){var e;return e=Yr(),e===null&&(e=ts(),e===null&&(e=Ke())),e}function Yr(){var e,l,u,f,p;return f=r,p=r,o.substr(r,1).toLowerCase()==="q"?(e=o.substr(r,1),r++):(e=null,h('"q"')),e!==null?(l=ie(),l!==null?(u=We(),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,o.substr(r,7).toLowerCase()==="expires"?(e=o.substr(r,7),r+=7):(e=null,h('"expires"')),e!==null?(l=ie(),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 We(){var e,l,u,f,p,m,v,y;return m=r,v=r,o.charCodeAt(r)===48?(e="0",r++):(e=null,h('"0"')),e!==null?(y=r,o.charCodeAt(r)===46?(l=".",r++):(l=null,h('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=y)):(l=null,r=y)):(l=null,r=y)):(l=null,r=y),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(o.substring(r,O))}(m)),e===null&&(r=m),e}function Ke(){var e,l,u,f,p,m;return f=r,p=r,e=U(),e!==null?(m=r,l=ie(),l!==null?(u=Tl(),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,y,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[y.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function Tl(){var e;return e=U(),e===null&&(e=us(),e===null&&(e=Oe())),e}function vl(){var e,l,u,f,p,m;if(p=r,e=Hn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Fn(),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=Fn(),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 Hn(){var e;return o.substr(r,6).toLowerCase()==="render"?(e=o.substr(r,6),r+=6):(e=null,h('"render"')),e===null&&(o.substr(r,7).toLowerCase()==="session"?(e=o.substr(r,7),r+=7):(e=null,h('"session"')),e===null&&(o.substr(r,4).toLowerCase()==="icon"?(e=o.substr(r,4),r+=4):(e=null,h('"icon"')),e===null&&(o.substr(r,5).toLowerCase()==="alert"?(e=o.substr(r,5),r+=5):(e=null,h('"alert"')),e===null&&(e=U())))),e}function Fn(){var e;return e=Sl(),e===null&&(e=Ke()),e}function Sl(){var e,l,u,f;return f=r,o.substr(r,8).toLowerCase()==="handling"?(e=o.substr(r,8),r+=8):(e=null,h('"handling"')),e!==null?(l=ie(),l!==null?(o.substr(r,8).toLowerCase()==="optional"?(u=o.substr(r,8),r+=8):(u=null,h('"optional"')),u===null&&(o.substr(r,8).toLowerCase()==="required"?(u=o.substr(r,8),r+=8):(u=null,h('"required"')),u===null&&(u=U())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Qo(){var e,l,u,f,p,m;if(p=r,e=U(),e!==null){for(l=[],m=r,u=oe(),u!==null?(f=U(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=oe(),u!==null?(f=U(),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 Zo(){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 El(){var e,l;return l=r,e=Jr(),e!==null&&(e=function(u){w=o.substring(r,u)}(l)),e===null&&(r=l),e}function Jr(){var e,l,u,f,p,m,v,y;if(v=r,e=zr(),e!==null)if(l=B(),l!==null)if(u=Vn(),u!==null){for(f=[],y=r,p=ye(),p!==null?(m=jn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ye(),p!==null?(m=jn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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 zr(){var e;return e=Xr(),e===null&&(e=ln()),e}function Xr(){var e;return o.substr(r,4).toLowerCase()==="text"?(e=o.substr(r,4),r+=4):(e=null,h('"text"')),e===null&&(o.substr(r,5).toLowerCase()==="image"?(e=o.substr(r,5),r+=5):(e=null,h('"image"')),e===null&&(o.substr(r,5).toLowerCase()==="audio"?(e=o.substr(r,5),r+=5):(e=null,h('"audio"')),e===null&&(o.substr(r,5).toLowerCase()==="video"?(e=o.substr(r,5),r+=5):(e=null,h('"video"')),e===null&&(o.substr(r,11).toLowerCase()==="application"?(e=o.substr(r,11),r+=11):(e=null,h('"application"')),e===null&&(e=on()))))),e}function ln(){var e;return o.substr(r,7).toLowerCase()==="message"?(e=o.substr(r,7),r+=7):(e=null,h('"message"')),e===null&&(o.substr(r,9).toLowerCase()==="multipart"?(e=o.substr(r,9),r+=9):(e=null,h('"multipart"')),e===null&&(e=on())),e}function on(){var e;return e=U(),e===null&&(e=Qr()),e}function Qr(){var e,l,u;return u=r,o.substr(r,2).toLowerCase()==="x-"?(e=o.substr(r,2),r+=2):(e=null,h('"x-"')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Vn(){var e;return e=on(),e===null&&(e=U()),e}function jn(){var e,l,u,f;return f=r,e=U(),e!==null?(l=ie(),l!==null?(u=yl(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function yl(){var e;return e=U(),e===null&&(e=Oe()),e}function Cl(){var e,l,u,f;return f=r,e=Al(),e!==null?(l=P(),l!==null?(u=rn(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Al(){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 ea(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function an(){var e,l,u,f,p,m,v;if(p=r,m=r,e=un(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Ke(),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=Ke(),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(y,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=X(),e!==null){for(l=[],m=r,o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."')),u!==null?(f=X(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,o.charCodeAt(r)===46?(u=".",r++):(u=null,h('"."')),u!==null?(f=X(),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 Zr(){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(y){var O=w.tag;try{w=new I(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=ei(),e===null&&(e=Ke()),e}function ei(){var e,l,u,f,p;return f=r,p=r,o.substr(r,3).toLowerCase()==="tag"?(e=o.substr(r,3),r+=3):(e=null,h('"tag"')),e!==null?(l=ie(),l!==null?(u=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){w.tag=v}(f,e[2])),e===null&&(r=f),e}function ta(){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 sa(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function na(){var e,l,u,f,p,m,v,y,O,le;for(y=r,O=r,e=[],l=xs();l!==null;)e.push(l),l=xs();if(e!==null)if(l=Ae(),l!==null)if(u=Ne(),u!==null)if(f=ke(),f!==null){for(p=[],le=r,m=ye(),m!==null?(v=Ke(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);m!==null;)p.push(m),le=r,m=ye(),m!==null?(v=Ke(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);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(xe){try{w=new I(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=y),e}function ti(){var e;return e=qn(),e}function qn(){var e,l,u,f,p,m,v,y;if(v=r,o.substr(r,6).toLowerCase()==="digest"?(e=o.substr(r,6),r+=6):(e=null,h('"Digest"')),e!==null)if(l=P(),l!==null)if(u=fn(),u!==null){for(f=[],y=r,p=oe(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=oe(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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=Us()),e}function Us(){var e,l,u,f,p,m,v,y;if(v=r,e=U(),e!==null)if(l=P(),l!==null)if(u=ns(),u!==null){for(f=[],y=r,p=oe(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=oe(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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=U(),e!==null?(l=ie(),l!==null?(u=U(),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=si(),e===null&&(e=dn(),e===null&&(e=ri(),e===null&&(e=li(),e===null&&(e=oi(),e===null&&(e=ai(),e===null&&(e=_n(),e===null&&(e=ns()))))))),e}function si(){var e,l,u,f;return f=r,o.substr(r,5).toLowerCase()==="realm"?(e=o.substr(r,5),r+=5):(e=null,h('"realm"')),e!==null?(l=ie(),l!==null?(u=ni(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ni(){var e,l;return l=r,e=ge(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function dn(){var e,l,u,f,p,m,v,y,O;if(y=r,o.substr(r,6).toLowerCase()==="domain"?(e=o.substr(r,6),r+=6):(e=null,h('"domain"')),e!==null)if(l=ie(),l!==null)if(u=ot(),u!==null)if(f=hn(),f!==null){if(p=[],O=r,v=$(),v!==null)for(m=[];v!==null;)m.push(v),v=$();else m=null;for(m!==null?(v=hn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=$(),v!==null)for(m=[];v!==null;)m.push(v),v=$();else m=null;m!==null?(v=hn(),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=y)):(e=null,r=y)}else e=null,r=y;else e=null,r=y;else e=null,r=y;else e=null,r=y;return e}function hn(){var e;return e=kn(),e===null&&(e=tn()),e}function ri(){var e,l,u,f;return f=r,o.substr(r,5).toLowerCase()==="nonce"?(e=o.substr(r,5),r+=5):(e=null,h('"nonce"')),e!==null?(l=ie(),l!==null?(u=ii(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ii(){var e,l;return l=r,e=ge(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function li(){var e,l,u,f,p;return f=r,p=r,o.substr(r,6).toLowerCase()==="opaque"?(e=o.substr(r,6),r+=6):(e=null,h('"opaque"')),e!==null?(l=ie(),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.opaque=v}(f,e[2])),e===null&&(r=f),e}function oi(){var e,l,u,f,p;return f=r,o.substr(r,5).toLowerCase()==="stale"?(e=o.substr(r,5),r+=5):(e=null,h('"stale"')),e!==null?(l=ie(),l!==null?(p=r,o.substr(r,4).toLowerCase()==="true"?(u=o.substr(r,4),r+=4):(u=null,h('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,o.substr(r,5).toLowerCase()==="false"?(u=o.substr(r,5),r+=5):(u=null,h('"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 ai(){var e,l,u,f,p;return f=r,p=r,o.substr(r,9).toLowerCase()==="algorithm"?(e=o.substr(r,9),r+=9):(e=null,h('"algorithm"')),e!==null?(l=ie(),l!==null?(o.substr(r,3).toLowerCase()==="md5"?(u=o.substr(r,3),r+=3):(u=null,h('"MD5"')),u===null&&(o.substr(r,8).toLowerCase()==="md5-sess"?(u=o.substr(r,8),r+=8):(u=null,h('"MD5-sess"')),u===null&&(u=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){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function _n(){var e,l,u,f,p,m,v,y,O,le;if(y=r,o.substr(r,3).toLowerCase()==="qop"?(e=o.substr(r,3),r+=3):(e=null,h('"qop"')),e!==null)if(l=ie(),l!==null)if(u=ot(),u!==null){if(O=r,f=Bn(),f!==null){for(p=[],le=r,o.charCodeAt(r)===44?(m=",",r++):(m=null,h('","')),m!==null?(v=Bn(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);m!==null;)p.push(m),le=r,o.charCodeAt(r)===44?(m=",",r++):(m=null,h('","')),m!==null?(v=Bn(),v!==null?m=[m,v]:(m=null,r=le)):(m=null,r=le);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=y)):(e=null,r=y)}else e=null,r=y;else e=null,r=y;else e=null,r=y;return e}function Bn(){var e,l;return l=r,o.substr(r,8).toLowerCase()==="auth-int"?(e=o.substr(r,8),r+=8):(e=null,h('"auth-int"')),e===null&&(o.substr(r,4).toLowerCase()==="auth"?(e=o.substr(r,4),r+=4):(e=null,h('"auth"')),e===null&&(e=U())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function ra(){var e,l,u,f,p,m;if(p=r,e=U(),e!==null){for(l=[],m=r,u=oe(),u!==null?(f=U(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=oe(),u!==null?(f=U(),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 Gn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Wn(),e!==null){for(l=[],v=r,u=oe(),u!==null?(f=Wn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=oe(),u!==null?(f=Wn(),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(y){var O,le;for(le=w.multi_header.length,O=0;O<le;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 Wn(){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=Ke(),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=Ke(),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(y){var O;w.multi_header||(w.multi_header=[]);try{O=new I(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:y,parsed:O})}(p)),e===null&&(r=p),e}function ui(){var e,l,u,f,p,m,v;if(p=r,m=r,o.substr(r,3).toLowerCase()==="sip"?(e=o.substr(r,3),r+=3):(e=null,h('"SIP"')),e===null&&(e=U()),e!==null){for(l=[],v=r,u=ye(),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=ye(),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(y,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var le=w.params.text;w.text=le.substring(1,le.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function Kn(){var e;return e=Rl(),e===null&&(e=Ke()),e}function Rl(){var e,l,u,f,p,m;if(p=r,m=r,o.substr(r,5).toLowerCase()==="cause"?(e=o.substr(r,5),r+=5):(e=null,h('"cause"')),e!==null)if(l=ie(),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,y){w.cause=parseInt(y.join(""))}(p,e[2])),e===null&&(r=p),e}function ia(){var e,l,u,f,p,m;if(p=r,e=U(),e!==null){for(l=[],m=r,u=oe(),u!==null?(f=U(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=oe(),u!==null?(f=U(),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 Yn(){var e,l,u,f,p,m;if(p=r,e=Jn(),e!==null){for(l=[],m=r,u=oe(),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=oe(),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 Jn(){var e,l,u,f,p,m;if(p=r,e=Ht(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Ke(),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=Ke(),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=zn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Xn(),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=Xn(),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;return l=r,o.substr(r,6).toLowerCase()==="active"?(e=o.substr(r,6),r+=6):(e=null,h('"active"')),e===null&&(o.substr(r,7).toLowerCase()==="pending"?(e=o.substr(r,7),r+=7):(e=null,h('"pending"')),e===null&&(o.substr(r,10).toLowerCase()==="terminated"?(e=o.substr(r,10),r+=10):(e=null,h('"terminated"')),e===null&&(e=U()))),e!==null&&(e=function(u){w.state=o.substring(r,u)}(l)),e===null&&(r=l),e}function Xn(){var e,l,u,f,p;return f=r,p=r,o.substr(r,6).toLowerCase()==="reason"?(e=o.substr(r,6),r+=6):(e=null,h('"reason"')),e!==null?(l=ie(),l!==null?(u=Il(),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,o.substr(r,7).toLowerCase()==="expires"?(e=o.substr(r,7),r+=7):(e=null,h('"expires"')),e!==null?(l=ie(),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,o.substr(r,11).toLowerCase()==="retry_after"?(e=o.substr(r,11),r+=11):(e=null,h('"retry_after"')),e!==null?(l=ie(),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=Ke()))),e}function Il(){var e;return o.substr(r,11).toLowerCase()==="deactivated"?(e=o.substr(r,11),r+=11):(e=null,h('"deactivated"')),e===null&&(o.substr(r,9).toLowerCase()==="probation"?(e=o.substr(r,9),r+=9):(e=null,h('"probation"')),e===null&&(o.substr(r,8).toLowerCase()==="rejected"?(e=o.substr(r,8),r+=8):(e=null,h('"rejected"')),e===null&&(o.substr(r,7).toLowerCase()==="timeout"?(e=o.substr(r,7),r+=7):(e=null,h('"timeout"')),e===null&&(o.substr(r,6).toLowerCase()==="giveup"?(e=o.substr(r,6),r+=6):(e=null,h('"giveup"')),e===null&&(o.substr(r,10).toLowerCase()==="noresource"?(e=o.substr(r,10),r+=10):(e=null,h('"noresource"')),e===null&&(o.substr(r,9).toLowerCase()==="invariant"?(e=o.substr(r,9),r+=9):(e=null,h('"invariant"')),e===null&&(e=U()))))))),e}function la(){var e;return e=j(),e=e!==null?e:"",e}function oa(){var e,l,u,f,p,m;if(p=r,e=U(),e!==null){for(l=[],m=r,u=oe(),u!==null?(f=U(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=oe(),u!==null?(f=U(),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 ci(){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=fi(),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=fi(),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(y){var O=w.tag;try{w=new I(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function fi(){var e;return e=ei(),e===null&&(e=Ke()),e}function Qn(){var e,l,u,f,p,m;if(p=r,e=ks(),e!==null){for(l=[],m=r,u=oe(),u!==null?(f=ks(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=oe(),u!==null?(f=ks(),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 ks(){var e,l,u,f,p,m,v,y;if(v=r,e=Ti(),e!==null)if(l=P(),l!==null)if(u=Ei(),u!==null){for(f=[],y=r,p=ye(),p!==null?(m=Zn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);p!==null;)f.push(p),y=r,p=ye(),p!==null?(m=Zn(),m!==null?p=[p,m]:(p=null,r=y)):(p=null,r=y);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 Zn(){var e;return e=di(),e===null&&(e=hi(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi(),e===null&&(e=Ke()))))),e}function di(){var e,l,u,f,p;return f=r,p=r,o.substr(r,3).toLowerCase()==="ttl"?(e=o.substr(r,3),r+=3):(e=null,h('"ttl"')),e!==null?(l=ie(),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 hi(){var e,l,u,f,p;return f=r,p=r,o.substr(r,5).toLowerCase()==="maddr"?(e=o.substr(r,5),r+=5):(e=null,h('"maddr"')),e!==null?(l=ie(),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 _i(){var e,l,u,f,p;return f=r,p=r,o.substr(r,8).toLowerCase()==="received"?(e=o.substr(r,8),r+=8):(e=null,h('"received"')),e!==null?(l=ie(),l!==null?(u=Wt(),u===null&&(u=Te()),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 pi(){var e,l,u,f,p;return f=r,p=r,o.substr(r,6).toLowerCase()==="branch"?(e=o.substr(r,6),r+=6):(e=null,h('"branch"')),e!==null?(l=ie(),l!==null?(u=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){w.branch=v}(f,e[2])),e===null&&(r=f),e}function mi(){var e,l,u,f,p;return f=r,o.substr(r,5).toLowerCase()==="rport"?(e=o.substr(r,5),r+=5):(e=null,h('"rport"')),e!==null?(p=r,l=ie(),l!==null?(u=gi(),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 gi(){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(y,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function Ti(){var e,l,u,f,p,m;return m=r,e=vi(),e!==null?(l=B(),l!==null?(u=U(),u!==null?(f=B(),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 vi(){var e,l;return l=r,o.substr(r,3).toLowerCase()==="sip"?(e=o.substr(r,3),r+=3):(e=null,h('"SIP"')),e===null&&(e=U()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function Si(){var e,l;return l=r,o.substr(r,3).toLowerCase()==="udp"?(e=o.substr(r,3),r+=3):(e=null,h('"UDP"')),e===null&&(o.substr(r,3).toLowerCase()==="tcp"?(e=o.substr(r,3),r+=3):(e=null,h('"TCP"')),e===null&&(o.substr(r,3).toLowerCase()==="tls"?(e=o.substr(r,3),r+=3):(e=null,h('"TLS"')),e===null&&(o.substr(r,4).toLowerCase()==="sctp"?(e=o.substr(r,4),r+=4):(e=null,h('"SCTP"')),e===null&&(e=U())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function Ei(){var e,l,u,f,p;return f=r,e=yi(),e!==null?(p=r,l=nt(),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 yi(){var e,l;return l=r,e=Wt(),e===null&&(e=zs(),e===null&&(e=Js())),e!==null&&(e=function(u){w.host=o.substring(r,u)}(l)),e===null&&(r=l),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(y,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 aa(){var e;return e=qn(),e}function wl(){var e,l,u,f,p,m;if(p=r,e=tr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function tr(){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 sr(){var e;return e=Ol(),e===null&&(e=Ke()),e}function Ol(){var e,l,u,f,p;return f=r,p=r,o.substr(r,9).toLowerCase()==="refresher"?(e=o.substr(r,9),r+=9):(e=null,h('"refresher"')),e!==null?(l=ie(),l!==null?(o.substr(r,3).toLowerCase()==="uac"?(u=o.substr(r,3),r+=3):(u=null,h('"uac"')),u===null&&(o.substr(r,3).toLowerCase()==="uas"?(u=o.substr(r,3),r+=3):(u=null,h('"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 Dl(){var e,l,u,f;return f=r,e=U(),e!==null?(l=q(),l!==null?(u=Nl(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Nl(){var e,l;for(e=[],l=K(),l===null&&(l=z(),l===null&&(l=P()));l!==null;)e.push(l),l=K(),l===null&&(l=z(),l===null&&(l=P()));return e}function ua(){var e,l;for(e=[],l=R();l!==null;)e.push(l),l=R();return e}function xl(){var e,l,u;return u=r,o.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,h('"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,y,O,le,xe;return le=r,xe=r,e=Ai(),e!==null?(o.charCodeAt(r)===45?(l="-",r++):(l=null,h('"-"')),l!==null?(u=Vt(),u!==null?(o.charCodeAt(r)===45?(f="-",r++):(f=null,h('"-"')),f!==null?(p=Vt(),p!==null?(o.charCodeAt(r)===45?(m="-",r++):(m=null,h('"-"')),m!==null?(v=Vt(),v!==null?(o.charCodeAt(r)===45?(y="-",r++):(y=null,h('"-"')),y!==null?(O=Ul(),O!==null?e=[e,l,u,f,p,m,v,y,O]:(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe)):(e=null,r=xe),e!==null&&(e=function(wt,Ps){w=o.substring(r+5,wt)}(le,e[0])),e===null&&(r=le),e}function Vt(){var e,l,u,f,p;return p=r,e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?(f=E(),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 Ai(){var e,l,u;return u=r,e=Vt(),e!==null?(l=Vt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ul(){var e,l,u,f;return f=r,e=Vt(),e!==null?(l=Vt(),l!==null?(u=Vt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ca(){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=Ke(),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=Ke(),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(y){try{w=new I(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=nr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=rr(),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=rr(),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 nr(){var e,l,u,f,p,m;return f=r,p=r,e=Q(),e!==null?(m=r,o.charCodeAt(r)===64?(l="@",r++):(l=null,h('"@"')),l!==null?(u=Q(),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=o.substring(r,v)}(f)),e===null&&(r=f),e}function rr(){var e;return e=Ri(),e===null&&(e=bi(),e===null&&(e=Pl(),e===null&&(e=Ke()))),e}function Ri(){var e,l,u,f,p;return f=r,p=r,o.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,h('"to-tag"')),e!==null?(l=ie(),l!==null?(u=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){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,o.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,h('"from-tag"')),e!==null?(l=ie(),l!==null?(u=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){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Pl(){var e,l;return l=r,o.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,h('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function fa(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 Ml(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,_);f++){var p=o.charAt(f);p===`
|
|
4
|
+
`?(u||e++,l=1,u=!1):p==="\r"||p==="\u2028"||p==="\u2029"?(e++,l=1,u=!0):(l++,u=!1)}return{line:e,column:l}}var fs=Ks(),I=Du(),w={},Ii=s[a]();if(Ii===null||r!==o.length){var wi=Math.max(r,_),Ll=wi<o.length?o.charAt(wi):null,i=Ml();return new this.SyntaxError(fa(d),Ll,wi,i.line,i.column),-1}return w},toSource:function(){return this._source}};return t.SyntaxError=function(n,o,a,s,r){function _(d,h){var g,T;switch(d.length){case 0:g="end of input";break;case 1:g=d[0];break;default:g=d.slice(0,d.length-1).join(", ")+" or "+d[d.length-1]}return T=h?c(h):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=o,this.message=_(n,o),this.offset=a,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),ha}var _a,Ju;function Ks(){if(Ju)return _a;Ju=1;function c(h,g){var T;if(typeof Symbol>"u"||h[Symbol.iterator]==null){if(Array.isArray(h)||(T=t(h))||g&&h&&typeof h.length=="number"){T&&(h=T);var S=0,E=function(){};return{s:E,n:function(){return S>=h.length?{done:!0}:{done:!1,value:h[S++]}},e:function(k){throw k},f:E}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,R=!1,C;return{s:function(){T=h[Symbol.iterator]()},n:function(){var k=T.next();return A=k.done,k},e:function(k){R=!0,C=k},f:function(){try{!A&&T.return!=null&&T.return()}finally{if(R)throw C}}}}function t(h,g){if(h){if(typeof h=="string")return n(h,g);var T=Object.prototype.toString.call(h).slice(8,-1);if(T==="Object"&&h.constructor&&(T=h.constructor.name),T==="Map"||T==="Set")return Array.from(h);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return n(h,g)}}function n(h,g){(g==null||g>h.length)&&(g=h.length);for(var T=0,S=new Array(g);T<g;T++)S[T]=h[T];return S}function o(h,g){if(!(h instanceof g))throw new TypeError("Cannot call a class as a function")}function a(h,g){for(var T=0;T<g.length;T++){var S=g[T];S.enumerable=S.enumerable||!1,S.configurable=!0,"value"in S&&(S.writable=!0),Object.defineProperty(h,S.key,S)}}function s(h,g,T){return g&&a(h.prototype,g),T&&a(h,T),h}var r=lt,_=It(),d=as();return _a=function(){s(h,null,[{key:"parse",value:function(T){if(T=d.parse(T,"SIP_URI"),T!==-1)return T}}]);function h(g,T,S,E){var A=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},R=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(o(this,h),!S)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=g||r.SIP,this._user=T,this._host=S,this._port=E;for(var C in A)Object.prototype.hasOwnProperty.call(A,C)&&this.setParam(C,A[C]);for(var $ in R)Object.prototype.hasOwnProperty.call(R,$)&&this.setHeader($,R[$])}return s(h,[{key:"setParam",value:function(T,S){T&&(this._parameters[T.toLowerCase()]=typeof S>"u"||S===null?null:S.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 S=this._parameters[T];return delete this._parameters[T],S}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(T,S){this._headers[_.headerize(T)]=Array.isArray(S)?S:[S]}},{key:"getHeader",value:function(T){if(T)return this._headers[_.headerize(T)]}},{key:"hasHeader",value:function(T){if(T)return this._headers.hasOwnProperty(_.headerize(T))&&!0||!1}},{key:"deleteHeader",value:function(T){if(T=_.headerize(T),this._headers.hasOwnProperty(T)){var S=this._headers[T];return delete this._headers[T],S}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new h(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var T=[],S="".concat(this._scheme,":");this._user&&(S+="".concat(_.escapeUser(this._user),"@")),S+=this._host,(this._port||this._port===0)&&(S+=":".concat(this._port));for(var E in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,E)&&(S+=";".concat(E),this._parameters[E]!==null&&(S+="=".concat(this._parameters[E])));for(var A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var R=c(this._headers[A]),C;try{for(R.s();!(C=R.n()).done;){var $=C.value;T.push("".concat(A,"=").concat($))}}catch(k){R.e(k)}finally{R.f()}}return T.length>0&&(S+="?".concat(T.join("&"))),S}},{key:"toAor",value:function(T){var S="".concat(this._scheme,":");return this._user&&(S+="".concat(_.escapeUser(this._user),"@")),S+=this._host,T&&(this._port||this._port===0)&&(S+=":".concat(this._port)),S}},{key:"scheme",get:function(){return this._scheme},set:function(T){this._scheme=T.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(T){this._user=T}},{key:"host",get:function(){return this._host},set:function(T){this._host=T.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(T){this._port=T===0?T:parseInt(T,10)||null}}]),h}(),_a}var zu;function It(){if(zu)return et;zu=1;function c(g){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?c=function(S){return typeof S}:c=function(S){return S&&typeof Symbol=="function"&&S.constructor===Symbol&&S!==Symbol.prototype?"symbol":typeof S},c(g)}function t(g,T){var S;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(S=n(g))||T&&g&&typeof g.length=="number"){S&&(g=S);var E=0,A=function(){};return{s:A,n:function(){return E>=g.length?{done:!0}:{done:!1,value:g[E++]}},e:function(re){throw re},f:A}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var R=!0,C=!1,$;return{s:function(){S=g[Symbol.iterator]()},n:function(){var re=S.next();return R=re.done,re},e:function(re){C=!0,$=re},f:function(){try{!R&&S.return!=null&&S.return()}finally{if(C)throw $}}}}function n(g,T){if(g){if(typeof g=="string")return o(g,T);var S=Object.prototype.toString.call(g).slice(8,-1);if(S==="Object"&&g.constructor&&(S=g.constructor.name),S==="Map"||S==="Set")return Array.from(g);if(S==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(S))return o(g,T)}}function o(g,T){(T==null||T>g.length)&&(T=g.length);for(var S=0,E=new Array(T);S<T;S++)E[S]=g[S];return E}var a=lt,s=Ks(),r=as();et.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var _=et.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};et.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},et.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},et.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},et.hasMethods=function(g){for(var T=arguments.length,S=new Array(T>1?T-1:0),E=1;E<T;E++)S[E-1]=arguments[E];for(var A=0,R=S;A<R.length;A++){var C=R[A];if(_(g[C]))return!1}return!0};var d=et.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,S,E,A="";for(S=0;S<g;S++)E=Math.random()*T|0,A+=E.toString(T);return A};et.newTag=function(){return d(10)},et.newUUID=function(){var g="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var S=Math.random()*16|0,E=T==="x"?S:S&3|8;return E.toString(16)});return g},et.hostType=function(g){if(g){if(g=r.parse(g,"host"),g!==-1)return g.host_type}else return};var h=et.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return et.normalizeTarget=function(g,T){if(g){if(g instanceof s)return g;if(typeof g=="string"){var S=g.split("@"),E,A;switch(S.length){case 1:if(!T)return;E=g,A=T;break;case 2:E=S[0],A=S[1];break;default:E=S.slice(0,S.length-1).join("@"),A=S[S.length-1]}E=E.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(E)&&(E=E.replace(/[-.()]/g,"")),g="".concat(a.SIP,":").concat(h(E),"@").concat(A);var R;return(R=s.parse(g))?R:void 0}else return}else return},et.headerize=function(g){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},S=g.toLowerCase().replace(/_/g,"-").split("-"),E="",A=S.length,R;for(R=0;R<A;R++)R!==0&&(E+="-"),E+=S[R].charAt(0).toUpperCase()+S[R].substring(1);return T[E]&&(E=T[E]),E},et.sipErrorCause=function(g){for(var T in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return a.causes[T];return a.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=function(){function g(T,S){return Math.floor(Math.random()*(S-T+1)+T)}return"192.0.2.".concat(g(1,254))},et.calculateMD5=function(g){function T(ge,ue){return ge<<ue|ge>>>32-ue}function S(ge,ue){var me=ge&2147483648,we=ue&2147483648,Ne=ge&1073741824,Ze=ue&1073741824,Le=(ge&1073741823)+(ue&1073741823);return Ne&Ze?Le^2147483648^me^we:Ne|Ze?Le&1073741824?Le^3221225472^me^we:Le^1073741824^me^we:Le^me^we}function E(ge,ue,me){return ge&ue|~ge&me}function A(ge,ue,me){return ge&me|ue&~me}function R(ge,ue,me){return ge^ue^me}function C(ge,ue,me){return ue^(ge|~me)}function $(ge,ue,me,we,Ne,Ze,Le){return ge=S(ge,S(S(E(ue,me,we),Ne),Le)),S(T(ge,Ze),ue)}function k(ge,ue,me,we,Ne,Ze,Le){return ge=S(ge,S(S(A(ue,me,we),Ne),Le)),S(T(ge,Ze),ue)}function re(ge,ue,me,we,Ne,Ze,Le){return ge=S(ge,S(S(R(ue,me,we),Ne),Le)),S(T(ge,Ze),ue)}function x(ge,ue,me,we,Ne,Ze,Le){return ge=S(ge,S(S(C(ue,me,we),Ne),Le)),S(T(ge,Ze),ue)}function F(ge){for(var ue,me=ge.length,we=me+8,Ne=(we-we%64)/64,Ze=(Ne+1)*16,Le=new Array(Ze-1),Lt=0,ht=0;ht<me;)ue=(ht-ht%4)/4,Lt=ht%4*8,Le[ue]=Le[ue]|ge.charCodeAt(ht)<<Lt,ht++;return ue=(ht-ht%4)/4,Lt=ht%4*8,Le[ue]=Le[ue]|128<<Lt,Le[Ze-2]=me<<3,Le[Ze-1]=me>>>29,Le}function _e(ge){var ue="",me="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=ge>>>Ne*8&255,me="0".concat(we.toString(16)),ue=ue+me.substr(me.length-2,2);return ue}function pe(ge){for(var ue="",me=0;me<ge.length;me++){var we=ge.charCodeAt(me);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 P=[],N,q,j,K,V,z,D,U,X,He=7,Q=12,W=17,B=22,ie=5,ve=9,Ie=14,ke=20,Ae=4,oe=11,ye=16,nt=23,ot=6,Ee=10,Ce=15,be=21;for(g=pe(g),P=F(g),z=1732584193,D=4023233417,U=2562383102,X=271733878,N=0;N<P.length;N+=16)q=z,j=D,K=U,V=X,z=$(z,D,U,X,P[N+0],He,3614090360),X=$(X,z,D,U,P[N+1],Q,3905402710),U=$(U,X,z,D,P[N+2],W,606105819),D=$(D,U,X,z,P[N+3],B,3250441966),z=$(z,D,U,X,P[N+4],He,4118548399),X=$(X,z,D,U,P[N+5],Q,1200080426),U=$(U,X,z,D,P[N+6],W,2821735955),D=$(D,U,X,z,P[N+7],B,4249261313),z=$(z,D,U,X,P[N+8],He,1770035416),X=$(X,z,D,U,P[N+9],Q,2336552879),U=$(U,X,z,D,P[N+10],W,4294925233),D=$(D,U,X,z,P[N+11],B,2304563134),z=$(z,D,U,X,P[N+12],He,1804603682),X=$(X,z,D,U,P[N+13],Q,4254626195),U=$(U,X,z,D,P[N+14],W,2792965006),D=$(D,U,X,z,P[N+15],B,1236535329),z=k(z,D,U,X,P[N+1],ie,4129170786),X=k(X,z,D,U,P[N+6],ve,3225465664),U=k(U,X,z,D,P[N+11],Ie,643717713),D=k(D,U,X,z,P[N+0],ke,3921069994),z=k(z,D,U,X,P[N+5],ie,3593408605),X=k(X,z,D,U,P[N+10],ve,38016083),U=k(U,X,z,D,P[N+15],Ie,3634488961),D=k(D,U,X,z,P[N+4],ke,3889429448),z=k(z,D,U,X,P[N+9],ie,568446438),X=k(X,z,D,U,P[N+14],ve,3275163606),U=k(U,X,z,D,P[N+3],Ie,4107603335),D=k(D,U,X,z,P[N+8],ke,1163531501),z=k(z,D,U,X,P[N+13],ie,2850285829),X=k(X,z,D,U,P[N+2],ve,4243563512),U=k(U,X,z,D,P[N+7],Ie,1735328473),D=k(D,U,X,z,P[N+12],ke,2368359562),z=re(z,D,U,X,P[N+5],Ae,4294588738),X=re(X,z,D,U,P[N+8],oe,2272392833),U=re(U,X,z,D,P[N+11],ye,1839030562),D=re(D,U,X,z,P[N+14],nt,4259657740),z=re(z,D,U,X,P[N+1],Ae,2763975236),X=re(X,z,D,U,P[N+4],oe,1272893353),U=re(U,X,z,D,P[N+7],ye,4139469664),D=re(D,U,X,z,P[N+10],nt,3200236656),z=re(z,D,U,X,P[N+13],Ae,681279174),X=re(X,z,D,U,P[N+0],oe,3936430074),U=re(U,X,z,D,P[N+3],ye,3572445317),D=re(D,U,X,z,P[N+6],nt,76029189),z=re(z,D,U,X,P[N+9],Ae,3654602809),X=re(X,z,D,U,P[N+12],oe,3873151461),U=re(U,X,z,D,P[N+15],ye,530742520),D=re(D,U,X,z,P[N+2],nt,3299628645),z=x(z,D,U,X,P[N+0],ot,4096336452),X=x(X,z,D,U,P[N+7],Ee,1126891415),U=x(U,X,z,D,P[N+14],Ce,2878612391),D=x(D,U,X,z,P[N+5],be,4237533241),z=x(z,D,U,X,P[N+12],ot,1700485571),X=x(X,z,D,U,P[N+3],Ee,2399980690),U=x(U,X,z,D,P[N+10],Ce,4293915773),D=x(D,U,X,z,P[N+1],be,2240044497),z=x(z,D,U,X,P[N+8],ot,1873313359),X=x(X,z,D,U,P[N+15],Ee,4264355552),U=x(U,X,z,D,P[N+6],Ce,2734768916),D=x(D,U,X,z,P[N+13],be,1309151649),z=x(z,D,U,X,P[N+4],ot,4149444226),X=x(X,z,D,U,P[N+11],Ee,3174756917),U=x(U,X,z,D,P[N+2],Ce,718787259),D=x(D,U,X,z,P[N+9],be,3951481745),z=S(z,q),D=S(D,j),U=S(U,K),X=S(X,V);var Oe=_e(z)+_e(D)+_e(U)+_e(X);return Oe.toLowerCase()},et.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var S=t(T),E;try{for(S.s();!(E=S.n()).done;){var A=E.value;A.stop()}}catch(F){S.e(F)}finally{S.f()}}else{T=g.getAudioTracks();var R=t(T),C;try{for(R.s();!(C=R.n()).done;){var $=C.value;$.stop()}}catch(F){R.e(F)}finally{R.f()}T=g.getVideoTracks();var k=t(T),re;try{for(k.s();!(re=k.n()).done;){var x=re.value;x.stop()}}catch(F){k.e(F)}finally{k.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},et.cloneArray=function(g){return g&&g.slice()||[]},et.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},et}var Nu={exports:{}},hr=typeof Reflect=="object"?Reflect:null,Xu=hr&&typeof hr.apply=="function"?hr.apply:function(t,n,o){return Function.prototype.apply.call(t,n,o)},vo;hr&&typeof hr.ownKeys=="function"?vo=hr.ownKeys:Object.getOwnPropertySymbols?vo=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:vo=function(t){return Object.getOwnPropertyNames(t)};function ch(c){console&&console.warn&&console.warn(c)}var qf=Number.isNaN||function(t){return t!==t};function Me(){Me.init.call(this)}Nu.exports=Me;Nu.exports.once=_h;Me.EventEmitter=Me;Me.prototype._events=void 0;Me.prototype._eventsCount=0;Me.prototype._maxListeners=void 0;var Qu=10;function Go(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 Qu},set:function(c){if(typeof c!="number"||c<0||qf(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Qu=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||qf(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=[],o=1;o<arguments.length;o++)n.push(arguments[o]);var a=t==="error",s=this._events;if(s!==void 0)a=a&&s.error===void 0;else if(!a)return!1;if(a){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var _=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw _.context=r,_}var d=s[t];if(d===void 0)return!1;if(typeof d=="function")Xu(d,this,n);else for(var h=d.length,g=Jf(d,h),o=0;o<h;++o)Xu(g[o],this,n);return!0};function Gf(c,t,n,o){var a,s,r;if(Go(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]=o?[n,r]:[r,n]:o?r.unshift(n):r.push(n),a=Bf(c),a>0&&r.length>a&&!r.warned){r.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=c,_.type=t,_.count=r.length,ch(_)}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 fh(){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 o={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},a=fh.bind(o);return a.listener=n,o.wrapFn=a,a}Me.prototype.once=function(t,n){return Go(n),this.on(t,Wf(this,t,n)),this};Me.prototype.prependOnceListener=function(t,n){return Go(n),this.prependListener(t,Wf(this,t,n)),this};Me.prototype.removeListener=function(t,n){var o,a,s,r,_;if(Go(n),a=this._events,a===void 0)return this;if(o=a[t],o===void 0)return this;if(o===n||o.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete a[t],a.removeListener&&this.emit("removeListener",t,o.listener||n));else if(typeof o!="function"){for(s=-1,r=o.length-1;r>=0;r--)if(o[r]===n||o[r].listener===n){_=o[r].listener,s=r;break}if(s<0)return this;s===0?o.shift():dh(o,s),o.length===1&&(a[t]=o[0]),a.removeListener!==void 0&&this.emit("removeListener",t,_||n)}return this};Me.prototype.off=Me.prototype.removeListener;Me.prototype.removeAllListeners=function(t){var n,o,a;if(o=this._events,o===void 0)return this;if(o.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):o[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete o[t]),this;if(arguments.length===0){var s=Object.keys(o),r;for(a=0;a<s.length;++a)r=s[a],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=o[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(a=n.length-1;a>=0;a--)this.removeListener(t,n[a]);return this};function Kf(c,t,n){var o=c._events;if(o===void 0)return[];var a=o[t];return a===void 0?[]:typeof a=="function"?n?[a.listener||a]:[a]:n?hh(a):Jf(a,a.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?vo(this._events):[]};function Jf(c,t){for(var n=new Array(t),o=0;o<t;++o)n[o]=c[o];return n}function dh(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function hh(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function _h(c,t){return new Promise(function(n,o){function a(r){c.removeListener(t,s),o(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",a),n([].slice.call(arguments))}zf(c,t,s,{once:!0}),t!=="error"&&ph(c,a,{once:!0})})}function ph(c,t,n){typeof c.on=="function"&&zf(c,"error",t,n)}function zf(c,t,n,o){if(typeof c.on=="function")o.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function a(s){o.once&&c.removeEventListener(t,a),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ft=Nu.exports,cu={exports:{}},pa,Zu;function mh(){if(Zu)return pa;Zu=1;var c=1e3,t=c*60,n=t*60,o=n*24,a=o*7,s=o*365.25;pa=function(g,T){T=T||{};var S=typeof g;if(S==="string"&&g.length>0)return r(g);if(S==="number"&&isFinite(g))return T.long?d(g):_(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 S=parseFloat(T[1]),E=(T[2]||"ms").toLowerCase();switch(E){case"years":case"year":case"yrs":case"yr":case"y":return S*s;case"weeks":case"week":case"w":return S*a;case"days":case"day":case"d":return S*o;case"hours":case"hour":case"hrs":case"hr":case"h":return S*n;case"minutes":case"minute":case"mins":case"min":case"m":return S*t;case"seconds":case"second":case"secs":case"sec":case"s":return S*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return S;default:return}}}}function _(g){var T=Math.abs(g);return T>=o?Math.round(g/o)+"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 d(g){var T=Math.abs(g);return T>=o?h(g,T,o,"day"):T>=n?h(g,T,n,"hour"):T>=t?h(g,T,t,"minute"):T>=c?h(g,T,c,"second"):g+" ms"}function h(g,T,S,E){var A=T>=S*1.5;return Math.round(g/S)+" "+E+(A?"s":"")}return pa}function gh(c){n.debug=n,n.default=n,n.coerce=d,n.disable=s,n.enable=a,n.enabled=r,n.humanize=mh(),n.destroy=h,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let S=0;S<g.length;S++)T=(T<<5)-T+g.charCodeAt(S),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,S=null,E,A;function R(...C){if(!R.enabled)return;const $=R,k=Number(new Date),re=k-(T||k);$.diff=re,$.prev=T,$.curr=k,T=k,C[0]=n.coerce(C[0]),typeof C[0]!="string"&&C.unshift("%O");let x=0;C[0]=C[0].replace(/%([a-zA-Z%])/g,(_e,pe)=>{if(_e==="%%")return"%";x++;const P=n.formatters[pe];if(typeof P=="function"){const N=C[x];_e=P.call($,N),C.splice(x,1),x--}return _e}),n.formatArgs.call($,C),($.log||n.log).apply($,C)}return R.namespace=g,R.useColors=n.useColors(),R.color=n.selectColor(g),R.extend=o,R.destroy=n.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>S!==null?S:(E!==n.namespaces&&(E=n.namespaces,A=n.enabled(g)),A),set:C=>{S=C}}),typeof n.init=="function"&&n.init(R),R}function o(g,T){const S=n(this.namespace+(typeof T>"u"?":":T)+g);return S.log=this.log,S}function a(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const S=(typeof g=="string"?g:"").split(/[\s,]+/),E=S.length;for(T=0;T<E;T++)S[T]&&(g=S[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(_),...n.skips.map(_).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,S;for(T=0,S=n.skips.length;T<S;T++)if(n.skips[T].test(g))return!1;for(T=0,S=n.names.length;T<S;T++)if(n.names[T].test(g))return!0;return!1}function _(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function d(g){return g instanceof Error?g.stack||g.message:g}function h(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var Th=gh;(function(c,t){t.formatArgs=o,t.save=a,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let d=!1;return()=>{d||(d=!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 o(d){if(d[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+d[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const h="color: "+this.color;d.splice(1,0,h,"color: inherit");let g=0,T=0;d[0].replace(/%[a-zA-Z%]/g,S=>{S!=="%%"&&(g++,S==="%c"&&(T=g))}),d.splice(T,0,h)}t.log=console.debug||console.log||(()=>{});function a(d){try{d?t.storage.setItem("debug",d):t.storage.removeItem("debug")}catch{}}function s(){let d;try{d=t.storage.getItem("debug")}catch{}return!d&&typeof process<"u"&&"env"in process&&(d=process.env.DEBUG),d}function r(){try{return localStorage}catch{}}c.exports=Th(t);const{formatters:_}=c.exports;_.j=function(d){try{return JSON.stringify(d)}catch(h){return"[UnexpectedJSONParseError]: "+h.message}}})(cu,cu.exports);var mr=cu.exports;function vh(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ec(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Sh(c,t,n){return t&&ec(c.prototype,t),n&&ec(c,n),c}var ir=mr,lr="JsSIP",dt=function(){function c(t){vh(this,c),t?(this._debug=ir.default("".concat(lr,":").concat(t)),this._warn=ir.default("".concat(lr,":WARN:").concat(t)),this._error=ir.default("".concat(lr,":ERROR:").concat(t))):(this._debug=ir.default(lr),this._warn=ir.default("".concat(lr,":WARN")),this._error=ir.default("".concat(lr,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Sh(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),kt={},Xf={},Qf={exports:{}},tc=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(tc).forEach(function(c){var t=tc[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Zf=Qf.exports;(function(c){var t=function(_){return String(Number(_))===_?Number(_):_},n=function(_,d,h,g){if(g&&!h)d[g]=t(_[1]);else for(var T=0;T<h.length;T+=1)_[T+1]!=null&&(d[h[T]]=t(_[T+1]))},o=function(_,d,h){var g=_.name&&_.names;_.push&&!d[_.push]?d[_.push]=[]:g&&!d[_.name]&&(d[_.name]={});var T=_.push?{}:g?d[_.name]:d;n(h.match(_.reg),T,_.names,_.name),_.push&&d[_.push].push(T)},a=Zf,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(_){var d={},h=[],g=d;return _.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var S=T[0],E=T.slice(2);S==="m"&&(h.push({rtp:[],fmtp:[]}),g=h[h.length-1]);for(var A=0;A<(a[S]||[]).length;A+=1){var R=a[S][A];if(R.reg.test(E))return o(R,g,E)}}),d.media=h,d};var r=function(_,d){var h=d.split(/=(.+)/,2);return h.length===2?_[h[0]]=t(h[1]):h.length===1&&d.length>1&&(_[h[0]]=void 0),_};c.parseParams=function(_){return _.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(_){return _.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(_){for(var d=[],h=_.split(" ").map(t),g=0;g<h.length;g+=3)d.push({component:h[g],ip:h[g+1],port:h[g+2]});return d},c.parseImageAttributes=function(_){return _.split(" ").map(function(d){return d.substring(1,d.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(_){return _.split(";").map(function(d){return d.split(",").map(function(h){var g,T=!1;return h[0]!=="~"?g=t(h):(g=t(h.substring(1,h.length)),T=!0),{scid:g,paused:T}})})}})(Xf);var ma=Zf,Eh=/%[sdv%]/g,yh=function(c){var t=1,n=arguments,o=n.length;return c.replace(Eh,function(a){if(t>=o)return a;var s=n[t];switch(t+=1,a){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Oi=function(c,t,n){var o=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,a=[c+"="+o];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?a.push(n[t.name][r]):a.push(n[t.names[s]])}else a.push(n[t.name]);return yh.apply(null,a)},Ch=["v","o","s","i","u","e","p","c","b","t","r","z","a"],Ah=["i","c","b","a"],Rh=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||Ch,o=t.innerOrder||Ah,a=[];return n.forEach(function(s){ma[s].forEach(function(r){r.name in c&&c[r.name]!=null?a.push(Oi(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(_){a.push(Oi(s,r,_))})})}),c.media.forEach(function(s){a.push(Oi("m",ma.m[0],s)),o.forEach(function(r){ma[r].forEach(function(_){_.name in s&&s[_.name]!=null?a.push(Oi(r,_,s)):_.push in s&&s[_.push]!=null&&s[_.push].forEach(function(d){a.push(Oi(r,_,d))})})})}),a.join(`\r
|
|
7
7
|
`)+`\r
|
|
8
|
-
`},
|
|
9
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var
|
|
10
|
-
`);for(var
|
|
11
|
-
`)}}catch(E){
|
|
8
|
+
`},bn=Xf,bh=Rh;kt.write=bh;kt.parse=bn.parse;kt.parseParams=bn.parseParams;kt.parseFmtpConfig=bn.parseFmtpConfig;kt.parsePayloads=bn.parsePayloads;kt.parseRemoteCandidates=bn.parseRemoteCandidates;kt.parseImageAttributes=bn.parseImageAttributes;kt.parseSimulcastStreamList=bn.parseSimulcastStreamList;function So(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?So=function(n){return typeof n}:So=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},So(c)}function xu(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(o,a){return o.__proto__=a,o},fu(c,t)}function Uu(c){var t=Oh();return function(){var o=No(c),a;if(t){var s=No(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return Ih(this,a)}}function Ih(c,t){return t&&(So(t)==="object"||typeof t=="function")?t:wh(c)}function wh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Oh(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function No(c){return No=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},No(c)}function Bt(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Dh(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
9
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var h=n.next();return s=h.done,h},e:function(h){r=!0,_=h},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}function Dh(c,t){if(c){if(typeof c=="string")return sc(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 sc(c,t)}}function sc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=c[n];return o}function rl(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function nc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Wo(c,t,n){return t&&nc(c.prototype,t),n&&nc(c,n),c}var ed=kt,Nh=dt,St=lt,rt=It(),rc=Du(),xh=as(),ga=new Nh("SIPMessage"),td=function(){function c(t,n,o,a,s,r){if(rl(this,c),!t||!n||!o)return null;a=a||{},this.ua=o,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)),a.route_set?this.setHeader("route",a.route_set):o.configuration.use_preloaded_route&&this.setHeader("route","<".concat(o.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",St.MAX_FORWARDS);var _=a.to_uri||n,d=a.to_tag?{tag:a.to_tag}:null,h=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new rc(_,h,d),this.setHeader("to",this.to.toString());var g=a.from_uri||o.configuration.uri,T={tag:a.from_tag||rt.newTag()},S;typeof a.from_display_name<"u"?S=a.from_display_name:o.configuration.display_name?S=o.configuration.display_name:S=null,this.from=new rc(g,S,T),this.setHeader("from",this.from.toString());var E=a.call_id||o.configuration.jssip_id+rt.createRandomToken(15);this.call_id=E,this.setHeader("call-id",E);var A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq","".concat(A," ").concat(t))}return Wo(c,[{key:"setHeader",value:function(n,o){for(var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=0;s<this.extraHeaders.length;s++)a.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[rt.headerize(n)]=Array.isArray(o)?o:[o]}},{key:"getHeader",value:function(n){var o=this.headers[rt.headerize(n)];if(o){if(o[0])return o[0]}else{var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=Bt(this.extraHeaders),r;try{for(s.s();!(r=s.n()).done;){var _=r.value;if(a.test(_))return _.substring(_.indexOf(":")+1).trim()}}catch(d){s.e(d)}finally{s.f()}}}},{key:"getHeaders",value:function(n){var o=this.headers[rt.headerize(n)],a=[];if(o){var s=Bt(o),r;try{for(s.s();!(r=s.n()).done;){var _=r.value;a.push(_)}}catch(S){s.e(S)}finally{s.f()}return a}else{var d=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),h=Bt(this.extraHeaders),g;try{for(h.s();!(g=h.n()).done;){var T=g.value;d.test(T)&&a.push(T.substring(T.indexOf(":")+1).trim())}}catch(S){h.e(S)}finally{h.f()}return a}}},{key:"hasHeader",value:function(n){if(this.headers[rt.headerize(n)])return!0;var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),a=Bt(this.extraHeaders),s;try{for(a.s();!(s=a.n()).done;){var r=s.value;if(o.test(r))return!0}}catch(_){a.e(_)}finally{a.f()}return!1}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=ed.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var n="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
|
|
10
|
+
`);for(var o in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,o)){var a=Bt(this.headers[o]),s;try{for(a.s();!(s=a.n()).done;){var r=s.value;n+="".concat(o,": ").concat(r,`\r
|
|
11
|
+
`)}}catch(E){a.e(E)}finally{a.f()}}var _=Bt(this.extraHeaders),d;try{for(_.s();!(d=_.n()).done;){var h=d.value;n+="".concat(h.trim(),`\r
|
|
12
12
|
`)}}catch(E){_.e(E)}finally{_.f()}var g=[];switch(this.method){case St.REGISTER:g.push("path","gruu");break;case St.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 St.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var T=this.ua.configuration.user_agent||St.USER_AGENT;if(n+="Allow: ".concat(St.ALLOWED_METHODS,`\r
|
|
13
13
|
`),n+="Supported: ".concat(g,`\r
|
|
14
14
|
`),n+="User-Agent: ".concat(T,`\r
|
|
@@ -16,144 +16,144 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
16
16
|
\r
|
|
17
17
|
`),n+=this.body}else n+=`Content-Length: 0\r
|
|
18
18
|
\r
|
|
19
|
-
`;return n}},{key:"clone",value:function(){var n=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(
|
|
20
|
-
`);if(this.method===St.INVITE&&
|
|
21
|
-
`)}}catch(
|
|
22
|
-
`)}}catch(
|
|
19
|
+
`;return n}},{key:"clone",value:function(){var n=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(o){n.headers[o]=this.headers[o].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}(),Uh=function(c){xu(n,c);var t=Uu(n);function n(o,a,s,r,_){var d;return rl(this,n),d=t.call(this,St.INVITE,o,a,s,r,_),d.transaction=null,d}return Wo(n,[{key:"cancel",value:function(a){this.transaction.cancel(a)}},{key:"clone",value:function(){var a=new n(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){a.headers[s]=this.headers[s].slice()},this),a.body=this.body,a.extraHeaders=rt.cloneArray(this.extraHeaders),a.to=this.to,a.from=this.from,a.call_id=this.call_id,a.cseq=this.cseq,a.transaction=this.transaction,a}}]),n}(td),sd=function(){function c(){rl(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 Wo(c,[{key:"addHeader",value:function(n,o){var a={raw:o};n=rt.headerize(n),this.headers[n]?this.headers[n].push(a):this.headers[n]=[a]}},{key:"getHeader",value:function(n){var o=this.headers[rt.headerize(n)];if(o){if(o[0])return o[0].raw}else return}},{key:"getHeaders",value:function(n){var o=this.headers[rt.headerize(n)],a=[];if(!o)return[];var s=Bt(o),r;try{for(s.s();!(r=s.n()).done;){var _=r.value;a.push(_.raw)}}catch(d){s.e(d)}finally{s.f()}return a}},{key:"hasHeader",value:function(n){return!!this.headers[rt.headerize(n)]}},{key:"parseHeader",value:function(n){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=rt.headerize(n),this.headers[n]){if(o>=this.headers[n].length){ga.debug('not so many "'.concat(n,'" headers present'));return}}else{ga.debug('header "'.concat(n,'" not present'));return}var a=this.headers[n][o],s=a.raw;if(a.parsed)return a.parsed;var r=xh.parse(s,n.replace(/-/g,"_"));if(r===-1){this.headers[n].splice(o,1),ga.debug('error parsing "'.concat(n,'" header field with value "').concat(s,'"'));return}else return a.parsed=r,r}},{key:"s",value:function(n,o){return this.parseHeader(n,o)}},{key:"setHeader",value:function(n,o){var a={raw:o};this.headers[rt.headerize(n)]=[a]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=ed.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),kh=function(c){xu(n,c);var t=Uu(n);function n(o){var a;return rl(this,n),a=t.call(this),a.ua=o,a.headers={},a.ruri=null,a.transport=null,a.server_transaction=null,a}return Wo(n,[{key:"reply",value:function(a,s,r,_,d,h){var g=[],T=this.getHeader("To");if(a=a||null,s=s||null,!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||St.REASON_PHRASE[a]||"",r=rt.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));var S="SIP/2.0 ".concat(a," ").concat(s,`\r
|
|
20
|
+
`);if(this.method===St.INVITE&&a>100&&a<=200){var E=this.getHeaders("record-route"),A=Bt(E),R;try{for(A.s();!(R=A.n()).done;){var C=R.value;S+="Record-Route: ".concat(C,`\r
|
|
21
|
+
`)}}catch(N){A.e(N)}finally{A.f()}}var $=this.getHeaders("via"),k=Bt($),re;try{for(k.s();!(re=k.n()).done;){var x=re.value;S+="Via: ".concat(x,`\r
|
|
22
|
+
`)}}catch(N){k.e(N)}finally{k.f()}!this.to_tag&&a>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),S+="To: ".concat(T,`\r
|
|
23
23
|
`),S+="From: ".concat(this.getHeader("From"),`\r
|
|
24
24
|
`),S+="Call-ID: ".concat(this.call_id,`\r
|
|
25
25
|
`),S+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
|
|
26
|
-
`);var
|
|
27
|
-
`)}}catch(
|
|
26
|
+
`);var F=Bt(r),_e;try{for(F.s();!(_e=F.n()).done;){var pe=_e.value;S+="".concat(pe.trim(),`\r
|
|
27
|
+
`)}}catch(N){F.e(N)}finally{F.f()}switch(this.method){case St.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 St.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),_&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===St.OPTIONS?(S+="Allow: ".concat(St.ALLOWED_METHODS,`\r
|
|
28
28
|
`),S+="Accept: ".concat(St.ACCEPTED_BODY_TYPES,`\r
|
|
29
|
-
`)):
|
|
30
|
-
`):
|
|
29
|
+
`)):a===405?S+="Allow: ".concat(St.ALLOWED_METHODS,`\r
|
|
30
|
+
`):a===415&&(S+="Accept: ".concat(St.ACCEPTED_BODY_TYPES,`\r
|
|
31
31
|
`)),S+="Supported: ".concat(g,`\r
|
|
32
|
-
`),_){var
|
|
33
|
-
`,S+="Content-Length: ".concat(
|
|
32
|
+
`),_){var P=rt.str_utf8_length(_);S+=`Content-Type: application/sdp\r
|
|
33
|
+
`,S+="Content-Length: ".concat(P,`\r
|
|
34
34
|
\r
|
|
35
35
|
`),S+=_}else S+="Content-Length: ".concat(0,`\r
|
|
36
36
|
\r
|
|
37
|
-
`);this.server_transaction.receiveResponse(
|
|
38
|
-
`),
|
|
39
|
-
`)}}catch(
|
|
37
|
+
`);this.server_transaction.receiveResponse(a,S,d,h)}},{key:"reply_sl",value:function(){var a=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(!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||St.REASON_PHRASE[a]||"";var _="SIP/2.0 ".concat(a," ").concat(s,`\r
|
|
38
|
+
`),d=Bt(r),h;try{for(d.s();!(h=d.n()).done;){var g=h.value;_+="Via: ".concat(g,`\r
|
|
39
|
+
`)}}catch(R){d.e(R)}finally{d.f()}var T=this.getHeader("To");if(!this.to_tag&&a>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),_+="To: ".concat(T,`\r
|
|
40
40
|
`),_+="From: ".concat(this.getHeader("From"),`\r
|
|
41
41
|
`),_+="Call-ID: ".concat(this.call_id,`\r
|
|
42
42
|
`),_+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
|
|
43
43
|
`),this.ua.configuration.extra_headers){var S=Bt(this.ua.configuration.extra_headers),E;try{for(S.s();!(E=S.n()).done;){var A=E.value;_+="".concat(A.trim(),`\r
|
|
44
|
-
`)}}catch(
|
|
44
|
+
`)}}catch(R){S.e(R)}finally{S.f()}}_+="Content-Length: ".concat(0,`\r
|
|
45
45
|
\r
|
|
46
|
-
`),this.transport.send(_)}}]),n}(th),Pd=function(c){Nu(n,c);var t=Uu(n);function n(){var a;return rl(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(th),Es={OutgoingRequest:eh,InitialOutgoingInviteRequest:Ud,IncomingRequest:xd,IncomingResponse:Pd};function kd(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 Md(c,t,n){return t&&rc(c.prototype,t),n&&rc(c,n),c}var Ld=ht,hs=bt(),Yt=new Ld("DigestAuthentication"),$d=function(){function c(t){kd(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 Md(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,_=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=_||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 d,g;return this._qop==="auth"?(d="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(d="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(d="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=null [a2:"%s"]',d),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,Hd=4e3,ic=5e3,sh={T1:ds,T2:Hd,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 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 il(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 ll(c,t,n){return t&&lc(c.prototype,t),n&&lc(c,n),c}function al(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 ol(c){var t=Vd();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 Fd(this,o)}}function Fd(c,t){return t&&(va(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 Vd(){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)}var ul=ft.EventEmitter,cl=ht,Ji=lt,ac=Es,ls=sh,oc=new cl("NonInviteClientTransaction"),$l=new cl("InviteClientTransaction"),jd=new cl("AckClientTransaction"),uc=new cl("NonInviteServerTransaction"),Hl=new cl("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"},qd=function(c){al(n,c);var t=ol(n);function n(a,o,s,r){var _;il(this,n),_=t.call(this),_.type=he.NON_INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=a,_.transport=o,_.request=s,_.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",h),_.ua.newTransaction(Bs(_)),_}return ll(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}(ul),Bd=function(c){al(n,c);var t=ol(n);function n(a,o,s,r){var _;il(this,n),_=t.call(this),_.type=he.INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=a,_.transport=o,_.request=s,_.eventHandlers=r,s.transaction=Bs(_);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",h),_.ua.newTransaction(Bs(_)),_}return ll(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&&($l.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(){$l.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(){$l.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(){$l.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(Ji.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(Ji.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}(ul),Gd=function(c){al(n,c);var t=ol(n);function n(a,o,s,r){var _;il(this,n),_=t.call(this),_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.transport=o,_.request=s,_.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",h),_}return ll(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){jd.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return he}}]),n}(ul),Wd=function(c){al(n,c);var t=ol(n);function n(a,o,s){var r;return il(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 ll(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,_){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(),_&&_());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(),_&&_());break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(ul),Kd=function(c){al(n,c);var t=ol(n);function n(a,o,s){var r;return il(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 ll(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Hl.debug("Timer H expired for transaction ".concat(this.id)),this.state===he.STATUS_COMPLETED&&Hl.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(){Hl.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,Hl.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,_){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(),_&&_());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(),_&&_());break}}},{key:"C",get:function(){return he}}]),n}(ul);function Yd(c,t){var n=c._transactions,a;switch(t.method){case Ji.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 Ji.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 Ji.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 fl={C:he,NonInviteClientTransaction:qd,InviteClientTransaction:Bd,AckClientTransaction:Gd,NonInviteServerTransaction:Wd,InviteServerTransaction:Kd,checkTransaction:Yd};function Jd(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 zd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Xd=ht,fc=lt,Qd=$d,go=fl,Zd=new Xd("RequestSender"),To={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},hl=function(){function c(t,n,a){Jd(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 To)Object.prototype.hasOwnProperty.call(To,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=To[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==fc.BYE||this._method!==fc.ACK)&&this._eventHandlers.onTransportError()}return zd(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 go.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new go.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new go.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){Zd.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 Qd({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 e_(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 t_(c,t,n){return t&&hc(c.prototype,t),n&&hc(c,n),c}var s_=ht,vo=bt(),pn=lt,dc=Es,_c=hl,Di=new s_("Registrator"),Fl=10,n_=function(){function c(t,n){e_(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=vo.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 t_(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){Di.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(_){if(_.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(_.status_code):break;case/^2[0-9]{2}$/.test(_.status_code):{if(n._registering=!1,!_.hasHeader("Contact")){Di.debug("no Contact header in response to REGISTER, response ignored");break}var h=_.headers.Contact.reduce(function(E,A){return E.concat(A.parsed)},[]),d=h.find(function(E){return n._sipInstance===E.getParam("+sip.instance")&&n._reg_id===parseInt(E.getParam("reg-id"))});if(d||(d=h.find(function(E){return E.uri.user===n._ua.contact.uri.user})),!d){Di.debug("no Contact header pointing to us, response ignored");break}var g=d.getParam("expires");!g&&_.hasHeader("expires")&&(g=_.getHeader("expires")),g||(g=n._expires),g=Number(g),g<Fl&&(g=Fl);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),d.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=d.getParam("temp-gruu").replace(/"/g,"")),d.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=d.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:_}));break}case/^423$/.test(_.status_code):{_.hasHeader("min-expires")?(n._expires=Number(_.getHeader("min-expires")),n._expires<Fl&&(n._expires=Fl),n.register()):(Di.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(_,pn.causes.SIP_FAILURE_CODE));break}default:{var S=vo.sipErrorCause(_.status_code);n._registrationFailure(_,S)}}}});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){Di.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 d=vo.sipErrorCause(h.status_code);n._unregistered(h,d)}}}});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 r_(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 i_(c,t,n){return t&&pc(c.prototype,t),n&&pc(c,n),c}var So=lt,Vl=fl,l_=hl,Eo={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},a_=function(){function c(t,n,a){r_(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 Eo)Object.prototype.hasOwnProperty.call(Eo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Eo[o]))}return i_(c,[{key:"send",value:function(){var n=this,a=new l_(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!==Vl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===Vl.C.STATUS_ACCEPTED||a.clientTransaction.state===Vl.C.STATUS_COMPLETED||a.clientTransaction.state===Vl.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 o_(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 u_=ht,Tc=Es,Ms=lt,Ni=fl,c_=a_,yo=bt(),Ao=new u_("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},f_=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(o_(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=yo.cloneArray(o.extraHeaders),r=yo.cloneObject(o.eventHandlers),_=o.body||null,h=this._createRequest(n,s,_);r.onAuthenticated=function(){a._local_seqnum+=1};var d=new c_(this,h,r);return d.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=yo.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===Ni.C.STATUS_ACCEPTED||n.server_transaction.state===Ni.C.STATUS_COMPLETED||n.server_transaction.state===Ni.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===Ni.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===Ni.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}(),xu={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 h_(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 d_(c,t,n){return t&&vc(c.prototype,t),n&&vc(c,n),c}function __(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 p_(c){var t=T_();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 m_(this,o)}}function m_(c,t){return t&&(Sa(t)==="object"||typeof t=="function")?t:g_(c)}function g_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function T_(){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 v_=ft.EventEmitter,S_=ht,E_=lt,y_=Ws,Sc=bt(),A_=new S_("RTCSession:DTMF"),nh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};xu.exports=function(c){__(n,c);var t=p_(n);function n(a){var o;return h_(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return d_(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 y_.InvalidStateError(this._session.status);var _=Sc.cloneArray(r.extraHeaders);if(this.eventHandlers=Sc.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,_.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
|
|
47
|
-
`);
|
|
48
|
-
`);_.length>=1&&s.test(_[0])&&(this._tone=_[0].replace(s,"$2")),_.length>=2&&r.test(_[1])&&(this._duration=parseInt(_[1].replace(r,"$2"),10))}this._duration||(this._duration=
|
|
49
|
-
`,1)[0],"Status_Line");if(s===-1){mn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(
|
|
50
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var d=n.next();return s=d.done,d},e:function(d){r=!0,_=d},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}function Z_(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 ep(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 tp(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 sp(c){var t=ip();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 np(this,o)}}function np(c,t){return t&&(Aa(t)==="object"||typeof t=="function")?t:rp(c)}function rp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function ip(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Pa(c){return Pa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Pa(c)}var lp=ft.EventEmitter,Oc=Pt,ap=ht,ce=lt,gn=Ws,Dc=fl,qe=bt(),xi=sh,op=Es,jl=f_,up=hl,kt=C_,Nc=M_,cp=V_,fp=Q_,Uc=Ks(),K=new ap("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},ql=["audio","video"],hp=function(c){tp(n,c);var t=sp(n);wc(n,null,[{key:"C",get:function(){return Q}}]);function n(a){var o;return ep(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 _=o,h=qe.cloneObject(s.eventHandlers),d=qe.cloneArray(s.extraHeaders),g=qe.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,S=qe.cloneObject(s.pcConfig,{iceServers:[]}),E=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(_));this._sessionTimers.enabled&&qe.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=qe.newTag();var R=s.anonymous||!1,k={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:R,outbound:!0}),R?(k.from_display_name="Anonymous",k.from_uri=new Uc("sip","anonymous","anonymous.invalid"),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),d.push("Privacy: id")):s.fromUserName&&(k.from_uri=new Uc("sip",s.fromUserName,this._ua.configuration.uri.host),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(k.from_display_name=s.fromDisplayName),d.push("Contact: ".concat(this._contact)),d.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&d.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new op.InitialOutgoingInviteRequest(o,this._ua,k,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(S,E),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 _,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")&&(_=o.getHeader("expires")*1e3),o.to_tag=qe.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),_&&(this._timers.expiresTimer=setTimeout(function(){r._status===Q.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},_)),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,_=qe.cloneArray(s.extraHeaders),h=qe.cloneObject(s.mediaConstraints),d=s.mediaStream||null,g=qe.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,S=s.rtcAnswerConstraints||null,E=qe.cloneObject(s.rtcOfferConstraints),A,C=!1,R=!1,k=!1,M=!1;if(this._rtcAnswerConstraints=S,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&&qe.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),_.unshift("Contact: ".concat(this._contact));var ie=r.parseSDP();Array.isArray(ie.media)||(ie.media=[ie.media]);var N=_s(ie.media),V;try{for(N.s();!(V=N.n()).done;){var Ee=V.value;Ee.type==="audio"&&(C=!0,(!Ee.direction||Ee.direction==="sendrecv")&&(k=!0)),Ee.type==="video"&&(R=!0,(!Ee.direction||Ee.direction==="sendrecv")&&(M=!0))}}catch(F){N.e(F)}finally{N.f()}if(d&&h.audio===!1){A=d.getAudioTracks();var ve=_s(A),L;try{for(ve.s();!(L=ve.n()).done;){var D=L.value;d.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(d&&h.video===!1){A=d.getVideoTracks();var B=_s(A),q;try{for(B.s();!(q=B.n()).done;){var J=q.value;d.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!d&&h.audio===void 0&&(h.audio=k),!d&&h.video===void 0&&(h.video=M),!d&&!C&&!E.offerToReceiveAudio&&(h.audio=!1),!d&&!R&&!E.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(d)return d;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",S).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,_),r.reply(200,null,_,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,_=qe.cloneArray(s.extraHeaders),h=s.body,d,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]||"",d="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=d):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(d),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,_,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&&_.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 S=this._dialog;this.receiveRequest=function(E){var A=E.method;A===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:_,body:h}),S.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Dc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:_,body:h}),S.terminate())}),this._ended("local",null,r),this._dialog=S,this._ua.newDialog(S)}else this.sendRequest(ce.BYE,{extraHeaders:_,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,_=s.duration||null,h=s.interToneGap||null,d=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(d!==ce.DTMF_TRANSPORT.INFO&&d!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(d));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(_&&!qe.isDecimal(_))throw new TypeError("Invalid tone duration: ".concat(_));if(_?_<kt.C.MIN_DURATION?(K.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_DURATION," milliseconds")),_=kt.C.MIN_DURATION):_>kt.C.MAX_DURATION?(K.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(kt.C.MAX_DURATION," milliseconds")),_=kt.C.MAX_DURATION):_=Math.abs(_):_=kt.C.DEFAULT_DURATION,s.duration=_,h&&!qe.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,d===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,_,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var S=this,E;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===",")E=2e3;else{var C=new kt(this);s.eventHandlers={onFailed:function(){S._tones=null}},C.send(A,s),E=_+h}setTimeout(T.bind(this),E)}}},{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 _=new Nc(this);_.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 _={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:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:_,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 _={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:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:_,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 _=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:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:_,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;K.debug("refer()");var _=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(_));var h=new fp(this);h.sendRefer(o,s);var d=h.id;return this._referSubscribers[d]=h,h.on("requestFailed",function(){delete r._referSubscribers[d]}),h.on("accepted",function(){delete r._referSubscribers[d]}),h.on("failed",function(){delete r._referSubscribers[d]}),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 _=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(_)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(d){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),s.emit("peerconnection:setremotedescriptionfailed",d)})}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"),qe.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(_){K.warn("close() | error closing the RTCPeerConnection: %o",_)}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 _(){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(_.bind(this),r))}this._timers.invite2xxTimer=setTimeout(_.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 _=r._connection.iceConnectionState;_==="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 _=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?_.createOffer(s).catch(function(h){return K.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):_.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 _.setLocalDescription(h).catch(function(d){return r._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',d),r.emit("peerconnection:setlocaldescriptionfailed",d),Promise.reject(d)})}).then(function(){var h=s&&s.iceRestart;if(_.iceGatheringState==="complete"&&!h||_.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var d={originator:"local",type:o,sdp:_.localDescription.sdp};return K.debug('emit "sdp"'),r.emit("sdp",d),Promise.resolve(d.sdp)}return new Promise(function(g){var T=!1,S,E;r._iceReady=!1;var A=function(){_.removeEventListener("icecandidate",S),_.removeEventListener("icegatheringstatechange",E),T=!0,r._rtcReady=!0,r._iceReady=!0;var R={originator:"local",type:o,sdp:_.localDescription.sdp};K.debug('emit "sdp"'),r.emit("sdp",R),g(R.sdp)};_.addEventListener("icecandidate",S=function(R){var k=R.candidate;k?r.emit("icecandidate",{candidate:k,ready:A}):T||A()}),_.addEventListener("icegatheringstatechange",E=function(){_.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(o,s,r){var _=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,d=o.call_id+_+h,g=this._earlyDialogs[d];if(r)return g?!0:(g=new jl(this,o,s,jl.C.STATUS_EARLY),g.error?(K.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=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[d],!0;var T=new jl(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,_={request:o,callback:void 0,reject:d.bind(this)},h=!1;function d(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var S=T.status_code||403,E=T.reason_phrase||"",A=qe.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(S<300||S>=700)throw new TypeError("Invalid status_code: ".concat(S));o.reply(S,E,A)}if(this.emit("reinvite",_),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 S=this,E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,E,T,function(){S._status=Q.STATUS_WAITING_FOR_ACK,S._setInvite2xxTimer(o,T),S._setACKTimer()}),typeof _.callback=="function"&&_.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,_={request:o,callback:void 0,reject:d.bind(this)},h=!1;function d(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var S=T.status_code||403,E=T.reason_phrase||"",A=qe.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(S<300||S>=700)throw new TypeError("Invalid status_code: ".concat(S));o.reply(S,E,A)}if(this.emit("update",_),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 S=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,S),o.reply(200,null,S,T),typeof _.callback=="function"&&_.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;K.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),_=!1,h=_s(r.media),d;try{for(h.s();!(d=h.n()).done;){var g=d.value;if(ql.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")_=!0;else{_=!1;break}}}}catch(A){h.e(A)}finally{h.f()}var S={originator:"remote",type:"offer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",S);var E=new RTCSessionDescription({type:"offer",sdp:S.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(E).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&&_===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&_===!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 cp(this,o.cseq);K.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){_.call(s,g,T)},reject:function(){h.call(s)}});function _(d){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(d=typeof d=="function"?d: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(E){var A=E.response;r.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(E){var A=E.response;r.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(E){var A=E.message,C=E.cause;A?r.notify(A.status_code,A.reason_phrase):r.notify(487,C)}),o.refer_to.uri.hasHeader("replaces")){var S=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=qe.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(S))}T.connect(o.refer_to.uri.toAor(),g,d)}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 d=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(){d.terminate()}),g.init_incoming(o,h)}function _(){K.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(d){r.call(s,d)},reject:function(){_.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var _=this,h=new up(this._ua,this._request,{onRequestTimeout:function(){_.onRequestTimeout()},onTransportError:function(){_.onTransportError()},onAuthenticated:function(g){_._request=g},onReceiveResponse:function(g){_._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return _._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(d){throw _._status===Q.STATUS_TERMINATED?new Error("terminated"):(_._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',d),_.emit("getusermediafailed",d),d)})}).then(function(d){if(_._status===Q.STATUS_TERMINATED)throw new Error("terminated");return _._localMediaStream=d,d&&d.getTracks().forEach(function(g){_._connection.addTrack(g,d)}),_._connecting(_._request),_._createLocalDescription("offer",s).catch(function(g){throw _._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(d){if(_._is_canceled||_._status===Q.STATUS_TERMINATED)throw new Error("terminated");_._request.body=d,_._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',_._request),_.emit("sending",{request:_._request}),h.send()}).catch(function(d){_._status!==Q.STATUS_TERMINATED&&K.warn(d)})}},{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 jl(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 _={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",_);var h=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(S){K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),s.emit("peerconnection:setremotedescriptionfailed",S)});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 d={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",d);var g=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(S){return s._connection.setLocalDescription(S)}).catch(function(S){s._acceptAndTerminate(o,500,S.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(S){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),s.emit("peerconnection:setremotedescriptionfailed",S)})});break}default:{var T=qe.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=qe.cloneArray(s.extraHeaders),_=qe.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,d=!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(S){S=o._mangleOffer(S);var E={originator:"local",type:"offer",sdp:S};K.debug('emit "sdp"'),o.emit("sdp",E),o.sendRequest(ce.INVITE,{extraHeaders:r,body:S,eventHandlers:{onSuccessResponse:function(C){g.call(o,C),d=!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(S){var E=this;if(this._status!==Q.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!d)){if(this._handleSessionTimersInIncomingResponse(S),S.body){if(!S.hasHeader("Content-Type")||S.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var A={originator:"remote",type:"answer",sdp:S.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 E._connection.setRemoteDescription(C)}).then(function(){_.succeeded&&_.succeeded(S)}).catch(function(R){T.call(E),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',R),E.emit("peerconnection:setremotedescriptionfailed",R)})}}function T(S){_.failed&&_.failed(S)}}},{key:"_sendUpdate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendUpdate()");var r=qe.cloneArray(s.extraHeaders),_=qe.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,d=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")),d?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var A={originator:"local",type:"offer",sdp:E};K.debug('emit "sdp"'),o.emit("sdp",A),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(R){T.call(o,R),g=!0},onErrorResponse:function(R){S.call(o,R)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){S.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(A){T.call(o,A)},onErrorResponse:function(A){S.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(E){var A=this;if(this._status!==Q.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(E),d){if(E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){S.call(this);return}}else{S.call(this);return}var C={originator:"remote",type:"answer",sdp:E.body};K.debug('emit "sdp"'),this.emit("sdp",C);var R=new RTCSessionDescription({type:"answer",sdp:C.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(R)}).then(function(){_.succeeded&&_.succeeded(E)}).catch(function(k){S.call(A),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',k),A.emit("peerconnection:setremotedescriptionfailed",k)})}else _.succeeded&&_.succeeded(E)}function S(E){_.failed&&_.failed(E)}}},{key:"_acceptAndTerminate",value:function(o,s,r){K.debug("acceptAndTerminate()");var _=[];s&&(r=r||ce.REASON_PHRASE[s]||"",_.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:_})),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 _=r.value;ql.indexOf(_.type)!==-1&&(_.direction?_.direction==="sendrecv"?_.direction="sendonly":_.direction==="recvonly"&&(_.direction="inactive"):_.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),d;try{for(h.s();!(d=h.n()).done;){var g=d.value;ql.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),S;try{for(T.s();!(S=T.n()).done;){var E=S.value;ql.indexOf(E.type)!==-1&&(E.direction?E.direction==="sendrecv"?E.direction="recvonly":E.direction==="recvonly"&&(E.direction="inactive"):E.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(d){return d.track&&d.track.kind==="audio"}),r=_s(s),_;try{for(r.s();!(_=r.n()).done;){var h=_.value;h.track.enabled=!o}}catch(d){r.e(d)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(d){return d.track&&d.track.kind==="video"}),r=_s(s),_;try{for(r.s();!(_=r.n()).done;){var h=_.value;h.track.enabled=!o}}catch(d){r.e(d)}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}(lp);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 dp(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 _p(c,t,n){return t&&xc(c.prototype,t),n&&xc(c,n),c}function pp(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 mp(c){var t=vp();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 gp(this,o)}}function gp(c,t){return t&&(Ca(t)==="object"||typeof t=="function")?t:Tp(c)}function Tp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function vp(){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 Sp=ft.EventEmitter,Ep=ht,Ro=lt,yp=Es,Pi=bt(),Ap=hl,Pc=Ws,Cp=Ks(),Bl=new Ep("Message"),Rp=function(c){pp(n,c);var t=mp(n);function n(a){var o;return dp(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 _p(n,[{key:"send",value:function(o,s){var r=this,_=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 d=Pi.cloneArray(_.extraHeaders),g=Pi.cloneObject(_.eventHandlers),T=_.contentType||"text/plain",S={};_.fromUserName&&(S.from_uri=new Cp("sip",_.fromUserName,this._ua.configuration.uri.host),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),_.fromDisplayName&&(S.from_display_name=_.fromDisplayName);for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);d.push("Content-Type: ".concat(T)),this._request=new yp.OutgoingRequest(Ro.MESSAGE,o,this._ua,S,d),s&&(this._request.body=s);var A=new Ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(R){r._receiveResponse(R)}});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=Pi.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Pc.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,_=Pi.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Pc.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,_,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=Pi.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Ro.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Ro.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){Bl.debug("MESSAGE failed"),this._close(),Bl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Bl.debug("MESSAGE succeeded"),this._close(),Bl.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 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 Ip(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 bp(c,t,n){return t&&kc(c.prototype,t),n&&kc(c,n),c}function wp(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 Op(c){var t=Up();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 Dp(this,o)}}function Dp(c,t){return t&&(Ra(t)==="object"||typeof t=="function")?t:Np(c)}function Np(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Up(){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 xp=ft.EventEmitter,Pp=ht,Io=lt,kp=Es,ki=bt(),Mp=hl,Mc=Ws,Gl=new Pp("Options"),Lp=function(c){wp(n,c);var t=Op(n);function n(a){var o;return Ip(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 bp(n,[{key:"send",value:function(o,s){var r=this,_=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 d=ki.cloneArray(_.extraHeaders),g=ki.cloneObject(_.eventHandlers),T=_.contentType||"application/sdp";for(var S in g)Object.prototype.hasOwnProperty.call(g,S)&&this.on(S,g[S]);d.push("Content-Type: ".concat(T)),this._request=new kp.OutgoingRequest(Io.OPTIONS,o,this._ua,null,d),s&&(this._request.body=s);var E=new Mp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(C){r._receiveResponse(C)}});this._newOptions("local",this._request),E.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=ki.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,_=ki.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,_,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:"_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){Gl.debug("OPTIONS 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("OPTIONS 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}(xp),Pu={},$p=ht,bo=bt(),Hp=os(),Mi=new $p("Socket");Pu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return Mi.warn("undefined JsSIP.Socket instance"),!1;try{if(!bo.isString(c.url))throw Mi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!bo.isString(c.via_transport))throw Mi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Hp.parse(c.sip_uri,"SIP_URI")===-1)throw Mi.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(!bo.isFunction(c[t]))throw Mi.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 Fp(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 Vp(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}var jp=ht,qp=Pu,$c=lt,Nt=new jp("Transport"),jt={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}},Bp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:jt.recovery_options;Fp(this,c),Nt.debug("new()"),this.status=jt.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(!qp.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:jt.SOCKET_STATUS_READY})},this),this._getSocket()}return Vp(c,[{key:"connect",value:function(){if(Nt.debug("connect()"),this.isConnected()){Nt.debug("Transport is already connected");return}else if(this.isConnecting()){Nt.debug("Transport is connecting");return}this.close_requested=!1,this.status=jt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Nt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=jt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(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:
|
|
46
|
+
`),this.transport.send(_)}}]),n}(sd),Ph=function(c){xu(n,c);var t=Uu(n);function n(){var o;return rl(this,n),o=t.call(this),o.headers={},o.status_code=null,o.reason_phrase=null,o}return n}(sd),Es={OutgoingRequest:td,InitialOutgoingInviteRequest:Uh,IncomingRequest:kh,IncomingResponse:Ph};function Mh(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ic(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Lh(c,t,n){return t&&ic(c.prototype,t),n&&ic(c,n),c}var $h=dt,ds=It(),Yt=new $h("DigestAuthentication"),Hh=function(){function c(t){Mh(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 Lh(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,o){var a=n.method,s=n.ruri,r=n.body,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=o.algorithm,this._realm=o.realm,this._nonce=o.nonce,this._opaque=o.opaque,this._stale=o.stale,this._algorithm){if(this._algorithm!=="MD5")return 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(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 Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=a,this._uri=s,this._cnonce=_||ds.createRandomToken(12),this._nc+=1;var d=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-d.length)+d,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ds.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var h,g;return this._qop==="auth"?(h="".concat(this._method,":").concat(this._uri),g=ds.calculateMD5(h),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',h),this._response=ds.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(h="".concat(this._method,":").concat(this._uri,":").concat(ds.calculateMD5(r||"")),g=ds.calculateMD5(h),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',h),this._response=ds.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(h="".concat(this._method,":").concat(this._uri),g=ds.calculateMD5(h),Yt.debug('authenticate() | using qop=null [a2:"%s"]',h),this._response=ds.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}(),hs=500,Fh=4e3,lc=5e3,nd={T1:hs,T2:Fh,T4:lc,TIMER_B:64*hs,TIMER_D:0*hs,TIMER_F:64*hs,TIMER_H:64*hs,TIMER_I:0*hs,TIMER_J:0*hs,TIMER_K:0*lc,TIMER_L:64*hs,TIMER_M:64*hs,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Eo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Eo=function(n){return typeof n}:Eo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Eo(c)}function il(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function oc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function ll(c,t,n){return t&&oc(c.prototype,t),n&&oc(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&&du(c,t)}function du(c,t){return du=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},du(c,t)}function al(c){var t=jh();return function(){var o=xo(c),a;if(t){var s=xo(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return Vh(this,a)}}function Vh(c,t){return t&&(Eo(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 jh(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function xo(c){return xo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},xo(c)}var ul=ft.EventEmitter,cl=dt,Ji=lt,ac=Es,ls=nd,uc=new cl("NonInviteClientTransaction"),$l=new cl("InviteClientTransaction"),qh=new cl("AckClientTransaction"),cc=new cl("NonInviteServerTransaction"),Hl=new cl("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"},Bh=function(c){ol(n,c);var t=al(n);function n(o,a,s,r){var _;il(this,n),_=t.call(this),_.type=de.NON_INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=o,_.transport=a,_.request=s,_.eventHandlers=r;var d="SIP/2.0/".concat(a.via_transport);return d+=" ".concat(o.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",d),_.ua.newTransaction(Bs(_)),_}return ll(n,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(de.STATUS_TRYING),this.F=setTimeout(function(){a.timer_F()},ls.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){uc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){uc.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(a){var s=this,r=a.status_code;if(r<200)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break}else switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(a),this.K=setTimeout(function(){s.timer_K()},ls.TIMER_K);break;case de.STATUS_COMPLETED:break}}},{key:"C",get:function(){return de}}]),n}(ul),Gh=function(c){ol(n,c);var t=al(n);function n(o,a,s,r){var _;il(this,n),_=t.call(this),_.type=de.INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=o,_.transport=a,_.request=s,_.eventHandlers=r,s.transaction=Bs(_);var d="SIP/2.0/".concat(a.via_transport);return d+=" ".concat(o.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",d),_.ua.newTransaction(Bs(_)),_}return ll(n,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(de.STATUS_CALLING),this.B=setTimeout(function(){a.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!==de.STATUS_ACCEPTED&&($l.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){$l.debug("Timer M expired for transaction ".concat(this.id)),this.state===de.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){$l.debug("Timer B expired for transaction ".concat(this.id)),this.state===de.STATUS_CALLING&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){$l.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(a){var s=this,r=new ac.OutgoingRequest(Ji.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",a.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ls.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(a){if(this.state===de.STATUS_PROCEEDING){var s=new ac.OutgoingRequest(Ji.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")),a&&s.setHeader("reason",a),this.transport.send(s)}}},{key:"receiveResponse",value:function(a){var s=this,r=a.status_code;if(r>=100&&r<=199)switch(this.state){case de.STATUS_CALLING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break;case de.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(a);break}else if(r>=200&&r<=299)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},ls.TIMER_M),this.eventHandlers.onReceiveResponse(a);break;case de.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(a);break}else if(r>=300&&r<=699)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.sendACK(a),this.eventHandlers.onReceiveResponse(a);break;case de.STATUS_COMPLETED:this.sendACK(a);break}}},{key:"C",get:function(){return de}}]),n}(ul),Wh=function(c){ol(n,c);var t=al(n);function n(o,a,s,r){var _;il(this,n),_=t.call(this),_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.transport=a,_.request=s,_.eventHandlers=r;var d="SIP/2.0/".concat(a.via_transport);return d+=" ".concat(o.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",d),_}return ll(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){qh.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return de}}]),n}(ul),Kh=function(c){ol(n,c);var t=al(n);function n(o,a,s){var r;return il(this,n),r=t.call(this),r.type=de.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=o,r.transport=a,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=de.STATUS_TRYING,o.newTransaction(Bs(r)),r}return ll(n,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_J",value:function(){cc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,cc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(a,s,r,_){var d=this;if(a===100)switch(this.state){case de.STATUS_TRYING:this.stateChanged(de.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case de.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),_&&_());break}else if(a>=200&&a<=699)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){d.timer_J()},ls.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),_&&_());break;case de.STATUS_COMPLETED:break}}},{key:"C",get:function(){return de}}]),n}(ul),Yh=function(c){ol(n,c);var t=al(n);function n(o,a,s){var r;return il(this,n),r=t.call(this),r.type=de.INVITE_SERVER,r.id=s.via_branch,r.ua=o,r.transport=a,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=de.STATUS_PROCEEDING,o.newTransaction(Bs(r)),r.resendProvisionalTimer=null,s.reply(100),r}return ll(n,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_H",value:function(){Hl.debug("Timer H expired for transaction ".concat(this.id)),this.state===de.STATUS_COMPLETED&&Hl.debug("ACK not received, dialog will be terminated"),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Hl.debug("Timer L expired for transaction ".concat(this.id)),this.state===de.STATUS_ACCEPTED&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Hl.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(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(a,s,r,_){var d=this;if(a>=100&&a<=199)switch(this.state){case de.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(a>100&&a<=199&&this.state===de.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){d.resend_provisional()},ls.PROVISIONAL_RESPONSE_INTERVAL));else if(a>=200&&a<=299)switch(this.state){case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){d.timer_L()},ls.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case de.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),_&&_());break}else if(a>=300&&a<=699)switch(this.state){case de.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(de.STATUS_COMPLETED),this.H=setTimeout(function(){d.timer_H()},ls.TIMER_H),r&&r()):(this.onTransportError(),_&&_());break}}},{key:"C",get:function(){return de}}]),n}(ul);function Jh(c,t){var n=c._transactions,o;switch(t.method){case Ji.INVITE:if(o=n.ist[t.via_branch],o){switch(o.state){case de.STATUS_PROCEEDING:o.transport.send(o.last_response);break;case de.STATUS_ACCEPTED:break}return!0}break;case Ji.ACK:if(o=n.ist[t.via_branch],o){if(o.state===de.STATUS_ACCEPTED)return!1;if(o.state===de.STATUS_COMPLETED)return o.state=de.STATUS_CONFIRMED,o.I=setTimeout(function(){o.timer_I()},ls.TIMER_I),!0}else return!1;break;case Ji.CANCEL:return o=n.ist[t.via_branch],o?(t.reply_sl(200),o.state!==de.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(o=n.nist[t.via_branch],o){switch(o.state){case de.STATUS_TRYING:break;case de.STATUS_PROCEEDING:case de.STATUS_COMPLETED:o.transport.send(o.last_response);break}return!0}break}}var fl={C:de,NonInviteClientTransaction:Bh,InviteClientTransaction:Gh,AckClientTransaction:Wh,NonInviteServerTransaction:Kh,InviteServerTransaction:Yh,checkTransaction:Jh};function zh(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function fc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Xh(c,t,n){return t&&fc(c.prototype,t),n&&fc(c,n),c}var Qh=dt,dc=lt,Zh=Hh,Ta=fl,e_=new Qh("RequestSender"),va={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},dl=function(){function c(t,n,o){zh(this,c),this._ua=t,this._eventHandlers=o,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var a in va)Object.prototype.hasOwnProperty.call(va,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=va[a]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==dc.BYE||this._method!==dc.ACK)&&this._eventHandlers.onTransportError()}return Xh(c,[{key:"send",value:function(){var n=this,o={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new Ta.InviteClientTransaction(this._ua,this._ua.transport,this._request,o);break;case"ACK":this.clientTransaction=new Ta.AckClientTransaction(this._ua,this._ua.transport,this._request,o);break;default:this.clientTransaction=new Ta.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,o)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var o,a,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(o=n.parseHeader("www-authenticate"),a="authorization"):(o=n.parseHeader("proxy-authenticate"),a="proxy-authorization"),!o){e_.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&o.stale===!0){if(this._auth||(this._auth=new Zh({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,o)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),o.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function s_(c,t,n){return t&&hc(c.prototype,t),n&&hc(c,n),c}var n_=dt,Sa=It(),pn=lt,_c=Es,pc=dl,Di=new n_("Registrator"),Fl=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=Sa.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 o in n)if(Object.prototype.hasOwnProperty.call(n,o)){var a=n[o];this._extraContactParams+=";".concat(o),a&&(this._extraContactParams+="=".concat(a))}}},{key:"register",value:function(){var n=this;if(this._registering){Di.debug("Register request in progress...");return}var o=this._extraHeaders.slice();o.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),o.push("Expires: ".concat(this._expires));var a=new _c.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),s=new pc(this._ua,a,{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(_){if(_.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(_.status_code):break;case/^2[0-9]{2}$/.test(_.status_code):{if(n._registering=!1,!_.hasHeader("Contact")){Di.debug("no Contact header in response to REGISTER, response ignored");break}var d=_.headers.Contact.reduce(function(E,A){return E.concat(A.parsed)},[]),h=d.find(function(E){return n._sipInstance===E.getParam("+sip.instance")&&n._reg_id===parseInt(E.getParam("reg-id"))});if(h||(h=d.find(function(E){return E.uri.user===n._ua.contact.uri.user})),!h){Di.debug("no Contact header pointing to us, response ignored");break}var g=h.getParam("expires");!g&&_.hasHeader("expires")&&(g=_.getHeader("expires")),g||(g=n._expires),g=Number(g),g<Fl&&(g=Fl);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),h.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=h.getParam("temp-gruu").replace(/"/g,"")),h.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=h.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:_}));break}case/^423$/.test(_.status_code):{_.hasHeader("min-expires")?(n._expires=Number(_.getHeader("min-expires")),n._expires<Fl&&(n._expires=Fl),n.register()):(Di.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(_,pn.causes.SIP_FAILURE_CODE));break}default:{var S=Sa.sipErrorCause(_.status_code);n._registrationFailure(_,S)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){Di.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var a=this._extraHeaders.slice();o.all?a.push("Contact: *".concat(this._extraContactParams)):a.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),a.push("Expires: 0");var s=new _c.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),r=new pc(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(d){switch(!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):n._unregistered(d);break;default:{var h=Sa.sipErrorCause(d.status_code);n._unregistered(d,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,o){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:o}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:o}))}},{key:"_unregistered",value:function(n,o){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:o||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 mc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function l_(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var Ea=lt,Vl=fl,o_=dl,ya={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},a_=function(){function c(t,n,o){i_(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=o,this._reattempt=!1,this._reattemptTimer=null;for(var a in ya)Object.prototype.hasOwnProperty.call(ya,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=ya[a]))}return l_(c,[{key:"send",value:function(){var n=this,o=new o_(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(o.send(),(this._request.method===Ea.INVITE||this._request.method===Ea.UPDATE&&this._request.body)&&o.clientTransaction.state!==Vl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var a=function s(){(o.clientTransaction.state===Vl.C.STATUS_ACCEPTED||o.clientTransaction.state===Vl.C.STATUS_COMPLETED||o.clientTransaction.state===Vl.C.STATUS_TERMINATED)&&(o.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};o.clientTransaction.on("stateChanged",a)}}},{key:"_receiveResponse",value:function(n){var o=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===Ea.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(){o._dialog.isTerminated()||(o._reattempt=!0,o.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 gc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Tc(c,t,n){return t&&gc(c.prototype,t),n&&gc(c,n),c}var c_=dt,vc=Es,Ms=lt,Ni=fl,f_=a_,Ca=It(),Aa=new c_("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},d_=function(){Tc(c,null,[{key:"C",get:function(){return Ls}}]);function c(t,n,o){var a=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 vc.IncomingResponse&&(a=n.status_code<200?Ls.STATUS_EARLY:Ls.STATUS_CONFIRMED);var s=n.parseHeader("contact");o==="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=a,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):o==="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=a,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),Aa.debug("new ".concat(o," dialog created with status ").concat(this._state===Ls.STATUS_EARLY?"EARLY":"CONFIRMED"))}return Tc(c,[{key:"isTerminated",value:function(){return this._status===Ls.STATUS_TERMINATED}},{key:"update",value:function(n,o){this._state=Ls.STATUS_CONFIRMED,Aa.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),o==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Aa.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ls.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var o=this,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=Ca.cloneArray(a.extraHeaders),r=Ca.cloneObject(a.eventHandlers),_=a.body||null,d=this._createRequest(n,s,_);r.onAuthenticated=function(){o._local_seqnum+=1};var h=new f_(this,d,r);return h.send(),d}},{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,o,a){o=Ca.cloneArray(o),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 vc.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},o,a);return r}},{key:"_checkInDialogRequest",value:function(n){var o=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 a=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(a)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Ni.C.STATUS_ACCEPTED||n.server_transaction.state===Ni.C.STATUS_COMPLETED||n.server_transaction.state===Ni.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),o._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ni.C.STATUS_ACCEPTED&&(o._remote_target=n.parseHeader("contact").uri)})}else n.method===Ms.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ni.C.STATUS_COMPLETED&&(o._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}(),ku={exports:{}};function yo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?yo=function(n){return typeof n}:yo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},yo(c)}function h_(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function __(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(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(o,a){return o.__proto__=a,o},hu(c,t)}function m_(c){var t=v_();return function(){var o=Uo(c),a;if(t){var s=Uo(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return g_(this,a)}}function g_(c,t){return t&&(yo(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 Uo(c){return Uo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Uo(c)}var S_=ft.EventEmitter,E_=dt,y_=lt,C_=Ws,Ec=It(),A_=new E_("RTCSession:DTMF"),rd={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ku.exports=function(c){p_(n,c);var t=m_(n);function n(o){var a;return h_(this,n),a=t.call(this),a._session=o,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return __(n,[{key:"send",value:function(a){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(a===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new C_.InvalidStateError(this._session.status);var _=Ec.cloneArray(r.extraHeaders);if(this.eventHandlers=Ec.cloneObject(r.eventHandlers),typeof a=="string")a=a.toUpperCase();else if(typeof a=="number")a=a.toString();else throw new TypeError("Invalid tone: ".concat(a));if(a.match(/^[0-9A-DR#*]$/))this._tone=a;else throw new TypeError("Invalid tone: ".concat(a));this._duration=r.duration,_.push("Content-Type: application/dtmf-relay");var d="Signal=".concat(this._tone,`\r
|
|
47
|
+
`);d+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(y_.INFO,{extraHeaders:_,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:d})}},{key:"init_incoming",value:function(a){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=a,a.reply(200),a.body){var _=a.body.split(`
|
|
48
|
+
`);_.length>=1&&s.test(_[0])&&(this._tone=_[0].replace(s,"$2")),_.length>=2&&r.test(_[1])&&(this._duration=parseInt(_[1].replace(r,"$2"),10))}this._duration||(this._duration=rd.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:a}):A_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(S_);ku.exports.C=rd;var R_=ku.exports;function Co(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Co=function(n){return typeof n}:Co=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Co(c)}function b_(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function I_(c,t,n){return t&&yc(c.prototype,t),n&&yc(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&&_u(c,t)}function _u(c,t){return _u=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},_u(c,t)}function O_(c){var t=x_();return function(){var o=ko(c),a;if(t){var s=ko(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return D_(this,a)}}function D_(c,t){return t&&(Co(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 x_(){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 ko(c){return ko=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},ko(c)}var U_=ft.EventEmitter,k_=lt,P_=Ws,M_=It(),L_=function(c){w_(n,c);var t=O_(n);function n(o){var a;return b_(this,n),a=t.call(this),a._session=o,a._direction=null,a._contentType=null,a._body=null,a}return I_(n,[{key:"send",value:function(a,s){var r=this,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",a===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new P_.InvalidStateError(this._session.status);this._contentType=a,this._body=s;var d=M_.cloneArray(_.extraHeaders);d.push("Content-Type: ".concat(a)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(k_.INFO,{extraHeaders:d,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(a){this._direction="incoming",this.request=a,a.reply(200),this._contentType=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,this._body=a.body,this._session.newInfo({originator:"remote",info:this,request:a})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(U_);function $_(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function H_(c,t,n){return t&&Cc(c.prototype,t),n&&Cc(c,n),c}var F_=dt,Ac=lt,V_=new F_("RTCSession:ReferNotifier"),Ra={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},j_=function(){function c(t,n,o){$_(this,c),this._session=t,this._id=n,this._expires=o||Ra.expires,this._active=!0,this.notify(100)}return H_(c,[{key:"notify",value:function(n,o){if(V_.debug("notify()"),this._active!==!1){o=o||Ac.REASON_PHRASE[n]||"";var a;n>=200?a="terminated;reason=noresource":a="active;expires=".concat(this._expires),this._session.sendRequest(Ac.NOTIFY,{extraHeaders:["Event: ".concat(Ra.event_type,";id=").concat(this._id),"Subscription-State: ".concat(a),"Content-Type: ".concat(Ra.body_type)],body:"SIP/2.0 ".concat(n," ").concat(o),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function Ao(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ao=function(n){return typeof n}:Ao=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ao(c)}function q_(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function B_(c,t,n){return t&&Rc(c.prototype,t),n&&Rc(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&&pu(c,t)}function pu(c,t){return pu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},pu(c,t)}function W_(c){var t=J_();return function(){var o=Po(c),a;if(t){var s=Po(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return K_(this,a)}}function K_(c,t){return t&&(Ao(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 Po(c){return Po=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Po(c)}var z_=ft.EventEmitter,X_=dt,xi=lt,Q_=as(),bc=It(),mn=new X_("RTCSession:ReferSubscriber"),Z_=function(c){G_(n,c);var t=W_(n);function n(o){var a;return q_(this,n),a=t.call(this),a._id=null,a._session=o,a}return B_(n,[{key:"sendRefer",value:function(a){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};mn.debug("sendRefer()");var _=bc.cloneArray(r.extraHeaders),d=bc.cloneObject(r.eventHandlers);for(var h in d)Object.prototype.hasOwnProperty.call(d,h)&&this.on(h,d[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(a).concat(g?"?Replaces=".concat(g):"",">");if(_.push(T),!_.some(function(A){return A.toLowerCase().startsWith("referred-by:")})){var S="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");_.push(S)}_.push("Contact: ".concat(this._session.contact));var E=this._session.sendRequest(xi.REFER,{extraHeaders:_,eventHandlers:{onSuccessResponse:function(R){s._requestSucceeded(R)},onErrorResponse:function(R){s._requestFailed(R,xi.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,xi.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,xi.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,xi.causes.DIALOG_ERROR)}}});this._id=E.cseq}},{key:"receiveNotify",value:function(a){if(mn.debug("receiveNotify()"),!!a.body){var s=Q_.parse(a.body.trim().split(`\r
|
|
49
|
+
`,1)[0],"Status_Line");if(s===-1){mn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(a.body,'"'));return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:a,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:a,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:a,status_line:s});break;default:this.emit("failed",{request:a,status_line:s});break}}}},{key:"_requestSucceeded",value:function(a){mn.debug("REFER succeeded"),mn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:a})}},{key:"_requestFailed",value:function(a,s){mn.debug("REFER failed"),mn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:a||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(z_);function Ro(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ro=function(n){return typeof n}:Ro=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ro(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 o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
50
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var h=n.next();return s=h.done,h},e:function(h){r=!0,_=h},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}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,o=new Array(t);n<t;n++)o[n]=c[n];return o}function tp(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Oc(c,t,n){return t&&wc(c.prototype,t),n&&wc(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&&mu(c,t)}function mu(c,t){return mu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},mu(c,t)}function np(c){var t=lp();return function(){var o=Mo(c),a;if(t){var s=Mo(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return rp(this,a)}}function rp(c,t){return t&&(Ro(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 Mo(c){return Mo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Mo(c)}var op=ft.EventEmitter,Dc=kt,ap=dt,ce=lt,gn=Ws,Nc=fl,Be=It(),Ui=nd,up=Es,jl=d_,cp=dl,Pt=R_,xc=L_,fp=j_,dp=Z_,Uc=Ks(),Y=new ap("RTCSession"),ee={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},ql=["audio","video"],hp=function(c){sp(n,c);var t=np(n);Oc(n,null,[{key:"C",get:function(){return ee}}]);function n(o){var a;return tp(this,n),Y.debug("new"),a=t.call(this),a._id=null,a._ua=o,a._status=ee.STATUS_NULL,a._dialog=null,a._earlyDialogs={},a._contact=null,a._from_tag=null,a._to_tag=null,a._connection=null,a._connectionPromiseQueue=Promise.resolve(),a._request=null,a._is_canceled=!1,a._cancel_reason="",a._is_confirmed=!1,a._late_sdp=!1,a._rtcOfferConstraints=null,a._rtcAnswerConstraints=null,a._localMediaStream=null,a._localMediaStreamLocallyGenerated=!1,a._rtcReady=!0,a._iceReady=!1,a._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},a._direction=null,a._local_identity=null,a._remote_identity=null,a._start_time=null,a._end_time=null,a._tones=null,a._audioMuted=!1,a._videoMuted=!1,a._localHold=!1,a._remoteHold=!1,a._sessionTimers={enabled:a._ua.configuration.session_timers,refreshMethod:a._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},a._referSubscribers={},a._data={},a}return Oc(n,[{key:"isInProgress",value:function(){switch(this._status){case ee.STATUS_NULL:case ee.STATUS_INVITE_SENT:case ee.STATUS_1XX_RECEIVED:case ee.STATUS_INVITE_RECEIVED:case ee.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case ee.STATUS_ANSWERED:case ee.STATUS_WAITING_FOR_ACK:case ee.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case ee.STATUS_CANCELED:case ee.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(a){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;Y.debug("connect()");var _=a,d=Be.cloneObject(s.eventHandlers),h=Be.cloneArray(s.extraHeaders),g=Be.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,S=Be.cloneObject(s.pcConfig,{iceServers:[]}),E=s.rtcConstraints||null,A=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,a===void 0)throw new TypeError("Not enough arguments");if(this._status!==ee.STATUS_NULL)throw new gn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new gn.NotSupportedError("WebRTC not supported");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(_));this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var R in d)Object.prototype.hasOwnProperty.call(d,R)&&this.on(R,d[R]);this._from_tag=Be.newTag();var C=s.anonymous||!1,$={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:C,outbound:!0}),C?($.from_display_name="Anonymous",$.from_uri=new Uc("sip","anonymous","anonymous.invalid"),h.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),h.push("Privacy: id")):s.fromUserName&&($.from_uri=new Uc("sip",s.fromUserName,this._ua.configuration.uri.host),h.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&($.from_display_name=s.fromDisplayName),h.push("Contact: ".concat(this._contact)),h.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&h.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new up.InitialOutgoingInviteRequest(a,this._ua,$,h),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(S,E),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(a,s){var r=this;Y.debug("init_incoming()");var _,d=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;if(a.body&&d!=="application/sdp"){a.reply(415);return}if(this._status=ee.STATUS_INVITE_RECEIVED,this._from_tag=a.from_tag,this._id=a.call_id+this._from_tag,this._request=a,this._contact=this._ua.contact.toString(),a.hasHeader("expires")&&(_=a.getHeader("expires")*1e3),a.to_tag=Be.newTag(),!this._createDialog(a,"UAS",!0)){a.reply(500,"Missing Contact header field");return}a.body?this._late_sdp=!1:this._late_sdp=!0,this._status=ee.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){a.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),_&&(this._timers.expiresTimer=setTimeout(function(){r._status===ee.STATUS_WAITING_FOR_ANSWER&&(a.reply(487),r._failed("system",null,ce.causes.EXPIRES))},_)),this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from,s&&s(this),this._newRTCSession("remote",a),this._status!==ee.STATUS_TERMINATED&&(a.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Y.debug("answer()");var r=this._request,_=Be.cloneArray(s.extraHeaders),d=Be.cloneObject(s.mediaConstraints),h=s.mediaStream||null,g=Be.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,S=s.rtcAnswerConstraints||null,E=Be.cloneObject(s.rtcOfferConstraints),A,R=!1,C=!1,$=!1,k=!1;if(this._rtcAnswerConstraints=S,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!==ee.STATUS_WAITING_FOR_ANSWER)throw new gn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=ee.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),_.unshift("Contact: ".concat(this._contact));var re=r.parseSDP();Array.isArray(re.media)||(re.media=[re.media]);var x=_s(re.media),F;try{for(x.s();!(F=x.n()).done;){var _e=F.value;_e.type==="audio"&&(R=!0,(!_e.direction||_e.direction==="sendrecv")&&($=!0)),_e.type==="video"&&(C=!0,(!_e.direction||_e.direction==="sendrecv")&&(k=!0))}}catch(V){x.e(V)}finally{x.f()}if(h&&d.audio===!1){A=h.getAudioTracks();var pe=_s(A),P;try{for(pe.s();!(P=pe.n()).done;){var N=P.value;h.removeTrack(N)}}catch(V){pe.e(V)}finally{pe.f()}}if(h&&d.video===!1){A=h.getVideoTracks();var q=_s(A),j;try{for(q.s();!(j=q.n()).done;){var K=j.value;h.removeTrack(K)}}catch(V){q.e(V)}finally{q.f()}}!h&&d.audio===void 0&&(d.audio=$),!h&&d.video===void 0&&(d.video=k),!h&&!R&&!E.offerToReceiveAudio&&(d.audio=!1),!h&&!C&&!E.offerToReceiveVideo&&(d.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(h)return h;if(d.audio||d.video)return a._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(d).catch(function(V){throw a._status===ee.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),a._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',V),a.emit("getusermediafailed",V),new Error("getUserMedia() failed"))})}).then(function(V){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");a._localMediaStream=V,V&&V.getTracks().forEach(function(z){a._connection.addTrack(z,V)})}).then(function(){if(!a._late_sdp){var V={originator:"remote",type:"offer",sdp:r.body};Y.debug('emit "sdp"'),a.emit("sdp",V);var z=new RTCSessionDescription({type:"offer",sdp:V.sdp});return a._connectionPromiseQueue=a._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(z)}).catch(function(D){throw r.reply(488),a._failed("system",null,ce.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',D),a.emit("peerconnection:setremotedescriptionfailed",D),new Error("peerconnection.setRemoteDescription() failed")}),a._connectionPromiseQueue}}).then(function(){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");return a._connecting(r),a._late_sdp?a._createLocalDescription("offer",a._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):a._createLocalDescription("answer",S).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(V){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");a._handleSessionTimersInIncomingRequest(r,_),r.reply(200,null,_,V,function(){a._status=ee.STATUS_WAITING_FOR_ACK,a._setInvite2xxTimer(r,V),a._setACKTimer(),a._accepted("local")},function(){a._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(V){a._status!==ee.STATUS_TERMINATED&&Y.warn(V)})}},{key:"terminate",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Y.debug("terminate()");var r=s.cause||ce.causes.BYE,_=Be.cloneArray(s.extraHeaders),d=s.body,h,g=s.status_code,T=s.reason_phrase;if(this._status===ee.STATUS_TERMINATED)throw new gn.InvalidStateError(this._status);switch(this._status){case ee.STATUS_NULL:case ee.STATUS_INVITE_SENT:case ee.STATUS_1XX_RECEIVED:if(Y.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(T=T||ce.REASON_PHRASE[g]||"",h="SIP ;cause=".concat(g,' ;text="').concat(T,'"')),this._status===ee.STATUS_NULL||this._status===ee.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=h):this._status===ee.STATUS_1XX_RECEIVED&&this._request.cancel(h),this._status=ee.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case ee.STATUS_WAITING_FOR_ANSWER:case ee.STATUS_ANSWERED:if(Y.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,T,_,d),this._failed("local",null,ce.causes.REJECTED);break;case ee.STATUS_WAITING_FOR_ACK:case ee.STATUS_CONFIRMED:if(Y.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&&_.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===ee.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Nc.C.STATUS_TERMINATED){var S=this._dialog;this.receiveRequest=function(E){var A=E.method;A===ce.ACK&&(a.sendRequest(ce.BYE,{extraHeaders:_,body:d}),S.terminate())},this._request.server_transaction.on("stateChanged",function(){a._request.server_transaction.state===Nc.C.STATUS_TERMINATED&&(a.sendRequest(ce.BYE,{extraHeaders:_,body:d}),S.terminate())}),this._ended("local",null,r),this._dialog=S,this._ua.newDialog(S)}else this.sendRequest(ce.BYE,{extraHeaders:_,body:d}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(a){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Y.debug("sendDTMF() | tones: %s",a);var r=0,_=s.duration||null,d=s.interToneGap||null,h=s.transportType||ce.DTMF_TRANSPORT.INFO;if(a===void 0)throw new TypeError("Not enough arguments");if(this._status!==ee.STATUS_CONFIRMED&&this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);if(h!==ce.DTMF_TRANSPORT.INFO&&h!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(h));if(typeof a=="number"&&(a=a.toString()),!a||typeof a!="string"||!a.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(a));if(_&&!Be.isDecimal(_))throw new TypeError("Invalid tone duration: ".concat(_));if(_?_<Pt.C.MIN_DURATION?(Y.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(Pt.C.MIN_DURATION," milliseconds")),_=Pt.C.MIN_DURATION):_>Pt.C.MAX_DURATION?(Y.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(Pt.C.MAX_DURATION," milliseconds")),_=Pt.C.MAX_DURATION):_=Math.abs(_):_=Pt.C.DEFAULT_DURATION,s.duration=_,d&&!Be.isDecimal(d))throw new TypeError("Invalid interToneGap: ".concat(d));if(d?d<Pt.C.MIN_INTER_TONE_GAP?(Y.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(Pt.C.MIN_INTER_TONE_GAP," milliseconds")),d=Pt.C.MIN_INTER_TONE_GAP):d=Math.abs(d):d=Pt.C.DEFAULT_INTER_TONE_GAP,h===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(a=g.toneBuffer+a,g.insertDTMF(a,_,d));return}if(this._tones){this._tones+=a;return}this._tones=a,T.call(this);function T(){var S=this,E;if(this._status===ee.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var A=this._tones[r];if(r+=1,A===",")E=2e3;else{var R=new Pt(this);s.eventHandlers={onFailed:function(){S._tones=null}},R.send(A,s),E=_+d}setTimeout(T.bind(this),E)}}},{key:"sendInfo",value:function(a,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(Y.debug("sendInfo()"),this._status!==ee.STATUS_CONFIRMED&&this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);var _=new xc(this);_.send(a,s,r)}},{key:"mute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};Y.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&a.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&a.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};Y.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&a.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&a.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 a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(Y.debug("hold()"),this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var _={succeeded:function(){r&&r()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:_,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(Y.debug("unhold()"),this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var _={succeeded:function(){r&&r()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:_,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;Y.debug("renegotiate()");var _=s.rtcOfferConstraints||null;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var d={succeeded:function(){r&&r()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,rtcOfferConstraints:_,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,rtcOfferConstraints:_,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(a,s){var r=this;Y.debug("refer()");var _=a;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(_));var d=new dp(this);d.sendRefer(a,s);var h=d.id;return this._referSubscribers[h]=d,d.on("requestFailed",function(){delete r._referSubscribers[h]}),d.on("accepted",function(){delete r._referSubscribers[h]}),d.on("failed",function(){delete r._referSubscribers[h]}),d}},{key:"sendRequest",value:function(a,s){return Y.debug("sendRequest()"),this._dialog.sendRequest(a,s)}},{key:"receiveRequest",value:function(a){var s=this;if(Y.debug("receiveRequest()"),a.method===ce.CANCEL)(this._status===ee.STATUS_WAITING_FOR_ANSWER||this._status===ee.STATUS_ANSWERED)&&(this._status=ee.STATUS_CANCELED,this._request.reply(487),this._failed("remote",a,ce.causes.CANCELED));else switch(a.method){case ce.ACK:if(this._status!==ee.STATUS_WAITING_FOR_ACK)return;if(this._status=ee.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!a.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:a.body};Y.debug('emit "sdp"'),this.emit("sdp",r);var _=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(_)}).then(function(){s._is_confirmed||s._confirmed("remote",a)}).catch(function(h){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',h),s.emit("peerconnection:setremotedescriptionfailed",h)})}else this._is_confirmed||this._confirmed("remote",a);break;case ce.BYE:this._status===ee.STATUS_CONFIRMED||this._status===ee.STATUS_WAITING_FOR_ACK?(a.reply(200),this._ended("remote",a,ce.causes.BYE)):this._status===ee.STATUS_INVITE_RECEIVED||this._status===ee.STATUS_WAITING_FOR_ANSWER?(a.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",a,ce.causes.BYE)):a.reply(403,"Wrong Status");break;case ce.INVITE:this._status===ee.STATUS_CONFIRMED?a.hasHeader("replaces")?this._receiveReplaces(a):this._receiveReinvite(a):a.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===ee.STATUS_1XX_RECEIVED||this._status===ee.STATUS_WAITING_FOR_ANSWER||this._status===ee.STATUS_ANSWERED||this._status===ee.STATUS_WAITING_FOR_ACK||this._status===ee.STATUS_CONFIRMED){var d=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;d&&d.match(/^application\/dtmf-relay/i)?new Pt(this).init_incoming(a):d!==void 0?new xc(this).init_incoming(a):a.reply(415)}else a.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===ee.STATUS_CONFIRMED?this._receiveUpdate(a):a.reply(403,"Wrong Status");break;case ce.REFER:this._status===ee.STATUS_CONFIRMED?this._receiveRefer(a):a.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===ee.STATUS_CONFIRMED?this._receiveNotify(a):a.reply(403,"Wrong Status");break;default:a.reply(501)}}},{key:"onTransportError",value:function(){Y.warn("onTransportError()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){Y.warn("onRequestTimeout()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){Y.warn("onDialogError()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(a){Y.debug("newDTMF()"),this.emit("newDTMF",a)}},{key:"newInfo",value:function(a){Y.debug("newInfo()"),this.emit("newInfo",a)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(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)}},{key:"_close",value:function(){if(Y.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(Y.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==ee.STATUS_TERMINATED){if(this._status=ee.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(_){Y.warn("close() | error closing the RTCPeerConnection: %o",_)}for(var a in this._timers)Object.prototype.hasOwnProperty.call(this._timers,a)&&clearTimeout(this._timers[a]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var 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(a,s){var r=Ui.T1;function _(){this._status===ee.STATUS_WAITING_FOR_ACK&&(a.reply(200,null,["Contact: ".concat(this._contact)],s),r<Ui.T2&&(r=r*2,r>Ui.T2&&(r=Ui.T2)),this._timers.invite2xxTimer=setTimeout(_.bind(this),r))}this._timers.invite2xxTimer=setTimeout(_.bind(this),r)}},{key:"_setACKTimer",value:function(){var a=this;this._timers.ackTimer=setTimeout(function(){a._status===ee.STATUS_WAITING_FOR_ACK&&(Y.debug("no ACK received, terminating the session"),clearTimeout(a._timers.invite2xxTimer),a.sendRequest(ce.BYE),a._ended("remote",null,ce.causes.NO_ACK))},Ui.TIMER_H)}},{key:"_createRTCConnection",value:function(a,s){var r=this;this._connection=new RTCPeerConnection(a,s),this._connection.addEventListener("iceconnectionstatechange",function(){var _=r._connection.iceConnectionState;_==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),Y.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(a,s){var r=this;if(Y.debug("createLocalDescription()"),a!=="offer"&&a!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(a,'"'));var _=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return a==="offer"?_.createOffer(s).catch(function(d){return Y.warn('emit "peerconnection:createofferfailed" [error:%o]',d),r.emit("peerconnection:createofferfailed",d),Promise.reject(d)}):_.createAnswer(s).catch(function(d){return Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',d),r.emit("peerconnection:createanswerfailed",d),Promise.reject(d)})}).then(function(d){return _.setLocalDescription(d).catch(function(h){return r._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',h),r.emit("peerconnection:setlocaldescriptionfailed",h),Promise.reject(h)})}).then(function(){var d=s&&s.iceRestart;if(_.iceGatheringState==="complete"&&!d||_.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var h={originator:"local",type:a,sdp:_.localDescription.sdp};return Y.debug('emit "sdp"'),r.emit("sdp",h),Promise.resolve(h.sdp)}return new Promise(function(g){var T=!1,S,E;r._iceReady=!1;var A=function(){_.removeEventListener("icecandidate",S),_.removeEventListener("icegatheringstatechange",E),T=!0,r._rtcReady=!0,r._iceReady=!0;var C={originator:"local",type:a,sdp:_.localDescription.sdp};Y.debug('emit "sdp"'),r.emit("sdp",C),g(C.sdp)};_.addEventListener("icecandidate",S=function(C){var $=C.candidate;$?r.emit("icecandidate",{candidate:$,ready:A}):T||A()}),_.addEventListener("icegatheringstatechange",E=function(){_.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(a,s,r){var _=s==="UAS"?a.to_tag:a.from_tag,d=s==="UAS"?a.from_tag:a.to_tag,h=a.call_id+_+d,g=this._earlyDialogs[h];if(r)return g?!0:(g=new jl(this,a,s,jl.C.STATUS_EARLY),g.error?(Y.debug(g.error),this._failed("remote",a,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[h]=g,!0));if(this._from_tag=a.from_tag,this._to_tag=a.to_tag,g)return g.update(a,s),this._dialog=g,delete this._earlyDialogs[h],!0;var T=new jl(this,a,s);return T.error?(Y.debug(T.error),this._failed("remote",a,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(a){var s=this;Y.debug("receiveReinvite()");var r=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,_={request:a,callback:void 0,reject:h.bind(this)},d=!1;function h(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};d=!0;var S=T.status_code||403,E=T.reason_phrase||"",A=Be.cloneArray(T.extraHeaders);if(this._status!==ee.STATUS_CONFIRMED)return!1;if(S<300||S>=700)throw new TypeError("Invalid status_code: ".concat(S));a.reply(S,E,A)}if(this.emit("reinvite",_),d)return;if(this._late_sdp=!1,!a.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){a.reply(500)});return}if(r!=="application/sdp"){Y.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(T){s._status!==ee.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){Y.warn(T)});function g(T){var S=this,E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,E),this._late_sdp&&(T=this._mangleOffer(T)),a.reply(200,null,E,T,function(){S._status=ee.STATUS_WAITING_FOR_ACK,S._setInvite2xxTimer(a,T),S._setACKTimer()}),typeof _.callback=="function"&&_.callback()}}},{key:"_receiveUpdate",value:function(a){var s=this;Y.debug("receiveUpdate()");var r=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,_={request:a,callback:void 0,reject:h.bind(this)},d=!1;function h(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};d=!0;var S=T.status_code||403,E=T.reason_phrase||"",A=Be.cloneArray(T.extraHeaders);if(this._status!==ee.STATUS_CONFIRMED)return!1;if(S<300||S>=700)throw new TypeError("Invalid status_code: ".concat(S));a.reply(S,E,A)}if(this.emit("update",_),d)return;if(!a.body){g.call(this,null);return}if(r!=="application/sdp"){Y.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(T){s._status!==ee.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){Y.warn(T)});function g(T){var S=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,S),a.reply(200,null,S,T),typeof _.callback=="function"&&_.callback()}}},{key:"_processInDialogSdpOffer",value:function(a){var s=this;Y.debug("_processInDialogSdpOffer()");var r=a.parseSDP(),_=!1,d=_s(r.media),h;try{for(d.s();!(h=d.n()).done;){var g=h.value;if(ql.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")_=!0;else{_=!1;break}}}}catch(A){d.e(A)}finally{d.f()}var S={originator:"remote",type:"offer",sdp:a.body};Y.debug('emit "sdp"'),this.emit("sdp",S);var E=new RTCSessionDescription({type:"offer",sdp:S.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===ee.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(E).catch(function(A){throw a.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),s.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(s._status===ee.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&_===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&_===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===ee.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(A){throw a.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){Y.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(a){var s=this;if(Y.debug("receiveRefer()"),!a.refer_to){Y.debug("no Refer-To header field present in REFER"),a.reply(400);return}if(a.refer_to.uri.scheme!==ce.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),a.reply(416);return}a.reply(202);var r=new fp(this,a.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:a,accept:function(g,T){_.call(s,g,T)},reject:function(){d.call(s)}});function _(h){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(h=typeof h=="function"?h:null,this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(E){var A=E.response;r.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(E){var A=E.response;r.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(E){var A=E.message,R=E.cause;A?r.notify(A.status_code,A.reason_phrase):r.notify(487,R)}),a.refer_to.uri.hasHeader("replaces")){var S=decodeURIComponent(a.refer_to.uri.getHeader("replaces"));g.extraHeaders=Be.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(S))}T.connect(a.refer_to.uri.toAor(),g,h)}function d(){r.notify(603)}}},{key:"_receiveNotify",value:function(a){switch(Y.debug("receiveNotify()"),a.event||a.reply(400),a.event.event){case"refer":{var s,r;if(a.event.params&&a.event.params.id)s=a.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{a.reply(400,"Missing event id parameter");return}if(!r){a.reply(481,"Subscription does not exist");return}r.receiveNotify(a),a.reply(200);break}default:a.reply(489)}}},{key:"_receiveReplaces",value:function(a){var s=this;Y.debug("receiveReplaces()");function r(d){var h=this;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){h.terminate()}),g.init_incoming(a,d)}function _(){Y.debug("Replaced INVITE rejected by the user"),a.reply(486)}this.emit("replaces",{request:a,accept:function(h){r.call(s,h)},reject:function(){_.call(s)}})}},{key:"_sendInitialRequest",value:function(a,s,r){var _=this,d=new cp(this._ua,this._request,{onRequestTimeout:function(){_.onRequestTimeout()},onTransportError:function(){_.onTransportError()},onAuthenticated:function(g){_._request=g},onReceiveResponse:function(g){_._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(a.audio||a.video)return _._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(function(h){throw _._status===ee.STATUS_TERMINATED?new Error("terminated"):(_._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',h),_.emit("getusermediafailed",h),h)})}).then(function(h){if(_._status===ee.STATUS_TERMINATED)throw new Error("terminated");return _._localMediaStream=h,h&&h.getTracks().forEach(function(g){_._connection.addTrack(g,h)}),_._connecting(_._request),_._createLocalDescription("offer",s).catch(function(g){throw _._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(h){if(_._is_canceled||_._status===ee.STATUS_TERMINATED)throw new Error("terminated");_._request.body=h,_._status=ee.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',_._request),_.emit("sending",{request:_._request}),d.send()}).catch(function(h){_._status!==ee.STATUS_TERMINATED&&Y.warn(h)})}},{key:"_getDTMFRTPSender",value:function(){var a=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(a&&a.dtmf)){Y.warn("sendDTMF() | no local audio track to send DTMF with");return}return a.dtmf}},{key:"_receiveInviteResponse",value:function(a){var s=this;if(Y.debug("receiveInviteResponse()"),this._dialog&&a.status_code>=200&&a.status_code<=299)if(this._dialog.id.call_id===a.call_id&&this._dialog.id.local_tag===a.from_tag&&this._dialog.id.remote_tag===a.to_tag){this.sendRequest(ce.ACK);return}else{var r=new jl(this,a,"UAC");if(r.error!==void 0){Y.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){a.status_code>=100&&a.status_code<200?this._request.cancel(this._cancel_reason):a.status_code>=200&&a.status_code<299&&this._acceptAndTerminate(a);return}if(!(this._status!==ee.STATUS_INVITE_SENT&&this._status!==ee.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(a.status_code):this._status=ee.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(a.status_code):{if(!a.to_tag){Y.debug("1xx response received without to tag");break}if(a.hasHeader("contact")&&!this._createDialog(a,"UAC",!0))break;if(this._status=ee.STATUS_1XX_RECEIVED,!a.body){this._progress("remote",a);break}var _={originator:"remote",type:"answer",sdp:a.body};Y.debug('emit "sdp"'),this.emit("sdp",_);var d=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){return s._progress("remote",a)}).catch(function(S){Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),s.emit("peerconnection:setremotedescriptionfailed",S)});break}case/^2[0-9]{2}$/.test(a.status_code):{if(this._status=ee.STATUS_CONFIRMED,!a.body){this._acceptAndTerminate(a,400,ce.causes.MISSING_SDP),this._failed("remote",a,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(a,"UAC"))break;var h={originator:"remote",type:"answer",sdp:a.body};Y.debug('emit "sdp"'),this.emit("sdp",h);var g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(S){return s._connection.setLocalDescription(S)}).catch(function(S){s._acceptAndTerminate(a,500,S.toString()),s._failed("local",a,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(a),s._accepted("remote",a),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(S){s._acceptAndTerminate(a,488,"Not Acceptable Here"),s._failed("remote",a,ce.causes.BAD_MEDIA_DESCRIPTION),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),s.emit("peerconnection:setremotedescriptionfailed",S)})});break}default:{var T=Be.sipErrorCause(a.status_code);this._failed("remote",a,T)}}}},{key:"_sendReinvite",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Y.debug("sendReinvite()");var r=Be.cloneArray(s.extraHeaders),_=Be.cloneObject(s.eventHandlers),d=s.rtcOfferConstraints||this._rtcOfferConstraints||null,h=!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 a._createLocalDescription("offer",d)}).then(function(S){S=a._mangleOffer(S);var E={originator:"local",type:"offer",sdp:S};Y.debug('emit "sdp"'),a.emit("sdp",E),a.sendRequest(ce.INVITE,{extraHeaders:r,body:S,eventHandlers:{onSuccessResponse:function(R){g.call(a,R),h=!0},onErrorResponse:function(R){T.call(a,R)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){T()});function g(S){var E=this;if(this._status!==ee.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!h)){if(this._handleSessionTimersInIncomingResponse(S),S.body){if(!S.hasHeader("Content-Type")||S.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var A={originator:"remote",type:"answer",sdp:S.body};Y.debug('emit "sdp"'),this.emit("sdp",A);var R=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return E._connection.setRemoteDescription(R)}).then(function(){_.succeeded&&_.succeeded(S)}).catch(function(C){T.call(E),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',C),E.emit("peerconnection:setremotedescriptionfailed",C)})}}function T(S){_.failed&&_.failed(S)}}},{key:"_sendUpdate",value:function(){var a=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Y.debug("sendUpdate()");var r=Be.cloneArray(s.extraHeaders),_=Be.cloneObject(s.eventHandlers),d=s.rtcOfferConstraints||this._rtcOfferConstraints||null,h=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")),h?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",d)}).then(function(E){E=a._mangleOffer(E);var A={originator:"local",type:"offer",sdp:E};Y.debug('emit "sdp"'),a.emit("sdp",A),a.sendRequest(ce.UPDATE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(C){T.call(a,C),g=!0},onErrorResponse:function(C){S.call(a,C)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){S.call(a)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(A){T.call(a,A)},onErrorResponse:function(A){S.call(a,A)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}});function T(E){var A=this;if(this._status!==ee.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(E),h){if(E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){S.call(this);return}}else{S.call(this);return}var R={originator:"remote",type:"answer",sdp:E.body};Y.debug('emit "sdp"'),this.emit("sdp",R);var C=new RTCSessionDescription({type:"answer",sdp:R.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(C)}).then(function(){_.succeeded&&_.succeeded(E)}).catch(function($){S.call(A),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),A.emit("peerconnection:setremotedescriptionfailed",$)})}else _.succeeded&&_.succeeded(E)}function S(E){_.failed&&_.failed(E)}}},{key:"_acceptAndTerminate",value:function(a,s,r){Y.debug("acceptAndTerminate()");var _=[];s&&(r=r||ce.REASON_PHRASE[s]||"",_.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(a,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:_})),this._status=ee.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(a){if(!this._localHold&&!this._remoteHold)return a;if(a=Dc.parse(a),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");var s=_s(a.media),r;try{for(s.s();!(r=s.n()).done;){var _=r.value;ql.indexOf(_.type)!==-1&&(_.direction?_.direction==="sendrecv"?_.direction="sendonly":_.direction==="recvonly"&&(_.direction="inactive"):_.direction="sendonly")}}catch(A){s.e(A)}finally{s.f()}}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");var d=_s(a.media),h;try{for(d.s();!(h=d.n()).done;){var g=h.value;ql.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){d.e(A)}finally{d.f()}}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(a.media),S;try{for(T.s();!(S=T.n()).done;){var E=S.value;ql.indexOf(E.type)!==-1&&(E.direction?E.direction==="sendrecv"?E.direction="recvonly":E.direction==="recvonly"&&(E.direction="inactive"):E.direction="recvonly")}}catch(A){T.e(A)}finally{T.f()}}return Dc.write(a)}},{key:"_setLocalMediaStatus",value:function(){var a=!0,s=!0;(this._localHold||this._remoteHold)&&(a=!1,s=!1),this._audioMuted&&(a=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!a),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(a,s){if(this._sessionTimers.enabled){var r;a.session_expires&&a.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,r=a.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(a){if(this._sessionTimers.enabled){var s;a.session_expires&&a.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,s=a.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var a=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){a._status!==ee.STATUS_TERMINATED&&a._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),a._sessionTimers.refreshMethod===ce.UPDATE?a._sendUpdate():a._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){a._status!==ee.STATUS_TERMINATED&&(Y.warn("runSessionTimer() | timer expired, terminating the session"),a.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(a){var s=this._connection.getSenders().filter(function(h){return h.track&&h.track.kind==="audio"}),r=_s(s),_;try{for(r.s();!(_=r.n()).done;){var d=_.value;d.track.enabled=!a}}catch(h){r.e(h)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(a){var s=this._connection.getSenders().filter(function(h){return h.track&&h.track.kind==="video"}),r=_s(s),_;try{for(r.s();!(_=r.n()).done;){var d=_.value;d.track.enabled=!a}}catch(h){r.e(h)}finally{r.f()}}},{key:"_newRTCSession",value:function(a,s){Y.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:a,session:this,request:s})}},{key:"_connecting",value:function(a){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:a})}},{key:"_progress",value:function(a,s){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:a,response:s||null})}},{key:"_accepted",value:function(a,s){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:a,response:s||null})}},{key:"_confirmed",value:function(a,s){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:a,ack:s||null})}},{key:"_ended",value:function(a,s,r){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:a,message:s||null,cause:r})}},{key:"_failed",value:function(a,s,r){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:a,message:s||null,cause:r}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:a,message:s||null,cause:r})}},{key:"_onhold",value:function(a){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:a})}},{key:"_onunhold",value:function(a){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:a})}},{key:"_onmute",value:function(a){var s=a.audio,r=a.video;Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(a){var s=a.audio,r=a.video;Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{key:"C",get:function(){return ee}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(a){this._data=a}},{key:"status",get:function(){return this._status}}]),n}(op);function bo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?bo=function(n){return typeof n}:bo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bo(c)}function _p(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function pp(c,t,n){return t&&kc(c.prototype,t),n&&kc(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&&gu(c,t)}function gu(c,t){return gu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},gu(c,t)}function gp(c){var t=Sp();return function(){var o=Lo(c),a;if(t){var s=Lo(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return Tp(this,a)}}function Tp(c,t){return t&&(bo(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 Sp(){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 Lo(c){return Lo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Lo(c)}var Ep=ft.EventEmitter,yp=dt,ba=lt,Cp=Es,ki=It(),Ap=dl,Pc=Ws,Rp=Ks(),Bl=new yp("Message"),bp=function(c){mp(n,c);var t=gp(n);function n(o){var a;return _p(this,n),a=t.call(this),a._ua=o,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return pp(n,[{key:"send",value:function(a,s){var r=this,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},d=a;if(a===void 0||s===void 0)throw new TypeError("Not enough arguments");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(d));var h=ki.cloneArray(_.extraHeaders),g=ki.cloneObject(_.eventHandlers),T=_.contentType||"text/plain",S={};_.fromUserName&&(S.from_uri=new Rp("sip",_.fromUserName,this._ua.configuration.uri.host),h.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),_.fromDisplayName&&(S.from_display_name=_.fromDisplayName);for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);h.push("Content-Type: ".concat(T)),this._request=new Cp.OutgoingRequest(ba.MESSAGE,a,this._ua,S,h),s&&(this._request.body=s);var A=new Ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(C){r._receiveResponse(C)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newMessage("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=ki.cloneArray(a.extraHeaders),r=a.body;if(this._direction!=="incoming")throw new Pc.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 a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=a.status_code||480,r=a.reason_phrase,_=ki.cloneArray(a.extraHeaders),d=a.body;if(this._direction!=="incoming")throw new Pc.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)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var s=ki.sipErrorCause(a.status_code);this._failed("remote",a,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,ba.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,ba.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(a,s){a==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):a==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:a,message:this,request:s})}},{key:"_failed",value:function(a,s,r){Bl.debug("MESSAGE failed"),this._close(),Bl.debug('emit "failed"'),this.emit("failed",{originator:a,response:s||null,cause:r})}},{key:"_succeeded",value:function(a,s){Bl.debug("MESSAGE succeeded"),this._close(),Bl.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,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}(Ep);function Io(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Io=function(n){return typeof n}:Io=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Io(c)}function Ip(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function wp(c,t,n){return t&&Mc(c.prototype,t),n&&Mc(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&&Tu(c,t)}function Tu(c,t){return Tu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},Tu(c,t)}function Dp(c){var t=Up();return function(){var o=$o(c),a;if(t){var s=$o(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return Np(this,a)}}function Np(c,t){return t&&(Io(t)==="object"||typeof t=="function")?t:xp(c)}function xp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Up(){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 $o(c){return $o=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},$o(c)}var kp=ft.EventEmitter,Pp=dt,Ia=lt,Mp=Es,Pi=It(),Lp=dl,Lc=Ws,Gl=new Pp("Options"),$p=function(c){Op(n,c);var t=Dp(n);function n(o){var a;return Ip(this,n),a=t.call(this),a._ua=o,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return wp(n,[{key:"send",value:function(a,s){var r=this,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},d=a;if(a===void 0)throw new TypeError("A target is required for OPTIONS");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(d));var h=Pi.cloneArray(_.extraHeaders),g=Pi.cloneObject(_.eventHandlers),T=_.contentType||"application/sdp";for(var S in g)Object.prototype.hasOwnProperty.call(g,S)&&this.on(S,g[S]);h.push("Content-Type: ".concat(T)),this._request=new Mp.OutgoingRequest(Ia.OPTIONS,a,this._ua,null,h),s&&(this._request.body=s);var E=new Lp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(R){r._receiveResponse(R)}});this._newOptions("local",this._request),E.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newOptions("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Pi.cloneArray(a.extraHeaders),r=a.body;if(this._direction!=="incoming")throw new Lc.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 a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=a.status_code||480,r=a.reason_phrase,_=Pi.cloneArray(a.extraHeaders),d=a.body;if(this._direction!=="incoming")throw new Lc.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)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var s=Pi.sipErrorCause(a.status_code);this._failed("remote",a,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Ia.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Ia.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(a,s){a==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):a==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:a,message:this,request:s})}},{key:"_failed",value:function(a,s,r){Gl.debug("OPTIONS failed"),this._close(),Gl.debug('emit "failed"'),this.emit("failed",{originator:a,response:s||null,cause:r})}},{key:"_succeeded",value:function(a,s){Gl.debug("OPTIONS succeeded"),this._close(),Gl.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,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}(kp),Pu={},Hp=dt,wa=It(),Fp=as(),Mi=new Hp("Socket");Pu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return Mi.warn("undefined JsSIP.Socket instance"),!1;try{if(!wa.isString(c.url))throw Mi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wa.isString(c.via_transport))throw Mi.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 Mi.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(!wa.isFunction(c[t]))throw Mi.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 Vp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function $c(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function jp(c,t,n){return t&&$c(c.prototype,t),n&&$c(c,n),c}var qp=dt,Bp=Pu,Hc=lt,Nt=new qp("Transport"),jt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Hc.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Hc.CONNECTION_RECOVERY_MAX_INTERVAL}},Gp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:jt.recovery_options;Vp(this,c),Nt.debug("new()"),this.status=jt.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(o){Nt.warn("cannot use TextDecoder: ".concat(o))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(o){if(!Bp.isSocket(o.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(o.weight&&!Number(o.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:o.socket,weight:o.weight||0,status:jt.SOCKET_STATUS_READY})},this),this._getSocket()}return jp(c,[{key:"connect",value:function(){if(Nt.debug("connect()"),this.isConnected()){Nt.debug("Transport is already connected");return}else if(this.isConnecting()){Nt.debug("Transport is connecting");return}this.close_requested=!1,this.status=jt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Nt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=jt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Nt.debug("send()"),!this.isConnected())return Nt.warn("unable to send message, transport is not connected"),!1;var o=n.toString();return Nt.debug(`sending message:
|
|
51
51
|
|
|
52
|
-
`.concat(
|
|
53
|
-
`)),this.socket.send(
|
|
52
|
+
`.concat(o,`
|
|
53
|
+
`)),this.socket.send(o)}},{key:"isConnected",value:function(){return this.status===jt.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===jt.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var n=this;this.recover_attempts+=1;var o=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);o<this.recovery_options.min_interval?o=this.recovery_options.min_interval:o>this.recovery_options.max_interval&&(o=this.recovery_options.max_interval),Nt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(o," seconds")),this.recovery_timer=setTimeout(function(){!n.close_requested&&!(n.isConnected()||n.isConnecting())&&(n._getSocket(),n.connect())},o*1e3)}},{key:"_getSocket",value:function(){var n=[];if(this.sockets.forEach(function(a){a.status!==jt.SOCKET_STATUS_ERROR&&(n.length===0?n.push(a):a.weight>n[0].weight?n=[a]:a.weight===n[0].weight&&n.push(a))}),n.length===0){this.sockets.forEach(function(a){a.status=jt.SOCKET_STATUS_READY}),this._getSocket();return}var o=Math.floor(Math.random()*n.length);this.socket=n[o].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=jt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(n,o,a){this.status=jt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:n,code:o,reason:a}),!this.close_requested&&(this.sockets.forEach(function(s){this.socket===s.socket&&(s.status=jt.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
|
|
54
54
|
`){Nt.debug("received message with CRLF Keep Alive response");return}else if(typeof n!="string"){try{this.textDecoder?n=this.textDecoder.decode(n):n=String.fromCharCode.apply(null,new Uint8Array(n))}catch{Nt.debug("received binary message failed to be converted into string, message discarded");return}Nt.debug(`received binary message:
|
|
55
55
|
|
|
56
56
|
`.concat(n,`
|
|
57
57
|
`))}else Nt.debug(`received text message:
|
|
58
58
|
|
|
59
59
|
`.concat(n,`
|
|
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}(),
|
|
61
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var
|
|
62
|
-
`);if(
|
|
63
|
-
`,n),
|
|
64
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var
|
|
65
|
-
`),
|
|
66
|
-
`)}}catch(_){
|
|
67
|
-
`),
|
|
68
|
-
`),
|
|
69
|
-
`),
|
|
70
|
-
`),
|
|
71
|
-
`,
|
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var d=n.next();return s=d.done,d},e:function(d){r=!0,_=d},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}function om(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 cr=bt(),yn=lt,wo=os(),Gc=Ks(),Oo=Pu,Do=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(cr.createRandomToken(12),".invalid")};var Kl={mandatory:{sockets:function(t){var n=[];if(Oo.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=qc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&Oo.isSocket(s.socket)?n.push(s):Oo.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(wo.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(cr.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(cr.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=wo.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)),wo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(cr.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(cr.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=qc(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 Kl.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=Kl.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Do.ConfigurationError(n,a)}else throw new Do.ConfigurationError(n);for(var s in Kl.optional)if(t.hasOwnProperty(s)){var r=t[s];if(cr.isEmpty(r))continue;var _=Kl.optional[s](r);if(_!==void 0)c[s]=_;else throw new Do.ConfigurationError(s,r)}};function ba(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ba=function(n){return typeof n}:ba=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ba(c)}function um(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 cm(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&&Su(c,t)}function Su(c,t){return Su=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Su(c,t)}function fm(c){var t=dm();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 hm(this,o)}}function hm(c,t){return t&&(ba(t)==="object"||typeof t=="function")?t:ah(c)}function ah(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function dm(){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 _m=ft.EventEmitter,pm=ht,pt=lt,mm=n_,Yc=hp,Jc=Rp,zc=Lp,No=fl,gm=Bp,Yl=bt(),Tm=Ws,vm=Ks(),Sm=rh,Uo=Es,Em=em,xo=Lu,Ve=new pm("UA"),Tt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},ym=function(c){cm(n,c);var t=fm(n);Kc(n,null,[{key:"C",get:function(){return Tt}}]);function n(a){var o;if(um(this,n),Ve.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 mm(ah(o)),o}return Kc(n,[{key:"start",value:function(){Ve.debug("start()"),this._status===Tt.STATUS_INIT?this._transport.connect():this._status===Tt.STATUS_USER_CLOSED?(Ve.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?Ve.debug("UA is in READY status, not restarted"):Ve.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){Ve.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(o){Ve.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){Ve.debug("call()");var r=new Yc(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){Ve.debug("sendMessage()");var _=new Jc(this);return _.send(o,s,r),_}},{key:"sendOptions",value:function(o,s,r){Ve.debug("sendOptions()");var _=new zc(this);return _.send(o,s,r),_}},{key:"terminateSessions",value:function(o){Ve.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(Ve.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){Ve.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){Ve.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var _ in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,_))try{this._applicants[_].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 Yl.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:Ve.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return Ve.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){Ve.debug("Request-URI does not point to us"),o.method!==pt.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===pt.SIPS){o.reply_sl(416);return}if(!No.checkTransaction(this,o)){if(s===pt.INVITE?new No.InviteServerTransaction(this,this._transport,o):s!==pt.ACK&&s!==pt.CANCEL&&new No.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 _=new Jc(this);_.init_incoming(o)}else if(s===pt.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,d;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===pt.NOTIFY?(d=this._findSession(o),d?d.receiveRequest(o):(Ve.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?(d=h.owner,d.isEnded()?o.reply(603):d.receiveRequest(o)):o.reply(481)}else d=new Yc(this),d.init_incoming(o);else Ve.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case pt.BYE:o.reply(481);break;case pt.CANCEL:d=this._findSession(o),d?d.receiveRequest(o):Ve.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,_=o.to_tag,h=s+r,d=this._sessions[h],g=s+_,T=this._sessions[g];return d||T||null}},{key:"_findDialog",value:function(o,s,r){var _=o+s+r,h=this._dialogs[_];return h||(_=o+r+s,h=this._dialogs[_],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=Yl.newUUID()),this._configuration.jssip_id=Yl.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new gm(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=Cm.bind(this),this._transport.ondisconnect=Rm.bind(this),this._transport.ondata=Im.bind(this)}catch(g){throw Ve.warn(g),new Tm.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 vm("sip",Yl.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]:{},S=T.anonymous||null,E=T.outbound||null,A="<";return S?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),E&&(S?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var _=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(_.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));Ve.debug("configuration parameters after validation:");for(var d in this._configuration)if(Object.prototype.hasOwnProperty.call(xo.settings,d))switch(d){case"uri":case"registrar_server":Ve.debug("- ".concat(d,": ").concat(this._configuration[d]));break;case"password":case"ha1":case"authorization_jwt":Ve.debug("- ".concat(d,": NOT SHOWN"));break;default:Ve.debug("- ".concat(d,": ").concat(JSON.stringify(this._configuration[d])))}}},{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}(_m);function Am(c){this.emit("connecting",c)}function Cm(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 Rm(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 Im(c){var t=c.transport,n=c.message;if(n=Sm.parseMessage(n,this),!!n&&!(this._status===Tt.STATUS_USER_CLOSED&&n instanceof Uo.IncomingRequest)&&Em(n,this,t)){if(n instanceof Uo.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Uo.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 bm(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 wm(c,t,n){return t&&Xc(c.prototype,t),n&&Xc(c,n),c}var Om=ht,Dm=os(),Ot=new Om("WebSocketInterface"),Nm=function(){function c(t){bm(this,c),Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=Dm.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 wm(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}(),Eu=Ha,Um=lt,xm=Ws,Pm=bt(),km=ym,Mm=Ks(),Lm=Ou(),$m=os(),Hm=Nm,Fm=mr("JsSIP");Fm("version %s",Eu.version);var Qc={C:Um,Exceptions:xm,Utils:Pm,UA:km,URI:Mm,NameAddrHeader:Lm,WebSocketInterface:Hm,Grammar:$m,debug:mr,get name(){return Eu.title},get version(){return Eu.version}};const ar=mr,or="JsSIP";var ut=class{constructor(t){t?(this._debug=ar.default(`${or}:${t}`),this._warn=ar.default(`${or}:WARN:${t}`),this._error=ar.default(`${or}:ERROR:${t}`)):(this._debug=ar.default(or),this._warn=ar.default(`${or}:WARN`),this._error=ar.default(`${or}: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 Ga=ze(ut),Zc=Ha;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 H=ze(De);var et={},Po,ef;function $u(){if(ef)return Po;ef=1;const c=ys(),t=Zt();return Po=class oh{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 oh(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}},Po}var ko,tf;function Zt(){return tf||(tf=1,ko=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:d,DIGIT:g,ALPHA:T,HEXDIG:S,WSP:E,OCTET:A,DQUOTE:C,SP:R,HTAB:k,alphanum:M,reserved:ie,unreserved:N,mark:V,escaped:Ee,LWS:ve,SWS:L,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:q,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:X,token:U,token_nodot:x,separators:se,word:st,STAR:ee,SLASH:W,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:Pe,COMMA:Ce,SEMI:ae,COLON:ye,LDQUOT:nt,RDQUOT:at,comment:Se,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:bn,password:wn,hostport:Ys,host:es,hostname:us,domainlabel:Js,toplabel:On,IPv6reference:Dn,IPv6address:zs,h16:me,ls32:oe,IPv4address:ot,dec_octet:Wt,port:Cs,uri_parameters:vr,uri_parameter:Nn,transport_param:Un,user_param:Sr,method_param:Er,ttl_param:yr,maddr_param:Ar,lr_param:Cr,other_param:Rr,pname:Ir,pvalue:br,paramchar:Rs,param_unreserved:Is,headers:wr,header:Xs,hname:Qs,hvalue:Or,hnv_unreserved:bs,Request_Response:Zs,Request_Line:ml,Request_URI:Dr,absoluteURI:xn,hier_part:Pn,net_path:Nr,abs_path:en,opaque_part:tn,uric:ws,uric_no_slash:Os,path_segments:Ur,segment:sn,param:Ds,pchar:cs,scheme:Ns,authority:xr,srvr:Pr,reg_name:kr,query:Mr,SIP_Version:kn,INVITEm:Mn,ACKm:Lr,OPTIONSm:$r,BYEm:Hr,CANCELm:Fr,REGISTERm:Vr,SUBSCRIBEm:jr,NOTIFYm:qr,REFERm:Br,Method:nn,Status_Line:rn,Status_Code:Gr,extension_code:Wr,Reason_Phrase:Kr,Allow_Events:gl,Call_ID:Ya,Contact:Ja,contact_param:Ln,name_addr:$t,display_name:Ht,contact_params:Us,c_p_q:$n,c_p_expires:Yr,delta_seconds:ts,qvalue:ss,generic_param:Ge,gen_value:We,Content_Disposition:Tl,disp_type:vl,disp_param:Hn,handling_param:Fn,Content_Encoding:Sl,Content_Length:za,Content_Type:Xa,media_type:El,m_type:Jr,discrete_type:zr,composite_type:Xr,extension_token:ln,x_token:an,m_subtype:Qr,m_parameter:Vn,m_value:jn,CSeq:yl,CSeq_value:Al,Expires:Cl,Event:Qa,event_type:on,From:un,from_param:Zr,tag_param:cn,Max_Forwards:ei,Min_Expires:Za,Name_Addr_Header:eo,Proxy_Authenticate:to,challenge:ti,other_challenge:qn,auth_param:xs,digest_cln:ns,realm:fn,realm_value:si,domain:ni,URI:hn,nonce:dn,nonce_value:ri,opaque:ii,stale:li,algorithm:ai,qop_options:oi,qop_value:_n,Proxy_Require:Bn,Record_Route:so,rec_route:Gn,Reason:Wn,reason_param:ui,reason_cause:Kn,Require:Rl,Route:no,route_param:Yn,Subscription_State:Jn,substate_value:Il,subexp_params:zn,event_reason_value:Xn,Subject:bl,Supported:ro,To:io,to_param:ci,Via:fi,via_param:Qn,via_params:Ps,via_ttl:Zn,via_maddr:hi,via_received:di,via_branch:_i,response_port:pi,rport:mi,sent_protocol:gi,protocol_name:Ti,transport:vi,sent_by:Si,via_host:Ei,via_port:yi,ttl:er,WWW_Authenticate:Ai,Session_Expires:lo,s_e_expires:wl,s_e_params:tr,s_e_refresher:sr,extension_header:Ol,header_value:Dl,message_body:Nl,uuid_URI:ao,uuid:Ul,hex4:Ft,hex8:Vt,hex12:Ci,Refer_To:xl,Replaces:oo,call_id:Pl,replaces_param:nr,to_tag:rr,from_tag:Ri,early_flag:Ii};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,_=[];function h(i){s<r||(s>r&&(r=s,_=[]),_.push(i))}function d(){var i;return n.substr(s,2)===`\r
|
|
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}(),id={};function Fc(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 o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
61
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var h=n.next();return s=h.done,h},e:function(h){r=!0,_=h},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}function Wp(c,t){if(c){if(typeof c=="string")return Vc(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 Vc(c,t)}}function Vc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=c[n];return o}var Kp=dt,vu=as(),Su=Es,Wl=new Kp("Parser");id.parseMessage=function(c,t){var n,o,a=c.indexOf(`\r
|
|
62
|
+
`);if(a===-1){Wl.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=c.substring(0,a),r=vu.parse(s,"Request_Response");if(r===-1){Wl.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else r.status_code?(n=new Su.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new Su.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;for(var _=a+2;;){if(a=Yp(c,_),a===-2){o=_+2;break}else if(a===-1){Wl.warn("parseMessage() | malformed message");return}if(r=Jp(n,c,_,a),r!==!0){Wl.warn("parseMessage() |",r.error);return}_=a+2}if(n.hasHeader("content-length")){var d=n.getHeader("content-length");n.body=c.substr(o,d)}else n.body=c.substring(o);return n};function Yp(c,t){var n=t,o=0,a=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;o===0;){if(a=c.indexOf(`\r
|
|
63
|
+
`,n),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?n=a+2:o=a}return o}function Jp(c,t,n,o){var a,s=t.indexOf(":",n),r=t.substring(n,s).trim(),_=t.substring(s+1,o).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",_),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",_),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",_),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=vu.parse(_,"Record_Route"),a===-1)a=void 0;else{var d=Fc(a),h;try{for(d.s();!(h=d.n()).done;){var g=h.value;c.addHeader("record-route",_.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(A){d.e(A)}finally{d.f()}}break;case"call-id":case"i":c.setHeader("call-id",_),a=c.parseHeader("call-id"),a&&(c.call_id=_);break;case"contact":case"m":if(a=vu.parse(_,"Contact"),a===-1)a=void 0;else{var T=Fc(a),S;try{for(T.s();!(S=T.n()).done;){var E=S.value;c.addHeader("contact",_.substring(E.possition,E.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=E.parsed}}catch(A){T.e(A)}finally{T.f()}}break;case"content-length":case"l":c.setHeader("content-length",_),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",_),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",_),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof Su.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",_),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",_),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",_),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",_),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",_),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",_),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",_),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(r,_),a=0}return a===void 0?{error:'error parsing header "'.concat(r,'"')}:!0}function wo(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 o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
64
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var h=n.next();return s=h.done,h},e:function(h){r=!0,_=h},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}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,o=new Array(t);n<t;n++)o[n]=c[n];return o}var Xp=dt,ld=lt,qc=Es,Mu=It(),Lu=new Xp("sanityCheck"),Qp=[am],Zp=[sm,nm,rm,im],em=[lm,om],Fe,rs,od,tm=function(c,t,n){Fe=c,rs=t,od=n;var o=wo(Qp),a;try{for(o.s();!(a=o.n()).done;){var s=a.value;if(s()===!1)return!1}}catch(S){o.e(S)}finally{o.f()}if(Fe instanceof qc.IncomingRequest){var r=wo(Zp),_;try{for(r.s();!(_=r.n()).done;){var d=_.value;if(d()===!1)return!1}}catch(S){r.e(S)}finally{r.f()}}else if(Fe instanceof qc.IncomingResponse){var h=wo(em),g;try{for(h.s();!(g=h.n()).done;){var T=g.value;if(T()===!1)return!1}}catch(S){h.e(S)}finally{h.f()}}return!0};function sm(){if(Fe.s("to").uri.scheme!=="sip")return el(416),!1}function nm(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===rs.configuration.jssip_id)return el(482),!1}function rm(){var c=Mu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return el(400),!1}function im(){var c=Fe.from_tag,t=Fe.call_id,n=Fe.cseq,o;if(!Fe.to_tag)if(Fe.method===ld.INVITE){if(rs._transactions.ist[Fe.via_branch])return!1;for(var a in rs._transactions.ist)if(Object.prototype.hasOwnProperty.call(rs._transactions.ist,a)&&(o=rs._transactions.ist[a],o.request.from_tag===c&&o.request.call_id===t&&o.request.cseq===n))return el(482),!1}else{if(rs._transactions.nist[Fe.via_branch])return!1;for(var s in rs._transactions.nist)if(Object.prototype.hasOwnProperty.call(rs._transactions.nist,s)&&(o=rs._transactions.nist[s],o.request.from_tag===c&&o.request.call_id===t&&o.request.cseq===n))return el(482),!1}}function lm(){if(Fe.getHeaders("via").length>1)return Lu.debug("more than one Via header field present in the response, dropping the response"),!1}function om(){var c=Mu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return Lu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function am(){for(var c=["from","to","call_id","cseq","via"],t=0,n=c;t<n.length;t++){var o=n[t];if(!Fe.hasHeader(o))return Lu.debug("missing mandatory header field : ".concat(o,", dropping the response")),!1}}function el(c){var t=Fe.getHeaders("via"),n,o="SIP/2.0 ".concat(c," ").concat(ld.REASON_PHRASE[c],`\r
|
|
65
|
+
`),a=wo(t),s;try{for(a.s();!(s=a.n()).done;){var r=s.value;o+="Via: ".concat(r,`\r
|
|
66
|
+
`)}}catch(_){a.e(_)}finally{a.f()}n=Fe.getHeader("To"),Fe.to_tag||(n+=";tag=".concat(Mu.newTag())),o+="To: ".concat(n,`\r
|
|
67
|
+
`),o+="From: ".concat(Fe.getHeader("From"),`\r
|
|
68
|
+
`),o+="Call-ID: ".concat(Fe.call_id,`\r
|
|
69
|
+
`),o+="CSeq: ".concat(Fe.cseq," ").concat(Fe.method,`\r
|
|
70
|
+
`),o+=`\r
|
|
71
|
+
`,od.send(o)}var $u={};function Bc(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 o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
72
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,_;return{s:function(){n=c[Symbol.iterator]()},n:function(){var h=n.next();return s=h.done,h},e:function(h){r=!0,_=h},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw _}}}}function um(c,t){if(c){if(typeof c=="string")return Gc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Gc(c,t)}}function Gc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=c[n];return o}var cr=It(),yn=lt,Oa=as(),Wc=Ks(),Da=Pu,Na=Ws;$u.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(cr.createRandomToken(12),".invalid")};var Kl={mandatory:{sockets:function(t){var n=[];if(Da.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var o=Bc(t),a;try{for(o.s();!(a=o.n()).done;){var s=a.value;Object.prototype.hasOwnProperty.call(s,"socket")&&Da.isSocket(s.socket)?n.push(s):Da.isSocket(s)&&n.push({socket:s})}}catch(r){o.e(r)}finally{o.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Wc.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(Oa.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(cr.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(cr.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=Oa.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)),Oa.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(cr.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(cr.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=Wc.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 o=Bc(t),a;try{for(o.s();!(a=o.n()).done;){var s=a.value;typeof s=="string"&&n.push(s)}}catch(r){o.e(r)}finally{o.f()}}else return;return n}}};$u.load=function(c,t){for(var n in Kl.mandatory)if(t.hasOwnProperty(n)){var o=t[n],a=Kl.mandatory[n](o);if(a!==void 0)c[n]=a;else throw new Na.ConfigurationError(n,o)}else throw new Na.ConfigurationError(n);for(var s in Kl.optional)if(t.hasOwnProperty(s)){var r=t[s];if(cr.isEmpty(r))continue;var _=Kl.optional[s](r);if(_!==void 0)c[s]=_;else throw new Na.ConfigurationError(s,r)}};function Oo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Oo=function(n){return typeof n}:Oo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Oo(c)}function cm(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Yc(c,t,n){return t&&Kc(c.prototype,t),n&&Kc(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(o,a){return o.__proto__=a,o},Eu(c,t)}function dm(c){var t=_m();return function(){var o=Ho(c),a;if(t){var s=Ho(this).constructor;a=Reflect.construct(o,arguments,s)}else a=o.apply(this,arguments);return hm(this,a)}}function hm(c,t){return t&&(Oo(t)==="object"||typeof t=="function")?t:ad(c)}function ad(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 Ho(c){return Ho=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ho(c)}var pm=ft.EventEmitter,mm=dt,pt=lt,gm=r_,Jc=hp,zc=bp,Xc=$p,xa=fl,Tm=Gp,Yl=It(),vm=Ws,Sm=Ks(),Em=id,Ua=Es,ym=tm,ka=$u,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=dm(n);Yc(n,null,[{key:"C",get:function(){return Tt}}]);function n(o){var a;if(cm(this,n),je.debug("new() [configuration:%o]",o),a=t.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},ka.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=Tt.STATUS_INIT,a._error=null,a._transactions={nist:{},nict:{},ist:{},ict:{}},a._data={},a._closeTimer=null,o===void 0)throw new TypeError("Not enough arguments");try{a._loadConfig(o)}catch(s){throw a._status=Tt.STATUS_NOT_READY,a._error=Tt.CONFIGURATION_ERROR,s}return a._registrator=new gm(ad(a)),a}return Yc(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(a){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(a)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(a,s){je.debug("call()");var r=new Jc(this);return r.connect(a,s),r}},{key:"sendMessage",value:function(a,s,r){je.debug("sendMessage()");var _=new zc(this);return _.send(a,s,r),_}},{key:"sendOptions",value:function(a,s,r){je.debug("sendOptions()");var _=new Xc(this);return _.send(a,s,r),_}},{key:"terminateSessions",value:function(a){je.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(a)}},{key:"stop",value:function(){var a=this;if(je.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();var 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 _ in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,_))try{this._applicants[_].close()}catch{}this._status=Tt.STATUS_USER_CLOSED;var d=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;d===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){a._closeTimer=null,a._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(a){return Yl.normalizeTarget(a,this._configuration.hostport_params)}},{key:"get",value:function(a){switch(a){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:je.warn('get() | cannot get "%s" parameter in runtime',a);return}}},{key:"set",value:function(a,s){switch(a){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',a),!1}return!0}},{key:"newTransaction",value:function(a){this._transactions[a.type][a.id]=a,this.emit("newTransaction",{transaction:a})}},{key:"destroyTransaction",value:function(a){delete this._transactions[a.type][a.id],this.emit("transactionDestroyed",{transaction:a})}},{key:"newDialog",value:function(a){this._dialogs[a.id]=a}},{key:"destroyDialog",value:function(a){delete this._dialogs[a.id]}},{key:"newMessage",value:function(a,s){this._applicants[a]=a,this.emit("newMessage",s)}},{key:"newOptions",value:function(a,s){this._applicants[a]=a,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(a){delete this._applicants[a]}},{key:"newRTCSession",value:function(a,s){this._sessions[a.id]=a,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(a){delete this._sessions[a.id]}},{key:"registered",value:function(a){this.emit("registered",a)}},{key:"unregistered",value:function(a){this.emit("unregistered",a)}},{key:"registrationFailed",value:function(a){this.emit("registrationFailed",a)}},{key:"receiveRequest",value:function(a){var s=a.method;if(a.ruri.user!==this._configuration.uri.user&&a.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),a.method!==pt.ACK&&a.reply_sl(404);return}if(a.ruri.scheme===pt.SIPS){a.reply_sl(416);return}if(!xa.checkTransaction(this,a)){if(s===pt.INVITE?new xa.InviteServerTransaction(this,this._transport,a):s!==pt.ACK&&s!==pt.CANCEL&&new xa.NonInviteServerTransaction(this,this._transport,a),s===pt.OPTIONS){if(this.listeners("newOptions").length===0){a.reply(200);return}var r=new Xc(this);r.init_incoming(a)}else if(s===pt.MESSAGE){if(this.listeners("newMessage").length===0){a.reply(405);return}var _=new zc(this);_.init_incoming(a)}else if(s===pt.INVITE&&!a.to_tag&&this.listeners("newRTCSession").length===0){a.reply(405);return}var d,h;if(a.to_tag)d=this._findDialog(a.call_id,a.from_tag,a.to_tag),d?d.receiveRequest(a):s===pt.NOTIFY?(h=this._findSession(a),h?h.receiveRequest(a):(je.debug("received NOTIFY request for a non existent subscription"),a.reply(481,"Subscription does not exist"))):s!==pt.ACK&&a.reply(481);else switch(s){case pt.INVITE:if(window.RTCPeerConnection)if(a.hasHeader("replaces")){var g=a.replaces;d=this._findDialog(g.call_id,g.from_tag,g.to_tag),d?(h=d.owner,h.isEnded()?a.reply(603):h.receiveRequest(a)):a.reply(481)}else h=new Jc(this),h.init_incoming(a);else je.warn("INVITE received but WebRTC is not supported"),a.reply(488);break;case pt.BYE:a.reply(481);break;case pt.CANCEL:h=this._findSession(a),h?h.receiveRequest(a):je.debug("received CANCEL request for a non existent session");break;case pt.ACK:break;case pt.NOTIFY:this.emit("sipEvent",{event:a.event,request:a}),a.reply(200);break;default:a.reply(405);break}}}},{key:"_findSession",value:function(a){var s=a.call_id,r=a.from_tag,_=a.to_tag,d=s+r,h=this._sessions[d],g=s+_,T=this._sessions[g];return h||T||null}},{key:"_findDialog",value:function(a,s,r){var _=a+s+r,d=this._dialogs[_];return d||(_=a+r+s,d=this._dialogs[_],d||null)}},{key:"_loadConfig",value:function(a){try{ka.load(this._configuration,a)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Yl.newUUID()),this._configuration.jssip_id=Yl.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=bm.bind(this),this._transport.ondata=Im.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 Sm("sip",Yl.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]:{},S=T.anonymous||null,E=T.outbound||null,A="<";return S?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),E&&(S?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var _=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var d in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,d)&&(_.indexOf(d)!==-1?Object.defineProperty(this._configuration,d,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,d,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(var h in this._configuration)if(Object.prototype.hasOwnProperty.call(ka.settings,h))switch(h){case"uri":case"registrar_server":je.debug("- ".concat(h,": ").concat(this._configuration[h]));break;case"password":case"ha1":case"authorization_jwt":je.debug("- ".concat(h,": NOT SHOWN"));break;default:je.debug("- ".concat(h,": ").concat(JSON.stringify(this._configuration[h])))}}},{key:"C",get:function(){return Tt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),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 bm(c){for(var t=["nict","ict","nist","ist"],n=0,o=t;n<o.length;n++){var a=o[n];for(var s in this._transactions[a])Object.prototype.hasOwnProperty.call(this._transactions[a],s)&&this._transactions[a][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 Im(c){var t=c.transport,n=c.message;if(n=Em.parseMessage(n,this),!!n&&!(this._status===Tt.STATUS_USER_CLOSED&&n instanceof Ua.IncomingRequest)&&ym(n,this,t)){if(n instanceof Ua.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Ua.IncomingResponse){var o;switch(n.method){case pt.INVITE:o=this._transactions.ict[n.via_branch],o&&o.receiveResponse(n);break;case pt.ACK:break;default:o=this._transactions.nict[n.via_branch],o&&o.receiveResponse(n);break}}}}function wm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Qc(c,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Om(c,t,n){return t&&Qc(c.prototype,t),n&&Qc(c,n),c}var Dm=dt,Nm=as(),Ot=new Dm("WebSocketInterface"),xm=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 o=n.wasClean,a=n.code,s=n.reason;Ot.debug("WebSocket ".concat(this._url," closed")),o===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!o,a,s)}},{key:"_onMessage",value:function(n){var o=n.data;Ot.debug("received WebSocket message"),this.ondata(o)}},{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}(),yu=Vo,Um=lt,km=Ws,Pm=It(),Mm=Cm,Lm=Ks(),$m=Du(),Hm=as(),Fm=xm,Vm=mr("JsSIP");Vm("version %s",yu.version);var Zc={C:Um,Exceptions:km,Utils:Pm,UA:Mm,URI:Lm,NameAddrHeader:$m,WebSocketInterface:Fm,Grammar:Hm,debug:mr,get name(){return yu.title},get version(){return yu.version}};const or=mr,ar="JsSIP";var ut=class{constructor(t){t?(this._debug=or.default(`${ar}:${t}`),this._warn=or.default(`${ar}:WARN:${t}`),this._error=or.default(`${ar}:ERROR:${t}`)):(this._debug=or.default(ar),this._warn=or.default(`${ar}:WARN`),this._error=or.default(`${ar}: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 Ko=Xe(ut),ef=Vo;var De={USER_AGENT:`${ef.title} ${ef.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 H=Xe(De);var tt={},Pa,tf;function Hu(){if(tf)return Pa;tf=1;const c=ys(),t=Zt();return Pa=class ud{static parse(o){if(o=t.parse(o,"Name_Addr_Header"),o!==-1)return o}constructor(o,a,s){if(!o||!(o instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=o,this._parameters={},this.display_name=a;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(o){this._display_name=o===0?"0":o}setParam(o,a){o&&(this._parameters[o.toLowerCase()]=typeof a>"u"||a===null?null:a.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const a=this._parameters[o];return delete this._parameters[o],a}}clearParams(){this._parameters={}}clone(){return new ud(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(o){return o.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let o=this._display_name?`"${this._quote(this._display_name)}" `:"";o+=`<${this._uri.toString()}>`;for(const a in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,a)&&(o+=`;${a}`,this._parameters[a]!==null&&(o+=`=${this._parameters[a]}`));return o}},Pa}var Ma,sf;function Zt(){return sf||(sf=1,Ma=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,o){var a={CRLF:h,DIGIT:g,ALPHA:T,HEXDIG:S,WSP:E,OCTET:A,DQUOTE:R,SP:C,HTAB:$,alphanum:k,reserved:re,unreserved:x,mark:F,escaped:_e,LWS:pe,SWS:P,HCOLON:N,TEXT_UTF8_TRIM:q,TEXT_UTF8char:j,UTF8_NONASCII:K,UTF8_CONT:V,LHEX:z,token:D,token_nodot:U,separators:X,word:He,STAR:Q,SLASH:W,EQUAL:B,LPAREN:ie,RPAREN:ve,RAQUOT:Ie,LAQUOT:ke,COMMA:Ae,SEMI:oe,COLON:ye,LDQUOT:nt,RDQUOT:ot,comment:Ee,ctext:Ce,quoted_string:be,quoted_string_clean:Oe,qdtext:ge,quoted_pair:ue,SIP_URI_noparams:me,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:Ze,uri_scheme_sip:Le,userinfo:Lt,user:ht,user_unreserved:In,password:wn,hostport:Ys,host:es,hostname:us,domainlabel:Js,toplabel:On,IPv6reference:Dn,IPv6address:zs,h16:Te,ls32:ae,IPv4address:at,dec_octet:Wt,port:As,uri_parameters:vr,uri_parameter:Nn,transport_param:xn,user_param:Sr,method_param:Er,ttl_param:yr,maddr_param:Cr,lr_param:Ar,other_param:Rr,pname:br,pvalue:Ir,paramchar:Rs,param_unreserved:bs,headers:wr,header:Xs,hname:Qs,hvalue:Or,hnv_unreserved:Is,Request_Response:Zs,Request_Line:ml,Request_URI:Dr,absoluteURI:Un,hier_part:kn,net_path:Nr,abs_path:en,opaque_part:tn,uric:ws,uric_no_slash:Os,path_segments:xr,segment:sn,param:Ds,pchar:cs,scheme:Ns,authority:Ur,srvr:kr,reg_name:Pr,query:Mr,SIP_Version:Pn,INVITEm:Mn,ACKm:Lr,OPTIONSm:$r,BYEm:Hr,CANCELm:Fr,REGISTERm:Vr,SUBSCRIBEm:jr,NOTIFYm:qr,REFERm:Br,Method:nn,Status_Line:rn,Status_Code:Gr,extension_code:Wr,Reason_Phrase:Kr,Allow_Events:gl,Call_ID:zo,Contact:Xo,contact_param:Ln,name_addr:$t,display_name:Ht,contact_params:xs,c_p_q:$n,c_p_expires:Yr,delta_seconds:ts,qvalue:ss,generic_param:We,gen_value:Ke,Content_Disposition:Tl,disp_type:vl,disp_param:Hn,handling_param:Fn,Content_Encoding:Sl,Content_Length:Qo,Content_Type:Zo,media_type:El,m_type:Jr,discrete_type:zr,composite_type:Xr,extension_token:ln,x_token:on,m_subtype:Qr,m_parameter:Vn,m_value:jn,CSeq:yl,CSeq_value:Cl,Expires:Al,Event:ea,event_type:an,From:un,from_param:Zr,tag_param:cn,Max_Forwards:ei,Min_Expires:ta,Name_Addr_Header:sa,Proxy_Authenticate:na,challenge:ti,other_challenge:qn,auth_param:Us,digest_cln:ns,realm:fn,realm_value:si,domain:ni,URI:dn,nonce:hn,nonce_value:ri,opaque:ii,stale:li,algorithm:oi,qop_options:ai,qop_value:_n,Proxy_Require:Bn,Record_Route:ra,rec_route:Gn,Reason:Wn,reason_param:ui,reason_cause:Kn,Require:Rl,Route:ia,route_param:Yn,Subscription_State:Jn,substate_value:bl,subexp_params:zn,event_reason_value:Xn,Subject:Il,Supported:la,To:oa,to_param:ci,Via:fi,via_param:Qn,via_params:ks,via_ttl:Zn,via_maddr:di,via_received:hi,via_branch:_i,response_port:pi,rport:mi,sent_protocol:gi,protocol_name:Ti,transport:vi,sent_by:Si,via_host:Ei,via_port:yi,ttl:er,WWW_Authenticate:Ci,Session_Expires:aa,s_e_expires:wl,s_e_params:tr,s_e_refresher:sr,extension_header:Ol,header_value:Dl,message_body:Nl,uuid_URI:ua,uuid:xl,hex4:Ft,hex8:Vt,hex12:Ai,Refer_To:Ul,Replaces:ca,call_id:kl,replaces_param:nr,to_tag:rr,from_tag:Ri,early_flag:bi};if(o!==void 0){if(a[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var s=0,r=0,_=[];function d(i){s<r||(s>r&&(r=s,_=[]),_.push(i))}function h(){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 S(){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 E(){var i;return i=R(),i===null&&(i=k()),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 R(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function k(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function M(){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 ie(){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=M(),i===null&&(i=V()),i}function V(){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 Ee(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=S(),e!==null?(l=S(),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=E();e!==null;)i.push(e),e=E();if(i!==null?(e=d(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=E(),l!==null)for(e=[];l!==null;)e.push(l),l=E();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 L(){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=R(),e===null&&(e=k());e!==null;)i.push(e),e=R(),e===null&&(e=k());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=L(),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=q(),e!==null)for(i=[];e!==null;)i.push(e),e=q();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=q(),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=q(),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 q(){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=M(),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=M(),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 x(){var i,e,l;if(l=s,e=M(),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=M(),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=R(),i===null&&(i=k())))))))))))))))))),i}function st(){var i,e,l;if(l=s,e=M(),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=M(),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=L(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=L(),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=L(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=L(),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=L(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=L(),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=L(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=L(),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=L(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=L(),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=L(),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 Pe(){var i,e,l,u;return l=s,u=s,i=L(),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=L(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=L(),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 ae(){var i,e,l,u,f;return u=s,f=s,i=L(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=L(),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=L(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=L(),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=L(),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=L(),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 Se(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ae(),l===null&&(l=ue(),l===null&&(l=Se()));l!==null;)e.push(l),l=Ae(),l===null&&(l=ue(),l===null&&(l=Se()));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=L(),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=L(),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 Ml(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=vr(),f!==null?(p=wr(),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(y){try{b.uri=new Ml(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=wn(),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=Ee(),e===null&&(e=bn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Ee(),e===null&&(e=bn()));else i=null;return i}function bn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function wn(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Ee(),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=Ee(),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=Dn())),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=On(),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=M(),i!==null){for(e=[],l=M(),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=M(),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 On(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=M(),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=M(),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,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,y,O,le,Ue,wt,ks,$,I;return ks=s,$=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?(y=me(),y!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(le=me(),le!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(wt=oe(),wt!==null?i=[i,e,l,u,f,p,m,v,y,O,le,Ue,wt]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=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?(y=":",s++):(y=null,h('":"')),y!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(le=":",s++):(le=null,h('":"')),le!==null?(Ue=oe(),Ue!==null?i=[i,e,l,u,f,p,m,v,y,O,le,Ue]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=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?(y=":",s++):(y=null,h('":"')),y!==null?(O=oe(),O!==null?i=[i,e,l,u,f,p,m,v,y,O]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=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=oe(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=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=oe(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=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=oe(),u!==null?i=[i,e,l,u]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=oe(),e!==null?i=[i,e]:(i=null,s=$)):(i=null,s=$),i===null&&($=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=$)):(i=null,s=$),i===null&&($=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?(y=me(),y!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(le=oe(),le!==null?i=[i,e,l,u,f,p,m,v,y,O,le]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),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?(y=":",s++):(y=null,h('":"')),y!==null?(O=oe(),O!==null?i=[i,e,l,u,f,p,m,v,y,O]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),e=e!==null?e:"",e!==null?(I=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=I)):(l=null,s=I),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?(y=oe(),y!==null?i=[i,e,l,u,f,p,m,v,y]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),e=e!==null?e:"",e!==null?(I=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=I)):(l=null,s=I),l=l!==null?l:"",l!==null?(I=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=I)):(u=null,s=I),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=oe(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),e=e!==null?e:"",e!==null?(I=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=I)):(l=null,s=I),l=l!==null?l:"",l!==null?(I=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=I)):(u=null,s=I),u=u!==null?u:"",u!==null?(I=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=I)):(f=null,s=I),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=oe(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),e=e!==null?e:"",e!==null?(I=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=I)):(l=null,s=I),l=l!==null?l:"",l!==null?(I=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=I)):(u=null,s=I),u=u!==null?u:"",u!==null?(I=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=I)):(f=null,s=I),f=f!==null?f:"",f!==null?(I=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=I)):(p=null,s=I),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=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$),i===null&&($=s,i=me(),i!==null?(I=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=I)):(e=null,s=I),e=e!==null?e:"",e!==null?(I=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=I)):(l=null,s=I),l=l!==null?l:"",l!==null?(I=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=I)):(u=null,s=I),u=u!==null?u:"",u!==null?(I=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=I)):(f=null,s=I),f=f!==null?f:"",f!==null?(I=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=I)):(p=null,s=I),p=p!==null?p:"",p!==null?(I=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=I)):(m=null,s=I),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=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$)):(i=null,s=$))))))))))))))),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=S(),i!==null?(e=S(),e=e!==null?e:"",e!==null?(l=S(),l=l!==null?l:"",l!==null?(u=S(),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 oe(){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,y;return v=s,y=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=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y),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,y){return y=parseInt(y.join("")),b.port=y,y}(p,i)),i===null&&(s=p),i}function vr(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Nn(),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=Nn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Nn(){var i;return i=Un(),i===null&&(i=Sr(),i===null&&(i=Er(),i===null&&(i=yr(),i===null&&(i=Ar(),i===null&&(i=Cr(),i===null&&(i=Rr())))))),i}function Un(){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 Er(){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 yr(){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=er(),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 Cr(){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 Rr(){var i,e,l,u,f,p;return u=s,f=s,i=Ir(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=br(),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,y){b.uri_params||(b.uri_params={}),typeof y>"u"?y=void 0:y=y[1],b.uri_params[v.toLowerCase()]=y}(u,i[0],i[1])),i===null&&(s=u),i}function Ir(){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 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 Rs(){var i;return i=Is(),i===null&&(i=N(),i===null&&(i=Ee())),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 wr(){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=Or(),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=Ee())),e!==null)for(i=[];e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Ee()));else i=null;return i}function Or(){var i,e;for(i=[],e=bs(),e===null&&(e=N(),e===null&&(e=Ee()));e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Ee()));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=ml()),i}function ml(){var i,e,l,u,f,p;return p=s,i=nn(),i!==null?(e=R(),e!==null?(l=Dr(),l!==null?(u=R(),u!==null?(f=kn(),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 Dr(){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=Pn(),l===null&&(l=tn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Pn(){var i,e,l,u,f;return u=s,i=Nr(),i===null&&(i=en()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Mr(),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 Nr(){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=Ur(),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=ie(),i===null&&(i=N(),i===null&&(i=Ee())),i}function Os(){var i;return i=N(),i===null&&(i=Ee(),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 Ur(){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=Ee(),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=Pr(),i===null&&(i=kr()),i}function Pr(){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 kr(){var i,e;if(e=N(),e===null&&(e=Ee(),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=Ee(),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 Mr(){var i,e;for(i=[],e=ws();e!==null;)i.push(e),e=ws();return i}function kn(){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(y){b.sip_version=n.substring(s,y)}(m)),i===null&&(s=m),i}function Mn(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function Lr(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function $r(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Hr(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function Fr(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function Vr(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function jr(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function qr(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function Br(){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=Mn(),i===null&&(i=Lr(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=Vr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=Br(),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=kn(),i!==null?(e=R(),e!==null?(l=Gr(),l!==null?(u=R(),u!==null?(f=Kr(),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 Gr(){var i,e;return e=s,i=Wr(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Wr(){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 Kr(){var i,e,l;for(l=s,i=[],e=ie(),e===null&&(e=N(),e===null&&(e=Ee(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=R(),e===null&&(e=k()))))));e!==null;)i.push(e),e=ie(),e===null&&(e=N(),e===null&&(e=Ee(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=R(),e===null&&(e=k()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function gl(){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 Ya(){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 Ja(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=Ln(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=Ln(),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=Ln(),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 y,O;for(O=b.multi_header.length,y=0;y<O;y++)if(b.multi_header[y].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function Ln(){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=ae(),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=ae(),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 y;b.multi_header||(b.multi_header=[]);try{y=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{y=null}b.multi_header.push({possition:s,offset:v,parsed:y})}(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=Pe(),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,y){typeof y=="string"?b.display_name=y:b.display_name=y[1].reduce(function(O,le){return O+le[0]+le[1]},y[0])}(f,i)),i===null&&(s=f),i}function Us(){var i;return i=$n(),i===null&&(i=Yr(),i===null&&(i=Ge())),i}function $n(){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 Yr(){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(y){return parseFloat(n.substring(s,y))}(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,y){b.params||(b.params={}),typeof y>"u"?y=void 0:y=y[1],b.params[v.toLowerCase()]=y}(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 Tl(){var i,e,l,u,f,p;if(f=s,i=vl(),i!==null){for(e=[],p=s,l=ae(),l!==null?(u=Hn(),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=Hn(),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 vl(){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 Hn(){var i;return i=Fn(),i===null&&(i=Ge()),i}function Fn(){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 za(){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 Xa(){var i,e;return e=s,i=El(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function El(){var i,e,l,u,f,p,m,v;if(m=s,i=Jr(),i!==null)if(e=W(),e!==null)if(l=Qr(),l!==null){for(u=[],v=s,f=ae(),f!==null?(p=Vn(),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=Vn(),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 Jr(){var i;return i=zr(),i===null&&(i=Xr()),i}function zr(){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 Xr(){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 Qr(){var i;return i=ln(),i===null&&(i=U()),i}function Vn(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=jn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function jn(){var i;return i=U(),i===null&&(i=Ie()),i}function yl(){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 Cl(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Qa(){var i,e,l,u,f,p,m;if(f=s,p=s,i=on(),i!==null){for(e=[],m=s,l=ae(),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=ae(),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,y){b.event=y.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function on(){var i,e,l,u,f,p;if(f=s,i=x(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=x(),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=x(),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=ae(),l!==null?(u=Zr(),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=Zr(),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 y=b.tag;try{b=new fs(b.uri,b.display_name,b.params),y&&b.setParam("tag",y)}catch{b=-1}}()),i===null&&(s=f),i}function Zr(){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 ei(){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 Za(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function eo(){var i,e,l,u,f,p,m,v,y,O;for(v=s,y=s,i=[],e=Ht();e!==null;)i.push(e),e=Ht();if(i!==null)if(e=Pe(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=ae(),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=ae(),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=y)}else i=null,s=y;else i=null,s=y;else i=null,s=y;else i=null,s=y;return i!==null&&(i=function(le){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function to(){var i;return i=ti(),i}function ti(){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=qn()),i}function qn(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=xs(),l!==null){for(u=[],v=s,f=Ce(),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=Ce(),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,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=ni(),i===null&&(i=dn(),i===null&&(i=ii(),i===null&&(i=li(),i===null&&(i=ai(),i===null&&(i=oi(),i===null&&(i=xs()))))))),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=si(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function si(){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 ni(){var i,e,l,u,f,p,m,v,y;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=[],y=s,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;for(p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=y)):(p=null,s=y);p!==null;){if(f.push(p),y=s,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=y)):(p=null,s=y)}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=ri(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ri(){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 ii(){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 li(){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 ai(){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 oi(){var i,e,l,u,f,p,m,v,y,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(y=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=y)}else u=null,s=y;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 Bn(){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 so(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Gn(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=Gn(),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=Gn(),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 y,O;for(O=b.multi_header.length,y=0;y<O;y++)if(b.multi_header[y].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function Gn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=$t(),i!==null){for(e=[],m=s,l=ae(),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=ae(),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 y;b.multi_header||(b.multi_header=[]);try{y=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{y=null}b.multi_header.push({possition:s,offset:v,parsed:y})}(f)),i===null&&(s=f),i}function Wn(){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=ae(),l!==null?(u=ui(),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=ui(),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,y){if(b.protocol=y.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 ui(){var i;return i=Kn(),i===null&&(i=Ge()),i}function Kn(){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 Rl(){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;if(f=s,i=Yn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Yn(),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=Yn(),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 Yn(){var i,e,l,u,f,p;if(f=s,i=$t(),i!==null){for(e=[],p=s,l=ae(),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=ae(),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 Jn(){var i,e,l,u,f,p;if(f=s,i=Il(),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 Il(){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 zn(){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=Xn(),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 Xn(){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 bl(){var i;return i=B(),i=i!==null?i:"",i}function ro(){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 io(){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=ae(),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=ae(),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){var y=b.tag;try{b=new fs(b.uri,b.display_name,b.params),y&&b.setParam("tag",y)}catch{b=-1}}()),i===null&&(s=f),i}function ci(){var i;return i=cn(),i===null&&(i=Ge()),i}function fi(){var i,e,l,u,f,p;if(f=s,i=Qn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Qn(),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=Qn(),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 Qn(){var i,e,l,u,f,p,m,v;if(m=s,i=gi(),i!==null)if(e=ve(),e!==null)if(l=Si(),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;return i=Zn(),i===null&&(i=hi(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi(),i===null&&(i=Ge()))))),i}function Zn(){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=er(),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 hi(){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 di(){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 _i(){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 pi(){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=mi(),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 mi(){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,y){b.rport=parseInt(y.join(""))}(p,i)),i===null&&(s=p),i}function gi(){var i,e,l,u,f,p;return p=s,i=Ti(),i!==null?(e=W(),e!==null?(l=U(),l!==null?(u=W(),u!==null?(f=vi(),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 Ti(){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 vi(){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=Ei(),i!==null?(f=s,e=ye(),e!==null?(l=yi(),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 Ei(){var i,e;return e=s,i=ot(),i===null&&(i=Dn(),i===null&&(i=us())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function yi(){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,y){b.port=parseInt(y.join(""))}(p,i)),i===null&&(s=p),i}function er(){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=ti(),i}function lo(){var i,e,l,u,f,p;if(f=s,i=wl(),i!==null){for(e=[],p=s,l=ae(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=ae(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function wl(){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 tr(){var i;return i=sr(),i===null&&(i=Ge()),i}function sr(){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 Ol(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=Dl(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Dl(){var i,e;for(i=[],e=q(),e===null&&(e=F(),e===null&&(e=ve()));e!==null;)i.push(e),e=q(),e===null&&(e=F(),e===null&&(e=ve()));return i}function Nl(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function ao(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Ul(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ul(){var i,e,l,u,f,p,m,v,y,O,le;return O=s,le=s,i=Vt(),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?(y=Ci(),y!==null?i=[i,e,l,u,f,p,m,v,y]:(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le),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=S(),i!==null?(e=S(),e!==null?(l=S(),l!==null?(u=S(),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 Vt(){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 Ci(){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=ae(),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=ae(),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 oo(){var i,e,l,u,f,p;if(f=s,i=Pl(),i!==null){for(e=[],p=s,l=ae(),l!==null?(u=nr(),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=nr(),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 Pl(){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 nr(){var i;return i=rr(),i===null&&(i=Ri(),i===null&&(i=Ii(),i===null&&(i=Ge()))),i}function rr(){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 Ri(){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 Ii(){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 kl(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 uo(){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 Ml=ys(),fs=$u(),b={},w=o[a]();if(w===null||s!==n.length){var bi=Math.max(s,r),wi=bi<n.length?n.charAt(bi):null,Ll=uo();return new this.SyntaxError(kl(_),wi,bi,Ll.line,Ll.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function _(h,d){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=d?c(d):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=_(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),ko}var Mo,sf;function ys(){if(sf)return Mo;sf=1;const c=De,t=At(),n=Zt();return Mo=class uh{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,_,h={},d={}){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=_;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in d)Object.prototype.hasOwnProperty.call(d,g)&&this.setHeader(g,d[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 uh(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 _ of this._headers[r])o.push(`${r}=${_}`);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}},Mo}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,..._){for(const h of _)if(a(r[h]))return!1;return!0};const o=et.createRandomToken=(r,_=32)=>{let h,d,g="";for(h=0;h<r;h++)d=Math.random()*_|0,g+=d.toString(_);return g};et.newTag=()=>o(10),et.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,_=>{const h=Math.random()*16|0;return(_==="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,_)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let d,g;switch(h.length){case 1:if(!_)return;d=r,g=_;break;case 2:d=h[0],g=h[1];break;default:d=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}d=d.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(d)&&(d=d.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(d)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},et.headerize=r=>{const _={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let d="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(d+="-"),d+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return _[d]&&(d=_[d]),d},et.sipErrorCause=r=>{for(const _ in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[_].indexOf(r)!==-1)return c.causes[_];return c.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=()=>{function r(_,h){return Math.floor(Math.random()*(h-_+1)+_)}return`192.0.2.${r(1,254)}`},et.calculateMD5=r=>{function _(Se,Ae){return Se<<Ae|Se>>>32-Ae}function h(Se,Ae){const Ie=Se&2147483648,Oe=Ae&2147483648,pe=Se&1073741824,ue=Ae&1073741824,_e=(Se&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 d(Se,Ae,Ie){return Se&Ae|~Se&Ie}function g(Se,Ae,Ie){return Se&Ie|Ae&~Ie}function T(Se,Ae,Ie){return Se^Ae^Ie}function S(Se,Ae,Ie){return Ae^(Se|~Ie)}function E(Se,Ae,Ie,Oe,pe,ue,_e){return Se=h(Se,h(h(d(Ae,Ie,Oe),pe),_e)),h(_(Se,ue),Ae)}function A(Se,Ae,Ie,Oe,pe,ue,_e){return Se=h(Se,h(h(g(Ae,Ie,Oe),pe),_e)),h(_(Se,ue),Ae)}function C(Se,Ae,Ie,Oe,pe,ue,_e){return Se=h(Se,h(h(T(Ae,Ie,Oe),pe),_e)),h(_(Se,ue),Ae)}function R(Se,Ae,Ie,Oe,pe,ue,_e){return Se=h(Se,h(h(S(Ae,Ie,Oe),pe),_e)),h(_(Se,ue),Ae)}function k(Se){let Ae;const Ie=Se.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]|Se.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 M(Se){let Ae="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Se>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ae=Ae+Ie.substr(Ie.length-2,2);return Ae}function ie(Se){let Ae="";for(let Ie=0;Ie<Se.length;Ie++){const Oe=Se.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=[],V,Ee,ve,L,D,B,q,J,F;const X=7,U=12,x=17,se=22,st=5,ee=9,W=14,G=20,re=4,ge=11,be=16,Pe=23,Ce=6,ae=10,ye=15,nt=21;for(r=ie(r),N=k(r),B=1732584193,q=4023233417,J=2562383102,F=271733878,V=0;V<N.length;V+=16)Ee=B,ve=q,L=J,D=F,B=E(B,q,J,F,N[V+0],X,3614090360),F=E(F,B,q,J,N[V+1],U,3905402710),J=E(J,F,B,q,N[V+2],x,606105819),q=E(q,J,F,B,N[V+3],se,3250441966),B=E(B,q,J,F,N[V+4],X,4118548399),F=E(F,B,q,J,N[V+5],U,1200080426),J=E(J,F,B,q,N[V+6],x,2821735955),q=E(q,J,F,B,N[V+7],se,4249261313),B=E(B,q,J,F,N[V+8],X,1770035416),F=E(F,B,q,J,N[V+9],U,2336552879),J=E(J,F,B,q,N[V+10],x,4294925233),q=E(q,J,F,B,N[V+11],se,2304563134),B=E(B,q,J,F,N[V+12],X,1804603682),F=E(F,B,q,J,N[V+13],U,4254626195),J=E(J,F,B,q,N[V+14],x,2792965006),q=E(q,J,F,B,N[V+15],se,1236535329),B=A(B,q,J,F,N[V+1],st,4129170786),F=A(F,B,q,J,N[V+6],ee,3225465664),J=A(J,F,B,q,N[V+11],W,643717713),q=A(q,J,F,B,N[V+0],G,3921069994),B=A(B,q,J,F,N[V+5],st,3593408605),F=A(F,B,q,J,N[V+10],ee,38016083),J=A(J,F,B,q,N[V+15],W,3634488961),q=A(q,J,F,B,N[V+4],G,3889429448),B=A(B,q,J,F,N[V+9],st,568446438),F=A(F,B,q,J,N[V+14],ee,3275163606),J=A(J,F,B,q,N[V+3],W,4107603335),q=A(q,J,F,B,N[V+8],G,1163531501),B=A(B,q,J,F,N[V+13],st,2850285829),F=A(F,B,q,J,N[V+2],ee,4243563512),J=A(J,F,B,q,N[V+7],W,1735328473),q=A(q,J,F,B,N[V+12],G,2368359562),B=C(B,q,J,F,N[V+5],re,4294588738),F=C(F,B,q,J,N[V+8],ge,2272392833),J=C(J,F,B,q,N[V+11],be,1839030562),q=C(q,J,F,B,N[V+14],Pe,4259657740),B=C(B,q,J,F,N[V+1],re,2763975236),F=C(F,B,q,J,N[V+4],ge,1272893353),J=C(J,F,B,q,N[V+7],be,4139469664),q=C(q,J,F,B,N[V+10],Pe,3200236656),B=C(B,q,J,F,N[V+13],re,681279174),F=C(F,B,q,J,N[V+0],ge,3936430074),J=C(J,F,B,q,N[V+3],be,3572445317),q=C(q,J,F,B,N[V+6],Pe,76029189),B=C(B,q,J,F,N[V+9],re,3654602809),F=C(F,B,q,J,N[V+12],ge,3873151461),J=C(J,F,B,q,N[V+15],be,530742520),q=C(q,J,F,B,N[V+2],Pe,3299628645),B=R(B,q,J,F,N[V+0],Ce,4096336452),F=R(F,B,q,J,N[V+7],ae,1126891415),J=R(J,F,B,q,N[V+14],ye,2878612391),q=R(q,J,F,B,N[V+5],nt,4237533241),B=R(B,q,J,F,N[V+12],Ce,1700485571),F=R(F,B,q,J,N[V+3],ae,2399980690),J=R(J,F,B,q,N[V+10],ye,4293915773),q=R(q,J,F,B,N[V+1],nt,2240044497),B=R(B,q,J,F,N[V+8],Ce,1873313359),F=R(F,B,q,J,N[V+15],ae,4264355552),J=R(J,F,B,q,N[V+6],ye,2734768916),q=R(q,J,F,B,N[V+13],nt,1309151649),B=R(B,q,J,F,N[V+4],Ce,4149444226),F=R(F,B,q,J,N[V+11],ae,3174756917),J=R(J,F,B,q,N[V+2],ye,718787259),q=R(q,J,F,B,N[V+9],nt,3951481745),B=h(B,Ee),q=h(q,ve),J=h(J,L),F=h(F,D);return(M(B)+M(q)+M(J)+M(F)).toLowerCase()},et.closeMediaStream=r=>{if(r)try{let _;if(r.getTracks){_=r.getTracks();for(const h of _)h.stop()}else{_=r.getAudioTracks();for(const h of _)h.stop();_=r.getVideoTracks();for(const h of _)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},et.cloneArray=r=>r&&r.slice()||[],et.cloneObject=(r,_={})=>r&&Object.assign({},r)||_,et}const ch=Pt,Vm=ut,Et=De,it=At(),rf=$u(),jm=Zt(),Lo=new Vm("SIPMessage");class Wa{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",Et.MAX_FORWARDS);const _=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,d=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 S;typeof o.from_display_name<"u"?S=o.from_display_name:a.configuration.display_name?S=a.configuration.display_name:S=null,this.from=new rf(g,S,T),this.setHeader("from",this.from.toString());const E=o.call_id||a.configuration.jssip_id+it.createRandomToken(15);this.call_id=E,this.setHeader("call-id",E);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=ch.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
|
76
|
-
`;for(const
|
|
77
|
-
`;for(const
|
|
78
|
-
`;const n=[];switch(this.method){case Et.REGISTER:n.push("path","gruu");break;case Et.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 Et.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const
|
|
74
|
+
`,s+=2):(i=null,d('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[a-zA-Z]")),i}function S(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[0-9a-fA-F]")),i}function E(){var i;return i=C(),i===null&&(i=$()),i}function A(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[\\0-\\xFF]")),i}function R(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d('["]')),i}function C(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,d('" "')),i}function $(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,d('"\\t"')),i}function k(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[a-zA-Z0-9]")),i}function re(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,d('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,d('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,d('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,d('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,d('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,d('","'))))))))))),i}function x(){var i;return i=k(),i===null&&(i=F()),i}function F(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,d('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,d('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,d('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,d('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,d('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,d('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,d(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,d('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,d('")"')))))))))),i}function _e(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,d('"%"')),i!==null?(e=S(),e!==null?(l=S(),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 pe(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=E();e!==null;)i.push(e),e=E();if(i!==null?(e=h(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=E(),l!==null)for(e=[];l!==null;)e.push(l),l=E();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 P(){var i;return i=pe(),i=i!==null?i:"",i}function N(){var i,e,l,u,f;for(u=s,f=s,i=[],e=C(),e===null&&(e=$());e!==null;)i.push(e),e=C(),e===null&&(e=$());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=P(),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 q(){var i,e,l,u,f,p,m;if(f=s,p=s,e=j(),e!==null)for(i=[];e!==null;)i.push(e),e=j();else i=null;if(i!==null){for(e=[],m=s,l=[],u=pe();u!==null;)l.push(u),u=pe();for(l!==null?(u=j(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=pe();u!==null;)l.push(u),u=pe();l!==null?(u=j(),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 j(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[!-~]")),i===null&&(i=K()),i}function K(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[\\x80-\\uFFFF]")),i}function V(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[\\x80-\\xBF]")),i}function z(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[a-f]"))),i}function D(){var i,e,l;if(l=s,e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function U(){var i,e,l;if(l=s,e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function X(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,d('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,d('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,d('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,d('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,d('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,d('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,d('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,d('"\\\\"')),i===null&&(i=R(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,d('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,d('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,d('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,d('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,d('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,d('"}"')),i===null&&(i=C(),i===null&&(i=$())))))))))))))))))),i}function He(){var i,e,l;if(l=s,e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,d('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,d('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,d('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,d('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,d('"\\\\"')),e===null&&(e=R(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,d('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,d('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,d('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,d('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,d('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,d('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=k(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,d('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,d('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,d('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,d('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,d(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,d('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,d('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,d('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,d('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,d('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,d('"\\\\"')),e===null&&(e=R(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,d('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,d('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,d('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,d('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,d('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,d('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function Q(){var i,e,l,u,f;return u=s,f=s,i=P(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,d('"*"')),e!==null?(l=P(),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=P(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,d('"/"')),e!==null?(l=P(),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;return u=s,f=s,i=P(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e!==null?(l=P(),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 ie(){var i,e,l,u,f;return u=s,f=s,i=P(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,d('"("')),e!==null?(l=P(),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 ve(){var i,e,l,u,f;return u=s,f=s,i=P(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,d('")"')),e!==null?(l=P(),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 Ie(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,d('">"')),i!==null?(e=P(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function ke(){var i,e,l,u;return l=s,u=s,i=P(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,d('"<"')),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=P(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,d('","')),e!==null?(l=P(),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 oe(){var i,e,l,u,f;return u=s,f=s,i=P(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,d('";"')),e!==null?(l=P(),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=P(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=P(),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=P(),i!==null?(e=R(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function ot(){var i,e,l,u;return l=s,u=s,i=R(),i!==null?(e=P(),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=ie(),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=ve(),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,d("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[\\]-~]")),i===null&&(i=K(),i===null&&(i=pe())))),i}function be(){var i,e,l,u,f,p;if(f=s,p=s,i=P(),i!==null)if(e=R(),e!==null){for(l=[],u=ge(),u===null&&(u=ue());u!==null;)l.push(u),u=ge(),u===null&&(u=ue());l!==null?(u=R(),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=P(),i!==null)if(e=R(),e!==null){for(l=[],u=ge(),u===null&&(u=ue());u!==null;)l.push(u),u=ge(),u===null&&(u=ue());l!==null?(u=R(),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 ge(){var i;return i=pe(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,d('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,d("[\\]-~]")),i===null&&(i=K())))),i}function ue(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,d('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,d("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,d("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,d("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function me(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),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{I.uri=new Ml(I.scheme,I.user,I.host,I.port),delete I.scheme,delete I.user,delete I.host,delete I.host_type,delete I.port}catch{I=-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,d('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?(f=vr(),f!==null?(p=wr(),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(y){try{I.uri=new Ml(I.scheme,I.user,I.host,I.port,I.uri_params,I.uri_headers),delete I.scheme,delete I.user,delete I.host,delete I.host_type,delete I.port,delete I.uri_params,o==="SIP_URI"&&(I=I.uri)}catch{I=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=Ze(),i===null&&(i=Le()),i}function Ze(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,d('"sips"')),i!==null&&(i=function(l,u){I.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,d('"sip"')),i!==null&&(i=function(l,u){I.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=ht(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=wn(),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,d('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){I.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function ht(){var i,e;if(e=x(),e===null&&(e=_e(),e===null&&(e=In())),e!==null)for(i=[];e!==null;)i.push(e),e=x(),e===null&&(e=_e(),e===null&&(e=In()));else i=null;return i}function In(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,d('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,d('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,d('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,d('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,d('"/"'))))))))),i}function wn(){var i,e,l;for(l=s,i=[],e=x(),e===null&&(e=_e(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,d('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,d('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,d('","'))))))));e!==null;)i.push(e),e=x(),e===null&&(e=_e(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,d('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,d('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,d('","'))))))));return i!==null&&(i=function(u){I.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,d('":"')),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=at(),i===null&&(i=Dn())),i!==null&&(i=function(l){return I.host=n.substring(s,l).toLowerCase(),I.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,d('"."')),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,d('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=On(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,d('"."')),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 I.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function Js(){var i,e,l,u;if(u=s,i=k(),i!==null){for(e=[],l=k(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,d('"_"'))));l!==null;)e.push(l),l=k(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,d('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function On(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=k(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,d('"_"'))));l!==null;)e.push(l),l=k(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,d('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Dn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,d('"["')),i!==null?(e=zs(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,d('"]"')),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.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function zs(){var i,e,l,u,f,p,m,v,y,O,le,xe,wt,Ps,L,b;return Ps=s,L=s,i=Te(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,d('":"')),p!==null?(m=Te(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,d('":"')),v!==null?(y=Te(),y!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,d('":"')),O!==null?(le=Te(),le!==null?(n.charCodeAt(s)===58?(xe=":",s++):(xe=null,d('":"')),xe!==null?(wt=ae(),wt!==null?i=[i,e,l,u,f,p,m,v,y,O,le,xe,wt]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=Te(),v!==null?(n.charCodeAt(s)===58?(y=":",s++):(y=null,d('":"')),y!==null?(O=Te(),O!==null?(n.charCodeAt(s)===58?(le=":",s++):(le=null,d('":"')),le!==null?(xe=ae(),xe!==null?i=[i,e,l,u,f,p,m,v,y,O,le,xe]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=Te(),v!==null?(n.charCodeAt(s)===58?(y=":",s++):(y=null,d('":"')),y!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,y,O]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=L)):(i=null,s=L),i===null&&(L=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,d('"::"')),i!==null?(e=Te(),e!==null?i=[i,e]:(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,d('"::"')),e!==null?(l=Te(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,d('":"')),p!==null?(m=Te(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,d('":"')),v!==null?(y=Te(),y!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,d('":"')),O!==null?(le=ae(),le!==null?i=[i,e,l,u,f,p,m,v,y,O,le]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,d('"::"')),l!==null?(u=Te(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=Te(),v!==null?(n.charCodeAt(s)===58?(y=":",s++):(y=null,d('":"')),y!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,y,O]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(b=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?l=[l,u]:(l=null,s=b)):(l=null,s=b),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,d('"::"')),u!==null?(f=Te(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,d('":"')),p!==null?(m=Te(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,d('":"')),v!==null?(y=ae(),y!==null?i=[i,e,l,u,f,p,m,v,y]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(b=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?l=[l,u]:(l=null,s=b)):(l=null,s=b),l=l!==null?l:"",l!==null?(b=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?u=[u,f]:(u=null,s=b)):(u=null,s=b),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,d('"::"')),f!==null?(p=Te(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(b=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?l=[l,u]:(l=null,s=b)):(l=null,s=b),l=l!==null?l:"",l!==null?(b=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?u=[u,f]:(u=null,s=b)):(u=null,s=b),u=u!==null?u:"",u!==null?(b=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?f=[f,p]:(f=null,s=b)):(f=null,s=b),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,d('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(b=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?l=[l,u]:(l=null,s=b)):(l=null,s=b),l=l!==null?l:"",l!==null?(b=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?u=[u,f]:(u=null,s=b)):(u=null,s=b),u=u!==null?u:"",u!==null?(b=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?f=[f,p]:(f=null,s=b)):(f=null,s=b),f=f!==null?f:"",f!==null?(b=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,d('":"')),p!==null?(m=Te(),m!==null?p=[p,m]:(p=null,s=b)):(p=null,s=b),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,d('"::"')),m!==null?(v=Te(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L),i===null&&(L=s,i=Te(),i!==null?(b=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?e=[e,l]:(e=null,s=b)):(e=null,s=b),e=e!==null?e:"",e!==null?(b=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,d('":"')),l!==null?(u=Te(),u!==null?l=[l,u]:(l=null,s=b)):(l=null,s=b),l=l!==null?l:"",l!==null?(b=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,d('":"')),u!==null?(f=Te(),f!==null?u=[u,f]:(u=null,s=b)):(u=null,s=b),u=u!==null?u:"",u!==null?(b=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,d('":"')),f!==null?(p=Te(),p!==null?f=[f,p]:(f=null,s=b)):(f=null,s=b),f=f!==null?f:"",f!==null?(b=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,d('":"')),p!==null?(m=Te(),m!==null?p=[p,m]:(p=null,s=b)):(p=null,s=b),p=p!==null?p:"",p!==null?(b=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,d('":"')),m!==null?(v=Te(),v!==null?m=[m,v]:(m=null,s=b)):(m=null,s=b),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,d('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L)):(i=null,s=L))))))))))))))),i!==null&&(i=function(Se){return I.host_type="IPv6",n.substring(s,Se)}(Ps)),i===null&&(s=Ps),i}function Te(){var i,e,l,u,f;return f=s,i=S(),i!==null?(e=S(),e=e!==null?e:"",e!==null?(l=S(),l=l!==null?l:"",l!==null?(u=S(),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=Te(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e!==null?(l=Te(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=at()),i}function at(){var i,e,l,u,f,p,m,v,y;return v=s,y=s,i=Wt(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,d('"."')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,d('"."')),p!==null?(m=Wt(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y)):(i=null,s=y),i!==null&&(i=function(O){return I.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,d('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,d("[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,d('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,d("[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,d('"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,d("[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,y){return y=parseInt(y.join("")),I.port=y,y}(p,i)),i===null&&(s=p),i}function vr(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,d('";"')),e!==null?(l=Nn(),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,d('";"')),e!==null?(l=Nn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Nn(){var i;return i=xn(),i===null&&(i=Sr(),i===null&&(i=Er(),i===null&&(i=yr(),i===null&&(i=Cr(),i===null&&(i=Ar(),i===null&&(i=Rr())))))),i}function xn(){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,d('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,d('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,d('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,d('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,d('"tls"')),e===null&&(e=D())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){I.uri_params||(I.uri_params={}),I.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,d('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,d('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,d('"ip"')),e===null&&(e=D())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){I.uri_params||(I.uri_params={}),I.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function Er(){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,d('"method="')),i!==null?(e=nn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){I.uri_params||(I.uri_params={}),I.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function yr(){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,d('"ttl="')),i!==null?(e=er(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){I.params||(I.params={}),I.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,d('"maddr="')),i!==null?(e=es(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){I.uri_params||(I.uri_params={}),I.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function Ar(){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,d('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e!==null?(l=D(),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){I.uri_params||(I.uri_params={}),I.uri_params.lr=void 0}()),i===null&&(s=u),i}function Rr(){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,d('"="')),e!==null?(l=Ir(),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,y){I.uri_params||(I.uri_params={}),typeof y>"u"?y=void 0:y=y[1],I.uri_params[v.toLowerCase()]=y}(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 Ir(){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=bs(),i===null&&(i=x(),i===null&&(i=_e())),i}function bs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,d('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,d('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,d('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,d('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')))))))),i}function wr(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i!==null)if(e=Xs(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,d('"&"')),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,d('"&"')),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,d('"="')),e!==null?(l=Or(),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(""),I.uri_headers||(I.uri_headers={}),I.uri_headers[m]?I.uri_headers[m].push(v):I.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function Qs(){var i,e;if(e=Is(),e===null&&(e=x(),e===null&&(e=_e())),e!==null)for(i=[];e!==null;)i.push(e),e=Is(),e===null&&(e=x(),e===null&&(e=_e()));else i=null;return i}function Or(){var i,e;for(i=[],e=Is(),e===null&&(e=x(),e===null&&(e=_e()));e!==null;)i.push(e),e=Is(),e===null&&(e=x(),e===null&&(e=_e()));return i}function Is(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,d('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,d('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,d('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')))))))),i}function Zs(){var i;return i=rn(),i===null&&(i=ml()),i}function ml(){var i,e,l,u,f,p;return p=s,i=nn(),i!==null?(e=C(),e!==null?(l=Dr(),l!==null?(u=C(),u!==null?(f=Pn(),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 Dr(){var i;return i=we(),i===null&&(i=Un()),i}function Un(){var i,e,l,u;return u=s,i=Ns(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),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=Nr(),i===null&&(i=en()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,d('"?"')),e!==null?(l=Mr(),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 Nr(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,d('"//"')),i!==null?(e=Ur(),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,d('"/"')),i!==null?(e=xr(),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=re(),i===null&&(i=x(),i===null&&(i=_e())),i}function Os(){var i;return i=x(),i===null&&(i=_e(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,d('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,d('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,d('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,d('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,d('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,d('","')))))))))))),i}function xr(){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,d('"/"')),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,d('"/"')),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,d('";"')),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,d('";"')),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=x(),i===null&&(i=_e(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,d('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,d('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,d('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,d('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,d('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,d('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,d('","')))))))))),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,d('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,d('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,d('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,d('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,d('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){I.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function Ur(){var i;return i=kr(),i===null&&(i=Pr()),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,d('"@"')),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 Pr(){var i,e;if(e=x(),e===null&&(e=_e(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,d('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,d('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,d('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,d('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,d('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=x(),e===null&&(e=_e(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,d('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,d('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,d('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,d('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,d('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,d('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,d('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,d('"+"')))))))))));else i=null;return i}function Mr(){var i,e;for(i=[],e=ws();e!==null;)i.push(e),e=ws();return i}function Pn(){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,d('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,d('"/"')),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,d('"."')),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(y){I.sip_version=n.substring(s,y)}(m)),i===null&&(s=m),i}function Mn(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,d('"INVITE"')),i}function Lr(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,d('"ACK"')),i}function $r(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,d('"OPTIONS"')),i}function Hr(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,d('"BYE"')),i}function Fr(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,d('"CANCEL"')),i}function Vr(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,d('"REGISTER"')),i}function jr(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,d('"SUBSCRIBE"')),i}function qr(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,d('"NOTIFY"')),i}function Br(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,d('"REFER"')),i}function nn(){var i,e;return e=s,i=Mn(),i===null&&(i=Lr(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=Vr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=Br(),i===null&&(i=D()))))))))),i!==null&&(i=function(l){return I.method=n.substring(s,l),I.method}(e)),i===null&&(s=e),i}function rn(){var i,e,l,u,f,p;return p=s,i=Pn(),i!==null?(e=C(),e!==null?(l=Gr(),l!==null?(u=C(),u!==null?(f=Kr(),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 Gr(){var i,e;return e=s,i=Wr(),i!==null&&(i=function(l,u){I.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Wr(){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 Kr(){var i,e,l;for(l=s,i=[],e=re(),e===null&&(e=x(),e===null&&(e=_e(),e===null&&(e=K(),e===null&&(e=V(),e===null&&(e=C(),e===null&&(e=$()))))));e!==null;)i.push(e),e=re(),e===null&&(e=x(),e===null&&(e=_e(),e===null&&(e=K(),e===null&&(e=V(),e===null&&(e=C(),e===null&&(e=$()))))));return i!==null&&(i=function(u){I.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function gl(){var i,e,l,u,f,p;if(f=s,i=an(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=an(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=an(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function zo(){var i,e,l,u,f,p;return u=s,f=s,i=He(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,d('"@"')),e!==null?(l=He(),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){I=n.substring(s,m)}(u)),i===null&&(s=u),i}function Xo(){var i,e,l,u,f,p,m;if(f=s,i=Q(),i===null)if(p=s,i=Ln(),i!==null){for(e=[],m=s,l=Ae(),l!==null?(u=Ln(),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=Ln(),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 y,O;for(O=I.multi_header.length,y=0;y<O;y++)if(I.multi_header[y].parsed===null){I=null;break}I!==null?I=I.multi_header:I=-1}()),i===null&&(s=f),i}function Ln(){var i,e,l,u,f,p,m;if(f=s,p=s,i=me(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=xs(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=xs(),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 y;I.multi_header||(I.multi_header=[]);try{y=new fs(I.uri,I.display_name,I.params),delete I.uri,delete I.display_name,delete I.params}catch{y=null}I.multi_header.push({possition:s,offset:v,parsed:y})}(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=ke(),e!==null?(l=we(),l!==null?(u=Ie(),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=D(),i!==null){for(e=[],m=s,l=pe(),l!==null?(u=D(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=pe(),l!==null?(u=D(),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,y){typeof y=="string"?I.display_name=y:I.display_name=y[1].reduce(function(O,le){return O+le[0]+le[1]},y[0])}(f,i)),i===null&&(s=f),i}function xs(){var i;return i=$n(),i===null&&(i=Yr(),i===null&&(i=We())),i}function $n(){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,d('"q"')),i!==null?(e=B(),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){I.params||(I.params={}),I.params.q=m}(u,i[2])),i===null&&(s=u),i}function Yr(){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,d('"expires"')),i!==null?(e=B(),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){I.params||(I.params={}),I.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,d('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,d('"."')),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(y){return parseFloat(n.substring(s,y))}(p)),i===null&&(s=p),i}function We(){var i,e,l,u,f,p;return u=s,f=s,i=D(),i!==null?(p=s,e=B(),e!==null?(l=Ke(),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,y){I.params||(I.params={}),typeof y>"u"?y=void 0:y=y[1],I.params[v.toLowerCase()]=y}(u,i[0],i[1])),i===null&&(s=u),i}function Ke(){var i;return i=D(),i===null&&(i=es(),i===null&&(i=be())),i}function Tl(){var i,e,l,u,f,p;if(f=s,i=vl(),i!==null){for(e=[],p=s,l=oe(),l!==null?(u=Hn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=oe(),l!==null?(u=Hn(),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 vl(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,d('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,d('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,d('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,d('"alert"')),i===null&&(i=D())))),i}function Hn(){var i;return i=Fn(),i===null&&(i=We()),i}function Fn(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,d('"handling"')),i!==null?(e=B(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,d('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,d('"required"')),l===null&&(l=D())),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=D(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=D(),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=D(),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 Qo(){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){I=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Zo(){var i,e;return e=s,i=El(),i!==null&&(i=function(l){I=n.substring(s,l)}(e)),i===null&&(s=e),i}function El(){var i,e,l,u,f,p,m,v;if(m=s,i=Jr(),i!==null)if(e=W(),e!==null)if(l=Qr(),l!==null){for(u=[],v=s,f=oe(),f!==null?(p=Vn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=oe(),f!==null?(p=Vn(),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 Jr(){var i;return i=zr(),i===null&&(i=Xr()),i}function zr(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,d('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,d('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,d('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,d('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,d('"application"')),i===null&&(i=ln()))))),i}function Xr(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,d('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,d('"multipart"')),i===null&&(i=ln())),i}function ln(){var i;return i=D(),i===null&&(i=on()),i}function on(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,d('"x-"')),i!==null?(e=D(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Qr(){var i;return i=ln(),i===null&&(i=D()),i}function Vn(){var i,e,l,u;return u=s,i=D(),i!==null?(e=B(),e!==null?(l=jn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function jn(){var i;return i=D(),i===null&&(i=be()),i}function yl(){var i,e,l,u;return u=s,i=Cl(),i!==null?(e=pe(),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){I.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Al(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){I=u}(e,i)),i===null&&(s=e),i}function ea(){var i,e,l,u,f,p,m;if(f=s,p=s,i=an(),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=We(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=We(),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,y){I.event=y.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function an(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,d('"."')),l!==null?(u=U(),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,d('"."')),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 un(){var i,e,l,u,f,p,m;if(f=s,p=s,i=me(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=Zr(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=Zr(),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 y=I.tag;try{I=new fs(I.uri,I.display_name,I.params),y&&I.setParam("tag",y)}catch{I=-1}}()),i===null&&(s=f),i}function Zr(){var i;return i=cn(),i===null&&(i=We()),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,d('"tag"')),i!==null?(e=B(),e!==null?(l=D(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.tag=m}(u,i[2])),i===null&&(s=u),i}function ei(){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){I=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ta(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){I=u}(e,i)),i===null&&(s=e),i}function sa(){var i,e,l,u,f,p,m,v,y,O;for(v=s,y=s,i=[],e=Ht();e!==null;)i.push(e),e=Ht();if(i!==null)if(e=ke(),e!==null)if(l=we(),l!==null)if(u=Ie(),u!==null){for(f=[],O=s,p=oe(),p!==null?(m=We(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=oe(),p!==null?(m=We(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=y)}else i=null,s=y;else i=null,s=y;else i=null,s=y;else i=null,s=y;return i!==null&&(i=function(le){try{I=new fs(I.uri,I.display_name,I.params)}catch{I=-1}}()),i===null&&(s=v),i}function na(){var i;return i=ti(),i}function ti(){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,d('"Digest"')),i!==null)if(e=pe(),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=qn()),i}function qn(){var i,e,l,u,f,p,m,v;if(m=s,i=D(),i!==null)if(e=pe(),e!==null)if(l=Us(),l!==null){for(u=[],v=s,f=Ae(),f!==null?(p=Us(),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=Us(),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 Us(){var i,e,l,u;return u=s,i=D(),i!==null?(e=B(),e!==null?(l=D(),l===null&&(l=be()),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=ni(),i===null&&(i=hn(),i===null&&(i=ii(),i===null&&(i=li(),i===null&&(i=oi(),i===null&&(i=ai(),i===null&&(i=Us()))))))),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,d('"realm"')),i!==null?(e=B(),e!==null?(l=si(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function si(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){I.realm=u}(e,i)),i===null&&(s=e),i}function ni(){var i,e,l,u,f,p,m,v,y;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,d('"domain"')),i!==null)if(e=B(),e!==null)if(l=nt(),l!==null)if(u=dn(),u!==null){if(f=[],y=s,m=C(),m!==null)for(p=[];m!==null;)p.push(m),m=C();else p=null;for(p!==null?(m=dn(),m!==null?p=[p,m]:(p=null,s=y)):(p=null,s=y);p!==null;){if(f.push(p),y=s,m=C(),m!==null)for(p=[];m!==null;)p.push(m),m=C();else p=null;p!==null?(m=dn(),m!==null?p=[p,m]:(p=null,s=y)):(p=null,s=y)}f!==null?(p=ot(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function dn(){var i;return i=Un(),i===null&&(i=en()),i}function hn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,d('"nonce"')),i!==null?(e=B(),e!==null?(l=ri(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ri(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){I.nonce=u}(e,i)),i===null&&(s=e),i}function ii(){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,d('"opaque"')),i!==null?(e=B(),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){I.opaque=m}(u,i[2])),i===null&&(s=u),i}function li(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,d('"stale"')),i!==null?(e=B(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,d('"true"')),l!==null&&(l=function(p){I.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,d('"false"')),l!==null&&(l=function(p){I.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,d('"algorithm"')),i!==null?(e=B(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,d('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,d('"MD5-sess"')),l===null&&(l=D())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function ai(){var i,e,l,u,f,p,m,v,y,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,d('"qop"')),i!==null)if(e=B(),e!==null)if(l=nt(),l!==null){if(y=s,u=_n(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,d('","')),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,d('","')),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=y)}else u=null,s=y;u!==null?(f=ot(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function _n(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,d('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,d('"auth"')),i===null&&(i=D())),i!==null&&(i=function(l,u){I.qop||(I.qop=[]),I.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function Bn(){var i,e,l,u,f,p;if(f=s,i=D(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=D(),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=D(),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 ra(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Gn(),i!==null){for(e=[],m=s,l=Ae(),l!==null?(u=Gn(),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=Gn(),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 y,O;for(O=I.multi_header.length,y=0;y<O;y++)if(I.multi_header[y].parsed===null){I=null;break}I!==null?I=I.multi_header:I=-1}()),i===null&&(s=f),i}function Gn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=$t(),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=We(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=We(),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 y;I.multi_header||(I.multi_header=[]);try{y=new fs(I.uri,I.display_name,I.params),delete I.uri,delete I.display_name,delete I.params}catch{y=null}I.multi_header.push({possition:s,offset:v,parsed:y})}(f)),i===null&&(s=f),i}function Wn(){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,d('"SIP"')),i===null&&(i=D()),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=ui(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=ui(),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,y){if(I.protocol=y.toLowerCase(),I.params||(I.params={}),I.params.text&&I.params.text[0]==='"'){var O=I.params.text;I.text=O.substring(1,O.length-1),delete I.params.text}}(f,i[0])),i===null&&(s=f),i}function ui(){var i;return i=Kn(),i===null&&(i=We()),i}function Kn(){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,d('"cause"')),i!==null)if(e=B(),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){I.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function Rl(){var i,e,l,u,f,p;if(f=s,i=D(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=D(),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=D(),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 ia(){var i,e,l,u,f,p;if(f=s,i=Yn(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=Yn(),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=Yn(),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 Yn(){var i,e,l,u,f,p;if(f=s,i=$t(),i!==null){for(e=[],p=s,l=oe(),l!==null?(u=We(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=oe(),l!==null?(u=We(),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=bl(),i!==null){for(e=[],p=s,l=oe(),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=oe(),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 bl(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,d('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,d('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,d('"terminated"')),i===null&&(i=D()))),i!==null&&(i=function(l){I.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function zn(){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,d('"reason"')),i!==null?(e=B(),e!==null?(l=Xn(),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"&&(I.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,d('"expires"')),i!==null?(e=B(),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"&&(I.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,d('"retry_after"')),i!==null?(e=B(),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"&&(I.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=We()))),i}function Xn(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,d('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,d('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,d('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,d('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,d('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,d('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,d('"invariant"')),i===null&&(i=D()))))))),i}function Il(){var i;return i=q(),i=i!==null?i:"",i}function la(){var i,e,l,u,f,p;if(f=s,i=D(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=D(),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=D(),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 oa(){var i,e,l,u,f,p,m;if(f=s,p=s,i=me(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=oe(),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=oe(),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){var y=I.tag;try{I=new fs(I.uri,I.display_name,I.params),y&&I.setParam("tag",y)}catch{I=-1}}()),i===null&&(s=f),i}function ci(){var i;return i=cn(),i===null&&(i=We()),i}function fi(){var i,e,l,u,f,p;if(f=s,i=Qn(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=Qn(),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=Qn(),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 Qn(){var i,e,l,u,f,p,m,v;if(m=s,i=gi(),i!==null)if(e=pe(),e!==null)if(l=Si(),l!==null){for(u=[],v=s,f=oe(),f!==null?(p=ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=oe(),f!==null?(p=ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function ks(){var i;return i=Zn(),i===null&&(i=di(),i===null&&(i=hi(),i===null&&(i=_i(),i===null&&(i=pi(),i===null&&(i=We()))))),i}function Zn(){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,d('"ttl"')),i!==null?(e=B(),e!==null?(l=er(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.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,d('"maddr"')),i!==null?(e=B(),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){I.maddr=m}(u,i[2])),i===null&&(s=u),i}function hi(){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,d('"received"')),i!==null?(e=B(),e!==null?(l=at(),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){I.received=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,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,d('"branch"')),i!==null?(e=B(),e!==null?(l=D(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.branch=m}(u,i[2])),i===null&&(s=u),i}function pi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,d('"rport"')),i!==null?(f=s,e=B(),e!==null?(l=mi(),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 mi(){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,y){I.rport=parseInt(y.join(""))}(p,i)),i===null&&(s=p),i}function gi(){var i,e,l,u,f,p;return p=s,i=Ti(),i!==null?(e=W(),e!==null?(l=D(),l!==null?(u=W(),u!==null?(f=vi(),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 Ti(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,d('"SIP"')),i===null&&(i=D()),i!==null&&(i=function(l,u){I.protocol=u}(e,i)),i===null&&(s=e),i}function vi(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,d('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,d('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,d('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,d('"SCTP"')),i===null&&(i=D())))),i!==null&&(i=function(l,u){I.transport=u}(e,i)),i===null&&(s=e),i}function Si(){var i,e,l,u,f;return u=s,i=Ei(),i!==null?(f=s,e=ye(),e!==null?(l=yi(),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 Ei(){var i,e;return e=s,i=at(),i===null&&(i=Dn(),i===null&&(i=us())),i!==null&&(i=function(l){I.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function yi(){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,y){I.port=parseInt(y.join(""))}(p,i)),i===null&&(s=p),i}function er(){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=ti(),i}function aa(){var i,e,l,u,f,p;if(f=s,i=wl(),i!==null){for(e=[],p=s,l=oe(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=oe(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function wl(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){I.expires=u}(e,i)),i===null&&(s=e),i}function tr(){var i;return i=sr(),i===null&&(i=We()),i}function sr(){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,d('"refresher"')),i!==null?(e=B(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,d('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,d('"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){I.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function Ol(){var i,e,l,u;return u=s,i=D(),i!==null?(e=N(),e!==null?(l=Dl(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Dl(){var i,e;for(i=[],e=j(),e===null&&(e=V(),e===null&&(e=pe()));e!==null;)i.push(e),e=j(),e===null&&(e=V(),e===null&&(e=pe()));return i}function Nl(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function ua(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,d('"uuid:"')),i!==null?(e=xl(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function xl(){var i,e,l,u,f,p,m,v,y,O,le;return O=s,le=s,i=Vt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,d('"-"')),e!==null?(l=Ft(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,d('"-"')),u!==null?(f=Ft(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,d('"-"')),p!==null?(m=Ft(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,d('"-"')),v!==null?(y=Ai(),y!==null?i=[i,e,l,u,f,p,m,v,y]:(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le)):(i=null,s=le),i!==null&&(i=function(xe,wt){I=n.substring(s+5,xe)}(O,i[0])),i===null&&(s=O),i}function Ft(){var i,e,l,u,f;return f=s,i=S(),i!==null?(e=S(),e!==null?(l=S(),l!==null?(u=S(),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 Vt(){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 Ai(){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 Ul(){var i,e,l,u,f,p,m;if(f=s,p=s,i=me(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=oe(),l!==null?(u=We(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=oe(),l!==null?(u=We(),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{I=new fs(I.uri,I.display_name,I.params)}catch{I=-1}}()),i===null&&(s=f),i}function ca(){var i,e,l,u,f,p;if(f=s,i=kl(),i!==null){for(e=[],p=s,l=oe(),l!==null?(u=nr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=oe(),l!==null?(u=nr(),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=He(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,d('"@"')),e!==null?(l=He(),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){I.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function nr(){var i;return i=rr(),i===null&&(i=Ri(),i===null&&(i=bi(),i===null&&(i=We()))),i}function rr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,d('"to-tag"')),i!==null?(e=B(),e!==null?(l=D(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.to_tag=m}(u,i[2])),i===null&&(s=u),i}function Ri(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,d('"from-tag"')),i!==null?(e=B(),e!==null?(l=D(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){I.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,d('"early-only"')),i!==null&&(i=function(l){I.early_only=!0}()),i===null&&(s=e),i}function Pl(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 fa(){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 Ml=ys(),fs=Hu(),I={},w=a[o]();if(w===null||s!==n.length){var Ii=Math.max(s,r),wi=Ii<n.length?n.charAt(Ii):null,Ll=fa();return new this.SyntaxError(Pl(_),wi,Ii,Ll.line,Ll.column),-1}return I},toSource:function(){return this._source}};return t.SyntaxError=function(n,o,a,s,r){function _(d,h){var g,T;switch(d.length){case 0:g="end of input";break;case 1:g=d[0];break;default:g=d.slice(0,d.length-1).join(", ")+" or "+d[d.length-1]}return T=h?c(h):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=o,this.message=_(n,o),this.offset=a,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Ma}var La,nf;function ys(){if(nf)return La;nf=1;const c=De,t=Ct(),n=Zt();return La=class cd{static parse(a){if(a=n.parse(a,"SIP_URI"),a!==-1)return a}constructor(a,s,r,_,d={},h={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=a||c.SIP,this._user=s,this._host=r,this._port=_;for(const g in d)Object.prototype.hasOwnProperty.call(d,g)&&this.setParam(g,d[g]);for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setHeader(g,h[g])}get scheme(){return this._scheme}set scheme(a){this._scheme=a.toLowerCase()}get user(){return this._user}set user(a){this._user=a}get host(){return this._host}set host(a){this._host=a.toLowerCase()}get port(){return this._port}set port(a){this._port=a===0?a:parseInt(a,10)||null}setParam(a,s){a&&(this._parameters[a.toLowerCase()]=typeof s>"u"||s===null?null:s.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 s=this._parameters[a];return delete this._parameters[a],s}}clearParams(){this._parameters={}}setHeader(a,s){this._headers[t.headerize(a)]=Array.isArray(s)?s:[s]}getHeader(a){if(a)return this._headers[t.headerize(a)]}hasHeader(a){if(a)return this._headers.hasOwnProperty(t.headerize(a))&&!0||!1}deleteHeader(a){if(a=t.headerize(a),this._headers.hasOwnProperty(a)){const s=this._headers[a];return delete this._headers[a],s}}clearHeaders(){this._headers={}}clone(){return new cd(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const a=[];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 _ of this._headers[r])a.push(`${r}=${_}`);return a.length>0&&(s+=`?${a.join("&")}`),s}toAor(a){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,a&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},La}var rf;function Ct(){if(rf)return tt;rf=1;const c=De,t=ys(),n=Zt();tt.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const o=tt.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;tt.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,tt.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),tt.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),tt.hasMethods=function(r,..._){for(const d of _)if(o(r[d]))return!1;return!0};const a=tt.createRandomToken=(r,_=32)=>{let d,h,g="";for(d=0;d<r;d++)h=Math.random()*_|0,g+=h.toString(_);return g};tt.newTag=()=>a(10),tt.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,_=>{const d=Math.random()*16|0;return(_==="x"?d:d&3|8).toString(16)}),tt.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=tt.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return tt.normalizeTarget=(r,_)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const d=r.split("@");let h,g;switch(d.length){case 1:if(!_)return;h=r,g=_;break;case 2:h=d[0],g=d[1];break;default:h=d.slice(0,d.length-1).join("@"),g=d[d.length-1]}h=h.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(h)&&(h=h.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(h)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},tt.headerize=r=>{const _={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},d=r.toLowerCase().replace(/_/g,"-").split("-");let h="";const g=d.length;let T;for(T=0;T<g;T++)T!==0&&(h+="-"),h+=d[T].charAt(0).toUpperCase()+d[T].substring(1);return _[h]&&(h=_[h]),h},tt.sipErrorCause=r=>{for(const _ in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[_].indexOf(r)!==-1)return c.causes[_];return c.causes.SIP_FAILURE_CODE},tt.getRandomTestNetIP=()=>{function r(_,d){return Math.floor(Math.random()*(d-_+1)+_)}return`192.0.2.${r(1,254)}`},tt.calculateMD5=r=>{function _(Ee,Ce){return Ee<<Ce|Ee>>>32-Ce}function d(Ee,Ce){const be=Ee&2147483648,Oe=Ce&2147483648,ge=Ee&1073741824,ue=Ce&1073741824,me=(Ee&1073741823)+(Ce&1073741823);return ge&ue?me^2147483648^be^Oe:ge|ue?me&1073741824?me^3221225472^be^Oe:me^1073741824^be^Oe:me^be^Oe}function h(Ee,Ce,be){return Ee&Ce|~Ee&be}function g(Ee,Ce,be){return Ee&be|Ce&~be}function T(Ee,Ce,be){return Ee^Ce^be}function S(Ee,Ce,be){return Ce^(Ee|~be)}function E(Ee,Ce,be,Oe,ge,ue,me){return Ee=d(Ee,d(d(h(Ce,be,Oe),ge),me)),d(_(Ee,ue),Ce)}function A(Ee,Ce,be,Oe,ge,ue,me){return Ee=d(Ee,d(d(g(Ce,be,Oe),ge),me)),d(_(Ee,ue),Ce)}function R(Ee,Ce,be,Oe,ge,ue,me){return Ee=d(Ee,d(d(T(Ce,be,Oe),ge),me)),d(_(Ee,ue),Ce)}function C(Ee,Ce,be,Oe,ge,ue,me){return Ee=d(Ee,d(d(S(Ce,be,Oe),ge),me)),d(_(Ee,ue),Ce)}function $(Ee){let Ce;const be=Ee.length,Oe=be+8,ue=((Oe-Oe%64)/64+1)*16,me=new Array(ue-1);let we=0,Ne=0;for(;Ne<be;)Ce=(Ne-Ne%4)/4,we=Ne%4*8,me[Ce]=me[Ce]|Ee.charCodeAt(Ne)<<we,Ne++;return Ce=(Ne-Ne%4)/4,we=Ne%4*8,me[Ce]=me[Ce]|128<<we,me[ue-2]=be<<3,me[ue-1]=be>>>29,me}function k(Ee){let Ce="",be="",Oe,ge;for(ge=0;ge<=3;ge++)Oe=Ee>>>ge*8&255,be=`0${Oe.toString(16)}`,Ce=Ce+be.substr(be.length-2,2);return Ce}function re(Ee){let Ce="";for(let be=0;be<Ee.length;be++){const Oe=Ee.charCodeAt(be);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 x=[],F,_e,pe,P,N,q,j,K,V;const z=7,D=12,U=17,X=22,He=5,Q=9,W=14,B=20,ie=4,ve=11,Ie=16,ke=23,Ae=6,oe=10,ye=15,nt=21;for(r=re(r),x=$(r),q=1732584193,j=4023233417,K=2562383102,V=271733878,F=0;F<x.length;F+=16)_e=q,pe=j,P=K,N=V,q=E(q,j,K,V,x[F+0],z,3614090360),V=E(V,q,j,K,x[F+1],D,3905402710),K=E(K,V,q,j,x[F+2],U,606105819),j=E(j,K,V,q,x[F+3],X,3250441966),q=E(q,j,K,V,x[F+4],z,4118548399),V=E(V,q,j,K,x[F+5],D,1200080426),K=E(K,V,q,j,x[F+6],U,2821735955),j=E(j,K,V,q,x[F+7],X,4249261313),q=E(q,j,K,V,x[F+8],z,1770035416),V=E(V,q,j,K,x[F+9],D,2336552879),K=E(K,V,q,j,x[F+10],U,4294925233),j=E(j,K,V,q,x[F+11],X,2304563134),q=E(q,j,K,V,x[F+12],z,1804603682),V=E(V,q,j,K,x[F+13],D,4254626195),K=E(K,V,q,j,x[F+14],U,2792965006),j=E(j,K,V,q,x[F+15],X,1236535329),q=A(q,j,K,V,x[F+1],He,4129170786),V=A(V,q,j,K,x[F+6],Q,3225465664),K=A(K,V,q,j,x[F+11],W,643717713),j=A(j,K,V,q,x[F+0],B,3921069994),q=A(q,j,K,V,x[F+5],He,3593408605),V=A(V,q,j,K,x[F+10],Q,38016083),K=A(K,V,q,j,x[F+15],W,3634488961),j=A(j,K,V,q,x[F+4],B,3889429448),q=A(q,j,K,V,x[F+9],He,568446438),V=A(V,q,j,K,x[F+14],Q,3275163606),K=A(K,V,q,j,x[F+3],W,4107603335),j=A(j,K,V,q,x[F+8],B,1163531501),q=A(q,j,K,V,x[F+13],He,2850285829),V=A(V,q,j,K,x[F+2],Q,4243563512),K=A(K,V,q,j,x[F+7],W,1735328473),j=A(j,K,V,q,x[F+12],B,2368359562),q=R(q,j,K,V,x[F+5],ie,4294588738),V=R(V,q,j,K,x[F+8],ve,2272392833),K=R(K,V,q,j,x[F+11],Ie,1839030562),j=R(j,K,V,q,x[F+14],ke,4259657740),q=R(q,j,K,V,x[F+1],ie,2763975236),V=R(V,q,j,K,x[F+4],ve,1272893353),K=R(K,V,q,j,x[F+7],Ie,4139469664),j=R(j,K,V,q,x[F+10],ke,3200236656),q=R(q,j,K,V,x[F+13],ie,681279174),V=R(V,q,j,K,x[F+0],ve,3936430074),K=R(K,V,q,j,x[F+3],Ie,3572445317),j=R(j,K,V,q,x[F+6],ke,76029189),q=R(q,j,K,V,x[F+9],ie,3654602809),V=R(V,q,j,K,x[F+12],ve,3873151461),K=R(K,V,q,j,x[F+15],Ie,530742520),j=R(j,K,V,q,x[F+2],ke,3299628645),q=C(q,j,K,V,x[F+0],Ae,4096336452),V=C(V,q,j,K,x[F+7],oe,1126891415),K=C(K,V,q,j,x[F+14],ye,2878612391),j=C(j,K,V,q,x[F+5],nt,4237533241),q=C(q,j,K,V,x[F+12],Ae,1700485571),V=C(V,q,j,K,x[F+3],oe,2399980690),K=C(K,V,q,j,x[F+10],ye,4293915773),j=C(j,K,V,q,x[F+1],nt,2240044497),q=C(q,j,K,V,x[F+8],Ae,1873313359),V=C(V,q,j,K,x[F+15],oe,4264355552),K=C(K,V,q,j,x[F+6],ye,2734768916),j=C(j,K,V,q,x[F+13],nt,1309151649),q=C(q,j,K,V,x[F+4],Ae,4149444226),V=C(V,q,j,K,x[F+11],oe,3174756917),K=C(K,V,q,j,x[F+2],ye,718787259),j=C(j,K,V,q,x[F+9],nt,3951481745),q=d(q,_e),j=d(j,pe),K=d(K,P),V=d(V,N);return(k(q)+k(j)+k(K)+k(V)).toLowerCase()},tt.closeMediaStream=r=>{if(r)try{let _;if(r.getTracks){_=r.getTracks();for(const d of _)d.stop()}else{_=r.getAudioTracks();for(const d of _)d.stop();_=r.getVideoTracks();for(const d of _)d.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},tt.cloneArray=r=>r&&r.slice()||[],tt.cloneObject=(r,_={})=>r&&Object.assign({},r)||_,tt}const fd=kt,jm=ut,Et=De,it=Ct(),lf=Hu(),qm=Zt(),$a=new jm("SIPMessage");class Yo{constructor(t,n,o,a,s,r){if(!t||!n||!o)return null;a=a||{},this.ua=o,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)),a.route_set?this.setHeader("route",a.route_set):o.configuration.use_preloaded_route&&this.setHeader("route",`<${o.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);const _=a.to_uri||n,d=a.to_tag?{tag:a.to_tag}:null,h=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new lf(_,h,d),this.setHeader("to",this.to.toString());const g=a.from_uri||o.configuration.uri,T={tag:a.from_tag||it.newTag()};let S;typeof a.from_display_name<"u"?S=a.from_display_name:o.configuration.display_name?S=o.configuration.display_name:S=null,this.from=new lf(g,S,T),this.setHeader("from",this.from.toString());const E=a.call_id||o.configuration.jssip_id+it.createRandomToken(15);this.call_id=E,this.setHeader("call-id",E);const A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${t}`)}setHeader(t,n){const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(let a=0;a<this.extraHeaders.length;a++)o.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,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 o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(o.test(a))return a.substring(a.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[it.headerize(t)],o=[];if(n){for(const a of n)o.push(a);return o}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)a.test(s)&&o.push(s.substring(s.indexOf(":")+1).trim());return o}}hasHeader(t){if(this.headers[it.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(n.test(o))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fd.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
|
76
|
+
`;for(const a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a))for(const s of this.headers[a])t+=`${a}: ${s}\r
|
|
77
|
+
`;for(const a of this.extraHeaders)t+=`${a.trim()}\r
|
|
78
|
+
`;const n=[];switch(this.method){case Et.REGISTER:n.push("path","gruu");break;case Et.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 Et.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const o=this.ua.configuration.user_agent||Et.USER_AGENT;if(t+=`Allow: ${Et.ALLOWED_METHODS}\r
|
|
79
79
|
`,t+=`Supported: ${n}\r
|
|
80
|
-
`,t+=`User-Agent: ${
|
|
81
|
-
`,this.body){const
|
|
80
|
+
`,t+=`User-Agent: ${o}\r
|
|
81
|
+
`,this.body){const a=it.str_utf8_length(this.body);t+=`Content-Length: ${a}\r
|
|
82
82
|
\r
|
|
83
83
|
`,t+=this.body}else t+=`Content-Length: 0\r
|
|
84
84
|
\r
|
|
85
|
-
`;return t}clone(){const t=new
|
|
86
|
-
`;if(this.method===Et.INVITE&&t>100&&t<=200){const T=this.getHeaders("record-route");for(const S of T)
|
|
87
|
-
`}const g=this.getHeaders("via");for(const T of g)
|
|
88
|
-
`;!this.to_tag&&t>100?
|
|
89
|
-
`,
|
|
90
|
-
`,
|
|
91
|
-
`,
|
|
92
|
-
`;for(const T of
|
|
93
|
-
`;switch(this.method){case Et.INVITE:this.ua.configuration.session_timers&&_.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&_.push("gruu"),_.push("ice","replaces");break;case Et.UPDATE:this.ua.configuration.session_timers&&_.push("timer"),
|
|
94
|
-
`,
|
|
95
|
-
`):t===405?
|
|
96
|
-
`:t===415&&(
|
|
97
|
-
`),
|
|
98
|
-
`,
|
|
99
|
-
`,
|
|
85
|
+
`;return t}clone(){const t=new Yo(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){t.headers[n]=this.headers[n].slice()},this),t.body=this.body,t.extraHeaders=it.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}class Fu extends Yo{constructor(t,n,o,a,s){super(Et.INVITE,t,n,o,a,s),this.transaction=null}cancel(t){this.transaction.cancel(t)}clone(){const t=new Fu(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){t.headers[n]=this.headers[n].slice()},this),t.body=this.body,t.extraHeaders=it.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t.transaction=this.transaction,t}}class dd{constructor(){this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}addHeader(t,n){const o={raw:n};t=it.headerize(t),this.headers[t]?this.headers[t].push(o):this.headers[t]=[o]}getHeader(t){const n=this.headers[it.headerize(t)];if(n){if(n[0])return n[0].raw}else return}getHeaders(t){const n=this.headers[it.headerize(t)],o=[];if(!n)return[];for(const a of n)o.push(a.raw);return o}hasHeader(t){return!!this.headers[it.headerize(t)]}parseHeader(t,n=0){if(t=it.headerize(t),this.headers[t]){if(n>=this.headers[t].length){$a.debug(`not so many "${t}" headers present`);return}}else{$a.debug(`header "${t}" not present`);return}const o=this.headers[t][n],a=o.raw;if(o.parsed)return o.parsed;const s=qm.parse(a,t.replace(/-/g,"_"));if(s===-1){this.headers[t].splice(n,1),$a.debug(`error parsing "${t}" header field with value "${a}"`);return}else return o.parsed=s,s}s(t,n){return this.parseHeader(t,n)}setHeader(t,n){const o={raw:n};this.headers[it.headerize(t)]=[o]}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fd.parse(this.body||""),this.sdp)}toString(){return this.data}}class Bm extends dd{constructor(t){super(),this.ua=t,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(t,n,o,a,s,r){const _=[];let d=this.getHeader("To");if(t=t||null,n=n||null,!t||t<100||t>699)throw new TypeError(`Invalid status_code: ${t}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||Et.REASON_PHRASE[t]||"",o=it.cloneArray(o),this.ua.configuration.extra_headers&&(o=o.concat(this.ua.configuration.extra_headers));let h=`SIP/2.0 ${t} ${n}\r
|
|
86
|
+
`;if(this.method===Et.INVITE&&t>100&&t<=200){const T=this.getHeaders("record-route");for(const S of T)h+=`Record-Route: ${S}\r
|
|
87
|
+
`}const g=this.getHeaders("via");for(const T of g)h+=`Via: ${T}\r
|
|
88
|
+
`;!this.to_tag&&t>100?d+=`;tag=${it.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(d+=`;tag=${this.to_tag}`),h+=`To: ${d}\r
|
|
89
|
+
`,h+=`From: ${this.getHeader("From")}\r
|
|
90
|
+
`,h+=`Call-ID: ${this.call_id}\r
|
|
91
|
+
`,h+=`CSeq: ${this.cseq} ${this.method}\r
|
|
92
|
+
`;for(const T of o)h+=`${T.trim()}\r
|
|
93
|
+
`;switch(this.method){case Et.INVITE:this.ua.configuration.session_timers&&_.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&_.push("gruu"),_.push("ice","replaces");break;case Et.UPDATE:this.ua.configuration.session_timers&&_.push("timer"),a&&_.push("ice"),_.push("replaces")}if(_.push("outbound"),this.method===Et.OPTIONS?(h+=`Allow: ${Et.ALLOWED_METHODS}\r
|
|
94
|
+
`,h+=`Accept: ${Et.ACCEPTED_BODY_TYPES}\r
|
|
95
|
+
`):t===405?h+=`Allow: ${Et.ALLOWED_METHODS}\r
|
|
96
|
+
`:t===415&&(h+=`Accept: ${Et.ACCEPTED_BODY_TYPES}\r
|
|
97
|
+
`),h+=`Supported: ${_}\r
|
|
98
|
+
`,a){const T=it.str_utf8_length(a);h+=`Content-Type: application/sdp\r
|
|
99
|
+
`,h+=`Content-Length: ${T}\r
|
|
100
100
|
\r
|
|
101
|
-
`,
|
|
101
|
+
`,h+=a}else h+=`Content-Length: 0\r
|
|
102
102
|
\r
|
|
103
|
-
`;this.server_transaction.receiveResponse(t,
|
|
104
|
-
`;for(const r of a
|
|
105
|
-
`;let s=this.getHeader("To");if(!this.to_tag&&t>100?s+=`;tag=${it.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(s+=`;tag=${this.to_tag}`),
|
|
106
|
-
`,
|
|
107
|
-
`,
|
|
108
|
-
`,
|
|
109
|
-
`,this.ua.configuration.extra_headers)for(const r of this.ua.configuration.extra_headers)
|
|
110
|
-
`;
|
|
103
|
+
`;this.server_transaction.receiveResponse(t,h,s,r)}reply_sl(t=null,n=null){const o=this.getHeaders("via");if(!t||t<100||t>699)throw new TypeError(`Invalid status_code: ${t}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||Et.REASON_PHRASE[t]||"";let a=`SIP/2.0 ${t} ${n}\r
|
|
104
|
+
`;for(const r of o)a+=`Via: ${r}\r
|
|
105
|
+
`;let s=this.getHeader("To");if(!this.to_tag&&t>100?s+=`;tag=${it.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(s+=`;tag=${this.to_tag}`),a+=`To: ${s}\r
|
|
106
|
+
`,a+=`From: ${this.getHeader("From")}\r
|
|
107
|
+
`,a+=`Call-ID: ${this.call_id}\r
|
|
108
|
+
`,a+=`CSeq: ${this.cseq} ${this.method}\r
|
|
109
|
+
`,this.ua.configuration.extra_headers)for(const r of this.ua.configuration.extra_headers)a+=`${r.trim()}\r
|
|
110
|
+
`;a+=`Content-Length: 0\r
|
|
111
111
|
\r
|
|
112
|
-
`,this.transport.send(o)}}class Bm extends fh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var yt={OutgoingRequest:Wa,InitialOutgoingInviteRequest:Hu,IncomingRequest:qm,IncomingResponse:Bm};const _r=ze(yt),Gm=ut,ps=At(),Jt=new Gm("DigestAuthentication");var hh=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 _,h;return this._qop==="auth"?(_=`${this._method}:${this._uri}`,h=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(_=`${this._method}:${this._uri}:${ps.calculateMD5(a||"")}`,h=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(_=`${this._method}:${this._uri}`,h=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=null [a2:"%s"]',_),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 Wm=ze(hh),ms=500,Km=4e3,lf=5e3;var Fu={T1:ms,T2:Km,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 Li=ze(Fu),dl=ft.EventEmitter,_l=ut,zi=De,af=yt,as=Fu,of=new _l("NonInviteClientTransaction"),Jl=new _l("InviteClientTransaction"),Ym=new _l("AckClientTransaction"),uf=new _l("NonInviteServerTransaction"),zl=new _l("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 Jm extends dl{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 zm extends dl{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&&(Jl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){Jl.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(){Jl.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(){Jl.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(zi.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(zi.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 Xm extends dl{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(){Ym.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Qm extends dl{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 Zm extends dl{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(){zl.debug(`Timer H expired for transaction ${this.id}`),this.state===de.STATUS_COMPLETED&&zl.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(){zl.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,zl.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 eg({_transactions:c},t){let n;switch(t.method){case zi.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 zi.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 zi.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 gr={C:de,NonInviteClientTransaction:Jm,InviteClientTransaction:zm,AckClientTransaction:Xm,NonInviteServerTransaction:Qm,InviteServerTransaction:Zm,checkTransaction:eg};const Gt=ze(gr),tg=ut,cf=De,sg=hh,$o=gr,ng=new tg("RequestSender"),Ho={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Tr=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 Ho)Object.prototype.hasOwnProperty.call(Ho,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Ho[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 $o.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new $o.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new $o.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){ng.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 sg({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 tl=ze(Tr),rg=ut,Fo=At(),Tn=De,ff=yt,hf=Tr,$i=new rg("Registrator"),Xl=10;var ig=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=Fo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance=`"<urn:uuid:${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){$i.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")){$i.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((d,g)=>d.concat(g.parsed),[]);let r=s.find(d=>this._sipInstance===d.getParam("+sip.instance")&&this._reg_id===parseInt(d.getParam("reg-id")));if(r||(r=s.find(d=>d.uri.user===this._ua.contact.uri.user)),!r){$i.debug("no Contact header pointing to us, response ignored");break}let _=r.getParam("expires");!_&&o.hasHeader("expires")&&(_=o.getHeader("expires")),_||(_=this._expires),_=Number(_),_<Xl&&(_=Xl);const h=_>64?_*1e3/2+Math.floor((_/2-32)*1e3*Math.random()):_*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<Xl&&(this._expires=Xl),this.register()):($i.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,Tn.causes.SIP_FAILURE_CODE));break}default:{const s=Fo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){$i.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=Fo.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 lg 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 ag extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class og extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class ug extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var As={ConfigurationError:lg,InvalidStateError:ag,NotSupportedError:og,NotReadyError:ug};const js=ze(As),Vo=De,Ql=gr,cg=Tr,jo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var dh=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 jo)Object.prototype.hasOwnProperty.call(jo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=jo[o]))}get request(){return this._request}send(){const t=new cg(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===Vo.INVITE||this._request.method===Vo.UPDATE&&this._request.body)&&t.clientTransaction.state!==Ql.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===Ql.C.STATUS_ACCEPTED||t.clientTransaction.state===Ql.C.STATUS_COMPLETED||t.clientTransaction.state===Ql.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===Vo.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 fg=ze(dh),hg=ut,df=yt,$s=De,Hi=gr,dg=dh,qo=At(),Bo=new hg("Dialog"),Hs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var _h=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),Bo.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,Bo.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Bo.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Hs.STATUS_TERMINATED}sendRequest(t,n={}){const a=qo.cloneArray(n.extraHeaders),o=qo.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new dg(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=qo.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===Hi.C.STATUS_ACCEPTED||t.server_transaction.state===Hi.C.STATUS_COMPLETED||t.server_transaction.state===Hi.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===Hi.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===Hi.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const Zl=ze(_h);var Vu={exports:{}};const _g=ft.EventEmitter,pg=ut,mg=De,gg=As,_f=At(),Tg=new pg("RTCSession:DTMF"),ph={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Vu.exports=class extends _g{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 gg.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
|
-
`;
|
|
114
|
-
`);
|
|
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 Dg=ze(vh),Ng=ft.EventEmitter,gf=Pt,Ug=ut,fe=De,Sn=As,Tf=gr,Be=At(),Vi=Fu,xg=yt,ea=_h,Pg=Tr,Mt=mh,vf=gh,kg=Th,Mg=vh,Sf=ys(),Y=new Ug("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},ta=["audio","video"];var Sh=class Au extends Ng{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),_=Be.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,d=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 Sn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Sn.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 S=n.anonymous||!1,E={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:S,outbound:!0}),S?(E.from_display_name="Anonymous",E.from_uri=new Sf("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(E.from_uri=new Sf("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(E.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,E,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(d,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(_,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:[]}),_=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,d=Be.cloneObject(t.rtcOfferConstraints);let g,T=!1,S=!1,E=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new Sn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new Sn.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 R of C.media)R.type==="audio"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(E=!0)),R.type==="video"&&(S=!0,(!R.direction||R.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const R of g)s.removeTrack(R)}if(s&&o.video===!1){g=s.getVideoTracks();for(const R of g)s.removeTrack(R)}!s&&o.audio===void 0&&(o.audio=E),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!d.offerToReceiveAudio&&(o.audio=!1),!s&&!S&&!d.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,_),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(R=>{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]',R),this.emit("getusermediafailed",R),new Error("getUserMedia() failed"))})}).then(R=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(k=>{this._connection.addTrack(k,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",R);const k=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(k)).catch(M=>{throw n.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',M),this.emit("peerconnection:setremotedescriptionfailed",M),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(R=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,R,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,fe.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(R)})}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,_=t.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new Sn.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&&(_=_||fe.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),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,_,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"),_=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="${_}"`),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:d})=>{d===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 Sn.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,_.call(this);function _(){let h;if(this._status===Z.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const d=this._tones[a];if(a+=1,d===",")h=2e3;else{const g=new Mt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(d,n),h=o+s}setTimeout(_.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 Sn.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 Mg(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=Vi.T1;function o(){this._status===Z.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Vi.T2&&(a=a*2,a>Vi.T2&&(a=Vi.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))},Vi.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,_,h;this._iceReady=!1;const d=()=>{a.removeEventListener("icecandidate",_),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",_=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:d}):r||d()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&d()})})})}_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 _=this._earlyDialogs[r];if(a)return _?!0:(_=new ea(this,t,n,ea.C.STATUS_EARLY),_.error?(Y.debug(_.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const h=new ea(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(_={}){o=!0;const h=_.status_code||403,d=_.reason_phrase||"",g=Be.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,d,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(_=>{r.call(this,_)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(_=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{Y.warn(_)});function r(_){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(_=this._mangleOffer(_)),t.reply(200,null,h,_,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,_),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(_={}){o=!0;const h=_.status_code||403,d=_.reason_phrase||"",g=Be.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,d,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(_=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{Y.warn(_)});function r(_){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,_),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(ta.indexOf(r.type)===-1)continue;const _=r.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="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 kg(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 _=new Au(this._ua);if(_.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),_.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),_.on("_failed",({message:h,cause:d})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,d)}),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}`)}_.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 Pg(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 ea(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 d={originator:"local",type:"offer",sdp:h};Y.debug('emit "sdp"'),this.emit("sdp",d),this.sendRequest(fe.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{_.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});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"){_.call(this);return}}else{_.call(this);return}const d={originator:"remote",type:"answer",sdp:h.body};Y.debug('emit "sdp"'),this.emit("sdp",d);const g=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{_.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(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(d=>{d=this._mangleOffer(d);const g={originator:"local",type:"offer",sdp:d};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:n,body:d,eventHandlers:{onSuccessResponse:T=>{_.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,d)},onErrorResponse:d=>{h.call(this,d)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(d){if(this._status!==Z.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(d),s){if(d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:d.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(d)}).catch(S=>{h.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}else a.succeeded&&a.succeeded(d)}function h(d){a.failed&&a.failed(d)}}_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)ta.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)ta.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)ta.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 Lg=ze(Sh),$g=ft.EventEmitter,Hg=ut,Wo=De,Fg=yt,ji=At(),Vg=Tr,Ef=As,jg=ys(),sa=new Hg("Message");var qg=class extends $g{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=ji.cloneArray(a.extraHeaders),r=ji.cloneObject(a.eventHandlers),_=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new jg("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: ${_}`),this._request=new Fg.OutgoingRequest(Wo.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const d=new Vg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),d.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=ji.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new Ef.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=ji.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new Ef.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=ji.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Wo.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Wo.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(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){sa.debug("MESSAGE failed"),this._close(),sa.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){sa.debug("MESSAGE succeeded"),this._close(),sa.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const Bg=ft.EventEmitter,Gg=ut,Ko=De,Wg=yt,qi=At(),Kg=Tr,yf=As,na=new Gg("Options");var Yg=class extends Bg{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=qi.cloneArray(a.extraHeaders),r=qi.cloneObject(a.eventHandlers),_=a.contentType||"application/sdp";for(const d in r)Object.prototype.hasOwnProperty.call(r,d)&&this.on(d,r[d]);s.push(`Content-Type: ${_}`),this._request=new Wg.OutgoingRequest(Ko.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Kg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:d=>{this._receiveResponse(d)}});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=qi.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=qi.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=qi.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)}_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){na.debug("OPTIONS failed"),this._close(),na.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){na.debug("OPTIONS succeeded"),this._close(),na.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},ju={};const Jg=ut,Yo=At(),zg=Zt(),Bi=new Jg("Socket");ju.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return Bi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Yo.isString(c.url))throw Bi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Yo.isString(c.via_transport))throw Bi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(zg.parse(c.sip_uri,"SIP_URI")===-1)throw Bi.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(!Yo.isFunction(c[t]))throw Bi.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const Xg=ut,Qg=ju,Af=De,Ut=new Xg("Transport"),qt={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 Eh=class{constructor(t,n=qt.recovery_options){Ut.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){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(!Qg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(Ut.debug("connect()"),this.isConnected()){Ut.debug("Transport is already connected");return}else if(this.isConnecting()){Ut.debug("Transport is connecting");return}this.close_requested=!1,this.status=qt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){Ut.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=qt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(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:
|
|
112
|
+
`,this.transport.send(a)}}class Gm extends dd{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var yt={OutgoingRequest:Yo,InitialOutgoingInviteRequest:Fu,IncomingRequest:Bm,IncomingResponse:Gm};const _r=Xe(yt),Wm=ut,ps=Ct(),Jt=new Wm("DigestAuthentication");var hd=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:o},a,s=null){if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Jt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Jt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Jt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Jt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Jt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Jt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=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;return this._qop==="auth"?(_=`${this._method}:${this._uri}`,d=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${d}`)):this._qop==="auth-int"?(_=`${this._method}:${this._uri}:${ps.calculateMD5(o||"")}`,d=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${d}`)):this._qop===null&&(_=`${this._method}:${this._uri}`,d=ps.calculateMD5(_),Jt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${d}`)),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=Xe(hd),ms=500,Ym=4e3,of=5e3;var Vu={T1:ms,T2:Ym,T4:of,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*of,TIMER_L:64*ms,TIMER_M:64*ms,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Li=Xe(Vu),hl=ft.EventEmitter,_l=ut,zi=De,af=yt,os=Vu,uf=new _l("NonInviteClientTransaction"),Jl=new _l("InviteClientTransaction"),Jm=new _l("AckClientTransaction"),cf=new _l("NonInviteServerTransaction"),zl=new _l("InviteServerTransaction"),he={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"};class zm extends hl{constructor(t,n,o,a){super(),this.type=he.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=o,this.eventHandlers=a;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 he}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},os.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){uf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){uf.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},os.TIMER_K);break;case he.STATUS_COMPLETED:break}}}class Xm extends hl{constructor(t,n,o,a){super(),this.type=he.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=o,this.eventHandlers=a,o.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 he}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},os.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(Jl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){Jl.debug(`Timer M expired for transaction ${this.id}`),this.state===he.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){Jl.debug(`Timer B expired for transaction ${this.id}`),this.state===he.STATUS_CALLING&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){Jl.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new af.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});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()},os.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==he.STATUS_PROCEEDING)return;const n=new af.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});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 he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},os.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case he.STATUS_COMPLETED:this.sendACK(t);break}}}class Qm extends hl{constructor(t,n,o,a){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=o,this.eventHandlers=a;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return he}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Jm.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Zm extends hl{constructor(t,n,o){super(),this.type=he.NON_INVITE_SERVER,this.id=o.via_branch,this.ua=t,this.transport=n,this.request=o,this.last_response="",o.server_transaction=this,this.state=he.STATUS_TRYING,t.newTransaction(this)}get C(){return he}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){cf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,cf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,o,a){if(t===100)switch(this.state){case he.STATUS_TRYING:this.stateChanged(he.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case he.STATUS_PROCEEDING:this.last_response=n,this.transport.send(n)?o&&o():(this.onTransportError(),a&&a());break}else if(t>=200&&t<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},os.TIMER_J),this.transport.send(n)?o&&o():(this.onTransportError(),a&&a());break;case he.STATUS_COMPLETED:break}}}class eg extends hl{constructor(t,n,o){super(),this.type=he.INVITE_SERVER,this.id=o.via_branch,this.ua=t,this.transport=n,this.request=o,this.last_response="",o.server_transaction=this,this.state=he.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,o.reply(100)}get C(){return he}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){zl.debug(`Timer H expired for transaction ${this.id}`),this.state===he.STATUS_COMPLETED&&zl.debug("ACK not received, dialog will be terminated"),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){zl.debug(`Timer L expired for transaction ${this.id}`),this.state===he.STATUS_ACCEPTED&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,zl.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(t,n,o,a){if(t>=100&&t<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},os.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},os.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(n)?o&&o():(this.onTransportError(),a&&a());break}else if(t>=300&&t<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},os.TIMER_H),o&&o()):(this.onTransportError(),a&&a());break}}}function tg({_transactions:c},t){let n;switch(t.method){case zi.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case he.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case he.STATUS_ACCEPTED:break}return!0}break;case zi.ACK:if(n=c.ist[t.via_branch],n){if(n.state===he.STATUS_ACCEPTED)return!1;if(n.state===he.STATUS_COMPLETED)return n.state=he.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},os.TIMER_I),!0}else return!1;break;case zi.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==he.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case he.STATUS_TRYING:break;case he.STATUS_PROCEEDING:case he.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var gr={C:he,NonInviteClientTransaction:zm,InviteClientTransaction:Xm,AckClientTransaction:Qm,NonInviteServerTransaction:Zm,InviteServerTransaction:eg,checkTransaction:tg};const Gt=Xe(gr),sg=ut,ff=De,ng=hd,Ha=gr,rg=new sg("RequestSender"),Fa={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Tr=class{constructor(t,n,o){this._ua=t,this._eventHandlers=o,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const a in Fa)Object.prototype.hasOwnProperty.call(Fa,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=Fa[a]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==ff.BYE||this._method!==ff.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 Ha.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new Ha.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new Ha.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,o;const a=t.status_code;if((a===401||a===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(n=t.parseHeader("www-authenticate"),o="authorization"):(n=t.parseHeader("proxy-authenticate"),o="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(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}};const tl=Xe(Tr),ig=ut,Va=Ct(),Tn=De,df=yt,hf=Tr,$i=new ig("Registrator"),Xl=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=Va.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 o=t[n];this._extraContactParams+=`;${n}`,o&&(this._extraContactParams+=`=${o}`)}}register(){if(this._registering){$i.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 df.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),o=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:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){$i.debug("no Contact header in response to REGISTER, response ignored");break}const s=a.headers.Contact.reduce((h,g)=>h.concat(g.parsed),[]);let r=s.find(h=>this._sipInstance===h.getParam("+sip.instance")&&this._reg_id===parseInt(h.getParam("reg-id")));if(r||(r=s.find(h=>h.uri.user===this._ua.contact.uri.user)),!r){$i.debug("no Contact header pointing to us, response ignored");break}let _=r.getParam("expires");!_&&a.hasHeader("expires")&&(_=a.getHeader("expires")),_||(_=this._expires),_=Number(_),_<Xl&&(_=Xl);const d=_>64?_*1e3/2+Math.floor((_/2-32)*1e3*Math.random()):_*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},d),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:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<Xl&&(this._expires=Xl),this.register()):($i.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,Tn.causes.SIP_FAILURE_CODE));break}default:{const s=Va.sipErrorCause(a.status_code);this._registrationFailure(a,s)}}}});this._registering=!0,o.send()}unregister(t={}){if(!this._registered){$i.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 o=new df.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,o,{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=Va.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 og 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 ag 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:og,InvalidStateError:ag,NotSupportedError:ug,NotReadyError:cg};const js=Xe(Cs),ja=De,Ql=gr,fg=Tr,qa={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var _d=class{constructor(t,n,o){this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=o,this._reattempt=!1,this._reattemptTimer=null;for(const a in qa)Object.prototype.hasOwnProperty.call(qa,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=qa[a]))}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===ja.INVITE||this._request.method===ja.UPDATE&&this._request.body)&&t.clientTransaction.state!==Ql.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===Ql.C.STATUS_ACCEPTED||t.clientTransaction.state===Ql.C.STATUS_COMPLETED||t.clientTransaction.state===Ql.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===ja.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 dg=Xe(_d),hg=ut,_f=yt,$s=De,Hi=gr,_g=_d,Ba=Ct(),Ga=new hg("Dialog"),Hs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var pd=class{static get C(){return Hs}constructor(t,n,o,a=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 _f.IncomingResponse&&(a=n.status_code<200?Hs.STATUS_EARLY:Hs.STATUS_CONFIRMED);const s=n.parseHeader("contact");o==="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=a,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):o==="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=a,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),Ga.debug(`new ${o} 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,Ga.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Ga.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Hs.STATUS_TERMINATED}sendRequest(t,n={}){const o=Ba.cloneArray(n.extraHeaders),a=Ba.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,o,s);return a.onAuthenticated=()=>{this._local_seqnum+=1},new _g(this,r,a).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,o){n=Ba.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=t===$s.CANCEL||t===$s.ACK?this._local_seqnum:this._local_seqnum+=1;return new _f.OutgoingRequest(t,this._remote_target,this._ua,{cseq:a,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,o)}_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===Hi.C.STATUS_ACCEPTED||t.server_transaction.state===Hi.C.STATUS_COMPLETED||t.server_transaction.state===Hi.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===Hi.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===Hi.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const Zl=Xe(pd);var ju={exports:{}};const pg=ft.EventEmitter,mg=ut,gg=De,Tg=Cs,pf=Ct(),vg=new mg("RTCSession:DTMF"),md={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 o=pf.cloneArray(n.extraHeaders);if(this.eventHandlers=pf.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,o.push("Content-Type: application/dtmf-relay");let a=`Signal=${this._tone}\r
|
|
113
|
+
`;a+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(gg.INFO,{extraHeaders:o,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:a})}init_incoming(t){const n=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,o=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=t,t.reply(200),t.body){const a=t.body.split(`
|
|
114
|
+
`);a.length>=1&&n.test(a[0])&&(this._tone=a[0].replace(n,"$2")),a.length>=2&&o.test(a[1])&&(this._duration=parseInt(a[1].replace(o,"$2"),10))}this._duration||(this._duration=md.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):vg.debug("invalid INFO DTMF received, discarded")}};ju.exports.C=md;var gd=ju.exports;const Sg=Xe(gd),Eg=ft.EventEmitter,yg=De,Cg=Cs,Ag=Ct();var Td=class extends Eg{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,o={}){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 a=Ag.cloneArray(o.extraHeaders);a.push(`Content-Type: ${t}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(yg.INFO,{extraHeaders:a,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 Cu=Xe(Td),Rg=ut,mf=De,bg=new Rg("RTCSession:ReferNotifier"),Wa={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var vd=class{constructor(t,n,o){this._session=t,this._id=n,this._expires=o||Wa.expires,this._active=!0,this.notify(100)}notify(t,n){if(bg.debug("notify()"),this._active===!1)return;n=n||mf.REASON_PHRASE[t]||"";let o;t>=200?o="terminated;reason=noresource":o=`active;expires=${this._expires}`,this._session.sendRequest(mf.NOTIFY,{extraHeaders:[`Event: ${Wa.event_type};id=${this._id}`,`Subscription-State: ${o}`,`Content-Type: ${Wa.body_type}`],body:`SIP/2.0 ${t} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const Ig=Xe(vd),wg=ft.EventEmitter,Og=ut,Fi=De,Dg=Zt(),gf=Ct(),vn=new Og("RTCSession:ReferSubscriber");var Sd=class extends wg{constructor(t){super(),this._id=null,this._session=t}get id(){return this._id}sendRefer(t,n={}){vn.debug("sendRefer()");const o=gf.cloneArray(n.extraHeaders),a=gf.cloneObject(n.eventHandlers);for(const d in a)Object.prototype.hasOwnProperty.call(a,d)&&this.on(d,a[d]);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(o.push(r),!o.some(d=>d.toLowerCase().startsWith("referred-by:"))){const d=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;o.push(d)}o.push(`Contact: ${this._session.contact}`);const _=this._session.sendRequest(Fi.REFER,{extraHeaders:o,eventHandlers:{onSuccessResponse:d=>{this._requestSucceeded(d)},onErrorResponse:d=>{this._requestFailed(d,Fi.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,Fi.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,Fi.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,Fi.causes.DIALOG_ERROR)}}});this._id=_.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=Xe(Sd),xg=ft.EventEmitter,Tf=kt,Ug=ut,fe=De,Sn=Cs,vf=gr,Ge=Ct(),Vi=Vu,kg=yt,eo=pd,Pg=Tr,Mt=gd,Sf=Td,Mg=vd,Lg=Sd,Ef=ys(),J=new Ug("RTCSession"),te={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},to=["audio","video"];var Ed=class Au extends xg{static get C(){return te}constructor(t){J.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._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 te}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 te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(t,n={},o){J.debug("connect()");const a=t,s=Ge.cloneObject(n.eventHandlers),r=Ge.cloneArray(n.extraHeaders),_=Ge.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),d=n.mediaStream||null,h=Ge.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new Sn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Sn.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);this._sessionTimers.enabled&&Ge.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=Ge.newTag();const S=n.anonymous||!1,E={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:S,outbound:!0}),S?(E.from_display_name="Anonymous",E.from_uri=new Ef("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(E.from_uri=new Ef("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(E.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 kg.InitialOutgoingInviteRequest(t,this._ua,E,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(h,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newRTCSession("local",this._request),this._sendInitialRequest(_,T,d)}init_incoming(t,n){J.debug("init_incoming()");let o;const a=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&a!=="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")&&(o=t.getHeader("expires")*1e3),t.to_tag=Ge.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.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),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,fe.causes.EXPIRES))},o)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){J.debug("answer()");const n=this._request,o=Ge.cloneArray(t.extraHeaders),a=Ge.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Ge.cloneObject(t.pcConfig,{iceServers:[]}),_=t.rtcConstraints||null,d=t.rtcAnswerConstraints||null,h=Ge.cloneObject(t.rtcOfferConstraints);let g,T=!1,S=!1,E=!1,A=!1;if(this._rtcAnswerConstraints=d,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new Sn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new Sn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ge.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),o.unshift(`Contact: ${this._contact}`);const R=n.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const C of R.media)C.type==="audio"&&(T=!0,(!C.direction||C.direction==="sendrecv")&&(E=!0)),C.type==="video"&&(S=!0,(!C.direction||C.direction==="sendrecv")&&(A=!0));if(s&&a.audio===!1){g=s.getAudioTracks();for(const C of g)s.removeTrack(C)}if(s&&a.video===!1){g=s.getVideoTracks();for(const C of g)s.removeTrack(C)}!s&&a.audio===void 0&&(a.audio=E),!s&&a.video===void 0&&(a.video=A),!s&&!T&&!h.offerToReceiveAudio&&(a.audio=!1),!s&&!S&&!h.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(r,_),Promise.resolve().then(()=>{if(s)return s;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(C=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),J.warn('emit "getusermediafailed" [error:%o]',C),this.emit("getusermediafailed",C),new Error("getUserMedia() failed"))})}).then(C=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=C,C&&C.getTracks().forEach($=>{this._connection.addTrack($,C)})}).then(()=>{if(this._late_sdp)return;const C={originator:"remote",type:"offer",sdp:n.body};J.debug('emit "sdp"'),this.emit("sdp",C);const $=new RTCSessionDescription({type:"offer",sdp:C.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription($)).catch(k=>{throw n.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',k),this.emit("peerconnection:setremotedescriptionfailed",k),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",d).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(C=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,o),n.reply(200,null,o,C,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,C),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,fe.causes.CONNECTION_ERROR)})}).catch(C=>{this._status!==te.STATUS_TERMINATED&&J.warn(C)})}terminate(t={}){J.debug("terminate()");const n=t.cause||fe.causes.BYE,o=Ge.cloneArray(t.extraHeaders),a=t.body;let s,r=t.status_code,_=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new Sn.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(J.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(_=_||fe.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),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,fe.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(J.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,_,o,a),this._failed("local",null,fe.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(J.debug("terminating session"),_=t.reason_phrase||fe.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&o.push(`Reason: SIP ;cause=${r}; text="${_}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==vf.C.STATUS_TERMINATED){const d=this._dialog;this.receiveRequest=({method:h})=>{h===fe.ACK&&(this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),d.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===vf.C.STATUS_TERMINATED&&(this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),d.terminate())}),this._ended("local",null,n),this._dialog=d,this._ua.newDialog(d)}else this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),this._ended("local",null,n)}}sendDTMF(t,n={}){J.debug("sendDTMF() | tones: %s",t);let o=0,a=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!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new Sn.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(a&&!Ge.isDecimal(a))throw new TypeError(`Invalid tone duration: ${a}`);if(a?a<Mt.C.MIN_DURATION?(J.debug(`"duration" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_DURATION} milliseconds`),a=Mt.C.MIN_DURATION):a>Mt.C.MAX_DURATION?(J.debug(`"duration" value is greater than the maximum allowed, setting it to ${Mt.C.MAX_DURATION} milliseconds`),a=Mt.C.MAX_DURATION):a=Math.abs(a):a=Mt.C.DEFAULT_DURATION,n.duration=a,s&&!Ge.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<Mt.C.MIN_INTER_TONE_GAP?(J.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 d=this._getDTMFRTPSender();d&&(t=d.toneBuffer+t,d.insertDTMF(t,a,s));return}if(this._tones){this._tones+=t;return}this._tones=t,_.call(this);function _(){let d;if(this._status===te.STATUS_TERMINATED||!this._tones||o>=this._tones.length){this._tones=null;return}const h=this._tones[o];if(o+=1,h===",")d=2e3;else{const g=new Mt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(h,n),d=a+s}setTimeout(_.bind(this),d)}}sendInfo(t,n,o={}){if(J.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new Sn.InvalidStateError(this._status);new Sf(this).send(t,n,o)}mute(t={audio:!0,video:!1}){J.debug("mute()");let n=!1,o=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(o=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||o===!0)&&this._onmute({audio:n,video:o})}unmute(t={audio:!0,video:!0}){J.debug("unmute()");let n=!1,o=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(o=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||o===!0)&&this._onunmute({audio:n,video:o})}hold(t={},n){if(J.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const o={succeeded:()=>{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:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(J.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const o={succeeded:()=>{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:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){J.debug("renegotiate()");const o=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={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:a,rtcOfferConstraints:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:o,extraHeaders:t.extraHeaders}),!0}refer(t,n){J.debug("refer()");const o=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: ${o}`);const a=new Lg(this);a.sendRefer(t,n);const s=a.id;return this._referSubscribers[s]=a,a.on("requestFailed",()=>{delete this._referSubscribers[s]}),a.on("accepted",()=>{delete this._referSubscribers[s]}),a.on("failed",()=>{delete this._referSubscribers[s]}),a}sendRequest(t,n){return J.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(J.debug("receiveRequest()"),t.method===fe.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,fe.causes.CANCELED));else switch(t.method){case fe.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:fe.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};J.debug('emit "sdp"'),this.emit("sdp",n);const o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(a=>{this.terminate({cause:fe.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",t);break;case fe.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,fe.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,fe.causes.BYE)):t.reply(403,"Wrong Status");break;case fe.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case fe.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 Mt(this).init_incoming(t):n!==void 0?new Sf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case fe.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case fe.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case fe.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){J.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.CONNECTION_ERROR,cause:fe.causes.CONNECTION_ERROR})}onRequestTimeout(){J.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:fe.causes.REQUEST_TIMEOUT,cause:fe.causes.REQUEST_TIMEOUT})}onDialogError(){J.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.DIALOG_ERROR,cause:fe.causes.DIALOG_ERROR})}newDTMF(t){J.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){J.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(J.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(J.debug("_isReadyToReOffer() | session not established yet"),!1):(J.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(J.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(J.debug("close() | closing local MediaStream"),Ge.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){J.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 o=Vi.T1;function a(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),o<Vi.T2&&(o=o*2,o>Vi.T2&&(o=Vi.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),o))}this._timers.invite2xxTimer=setTimeout(a.bind(this),o)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(J.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(fe.BYE),this._ended("remote",null,fe.causes.NO_ACK))},Vi.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})}),J.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(J.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const o=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?o.createOffer(n).catch(a=>(J.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):o.createAnswer(n).catch(a=>(J.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>o.setLocalDescription(a).catch(s=>(this._rtcReady=!0,J.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const a=n&&n.iceRestart;if(o.iceGatheringState==="complete"&&!a||o.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:o.localDescription.sdp};return J.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,_,d;this._iceReady=!1;const h=()=>{o.removeEventListener("icecandidate",_),o.removeEventListener("icegatheringstatechange",d),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:o.localDescription.sdp};J.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};o.addEventListener("icecandidate",_=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:h}):r||h()}),o.addEventListener("icegatheringstatechange",d=()=>{o.iceGatheringState==="complete"&&!r&&h()})})})}_createDialog(t,n,o){const a=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+a+s;let _=this._earlyDialogs[r];if(o)return _?!0:(_=new eo(this,t,n,eo.C.STATUS_EARLY),_.error?(J.debug(_.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const d=new eo(this,t,n);return d.error?(J.debug(d.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._dialog=d,!0)}}_receiveReinvite(t){J.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,o={request:t,callback:void 0,reject:s.bind(this)};let a=!1;function s(_={}){a=!0;const d=_.status_code||403,h=_.reason_phrase||"",g=Ge.cloneArray(_.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);t.reply(d,h,g)}if(this.emit("reinvite",o),a)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(_=>{r.call(this,_)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){J.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(_=>{this._status!==te.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{J.warn(_)});function r(_){const d=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,d),this._late_sdp&&(_=this._mangleOffer(_)),t.reply(200,null,d,_,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,_),this._setACKTimer()}),typeof o.callback=="function"&&o.callback()}}_receiveUpdate(t){J.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,o={request:t,callback:void 0,reject:s.bind(this)};let a=!1;function s(_={}){a=!0;const d=_.status_code||403,h=_.reason_phrase||"",g=Ge.cloneArray(_.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);t.reply(d,h,g)}if(this.emit("update",o),a)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){J.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(_=>{this._status!==te.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{J.warn(_)});function r(_){const d=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,d),t.reply(200,null,d,_),typeof o.callback=="function"&&o.callback()}}_processInDialogSdpOffer(t){J.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let o=!1;for(const r of n.media){if(to.indexOf(r.type)===-1)continue;const _=r.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="inactive")o=!0;else{o=!1;break}}const a={originator:"remote",type:"offer",sdp:t.body};J.debug('emit "sdp"'),this.emit("sdp",a);const s=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),J.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&&o===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&o===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),J.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{J.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(J.debug("receiveRefer()"),!t.refer_to){J.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==fe.SIP){J.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);J.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{o.call(this,s,r)},reject:()=>{a.call(this)}});function o(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const _=new Au(this._ua);if(_.on("progress",({response:d})=>{n.notify(d.status_code,d.reason_phrase)}),_.on("accepted",({response:d})=>{n.notify(d.status_code,d.reason_phrase)}),_.on("_failed",({message:d,cause:h})=>{d?n.notify(d.status_code,d.reason_phrase):n.notify(487,h)}),t.refer_to.uri.hasHeader("replaces")){const d=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Ge.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${d}`)}_.connect(t.refer_to.uri.toAor(),r,s)}function a(){n.notify(603)}}_receiveNotify(t){switch(J.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,o;if(t.event.params&&t.event.params.id)n=t.event.params.id,o=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)o=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!o){t.reply(481,"Subscription does not exist");return}o.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){J.debug("receiveReplaces()");function n(a){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new Au(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,a)}function o(){J.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:a=>{n.call(this,a)},reject:()=>{o.call(this)}})}_sendInitialRequest(t,n,o){const a=new Pg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(o)return o;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),J.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,fe.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=te.STATUS_INVITE_SENT,J.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&J.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){J.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(J.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 eo(this,t,"UAC");if(n.error!==void 0){J.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!==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){J.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};J.debug('emit "sdp"'),this.emit("sdp",n);const o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",t)).catch(a=>{J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.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};J.debug('emit "sdp"'),this.emit("sdp",n);const o=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()),this._failed("local",t,fe.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(o).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(fe.ACK),this._confirmed("local",null)}).catch(a=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})});break}default:{const n=Ge.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){J.debug("sendReinvite()");const n=Ge.cloneArray(t.extraHeaders),o=Ge.cloneObject(t.eventHandlers),a=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",a)).then(d=>{d=this._mangleOffer(d);const h={originator:"local",type:"offer",sdp:d};J.debug('emit "sdp"'),this.emit("sdp",h),this.sendRequest(fe.INVITE,{extraHeaders:n,body:d,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{_.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function r(d){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(fe.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(d),d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const h={originator:"remote",type:"answer",sdp:d.body};J.debug('emit "sdp"'),this.emit("sdp",h);const g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{o.succeeded&&o.succeeded(d)}).catch(T=>{_.call(this),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(d){o.failed&&o.failed(d)}}_sendUpdate(t={}){J.debug("sendUpdate()");const n=Ge.cloneArray(t.extraHeaders),o=Ge.cloneObject(t.eventHandlers),a=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",a)).then(h=>{h=this._mangleOffer(h);const g={originator:"local",type:"offer",sdp:h};J.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),r=!0},onErrorResponse:T=>{d.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d.call(this)})):this.sendRequest(fe.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:h=>{_.call(this,h)},onErrorResponse:h=>{d.call(this,h)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(h){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(h),s){if(h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const g={originator:"remote",type:"answer",sdp:h.body};J.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{o.succeeded&&o.succeeded(h)}).catch(S=>{d.call(this),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}else o.succeeded&&o.succeeded(h)}function d(h){o.failed&&o.failed(h)}}_acceptAndTerminate(t,n,o){J.debug("acceptAndTerminate()");const a=[];n&&(o=o||fe.REASON_PHRASE[n]||"",a.push(`Reason: SIP ;cause=${n}; text="${o}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(fe.ACK),this.sendRequest(fe.BYE,{extraHeaders:a})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=Tf.parse(t),this._localHold&&!this._remoteHold){J.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)to.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){J.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)to.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){J.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)to.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Tf.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 o;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,o=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,o="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${o}`),this._sessionTimers.refresher=o==="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!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(J.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===fe.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(J.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(o=>o.track&&o.track.kind==="audio");for(const o of n)o.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="video");for(const o of n)o.track.enabled=!t}_newRTCSession(t,n){J.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){J.debug("session connecting"),J.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){J.debug("session progress"),J.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){J.debug("session accepted"),this._start_time=new Date,J.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){J.debug("session confirmed"),this._is_confirmed=!0,J.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,o){J.debug("session ended"),this._end_time=new Date,this._close(),J.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:o})}_failed(t,n,o){J.debug("session failed"),J.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:o}),this._close(),J.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:o})}_onhold(t){J.debug("session onhold"),this._setLocalMediaStatus(),J.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){J.debug("session onunhold"),this._setLocalMediaStatus(),J.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){J.debug("session onmute"),this._setLocalMediaStatus(),J.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){J.debug("session onunmute"),this._setLocalMediaStatus(),J.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const $g=Xe(Ed),Hg=ft.EventEmitter,Fg=ut,Ka=De,Vg=yt,ji=Ct(),jg=Tr,yf=Cs,qg=ys(),so=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,o={}){const a=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: ${a}`);const s=ji.cloneArray(o.extraHeaders),r=ji.cloneObject(o.eventHandlers),_=o.contentType||"text/plain",d={};o.fromUserName&&(d.from_uri=new qg("sip",o.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),o.fromDisplayName&&(d.from_display_name=o.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${_}`),this._request=new Vg.OutgoingRequest(Ka.MESSAGE,t,this._ua,d,s),n&&(this._request.body=n);const h=new jg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),h.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=ji.cloneArray(t.extraHeaders),o=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,o)}reject(t={}){const n=t.status_code||480,o=t.reason_phrase,a=ji.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,o,a,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=ji.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Ka.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Ka.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,o){so.debug("MESSAGE failed"),this._close(),so.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:o})}_succeeded(t,n){so.debug("MESSAGE succeeded"),this._close(),so.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const Gg=ft.EventEmitter,Wg=ut,Ya=De,Kg=yt,qi=Ct(),Yg=Tr,Cf=Cs,no=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,o={}){const a=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: ${a}`);const s=qi.cloneArray(o.extraHeaders),r=qi.cloneObject(o.eventHandlers),_=o.contentType||"application/sdp";for(const h in r)Object.prototype.hasOwnProperty.call(r,h)&&this.on(h,r[h]);s.push(`Content-Type: ${_}`),this._request=new Kg.OutgoingRequest(Ya.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const d=new Yg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:h=>{this._receiveResponse(h)}});this._newOptions("local",this._request),d.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=qi.cloneArray(t.extraHeaders),o=t.body;if(this._direction!=="incoming")throw new Cf.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,o)}reject(t={}){const n=t.status_code||480,o=t.reason_phrase,a=qi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new Cf.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,o,a,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=qi.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Ya.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Ya.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,o){no.debug("OPTIONS failed"),this._close(),no.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:o})}_succeeded(t,n){no.debug("OPTIONS succeeded"),this._close(),no.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},qu={};const zg=ut,Ja=Ct(),Xg=Zt(),Bi=new zg("Socket");qu.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return Bi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Ja.isString(c.url))throw Bi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Ja.isString(c.via_transport))throw Bi.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 Bi.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(!Ja.isFunction(c[t]))throw Bi.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,xt=new Qg("Transport"),qt={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 yd=class{constructor(t,n=qt.recovery_options){xt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(o){xt.warn(`cannot use TextDecoder: ${o}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(o){if(!Zg.isSocket(o.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(o.weight&&!Number(o.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:o.socket,weight:o.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(xt.debug("connect()"),this.isConnected()){xt.debug("Transport is already connected");return}else if(this.isConnecting()){xt.debug("Transport is connecting");return}this.close_requested=!1,this.status=qt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){xt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=qt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(xt.debug("send()"),!this.isConnected())return xt.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return xt.debug(`sending message:
|
|
116
116
|
|
|
117
117
|
${n}
|
|
118
|
-
`),this.socket.send(n)}isConnected(){return this.status===qt.STATUS_CONNECTED}isConnecting(){return this.status===qt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),
|
|
119
|
-
`){
|
|
118
|
+
`),this.socket.send(n)}isConnected(){return this.status===qt.STATUS_CONNECTED}isConnecting(){return this.status===qt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),xt.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${t} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},t*1e3)}_getSocket(){let t=[];if(this.sockets.forEach(o=>{o.status!==qt.SOCKET_STATUS_ERROR&&(t.length===0?t.push(o):o.weight>t[0].weight?t=[o]:o.weight===t[0].weight&&t.push(o))}),t.length===0){this.sockets.forEach(o=>{o.status=qt.SOCKET_STATUS_READY}),this._getSocket();return}const n=Math.floor(Math.random()*t.length);this.socket=t[n].socket}_onConnect(){this.recover_attempts=0,this.status=qt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(t,n,o){this.status=qt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:t,code:n,reason:o}),!this.close_requested&&(this.sockets.forEach(function(a){this.socket===a.socket&&(a.status=qt.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}_onData(t){if(t===`\r
|
|
119
|
+
`){xt.debug("received message with CRLF Keep Alive response");return}else if(typeof t!="string"){try{this.textDecoder?t=this.textDecoder.decode(t):t=String.fromCharCode.apply(null,new Uint8Array(t))}catch{xt.debug("received binary message failed to be converted into string, message discarded");return}xt.debug(`received binary message:
|
|
120
120
|
|
|
121
121
|
${t}
|
|
122
|
-
`)}else
|
|
122
|
+
`)}else xt.debug(`received text message:
|
|
123
123
|
|
|
124
124
|
${t}
|
|
125
|
-
`);this.ondata({transport:this,message:t})}};const
|
|
126
|
-
`);if(
|
|
127
|
-
`,n),
|
|
128
|
-
`;for(const
|
|
129
|
-
`;n=
|
|
130
|
-
`,
|
|
131
|
-
`,
|
|
132
|
-
`,
|
|
133
|
-
`,
|
|
134
|
-
`,Ch.send(a)}const _T=ze(Rh);var nl={};const fr=At(),An=De,Jo=Zt(),Rf=ys(),zo=ju,Xo=As;nl.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:`${fr.createRandomToken(12)}.invalid`};const ia={mandatory:{sockets(c){const t=[];if(zo.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&zo.isSocket(n.socket)?t.push(n):zo.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(Jo.parse(`"${c}"`,"quoted_string")!==-1)return c},authorization_jwt(c){if(typeof c=="string")return c},user_agent(c){if(typeof c=="string")return c},connection_recovery_max_interval(c){if(fr.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(fr.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=Jo.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)),Jo.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(fr.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(fr.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}}};nl.load=(c,t)=>{for(const n in ia.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=ia.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Xo.ConfigurationError(n,a)}else throw new Xo.ConfigurationError(n);for(const n in ia.optional)if(t.hasOwnProperty(n)){const a=t[n];if(fr.isEmpty(a))continue;const o=ia.optional[n](a);if(o!==void 0)c[n]=o;else throw new Xo.ConfigurationError(n,a)}};const pT=ft.EventEmitter,mT=ut,mt=De,gT=ig,If=Sh,bf=qg,wf=Yg,Qo=gr,TT=Eh,la=At(),vT=As,ST=ys(),ET=yh,Zo=yt,yT=Rh,eu=nl,je=new mT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var Ih=class extends pT{static get C(){return vt}constructor(t){if(je.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},eu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=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 gT(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(){je.debug("start()"),this._status===vt.STATUS_INIT?this._transport.connect():this._status===vt.STATUS_USER_CLOSED?(je.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?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}register(){je.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(t){je.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){je.debug("call()");const a=new If(this);return a.connect(t,n),a}sendMessage(t,n,a){je.debug("sendMessage()");const o=new bf(this);return o.send(t,n,a),o}sendOptions(t,n,a){je.debug("sendOptions()");const o=new wf(this);return o.send(t,n,a),o}terminateSessions(t){je.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(je.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){je.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)){je.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 la.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:je.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 je.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){je.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(Qo.checkTransaction(this,t))return;if(n===mt.INVITE?new Qo.InviteServerTransaction(this,this._transport,t):n!==mt.ACK&&n!==mt.CANCEL&&new Qo.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):(je.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 je.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):je.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,_=this._sessions[r];return s||_||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{eu.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=la.newUUID()),this._configuration.jssip_id=la.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new TT(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=CT.bind(this),this._transport.ondisconnect=RT.bind(this),this._transport.ondata=IT.bind(this)}catch(o){throw je.warn(o),new vT.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",la.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 _="<";return s?_+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":_+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(_+=";ob"),_+=">",_}};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}));je.debug("configuration parameters after validation:");for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(eu.settings,o))switch(o){case"uri":case"registrar_server":je.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":je.debug(`- ${o}: NOT SHOWN`);break;default:je.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}}};function AT(c){this.emit("connecting",c)}function CT(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 RT(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 IT(c){const t=c.transport;let n=c.message;if(n=ET.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof Zo.IncomingRequest)&&yT(n,this,t)){if(n instanceof Zo.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Zo.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 bT=ze(Ih);var _t=[];for(var tu=0;tu<256;++tu)_t.push((tu+256).toString(16).slice(1));function wT(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 aa,OT=new Uint8Array(16);function DT(){if(!aa&&(aa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!aa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return aa(OT)}var NT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Of={randomUUID:NT};function Df(c,t,n){if(Of.randomUUID&&!t&&!c)return Of.randomUUID();c=c||{};var a=c.random||(c.rng||DT)();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 wT(a)}var ke=At();const Ts=ze(ke),su=new Ga("Dialog"),Fs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class oa{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),su.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,su.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){su.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 fg(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===H.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===H.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===H.CANCEL||t===H.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===H.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===H.INVITE||t.method===H.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===H.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 UT{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,_,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:h.publisher_state).find(d=>d.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 Rn=ze(xT),xt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new Ga("JanusSession"),PT="/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},ua=["audio","video"];class $a 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:H.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 H.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),_=ke.cloneArray(a.extraHeaders),h=ke.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const d=a.mediaStream||null,g=ke.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,S=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=S,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 js.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new js.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>=H.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=H.SESSION_EXPIRES);for(const C in r)Object.prototype.hasOwnProperty.call(r,C)&&this.on(C,r[C]);this._from_tag=ke.newTag();const E=a.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(A.from_display_name="Anonymous",A.from_uri=new Rn("sip","anonymous","anonymous.invalid"),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),_.push("Privacy: id")):a.fromUserName&&(A.from_uri=new Rn("sip",a.fromUserName,this._ua.configuration.uri.host),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(A.from_display_name=a.fromDisplayName),_.push(`Contact: ${this._contact}`),_.push("Content-Type: application/json"),this._sessionTimers.enabled&&_.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(t,this._ua,A,_),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,S,d)}_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,H.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,H.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:[]}),_=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,d=ke.cloneObject(t.rtcOfferConstraints);let g,T=!1,S=!1,E=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new js.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new js.InvalidStateError(this._status);if(this._sessionTimers.enabled&&ke.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=H.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=H.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 R of C.media)R.type==="audio"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(E=!0)),R.type==="video"&&(S=!0,(!R.direction||R.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const R of g)s.removeTrack(R)}if(s&&o.video===!1){g=s.getVideoTracks();for(const R of g)s.removeTrack(R)}!s&&o.audio===void 0&&(o.audio=E),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!d.offerToReceiveAudio&&(o.audio=!1),!s&&!S&&!d.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,_),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(R=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,H.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',R),this.emit("getusermediafailed",R),new Error("getUserMedia() failed"))})}).then(R=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(k=>{this._connection.addTrack(k,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",R);const k=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(k)).catch(M=>{throw n.reply(488),this._failed("system",null,H.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',M),this.emit("peerconnection:setremotedescriptionfailed",M),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(R=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,R,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,H.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==te.STATUS_TERMINATED&&z.warn(R)})}terminate(t={}){z.debug("terminate()");const n=t.cause||H.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,_=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new js.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&&(_=_||H.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),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,H.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,_,a,o),this._failed("local",null,H.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),_=t.reason_phrase||H.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${_}"`),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:d})=>{d===H.ACK&&(this.sendRequest(H.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(H.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"},d=["Content-Type: application/json",this.getPTypeHeader(xt.LEAVE)];this.sendRequest(H.BYE,{extraHeaders:d,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(xt.AUDIO_CHANGE)];this.sendRequest(H.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(xt.VIDEO_CHANGE)];this.sendRequest(H.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(xt.STATE)];this.sendRequest(H.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 js.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:H.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:H.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:H.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 Dg(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===H.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,H.causes.CANCELED));else switch(t.method){case H.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:H.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:H.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 H.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,H.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,H.causes.BYE)):t.reply(403,"Wrong Status");break;case H.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case H.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 vg(this).init_incoming(t):n!==void 0?new yu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case H.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case H.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case H.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:H.causes.CONNECTION_ERROR,cause:H.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:H.causes.REQUEST_TIMEOUT,cause:H.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:H.causes.DIALOG_ERROR,cause:H.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=Li.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Li.T2&&(a=a*2,a>Li.T2&&(a=Li.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(H.BYE),this._ended("remote",null,H.causes.NO_ACK))},Li.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:H.causes.RTP_TIMEOUT,status_code:408,reason_phrase:H.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,_,h;this._iceReady=!1;const d=()=>{a.removeEventListener("icecandidate",_),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",_=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:d}):r||d()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&d()})})})}_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 _=this._earlyDialogs[r];if(a)return _?!0:(_=new oa(this,t,n,oa.C.STATUS_EARLY),_.error?(z.debug(_.error),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const h=new oa(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,H.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(_={}){o=!0;const h=_.status_code||403,d=_.reason_phrase||"",g=ke.cloneArray(_.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,d,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(_=>{r.call(this,_)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(_=>{this._status!==te.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{z.warn(_)});function r(_){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(_=this._mangleOffer(_)),t.reply(200,null,h,_,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,_),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(_={}){o=!0;const h=_.status_code||403,d=_.reason_phrase||"",g=ke.cloneArray(_.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,d,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(_=>{this._status!==te.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{z.warn(_)});function r(_){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,_),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(ua.indexOf(r.type)===-1)continue;const _=r.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="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!==H.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new Ig(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 _=new $a(this._ua);if(_.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),_.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),_.on("_failed",({message:h,cause:d})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,d)}),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}`)}_.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 $a(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 tl(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,H.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,H.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},_=JSON.stringify(r);this._request.body=_,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 PT+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(xt.ICE)];this.sendRequest(H.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
|
|
135
|
-
`),d=h[h.length-1],g=JSON.parse(d);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(xt.CONFIGURE)];this.sendRequest(H.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(xt.TRICKLE)];this.sendRequest(H.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 E={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),a=await t.rtcpPeer.createAnswer(E),this._sendMemberStartMessage(t,a)}const d=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];d[0]&&T.push(d[0]),g[0]&&T.push(g[0]);const S=new MediaStream(T);t.stream=S,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const _=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=_,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(xt.SUBSCRIBER)];this.sendRequest(H.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const _=JSON.parse(o.body);(r=(s=_==null?void 0:_.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,_)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(xt.SUBSCRIBER)];this.sendRequest(H.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(xt.SUBSCRIBER)];this.sendRequest(H.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,_,h,d,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 UT(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=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:h.publishers,this.private_id=(g=(d=t==null?void 0:t.plugindata)==null?void 0:d.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(_=>_.type===t);let s=a.getStream().clone();for(const _ of n)_.running&&(s=await _.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(H.ACK);return}else{const n=new oa(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(H.ACK),this.sendRequest(H.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(xt.PUBLISHER)];this.sendRequest(H.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,_,h,d;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((_=(r=g.plugindata)==null?void 0:r.data)==null?void 0:_.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(d=(h=g.plugindata)==null?void 0:h.data)!=null&&d.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,H.causes.MISSING_SDP),this._failed("remote",t,H.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 d={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",d),this.sendRequest(H.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{_.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(H.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const d={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",d);const g=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{_.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(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(d=>{d=this._mangleOffer(d);const g={originator:"local",type:"offer",sdp:d};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(H.UPDATE,{extraHeaders:n,body:d,eventHandlers:{onSuccessResponse:T=>{_.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(H.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:d=>{_.call(this,d)},onErrorResponse:d=>{h.call(this,d)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(d){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(d),s){if(d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:d.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(d)}).catch(S=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}else a.succeeded&&a.succeeded(d)}function h(d){a.failed&&a.failed(d)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||H.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(H.ACK),this.sendRequest(H.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=Pt.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ua.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)ua.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)ua.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Pt.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>=H.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>=H.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===H.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:H.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 ur{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
|
|
136
|
-
`),o
|
|
137
|
-
`;else{const r=s.split(": ");this.addHeader(r[0],r[1].trim())}}}else this.ident=
|
|
125
|
+
`);this.ondata({transport:this,message:t})}};const eT=Xe(yd);var Cd={};const tT=ut,Ru=Zt(),bu=yt,ro=new tT("Parser");Cd.parseMessage=(c,t)=>{let n,o,a=c.indexOf(`\r
|
|
126
|
+
`);if(a===-1){ro.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,a);let r=Ru.parse(s,"Request_Response");if(r===-1){ro.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new bu.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new bu.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let _=a+2;for(;;){if(a=sT(c,_),a===-2){o=_+2;break}else if(a===-1){ro.warn("parseMessage() | malformed message");return}if(r=nT(n,c,_,a),r!==!0){ro.warn("parseMessage() |",r.error);return}_=a+2}if(n.hasHeader("content-length")){const d=n.getHeader("content-length");n.body=c.substr(o,d)}else n.body=c.substring(o);return n};function sT(c,t){let n=t,o=0,a=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;o===0;){if(a=c.indexOf(`\r
|
|
127
|
+
`,n),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?n=a+2:o=a}return o}function nT(c,t,n,o){let a;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),_=t.substring(s+1,o).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",_),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",_),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",_),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Ru.parse(_,"Record_Route"),a===-1)a=void 0;else for(const d of a)c.addHeader("record-route",_.substring(d.possition,d.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=d.parsed;break;case"call-id":case"i":c.setHeader("call-id",_),a=c.parseHeader("call-id"),a&&(c.call_id=_);break;case"contact":case"m":if(a=Ru.parse(_,"Contact"),a===-1)a=void 0;else for(const d of a)c.addHeader("contact",_.substring(d.possition,d.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=d.parsed;break;case"content-length":case"l":c.setHeader("content-length",_),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",_),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",_),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof bu.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",_),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",_),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",_),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",_),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",_),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",_),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",_),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(r,_),a=0}return a===void 0?{error:`error parsing header "${r}"`}:!0}const rT=ut,Ad=De,Rf=yt,Bu=Ct(),Gu=new rT("sanityCheck"),iT=[_T],lT=[aT,uT,cT,fT],oT=[dT,hT];let Ve,is,Rd;var bd=(c,t,n)=>{Ve=c,is=t,Rd=n;for(const o of iT)if(o()===!1)return!1;if(Ve instanceof Rf.IncomingRequest){for(const o of lT)if(o()===!1)return!1}else if(Ve instanceof Rf.IncomingResponse){for(const o of oT)if(o()===!1)return!1}return!0};function aT(){if(Ve.s("to").uri.scheme!=="sip")return sl(416),!1}function uT(){if(!Ve.to_tag&&Ve.call_id.substr(0,5)===is.configuration.jssip_id)return sl(482),!1}function cT(){const c=Bu.str_utf8_length(Ve.body),t=Ve.getHeader("content-length");if(c<t)return sl(400),!1}function fT(){const c=Ve.from_tag,t=Ve.call_id,n=Ve.cseq;let o;if(!Ve.to_tag)if(Ve.method===Ad.INVITE){if(is._transactions.ist[Ve.via_branch])return!1;for(const a in is._transactions.ist)if(Object.prototype.hasOwnProperty.call(is._transactions.ist,a)&&(o=is._transactions.ist[a],o.request.from_tag===c&&o.request.call_id===t&&o.request.cseq===n))return sl(482),!1}else{if(is._transactions.nist[Ve.via_branch])return!1;for(const a in is._transactions.nist)if(Object.prototype.hasOwnProperty.call(is._transactions.nist,a)&&(o=is._transactions.nist[a],o.request.from_tag===c&&o.request.call_id===t&&o.request.cseq===n))return sl(482),!1}}function dT(){if(Ve.getHeaders("via").length>1)return Gu.debug("more than one Via header field present in the response, dropping the response"),!1}function hT(){const c=Bu.str_utf8_length(Ve.body),t=Ve.getHeader("content-length");if(c<t)return Gu.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(!Ve.hasHeader(t))return Gu.debug(`missing mandatory header field : ${t}, dropping the response`),!1}function sl(c){const t=Ve.getHeaders("via");let n,o=`SIP/2.0 ${c} ${Ad.REASON_PHRASE[c]}\r
|
|
128
|
+
`;for(const a of t)o+=`Via: ${a}\r
|
|
129
|
+
`;n=Ve.getHeader("To"),Ve.to_tag||(n+=`;tag=${Bu.newTag()}`),o+=`To: ${n}\r
|
|
130
|
+
`,o+=`From: ${Ve.getHeader("From")}\r
|
|
131
|
+
`,o+=`Call-ID: ${Ve.call_id}\r
|
|
132
|
+
`,o+=`CSeq: ${Ve.cseq} ${Ve.method}\r
|
|
133
|
+
`,o+=`\r
|
|
134
|
+
`,Rd.send(o)}const pT=Xe(bd);var nl={};const fr=Ct(),Cn=De,za=Zt(),bf=ys(),Xa=qu,Qa=Cs;nl.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:`${fr.createRandomToken(12)}.invalid`};const io={mandatory:{sockets(c){const t=[];if(Xa.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&Xa.isSocket(n.socket)?t.push(n):Xa.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${Cn.SIP}:${c}`);const t=bf.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(za.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(fr.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(fr.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=za.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)),za.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(fr.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(fr.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${Cn.SIP}:${c}`);const t=bf.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}}};nl.load=(c,t)=>{for(const n in io.mandatory)if(t.hasOwnProperty(n)){const o=t[n],a=io.mandatory[n](o);if(a!==void 0)c[n]=a;else throw new Qa.ConfigurationError(n,o)}else throw new Qa.ConfigurationError(n);for(const n in io.optional)if(t.hasOwnProperty(n)){const o=t[n];if(fr.isEmpty(o))continue;const a=io.optional[n](o);if(a!==void 0)c[n]=a;else throw new Qa.ConfigurationError(n,o)}};const mT=ft.EventEmitter,gT=ut,mt=De,TT=lg,If=Ed,wf=Bg,Of=Jg,Za=gr,vT=yd,lo=Ct(),ST=Cs,ET=ys(),yT=Cd,eu=yt,CT=bd,tu=nl,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 Id=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 o=new If(this);return o.connect(t,n),o}sendMessage(t,n,o){qe.debug("sendMessage()");const a=new wf(this);return a.send(t,n,o),a}sendOptions(t,n,o){qe.debug("sendOptions()");const a=new Of(this);return a.send(t,n,o),a}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 o in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,o)){qe.debug(`closing session ${o}`);try{this._sessions[o].terminate()}catch{}}for(const o in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,o))try{this._applicants[o].close()}catch{}this._status=vt.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return lo.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(Za.checkTransaction(this,t))return;if(n===mt.INVITE?new Za.InviteServerTransaction(this,this._transport,t):n!==mt.ACK&&n!==mt.CANCEL&&new Za.NonInviteServerTransaction(this,this._transport,t),n===mt.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new Of(this).init_incoming(t)}else if(n===mt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new wf(this).init_incoming(t)}else if(n===mt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let o,a;if(t.to_tag)o=this._findDialog(t.call_id,t.from_tag,t.to_tag),o?o.receiveRequest(t):n===mt.NOTIFY?(a=this._findSession(t),a?a.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;o=this._findDialog(s.call_id,s.from_tag,s.to_tag),o?(a=o.owner,a.isEnded()?t.reply(603):a.receiveRequest(t)):t.reply(481)}else a=new If(this),a.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:a=this._findSession(t),a?a.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:o}){const a=t+n,s=this._sessions[a],r=t+o,_=this._sessions[r];return s||_||null}_findDialog(t,n,o){let a=t+n+o,s=this._dialogs[a];return s||(a=t+o+n,s=this._dialogs[a],s||null)}_loadConfig(t){try{tu.load(this._configuration,t)}catch(a){throw a}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=lo.newUUID()),this._configuration.jssip_id=lo.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=bT.bind(this),this._transport.ondata=IT.bind(this)}catch(a){throw qe.warn(a),new ST.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const a=this._configuration.uri.clone();a.user=null,a.clearParams(),a.clearHeaders(),this._configuration.registrar_server=a}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ET("sip",lo.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(a={}){const s=a.anonymous||null,r=a.outbound||null;let _="<";return s?_+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":_+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(_+=";ob"),_+=">",_}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const a in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,a)&&(o.indexOf(a)!==-1?Object.defineProperty(this._configuration,a,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,a,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:");for(const a in this._configuration)if(Object.prototype.hasOwnProperty.call(tu.settings,a))switch(a){case"uri":case"registrar_server":qe.debug(`- ${a}: ${this._configuration[a]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${a}: NOT SHOWN`);break;default:qe.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}};function 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 bT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const o in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],o)&&this._transactions[n][o].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function IT(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 o;switch(n.method){case mt.INVITE:o=this._transactions.ict[n.via_branch],o&&o.receiveResponse(n);break;case mt.ACK:break;default:o=this._transactions.nict[n.via_branch],o&&o.receiveResponse(n);break}}}}const wT=Xe(Id);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 oo,DT=new Uint8Array(16);function NT(){if(!oo&&(oo=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oo))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oo(DT)}var xT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Df={randomUUID:xT};function Nf(c,t,n){if(Df.randomUUID&&!t&&!c)return Df.randomUUID();c=c||{};var o=c.random||(c.rng||NT)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,t){n=n||0;for(var a=0;a<16;++a)t[n+a]=o[a];return t}return OT(o)}var Pe=Ct();const Ts=Xe(Pe),nu=new Ko("Dialog"),Fs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class ao{static get C(){return Fs}constructor(t,n,o,a=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&&(a=n.status_code<200?Fs.STATUS_EARLY:Fs.STATUS_CONFIRMED),o==="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=a,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(o==="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=a,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 ${o} 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 o=Ts.cloneArray(n.extraHeaders),a=Ts.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,o,s);return a.onAuthenticated=()=>{this._local_seqnum+=1},new dg(this,r,a).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===H.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===H.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,o){n=Ts.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=t===H.CANCEL||t===H.ACK?this._local_seqnum:this._local_seqnum+=1;return new yt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:a,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,o)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===H.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===H.INVITE||t.method===H.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===H.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 UT{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;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,a=((d=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:d.publisher_state).find(h=>h.id===n);this.updateMemberState(a==null?void 0:a.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(o=>o.kind===t):[]}static async getMicrophoneList(){return(await Qt.getDevices("audioinput")).map((n,o)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${o+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Qt.getDevices("audiooutput")).map((n,o)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${o+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Qt.getDevices("videoinput")).map((n,o)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${o+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 o,a;t==="default"?o=!0:t&&t!=="default"&&(o={deviceId:{exact:t}}),n==="default"?a=!0:n&&n!=="default"&&(a={deviceId:{exact:n}});const s={audio:a,video:o};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(o){let a=o;o.name==="SecurityError"&&(a=`You need to use HTTPS for selecting audio output device: ${o}`),console.error(a)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(o=>{o.enabled=!o.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(o=>{o.enabled=!o.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let o=n.getTracks();return t.video?o=n.getVideoTracks():t.audio&&(o=n.getAudioTracks()),o.length===0?{stream:n,track:null}:{stream:n,track:o[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var kT=ys();const Rn=Xe(kT),Ut={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},Z=new Ko("JanusSession"),PT="/opt/recordings/",se={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},uo=["audio","video"];class Fo extends ft.EventEmitter{static get C(){return se}constructor(t){Z.debug("new"),super(),this._id=null,this._ua=t,this._status=se.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:H.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 se}get causes(){return H.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 se.STATUS_NULL:case se.STATUS_INVITE_SENT:case se.STATUS_1XX_RECEIVED:case se.STATUS_INVITE_RECEIVED:case se.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case se.STATUS_ANSWERED:case se.STATUS_WAITING_FOR_ACK:case se.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case se.STATUS_CANCELED:case se.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-${Nf().replace(/-/g,"").slice(0,12)}`}connect(t,n,o={},a){Z.debug("connect()"),this.display_name=n;const s=t,r=Pe.cloneObject(o.eventHandlers),_=Pe.cloneArray(o.extraHeaders),d=Pe.cloneObject(o.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...d};const h=o.mediaStream||null,g=Pe.cloneObject(o.pcConfig,{iceServers:[]}),T=o.rtcConstraints||null,S=o.rtcOfferConstraints||null;if(this._rtcOfferConstraints=S,this._rtcAnswerConstraints=o.rtcAnswerConstraints||null,this._data=o.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==se.STATUS_NULL)throw new js.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new js.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&&Pe.isDecimal(o.sessionTimersExpires)&&(o.sessionTimersExpires>=H.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=o.sessionTimersExpires:this._sessionTimers.defaultExpires=H.SESSION_EXPIRES);for(const R in r)Object.prototype.hasOwnProperty.call(r,R)&&this.on(R,r[R]);this._from_tag=Pe.newTag();const E=o.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(A.from_display_name="Anonymous",A.from_uri=new Rn("sip","anonymous","anonymous.invalid"),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),_.push("Privacy: id")):o.fromUserName&&(A.from_uri=new Rn("sip",o.fromUserName,this._ua.configuration.uri.host),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),o.fromDisplayName&&(A.from_display_name=o.fromDisplayName),_.push(`Contact: ${this._contact}`),_.push("Content-Type: application/json"),this._sessionTimers.enabled&&_.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(t,this._ua,A,_),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,a&&a(this),this._newJanusSession("local",this._request),this._sendInitialRequest(d,S,h)}_overrideSenderTracks(t,n){t.getTracks().forEach(o=>{n.getSenders().forEach(async s=>{s.track.kind===o.kind&&(o.kind==="audio"&&!this.isAudioOn&&(o.enabled=!1),o.kind==="video"&&!this.isVideoOn&&(o.enabled=!1),await s.replaceTrack(o))})})}init_incoming(t,n){Z.debug("init_incoming()");let o;const a=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&a!=="application/sdp"){t.reply(415);return}if(this._status=se.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")&&(o=t.getHeader("expires")*1e3),t.to_tag=Pe.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=se.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,H.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===se.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,H.causes.EXPIRES))},o)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==se.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){Z.debug("answer()");const n=this._request,o=Pe.cloneArray(t.extraHeaders),a=Pe.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Pe.cloneObject(t.pcConfig,{iceServers:[]}),_=t.rtcConstraints||null,d=t.rtcAnswerConstraints||null,h=Pe.cloneObject(t.rtcOfferConstraints);let g,T=!1,S=!1,E=!1,A=!1;if(this._rtcAnswerConstraints=d,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new js.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==se.STATUS_WAITING_FOR_ANSWER)throw new js.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Pe.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=H.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=H.SESSION_EXPIRES),this._status=se.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),o.unshift(`Contact: ${this._contact}`);const R=n.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const C of R.media)C.type==="audio"&&(T=!0,(!C.direction||C.direction==="sendrecv")&&(E=!0)),C.type==="video"&&(S=!0,(!C.direction||C.direction==="sendrecv")&&(A=!0));if(s&&a.audio===!1){g=s.getAudioTracks();for(const C of g)s.removeTrack(C)}if(s&&a.video===!1){g=s.getVideoTracks();for(const C of g)s.removeTrack(C)}!s&&a.audio===void 0&&(a.audio=E),!s&&a.video===void 0&&(a.video=A),!s&&!T&&!h.offerToReceiveAudio&&(a.audio=!1),!s&&!S&&!h.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(r,_),Promise.resolve().then(()=>{if(s)return s;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(C=>{throw this._status===se.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,H.causes.USER_DENIED_MEDIA_ACCESS),Z.warn('emit "getusermediafailed" [error:%o]',C),this.emit("getusermediafailed",C),new Error("getUserMedia() failed"))})}).then(C=>{if(this._status===se.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=C,C&&C.getTracks().forEach($=>{this._connection.addTrack($,C)})}).then(()=>{if(this._late_sdp)return;const C={originator:"remote",type:"offer",sdp:n.body};Z.debug('emit "sdp"'),this.emit("sdp",C);const $=new RTCSessionDescription({type:"offer",sdp:C.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription($)).catch(k=>{throw n.reply(488),this._failed("system",null,H.causes.WEBRTC_ERROR),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',k),this.emit("peerconnection:setremotedescriptionfailed",k),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===se.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",d).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(C=>{if(this._status===se.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,o),n.reply(200,null,o,C,()=>{this._status=se.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,C),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,H.causes.CONNECTION_ERROR)})}).catch(C=>{this._status!==se.STATUS_TERMINATED&&Z.warn(C)})}terminate(t={}){Z.debug("terminate()");const n=t.cause||H.causes.BYE,o=Pe.cloneArray(t.extraHeaders),a=t.body;let s,r=t.status_code,_=t.reason_phrase;if(this._status===se.STATUS_TERMINATED)throw new js.InvalidStateError(this._status);switch(this._status){case se.STATUS_NULL:case se.STATUS_INVITE_SENT:case se.STATUS_1XX_RECEIVED:if(Z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(_=_||H.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),this._status===se.STATUS_NULL||this._status===se.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===se.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=se.STATUS_CANCELED,this._failed("local",null,H.causes.CANCELED);break;case se.STATUS_WAITING_FOR_ANSWER:case se.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,_,o,a),this._failed("local",null,H.causes.REJECTED);break;case se.STATUS_WAITING_FOR_ACK:case se.STATUS_CONFIRMED:if(Z.debug("terminating session"),_=t.reason_phrase||H.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&o.push(`Reason: SIP ;cause=${r}; text="${_}"`),this._status===se.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const d=this._dialog;this.receiveRequest=({method:h})=>{h===H.ACK&&(this.sendRequest(H.BYE,{extraHeaders:o,body:a}),d.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(H.BYE,{extraHeaders:o,body:a}),d.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=d,this._ua.newDialog(d)}else{const d={janus:"leave"},h=["Content-Type: application/json",this.getPTypeHeader(Ut.LEAVE)];this.sendRequest(H.BYE,{extraHeaders:h,body:JSON.stringify(d)}),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},o=["Content-Type: application/json",this.getPTypeHeader(Ut.AUDIO_CHANGE)];this.sendRequest(H.INFO,{extraHeaders:o,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async a=>{a.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},o=["Content-Type: application/json",this.getPTypeHeader(Ut.VIDEO_CHANGE)];this.sendRequest(H.INFO,{extraHeaders:o,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async a=>{a.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},o=["Content-Type: application/json",this.getPTypeHeader(Ut.STATE)];this.sendRequest(H.INFO,{extraHeaders:o,body:JSON.stringify(n)})}sendInfo(t,n,o={}){if(Z.debug("sendInfo()"),this._status!==se.STATUS_CONFIRMED&&this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_1XX_RECEIVED)throw new js.InvalidStateError(this._status);new Cu(this).send(t,n,o)}mute(t={audio:!0,video:!1}){Z.debug("mute()");let n=!1,o=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(o=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||o===!0)&&this._onmute({audio:n,video:o})}unmute(t={audio:!0,video:!0}){Z.debug("unmute()");let n=!1,o=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(o=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||o===!0)&&this._onunmute({audio:n,video:o})}hold(t={},n){if(Z.debug("hold()"),this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:H.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(Z.debug("unhold()"),this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:H.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){Z.debug("renegotiate()");const o=t.rtcOfferConstraints||null;if(this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:H.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:o,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:o,extraHeaders:t.extraHeaders}),!0}refer(t,n){Z.debug("refer()");const o=t;if(this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const a=new Ng(this);a.sendRefer(t,n);const s=a.id;return this._referSubscribers[s]=a,a.on("requestFailed",()=>{delete this._referSubscribers[s]}),a.on("accepted",()=>{delete this._referSubscribers[s]}),a.on("failed",()=>{delete this._referSubscribers[s]}),a}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===H.CANCEL)(this._status===se.STATUS_WAITING_FOR_ANSWER||this._status===se.STATUS_ANSWERED)&&(this._status=se.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,H.causes.CANCELED));else switch(t.method){case H.ACK:if(this._status!==se.STATUS_WAITING_FOR_ACK)return;if(this._status=se.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:H.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 o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(a=>{this.terminate({cause:H.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",t);break;case H.BYE:this._status===se.STATUS_CONFIRMED||this._status===se.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,H.causes.BYE)):this._status===se.STATUS_INVITE_RECEIVED||this._status===se.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,H.causes.BYE)):t.reply(403,"Wrong Status");break;case H.INVITE:this._status===se.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case H.INFO:if(this._status===se.STATUS_1XX_RECEIVED||this._status===se.STATUS_WAITING_FOR_ANSWER||this._status===se.STATUS_ANSWERED||this._status===se.STATUS_WAITING_FOR_ACK||this._status===se.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Sg(this).init_incoming(t):n!==void 0?new Cu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case H.UPDATE:this._status===se.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case H.REFER:this._status===se.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case H.NOTIFY:this._status===se.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){Z.warn("onTransportError()"),this._status!==se.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:H.causes.CONNECTION_ERROR,cause:H.causes.CONNECTION_ERROR})}onRequestTimeout(){Z.warn("onRequestTimeout()"),this._status!==se.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:H.causes.REQUEST_TIMEOUT,cause:H.causes.REQUEST_TIMEOUT})}onDialogError(){Z.warn("onDialogError()"),this._status!==se.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:H.causes.DIALOG_ERROR,cause:H.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"),Pe.closeMediaStream(this._localMediaStream)),this._status!==se.STATUS_TERMINATED){if(this._status=se.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 o=Li.T1;function a(){this._status===se.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),o<Li.T2&&(o=o*2,o>Li.T2&&(o=Li.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),o))}this._timers.invite2xxTimer=setTimeout(a.bind(this),o)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===se.STATUS_WAITING_FOR_ACK&&(Z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(H.BYE),this._ended("remote",null,H.causes.NO_ACK))},Li.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:H.causes.RTP_TIMEOUT,status_code:408,reason_phrase:H.causes.RTP_TIMEOUT})});let o;const a=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(o),o=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=a,Z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(Z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const o=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?o.createOffer(n).catch(a=>(Z.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):o.createAnswer(n).catch(a=>(Z.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>(this.jsepOffer=a,o.setLocalDescription(a).catch(s=>(this._rtcReady=!0,Z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const a=n&&n.iceRestart;if(o.iceGatheringState==="complete"&&!a||o.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:o.localDescription.sdp};return Z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,_,d;this._iceReady=!1;const h=()=>{o.removeEventListener("icecandidate",_),o.removeEventListener("icegatheringstatechange",d),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:o.localDescription.sdp};Z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};o.addEventListener("icecandidate",_=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:h}):r||h()}),o.addEventListener("icegatheringstatechange",d=()=>{o.iceGatheringState==="complete"&&!r&&h()})})})}_createDialog(t,n,o){const a=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+a+s;let _=this._earlyDialogs[r];if(o)return _?!0:(_=new ao(this,t,n,ao.C.STATUS_EARLY),_.error?(Z.debug(_.error),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const d=new ao(this,t,n);return d.error?(Z.debug(d.error),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._dialog=d,!0)}}_receiveReinvite(t){Z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,o={request:t,callback:void 0,reject:s.bind(this)};let a=!1;function s(_={}){a=!0;const d=_.status_code||403,h=_.reason_phrase||"",g=Pe.cloneArray(_.extraHeaders);if(this._status!==se.STATUS_CONFIRMED)return!1;if(d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);t.reply(d,h,g)}if(this.emit("reinvite",o),a)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(_=>{r.call(this,_)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){Z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(_=>{this._status!==se.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{Z.warn(_)});function r(_){const d=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,d),this._late_sdp&&(_=this._mangleOffer(_)),t.reply(200,null,d,_,()=>{this._status=se.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,_),this._setACKTimer()}),typeof o.callback=="function"&&o.callback()}}_receiveUpdate(t){Z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,o={request:t,callback:void 0,reject:s.bind(this)};let a=!1;function s(_={}){a=!0;const d=_.status_code||403,h=_.reason_phrase||"",g=Pe.cloneArray(_.extraHeaders);if(this._status!==se.STATUS_CONFIRMED)return!1;if(d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);t.reply(d,h,g)}if(this.emit("update",o),a)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(_=>{this._status!==se.STATUS_TERMINATED&&r.call(this,_)}).catch(_=>{Z.warn(_)});function r(_){const d=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,d),t.reply(200,null,d,_),typeof o.callback=="function"&&o.callback()}}_processInDialogSdpOffer(t){Z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let o=!1;for(const r of n.media){if(uo.indexOf(r.type)===-1)continue;const _=r.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="inactive")o=!0;else{o=!1;break}}const a={originator:"remote",type:"offer",sdp:t.body};Z.debug('emit "sdp"'),this.emit("sdp",a);const s=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===se.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===se.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&o===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&o===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===se.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!==H.SIP){Z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new Ig(this,t.cseq);Z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{o.call(this,s,r)},reject:()=>{a.call(this)}});function o(s,r={}){if(s=typeof s=="function"?s:null,this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED)return!1;const _=new Fo(this._ua);if(_.on("progress",({response:d})=>{n.notify(d.status_code,d.reason_phrase)}),_.on("accepted",({response:d})=>{n.notify(d.status_code,d.reason_phrase)}),_.on("_failed",({message:d,cause:h})=>{d?n.notify(d.status_code,d.reason_phrase):n.notify(487,h)}),t.refer_to.uri.hasHeader("replaces")){const d=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Pe.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${d}`)}_.connect(t.refer_to.uri.toAor(),r,s)}function a(){n.notify(603)}}_receiveNotify(t){switch(Z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,o;if(t.event.params&&t.event.params.id)n=t.event.params.id,o=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)o=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!o){t.reply(481,"Subscription does not exist");return}o.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){Z.debug("receiveReplaces()");function n(a){if(this._status!==se.STATUS_WAITING_FOR_ACK&&this._status!==se.STATUS_CONFIRMED)return!1;const s=new Fo(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,a)}function o(){Z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:a=>{n.call(this,a)},reject:()=>{o.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,o){this.ackSent=!1,this.publisherSubscribeSent=!1;const a=new tl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(o)return o;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===se.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,H.causes.USER_DENIED_MEDIA_ACCESS),Z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===se.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,H.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===se.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},_=JSON.stringify(r);this._request.body=_,this._status=se.STATUS_INVITE_SENT,Z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(s=>{this._status!==se.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 PT+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})),a={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(Ut.ICE)];this.sendRequest(H.INFO,{extraHeaders:s,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const d=r.data.split(`\r
|
|
135
|
+
`),h=d[d.length-1],g=JSON.parse(h);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const o={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},a=["Content-Type: application/json",this.getPTypeHeader(Ut.CONFIGURE)];this.sendRequest(H.INFO,{extraHeaders:a,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const o={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},a=[this.getPTypeHeader(Ut.TRICKLE)];this.sendRequest(H.INFO,{extraHeaders:a,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let o=null;const a=async d=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const E={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),o=await t.rtcpPeer.createAnswer(E),this._sendMemberStartMessage(t,o)}const h=d.streams[0].getAudioTracks(),g=d.streams[0].getVideoTracks(),T=[];h[0]&&T.push(h[0]),g[0]&&T.push(g[0]);const S=new MediaStream(T);t.stream=S,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const _=d=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(d.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=a,t.rtcpPeer.onicecandidate=_,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},o=[this.getPTypeHeader(Ut.SUBSCRIBER)];this.sendRequest(H.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async a=>{var s,r;if(a.status_code===200){const _=JSON.parse(a.body);(r=(s=_==null?void 0:_.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,_)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},o=[this.getPTypeHeader(Ut.SUBSCRIBER)];this.sendRequest(H.INFO,{extraHeaders:o,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async a=>{if(a.status_code===200){const r=JSON.parse(a.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},o=[this.getPTypeHeader(Ut.SUBSCRIBER)];this.sendRequest(H.INFO,{extraHeaders:o,body:JSON.stringify(n)}),Qt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var o,a,s,r,_,d,h,g;const n={...this.memberList};(a=(o=t==null?void 0:t.plugindata)==null?void 0:o.data)==null||a.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 UT(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=(d=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:d.publishers,this.private_id=(g=(h=t==null?void 0:t.plugindata)==null?void 0:h.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 o of t)n=await o.process(n);this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),n.getTracks().forEach(o=>{this.stream.addTrack(o)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(o=>o.type===t);for(const o of n)o.running&&o.terminate();if(t==="video"){let o=await this.loadStream();for(const a of n)a.running&&(o=await a.start(o));this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),o.getTracks().forEach(a=>{this.stream.addTrack(a)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const o=this._ua.newStreamPlugins.find(_=>_.type===t);let s=o.getStream().clone();for(const _ of n)_.running&&(s=await _.start(s));const r=o.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(o=>o.type===t);for(const o of n)o.running&&o.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(H.ACK);return}else{const n=new ao(this,t,"UAC");if(n.error!==void 0){Z.debug(n.error);return}this.sendRequest(H.ACK),this.sendRequest(H.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=Nf();const o={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},a=[this.getPTypeHeader(Ut.PUBLISHER)];this.sendRequest(H.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(o),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)||{};((_=(r=g.plugindata)==null?void 0:r.data)==null?void 0:_.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(h=(d=g.plugindata)==null?void 0:d.data)!=null&&h.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!==se.STATUS_INVITE_SENT&&this._status!==se.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=se.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=se.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 o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",t)).catch(a=>{Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=se.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,H.causes.MISSING_SDP),this._failed("remote",t,H.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=Pe.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){Z.debug("sendReinvite()");const n=Pe.cloneArray(t.extraHeaders),o=Pe.cloneObject(t.eventHandlers),a=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",a)).then(d=>{d=this._mangleOffer(d);const h={originator:"local",type:"offer",sdp:d};Z.debug('emit "sdp"'),this.emit("sdp",h),this.sendRequest(H.INVITE,{extraHeaders:n,body:d,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{_.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function r(d){if(this._status===se.STATUS_TERMINATED||(this.sendRequest(H.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(d),d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const h={originator:"remote",type:"answer",sdp:d.body};Z.debug('emit "sdp"'),this.emit("sdp",h);const g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{o.succeeded&&o.succeeded(d)}).catch(T=>{_.call(this),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(d){o.failed&&o.failed(d)}}_sendUpdate(t={}){Z.debug("sendUpdate()");const n=Pe.cloneArray(t.extraHeaders),o=Pe.cloneObject(t.eventHandlers),a=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",a)).then(h=>{h=this._mangleOffer(h);const g={originator:"local",type:"offer",sdp:h};Z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(H.UPDATE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),r=!0},onErrorResponse:T=>{d.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d.call(this)})):this.sendRequest(H.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:h=>{_.call(this,h)},onErrorResponse:h=>{d.call(this,h)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(h){if(this._status!==se.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(h),s){if(h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const g={originator:"remote",type:"answer",sdp:h.body};Z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{o.succeeded&&o.succeeded(h)}).catch(S=>{d.call(this),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}else o.succeeded&&o.succeeded(h)}function d(h){o.failed&&o.failed(h)}}_acceptAndTerminate(t,n,o){Z.debug("acceptAndTerminate()");const a=[];n&&(o=o||H.REASON_PHRASE[n]||"",a.push(`Reason: SIP ;cause=${n}; text="${o}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(H.ACK),this.sendRequest(H.BYE,{extraHeaders:a})),this._status=se.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=kt.parse(t),this._localHold&&!this._remoteHold){Z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)uo.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)uo.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)uo.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return kt.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 o;t.session_expires&&t.session_expires>=H.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,o=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,o="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${o}`),this._sessionTimers.refresher=o==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=H.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!==se.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===H.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==se.STATUS_TERMINATED&&(Z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:H.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="audio");for(const o of n)o.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="video");for(const o of n)o.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,o){Z.debug("session ended"),this._end_time=new Date,this._close(),Z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:o})}_failed(t,n,o){Z.debug("session failed"),Z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:o}),this._close(),Z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:o})}_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 ur{constructor(t){if(this.headers={},t.length>0){let n=!1;const o=t.split(`\r
|
|
136
|
+
`),a=o.shift().split(/\s/);this.protocol=a[0],this.ident=a[1],this.code=a.length>3?parseInt(a[2]):0,this.method=a.length>3?a[3]:a[2],this.body="";for(const s of o){if(s==`-------${this.ident}$`)break;if(s===""){n=!0;continue}if(s&&n)this.body+=`${s}\r
|
|
137
|
+
`;else{const r=s.split(": ");this.addHeader(r[0],r[1].trim())}}}else this.ident=Pe.createRandomToken(12),this.protocol="MSRP"}addHeader(t,n){this.headers[t]=n}getHeader(t){return this.headers[t]}toString(){let t=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
|
|
138
138
|
`;for(const n in this.headers)t+=`${n}: ${this.headers[n]}\r
|
|
139
139
|
`;return this.body&&(t+=`\r
|
|
140
140
|
${this.body}\r
|
|
141
141
|
`),t+=`-------${this.ident}$\r
|
|
142
|
-
`,t}}const Re={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class
|
|
142
|
+
`,t}}const Re={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class ru extends ft.EventEmitter{constructor(t){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=t,this.auth_id=Pe.createRandomToken(10),this._status=Re.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username:t._configuration.authorization_user,ha1:t._configuration.ha1,realm:t._configuration.realm},this._request=null,this.status="new",this.target="",this.message="",this._connectionPromiseQueue=Promise.resolve(),this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:H.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Re}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(t=""){t!==""&&(this._direction="outgoing"),this.target=t;const n=this._ua.options.msrpWs?"ws":"wss";this._connection=new WebSocket(`${n}://${this._ua.options.msrpDomain||this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=o=>{console.log("open",o),this.onopen()},this._connection.onclose=o=>{console.log("close",o),this.onclose()},this._connection.onmessage=o=>{console.log("msg",o),this.onmessage(o)},this._connection.onerror=o=>{console.log("error",o),this.onerror()}}_sendKeepAlive(){const t=new ur("");t.method="SEND";let n="";this.my_addr[1]&&(n=this.my_addr[1]),this.target_addr[1]&&(n+=" "+this.target_addr[1]),this.target_addr[0]&&(n+=" "+this.target_addr[0]),t.addHeader("To-Path",n),t.addHeader("From-Path",`${this.my_addr[0]}`),t.addHeader("Message-ID",Pe.createRandomToken(10)),t.addHeader("Byte-Range","0-0/0"),t.addHeader("Content-Type","text/plain"),t.body="",this._connection.send(t.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Re.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(t){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
|
|
143
143
|
o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
|
|
144
144
|
c=IN IP4 ${this.my_ip}
|
|
145
145
|
t=0 0
|
|
146
146
|
m=message 2856 TCP/TLS/MSRP *
|
|
147
147
|
a=accept-types:text/plain text/html
|
|
148
148
|
a=path: ${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
|
|
149
|
-
`)}inviteParty(t){const n={},
|
|
149
|
+
`)}inviteParty(t){const n={},o=[];n.to_uri=new Rn("sip",this.target,this._ua._configuration.realm),n.from_uri=new Rn("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),o.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),o.push("Content-Type: application/sdp"),this._request=new yt.InitialOutgoingInviteRequest(new Rn("sip",this.target,this._ua._configuration.realm).clone(),this._ua,n,o,`v=0
|
|
150
150
|
o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
|
|
151
151
|
c=IN IP4 ${this.my_ip}
|
|
152
152
|
t=0 0
|
|
153
153
|
m=message 2856 TCP/TLS/MSRP *
|
|
154
154
|
a=accept-types:text/plain text/html
|
|
155
155
|
a=path:${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
|
|
156
|
-
`),this._newMSRPSession("local",this._request),this._from_tag||(this._from_tag=this._request.from._parameters.tag),this._id=this._request.call_id+this._from_tag,new tl(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||H.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,_=t.reason_phrase;if(this._status===Re.STATUS_TERMINATED)throw new js.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&&(_=_||H.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),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,H.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,_,a,o),this._failed("local",null,H.causes.REJECTED);break;case Re.STATUS_WAITING_FOR_ACK:case Re.STATUS_CONFIRMED:if(_=t.reason_phrase||H.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${_}"`),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:d})=>{d===H.ACK&&(this.sendRequest(H.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(H.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(H.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 ur("");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 ur(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Wm(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(H.ACK);return}else{const n=new Zl(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(H.ACK),this.sendRequest(H.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,H.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,H.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,H.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(H.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 ur("");let a="";this.my_addr[1]&&(a=this.my_addr[1]),this.target_addr[1]&&(a+=" "+this.target_addr[1]),this.target_addr[0]&&(a+=" "+this.target_addr[0]),n.method="SEND",n.addHeader("To-Path",a),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 o=n.toString();console.log(o);let s=[];for(var r=0;r<o.length;r++)s.push(o.charCodeAt(r).toString(16));console.log(s),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 ur("");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 _=0;_<s.length;_++)r.push(s.charCodeAt(_).toString(16));console.log(r),this._connection.send(o.toString())}_sendReport(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new ur("");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 _=0;_<s.length;_++)r.push(s.charCodeAt(_).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,H.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,H.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 _=this._earlyDialogs[r];if(a)return _?!0:(_=new Zl(this,t,n,Zl.C.STATUS_EARLY),_.error?(console.log("failed 8"),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const h=new Zl(this,t,n);return h.error?(console.log("failed 9"),this._failed("remote",t,H.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})}_runKeepAliveTimer(){if(!this._sessionTimers||!this._sessionTimers.enabled||this._sessionTimers.running)return;if(this._sessionTimers.currentExpires||(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires||30),!this._sessionTimers.refresher){console.log("Not the refresher; waiting for remote keep-alive");return}const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.timer=setTimeout(()=>{if(this._connection.readyState===WebSocket.OPEN)try{this._sendKeepAlive(),console.log("Session timer: sending MSRP keep-alive")}catch(n){console.error("Failed to send keep-alive:",n)}this._sessionTimers.running=!1,this._runKeepAliveTimer()},t*1e3*.5)}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=H.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._runKeepAliveTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===H.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,H.causes.CANCELED));else switch(t.method){case H.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:H.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:H.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 H.BYE:this._status===Re.STATUS_CONFIRMED||this._status===Re.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,H.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,H.causes.BYE)):t.reply(403,"Wrong Status");break;case H.INVITE:this._status===Re.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case H.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 H.UPDATE:this._status===Re.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case H.REFER:this._status===Re.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case H.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:H.causes.CONNECTION_ERROR,cause:H.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:H.causes.REQUEST_TIMEOUT,cause:H.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:H.causes.DIALOG_ERROR,cause:H.causes.DIALOG_ERROR})}}var kT=Zt();const Iu=ze(kT),ca=new Ga("Parser"),MT=(c,t)=>{let n,a,o=c.indexOf(`\r
|
|
157
|
-
`);if(
|
|
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 $T(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),_=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",_),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",_),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",_),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Iu.parse(_,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",_.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",_),o=c.parseHeader("call-id"),o&&(c.call_id=_);break;case"contact":case"m":if(o=Iu.parse(_,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",_.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",_),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",_),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",_),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof _r.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",_),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",_),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",_),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",_),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",_),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",_),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",_),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,_),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const HT={parseMessage:MT},Gi=new Ga("Registrator"),fa=10;class FT{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){Gi.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(H.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new tl(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,H.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,H.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")){Gi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((d,g)=>d.concat(g.parsed),[]);let r=s.find(d=>this._sipInstance===d.getParam("+sip.instance")&&this._reg_id===parseInt(d.getParam("reg-id")));if(r||(r=s.find(d=>d.uri.user===this._ua.contact.uri.user)),!r){Gi.debug("no Contact header pointing to us, response ignored");break}this._ua.clearKeepAliveInterval(),this._ua.setLastRegisterTimestamp();let _=r.getParam("expires");!_&&o.hasHeader("expires")&&(_=o.getHeader("expires")),_||(_=this._expires),_=Number(_),_<fa&&(_=fa);const h=_>64?_*1e3/2+Math.floor((_/2-32)*1e3*Math.random()):Math.floor(_*1e3/2);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<fa&&(this._expires=fa),this.register()):(Gi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,H.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){Gi.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(H.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new tl(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,H.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,H.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,qs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},VT=bT;class jT extends VT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this.optionsInterval=null,this.lastOptionsTimestamp=null,this.lastRegisterTimestamp=null,this._registrator=new FT(this)}setLastRegisterTimestamp(){this.lastRegisterTimestamp=Date.now()}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){tt.debug("call()");const o=new $a(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{nl.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 Zg(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=qT.bind(this),this._transport.onconnect=BT.bind(this),this._transport.ondisconnect=GT.bind(this),this._transport.ondata=WT.bind(this)}catch(s){throw tt.warn(s),new js.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 Rn("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,_=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),_&&(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(nl.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]}clearKeepAliveInterval(){clearInterval(this.optionsInterval),this.optionsInterval=null}receiveRequest(t){var s,r,_,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.lastOptionsTimestamp=Date.now(),this.optionsInterval||(this.emit("initKeepAliveInterval"),this.optionsInterval=setInterval(()=>{const g=Date.now(),T=this.lastOptionsTimestamp>g-35e3,S=this.lastRegisterTimestamp+this._configuration.register_expires*1e3>g;T&&S&&this.emit("keepAliveInterval")},35e3)),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 d=JSON.parse(t.body)||{};(r=(s=d.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(d),(h=(_=d.plugindata)==null?void 0:_.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(d.plugindata.data.unpublished)}catch(d){console.error(d)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const d=t.replaces;a=this._findDialog(d.call_id,d.from_tag,d.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 nu(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new Lg(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 nu(this);return a.connect(t),a}startJanus(t,n){tt.debug("startJanus()",n);const a=new nu(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===qs.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=qs.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 qT(c){this.emit("connecting",c)}function BT(c){this._status!==qs.STATUS_USER_CLOSED&&(this._status=qs.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function GT(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!==qs.STATUS_USER_CLOSED&&(this._status=qs.STATUS_NOT_READY,this._error=qs.NETWORK_ERROR)}function WT(c){const t=c.transport;let n=c.message;const a=n;if(n=HT.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,a),!!n&&!(this._status===qs.STATUS_USER_CLOSED&&n instanceof _r.IncomingRequest)&&_T(n,this,t)){if(n instanceof _r.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof _r.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 KT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],YT=["_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 KT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Uf(c){const t={};return YT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}async function ru(c,t,n){const a=c.createMediaStreamSource(t),o=c.createMediaStreamDestination(),s=c.createGain();return a.connect(s),s.connect(o),s.gain.value=n,o.stream}function JT(c,t,n,a){if(bh())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 zT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function bh(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const XT=ut,QT=Zt(),Dt=new XT("WebSocketInterface");var ZT=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=QT.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=Ha,ev=De,tv=As,sv=At(),nv=Ih,rv=ys(),iv=$u(),lv=Zt(),av=ZT,ov=mr("JsSIP");ov("version %s",bu.version);var uv={C:ev,Exceptions:tv,Utils:sv,UA:nv,URI:rv,NameAddrHeader:iv,WebSocketInterface:av,Grammar:lv,debug:mr,get name(){return bu.title},get version(){return bu.version}};const cv=ze(uv);function iu(c){return c<10?`0${c}`:`${c}`}function fv(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}}function hv(c){let t=0;for(let n=0;n<c.length;n++)t+=c[n]*c[n];return Math.sqrt(t/c.length)}async function dv(c,t,n=150){const a=t.createMediaStreamSource(c),o=t.createDelay();o.delayTime.value=n/1e3;const s=t.createGain();s.gain.value=0;const r=t.createMediaStreamDestination();return a.connect(o).connect(s).connect(r),{stream:r.stream,setSpeaking:_=>{s.gain.value=_?1:0}}}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 _=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(_).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 _=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(_).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 _=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(_).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 _=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(_).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 _=0;_<c.length;_++)_ in c&&(s[_]=Promise.resolve(c[_]).then(h=>t.call(n||globalThis,h,_,c)).catch(o));const r=[];for(let _=0;_<s.length;_++)await s[_]&&r.push(await c[_]);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 wh={};(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)}})})(wh);const _v=Ct,pv=wh;var mv=Object.assign(_v,{instanceMethods:pv});const Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"},gv={TRYING:100,RINGING:180,SESSION_PROGRESS:183,OK:200,MOVED_TEMPORARILY:302,BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,REQUEST_TIMEOUT:408,BUSY_HERE:486,REQUEST_TERMINATED:487,INTERNAL_SERVER_ERROR:500,SERVICE_UNAVAILABLE:503,BUSY_EVERYWHERE:600,DECLINE:603};var Tv={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,_=typeof Symbol=="function"?Symbol:{},h=_.iterator||"@@iterator",d=_.asyncIterator||"@@asyncIterator",g=_.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 S(ee,W,G,re){var ge=W&&W.prototype instanceof ie?W:ie,be=Object.create(ge.prototype),Pe=new x(re||[]);return s(be,"_invoke",{value:J(ee,G,Pe)}),be}n.wrap=S;function E(ee,W,G){try{return{type:"normal",arg:ee.call(W,G)}}catch(re){return{type:"throw",arg:re}}}var A="suspendedStart",C="suspendedYield",R="executing",k="completed",M={};function ie(){}function N(){}function V(){}var Ee={};T(Ee,h,function(){return this});var ve=Object.getPrototypeOf,L=ve&&ve(ve(se([])));L&&L!==a&&o.call(L,h)&&(Ee=L);var D=V.prototype=ie.prototype=Object.create(Ee);N.prototype=V,s(D,"constructor",{value:V,configurable:!0}),s(V,"constructor",{value:N,configurable:!0}),N.displayName=T(V,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,V):(ee.__proto__=V,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function q(ee,W){function G(be,Pe,Ce,ae){var ye=E(ee[be],ee,Pe);if(ye.type==="throw")ae(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(Se){G("next",Se,Ce,ae)},function(Se){G("throw",Se,Ce,ae)}):W.resolve(at).then(function(Se){nt.value=Se,Ce(nt)},function(Se){return G("throw",Se,Ce,ae)})}}var re;function ge(be,Pe){function Ce(){return new W(function(ae,ye){G(be,Pe,ae,ye)})}return re=re?re.then(Ce,Ce):Ce()}s(this,"_invoke",{value:ge})}B(q.prototype),T(q.prototype,d,function(){return this}),n.AsyncIterator=q,n.async=function(ee,W,G,re,ge){ge===void 0&&(ge=Promise);var be=new q(S(ee,W,G,re),ge);return n.isGeneratorFunction(W)?be:be.next().then(function(Pe){return Pe.done?Pe.value:be.next()})};function J(ee,W,G){var re=A;return function(be,Pe){if(re===R)throw new Error("Generator is already running");if(re===k){if(be==="throw")throw Pe;return st()}for(G.method=be,G.arg=Pe;;){var Ce=G.delegate;if(Ce){var ae=F(Ce,G);if(ae){if(ae===M)continue;return ae}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===A)throw re=k,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=R;var ye=E(ee,W,G);if(ye.type==="normal"){if(re=G.done?k:C,ye.arg===M)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=k,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")),M;var ge=E(re,ee.iterator,W.arg);if(ge.type==="throw")return W.method="throw",W.arg=ge.arg,W.delegate=null,M;var be=ge.arg;if(!be)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,M;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,M}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 x(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 x.prototype={constructor:x,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(ae,ye){return be.type="throw",be.arg=ee,W.next=ae,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 Pe=o.call(ge,"catchLoc"),Ce=o.call(ge,"finallyLoc");if(Pe&&Ce){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(Pe){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,M):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),M},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),M}},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),M}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(Tv);var Oh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(Fh,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,R){var k=C[R];if(typeof k.bind=="function")return k.bind(C);try{return Function.prototype.bind.call(k,C)}catch{return function(){return Function.prototype.apply.apply(k,[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 _(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,R){for(var k=0;k<o.length;k++){var M=o[k];this[M]=k<C?t:this.methodFactory(M,C,R)}this.log=this.debug}function d(C,R,k){return function(){typeof console!==n&&(h.call(this,R,k),this[C].apply(this,arguments))}}function g(C,R,k){return _(C)||d.apply(this,arguments)}function T(C,R,k){var M=this,ie;R=R??"WARN";var N="loglevel";typeof C=="string"?N+=":"+C:typeof C=="symbol"&&(N=void 0);function V(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 Ee(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,q=B.indexOf(encodeURIComponent(N)+"=");q!==-1&&(D=/^([^;]+)/.exec(B.slice(q))[1])}catch{}return M.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{}}}M.name=C,M.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},M.methodFactory=k||g,M.getLevel=function(){return ie},M.setLevel=function(D,B){if(typeof D=="string"&&M.levels[D.toUpperCase()]!==void 0&&(D=M.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=M.levels.SILENT){if(ie=D,B!==!1&&V(D),h.call(M,D,C),typeof console===n&&D<M.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},M.setDefaultLevel=function(D){R=D,Ee()||M.setLevel(D,!1)},M.resetLevel=function(){M.setLevel(R,!1),ve()},M.enableAll=function(D){M.setLevel(M.levels.TRACE,D)},M.disableAll=function(D){M.setLevel(M.levels.SILENT,D)};var L=Ee();L==null&&(L=R),M.setLevel(L,!1)}var S=new T,E={};S.getLogger=function(R){if(typeof R!="symbol"&&typeof R!="string"||R==="")throw new TypeError("You must supply a name when creating a logger.");var k=E[R];return k||(k=E[R]=new T(R,S.getLevel(),S.methodFactory)),k};var A=typeof window!==n?window.log:void 0;return S.noConflict=function(){return typeof window!==n&&window.log===S&&(window.log=A),S},S.getLoggers=function(){return E},S.default=S,S})})(Oh);var It=Oh.exports;const vs=()=>`${new Date().toISOString()} | metrics`,Ss=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const vv=c=>{It.info(Ss(vs(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},Sv=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Ss(vs(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Ss(vs(),"log ","Incorrect log level please choose one of "),t)},xe=(c,t,n)=>{n?It.debug(Ss(vs(),c,t),n):It.debug(Ss(vs(),c,t))},lu=(c,t)=>{It.info(Ss(vs(),c,t))},Cn=(c,t)=>{It.info(Ss(vs(),c,t))},wa=(c,t)=>{It.warn(Ss(vs(),c,t))},hr=(c,t)=>{It.error(Ss(vs(),c,t))};function Ev(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 yv(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[Ev(c.length)];return n}function Av({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",_=[],h=[],d=[];return t&&(o.length&&(s=xf(o,s)),h=s.split("")),n&&(o.length&&(r=xf(o,r)),d=r.split("")),_=[...h,...d,...a],yv(_,c)}var Cv=Av;const Xi=ze(Cv),Rv=()=>"WebRTCMetrics",Iv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},gs={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Wi={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},bv=()=>({...{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:[]}}),Dh={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},Nh={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},Uh={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},wv=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}}},Ov={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Xi()}`,cid:`c-${Xi()}`,uid:`u-${Xi()}`,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"},j={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"},P={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Ki={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 ",Dv=(c,t={},n)=>{const a={...n,...t};return t.pname||wa(ou,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||wa(ou,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||wa(ou,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},Nv=(c={})=>{const t={...Ov,...c};return t.name=Rv(),t.version=Iv(),t},pl=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const _=r[t][o];return _?_[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,Uv=()=>`probe-${Xi()}`,xv=()=>`coltr-${Xi()}`,Pf=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=pl(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((d,g)=>d+g,0)/o.length;return s===0?null:o.map(d=>Math.abs(s-d)).reduce((d,g)=>d+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=pl(c,t,n,a,o);return s.length===0?null:s.reduce((r,_)=>r+_,0)/s.length},En=(c,t,n)=>pl(c,t,n).reduce((o,s)=>o+s,0),Ye=(c,t,n,a)=>{const o=pl(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Je=(c,t,n,a)=>{const o=pl(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},Pv=c=>c.slice().pop(),ct=(c,t,n)=>{if(!t)return null;const a={};let o=t[P.AUDIO][c];o||(o=n===$e.INBOUND?{...Dh}:{...Nh}),a[P.AUDIO]=o;let s=t[P.VIDEO][c];return s||(s=n===$e.INBOUND?{...Uh}:{...xh}),a[P.VIDEO]=s,a},Yi="exporter ",kv="2.0",kf=(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},Mv=(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)},Lv=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,$v=c=>{const t=gt(c,"network","remote_candidate_type"),n=gt(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class Hv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){lu(Yi,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){lu(Yi,"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&&(xe(Yi,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){lu(Yi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){xe(Yi,"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=Pv(this._reports);return r&&(Object.keys(r[P.AUDIO]).forEach(_=>{const h=r[P.AUDIO][_];if(s[h.ssrc]={type:P.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const d={avg:Xe(this._reports,P.AUDIO,"delta_jitter_ms_in",!1,_),min:Ye(this._reports,P.AUDIO,"delta_jitter_ms_in",_),max:Je(this._reports,P.AUDIO,"delta_jitter_ms_in",_),volatility:Ke(this._reports,P.AUDIO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,P.AUDIO,"delta_kbs_in",!1,_),min:Ye(this._reports,P.AUDIO,"delta_kbs_in",_),max:Je(this._reports,P.AUDIO,"delta_kbs_in",_),volatility:Ke(this._reports,P.AUDIO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,P.AUDIO,"delta_KBytes_in",!1,_),min:Ye(this._reports,P.AUDIO,"delta_KBytes_in",_),max:Je(this._reports,P.AUDIO,"delta_KBytes_in",_),volatility:Ke(this._reports,P.AUDIO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S={emodel:{avg:Xe(this._reports,P.AUDIO,"mos_emodel_in",!1,_),min:Ye(this._reports,P.AUDIO,"mos_emodel_in",_),max:Je(this._reports,P.AUDIO,"mos_emodel_in",_),volatility:Ke(this._reports,P.AUDIO,"mos_emodel_in",_)},effective:{avg:Xe(this._reports,P.AUDIO,"mos_in",!1,_),min:Ye(this._reports,P.AUDIO,"mos_in",_),max:Je(this._reports,P.AUDIO,"mos_in",_),volatility:Ke(this._reports,P.AUDIO,"mos_in",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},E=gt(this._reports,P.AUDIO,"total_packets_lost_in",_),A=gt(this._reports,P.AUDIO,"total_packets_in",_),C={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=d,s[_].mos=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=C}else{const d={avg:Xe(this._reports,P.AUDIO,"delta_jitter_ms_out",!1,_),min:Ye(this._reports,P.AUDIO,"delta_jitter_ms_out",_),max:Je(this._reports,P.AUDIO,"delta_jitter_ms_out",_),volatility:Ke(this._reports,P.AUDIO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,P.AUDIO,"delta_kbs_out",!1,_),min:Ye(this._reports,P.AUDIO,"delta_kbs_out",_),max:Je(this._reports,P.AUDIO,"delta_kbs_out",_),volatility:Ke(this._reports,P.AUDIO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,P.AUDIO,"delta_KBytes_out",!1,_),min:Ye(this._reports,P.AUDIO,"delta_KBytes_out",_),max:Je(this._reports,P.AUDIO,"delta_KBytes_out",_),volatility:Ke(this._reports,P.AUDIO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},S={avg:kf(this._reports,P.AUDIO,_),min:Ye(this._reports,P.AUDIO,"delta_rtt_ms_out",_),max:Je(this._reports,P.AUDIO,"delta_rtt_ms_out",_),volatility:Ke(this._reports,P.AUDIO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},E=gt(this._reports,P.AUDIO,"total_packets_lost_out",_),A=gt(this._reports,P.AUDIO,"total_packets_out",_),C={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},R={emodel:{avg:Xe(this._reports,P.AUDIO,"mos_emodel_out",!1,_),min:Ye(this._reports,P.AUDIO,"mos_emodel_out",_),max:Je(this._reports,P.AUDIO,"mos_emodel_out",_),volatility:Ke(this._reports,P.AUDIO,"mos_emodel_out",_)},effective:{avg:Xe(this._reports,P.AUDIO,"mos_out",!1,_),min:Ye(this._reports,P.AUDIO,"mos_out",_),max:Je(this._reports,P.AUDIO,"mos_out",_),volatility:Ke(this._reports,P.AUDIO,"mos_out",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[_].jitter=d,s[_].rtt=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=C,s[_].mos=R}}),Object.keys(r[P.VIDEO]).forEach(_=>{const h=r[P.VIDEO][_];if(s[_]={type:P.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const d={avg:Xe(this._reports,P.VIDEO,"delta_jitter_ms_in",!1,_),min:Ye(this._reports,P.VIDEO,"delta_jitter_ms_in",_),max:Je(this._reports,P.VIDEO,"delta_jitter_ms_in",_),volatility:Ke(this._reports,P.VIDEO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,P.VIDEO,"delta_kbs_in",!1,_),min:Ye(this._reports,P.VIDEO,"delta_kbs_in",_),max:Je(this._reports,P.VIDEO,"delta_kbs_in",_),volatility:Ke(this._reports,P.VIDEO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,P.VIDEO,"delta_KBytes_in",!1,_),min:Ye(this._reports,P.VIDEO,"delta_KBytes_in",_),max:Je(this._reports,P.VIDEO,"delta_KBytes_in",_),volatility:Ke(this._reports,P.VIDEO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S=gt(this._reports,P.VIDEO,"total_packets_lost_in",_),E=gt(this._reports,P.VIDEO,"total_packets_in",_),A={lost:S,avg:Math.round((S/(S+E)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=d,s[_].traffic=T,s[_].bitrate=g,s[_].loss=A}else{const d={avg:Xe(this._reports,P.VIDEO,"delta_jitter_ms_out",!1,_),min:Ye(this._reports,P.VIDEO,"delta_jitter_ms_out",_),max:Je(this._reports,P.VIDEO,"delta_jitter_ms_out",_),volatility:Ke(this._reports,P.VIDEO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,P.VIDEO,"delta_kbs_out",!1,_),min:Ye(this._reports,P.VIDEO,"delta_kbs_out",_),max:Je(this._reports,P.VIDEO,"delta_kbs_out",_),volatility:Ke(this._reports,P.VIDEO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,P.VIDEO,"delta_KBytes_out",!1,_),min:Ye(this._reports,P.VIDEO,"delta_KBytes_out",_),max:Je(this._reports,P.VIDEO,"delta_KBytes_out",_),volatility:Ke(this._reports,P.VIDEO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S={avg:kf(this._reports,P.VIDEO,_),min:Ye(this._reports,P.VIDEO,"delta_rtt_ms_out",_),max:Je(this._reports,P.VIDEO,"delta_rtt_ms_out",_),volatility:Ke(this._reports,P.VIDEO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},E=gt(this._reports,P.VIDEO,"total_packets_lost_out",_),A=gt(this._reports,P.VIDEO,"total_packets_out",_),C={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=d,s[_].rtt=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=C}})),{version:kv,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:Mv(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:Lv(this._reports),remoteConnection:$v(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 Vs="extractor ",Mf=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,_=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,d={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[j.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,j.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,j.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[j.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[j.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return d;const g=1e3*Number(c[j.ROUND_TRIP_TIME]);let T=s+g,S=r+1;return o&&(T=1e3*Number(c[j.TOTAL_ROUND_TRIP_TIME])-_,S=Number(c[j.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:S}},Fv=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,j.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[j.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,j.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[j.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,j.RESPONSES_RECEIVED)&&(r=Number(c[j.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},ha=(c,t,n)=>c[j.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,j.JITTER)?null:1e3*(Number(c[j.JITTER])||0),Vv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,j.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,j.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[P.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[P.VIDEO].total_frames_decoded_in,total_decode_time:t[P.VIDEO].total_time_decoded_in};const n=c[j.FRAMES_DECODED],a=c[j.TOTAL_DECODE_TIME],o=a-t[P.VIDEO].total_time_decoded_in,s=n-t[P.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},jv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,j.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,j.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[P.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[P.VIDEO].total_frames_encoded_out,total_encode_time:t[P.VIDEO].total_time_encoded_out};const n=c[j.FRAMES_ENCODED],a=c[j.TOTAL_ENCODE_TIME],o=a-t[P.VIDEO].total_time_encoded_out,s=n-t[P.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},Lf=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,j.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,j.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[j.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[j.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),_=r-n[t].total_KBytes_out,h=c[j.TIMESTAMP]||Date.now(),d=a?a.timestamp:null;let g=n.timestamp;!g&&d&&(g=d);const T=g?h-g:0,S=T>0?_*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:_,kbsSent:S}},$f=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,j.PACKETS_LOST)&&(o=Number(c[j.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,j.FRACTION_LOST)&&(r=Number(100*c[j.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Hf=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,j.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,j.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,j.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[j.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[j.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,_=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+_):0,d=Number(c[j.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=d-n[t].total_KBytes_in,T=c[j.TIMESTAMP]||Date.now(),S=a?a.timestamp:null;let E=n.timestamp;!E&&S&&(E=S);const A=E?T-E:0,C=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:_,packetsLost:s,deltaPacketsLost:r,KBytesReceived:d,deltaKBytesReceived:g,kbsReceived:C}},qv=c=>c[j.CANDIDATE_TYPE]!=="relay"?"":c[j.RELAY_PROTOCOL]||"",Bv=c=>{if(!Object.prototype.hasOwnProperty.call(c,j.NETWORK_TYPE))return Ki.WIFI;switch(c[j.NETWORK_TYPE]){case au.ETHERNET:return Ki.ETHERNET;case au.CELLULAR_4G:return Ki.CELLULAR_4G;case au.WIFI:return Ki.WIFI;default:return Ki.CELLULAR}},Ff=c=>!Object.prototype.hasOwnProperty.call(c,j.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,j.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[j.FRAME_WIDTH]||null,height:c[j.FRAME_HEIGHT]||null,framerate:c[j.FRAMES_PER_SECOND]},Gv=c=>{const t=Object.prototype.hasOwnProperty.call(c,j.QUALITY_LIMITATION_REASON)?c[j.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,j.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[j.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,j.QUALITY_LIMITATION_DURATIONS)?c[j.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}},Wv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,j.PLI)||!Object.prototype.hasOwnProperty.call(c,j.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[j.PLI]||0)-(n?n[P.VIDEO].total_pli_sent_in:0),o=(c[j.NACK]||0)-(n?n[P.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[P.VIDEO].total_pli_sent_in,deltaNackCount:o-t[P.VIDEO].total_nack_sent_in}},Kv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,j.PLI)||!Object.prototype.hasOwnProperty.call(c,j.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[j.PLI]||0)-(n?n[P.VIDEO].total_pli_received_out:0),o=(c[j.NACK]||0)-(n?n[P.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[P.VIDEO].total_pli_received_out,deltaNackCount:o-t[P.VIDEO].total_nack_received_out}},Yv=c=>({channels:c[j.CHANNELS]||null,clock_rate:c[j.CLOCK_RATE]||null,mime_type:c[j.MIME_TYPE]||null,sdp_fmtp_line:c[j.SDP_FMTP_LINE]||null}),Jv=c=>({clock_rate:c[j.CLOCK_RATE]||null,mime_type:c[j.MIME_TYPE]||null}),zv=(c,t,n)=>{const a=(c[j.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[j.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[j.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,_=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let d=t.timestamp;!d&&h&&(d=h);const g=d?s-d:0,T=g>0?r*.008*1024/g*1e3:0,S=g>0?_*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:_,kbs_speed_received:T,kbs_speed_sent:S}},Xv=c=>{const t=c[j.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[j.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},Qv=(c,t,n,a)=>{if(!c)return[];switch(c[j.TYPE]){case zt.CANDIDATE_PAIR:let o=!1;if(c[j.NOMINATED]&&c[j.STATE]===P.SUCCEEDED&&(o=!0,xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c),j.SELECTED in c&&!c[j.SELECTED]&&(o=!1)),o){const r=c[j.LOCAL_CANDIDATE_ID],_=c[j.REMOTE_CANDIDATE_ID],h=zv(c,t,a),d=Xv(c),g=Fv(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:_}},{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:d.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:d.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[j.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:Bv(c)}},{type:ne.NETWORK,value:{local_candidate_type:c[j.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{local_candidate_protocol:c[j.PROTOCOL]||""}},{type:ne.NETWORK,value:{local_candidate_relay_protocol:qv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[j.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[j.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[j.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);const r=c[j.SSRC],_=ct(r,t,$e.INBOUND);_&&(_.timestamp=t.timestamp);const h=ct(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[j.MEDIA_TYPE]===P.AUDIO){const d=Hf(c,P.AUDIO,_,h),g=ha(c,P.AUDIO,_),T=c[j.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:d.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:d.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:d.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:d.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:d.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:d.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:d.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:d.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[j.MEDIA_TYPE]===P.VIDEO){const d=Vv(c,_),g=Hf(c,P.VIDEO,_,h),T=ha(c,P.VIDEO,_),S=c[j.DECODER_IMPLEMENTATION]||null,E=c[j.CODEC_ID]||null,A=Ff(c),C=Wv(c,_,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:E}},{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:S}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:d.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:d.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:d.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:{xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);const r=c[j.SSRC],_=ct(r,t,$e.OUTBOUND);_&&(_.timestamp=t.timestamp);const h=ct(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[j.MEDIA_TYPE]===P.AUDIO){const d=c[j.CODEC_ID]||null,g=Lf(c,P.AUDIO,_,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:d}},{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[j.MEDIA_TYPE]===P.VIDEO){const d=c[j.ENCODER_IMPLEMENTATION]||null,g=c[j.CODEC_ID]||null,T=jv(c,_),S=Ff(c),E=Gv(c),A=Kv(c,_,h),C=Lf(c,P.VIDEO,_,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:d}},{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:S}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:E}}]}break}case zt.MEDIA_SOURCE:{xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);break}case zt.TRACK:{xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);break}case zt.CODEC:const s=[];return Object.keys(t[P.AUDIO]).forEach(r=>{const _=t[P.AUDIO][r];if(_.codec_id_in===c[j.ID]||_.codec_id_out===c[j.ID]){xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);const h=Yv(c);c[j.ID]===_.codec_id_in?s.push({ssrc:_.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:_.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[P.VIDEO]).forEach(r=>{const _=t[P.VIDEO][r];if(_.codec_id_in===c[j.ID]||_.codec_id_out===c[j.ID]){xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);const h=Jv(c);c[j.ID]===_.codec_id_in?s.push({ssrc:_.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:_.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case zt.REMOTE_INBOUND_RTP:{xe(Vs,`analyze() - got stats ${c[j.TYPE]} for ${n}`,c);const r=c[j.SSRC],_=ct(r,t,$e.OUTBOUND),h=ct(r,a,$e.OUTBOUND);if(c[j.KIND]===P.AUDIO){const d=Mf(c,P.AUDIO,h,_),g=ha(c,P.AUDIO,_),T=$f(c,P.AUDIO,_,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:d.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:d.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:d.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[j.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[j.KIND]===P.VIDEO){const d=Mf(c,P.VIDEO,h,_),g=ha(c,P.VIDEO,_),T=$f(c,P.VIDEO,_,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:d.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:d.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:d.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[j.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[]},Ka=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Zv=(c,t=P.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),_=ct(o,a,$e.INBOUND),h=[],d=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,S=r&&r[t].delta_jitter_ms_in||null,E=_&&_[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,R=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),R&&h.push(R),T&&d.push(T),n&&S&&d.push(S),a&&E&&d.push(E);const k=h.length>0?Gs(h):100,M=d.length>0?Gs(d):10,ie=93.2-g,N=.18*ie*ie-27.9*ie+1126.62,V=(k+M)/2,Ee=V-177.3<0?0:1,ve=.024*V+.11*(V-177.3)*Ee,L=N-ve;return Ka(L)},eS=(c,t=P.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),_=ct(o,a,$e.OUTBOUND),h=[],d=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,S=r&&r[t].delta_rtt_ms_out||null,E=_&&_[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,R=_&&_[t].delta_jitter_ms_out||null,k=c.data.delta_rtt_connectivity_ms,M=n&&n.data.delta_rtt_connectivity_ms||null,ie=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):k&&h.push(k),S?h.push(S):M&&h.push(M),E?h.push(E):ie&&h.push(ie),A&&d.push(A),n&&C&&d.push(C),a&&R&&d.push(R);const N=h.length>0?Gs(h):100,V=d.length>0?Gs(d):10,Ee=93.2-g,ve=.18*Ee*Ee-27.9*Ee+1126.62,L=(N+V)/2,D=L-177.3<0?0:1,B=.024*L+.11*(L-177.3)*D,q=ve-B;return Ka(q)},tS=(c,t=P.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),_=ct(o,a,$e.INBOUND),h=[],d=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,S=r&&r[t].delta_jitter_ms_in||null,E=_&&_[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,R=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),R&&h.push(R),T&&d.push(T),r&&S&&d.push(S),_&&E&&d.push(E);const k=h.length>0?Gs(h):100,M=d.length>0?Gs(d):10,ie=0,N=19.8,V=29.7,Ee=30,ve=(k+M)/2+Ee,L=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*L,q=93.2-(ie+N*Math.log(1+V*g)+D);return Ka(q)},sS=(c,t=P.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),_=ct(o,a,$e.OUTBOUND),h=[],d=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,S=r&&r[t].delta_rtt_ms_out||null,E=_&&_[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,R=_&&_[t].delta_jitter_ms_out||null,k=c.data.delta_rtt_connectivity_ms,M=n&&n.data.delta_rtt_connectivity_ms||null,ie=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):k&&h.push(k),S?h.push(S):M&&h.push(M),E?h.push(E):ie&&h.push(ie),A&&d.push(A),r&&C&&d.push(C),_&&R&&d.push(R);const N=h.length>0?Gs(h):100,V=d.length>0?Gs(d):10,Ee=0,ve=19.8,L=29.7,D=30,B=(N+V)/2+D,q=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*q,X=93.2-(Ee+ve*Math.log(1+L*g)+J);return Ka(X)};class nS{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=xv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new Hv(t),this._state=gs.IDLE,this.registerToPCEvents(),Cn(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,d)=>h===P.AUDIO?d===zt.INBOUND_RTP?{...Dh}:{...Nh}:d===zt.INBOUND_RTP?{...Uh}:{...xh},r=wv(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 _=null;return t.forEach(h=>{!_&&h.timestamp&&(_=h.timestamp),Qv(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(S=>{T[S]=g.value[S]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=_,Object.keys(r[P.AUDIO]).forEach(h=>{const d=r[P.AUDIO][h];d.direction===$e.INBOUND?(d.mos_emodel_in=Zv(r,P.AUDIO,n,a,d.ssrc),d.mos_in=tS(r,P.AUDIO,n,a,d.ssrc)):(d.mos_emodel_out=eS(r,P.AUDIO,n,a,d.ssrc),d.mos_out=sS(r,P.AUDIO,n,a,d.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(),_=this.analyze(r,null,null,null),h=Date.now();_.experimental.time_to_measure_ms=h-s,_.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(_),xe(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 xe(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),xe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return hr(this._moduleName,`got error ${t}`),null}}async start(){xe(this._moduleName,"starting"),this.state=gs.RUNNING,this._startedTime=this._exporter.start(),xe(this._moduleName,"started")}async mute(){this.state=gs.MUTED,xe(this._moduleName,"muted")}async unmute(){this.state=gs.RUNNING,xe(this._moduleName,"unmuted")}async stop(t){if(xe(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(),xe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},xe(this._moduleName,`registered callback '${t}'`)):hr(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],xe(this._moduleName,`unregistered callback '${t}'`)):hr(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,xe(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{hr(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===Wi.CONNECTED||a===Wi.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Wi.DISCONNECTED||a===Wi.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Wi.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 rS{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||Uv(),this._moduleName=this._id,Cn(this._moduleName,"probe created"),this._config=t,this._collector=new nS(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){wa(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 iS{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},Cn(Rt,`configured for probing every ${this._config.refreshEvery}ms`),Cn(Rt,`configured for starting after ${this._config.startAfter}ms`),Cn(Rt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),xe(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=Dv(t,n,this._config),o=new rS(a);return this._probes.push(o),xe(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=bv(),r=this._probes.filter(_=>_.isRunning);for(const _ of r){const h=await _.collectStats();h&&s.probes.push(h),xe(Rt,`got probe ${_.id}`),await Pf(0)}return s.delta_time_to_measure_probes_ms=En(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=En(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=En(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=En(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=En(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=En(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=En(s.probes,"video","total_time_encoded_out"),s};for(xe(Rt,"starting to collect"),t(),xe(Rt,"generating reference reports..."),await n(),xe(Rt,"reference reports generated"),this._startedTime=Date.now();a();)if(xe(Rt,`wait ${this._config.refreshEvery}ms before collecting`),await Pf(this._config.refreshEvery),a()){xe(Rt,"collecting...");const s=Date.now(),r=await o(),_=Date.now();r.delta_time_consumed_to_measure_ms=_-s,this.fireOnReports(r),xe(Rt,"collected")}xe(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)})};Cn(Rt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},xe(Rt,`registered callback '${t}'`)):hr(Rt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],xe(this._moduleName,`unregistered callback '${t}'`)):hr(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 lS="interface ";class aS{constructor(t){this._config=Nv(t),Cn(lS,`welcome to ${this._config.name} version ${this._config.version}`),vv(this._config.verbose||!1),this._engine=new iS(this._config)}setupLogLevel(t){Sv(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 oS(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const uS=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"],cS={positiveSpeechThreshold:.6,negativeSpeechThreshold:.3,preSpeechPadMs:150,redemptionMs:1500,minSpeechMs:50};class fS{constructor(t){this.intervals={},this.analysers={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}async start(t,n,a){n&&n.getTracks().length&&await this.beginCalculation(t,n,a)}stop(t){this.clearVolumeInterval(t),this.analysers[t]&&typeof this.analysers[t].disconnect=="function"&&(this.analysers[t].disconnect(),delete this.analysers[t])}clearVolumeInterval(t){this.intervals[t]&&(clearInterval(this.intervals[t]),delete this.intervals[t])}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{this.stop(t)}),this.intervals={},this.analysers={}}async beginCalculation(t,n,a){this.clearVolumeInterval(a);const o=t.createAnalyser(),s=t.createMediaStreamSource(n);o.smoothingTimeConstant=.8,o.fftSize=1024,s.connect(o),this.analysers[a]=o,this.intervals[a]=setInterval(()=>{const r=new Uint8Array(o.frequencyBinCount);o.getByteFrequencyData(r);let _=0;const h=r.length;for(let g=0;g<h;g++)_+=r[g];const d=_/h;this.onChangeFunction(a,d)},this.emitInterval)}}class hS{constructor(){this.resumePromise=null,this.context=new AudioContext}async getContext(){return this.context.state==="suspended"&&(this.resumePromise||(this.resumePromise=this.context.resume().then(()=>{this.resumePromise=null}).catch(t=>{throw this.resumePromise=null,t})),await this.resumePromise),this.context}}const da={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},dS=0;class _S{constructor(t){var n;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.conferenceNodes={},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.vadSessions={},this.vadSessionsState={},this.vadIntervals={},this.vadMrsIntervals={},this.managedAudioContext=new hS,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new fS({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices(),this.processVADConfiguration(((n=this.context.options.configuration)==null?void 0:n.noiseReductionOptions)||{}),this.setupVADInstance()}setVADConfiguration(t){if(!this.MicVAD)throw new Error("VAD module is not provided in the initial configuration");const n=Object.keys(t);for(const a of n)this.noiseReduction[a]=t[a];this.hasActiveCalls&&this.roomReconfigure(this.currentActiveRoomId)}setupVADInstance(){var n,a;const t=(a=(n=this.context.options.configuration)==null?void 0:n.noiseReductionOptions)==null?void 0:a.vadModule;t&&t.MicVAD?(this.MicVAD=t.MicVAD,console.log("✅ VAD module loaded successfully")):this.noiseReduction.mode!=="disabled"&&(console.warn("⚠️ Noise reduction is enabled but VAD module is not provided. To use VAD features, please install @ricky0123/vad-web and pass it via configuration.noiseReductionOptions.vadModule option."),this.noiseReduction.mode="disabled")}processVADConfiguration(t){this.noiseReduction={mode:t.mode||"disabled",checkEveryMs:t.checkEveryMs||500,noiseCheckInterval:t.noiseCheckInterval||2e3,noiseThreshold:t.noiseThreshold||.004,vadConfig:t.vadConfig||{}}}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 bh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input},echoCancellation:!0,echoCancellationType:"system",noiseSuppression:!0,autoGainControl:!0,sampleRate:48e3,latency:.01},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(da.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(da.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)}}async cleanupConferenceNodes(t){const n=this.conferenceNodes[t];if(!n)return;let a=0;n.sources.forEach((r,_)=>{try{r.disconnect(),a++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting source ${_}:`,h)}});let o=0;n.destinations.forEach((r,_)=>{try{r.disconnect(),o++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting destination ${_}:`,h)}});let s=0;n.gains.forEach((r,_)=>{try{r.disconnect(),s++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting gain ${_}:`,h)}}),delete this.conferenceNodes[t]}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})}getNoiseReductionMode(){return this.noiseReduction.mode}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9*#]+$/g.test(n))throw new Error("Not allowed character used in the 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];if(!o)return;o._automaticHold=a??!1;const s=new Promise((r,_)=>{const h=setTimeout(()=>{_(new Error("Hold operation timeout"))},5e3),d=()=>{clearTimeout(h),o.putOnHoldTimestamp=n?Date.now():void 0,r()},g=T=>{clearTimeout(h),_(T)};try{n?(this.stopSessionVad(o._id),o.hold({},d)):o.unhold({},d)}catch(T){g(T)}});try{await s,this.updateCall(o);const r=Object.values(this.extendedCalls).filter(_=>_.roomId===o.roomId&&(n?t!==_._id:!0));r.length>1&&await this.doConference(r)}catch(r){throw console.error("Hold operation failed:",r),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===dS).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})}async setupActiveStream(){const t=await ru(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);t.getTracks().forEach(n=>n.enabled=!this.isMuted),await this.setActiveStream(t)}async getActiveStream(){const t=await ru(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),await 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=>{await this.setupActiveStream();const o=this.activeStream;a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}async setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),await 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})}startNoiseMonitor({sessionId:t,stream:n,onNoiseDetected:a,onNoiseStop:o}){const s=new AudioContext,r=s.createMediaStreamSource(n.clone()),_=s.createAnalyser();_.fftSize=1024;const h=new Float32Array(_.fftSize);r.connect(_);const d=[];this.vadIntervals[t]&&(clearInterval(this.vadIntervals[t]),this.vadIntervals[t]=null),this.vadMrsIntervals[t]&&(clearInterval(this.vadMrsIntervals[t]),this.vadMrsIntervals[t]=null),this.vadMrsIntervals[t]=setInterval(()=>{_.getFloatTimeDomainData(h);const g=hv(h);d.push(g);const T=Math.ceil(this.noiseReduction.noiseCheckInterval/this.noiseReduction.checkEveryMs);d.length>T&&d.shift()},this.noiseReduction.checkEveryMs),this.vadIntervals[t]=setInterval(()=>{if(d.length===0)return;const g=d.reduce((E,A)=>E+A,0)/d.length,T=this.vadSessionsState[t],S=g>this.noiseReduction.noiseThreshold;T.isSpeaking||(S&&T.currentMode==="clean"?(T.currentMode="noisy",console.log("Average noise high → enable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:t,enabled:!0}),a()):!S&&T.currentMode==="noisy"&&(T.currentMode="clean",console.log("Average noise low → disable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:t,enabled:!1}),o()))},this.noiseReduction.noiseCheckInterval)}async processVAD(t,n){const a=n.clone();this.stopSessionVad(t._id),this.vadSessionsState[t._id]={currentMode:"clean",isSpeaking:!1};const o=await this.managedAudioContext.getContext(),s=await dv(a,o,150);let r=!1;const _=await this.MicVAD.new({getStream:()=>new Promise(h=>h(a)),...cS,...this.noiseReduction.vadConfig,baseAssetPath:"https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.28/dist/",onnxWASMBasePath:"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/",onFrameProcessed:()=>{if(!r){if(r=!0,console.log("✅ VAD initialized, starting background noise monitoring"),this.noiseReduction.mode==="enabled"){t.connection.getSenders()[0]&&t.connection.getSenders()[0].replaceTrack(s.stream.getAudioTracks()[0]);return}this.startNoiseMonitor({sessionId:t._id,stream:a,onNoiseDetected:async()=>{var h;console.log("Replace track with Vad Controlled"),await((h=t.connection.getSenders()[0])==null?void 0:h.replaceTrack(s.stream.getAudioTracks()[0]))},onNoiseStop:async()=>{const h=t.connection.getSenders()[0];h&&h.track&&h.transport&&h.transport.state!=="closed"&&h.transport.state!=="failed"&&(console.log("Replace track with Original"),await h.replaceTrack(a.getAudioTracks()[0]))}})}},onSpeechStart:()=>{var h;console.log("🎤 Speech started"),s.setSpeaking(!0),this.noiseReduction.mode==="enabled"&&((h=t.connection.getSenders()[0])==null||h.replaceTrack(s.stream.getAudioTracks()[0])),this.vadSessionsState[t._id].isSpeaking=!0},onSpeechEnd:()=>{var h;console.log("🛑 Speech end"),s.setSpeaking(!1),this.noiseReduction.mode==="enabled"&&((h=t.connection.getSenders()[0])==null||h.replaceTrack(s.stream.getAudioTracks()[0])),this.vadSessionsState[t._id].isSpeaking=!1}});this.vadSessions[t._id]&&(this.vadSessions[t._id].pause(),delete this.vadSessions[t._id]),this.vadSessions[t._id]=_,_.start()}stopSessionVad(t){this.vadSessions[t]&&(this.vadSessions[t].pause(),delete this.vadSessions[t]),this.vadIntervals[t]&&(clearInterval(this.vadIntervals[t]),delete this.vadIntervals[t]),this.vadMrsIntervals[t]&&(clearInterval(this.vadMrsIntervals[t]),delete this.vadMrsIntervals[t]),this.vadSessionsState[t]&&delete this.vadSessionsState[t]}async roomReconfigure(t){var o;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t),a=this.currentActiveRoomId===t;if(n.forEach((s,r)=>{if(s.audioTag){s.connection.getReceivers().forEach(h=>{h.track.enabled=!s.localMuted}),a&&this.muteReconfigure(s);const _=!a;s.audioTag.muted=_,this.updateCall(s)}}),n.length===0){!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t),this.deleteRoomIfEmpty(t);return}if(n.length===1&&!a){const s=n[0];s.isOnHold().local||await this.holdCall(s._id,!0),!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t);return}if(n.length===1&&a){const s=n[0];s.isOnHold().local&&s._automaticHold&&await this.unholdCall(s._id);const h=(((o=s.connection)==null?void 0:o.getSenders())||[])[0];if(s.connection&&h)try{await this.setupActiveStream();const g=this.activeStream;["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(n[0],g);const T=g.getTracks();await h.replaceTrack(T[0]),this.muteReconfigure(s)}catch(g){console.error(g)}!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t);return}n.length>1&&await this.doConference(n)}async doConference(t){if(t.length===0)return;const n=t[0].roomId,a=this.currentActiveRoomId===n;if(t.find(h=>h.roomId!==n))return;const s=await this.managedAudioContext.getContext();if(s.state!=="running"){console.error(`[doConference] ERROR: AudioContext is not running! State: ${s.state}`);return}await this.cleanupConferenceNodes(n),this.conferenceNodes[n]={sources:new Map,destinations:new Map,gains:new Map};const r=this.conferenceNodes[n],_=new Map;t.forEach((h,d)=>{h&&h.connection&&h.connection.getReceivers().forEach((T,S)=>{var C,R,k;T.track.enabled=!h.localMuted;const E=(C=T.track)==null?void 0:C.id;(R=T.track)==null||R.readyState,(k=T.track)==null||k.kind;const A=`${h._id}-${E}`;T.track&&T.track.readyState==="live"&&_.set(A,T.track)})}),await this.setupActiveStream(),await mv.forEach(t,async(h,d)=>{if(!h||!h.connection)return;const g=s.createMediaStreamDestination();r.destinations.set(h._id,g);let T=0;if(_.forEach((C,R)=>{if(!R.startsWith(h._id))try{const k=s.createMediaStreamSource(new MediaStream([C])),M=s.createGain(),ie=`${h._id}-${R}`;k.connect(M),M.connect(g),r.sources.set(ie,k),r.gains.set(ie,M),T++}catch(k){console.error(k)}}),a&&this.activeStreamValue)try{const C=this.activeStream,R=s.createMediaStreamSource(C),k=s.createGain(),M=`${h._id}-local`;R.connect(k),k.connect(g),r.sources.set(M,R),r.gains.set(M,k)}catch(C){console.error(C)}else a&&console.error(`Host room but no activeStreamValue - skipping host microphone for session ${h._id}`);const E=h.connection.getSenders()[0],A=g.stream.getTracks();if(["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(h,g.stream),E&&A[0])try{await E.replaceTrack(A[0]),this.muteReconfigure(h)}catch(C){console.error(C)}})}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=fv(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 d,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};if(n.direction==="incoming")this.context.logger.log("New incoming call from",(g=(d=n._remote_identity)==null?void 0:d._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))});else if(n.direction==="outgoing"){const T=S=>{S.response&&S.response.status_code===gv.SESSION_PROGRESS&&(this.startCallTimer(n.id),n.off("progress",T))};n.on("progress",T),n.once("confirmed",()=>{this.startCallTimer(n.id)})}const r=n,_=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(_||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){const n=this.extendedCalls[t._id];if(!n)return;this.stopVUMeter("origin"),this.stopVUMeter(t._id);const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a).then(()=>{}).catch(o=>{console.error("Error reconfiguring room after call removal:",o)})}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}this.context.triggerListener({listenerType:Xt.NEW_CALL,session:n,event:t}),n.on("ended",o=>{var r,_,h;if(this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(_=(r=n._remote_identity)==null?void 0:r._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:n,event:o}),n.connection){const d=n.connection.connectionState;(d==="closed"||d==="disconnected")&&this.context.emit("connectionStateChange",{session:n,connectionState:d})}["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(n._id);const s=this.getActiveCalls[n.id];s&&this.activeCallListRemove(s),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(h=this.initialStreamValue)==null||h.getTracks().forEach(d=>d.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("progress",o=>{var s,r;this.context.logger.log("Session in progress for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:n,event:o})}),n.on("failed",o=>{var r,_,h;if(this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(_=(r=n._remote_identity)==null?void 0:r._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:n,event:o}),n.connection){const d=n.connection.connectionState;(d==="closed"||d==="disconnected")&&this.context.emit("connectionStateChange",{session:n,connectionState:d})}["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(n._id),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const s=this.getActiveCalls[n.id];s&&this.activeCallListRemove(s),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(h=this.initialStreamValue)==null||h.getTracks().forEach(d=>d.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("confirmed",o=>{var s,r;this.context.logger.log("Session confirmed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:o}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)});const a=o=>{o&&o.addEventListener("connectionstatechange",s=>{this.context.emit("connectionStateChange",{session:n,connectionState:o.connectionState})})};if(n.connection&&a(n.connection),n.on("peerconnection",({peerconnection:o})=>{a(o)}),await this.setupCall(t),n.direction==="outgoing"){const o=this.getActiveCalls[n.id].roomId;await this.setActiveRoom(o)}}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(da.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(da.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 aS(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id}),o=[];let s;a.onreport=r=>{Object.entries(r.audio).forEach(([d,g])=>{g.direction==="inbound"&&!o.includes(d)&&(o.push(d),s=d)});const _=r.audio[s];if(!_)return;const h=oS(_,uS);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Xt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}async setupVUMeter(t,n){await this.VUMeter.start(await this.managedAudioContext.getContext(),t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){try{const t=Date.now(),n=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach((o,s)=>{o.stop()}),this.initialStreamValue=null),this.initialStreamValue=n}catch(t){throw t}}async triggerAddStream(t,n){const a=this.muteWhenJoin||this.isMuted;this.setIsMuted(a),this.initialStreamValue||await this.setupStream();const o=await this.managedAudioContext.getContext(),s=await ru(o,this.initialStreamValue,this.microphoneInputLevel*2),r=this.isMuted||this.muteWhenJoin;s.getTracks().forEach(S=>{S.enabled=!r}),await this.setActiveStream(s),await n.connection.getSenders()[0].replaceTrack(s.getTracks()[0]);const d=new MediaStream([t.track]);!Object.values(this.extendedCalls).find(S=>S.audioTag&&S.audioTag.id===n._id)&&JT(d,n,this.selectedOutputDevice,this.speakerVolume);const T=n.roomId===this.currentActiveRoomId;n.audioTag&&(n.audioTag.muted=!T),await this.setupVUMeter(d,n._id),this.getCallQuality(n),this.updateCall(n),["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(n,s)}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];if(!a)return;const o=a.roomId;a.roomId=n,this.updateCall(a),await this.roomReconfigure(o),await this.roomReconfigure(n)}}class pS{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 mS{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this))}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){t.session._id||(t.session._id=t.request.call_id+t.request.from._parameters.tag);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 _a={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class Ph{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 kh extends Ph{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 Rn("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 tl(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(xt.PUBLISHER)];this.session.sendRequest(H.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,_,h,d;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((_=(r=g.plugindata)==null?void 0:r.data)==null?void 0:_.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(d=(h=g.plugindata)==null?void 0:h.data)!=null&&d.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(xt.ICE)];this.session.sendRequest(H.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
|
|
159
|
-
`),d
|
|
156
|
+
`),this._newMSRPSession("local",this._request),this._from_tag||(this._from_tag=this._request.from._parameters.tag),this._id=this._request.call_id+this._from_tag,new tl(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||H.causes.BYE,o=Pe.cloneArray(t.extraHeaders),a=t.body;let s,r=t.status_code,_=t.reason_phrase;if(this._status===Re.STATUS_TERMINATED)throw new js.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&&(_=_||H.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${_}"`),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,H.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,_,o,a),this._failed("local",null,H.causes.REJECTED);break;case Re.STATUS_WAITING_FOR_ACK:case Re.STATUS_CONFIRMED:if(_=t.reason_phrase||H.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&o.push(`Reason: SIP ;cause=${r}; text="${_}"`),this._status===Re.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const d=this._dialog;this.receiveRequest=({method:h})=>{h===H.ACK&&(this.sendRequest(H.BYE,{extraHeaders:o,body:a}),d.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(H.BYE,{extraHeaders:o,body:a}),d.terminate())}),this._ended("local",null,n),this._dialog=d,this._ua.newDialog(d)}else this.sendRequest(H.BYE,{extraHeaders:o,body:a}),this._ended("local",null,n)}}sendRequest(t,n){return this._dialog.sendRequest(t,n)}authenticate(t){this.status="auth";let n=new ur("");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 o=n.toString(),a=[];for(var s=0;s<o.length;s++)a.push(o.charCodeAt(s).toString(16));this._connection.send(n.toString())}onmessage(t){const n=new ur(t.data);if(this.status==="auth"&&n.code===401){const o=this.parseAuth(n.getHeader("WWW-Authenticate")),a=new Km(this.credentials);a.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},o,Pe.createRandomToken(12)),this.authenticate(a)}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 o=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,a=n.candidate.candidate.match(o);this.my_ip=a&&a[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(H.ACK);return}else{const n=new Zl(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(H.ACK),this.sendRequest(H.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 o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",t)).catch(a=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});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,H.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,H.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(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),console.log("failed 4"),this._failed("local",t,H.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(H.ACK),this._confirmed("local",null)});break}default:{const n=Pe.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new ur("");let o="";this.my_addr[1]&&(o=this.my_addr[1]),this.target_addr[1]&&(o+=" "+this.target_addr[1]),this.target_addr[0]&&(o+=" "+this.target_addr[0]),n.method="SEND",n.addHeader("To-Path",o),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",Pe.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 s=[];for(var r=0;r<a.length;r++)s.push(a.charCodeAt(r).toString(16));console.log(s),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,o=t.getHeader("Message-ID"),a=new ur("");a.method="200 OK",a.addHeader("To-Path",`${this.my_addr[1]}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",o),a.ident=n;let s=a.toString();console.log(s);let r=[];for(var _=0;_<s.length;_++)r.push(s.charCodeAt(_).toString(16));console.log(r),this._connection.send(a.toString())}_sendReport(t){let n=t.ident,o=t.getHeader("Message-ID"),a=new ur("");a.method="REPORT",a.addHeader("To-Path",`${t.getHeader("From-Path")}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",o),a.addHeader("Byte-Range","1-25/25"),a.addHeader("Status","000 200 OK"),a.ident=n;let s=a.toString();console.log(s);let r=[];for(var _=0;_<s.length;_++)r.push(s.charCodeAt(_).toString(16));console.log(r),this._connection.send(a.toString())}parseAuth(t){const n={},o=t.replace("Digest","").split(",");for(const a of o){const s=a.trim().split("=");n[s[0]]=s[1].match('^"(.+)"$')[1]}return n}init_incoming(t,n){let o;const a=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&a!=="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")&&(o=t.getHeader("expires")*1e3),t.to_tag=Pe.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,H.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Re.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),console.log("failed 7"),this._failed("system",null,H.causes.EXPIRES))},o)),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,o){this.emit("_failed",{originator:t,message:n||null,cause:o}),this._close(),this.emit("failed",{originator:t,message:n||null,cause:o})}_close(){if(console.log("CLOSE SESSION"),this._status!==Re.STATUS_TERMINATED){if(this._status=Re.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(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,o){const a=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+a+s;let _=this._earlyDialogs[r];if(o)return _?!0:(_=new Zl(this,t,n,Zl.C.STATUS_EARLY),_.error?(console.log("failed 8"),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=_,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,_)return _.update(t,n),this._dialog=_,delete this._earlyDialogs[r],!0;const d=new Zl(this,t,n);return d.error?(console.log("failed 9"),this._failed("remote",t,H.causes.INTERNAL_ERROR),!1):(this._dialog=d,!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,o){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:o})}_runKeepAliveTimer(){if(!this._sessionTimers||!this._sessionTimers.enabled||this._sessionTimers.running)return;if(this._sessionTimers.currentExpires||(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires||30),!this._sessionTimers.refresher){console.log("Not the refresher; waiting for remote keep-alive");return}const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.timer=setTimeout(()=>{if(this._connection.readyState===WebSocket.OPEN)try{this._sendKeepAlive(),console.log("Session timer: sending MSRP keep-alive")}catch(n){console.error("Failed to send keep-alive:",n)}this._sessionTimers.running=!1,this._runKeepAliveTimer()},t*1e3*.5)}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=H.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._runKeepAliveTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===H.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,H.causes.CANCELED));else switch(t.method){case H.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:H.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 o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(a=>{this.terminate({cause:H.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",t);break;case H.BYE:this._status===Re.STATUS_CONFIRMED||this._status===Re.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,H.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,H.causes.BYE)):t.reply(403,"Wrong Status");break;case H.INVITE:this._status===Re.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case H.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 Cu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case H.UPDATE:this._status===Re.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case H.REFER:this._status===Re.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case H.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:H.causes.CONNECTION_ERROR,cause:H.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:H.causes.REQUEST_TIMEOUT,cause:H.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:H.causes.DIALOG_ERROR,cause:H.causes.DIALOG_ERROR})}}var MT=Zt();const Iu=Xe(MT),co=new Ko("Parser"),LT=(c,t)=>{let n,o,a=c.indexOf(`\r
|
|
157
|
+
`);if(a===-1){co.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,a);let r=Iu.parse(s,"Request_Response");if(r===-1){co.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new _r.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new _r.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let _=a+2;for(;;){if(a=$T(c,_),a===-2){o=_+2;break}else if(a===-1){co.warn("parseMessage() | malformed message");return}if(r=HT(n,c,_,a),r!==!0){co.warn("parseMessage() |",r.error);return}_=a+2}if(n.hasHeader("content-length")){const d=n.getHeader("content-length");n.body=c.substr(o,d)}else n.body=c.substring(o);return n};function $T(c,t){let n=t,o=0,a=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;o===0;){if(a=c.indexOf(`\r
|
|
158
|
+
`,n),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?n=a+2:o=a}return o}function HT(c,t,n,o){let a;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),_=t.substring(s+1,o).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",_),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",_),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",_),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Iu.parse(_,"Record_Route"),a===-1)a=void 0;else for(const d of a)c.addHeader("record-route",_.substring(d.possition,d.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=d.parsed;break;case"call-id":case"i":c.setHeader("call-id",_),a=c.parseHeader("call-id"),a&&(c.call_id=_);break;case"contact":case"m":if(a=Iu.parse(_,"Contact"),a===-1)a=void 0;else for(const d of a)c.addHeader("contact",_.substring(d.possition,d.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=d.parsed;break;case"content-length":case"l":c.setHeader("content-length",_),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",_),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",_),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof _r.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",_),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",_),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",_),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",_),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",_),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",_),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",_),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(r,_),a=0}return a===void 0?{error:`error parsing header "${r}"`}:!0}const FT={parseMessage:LT},Gi=new Ko("Registrator"),fo=10;class VT{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 o=this._contact.indexOf(">");if(o!==-1){const a=this._contact.slice(0,o)+this._contact.slice(o+1,this._contact.length);this._contact=a}this._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 o=t[n];this._extraContactParams+=`;${n}`,o&&(this._extraContactParams+=`=${o}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const o=t[n];this._extraContactParams+=`;${n}`,o&&(this._extraContactParams+=`=${o}`)}}register(){if(this._registering){Gi.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(H.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),o=new tl(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,H.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,H.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){Gi.debug("no Contact header in response to REGISTER, response ignored");break}const s=a.headers.Contact.reduce((h,g)=>h.concat(g.parsed),[]);let r=s.find(h=>this._sipInstance===h.getParam("+sip.instance")&&this._reg_id===parseInt(h.getParam("reg-id")));if(r||(r=s.find(h=>h.uri.user===this._ua.contact.uri.user)),!r){Gi.debug("no Contact header pointing to us, response ignored");break}this._ua.clearKeepAliveInterval(),this._ua.setLastRegisterTimestamp();let _=r.getParam("expires");!_&&a.hasHeader("expires")&&(_=a.getHeader("expires")),_||(_=this._expires),_=Number(_),_<fo&&(_=fo);const d=_>64?_*1e3/2+Math.floor((_/2-32)*1e3*Math.random()):Math.floor(_*1e3/2);this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},d),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:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<fo&&(this._expires=fo),this.register()):(Gi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,H.causes.SIP_FAILURE_CODE));break}default:{const s=Ts.sipErrorCause(a.status_code);this._registrationFailure(a,s)}}}});this._registering=!0,o.send()}unregister(t={}){if(!this._registered){Gi.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 o=new yt.OutgoingRequest(H.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new tl(this._ua,o,{onRequestTimeout:()=>{this._unregistered(null,H.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,H.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 st=console,qs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},jT=wT;class qT extends jT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this.optionsInterval=null,this.lastOptionsTimestamp=null,this.lastRegisterTimestamp=null,this._registrator=new VT(this)}setLastRegisterTimestamp(){this.lastRegisterTimestamp=Date.now()}call(t,n){return super.call(t,n)}joinVideoCall(t,n,o){st.debug("call()");const a=new Fo(this);return a.configureMedia({audio:!0,video:!0}),a.connect(t,n,o),a}startScreenShare(){st.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{nl.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 o=this._configuration.uri.clone();o.user=null,this._configuration.hostport_params=o.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 st.warn(s),new js.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 Rn("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,_=s.outbound||null;let d="<";return r?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),_&&(r?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(a.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));st.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(nl.settings,s))switch(s){case"uri":case"registrar_server":st.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":st.debug(`- ${s}: NOT SHOWN`);break;default:st.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",o=>{console.log(o)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(o=>{o.setSession(t)}),this.processStreamPlugins.forEach(o=>{o.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}clearKeepAliveInterval(){clearInterval(this.optionsInterval),this.optionsInterval=null}receiveRequest(t){var s,r,_,d;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){st.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.lastOptionsTimestamp=Date.now(),this.optionsInterval||(this.emit("initKeepAliveInterval"),this.optionsInterval=setInterval(()=>{const g=Date.now(),T=this.lastOptionsTimestamp>g-35e3,S=this.lastRegisterTimestamp+this._configuration.register_expires*1e3>g;T&&S&&this.emit("keepAliveInterval")},35e3)),this.listeners("newOptions").length===0){t.reply(200);return}new Zc.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new Zc.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let o,a;if(t.to_tag)if(o=this._findDialog(t.call_id,t.from_tag,t.to_tag),o)o.receiveRequest(t);else if(n===De.NOTIFY)if(a=this._findSession(t),a)a.receiveRequest(t);else{if(t.body)try{const h=JSON.parse(t.body)||{};(r=(s=h.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(h),(d=(_=h.plugindata)==null?void 0:_.data)!=null&&d.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(h.plugindata.data.unpublished)}catch(h){console.error(h)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const h=t.replaces;o=this._findDialog(h.call_id,h.from_tag,h.to_tag),o?(a=o.owner,a.isEnded()?t.reply(603):a.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(a=new ru(this),a.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(a=new $g(this),a.init_incoming(t));else st.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:a=this._findSession(t),a?a.receiveRequest(t):st.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){st.debug("startMSRP()",n);const o=new ru(this);return o.connect(t),o}startJanus(t,n){st.debug("startJanus()",n);const o=new ru(this);return o.connect(t),o}terminateMSRPSessions(t){st.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){st.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){st.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){st.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)){st.debug(`closing session ${t}`);try{this._sessions[t].terminate()}catch(n){console.error(n)}}}stop(t=!0){if(st.debug("stop()"),this._dynConfiguration={},this._status===qs.STATUS_USER_CLOSED){st.debug("UA already closed");return}this._registrator.close();const n=Object.keys(this._sessions).length;t&&this.terminateAllSessions();for(const a in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,a)){st.debug(`closing session ${a}`);try{this._msrp_sessions[a].terminate()}catch(s){console.error(s)}}for(const a in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,a)){st.debug(`closing session ${a}`);try{this._janus_sessions[a].terminate()}catch(s){console.error(s)}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch(s){console.error(s)}this._status=qs.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!==qs.STATUS_USER_CLOSED&&(this._status=qs.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 o in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],o)&&this._transactions[n][o].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==qs.STATUS_USER_CLOSED&&(this._status=qs.STATUS_NOT_READY,this._error=qs.NETWORK_ERROR)}function KT(c){const t=c.transport;let n=c.message;const o=n;if(n=FT.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,o),!!n&&!(this._status===qs.STATUS_USER_CLOSED&&n instanceof _r.IncomingRequest)&&pT(n,this,t)){if(n instanceof _r.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof _r.IncomingResponse){let a;switch(n.method){case De.INVITE:if(a=this._transactions.ict[n.via_branch],a){const s=n.status_code;if((s===100||s===180||s===183)&&this.audio&&typeof this.audio.handleSipResponseForRingback=="function"){let r=null;if(a._session&&a._session.id)r=a._session.id;else if(n.call_id&&this._sessions){const d=Object.values(this._sessions).find(h=>h._id&&h._id.includes(n.call_id)||h.id&&h.id.includes(n.call_id)||h.call_id===n.call_id);d&&(d.id||d._id)&&(r=d.id||d._id)}else n.call_id&&(r=n.call_id);r&&this.audio.handleSipResponseForRingback(r,s)}a.receiveResponse(n)}break;case De.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.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 xf(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}async function iu(c,t,n){const o=c.createMediaStreamSource(t),a=c.createMediaStreamDestination(),s=c.createGain();return o.connect(s),s.connect(a),s.gain.value=n,a.stream}function zT(c,t,n,o){if(wd())return;const a=document.createElement("audio");a.id=t._id,a.className="audioTag",a.srcObject=c,a.setSinkId(n),a.volume=o,a.play(),t.audioTag=a}function XT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function wd(){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:o}){Dt.debug(`WebSocket ${this._url} closed`),t===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,o)}_onMessage({data:t}){Dt.debug("received WebSocket message"),this.ondata(t)}_onError(t){Dt.warn(`WebSocket ${this._url} error: `,t)}};const wu=Vo,tv=De,sv=Cs,nv=Ct(),rv=Id,iv=ys(),lv=Hu(),ov=Zt(),av=ev,uv=mr("JsSIP");uv("version %s",wu.version);var cv={C:tv,Exceptions:sv,Utils:nv,UA:rv,URI:iv,NameAddrHeader:lv,WebSocketInterface:av,Grammar:ov,debug:mr,get name(){return wu.title},get version(){return wu.version}};const fv=Xe(cv);function lu(c){return c<10?`0${c}`:`${c}`}function dv(c){let t=c.hours||0,n=c.minutes||0,o=c.seconds||0;o++,o===60&&(o=0,n++,n===60&&(n=0,t++));const a=`${lu(t)}:${lu(n)}:${lu(o)}`;return{seconds:o,minutes:n,hours:t,formatted:a}}function hv(c){let t=0;for(let n=0;n<c.length;n++)t+=c[n]*c[n];return Math.sqrt(t/c.length)}async function _v(c,t,n=150){const o=t.createMediaStreamSource(c),a=t.createDelay();a.delayTime.value=n/1e3;const s=t.createGain();s.gain.value=0;const r=t.createMediaStreamDestination();return o.connect(a).connect(s).connect(r),{stream:r.stream,setSpeaking:_=>{s.gain.value=_?1:0}}}var At={};At.forEach=async(c,t,n)=>{const o=[];for(let a=0;a<c.length;a++)if(a in c){const s=Promise.resolve(c[a]).then(r=>t.call(n||globalThis,r,a,c));o.push(s)}await Promise.all(o)};At.forEachSeries=async(c,t,n)=>{for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)};At.map=async(c,t,n)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&(o[a]=Promise.resolve(c[a]).then(s=>t.call(n||globalThis,s,a,c)));return Promise.all(o)};At.mapSeries=async(c,t,n)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&(o[a]=await t.call(n||globalThis,await c[a],a,c));return o};At.find=(c,t,n)=>new Promise((o,a)=>{if(c.length===0)return o();let s=1;for(let r=0;r<c.length;r++){const _=d=>{d?o(c[r]):s===c.length&&o(),s++};Promise.resolve(c[r]).then(d=>t.call(n||globalThis,d,r,c)).then(_).catch(a)}});At.findSeries=async(c,t,n)=>{for(let o=0;o<c.length;o++)if(await t.call(n||globalThis,await c[o],o,c))return c[o]};At.findIndex=(c,t,n)=>new Promise((o,a)=>{if(c.length===0)return o(-1);let s=1;for(let r=0;r<c.length;r++){const _=d=>{d?o(r):s===c.length&&o(-1),s++};Promise.resolve(c[r]).then(d=>t.call(n||globalThis,d,r,c)).then(_).catch(a)}});At.findIndexSeries=async(c,t,n)=>{for(let o=0;o<c.length;o++)if(await t.call(n||globalThis,await c[o],o,c))return o};At.some=(c,t,n)=>new Promise((o,a)=>{if(c.length===0)return o(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const _=d=>{d?o(!0):s===c.length&&o(!1),s++};Promise.resolve(c[r]).then(d=>t.call(n||globalThis,d,r,c)).then(_).catch(a)}});At.someSeries=async(c,t,n)=>{for(let o=0;o<c.length;o++)if(o in c&&await t.call(n||globalThis,await c[o],o,c))return!0;return!1};At.every=(c,t,n)=>new Promise((o,a)=>{if(c.length===0)return o(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const _=d=>{d?s===c.length&&o(!0):o(!1),s++};Promise.resolve(c[r]).then(d=>t.call(n||globalThis,d,r,c)).then(_).catch(a)}});At.everySeries=async(c,t,n)=>{for(let o=0;o<c.length;o++)if(o in c&&!await t.call(n||globalThis,await c[o],o,c))return!1;return!0};At.filter=(c,t,n)=>new Promise(async(o,a)=>{const s=[];for(let _=0;_<c.length;_++)_ in c&&(s[_]=Promise.resolve(c[_]).then(d=>t.call(n||globalThis,d,_,c)).catch(a));const r=[];for(let _=0;_<s.length;_++)await s[_]&&r.push(await c[_]);o(r)});At.filterSeries=async(c,t,n)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)&&o.push(await c[a]);return o};At.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let o,a;for(n!==void 0?(a=n,o=0):(a=c[0],o=1),o;o<c.length;o++)o in c&&(a=await t(await a,await c[o],o,c));return a};var Od={};(function(c){const t=At;Object.keys(t).forEach(n=>{const o=n.charAt(0).toUpperCase()+n.slice(1);c[`async${o}`]=async function(...a){return t[n](this,...a)}})})(Od);const pv=At,mv=Od;var gv=Object.assign(pv,{instanceMethods:mv});const Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"},ho={TRYING:100,RINGING:180,SESSION_PROGRESS:183,OK:200,MOVED_TEMPORARILY:302,BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,REQUEST_TIMEOUT:408,BUSY_HERE:486,REQUEST_TERMINATED:487,INTERNAL_SERVER_ERROR:500,SERVICE_UNAVAILABLE:503,BUSY_EVERYWHERE:600,DECLINE:603};var Tv={exports:{}};(function(c){var t=function(n){var o=Object.prototype,a=o.hasOwnProperty,s=Object.defineProperty||function(Q,W,B){Q[W]=B.value},r,_=typeof Symbol=="function"?Symbol:{},d=_.iterator||"@@iterator",h=_.asyncIterator||"@@asyncIterator",g=_.toStringTag||"@@toStringTag";function T(Q,W,B){return Object.defineProperty(Q,W,{value:B,enumerable:!0,configurable:!0,writable:!0}),Q[W]}try{T({},"")}catch{T=function(W,B,ie){return W[B]=ie}}function S(Q,W,B,ie){var ve=W&&W.prototype instanceof re?W:re,Ie=Object.create(ve.prototype),ke=new U(ie||[]);return s(Ie,"_invoke",{value:K(Q,B,ke)}),Ie}n.wrap=S;function E(Q,W,B){try{return{type:"normal",arg:Q.call(W,B)}}catch(ie){return{type:"throw",arg:ie}}}var A="suspendedStart",R="suspendedYield",C="executing",$="completed",k={};function re(){}function x(){}function F(){}var _e={};T(_e,d,function(){return this});var pe=Object.getPrototypeOf,P=pe&&pe(pe(X([])));P&&P!==o&&a.call(P,d)&&(_e=P);var N=F.prototype=re.prototype=Object.create(_e);x.prototype=F,s(N,"constructor",{value:F,configurable:!0}),s(F,"constructor",{value:x,configurable:!0}),x.displayName=T(F,g,"GeneratorFunction");function q(Q){["next","throw","return"].forEach(function(W){T(Q,W,function(B){return this._invoke(W,B)})})}n.isGeneratorFunction=function(Q){var W=typeof Q=="function"&&Q.constructor;return W?W===x||(W.displayName||W.name)==="GeneratorFunction":!1},n.mark=function(Q){return Object.setPrototypeOf?Object.setPrototypeOf(Q,F):(Q.__proto__=F,T(Q,g,"GeneratorFunction")),Q.prototype=Object.create(N),Q},n.awrap=function(Q){return{__await:Q}};function j(Q,W){function B(Ie,ke,Ae,oe){var ye=E(Q[Ie],Q,ke);if(ye.type==="throw")oe(ye.arg);else{var nt=ye.arg,ot=nt.value;return ot&&typeof ot=="object"&&a.call(ot,"__await")?W.resolve(ot.__await).then(function(Ee){B("next",Ee,Ae,oe)},function(Ee){B("throw",Ee,Ae,oe)}):W.resolve(ot).then(function(Ee){nt.value=Ee,Ae(nt)},function(Ee){return B("throw",Ee,Ae,oe)})}}var ie;function ve(Ie,ke){function Ae(){return new W(function(oe,ye){B(Ie,ke,oe,ye)})}return ie=ie?ie.then(Ae,Ae):Ae()}s(this,"_invoke",{value:ve})}q(j.prototype),T(j.prototype,h,function(){return this}),n.AsyncIterator=j,n.async=function(Q,W,B,ie,ve){ve===void 0&&(ve=Promise);var Ie=new j(S(Q,W,B,ie),ve);return n.isGeneratorFunction(W)?Ie:Ie.next().then(function(ke){return ke.done?ke.value:Ie.next()})};function K(Q,W,B){var ie=A;return function(Ie,ke){if(ie===C)throw new Error("Generator is already running");if(ie===$){if(Ie==="throw")throw ke;return He()}for(B.method=Ie,B.arg=ke;;){var Ae=B.delegate;if(Ae){var oe=V(Ae,B);if(oe){if(oe===k)continue;return oe}}if(B.method==="next")B.sent=B._sent=B.arg;else if(B.method==="throw"){if(ie===A)throw ie=$,B.arg;B.dispatchException(B.arg)}else B.method==="return"&&B.abrupt("return",B.arg);ie=C;var ye=E(Q,W,B);if(ye.type==="normal"){if(ie=B.done?$:R,ye.arg===k)continue;return{value:ye.arg,done:B.done}}else ye.type==="throw"&&(ie=$,B.method="throw",B.arg=ye.arg)}}}function V(Q,W){var B=W.method,ie=Q.iterator[B];if(ie===r)return W.delegate=null,B==="throw"&&Q.iterator.return&&(W.method="return",W.arg=r,V(Q,W),W.method==="throw")||B!=="return"&&(W.method="throw",W.arg=new TypeError("The iterator does not provide a '"+B+"' method")),k;var ve=E(ie,Q.iterator,W.arg);if(ve.type==="throw")return W.method="throw",W.arg=ve.arg,W.delegate=null,k;var Ie=ve.arg;if(!Ie)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,k;if(Ie.done)W[Q.resultName]=Ie.value,W.next=Q.nextLoc,W.method!=="return"&&(W.method="next",W.arg=r);else return Ie;return W.delegate=null,k}q(N),T(N,g,"Generator"),T(N,d,function(){return this}),T(N,"toString",function(){return"[object Generator]"});function z(Q){var W={tryLoc:Q[0]};1 in Q&&(W.catchLoc=Q[1]),2 in Q&&(W.finallyLoc=Q[2],W.afterLoc=Q[3]),this.tryEntries.push(W)}function D(Q){var W=Q.completion||{};W.type="normal",delete W.arg,Q.completion=W}function U(Q){this.tryEntries=[{tryLoc:"root"}],Q.forEach(z,this),this.reset(!0)}n.keys=function(Q){var W=Object(Q),B=[];for(var ie in W)B.push(ie);return B.reverse(),function ve(){for(;B.length;){var Ie=B.pop();if(Ie in W)return ve.value=Ie,ve.done=!1,ve}return ve.done=!0,ve}};function X(Q){if(Q){var W=Q[d];if(W)return W.call(Q);if(typeof Q.next=="function")return Q;if(!isNaN(Q.length)){var B=-1,ie=function ve(){for(;++B<Q.length;)if(a.call(Q,B))return ve.value=Q[B],ve.done=!1,ve;return ve.value=r,ve.done=!0,ve};return ie.next=ie}}return{next:He}}n.values=X;function He(){return{value:r,done:!0}}return U.prototype={constructor:U,reset:function(Q){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(D),!Q)for(var W in this)W.charAt(0)==="t"&&a.call(this,W)&&!isNaN(+W.slice(1))&&(this[W]=r)},stop:function(){this.done=!0;var Q=this.tryEntries[0],W=Q.completion;if(W.type==="throw")throw W.arg;return this.rval},dispatchException:function(Q){if(this.done)throw Q;var W=this;function B(oe,ye){return Ie.type="throw",Ie.arg=Q,W.next=oe,ye&&(W.method="next",W.arg=r),!!ye}for(var ie=this.tryEntries.length-1;ie>=0;--ie){var ve=this.tryEntries[ie],Ie=ve.completion;if(ve.tryLoc==="root")return B("end");if(ve.tryLoc<=this.prev){var ke=a.call(ve,"catchLoc"),Ae=a.call(ve,"finallyLoc");if(ke&&Ae){if(this.prev<ve.catchLoc)return B(ve.catchLoc,!0);if(this.prev<ve.finallyLoc)return B(ve.finallyLoc)}else if(ke){if(this.prev<ve.catchLoc)return B(ve.catchLoc,!0)}else if(Ae){if(this.prev<ve.finallyLoc)return B(ve.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(Q,W){for(var B=this.tryEntries.length-1;B>=0;--B){var ie=this.tryEntries[B];if(ie.tryLoc<=this.prev&&a.call(ie,"finallyLoc")&&this.prev<ie.finallyLoc){var ve=ie;break}}ve&&(Q==="break"||Q==="continue")&&ve.tryLoc<=W&&W<=ve.finallyLoc&&(ve=null);var Ie=ve?ve.completion:{};return Ie.type=Q,Ie.arg=W,ve?(this.method="next",this.next=ve.finallyLoc,k):this.complete(Ie)},complete:function(Q,W){if(Q.type==="throw")throw Q.arg;return Q.type==="break"||Q.type==="continue"?this.next=Q.arg:Q.type==="return"?(this.rval=this.arg=Q.arg,this.method="return",this.next="end"):Q.type==="normal"&&W&&(this.next=W),k},finish:function(Q){for(var W=this.tryEntries.length-1;W>=0;--W){var B=this.tryEntries[W];if(B.finallyLoc===Q)return this.complete(B.completion,B.afterLoc),D(B),k}},catch:function(Q){for(var W=this.tryEntries.length-1;W>=0;--W){var B=this.tryEntries[W];if(B.tryLoc===Q){var ie=B.completion;if(ie.type==="throw"){var ve=ie.arg;D(B)}return ve}}throw new Error("illegal catch attempt")},delegateYield:function(Q,W,B){return this.delegate={iterator:X(Q),resultName:W,nextLoc:B},this.method==="next"&&(this.arg=r),k}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(Tv);var Dd={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(Vd,function(){var t=function(){},n="undefined",o=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),a=["trace","debug","info","warn","error"];function s(R,C){var $=R[C];if(typeof $.bind=="function")return $.bind(R);try{return Function.prototype.bind.call($,R)}catch{return function(){return Function.prototype.apply.apply($,[R,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 _(R){return R==="debug"&&(R="log"),typeof console===n?!1:R==="trace"&&o?r:console[R]!==void 0?s(console,R):console.log!==void 0?s(console,"log"):t}function d(R,C){for(var $=0;$<a.length;$++){var k=a[$];this[k]=$<R?t:this.methodFactory(k,R,C)}this.log=this.debug}function h(R,C,$){return function(){typeof console!==n&&(d.call(this,C,$),this[R].apply(this,arguments))}}function g(R,C,$){return _(R)||h.apply(this,arguments)}function T(R,C,$){var k=this,re;C=C??"WARN";var x="loglevel";typeof R=="string"?x+=":"+R:typeof R=="symbol"&&(x=void 0);function F(N){var q=(a[N]||"silent").toUpperCase();if(!(typeof window===n||!x)){try{window.localStorage[x]=q;return}catch{}try{window.document.cookie=encodeURIComponent(x)+"="+q+";"}catch{}}}function _e(){var N;if(!(typeof window===n||!x)){try{N=window.localStorage[x]}catch{}if(typeof N===n)try{var q=window.document.cookie,j=q.indexOf(encodeURIComponent(x)+"=");j!==-1&&(N=/^([^;]+)/.exec(q.slice(j))[1])}catch{}return k.levels[N]===void 0&&(N=void 0),N}}function pe(){if(!(typeof window===n||!x)){try{window.localStorage.removeItem(x);return}catch{}try{window.document.cookie=encodeURIComponent(x)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}k.name=R,k.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},k.methodFactory=$||g,k.getLevel=function(){return re},k.setLevel=function(N,q){if(typeof N=="string"&&k.levels[N.toUpperCase()]!==void 0&&(N=k.levels[N.toUpperCase()]),typeof N=="number"&&N>=0&&N<=k.levels.SILENT){if(re=N,q!==!1&&F(N),d.call(k,N,R),typeof console===n&&N<k.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+N},k.setDefaultLevel=function(N){C=N,_e()||k.setLevel(N,!1)},k.resetLevel=function(){k.setLevel(C,!1),pe()},k.enableAll=function(N){k.setLevel(k.levels.TRACE,N)},k.disableAll=function(N){k.setLevel(k.levels.SILENT,N)};var P=_e();P==null&&(P=C),k.setLevel(P,!1)}var S=new T,E={};S.getLogger=function(C){if(typeof C!="symbol"&&typeof C!="string"||C==="")throw new TypeError("You must supply a name when creating a logger.");var $=E[C];return $||($=E[C]=new T(C,S.getLevel(),S.methodFactory)),$};var A=typeof window!==n?window.log:void 0;return S.noConflict=function(){return typeof window!==n&&window.log===S&&(window.log=A),S},S.getLoggers=function(){return E},S.default=S,S})})(Dd);var bt=Dd.exports;const vs=()=>`${new Date().toISOString()} | metrics`,Ss=(c,t,n)=>`${c} | ${t} | ${n}`;bt.setDefaultLevel(bt.levels.TRACE);const vv=c=>{bt.info(Ss(vs(),"log ",`set log level to ${c?"verbose":"info"}`)),bt.setLevel(c?bt.levels.TRACE:bt.levels.INFO)},Sv=c=>{const t=[...Object.keys(bt.levels)];t.includes(c)?(bt.info(Ss(vs(),"log ",`update log level to ${c.toLowerCase()}`)),bt.setLevel(c)):bt.warn(Ss(vs(),"log ","Incorrect log level please choose one of "),t)},Ue=(c,t,n)=>{n?bt.debug(Ss(vs(),c,t),n):bt.debug(Ss(vs(),c,t))},ou=(c,t)=>{bt.info(Ss(vs(),c,t))},An=(c,t)=>{bt.info(Ss(vs(),c,t))},Do=(c,t)=>{bt.warn(Ss(vs(),c,t))},dr=(c,t)=>{bt.error(Ss(vs(),c,t))};function Ev(c){return Math.floor(Math.random()*c).toString()}function kf(c,t){let n=t;return c.forEach(o=>{n=n.replace(o,"")}),n}function yv(c,t){let n="";for(let o=0;o<t;o+=1)n+=c[Ev(c.length)];return n}function Cv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:o=[],excludeSymbols:a=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",_=[],d=[],h=[];return t&&(a.length&&(s=kf(a,s)),d=s.split("")),n&&(a.length&&(r=kf(a,r)),h=r.split("")),_=[...d,...h,...o],yv(_,c)}var Av=Cv;const Xi=Xe(Av),Rv=()=>"WebRTCMetrics",bv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},gs={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Wi={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Iv=()=>({...{delta_time_to_measure_probes_ms:0,delta_time_consumed_to_measure_ms:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,total_time_decoded_in:0,total_time_encoded_out:0,probes:[]}}),Nd={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},xd={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},Ud={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},kd={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},wv=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(o=>{n.audio[o]={...c.audio[o]}}),Object.keys(c.video).forEach(o=>{n.video[o]={...c.video[o]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},Ov={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Xi()}`,cid:`c-${Xi()}`,uid:`u-${Xi()}`,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"},G={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},M={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Ki={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"},uu="config ",Dv=(c,t={},n)=>{const o={...n,...t};return t.pname||Do(uu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Do(uu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Do(uu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),o.pc=c,o},Nv=(c={})=>{const t={...Ov,...c};return t.name=Rv(),t.version=bv(),t},pl=(c,t,n,o=!1,a)=>{let s=c.map(r=>{if(!n)return r[t];if(!a)return r[t][n];const _=r[t][a];return _?_[n]:null});return s=s.filter(r=>o?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Gs=c=>c.reduce((t,n)=>t+n,0)/c.length,xv=()=>`probe-${Xi()}`,Uv=()=>`coltr-${Xi()}`,Pf=c=>new Promise(t=>setTimeout(t,c)),Ou=(c,t,n)=>{t?c.call(t,n):c(n)},Ye=(c,t,n,o)=>{const a=pl(c,t,n,!0,o);if(a.length===0)return null;const s=a.reduce((h,g)=>h+g,0)/a.length;return s===0?null:a.map(h=>Math.abs(s-h)).reduce((h,g)=>h+g,0)/a.length*100/s},Qe=(c,t,n,o=!1,a)=>{const s=pl(c,t,n,o,a);return s.length===0?null:s.reduce((r,_)=>r+_,0)/s.length},En=(c,t,n)=>pl(c,t,n).reduce((a,s)=>a+s,0),Je=(c,t,n,o)=>{const a=pl(c,t,n,!0,o);return a.length===0?null:Math.min(...a)},ze=(c,t,n,o)=>{const a=pl(c,t,n,!1,o);return a.length===0?null:Math.max(...a)},gt=(c,t,n,o)=>{const a=c.slice().pop();if(!a)return null;if(!n)return a[t];if(!o)return a[t][n];const s=a[t][o];return s?s[n]:null},kv=c=>c.slice().pop(),ct=(c,t,n)=>{if(!t)return null;const o={};let a=t[M.AUDIO][c];a||(a=n===$e.INBOUND?{...Nd}:{...xd}),o[M.AUDIO]=a;let s=t[M.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ud}:{...kd}),o[M.VIDEO]=s,o},Yi="exporter ",Pv="2.0",Mf=(c,t,n)=>{if(!c||c.length===0)return 0;const o=c[c.length-1];if(!o)return 0;const a=o[t][n];if(a){const s=a.total_rtt_ms_out,r=a.total_rtt_measure_out;return!r||!s?Qe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},Mv=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const o=n[t].total_rtt_connectivity_ms,a=n[t].total_rtt_connectivity_measure;return!a||!o?Qe(c,t,"delta_rtt_connectivity_ms"):Number(o/a)},Lv=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,$v=c=>{const t=gt(c,"network","remote_candidate_type"),n=gt(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class Hv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){ou(Yi,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){ou(Yi,"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&&(Ue(Yi,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){ou(Yi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Ue(Yi,"ticket() - generate ticket");const t=gt(this._reports,"audio","total_packets_lost_in"),n=gt(this._reports,"audio","total_packets_in"),o=gt(this._reports,"video","total_packets_lost_in"),a=gt(this._reports,"video","total_packets_in"),s={},r=kv(this._reports);return r&&(Object.keys(r[M.AUDIO]).forEach(_=>{const d=r[M.AUDIO][_];if(s[d.ssrc]={type:M.AUDIO,direction:d.direction},d.direction===$e.INBOUND){const h={avg:Qe(this._reports,M.AUDIO,"delta_jitter_ms_in",!1,_),min:Je(this._reports,M.AUDIO,"delta_jitter_ms_in",_),max:ze(this._reports,M.AUDIO,"delta_jitter_ms_in",_),volatility:Ye(this._reports,M.AUDIO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Qe(this._reports,M.AUDIO,"delta_kbs_in",!1,_),min:Je(this._reports,M.AUDIO,"delta_kbs_in",_),max:ze(this._reports,M.AUDIO,"delta_kbs_in",_),volatility:Ye(this._reports,M.AUDIO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Qe(this._reports,M.AUDIO,"delta_KBytes_in",!1,_),min:Je(this._reports,M.AUDIO,"delta_KBytes_in",_),max:ze(this._reports,M.AUDIO,"delta_KBytes_in",_),volatility:Ye(this._reports,M.AUDIO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S={emodel:{avg:Qe(this._reports,M.AUDIO,"mos_emodel_in",!1,_),min:Je(this._reports,M.AUDIO,"mos_emodel_in",_),max:ze(this._reports,M.AUDIO,"mos_emodel_in",_),volatility:Ye(this._reports,M.AUDIO,"mos_emodel_in",_)},effective:{avg:Qe(this._reports,M.AUDIO,"mos_in",!1,_),min:Je(this._reports,M.AUDIO,"mos_in",_),max:ze(this._reports,M.AUDIO,"mos_in",_),volatility:Ye(this._reports,M.AUDIO,"mos_in",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},E=gt(this._reports,M.AUDIO,"total_packets_lost_in",_),A=gt(this._reports,M.AUDIO,"total_packets_in",_),R={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=h,s[_].mos=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=R}else{const h={avg:Qe(this._reports,M.AUDIO,"delta_jitter_ms_out",!1,_),min:Je(this._reports,M.AUDIO,"delta_jitter_ms_out",_),max:ze(this._reports,M.AUDIO,"delta_jitter_ms_out",_),volatility:Ye(this._reports,M.AUDIO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Qe(this._reports,M.AUDIO,"delta_kbs_out",!1,_),min:Je(this._reports,M.AUDIO,"delta_kbs_out",_),max:ze(this._reports,M.AUDIO,"delta_kbs_out",_),volatility:Ye(this._reports,M.AUDIO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Qe(this._reports,M.AUDIO,"delta_KBytes_out",!1,_),min:Je(this._reports,M.AUDIO,"delta_KBytes_out",_),max:ze(this._reports,M.AUDIO,"delta_KBytes_out",_),volatility:Ye(this._reports,M.AUDIO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},S={avg:Mf(this._reports,M.AUDIO,_),min:Je(this._reports,M.AUDIO,"delta_rtt_ms_out",_),max:ze(this._reports,M.AUDIO,"delta_rtt_ms_out",_),volatility:Ye(this._reports,M.AUDIO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},E=gt(this._reports,M.AUDIO,"total_packets_lost_out",_),A=gt(this._reports,M.AUDIO,"total_packets_out",_),R={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},C={emodel:{avg:Qe(this._reports,M.AUDIO,"mos_emodel_out",!1,_),min:Je(this._reports,M.AUDIO,"mos_emodel_out",_),max:ze(this._reports,M.AUDIO,"mos_emodel_out",_),volatility:Ye(this._reports,M.AUDIO,"mos_emodel_out",_)},effective:{avg:Qe(this._reports,M.AUDIO,"mos_out",!1,_),min:Je(this._reports,M.AUDIO,"mos_out",_),max:ze(this._reports,M.AUDIO,"mos_out",_),volatility:Ye(this._reports,M.AUDIO,"mos_out",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[_].jitter=h,s[_].rtt=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=R,s[_].mos=C}}),Object.keys(r[M.VIDEO]).forEach(_=>{const d=r[M.VIDEO][_];if(s[_]={type:M.VIDEO,direction:d.direction},d.direction===$e.INBOUND){const h={avg:Qe(this._reports,M.VIDEO,"delta_jitter_ms_in",!1,_),min:Je(this._reports,M.VIDEO,"delta_jitter_ms_in",_),max:ze(this._reports,M.VIDEO,"delta_jitter_ms_in",_),volatility:Ye(this._reports,M.VIDEO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Qe(this._reports,M.VIDEO,"delta_kbs_in",!1,_),min:Je(this._reports,M.VIDEO,"delta_kbs_in",_),max:ze(this._reports,M.VIDEO,"delta_kbs_in",_),volatility:Ye(this._reports,M.VIDEO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Qe(this._reports,M.VIDEO,"delta_KBytes_in",!1,_),min:Je(this._reports,M.VIDEO,"delta_KBytes_in",_),max:ze(this._reports,M.VIDEO,"delta_KBytes_in",_),volatility:Ye(this._reports,M.VIDEO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S=gt(this._reports,M.VIDEO,"total_packets_lost_in",_),E=gt(this._reports,M.VIDEO,"total_packets_in",_),A={lost:S,avg:Math.round((S/(S+E)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=h,s[_].traffic=T,s[_].bitrate=g,s[_].loss=A}else{const h={avg:Qe(this._reports,M.VIDEO,"delta_jitter_ms_out",!1,_),min:Je(this._reports,M.VIDEO,"delta_jitter_ms_out",_),max:ze(this._reports,M.VIDEO,"delta_jitter_ms_out",_),volatility:Ye(this._reports,M.VIDEO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Qe(this._reports,M.VIDEO,"delta_kbs_out",!1,_),min:Je(this._reports,M.VIDEO,"delta_kbs_out",_),max:ze(this._reports,M.VIDEO,"delta_kbs_out",_),volatility:Ye(this._reports,M.VIDEO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Qe(this._reports,M.VIDEO,"delta_KBytes_out",!1,_),min:Je(this._reports,M.VIDEO,"delta_KBytes_out",_),max:ze(this._reports,M.VIDEO,"delta_KBytes_out",_),volatility:Ye(this._reports,M.VIDEO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},S={avg:Mf(this._reports,M.VIDEO,_),min:Je(this._reports,M.VIDEO,"delta_rtt_ms_out",_),max:ze(this._reports,M.VIDEO,"delta_rtt_ms_out",_),volatility:Ye(this._reports,M.VIDEO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},E=gt(this._reports,M.VIDEO,"total_packets_lost_out",_),A=gt(this._reports,M.VIDEO,"total_packets_out",_),R={lost:E,avg:Math.round((E/(E+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[_].jitter=h,s[_].rtt=S,s[_].traffic=T,s[_].bitrate=g,s[_].loss=R}})),{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:Mv(this._reports,"data"),min:Je(this._reports,"data","delta_rtt_connectivity_ms"),max:ze(this._reports,"data","delta_rtt_connectivity_ms"),volatility:Ye(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((o/(o+a)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Qe(this._reports,"data","delta_kbs_in"),min:Je(this._reports,"data","delta_kbs_in"),max:ze(this._reports,"data","delta_kbs_in"),volatility:Ye(this._reports,"data","delta_kbs_in")},out:{avg:Qe(this._reports,"data","delta_kbs_out"),min:Je(this._reports,"data","delta_kbs_out"),max:ze(this._reports,"data","delta_kbs_out"),volatility:Ye(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:Qe(this._reports,"data","delta_KBytes_in"),min:Je(this._reports,"data","delta_KBytes_in"),max:ze(this._reports,"data","delta_KBytes_in"),volatility:Ye(this._reports,"data","delta_KBytes_in")},out:{avg:Qe(this._reports,"data","delta_KBytes_out"),min:Je(this._reports,"data","delta_KBytes_out"),max:ze(this._reports,"data","delta_KBytes_out"),volatility:Ye(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:Lv(this._reports),remoteConnection:$v(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 Vs="extractor ",Lf=(c,t,n,o)=>{let a=!1;const s=o[t].total_rtt_ms_out,r=o[t].total_rtt_measure_out,_=n?n[t].total_rtt_ms_out:0,d=n?n[t].total_rtt_measure_out:0,h={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[G.TIMESTAMP]===o[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,G.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,G.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(c[G.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[G.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-d===r))return h;const g=1e3*Number(c[G.ROUND_TRIP_TIME]);let T=s+g,S=r+1;return a&&(T=1e3*Number(c[G.TOTAL_ROUND_TRIP_TIME])-_,S=Number(c[G.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-d),{rtt:g,totalRTT:T,totalRTTMeasurements:S}},Fv=(c,t,n,o)=>{if(!Object.prototype.hasOwnProperty.call(c,G.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:o[t].total_rtt_connectivity_ms,totalRTTMeasurements:o[t].total_rtt_connectivity_measure};const a=1e3*Number(c[G.CURRENT_ROUND_TRIP_TIME]);let s=o[t].total_rtt_connectivity_ms+a,r=o[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,G.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[G.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,G.RESPONSES_RECEIVED)&&(r=Number(c[G.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:s,totalRTTMeasurements:r}},_o=(c,t,n)=>c[G.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,G.JITTER)?null:1e3*(Number(c[G.JITTER])||0),Vv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,G.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,G.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[M.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[M.VIDEO].total_frames_decoded_in,total_decode_time:t[M.VIDEO].total_time_decoded_in};const n=c[G.FRAMES_DECODED],o=c[G.TOTAL_DECODE_TIME],a=o-t[M.VIDEO].total_time_decoded_in,s=n-t[M.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?a*1e3/s:0,frames_decoded:n,total_decode_time:o}},jv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,G.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,G.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[M.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[M.VIDEO].total_frames_encoded_out,total_encode_time:t[M.VIDEO].total_time_encoded_out};const n=c[G.FRAMES_ENCODED],o=c[G.TOTAL_ENCODE_TIME],a=o-t[M.VIDEO].total_time_encoded_out,s=n-t[M.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&a?a*1e3/s:0,frames_encoded:n,total_encode_time:o}},$f=(c,t,n,o)=>{if(!Object.prototype.hasOwnProperty.call(c,G.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,G.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const a=Number(c[G.PACKETS_SENT])||0-(o?o[t].total_packets_out:0),s=a-n[t].total_packets_out,r=Number(c[G.BYTES_SENT])/1024-(o?o[t].total_KBytes_out:0),_=r-n[t].total_KBytes_out,d=c[G.TIMESTAMP]||Date.now(),h=o?o.timestamp:null;let g=n.timestamp;!g&&h&&(g=h);const T=g?d-g:0,S=T>0?_*.008*1024/T*1e3:0;return{packetsSent:a,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:_,kbsSent:S}},Hf=(c,t,n,o)=>{let a=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,G.PACKETS_LOST)&&(a=Number(c[G.PACKETS_LOST])||0-(o?o[t].total_packets_lost_out:0),s=a-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,G.FRACTION_LOST)&&(r=Number(100*c[G.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:s,fractionLost:r}},Ff=(c,t,n,o)=>{if(!Object.prototype.hasOwnProperty.call(c,G.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,G.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,G.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 a=Number(c[G.PACKETS_RECEIVED])||0-(o?o[t].total_packets_in:0),s=Number(c[G.PACKETS_LOST])||0-(o?o[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,_=a-n[t].total_packets_in,d=a!==n[t].total_packets_in?r*100/(r+_):0,h=Number(c[G.BYTES_RECEIVED])/1024-(o?o[t].total_KBytes_in:0),g=h-n[t].total_KBytes_in,T=c[G.TIMESTAMP]||Date.now(),S=o?o.timestamp:null;let E=n.timestamp;!E&&S&&(E=S);const A=E?T-E:0,R=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:d,packetsReceived:a,deltaPacketsReceived:_,packetsLost:s,deltaPacketsLost:r,KBytesReceived:h,deltaKBytesReceived:g,kbsReceived:R}},qv=c=>c[G.CANDIDATE_TYPE]!=="relay"?"":c[G.RELAY_PROTOCOL]||"",Bv=c=>{if(!Object.prototype.hasOwnProperty.call(c,G.NETWORK_TYPE))return Ki.WIFI;switch(c[G.NETWORK_TYPE]){case au.ETHERNET:return Ki.ETHERNET;case au.CELLULAR_4G:return Ki.CELLULAR_4G;case au.WIFI:return Ki.WIFI;default:return Ki.CELLULAR}},Vf=c=>!Object.prototype.hasOwnProperty.call(c,G.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,G.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[G.FRAME_WIDTH]||null,height:c[G.FRAME_HEIGHT]||null,framerate:c[G.FRAMES_PER_SECOND]},Gv=c=>{const t=Object.prototype.hasOwnProperty.call(c,G.QUALITY_LIMITATION_REASON)?c[G.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,G.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[G.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,o=Object.prototype.hasOwnProperty.call(c,G.QUALITY_LIMITATION_DURATIONS)?c[G.QUALITY_LIMITATION_DURATIONS]:null;return o&&Object.keys(o).forEach(a=>{o[a]>1e3&&(o[a]=Number(o[a]/1e3))}),{reason:t,durations:o,resolutionChanges:n}},Wv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,G.PLI)||!Object.prototype.hasOwnProperty.call(c,G.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const o=(c[G.PLI]||0)-(n?n[M.VIDEO].total_pli_sent_in:0),a=(c[G.NACK]||0)-(n?n[M.VIDEO].total_nack_sent_in:0);return{pliCount:o,nackCount:a,deltaPliCount:o-t[M.VIDEO].total_pli_sent_in,deltaNackCount:a-t[M.VIDEO].total_nack_sent_in}},Kv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,G.PLI)||!Object.prototype.hasOwnProperty.call(c,G.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const o=(c[G.PLI]||0)-(n?n[M.VIDEO].total_pli_received_out:0),a=(c[G.NACK]||0)-(n?n[M.VIDEO].total_nack_received_out:0);return{pliCount:o,nackCount:a,deltaPliCount:o-t[M.VIDEO].total_pli_received_out,deltaNackCount:a-t[M.VIDEO].total_nack_received_out}},Yv=c=>({channels:c[G.CHANNELS]||null,clock_rate:c[G.CLOCK_RATE]||null,mime_type:c[G.MIME_TYPE]||null,sdp_fmtp_line:c[G.SDP_FMTP_LINE]||null}),Jv=c=>({clock_rate:c[G.CLOCK_RATE]||null,mime_type:c[G.MIME_TYPE]||null}),zv=(c,t,n)=>{const o=(c[G.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),a=(c[G.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[G.TIMESTAMP]||Date.now(),r=o-t.data.total_KBytes_in,_=a-t.data.total_KBytes_out,d=n?n.timestamp:null;let h=t.timestamp;!h&&d&&(h=d);const g=h?s-h:0,T=g>0?r*.008*1024/g*1e3:0,S=g>0?_*.008*1024/g*1e3:0;return{total_KBytes_received:o,total_KBytes_sent:a,delta_KBytes_received:r,delta_KBytes_sent:_,kbs_speed_received:T,kbs_speed_sent:S}},Xv=c=>{const t=c[G.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[G.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},Qv=(c,t,n,o)=>{if(!c)return[];switch(c[G.TYPE]){case zt.CANDIDATE_PAIR:let a=!1;if(c[G.NOMINATED]&&c[G.STATE]===M.SUCCEEDED&&(a=!0,Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c),G.SELECTED in c&&!c[G.SELECTED]&&(a=!1)),a){const r=c[G.LOCAL_CANDIDATE_ID],_=c[G.REMOTE_CANDIDATE_ID],d=zv(c,t,o),h=Xv(c),g=Fv(c,"data",o,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:_}},{type:ne.DATA,value:{total_KBytes_in:d.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:d.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:d.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:d.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:d.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:d.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:h.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:h.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case zt.LOCAL_CANDIDATE:if(c[G.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:Bv(c)}},{type:ne.NETWORK,value:{local_candidate_type:c[G.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{local_candidate_protocol:c[G.PROTOCOL]||""}},{type:ne.NETWORK,value:{local_candidate_relay_protocol:qv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[G.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[G.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[G.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);const r=c[G.SSRC],_=ct(r,t,$e.INBOUND);_&&(_.timestamp=t.timestamp);const d=ct(r,o,$e.INBOUND);if(d&&(d.timestamp=o.timestamp),c[G.MEDIA_TYPE]===M.AUDIO){const h=Ff(c,M.AUDIO,_,d),g=_o(c,M.AUDIO,_),T=c[G.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:h.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:h.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:h.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:h.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:h.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:h.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:h.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:h.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[G.MEDIA_TYPE]===M.VIDEO){const h=Vv(c,_),g=Ff(c,M.VIDEO,_,d),T=_o(c,M.VIDEO,_),S=c[G.DECODER_IMPLEMENTATION]||null,E=c[G.CODEC_ID]||null,A=Vf(c),R=Wv(c,_,d);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:E}},{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:S}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:h.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:h.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:h.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:R.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:R.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:R.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:R.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:A}}]}break}case zt.OUTBOUND_RTP:{Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);const r=c[G.SSRC],_=ct(r,t,$e.OUTBOUND);_&&(_.timestamp=t.timestamp);const d=ct(r,o,$e.OUTBOUND);if(d&&(d.timestamp=o.timestamp),c[G.MEDIA_TYPE]===M.AUDIO){const h=c[G.CODEC_ID]||null,g=$f(c,M.AUDIO,_,d);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:h}},{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[G.MEDIA_TYPE]===M.VIDEO){const h=c[G.ENCODER_IMPLEMENTATION]||null,g=c[G.CODEC_ID]||null,T=jv(c,_),S=Vf(c),E=Gv(c),A=Kv(c,_,d),R=$f(c,M.VIDEO,_,d);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:R.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:R.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:R.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:R.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:R.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:h}},{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:S}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:E}}]}break}case zt.MEDIA_SOURCE:{Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);break}case zt.TRACK:{Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);break}case zt.CODEC:const s=[];return Object.keys(t[M.AUDIO]).forEach(r=>{const _=t[M.AUDIO][r];if(_.codec_id_in===c[G.ID]||_.codec_id_out===c[G.ID]){Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);const d=Yv(c);c[G.ID]===_.codec_id_in?s.push({ssrc:_.ssrc,type:ne.AUDIO,value:{codec_in:d}}):s.push({ssrc:_.ssrc,type:ne.AUDIO,value:{codec_out:d}})}}),Object.keys(t[M.VIDEO]).forEach(r=>{const _=t[M.VIDEO][r];if(_.codec_id_in===c[G.ID]||_.codec_id_out===c[G.ID]){Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);const d=Jv(c);c[G.ID]===_.codec_id_in?s.push({ssrc:_.ssrc,type:ne.VIDEO,value:{codec_in:d}}):s.push({ssrc:_.ssrc,type:ne.VIDEO,value:{codec_out:d}})}}),s;case zt.REMOTE_INBOUND_RTP:{Ue(Vs,`analyze() - got stats ${c[G.TYPE]} for ${n}`,c);const r=c[G.SSRC],_=ct(r,t,$e.OUTBOUND),d=ct(r,o,$e.OUTBOUND);if(c[G.KIND]===M.AUDIO){const h=Lf(c,M.AUDIO,d,_),g=_o(c,M.AUDIO,_),T=Hf(c,M.AUDIO,_,d);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:h.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:h.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:h.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[G.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[G.KIND]===M.VIDEO){const h=Lf(c,M.VIDEO,d,_),g=_o(c,M.VIDEO,_),T=Hf(c,M.VIDEO,_,d);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:h.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:h.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:h.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[G.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[]},Jo=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Zv=(c,t=M.AUDIO,n,o,a)=>{const s=ct(a,c,$e.INBOUND),r=ct(a,n,$e.INBOUND),_=ct(a,o,$e.INBOUND),d=[],h=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,S=r&&r[t].delta_jitter_ms_in||null,E=_&&_[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,R=n&&n.data.delta_rtt_connectivity_ms||null,C=o&&o.data.delta_rtt_connectivity_ms||null;A&&d.push(A),R&&d.push(R),C&&d.push(C),T&&h.push(T),n&&S&&h.push(S),o&&E&&h.push(E);const $=d.length>0?Gs(d):100,k=h.length>0?Gs(h):10,re=93.2-g,x=.18*re*re-27.9*re+1126.62,F=($+k)/2,_e=F-177.3<0?0:1,pe=.024*F+.11*(F-177.3)*_e,P=x-pe;return Jo(P)},eS=(c,t=M.AUDIO,n,o,a)=>{const s=ct(a,c,$e.OUTBOUND),r=ct(a,n,$e.OUTBOUND),_=ct(a,o,$e.OUTBOUND),d=[],h=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,S=r&&r[t].delta_rtt_ms_out||null,E=_&&_[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,R=r&&r[t].delta_jitter_ms_out||null,C=_&&_[t].delta_jitter_ms_out||null,$=c.data.delta_rtt_connectivity_ms,k=n&&n.data.delta_rtt_connectivity_ms||null,re=o&&o.data.delta_rtt_connectivity_ms||null;T?d.push(T):$&&d.push($),S?d.push(S):k&&d.push(k),E?d.push(E):re&&d.push(re),A&&h.push(A),n&&R&&h.push(R),o&&C&&h.push(C);const x=d.length>0?Gs(d):100,F=h.length>0?Gs(h):10,_e=93.2-g,pe=.18*_e*_e-27.9*_e+1126.62,P=(x+F)/2,N=P-177.3<0?0:1,q=.024*P+.11*(P-177.3)*N,j=pe-q;return Jo(j)},tS=(c,t=M.AUDIO,n,o,a)=>{const s=ct(a,c,$e.INBOUND),r=ct(a,n,$e.INBOUND),_=ct(a,o,$e.INBOUND),d=[],h=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,S=r&&r[t].delta_jitter_ms_in||null,E=_&&_[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,R=n&&n.data.delta_rtt_connectivity_ms||null,C=o&&o.data.delta_rtt_connectivity_ms||null;A&&d.push(A),R&&d.push(R),C&&d.push(C),T&&h.push(T),r&&S&&h.push(S),_&&E&&h.push(E);const $=d.length>0?Gs(d):100,k=h.length>0?Gs(h):10,re=0,x=19.8,F=29.7,_e=30,pe=($+k)/2+_e,P=pe-177.3<0?0:1,N=.024*pe+.11*(pe-177.3)*P,j=93.2-(re+x*Math.log(1+F*g)+N);return Jo(j)},sS=(c,t=M.AUDIO,n,o,a)=>{const s=ct(a,c,$e.OUTBOUND),r=ct(a,n,$e.OUTBOUND),_=ct(a,o,$e.OUTBOUND),d=[],h=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,S=r&&r[t].delta_rtt_ms_out||null,E=_&&_[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,R=r&&r[t].delta_jitter_ms_out||null,C=_&&_[t].delta_jitter_ms_out||null,$=c.data.delta_rtt_connectivity_ms,k=n&&n.data.delta_rtt_connectivity_ms||null,re=o&&o.data.delta_rtt_connectivity_ms||null;T?d.push(T):$&&d.push($),S?d.push(S):k&&d.push(k),E?d.push(E):re&&d.push(re),A&&h.push(A),r&&R&&h.push(R),_&&C&&h.push(C);const x=d.length>0?Gs(d):100,F=h.length>0?Gs(h):10,_e=0,pe=19.8,P=29.7,N=30,q=(x+F)/2+N,j=q-177.3<0?0:1,K=.024*q+.11*(q-177.3)*j,z=93.2-(_e+pe*Math.log(1+P*g)+K);return Jo(z)};class nS{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=Uv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new Hv(t),this._state=gs.IDLE,this.registerToPCEvents(),An(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,o,a){const s=(d,h)=>d===M.AUDIO?h===zt.INBOUND_RTP?{...Nd}:{...xd}:h===zt.INBOUND_RTP?{...Ud}:{...kd},r=wv(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 _=null;return t.forEach(d=>{!_&&d.timestamp&&(_=d.timestamp),Qv(d,r,r.pname,a).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,d.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(S=>{T[S]=g.value[S]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=_,Object.keys(r[M.AUDIO]).forEach(d=>{const h=r[M.AUDIO][d];h.direction===$e.INBOUND?(h.mos_emodel_in=Zv(r,M.AUDIO,n,o,h.ssrc),h.mos_in=tS(r,M.AUDIO,n,o,h.ssrc)):(h.mos_emodel_out=eS(r,M.AUDIO,n,o,h.ssrc),h.mos_out=sS(r,M.AUDIO,n,o,h.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const o=Date.now();setTimeout(async()=>{try{const a=Date.now()-o,s=Date.now(),r=await this._config.pc.getStats(),_=this.analyze(r,null,null,null),d=Date.now();_.experimental.time_to_measure_ms=d-s,_.experimental.time_to_wait_ms=a,this._exporter.saveReferenceReport(_),Ue(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(a){n(a)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==gs.RUNNING||!this._config.pc)return Ue(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),o=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),a=Date.now();return o.experimental.time_to_measure_ms=a-t,this._exporter.addReport(o),Ue(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(o),o}catch(t){return dr(this._moduleName,`got error ${t}`),null}}async start(){Ue(this._moduleName,"starting"),this.state=gs.RUNNING,this._startedTime=this._exporter.start(),Ue(this._moduleName,"started")}async mute(){this.state=gs.MUTED,Ue(this._moduleName,"muted")}async unmute(){this.state=gs.RUNNING,Ue(this._moduleName,"unmuted")}async stop(t){if(Ue(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(),Ue(this._moduleName,"stopped")}registerCallback(t,n,o){t in this._callbacks?(this._callbacks[t]={callback:n,context:o},Ue(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],Ue(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&Ou(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&Ou(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,Ue(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,o,a){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:o,description:a})}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 o=t.iceConnectionState;o===Wi.CONNECTED||o===Wi.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",o,"ICE connection state"):o===Wi.DISCONNECTED||o===Wi.FAILED?this.addCustomEvent(new Date().toJSON(),"call",o,"ICE connection state"):o===Wi.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const o=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",o,"ICE gathering state")},t.ontrack=o=>{this.addCustomEvent(new Date().toJSON(),"call",`${o.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 o=n[0],{transport:a}=o;if(a){const{iceTransport:s}=a;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class rS{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||xv(),this._moduleName=this._id,An(this._moduleName,"probe created"),this._config=t,this._collector=new nS(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,o,a=new Date().toJSON()){this._collector.addCustomEvent(a,n,t,o)}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){Do(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 iS{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},An(Rt,`configured for probing every ${this._config.refreshEvery}ms`),An(Rt,`configured for starting after ${this._config.startAfter}ms`),An(Rt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Ue(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 o=Dv(t,n,this._config),a=new rS(o);return this._probes.push(a),Ue(Rt,`${this._probes.length} probes registered`),a}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())),o=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,a=async()=>{const s=Iv(),r=this._probes.filter(_=>_.isRunning);for(const _ of r){const d=await _.collectStats();d&&s.probes.push(d),Ue(Rt,`got probe ${_.id}`),await Pf(0)}return s.delta_time_to_measure_probes_ms=En(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=En(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=En(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=En(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=En(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=En(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=En(s.probes,"video","total_time_encoded_out"),s};for(Ue(Rt,"starting to collect"),t(),Ue(Rt,"generating reference reports..."),await n(),Ue(Rt,"reference reports generated"),this._startedTime=Date.now();o();)if(Ue(Rt,`wait ${this._config.refreshEvery}ms before collecting`),await Pf(this._config.refreshEvery),o()){Ue(Rt,"collecting...");const s=Date.now(),r=await a(),_=Date.now();r.delta_time_consumed_to_measure_ms=_-s,this.fireOnReports(r),Ue(Rt,"collected")}Ue(Rt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=o=>{this._probes.forEach(a=>{a.stop(o)})};An(Rt,"stop collecting"),n(t)}registerCallback(t,n,o){t in this._callbacks?(this._callbacks[t]={callback:n,context:o},Ue(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],Ue(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&&Ou(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const lS="interface ";class oS{constructor(t){this._config=Nv(t),An(lS,`welcome to ${this._config.name} version ${this._config.version}`),vv(this._config.verbose||!1),this._engine=new iS(this._config)}setupLogLevel(t){Sv(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 aS(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,o)=>{const a=o;return{...n,[a]:c[a]}},{})}const uS=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"],cS={positiveSpeechThreshold:.6,negativeSpeechThreshold:.3,preSpeechPadMs:150,redemptionMs:1500,minSpeechMs:50};class fS{constructor(t){this.intervals={},this.analysers={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}async start(t,n,o){n&&n.getTracks().length&&await this.beginCalculation(t,n,o)}stop(t){this.clearVolumeInterval(t),this.analysers[t]&&typeof this.analysers[t].disconnect=="function"&&(this.analysers[t].disconnect(),delete this.analysers[t])}clearVolumeInterval(t){this.intervals[t]&&(clearInterval(this.intervals[t]),delete this.intervals[t])}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{this.stop(t)}),this.intervals={},this.analysers={}}async beginCalculation(t,n,o){this.clearVolumeInterval(o);const a=t.createAnalyser(),s=t.createMediaStreamSource(n);a.smoothingTimeConstant=.8,a.fftSize=1024,s.connect(a),this.analysers[o]=a,this.intervals[o]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let _=0;const d=r.length;for(let g=0;g<d;g++)_+=r[g];const h=_/d;this.onChangeFunction(o,h)},this.emitInterval)}}class dS{constructor(){this.resumePromise=null,this.context=new AudioContext,this.setupErrorHandling()}setupErrorHandling(){this.context.addEventListener("statechange",()=>{(this.context.state==="interrupted"||this.context.state==="closed")&&console.warn(`[ManagedAudioContext] AudioContext state changed to: ${this.context.state}`)})}createNewContext(){return console.log("[ManagedAudioContext] Creating new AudioContext instance"),this.context=new AudioContext,this.setupErrorHandling(),this.context}async getContext(){if(this.context.state==="closed")return console.warn("[ManagedAudioContext] AudioContext is closed, creating new instance"),this.createNewContext();if(this.context.state==="interrupted"){console.warn("[ManagedAudioContext] AudioContext is interrupted, attempting to resume");try{this.resumePromise||(this.resumePromise=this.context.resume().then(()=>{this.resumePromise=null}).catch(t=>{console.error("[ManagedAudioContext] Failed to resume interrupted context:",t),this.resumePromise=null,this.createNewContext()})),await this.resumePromise}catch(t){return console.error("[ManagedAudioContext] Error resuming context, creating new one:",t),this.createNewContext()}}return this.context.state==="suspended"&&(this.resumePromise||(this.resumePromise=this.context.resume().then(()=>{this.resumePromise=null}).catch(t=>{throw console.error("[ManagedAudioContext] Failed to resume suspended context:",t),this.resumePromise=null,t})),await this.resumePromise),this.context.state==="closed"?(console.warn("[ManagedAudioContext] Context closed after resume attempt, creating new instance"),this.createNewContext()):this.context}}const po={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},hS=0;class _S{constructor(t){var n;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.conferenceNodes={},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.vadSessions={},this.vadSessionsState={},this.vadIntervals={},this.vadMrsIntervals={},this.ringbackTimers={},this.ringbackAudioContexts={},this.ringbackSessionProgressReceived={},this.managedAudioContext=new dS,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new fS({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices(),this.processVADConfiguration(((n=this.context.options.configuration)==null?void 0:n.noiseReductionOptions)||{}),this.setupVADInstance()}setVADConfiguration(t){if(!this.MicVAD)throw new Error("VAD module is not provided in the initial configuration");const n=Object.keys(t);for(const o of n)this.noiseReduction[o]=t[o];this.hasActiveCalls&&this.roomReconfigure(this.currentActiveRoomId)}setupVADInstance(){var n,o;const t=(o=(n=this.context.options.configuration)==null?void 0:n.noiseReductionOptions)==null?void 0:o.vadModule;t&&t.MicVAD?(this.MicVAD=t.MicVAD,console.log("✅ VAD module loaded successfully")):this.noiseReduction.mode!=="disabled"&&(console.warn("⚠️ Noise reduction is enabled but VAD module is not provided. To use VAD features, please install @ricky0123/vad-web and pass it via configuration.noiseReductionOptions.vadModule option."),this.noiseReduction.mode="disabled")}processVADConfiguration(t){this.noiseReduction={mode:t.mode||"disabled",checkEveryMs:t.checkEveryMs||500,noiseCheckInterval:t.noiseCheckInterval||2e3,noiseThreshold:t.noiseThreshold||.004,vadConfig:t.vadConfig||{}}}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(o=>!o.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 wd()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input},echoCancellation:!0,echoCancellationType:"system",noiseSuppression:!0,autoGainControl:!0,sampleRate:48e3,latency:.01},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(po.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(po.SELECTED_OUTPUT_DEVICE)||"default";try{const o=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),a=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(a),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),o.getTracks().forEach(s=>s.stop())}catch(o){console.error(o)}}async cleanupConferenceNodes(t){const n=this.conferenceNodes[t];if(!n)return;let o=0;n.sources.forEach((r,_)=>{var d;try{r.disconnect(),o++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting source ${_}:`,h),(d=this.context.logger)==null||d.error(`[cleanupConferenceNodes] Error disconnecting source ${_}:`,h)}});let a=0;n.destinations.forEach((r,_)=>{var d;try{r.disconnect(),a++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting destination ${_}:`,h),(d=this.context.logger)==null||d.error(`[cleanupConferenceNodes] Error disconnecting destination ${_}:`,h)}});let s=0;n.gains.forEach((r,_)=>{var d;try{r.disconnect(),s++}catch(h){console.error(`[cleanupConferenceNodes] Error disconnecting gain ${_}:`,h),(d=this.context.logger)==null||d.error(`[cleanupConferenceNodes] Error disconnecting gain ${_}:`,h)}}),delete this.conferenceNodes[t]}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})}getNoiseReductionMode(){return this.noiseReduction.mode}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9*#]+$/g.test(n))throw new Error("Not allowed character used in the 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(o=>o.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:o}){const a=this.extendedCalls[t];if(!a)return;a._automaticHold=o??!1;const s=new Promise((r,_)=>{const d=setTimeout(()=>{_(new Error("Hold operation timeout"))},5e3),h=()=>{clearTimeout(d),a.putOnHoldTimestamp=n?Date.now():void 0,r()},g=T=>{clearTimeout(d),_(T)};try{n?(this.stopSessionVad(a._id),a.hold({},h)):a.unhold({},h)}catch(T){g(T)}});try{await s,this.updateCall(a);const r=Object.values(this.extendedCalls).filter(_=>_.roomId===a.roomId&&(n?t!==_._id:!0));r.length>1&&await this.doConference(r)}catch(r){throw console.error("Hold operation failed:",r),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===hS).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",o=>{this.triggerAddStream(o,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]=xf(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const o={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...o}},this.context.emit("updateRoom",{room:o,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,a=t.request.getHeader("Call-Info");return a&&n.test(a)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:xf(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 o={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(o.isMoving=t.isMoving),t.isTransferring!==void 0&&(o.isTransferring=t.isTransferring),t.isMerging!==void 0&&(o.isMerging=t.isMerging),t.isTransferred!==void 0&&(o.isTransferred=t.isTransferred),this.callStatus={...this.callStatus,[t.callId]:{...o}},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})}async setupActiveStream(){const t=await iu(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);t.getTracks().forEach(n=>n.enabled=!this.isMuted),await this.setActiveStream(t)}async getActiveStream(){const t=await iu(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),await this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:o})=>o===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(o=>o.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async o=>{await this.setupActiveStream();const a=this.activeStream;o.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(o)}):await this.doConference(n)}async setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),await this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:a})=>a===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const o=n.filter(a=>a.roomId===this.currentActiveRoomId);o.length===1?n.forEach(a=>{var s;(s=a.audioTag)==null||s.setSinkId(t),this.updateCall(a)}):await this.doConference(o)}removeRoom(t){const n={...this.activeRooms},o={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:o,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 startNoiseMonitor({sessionId:t,stream:n,onNoiseDetected:o,onNoiseStop:a}){var g,T,S;let s;try{s=await this.managedAudioContext.getContext()}catch(E){console.error("[startNoiseMonitor] Failed to get AudioContext:",E),(g=this.context.logger)==null||g.error("[startNoiseMonitor] Failed to get AudioContext:",E);return}let r,_;try{r=s.createMediaStreamSource(n.clone()),_=s.createAnalyser()}catch(E){console.error("[startNoiseMonitor] Failed to create audio nodes:",E),console.error("[startNoiseMonitor] AudioContext state:",s.state),(T=this.context.logger)==null||T.error("[startNoiseMonitor] Failed to create audio nodes:",E),(S=this.context.logger)==null||S.error("[startNoiseMonitor] AudioContext state:",s.state);return}_.fftSize=1024;const d=new Float32Array(_.fftSize);r.connect(_);const h=[];this.vadIntervals[t]&&(clearInterval(this.vadIntervals[t]),this.vadIntervals[t]=null),this.vadMrsIntervals[t]&&(clearInterval(this.vadMrsIntervals[t]),this.vadMrsIntervals[t]=null),this.vadMrsIntervals[t]=setInterval(()=>{_.getFloatTimeDomainData(d);const E=hv(d);h.push(E);const A=Math.ceil(this.noiseReduction.noiseCheckInterval/this.noiseReduction.checkEveryMs);h.length>A&&h.shift()},this.noiseReduction.checkEveryMs),this.vadIntervals[t]=setInterval(()=>{var C;if(h.length===0)return;const E=h.reduce(($,k)=>$+k,0)/h.length,A=this.vadSessionsState[t];if(!A){console.warn(`[startNoiseMonitor] State not found for sessionId ${t}, stopping interval`),(C=this.context.logger)==null||C.warn(`[startNoiseMonitor] State not found for sessionId ${t}, stopping interval`),this.vadIntervals[t]&&(clearInterval(this.vadIntervals[t]),delete this.vadIntervals[t]),this.vadMrsIntervals[t]&&(clearInterval(this.vadMrsIntervals[t]),delete this.vadMrsIntervals[t]);return}const R=E>this.noiseReduction.noiseThreshold;A.isSpeaking||(R&&A.currentMode==="clean"?(A.currentMode="noisy",console.log("Average noise high → enable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:t,enabled:!0}),o()):!R&&A.currentMode==="noisy"&&(A.currentMode="clean",console.log("Average noise low → disable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:t,enabled:!1}),a()))},this.noiseReduction.noiseCheckInterval)}async processVAD(t,n){var d;const o=n.clone();this.stopSessionVad(t._id),this.vadSessionsState[t._id]={currentMode:"clean",isSpeaking:!1},console.log("[processVAD] Process for",t._id),(d=this.context.logger)==null||d.log("[processVAD] Process for",t._id);const a=await this.managedAudioContext.getContext(),s=await _v(o,a,150);let r=!1;const _=await this.MicVAD.new({getStream:()=>new Promise(h=>h(o)),...cS,...this.noiseReduction.vadConfig,baseAssetPath:"https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.28/dist/",onnxWASMBasePath:"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/",onFrameProcessed:()=>{var h;if(!r){if(r=!0,console.log("✅ VAD initialized, starting background noise monitoring"),this.noiseReduction.mode==="enabled"){t.connection.getSenders()[0]&&t.connection.getSenders()[0].replaceTrack(s.stream.getAudioTracks()[0]);return}if(!this.vadSessionsState[t._id]){console.error(`[processVAD] CRITICAL: State not found for session ${t._id} after being set at line 988! This should not happen.`),(h=this.context.logger)==null||h.error(`[processVAD] CRITICAL: State not found for session ${t._id} after being set at line 988! This should not happen.`);return}this.startNoiseMonitor({sessionId:t._id,stream:o,onNoiseDetected:async()=>{var g,T;console.log("[processVad] - Replace track with Vad Controlled"),(g=this.context.logger)==null||g.log("[processVad] - Replace track with Vad Controlled"),await((T=t.connection.getSenders()[0])==null?void 0:T.replaceTrack(s.stream.getAudioTracks()[0]))},onNoiseStop:async()=>{const g=t.connection.getSenders()[0];g&&g.track&&g.transport&&g.transport.state!=="closed"&&g.transport.state!=="failed"&&(console.log("Replace track with Original"),await g.replaceTrack(o.getAudioTracks()[0]))}})}},onSpeechStart:()=>{var h;console.log("🎤 Speech started"),s.setSpeaking(!0),this.noiseReduction.mode==="enabled"&&((h=t.connection.getSenders()[0])==null||h.replaceTrack(s.stream.getAudioTracks()[0])),this.vadSessionsState[t._id].isSpeaking=!0},onSpeechEnd:()=>{var h;console.log("🛑 Speech end"),s.setSpeaking(!1),this.noiseReduction.mode==="enabled"&&((h=t.connection.getSenders()[0])==null||h.replaceTrack(s.stream.getAudioTracks()[0])),this.vadSessionsState[t._id].isSpeaking=!1}});this.vadSessions[t._id]&&(this.vadSessions[t._id].pause(),delete this.vadSessions[t._id]),this.vadSessions[t._id]=_,_.start()}stopSessionVad(t){this.vadSessions[t]&&(this.vadSessions[t].pause(),delete this.vadSessions[t]),this.vadIntervals[t]&&(clearInterval(this.vadIntervals[t]),delete this.vadIntervals[t]),this.vadMrsIntervals[t]&&(clearInterval(this.vadMrsIntervals[t]),delete this.vadMrsIntervals[t]),this.vadSessionsState[t]&&delete this.vadSessionsState[t]}async roomReconfigure(t){var a,s,r,_;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(d=>d.roomId===t),o=this.currentActiveRoomId===t;if(console.log("[roomReconfigure] - Calls In Room:",n),(a=this.context.logger)==null||a.log("[roomReconfigure] - Calls In Room:",n),n.forEach((d,h)=>{if(d.audioTag){d.connection.getReceivers().forEach(T=>{T.track.enabled=!d.localMuted}),o&&this.muteReconfigure(d);const g=!o;d.audioTag.muted=g,this.updateCall(d)}}),n.length===0){!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t),console.log("[roomReconfigure] - Delete empty room",t),(s=this.context.logger)==null||s.log("[roomReconfigure] - Delete empty room",t),this.deleteRoomIfEmpty(t);return}if(n.length===1&&!o){const d=n[0];d.isOnHold().local||await this.holdCall(d._id,!0),!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t);return}if(n.length===1&&o){const d=n[0];d.isOnHold().local&&d._automaticHold&&await this.unholdCall(d._id);const T=(((r=d.connection)==null?void 0:r.getSenders())||[])[0];if(d.connection&&T)try{await this.setupActiveStream();const E=this.activeStream;["enabled","dynamic"].includes(this.noiseReduction.mode)&&(console.log("[roomReconfigure] - Call processVAD from roomReconfigure"),(_=this.context.logger)==null||_.log("[roomReconfigure] - Call processVAD from roomReconfigure"),this.processVAD(n[0],E));const A=E.getTracks();await T.replaceTrack(A[0]),this.muteReconfigure(d)}catch(E){console.error(E)}!!this.conferenceNodes[t]&&await this.cleanupConferenceNodes(t);return}n.length>1&&await this.doConference(n)}async doConference(t){var h,g,T,S,E,A,R;if(console.log("[doConference] - In doConference, sessions:",t),(h=this.context.logger)==null||h.log("[doConference] - In doConference, sessions:",t),t.length===0)return;const n=t[0].roomId,o=this.currentActiveRoomId===n;if(t.find(C=>C.roomId!==n))return;let s;try{s=await this.managedAudioContext.getContext()}catch(C){console.error("[doConference] Failed to get AudioContext:",C),(g=this.context.logger)==null||g.error("[doConference] Failed to get AudioContext:",C);return}const r=s.state;if(r!=="running")if(console.error(`[doConference] ERROR: AudioContext is not running! State: ${r}`),(T=this.context.logger)==null||T.error(`[doConference] ERROR: AudioContext is not running! State: ${r}`),r==="suspended"||r==="interrupted")try{await s.resume();const C=s.state;if(C!=="running"){console.error(`[doConference] Failed to resume AudioContext, state: ${C}`),(S=this.context.logger)==null||S.error(`[doConference] Failed to resume AudioContext, state: ${C}`);return}}catch(C){console.error("[doConference] Error resuming AudioContext:",C),(E=this.context.logger)==null||E.error("[doConference] Error resuming AudioContext:",C);return}else if(r==="closed"){console.error("[doConference] AudioContext is closed, cannot proceed"),(A=this.context.logger)==null||A.error("[doConference] AudioContext is closed, cannot proceed");return}else return;await this.cleanupConferenceNodes(n),this.conferenceNodes[n]={sources:new Map,destinations:new Map,gains:new Map};const _=this.conferenceNodes[n],d=new Map;console.log("[doConference] - Before sessions forEach, sessions:",t),(R=this.context.logger)==null||R.log("[doConference] - Before sessions forEach, sessions:",t),t.forEach((C,$)=>{var k,re,x;if(console.log("[doConference] - In sessions forEach, iteration for",C._id),(k=this.context.logger)==null||k.log("[doConference] - In sessions forEach, iteration for",C._id),C&&C.connection){const F=C.connection.getReceivers();console.log("[doConference] - Receivers list length for",C._id,F.length),(re=this.context.logger)==null||re.log("[doConference] - Receivers list length for",C._id,F.length),F.forEach((_e,pe)=>{var q,j,K,V,z,D;_e.track.enabled=!C.localMuted;const P=(q=_e.track)==null?void 0:q.id;(j=_e.track)==null||j.readyState,(K=_e.track)==null||K.kind;const N=`${C._id}-${P}`;console.log("[doConference] - Gathering receiver tracks",C._id),console.log("[doConference] - Receiver track readyState",_e.track.readyState),(V=this.context.logger)==null||V.log("[doConference] - Gathering receiver tracks",C._id),(z=this.context.logger)==null||z.log("[doConference] - Receiver track readyState",_e.track.readyState),_e.track&&_e.track.readyState==="live"&&(console.log("[doConference] - Gathered receiver track",C._id),(D=this.context.logger)==null||D.log("[doConference] - Gathered receiver track",C._id),d.set(N,_e.track))})}else console.log("[doConference] - No session or RTC connection, session:",C),(x=this.context.logger)==null||x.log("[doConference] - No session or RTC connection, session:",C)}),await this.setupActiveStream(),await gv.forEach(t,async(C,$)=>{var N,q,j,K,V,z;if(!C||!C.connection){console.log("[doConference] - Return because of no session or connection, session:",C),(N=this.context.logger)==null||N.log("[doConference] - Return because of no session or connection, session:",C);return}const k=s.createMediaStreamDestination();_.destinations.set(C._id,k);let re=0;const x=C.connection.getReceivers(),F=x.length>0;if(console.log(`[doConference] Session ${C._id} has ${x.length} receivers`),(q=this.context.logger)==null||q.log(`[doConference] Session ${C._id} has ${x.length} receivers`),F||(console.warn(`[doConference] Session ${C._id} has no receivers yet. Will re-configure when track arrives.`),(j=this.context.logger)==null||j.warn(`[doConference] Session ${C._id} has no receivers yet. Will re-configure when track arrives.`)),d.forEach((D,U)=>{var X,He,Q;if(console.log("[doConference] - In forEach receiverTracks for",C._id),(X=this.context.logger)==null||X.log("[doConference] - In forEach receiverTracks for",C._id),!U.startsWith(C._id)){if(!D||D.readyState!=="live"){console.warn(`[doConference] Skipping invalid track ${(D==null?void 0:D.id)||"unknown"} for session ${C._id}`),(He=this.context.logger)==null||He.warn(`[doConference] Skipping invalid track ${(D==null?void 0:D.id)||"unknown"} for session ${C._id}`);return}try{const W=s.createMediaStreamSource(new MediaStream([D])),B=s.createGain(),ie=`${C._id}-${U}`;W.connect(B),B.connect(k),console.log("[doConference] - In forEach connect track for",C._id),(Q=this.context.logger)==null||Q.log("[doConference] - In forEach connect track for",C._id),_.sources.set(ie,W),_.gains.set(ie,B),re++}catch(W){console.error(W)}}}),o&&this.activeStreamValue)try{const D=this.activeStream,U=s.createMediaStreamSource(D),X=s.createGain(),He=`${C._id}-local`;U.connect(X),X.connect(k),_.sources.set(He,U),_.gains.set(He,X)}catch(D){console.error(D)}else o&&(console.error(`Host room but no activeStreamValue - skipping host microphone for session ${C._id}`),(K=this.context.logger)==null||K.error(`Host room but no activeStreamValue - skipping host microphone for session ${C._id}`));const pe=C.connection.getSenders()[0],P=k.stream.getTracks();if(["enabled","dynamic"].includes(this.noiseReduction.mode)&&(console.log("[doConference] - Call processVAD from doConference"),(V=this.context.logger)==null||V.log("[doConference] - Call processVAD from doConference"),this.processVAD(C,k.stream)),pe&&P[0])try{console.log("[doConference] - Final replaceTrack for",C._id),(z=this.context.logger)==null||z.log("[doConference] - Final replaceTrack for",C._id),await pe.replaceTrack(P[0]),this.muteReconfigure(C)}catch(D){console.error(D)}})}processCallerMute(t,n){const o=this.extendedCalls[t];o&&o.connection.getReceivers().length&&(o.localMuted=n,o.connection.getReceivers().forEach(a=>{a.track.enabled=!n}),this.updateCall(o))}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()}handleSipResponseForRingback(t,n){var s,r,_,d,h;let o=null;if(this.extendedCalls[t])o=t;else{const g=Object.values(this.extendedCalls).find(T=>T.id===t||T._id===t||T.id&&T.id.includes(t)||T._id&&T._id.includes(t));g&&(o=g.id)}if(!o){(s=this.context.logger)==null||s.warn(`[handleSipResponseForRingback] Could not find session for identifier ${t}, status ${n}`);return}const a=this.extendedCalls[o];if(!a){(r=this.context.logger)==null||r.warn(`[handleSipResponseForRingback] Call not found in extendedCalls for ${o}`);return}if(a.direction==="outgoing"){if(n===ho.TRYING||n===ho.RINGING){if(this.ringbackTimers[o])return;this.ringbackSessionProgressReceived[o]=!1,this.ringbackTimers[o]=setTimeout(()=>{var g;this.ringbackSessionProgressReceived[o]||(this.startLocalRingbackTone(o),(g=this.context.logger)==null||g.log(`[handleSipResponseForRingback] Started local ringback tone for call ${o} after 2 seconds without 183`)),delete this.ringbackTimers[o]},2e3),(_=this.context.logger)==null||_.log(`[handleSipResponseForRingback] Started 2-second timer for call ${o} after receiving ${n}`)}n===ho.SESSION_PROGRESS&&(this.ringbackSessionProgressReceived[o]=!0,this.ringbackTimers[o]&&(clearTimeout(this.ringbackTimers[o]),delete this.ringbackTimers[o],(d=this.context.logger)==null||d.log(`[handleSipResponseForRingback] Cancelled ringback timer for call ${o} - 183 received`)),this.stopLocalRingbackTone(o),(h=this.context.logger)==null||h.log(`[handleSipResponseForRingback] Stopped local ringback tone for call ${o} - 183 received with SDP`))}}async startLocalRingbackTone(t){var n,o;if(!this.ringbackAudioContexts[t])try{const a=await this.managedAudioContext.getContext(),s=a.createOscillator(),r=a.createOscillator(),_=a.createGain();s.frequency.value=440,r.frequency.value=480,s.type="sine",r.type="sine",_.gain.value=0,s.connect(_),r.connect(_),_.connect(a.destination),s.start(),r.start();const d={context:a,oscillator1:s,oscillator2:r,gainNode:_,intervalId:null};this.ringbackAudioContexts[t]=d;const h=()=>{if(!this.ringbackAudioContexts[t])return;const T=a.currentTime;_.gain.cancelScheduledValues(T),_.gain.setValueAtTime(0,T),_.gain.linearRampToValueAtTime(.3,T+.05),_.gain.linearRampToValueAtTime(0,T+1)};h();const g=setInterval(()=>{if(!this.ringbackAudioContexts[t]){clearInterval(g);return}h()},4e3);d.intervalId=g,this.ringbackAudioContexts[t]=d,(n=this.context.logger)==null||n.log(`[startLocalRingbackTone] Started ringback tone for session ${t}`)}catch(a){(o=this.context.logger)==null||o.error(`[startLocalRingbackTone] Error starting ringback tone for session ${t}:`,a),console.error(`[startLocalRingbackTone] Error starting ringback tone for session ${t}:`,a)}}stopLocalRingbackTone(t){var o,a;const n=this.ringbackAudioContexts[t];if(n)try{n.intervalId&&clearInterval(n.intervalId),n.oscillator1&&n.oscillator1.stop(),n.oscillator2&&n.oscillator2.stop(),n.gainNode&&n.gainNode.disconnect(),delete this.ringbackAudioContexts[t],(o=this.context.logger)==null||o.log(`[stopLocalRingbackTone] Stopped ringback tone for session ${t}`)}catch(s){(a=this.context.logger)==null||a.error(`[stopLocalRingbackTone] Error stopping ringback tone for session ${t}:`,s),console.error(`[stopLocalRingbackTone] Error stopping ringback tone for session ${t}:`,s),delete this.ringbackAudioContexts[t]}}cleanupRingbackTone(t){this.ringbackTimers[t]&&(clearTimeout(this.ringbackTimers[t]),delete this.ringbackTimers[t]),this.stopLocalRingbackTone(t),delete this.ringbackSessionProgressReceived[t]}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const o=this.extendedCalls[t];if(!o._is_confirmed&&!o._is_canceled){const a=`sip:${n}@${this.context.sipDomain}`;o.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${a}`]});return}this.updateCallStatus({callId:t,isTransferring:!0,isTransferred:!1}),o.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(o)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const o=n[0],a=n[1];!o||!a||(this.updateCallStatus({callId:o._id,isMerging:!0}),this.updateCallStatus({callId:a._id,isMerging:!0}),o.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(o))}mergeCallByIds(t,n){const o=Object.values(this.extendedCalls).find(s=>s._id===t),a=Object.values(this.extendedCalls).find(s=>s._id===n);if(!o||!a)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),o.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(o)}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 o=setInterval(()=>{const a={...this.callTime[t]},s=dv(a);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,o)}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 h,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const a=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:a};if(n.direction==="incoming")this.context.logger.log("New incoming call from",(g=(h=n._remote_identity)==null?void 0:h._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:a}),this.startCallTimer(n.id))}),this.context.subscribe(Xt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:a}),this.deleteRoomIfEmpty(a))});else if(n.direction==="outgoing"){const T=S=>{var C,$,k,re,x,F,_e,pe,P;const E=!!((C=S==null?void 0:S.response)!=null&&C.body),A=(k=($=S==null?void 0:S.response)==null?void 0:$.getHeader)==null?void 0:k.call($,"Content-Type"),R=(x=(re=S==null?void 0:S.response)==null?void 0:re.getHeader)==null?void 0:x.call(re,"Content-Length");console.log("PPP SDP Check:",{hasBody:E,contentType:A,contentLength:R,bodyLength:((_e=(F=S==null?void 0:S.response)==null?void 0:F.body)==null?void 0:_e.length)||0,bodyPreview:((P=(pe=S==null?void 0:S.response)==null?void 0:pe.body)==null?void 0:P.substring(0,100))||"N/A"}),S.response&&S.response.status_code===ho.SESSION_PROGRESS&&(this.startCallTimer(n.id),n.off("progress",T))};n.on("progress",T),n.once("confirmed",()=>{this.startCallTimer(n.id)})}const r=n,_=this.hasAutoAnswerHeaders(t),d=r.direction==="incoming"&&!this.hasActiveCalls&&(_||this.autoAnswer);r.roomId=a,r.localMuted=!1,r.autoAnswer=d,d?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),d&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const o={...this.extendedCalls};delete o[t],this.extendedCalls={...o},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){const n=this.extendedCalls[t._id];if(!n)return;this.stopVUMeter("origin"),this.stopVUMeter(t._id);const o=n.roomId;this.removeCall(t._id),this.roomReconfigure(o).then(()=>{}).catch(a=>{console.error("Error reconfiguring room after call removal:",a)})}shouldTerminateNewSession(t){if(t.session.direction==="outgoing")return!1;const o=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||o}async newRTCSessionCallback(t){const n=t.session;if(this.shouldTerminateNewSession(t)){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}this.context.triggerListener({listenerType:Xt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var r,_,d;if(this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(_=(r=n._remote_identity)==null?void 0:r._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:n,event:a}),n.connection){const h=n.connection.connectionState;(h==="closed"||h==="disconnected")&&this.context.emit("connectionStateChange",{session:n,connectionState:h})}["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(n._id),this.cleanupRingbackTone(n.id);const s=this.getActiveCalls[n.id];s&&this.activeCallListRemove(s),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 s,r;this.context.logger.log("Session in progress for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var r,_,d;if(this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(_=(r=n._remote_identity)==null?void 0:r._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:n,event:a}),n.connection){const h=n.connection.connectionState;(h==="closed"||h==="disconnected")&&this.context.emit("connectionStateChange",{session:n,connectionState:h})}["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(n._id),this.cleanupRingbackTone(n.id),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const s=this.getActiveCalls[n.id];s&&this.activeCallListRemove(s),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 s,r;this.context.logger.log("Session confirmed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),this.cleanupRingbackTone(n.id),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)});const o=a=>{a&&a.addEventListener("connectionstatechange",s=>{this.context.emit("connectionStateChange",{session:n,connectionState:a.connectionState})})};if(n.connection&&o(n.connection),n.on("peerconnection",({peerconnection:a})=>{o(a)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;await 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(po.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(po.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 oS(this.metricConfig),o=n.createProbe(t.connection,{cid:t._id}),a=[];let s;o.onreport=r=>{Object.entries(r.audio).forEach(([h,g])=>{g.direction==="inbound"&&!a.includes(h)&&(a.push(h),s=h)});const _=r.audio[s];if(!_)return;const d=aS(_,uS);d.callId=t._id,this.setCallMetrics(d)},this.context.subscribe(Xt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}async setupVUMeter(t,n){await this.VUMeter.start(await this.managedAudioContext.getContext(),t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){try{const t=Date.now(),n=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach((a,s)=>{a.stop()}),this.initialStreamValue=null),this.initialStreamValue=n}catch(t){throw t}}async triggerAddStream(t,n){var S,E;console.log(`[triggerAddStream] - For ${n._id}`),(S=this.context.logger)==null||S.log(`[triggerAddStream] - For ${n._id}`);const o=this.muteWhenJoin||this.isMuted;this.setIsMuted(o),this.initialStreamValue||await this.setupStream();const a=await this.managedAudioContext.getContext(),s=await iu(a,this.initialStreamValue,this.microphoneInputLevel*2),r=this.isMuted||this.muteWhenJoin;s.getTracks().forEach(A=>{A.enabled=!r}),await this.setActiveStream(s),await n.connection.getSenders()[0].replaceTrack(s.getTracks()[0]);const h=new MediaStream([t.track]);!Object.values(this.extendedCalls).find(A=>A.audioTag&&A.audioTag.id===n._id)&&zT(h,n,this.selectedOutputDevice,this.speakerVolume);const T=n.roomId===this.currentActiveRoomId;n.audioTag&&(n.audioTag.muted=!T),await this.setupVUMeter(h,n._id),this.getCallQuality(n),this.updateCall(n),n.roomId!==void 0&&Object.values(this.extendedCalls).filter(R=>R.roomId===n.roomId).length>1&&(console.log(`[triggerAddStream] Re-configuring conference for room ${n.roomId} - track received for call ${n._id}`),(E=this.context.logger)==null||E.log(`[triggerAddStream] Re-configuring conference for room ${n.roomId} - track received for call ${n._id}`),setTimeout(()=>{this.roomReconfigure(n.roomId)},100)),["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(n,s)}initCall(t,n,o=!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 a=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=a.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:a.id,roomId:this.currentActiveRoomId}),o)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==a.id);for(const r of s)this.holdCall(r._id,!0)}a.connection.addEventListener("track",s=>{this.triggerAddStream(s,a)})}async processRoomChange({callId:t,roomId:n}){const o=this.extendedCalls[t];if(!o)return;const a=o.roomId;o.roomId=n,this.updateCall(o),await this.roomReconfigure(a),await this.roomReconfigure(n)}}class pS{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 mS{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this))}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 o=this.msrpHistory[n.id]||[];o.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...o]},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 o=t;this.addMMSRPSession(o)}triggerMSRPListener({listenerType:t,session:n,event:o}){const a=this.context.listenersList[t];!a||!a.length||a.forEach(s=>{s(n,o)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const o={...this.extendedMessages};delete o[t],this.extendedMessages={...o},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){t.session._id||(t.session._id=t.request.call_id+t.request.from._parameters.tag);const n=t.session;n.on("ended",o=>{this.triggerMSRPListener({listenerType:Xt.CALL_ENDED,session:n,event:o});const a=this.getActiveMessages[n.id];this.activeMessageListRemove(a)}),n.on("failed",o=>{this.triggerMSRPListener({listenerType:Xt.CALL_FAILED,session:n,event:o});const a=this.getActiveMessages[n.id];this.activeMessageListRemove(a)}),n.on("confirmed",o=>{this.triggerMSRPListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:o}),this.updateMSRPSession(n)}),n.on("newMessage",o=>{this.addMSRPMessage(o,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,o){if(t.length===0)return console.error("Target must be a valid string");const a=this.context.startMSRP(t,o);a.on("active",()=>{this.addMessageSession(a),a.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const o=this.extendedMessages[t];if(!o)throw new Error(`MSRP session with id ${t} doesn't exist!`);o.sendMSRP(n)}}const mo={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class Pd{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 Md extends Pd{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=Pe.cloneArray(t.extraHeaders),o={from_tag:this.session._from_tag};t.fromUserName&&(o.from_uri=new Rn("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(o.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,o,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 tl(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 o={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},a=JSON.stringify(o);this._request.body=a,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const o={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},a=[this.session.getPTypeHeader(Ut.PUBLISHER)];this.session.sendRequest(H.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(o),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)||{};((_=(r=g.plugindata)==null?void 0:r.data)==null?void 0:_.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(h=(d=g.plugindata)==null?void 0:d.data)!=null&&h.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})),a={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(Ut.ICE)];this.session.sendRequest(H.INFO,{extraHeaders:s,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const d=r.data.split(`\r
|
|
159
|
+
`),h=d[d.length-1],g=JSON.parse(h);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(Ut.DETACH)];this.session.sendRequest(H.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 o=n.track;o&&o.stop()}),t.forEach(n=>{this._connection.removeTrack(n)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class Ld extends Pd{constructor(t,n,o={}){super(t),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=o.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 gS extends qT{constructor(t,n){if(!t.modules.length)throw new Error("options.modules should include at least 1 module");const o={...t.configuration,sockets:t.socketInterfaces.map(a=>new fv.WebSocketInterface(a))};super(o),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.reconnectionAttemptsLimit=1/0,this.reconnectionAttemptsCounter=0,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,t.configuration.reconnectionAttemptsLimit&&(this.reconnectionAttemptsLimit=t.configuration.reconnectionAttemptsLimit),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&&this.reconnect()}get hasActiveSessions(){return this.modules.includes(mo.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 Md)t.setOpensips(this),this.newStreamPlugins.push(t);else if(t instanceof Ld)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)}reconnect(){if(this.reconnectionAttemptsCounter<this.reconnectionAttemptsLimit){const n=5e3*Math.pow(2,this.reconnectionAttemptsCounter);this.reconnectionAttemptsCounter++,setTimeout(this.start.bind(this),n)}else this.emit("reconnectionAttemptsLimitReached",void 0)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(mo.AUDIO)&&(this.audio=new _S(this)),this.modules.includes(mo.MSRP)&&(this.msrp=new mS(this)),this.modules.includes(mo.VIDEO)&&(this.video=new pS(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.reconnectionAttemptsCounter=0}),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&&this.reconnect()},12e5)):(this.stop(),this.setInitialized(!1),this.activeConnection&&this.reconnect()))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(t,n){const a=!this.listenersList[t]||!this.listenersList[t].length?[n]:[...this.listenersList[t],n];this.listenersList={...this.listenersList,[t]:a}}removeIListener(t){const n={...this.listenersList};delete n[t],this.listenersList={...n}}triggerListener({listenerType:t,session:n,event:o}){const a=this.listenersList[t];!a||!a.length||a.forEach(s=>{s(n,o)})}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=Md;exports.BaseProcessStreamPlugin=Ld;exports.default=gS;
|