opensips-js-vue 0.1.8 → 0.1.10

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.
@@ -1,160 +1,160 @@
1
- (function(et,ve){typeof exports=="object"&&typeof module!="undefined"?ve(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],ve):(et=typeof globalThis!="undefined"?globalThis:et||self,ve(et["vsip-next"]={},et.Vue))})(this,function(et,ve){"use strict";var Qy=Object.defineProperty,Jy=Object.defineProperties;var Zy=Object.getOwnPropertyDescriptors;var T_=Object.getOwnPropertySymbols;var eE=Object.prototype.hasOwnProperty,tE=Object.prototype.propertyIsEnumerable;var v_=(et,ve,mt)=>ve in et?Qy(et,ve,{enumerable:!0,configurable:!0,writable:!0,value:mt}):et[ve]=mt,oe=(et,ve)=>{for(var mt in ve||(ve={}))eE.call(ve,mt)&&v_(et,mt,ve[mt]);if(T_)for(var mt of T_(ve))tE.call(ve,mt)&&v_(et,mt,ve[mt]);return et},ot=(et,ve)=>Jy(et,Zy(ve));var re=(et,ve,mt)=>new Promise((jl,jt)=>{var $l=gn=>{try{er(mt.next(gn))}catch(tr){jt(tr)}},$e=gn=>{try{er(mt.throw(gn))}catch(tr){jt(tr)}},er=gn=>gn.done?jl(gn.value):Promise.resolve(gn.value).then($l,$e);er((mt=mt.apply(et,ve)).next())});var mt=Object.defineProperty,jl=(l,s,n)=>s in l?mt(l,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):l[s]=n,jt=(l,s,n)=>(jl(l,typeof s!="symbol"?s+"":s,n),n),$l=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $e(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}const er="jssip",gn="JsSIP",tr="the Javascript SIP library",S_="3.10.0",A_="https://jssip.net",C_=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],b_="lib/JsSIP.d.ts",R_="lib-es5/JsSIP.js",I_=["sip","websocket","webrtc","node","browser","library"],w_="MIT",O_={type:"git",url:"https://github.com/versatica/JsSIP.git"},N_={url:"https://github.com/versatica/JsSIP/issues"},D_={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},k_={"@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"},U_={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Oo={name:er,title:gn,description:tr,version:S_,homepage:A_,contributors:C_,types:b_,main:R_,keywords:I_,license:w_,repository:O_,bugs:N_,dependencies:D_,devDependencies:k_,scripts:U_};var fc=Oo,lt={USER_AGENT:"".concat(fc.title," ").concat(fc.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 No(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?No=function(s){return typeof s}:No=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},No(l)}function Do(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function ko(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&nr(l,s)}function Uo(l){var s=pc();return function(){var n=sr(l),i;if(s){var a=sr(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return M_(this,i)}}function M_(l,s){return s&&(No(s)==="object"||typeof s=="function")?s:x_(l)}function x_(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function qs(l){var s=typeof Map=="function"?new Map:void 0;return qs=function(n){if(n===null||!P_(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof s<"u"){if(s.has(n))return s.get(n);s.set(n,i)}function i(){return Mo(n,arguments,sr(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),nr(i,n)},qs(l)}function Mo(l,s,n){return pc()?Mo=Reflect.construct:Mo=function(i,a,e){var d=[null];d.push.apply(d,a);var _=Function.bind.apply(i,d),u=new _;return e&&nr(u,e.prototype),u},Mo.apply(null,arguments)}function pc(){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(l){return!1}}function P_(l){return Function.toString.call(l).indexOf("[native code]")!==-1}function nr(l,s){return nr=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},nr(l,s)}function sr(l){return sr=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},sr(l)}var L_=function(l){ko(n,l);var s=Uo(n);function n(i,a){var e;return Do(this,n),e=s.call(this),e.code=1,e.name="CONFIGURATION_ERROR",e.parameter=i,e.value=a,e.message=e.value?"Invalid value ".concat(JSON.stringify(e.value),' for parameter "').concat(e.parameter,'"'):"Missing parameter: ".concat(e.parameter),e}return n}(qs(Error)),H_=function(l){ko(n,l);var s=Uo(n);function n(i){var a;return Do(this,n),a=s.call(this),a.code=2,a.name="INVALID_STATE_ERROR",a.status=i,a.message="Invalid status: ".concat(i),a}return n}(qs(Error)),q_=function(l){ko(n,l);var s=Uo(n);function n(i){var a;return Do(this,n),a=s.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=i,a}return n}(qs(Error)),F_=function(l){ko(n,l);var s=Uo(n);function n(i){var a;return Do(this,n),a=s.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=i,a}return n}(qs(Error)),Kn={ConfigurationError:L_,InvalidStateError:H_,NotSupportedError:q_,NotReadyError:F_},tt={},Vl,mc;function Bl(){if(mc)return Vl;mc=1;function l(e,d){if(!(e instanceof d))throw new TypeError("Cannot call a class as a function")}function s(e,d){for(var _=0;_<d.length;_++){var u=d[_];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(e,u.key,u)}}function n(e,d,_){return d&&s(e.prototype,d),_&&s(e,_),e}var i=Gn(),a=dn();return Vl=function(){n(e,null,[{key:"parse",value:function(d){if(d=a.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function e(d,_,u){if(l(this,e),!d||!(d instanceof i))throw new TypeError('missing or invalid "uri" parameter');this._uri=d,this._parameters={},this.display_name=_;for(var g in u)Object.prototype.hasOwnProperty.call(u,g)&&this.setParam(g,u[g])}return n(e,[{key:"setParam",value:function(d,_){d&&(this._parameters[d.toLowerCase()]=typeof _>"u"||_===null?null:_.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var _=this._parameters[d];return delete this._parameters[d],_}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new e(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var _ in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,_)&&(d+=";".concat(_),this._parameters[_]!==null&&(d+="=".concat(this._parameters[_])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),e}(),Vl}var gc,Tc;function dn(){return Tc||(Tc=1,gc=function(){function l(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 s={parse:function(n,i){var a={CRLF:g,DIGIT:p,ALPHA:T,HEXDIG:y,WSP:A,OCTET:w,DQUOTE:R,SP:b,HTAB:G,alphanum:P,reserved:ye,unreserved:O,mark:j,escaped:pe,LWS:Te,SWS:N,HCOLON:H,TEXT_UTF8_TRIM:$,TEXT_UTF8char:q,UTF8_NONASCII:M,UTF8_CONT:W,LHEX:te,token:I,token_nodot:J,separators:ne,word:Ye,STAR:ee,SLASH:V,EQUAL:k,LPAREN:Ae,RPAREN:me,RAQUOT:Ie,LAQUOT:xe,COMMA:_e,SEMI:le,COLON:ze,LDQUOT:rt,RDQUOT:Ee,comment:ge,ctext:Re,quoted_string:we,quoted_string_clean:Ue,qdtext:fe,quoted_pair:ae,SIP_URI_noparams:Se,SIP_URI:De,uri_scheme:Ke,uri_scheme_sips:ct,uri_scheme_sip:He,userinfo:Ft,user:Ut,user_unreserved:ps,password:Vr,hostport:Nn,host:nn,hostname:ms,domainlabel:gs,toplabel:Br,IPv6reference:Ts,IPv6address:vs,h16:x,ls32:qe,IPv4address:sn,dec_octet:rn,port:Kr,uri_parameters:Gr,uri_parameter:ys,transport_param:Wr,user_param:Yr,method_param:zr,ttl_param:Xr,maddr_param:Qr,lr_param:Jr,other_param:Zr,pname:ei,pvalue:ti,paramchar:on,param_unreserved:ni,headers:si,header:Dn,hname:ri,hvalue:ii,hnv_unreserved:ln,Request_Response:Ou,Request_Line:oi,Request_URI:li,absoluteURI:Es,hier_part:ai,net_path:ui,abs_path:kn,opaque_part:ci,uric:an,uric_no_slash:hi,path_segments:di,segment:Un,param:Ss,pchar:un,scheme:_i,authority:fi,srvr:pi,reg_name:mi,query:gi,SIP_Version:As,INVITEm:Ti,ACKm:vi,OPTIONSm:yi,BYEm:Ei,CANCELm:Si,REGISTERm:Ai,SUBSCRIBEm:Ci,NOTIFYm:bi,REFERm:Ri,Method:Mn,Status_Line:Ii,Status_Code:wi,extension_code:Oi,Reason_Phrase:Ni,Allow_Events:Nu,Call_ID:Du,Contact:ku,contact_param:xn,name_addr:Mt,display_name:Pn,contact_params:Cs,c_p_q:Di,c_p_expires:ki,delta_seconds:xt,qvalue:Ui,generic_param:Oe,gen_value:Mi,Content_Disposition:Uu,disp_type:xi,disp_param:bs,handling_param:Pi,Content_Encoding:Mu,Content_Length:xu,Content_Type:Pu,media_type:Li,m_type:Hi,discrete_type:qi,composite_type:Fi,extension_token:Ln,x_token:ji,m_subtype:$i,m_parameter:Rs,m_value:Vi,CSeq:Lu,CSeq_value:Bi,Expires:Hu,Event:qu,event_type:cn,From:Fu,from_param:Is,tag_param:ws,Max_Forwards:ju,Min_Expires:$u,Name_Addr_Header:Vu,Proxy_Authenticate:Bu,challenge:Os,other_challenge:Ki,auth_param:hn,digest_cln:Hn,realm:Gi,realm_value:Wi,domain:Yi,URI:qn,nonce:zi,nonce_value:Xi,opaque:Qi,stale:Ji,algorithm:Zi,qop_options:eo,qop_value:Fn,Proxy_Require:Ku,Record_Route:Gu,rec_route:jn,Reason:Wu,reason_param:Ns,reason_cause:to,Require:Yu,Route:zu,route_param:$n,Subscription_State:Xu,substate_value:no,subexp_params:Ds,event_reason_value:so,Subject:Qu,Supported:Ju,To:Zu,to_param:ks,Via:ec,via_param:Vn,via_params:Us,via_ttl:ro,via_maddr:io,via_received:oo,via_branch:lo,response_port:ao,rport:uo,sent_protocol:co,protocol_name:ho,transport:_o,sent_by:fo,via_host:po,via_port:mo,ttl:Ms,WWW_Authenticate:tc,Session_Expires:nc,s_e_expires:go,s_e_params:xs,s_e_refresher:To,extension_header:sc,header_value:vo,message_body:rc,uuid_URI:ic,uuid:yo,hex4:dt,hex8:Eo,hex12:So,Refer_To:oc,Replaces:lc,call_id:Ao,replaces_param:Ps,to_tag:Co,from_tag:bo,early_flag:Ro};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+l(i)+".")}else i="CRLF";var e=0,d=0,_=[];function u(t){e<d||(e>d&&(d=e,_=[]),_.push(t))}function g(){var t;return n.substr(e,2)===`\r
1
+ (function(dn,Ce){typeof exports=="object"&&typeof module<"u"?Ce(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],Ce):(dn=typeof globalThis<"u"?globalThis:dn||self,Ce(dn["vsip-next"]={},dn.Vue))})(this,function(dn,Ce){"use strict";var h_=Object.defineProperty,d_=(l,n,s)=>n in l?h_(l,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[n]=s,on=(l,n,s)=>(d_(l,typeof n!="symbol"?n+"":n,s),s),__=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function We(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}const p_="jssip",f_="JsSIP",m_="the Javascript SIP library",g_="3.10.0",T_="https://jssip.net",v_=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],y_="lib/JsSIP.d.ts",E_="lib-es5/JsSIP.js",S_=["sip","websocket","webrtc","node","browser","library"],A_="MIT",C_={type:"git",url:"https://github.com/versatica/JsSIP.git"},b_={url:"https://github.com/versatica/JsSIP/issues"},R_={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},I_={"@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"},w_={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},So={name:p_,title:f_,description:m_,version:g_,homepage:T_,contributors:v_,types:y_,main:E_,keywords:S_,license:A_,repository:C_,bugs:b_,dependencies:R_,devDependencies:I_,scripts:w_};var oc=So,nt={USER_AGENT:"".concat(oc.title," ").concat(oc.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 Ao(l){"@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(l)}function Co(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function bo(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&zs(l,n)}function Ro(l){var n=lc();return function(){var s=Js(l),i;if(n){var a=Js(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return O_(this,i)}}function O_(l,n){return n&&(Ao(n)==="object"||typeof n=="function")?n:N_(l)}function N_(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Ms(l){var n=typeof Map=="function"?new Map:void 0;return Ms=function(s){if(s===null||!D_(s))return s;if(typeof s!="function")throw new TypeError("Super expression must either be null or a function");if(typeof n<"u"){if(n.has(s))return n.get(s);n.set(s,i)}function i(){return Io(s,arguments,Js(this).constructor)}return i.prototype=Object.create(s.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),zs(i,s)},Ms(l)}function Io(l,n,s){return lc()?Io=Reflect.construct:Io=function(i,a,e){var d=[null];d.push.apply(d,a);var _=Function.bind.apply(i,d),u=new _;return e&&zs(u,e.prototype),u},Io.apply(null,arguments)}function lc(){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 D_(l){return Function.toString.call(l).indexOf("[native code]")!==-1}function zs(l,n){return zs=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},zs(l,n)}function Js(l){return Js=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Js(l)}var k_=function(l){bo(s,l);var n=Ro(s);function s(i,a){var e;return Co(this,s),e=n.call(this),e.code=1,e.name="CONFIGURATION_ERROR",e.parameter=i,e.value=a,e.message=e.value?"Invalid value ".concat(JSON.stringify(e.value),' for parameter "').concat(e.parameter,'"'):"Missing parameter: ".concat(e.parameter),e}return s}(Ms(Error)),U_=function(l){bo(s,l);var n=Ro(s);function s(i){var a;return Co(this,s),a=n.call(this),a.code=2,a.name="INVALID_STATE_ERROR",a.status=i,a.message="Invalid status: ".concat(i),a}return s}(Ms(Error)),M_=function(l){bo(s,l);var n=Ro(s);function s(i){var a;return Co(this,s),a=n.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=i,a}return s}(Ms(Error)),P_=function(l){bo(s,l);var n=Ro(s);function s(i){var a;return Co(this,s),a=n.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=i,a}return s}(Ms(Error)),Fn={ConfigurationError:k_,InvalidStateError:U_,NotSupportedError:M_,NotReadyError:P_},Qe={},Ml,ac;function Pl(){if(ac)return Ml;ac=1;function l(e,d){if(!(e instanceof d))throw new TypeError("Cannot call a class as a function")}function n(e,d){for(var _=0;_<d.length;_++){var u=d[_];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(e,u.key,u)}}function s(e,d,_){return d&&n(e.prototype,d),_&&n(e,_),e}var i=jn(),a=ln();return Ml=function(){s(e,null,[{key:"parse",value:function(d){if(d=a.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function e(d,_,u){if(l(this,e),!d||!(d instanceof i))throw new TypeError('missing or invalid "uri" parameter');this._uri=d,this._parameters={},this.display_name=_;for(var g in u)Object.prototype.hasOwnProperty.call(u,g)&&this.setParam(g,u[g])}return s(e,[{key:"setParam",value:function(d,_){d&&(this._parameters[d.toLowerCase()]=typeof _>"u"||_===null?null:_.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var _=this._parameters[d];return delete this._parameters[d],_}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new e(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var _ in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,_)&&(d+=";".concat(_),this._parameters[_]!==null&&(d+="=".concat(this._parameters[_])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),e}(),Ml}var uc,cc;function ln(){return cc||(cc=1,uc=function(){function l(s){return'"'+s.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 n={parse:function(s,i){var a={CRLF:g,DIGIT:f,ALPHA:T,HEXDIG:y,WSP:A,OCTET:w,DQUOTE:b,SP:R,HTAB:G,alphanum:x,reserved:me,unreserved:O,mark:$,escaped:de,LWS:fe,SWS:N,HCOLON:H,TEXT_UTF8_TRIM:j,TEXT_UTF8char:F,UTF8_NONASCII:P,UTF8_CONT:W,LHEX:ee,token:I,token_nodot:X,separators:te,word:Ke,STAR:Q,SLASH:V,EQUAL:k,LPAREN:ve,RPAREN:_e,RAQUOT:Ae,LAQUOT:Ue,COMMA:ce,SEMI:re,COLON:Ge,LDQUOT:tt,RDQUOT:ge,comment:pe,ctext:Se,quoted_string:be,quoted_string_clean:De,qdtext:he,quoted_pair:ie,SIP_URI_noparams:Te,SIP_URI:we,uri_scheme:$e,uri_scheme_sips:it,uri_scheme_sip:xe,userinfo:Pt,user:wt,user_unreserved:cs,password:xr,hostport:bn,host:Jt,hostname:hs,domainlabel:ds,toplabel:Lr,IPv6reference:_s,IPv6address:ps,h16:M,ls32:Le,IPv4address:Xt,dec_octet:Qt,port:Hr,uri_parameters:qr,uri_parameter:fs,transport_param:Fr,user_param:jr,method_param:$r,ttl_param:Vr,maddr_param:Br,lr_param:Kr,other_param:Gr,pname:Wr,pvalue:Yr,paramchar:Zt,param_unreserved:zr,headers:Jr,header:Rn,hname:Xr,hvalue:Qr,hnv_unreserved:en,Request_Response:Eu,Request_Line:Zr,Request_URI:ei,absoluteURI:ms,hier_part:ti,net_path:ni,abs_path:In,opaque_part:si,uric:tn,uric_no_slash:ri,path_segments:ii,segment:wn,param:gs,pchar:nn,scheme:oi,authority:li,srvr:ai,reg_name:ui,query:ci,SIP_Version:Ts,INVITEm:hi,ACKm:di,OPTIONSm:_i,BYEm:pi,CANCELm:fi,REGISTERm:mi,SUBSCRIBEm:gi,NOTIFYm:Ti,REFERm:vi,Method:On,Status_Line:yi,Status_Code:Ei,extension_code:Si,Reason_Phrase:Ai,Allow_Events:Su,Call_ID:Au,Contact:Cu,contact_param:Nn,name_addr:Ot,display_name:Dn,contact_params:vs,c_p_q:Ci,c_p_expires:bi,delta_seconds:Nt,qvalue:Ri,generic_param:Re,gen_value:Ii,Content_Disposition:bu,disp_type:wi,disp_param:ys,handling_param:Oi,Content_Encoding:Ru,Content_Length:Iu,Content_Type:wu,media_type:Ni,m_type:Di,discrete_type:ki,composite_type:Ui,extension_token:kn,x_token:Mi,m_subtype:Pi,m_parameter:Es,m_value:xi,CSeq:Ou,CSeq_value:Li,Expires:Nu,Event:Du,event_type:sn,From:ku,from_param:Ss,tag_param:As,Max_Forwards:Uu,Min_Expires:Mu,Name_Addr_Header:Pu,Proxy_Authenticate:xu,challenge:Cs,other_challenge:Hi,auth_param:rn,digest_cln:Un,realm:qi,realm_value:Fi,domain:ji,URI:Mn,nonce:$i,nonce_value:Vi,opaque:Bi,stale:Ki,algorithm:Gi,qop_options:Wi,qop_value:Pn,Proxy_Require:Lu,Record_Route:Hu,rec_route:xn,Reason:qu,reason_param:bs,reason_cause:Yi,Require:Fu,Route:ju,route_param:Ln,Subscription_State:$u,substate_value:zi,subexp_params:Rs,event_reason_value:Ji,Subject:Vu,Supported:Bu,To:Ku,to_param:Is,Via:Gu,via_param:Hn,via_params:ws,via_ttl:Xi,via_maddr:Qi,via_received:Zi,via_branch:eo,response_port:to,rport:no,sent_protocol:so,protocol_name:ro,transport:io,sent_by:oo,via_host:lo,via_port:ao,ttl:Os,WWW_Authenticate:Wu,Session_Expires:Yu,s_e_expires:uo,s_e_params:Ns,s_e_refresher:co,extension_header:zu,header_value:ho,message_body:Ju,uuid_URI:Xu,uuid:_o,hex4:lt,hex8:po,hex12:fo,Refer_To:Qu,Replaces:Zu,call_id:mo,replaces_param:Ds,to_tag:go,from_tag:To,early_flag:vo};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+l(i)+".")}else i="CRLF";var e=0,d=0,_=[];function u(t){e<d||(e>d&&(d=e,_=[]),_.push(t))}function g(){var t;return s.substr(e,2)===`\r
2
2
  `?(t=`\r
3
- `,e+=2):(t=null,u('"\\r\\n"')),t}function p(){var t;return/^[0-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[0-9]")),t}function T(){var t;return/^[a-zA-Z]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-zA-Z]")),t}function y(){var t;return/^[0-9a-fA-F]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[0-9a-fA-F]")),t}function A(){var t;return t=b(),t===null&&(t=G()),t}function w(){var t;return/^[\0-\xFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function R(){var t;return/^["]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u('["]')),t}function b(){var t;return n.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function G(){var t;return n.charCodeAt(e)===9?(t=" ",e++):(t=null,u('"\\t"')),t}function P(){var t;return/^[a-zA-Z0-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-zA-Z0-9]")),t}function ye(){var t;return n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","'))))))))))),t}function O(){var t;return t=P(),t===null&&(t=j()),t}function j(){var t;return n.charCodeAt(e)===45?(t="-",e++):(t=null,u('"-"')),t===null&&(n.charCodeAt(e)===95?(t="_",e++):(t=null,u('"_"')),t===null&&(n.charCodeAt(e)===46?(t=".",e++):(t=null,u('"."')),t===null&&(n.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(n.charCodeAt(e)===126?(t="~",e++):(t=null,u('"~"')),t===null&&(n.charCodeAt(e)===42?(t="*",e++):(t=null,u('"*"')),t===null&&(n.charCodeAt(e)===39?(t="'",e++):(t=null,u(`"'"`)),t===null&&(n.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(n.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')))))))))),t}function pe(){var t,r,o,c,h;return c=e,h=e,n.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(o=y(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){return m.join("")}(c,t)),t===null&&(e=c),t}function Te(){var t,r,o,c,h,f;for(c=e,h=e,f=e,t=[],r=A();r!==null;)t.push(r),r=A();if(t!==null?(r=g(),r!==null?t=[t,r]:(t=null,e=f)):(t=null,e=f),t=t!==null?t:"",t!==null){if(o=A(),o!==null)for(r=[];o!==null;)r.push(o),o=A();else r=null;r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(m){return" "}()),t===null&&(e=c),t}function N(){var t;return t=Te(),t=t!==null?t:"",t}function H(){var t,r,o,c,h;for(c=e,h=e,t=[],r=b(),r===null&&(r=G());r!==null;)t.push(r),r=b(),r===null&&(r=G());return t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return":"}()),t===null&&(e=c),t}function $(){var t,r,o,c,h,f,m;if(h=e,f=e,r=q(),r!==null)for(t=[];r!==null;)t.push(r),r=q();else t=null;if(t!==null){for(r=[],m=e,o=[],c=Te();c!==null;)o.push(c),c=Te();for(o!==null?(c=q(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;){for(r.push(o),m=e,o=[],c=Te();c!==null;)o.push(c),c=Te();o!==null?(c=q(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m)}r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){return n.substring(e,E)}(h)),t===null&&(e=h),t}function q(){var t;return/^[!-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[!-~]")),t===null&&(t=M()),t}function M(){var t;return/^[\x80-\uFFFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\x80-\\uFFFF]")),t}function W(){var t;return/^[\x80-\xBF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\x80-\\xBF]")),t}function te(){var t;return t=p(),t===null&&(/^[a-f]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-f]"))),t}function I(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function J(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function ne(){var t;return n.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(n.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')),t===null&&(n.charCodeAt(e)===60?(t="<",e++):(t=null,u('"<"')),t===null&&(n.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t===null&&(t=R(),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===123?(t="{",e++):(t=null,u('"{"')),t===null&&(n.charCodeAt(e)===125?(t="}",e++):(t=null,u('"}"')),t===null&&(t=b(),t===null&&(t=G())))))))))))))))))),t}function Ye(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(n.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=R(),r===null&&(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(n.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(n.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(n.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(n.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"'))))))))))))))))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(n.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=R(),r===null&&(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(n.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(n.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(n.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(n.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"')))))))))))))))))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function ee(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"*"}()),t===null&&(e=c),t}function V(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"/"}()),t===null&&(e=c),t}function k(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"="}()),t===null&&(e=c),t}function Ae(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"("}()),t===null&&(e=c),t}function me(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return")"}()),t===null&&(e=c),t}function Ie(){var t,r,o,c;return o=e,c=e,n.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return">"}()),t===null&&(e=o),t}function xe(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return"<"}()),t===null&&(e=o),t}function _e(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return","}()),t===null&&(e=c),t}function le(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return";"}()),t===null&&(e=c),t}function ze(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return":"}()),t===null&&(e=c),t}function rt(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(r=R(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function Ee(){var t,r,o,c;return o=e,c=e,t=R(),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function ge(){var t,r,o,c;if(c=e,t=Ae(),t!==null){for(r=[],o=Re(),o===null&&(o=ae(),o===null&&(o=ge()));o!==null;)r.push(o),o=Re(),o===null&&(o=ae(),o===null&&(o=ge()));r!==null?(o=me(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)}else t=null,e=c;return t}function Re(){var t;return/^[!-']/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[!-']")),t===null&&(/^[*-[]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[*-[]")),t===null&&(/^[\]-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=M(),t===null&&(t=Te())))),t}function we(){var t,r,o,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=R(),r!==null){for(o=[],c=fe(),c===null&&(c=ae());c!==null;)o.push(c),c=fe(),c===null&&(c=ae());o!==null?(c=R(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m){return n.substring(e,m)}(h)),t===null&&(e=h),t}function Ue(){var t,r,o,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=R(),r!==null){for(o=[],c=fe(),c===null&&(c=ae());c!==null;)o.push(c),c=fe(),c===null&&(c=ae());o!==null?(c=R(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m){var E=n.substring(e,m).trim();return E.substring(1,E.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(h)),t===null&&(e=h),t}function fe(){var t;return t=Te(),t===null&&(n.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(/^[#-[]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[#-[]")),t===null&&(/^[\]-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=M())))),t}function ae(){var t,r,o;return o=e,n.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t!==null?(/^[\0-\t]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\0-\\t]")),r===null&&(/^[\x0B-\f]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\x0B-\\f]")),r===null&&(/^[\x0E-]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\x0E-]")))),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Se(){var t,r,o,c,h,f;return h=e,f=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Ft(),o=o!==null?o:"",o!==null?(c=Nn(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t!==null&&(t=function(m){try{v.uri=new Io(v.scheme,v.user,v.host,v.port),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port}catch(E){v=-1}}()),t===null&&(e=h),t}function De(){var t,r,o,c,h,f,m,E;return m=e,E=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Ft(),o=o!==null?o:"",o!==null?(c=Nn(),c!==null?(h=Gr(),h!==null?(f=si(),f=f!==null?f:"",f!==null?t=[t,r,o,c,h,f]:(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E),t!==null&&(t=function(C){try{v.uri=new Io(v.scheme,v.user,v.host,v.port,v.uri_params,v.uri_headers),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port,delete v.uri_params,i==="SIP_URI"&&(v=v.uri)}catch(z){v=-1}}()),t===null&&(e=m),t}function Ke(){var t;return t=ct(),t===null&&(t=He()),t}function ct(){var t,r;return r=e,n.substr(e,4).toLowerCase()==="sips"?(t=n.substr(e,4),e+=4):(t=null,u('"sips"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function He(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"sip"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Ft(){var t,r,o,c,h,f;return c=e,h=e,t=Ut(),t!==null?(f=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Vr(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?(n.charCodeAt(e)===64?(o="@",e++):(o=null,u('"@"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.user=decodeURIComponent(n.substring(e-1,m))}(c)),t===null&&(e=c),t}function Ut(){var t,r;if(r=O(),r===null&&(r=pe(),r===null&&(r=ps())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(r=ps()));else t=null;return t}function ps(){var t;return n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"'))))))))),t}function Vr(){var t,r,o;for(o=e,t=[],r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));return t!==null&&(t=function(c){v.password=n.substring(e,c)}(o)),t===null&&(e=o),t}function Nn(){var t,r,o,c,h;return c=e,t=nn(),t!==null?(h=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Kr(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function nn(){var t,r;return r=e,t=ms(),t===null&&(t=sn(),t===null&&(t=Ts())),t!==null&&(t=function(o){return v.host=n.substring(e,o).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function ms(){var t,r,o,c,h,f;for(c=e,h=e,t=[],f=e,r=gs(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f);r!==null;)t.push(r),f=e,r=gs(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f);return t!==null?(r=Br(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){return v.host_type="domain",n.substring(e,m)}(c)),t===null&&(e=c),t}function gs(){var t,r,o,c;if(c=e,t=P(),t!==null){for(r=[],o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Br(){var t,r,o,c;if(c=e,t=T(),t!==null){for(r=[],o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Ts(){var t,r,o,c,h;return c=e,h=e,n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=vs(),r!==null?(n.charCodeAt(e)===93?(o="]",e++):(o=null,u('"]"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return v.host_type="IPv6",n.substring(e,f)}(c)),t===null&&(e=c),t}function vs(){var t,r,o,c,h,f,m,E,C,z,be,it,Bn,Hs,S,L;return Hs=e,S=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?(n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=x(),C!==null?(n.charCodeAt(e)===58?(z=":",e++):(z=null,u('":"')),z!==null?(be=x(),be!==null?(n.charCodeAt(e)===58?(it=":",e++):(it=null,u('":"')),it!==null?(Bn=qe(),Bn!==null?t=[t,r,o,c,h,f,m,E,C,z,be,it,Bn]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=x(),z!==null?(n.charCodeAt(e)===58?(be=":",e++):(be=null,u('":"')),be!==null?(it=qe(),it!==null?t=[t,r,o,c,h,f,m,E,C,z,be,it]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,C,z]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=qe(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=qe(),f!==null?t=[t,r,o,c,h,f]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=qe(),c!==null?t=[t,r,o,c]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=qe(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(n.substr(e,2)==="::"?(r="::",e+=2):(r=null,u('"::"')),r!==null?(o=x(),o!==null?(n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=x(),C!==null?(n.charCodeAt(e)===58?(z=":",e++):(z=null,u('":"')),z!==null?(be=qe(),be!==null?t=[t,r,o,c,h,f,m,E,C,z,be]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(n.substr(e,2)==="::"?(o="::",e+=2):(o=null,u('"::"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,C,z]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(n.substr(e,2)==="::"?(c="::",e+=2):(c=null,u('"::"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=qe(),C!==null?t=[t,r,o,c,h,f,m,E,C]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(n.substr(e,2)==="::"?(h="::",e+=2):(h=null,u('"::"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=qe(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(n.substr(e,2)==="::"?(f="::",e+=2):(f=null,u('"::"')),f!==null?(m=qe(),m!==null?t=[t,r,o,c,h,f,m]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?f=[f,m]:(f=null,e=L)):(f=null,e=L),f=f!==null?f:"",f!==null?(n.substr(e,2)==="::"?(m="::",e+=2):(m=null,u('"::"')),m!==null?(E=x(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?f=[f,m]:(f=null,e=L)):(f=null,e=L),f=f!==null?f:"",f!==null?(L=e,n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?m=[m,E]:(m=null,e=L)):(m=null,e=L),m=m!==null?m:"",m!==null?(n.substr(e,2)==="::"?(E="::",e+=2):(E=null,u('"::"')),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S))))))))))))))),t!==null&&(t=function(dc){return v.host_type="IPv6",n.substring(e,dc)}(Hs)),t===null&&(e=Hs),t}function x(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(o=y(),o=o!==null?o:"",o!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function qe(){var t,r,o,c;return c=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=sn()),t}function sn(){var t,r,o,c,h,f,m,E,C;return E=e,C=e,t=rn(),t!==null?(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=rn(),o!==null?(n.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null?(h=rn(),h!==null?(n.charCodeAt(e)===46?(f=".",e++):(f=null,u('"."')),f!==null?(m=rn(),m!==null?t=[t,r,o,c,h,f,m]:(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C),t!==null&&(t=function(z){return v.host_type="IPv4",n.substring(e,z)}(E)),t===null&&(e=E),t}function rn(){var t,r,o,c;return c=e,n.substr(e,2)==="25"?(t="25",e+=2):(t=null,u('"25"')),t!==null?(/^[0-5]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[0-5]")),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(c=e,n.charCodeAt(e)===50?(t="2",e++):(t=null,u('"2"')),t!==null?(/^[0-4]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[0-4]")),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,n.charCodeAt(e)===49?(t="1",e++):(t=null,u('"1"')),t!==null?(r=p(),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,/^[1-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[1-9]")),t!==null?(r=p(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(t=p())))),t}function Kr(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){return C=parseInt(C.join("")),v.port=C,C}(f,t)),t===null&&(e=f),t}function Gr(){var t,r,o,c;for(t=[],c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=ys(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);r!==null;)t.push(r),c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=ys(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);return t}function ys(){var t;return t=Wr(),t===null&&(t=Yr(),t===null&&(t=zr(),t===null&&(t=Xr(),t===null&&(t=Qr(),t===null&&(t=Jr(),t===null&&(t=Zr())))))),t}function Wr(){var t,r,o,c;return o=e,c=e,n.substr(e,10).toLowerCase()==="transport="?(t=n.substr(e,10),e+=10):(t=null,u('"transport="')),t!==null?(n.substr(e,3).toLowerCase()==="udp"?(r=n.substr(e,3),e+=3):(r=null,u('"udp"')),r===null&&(n.substr(e,3).toLowerCase()==="tcp"?(r=n.substr(e,3),e+=3):(r=null,u('"tcp"')),r===null&&(n.substr(e,4).toLowerCase()==="sctp"?(r=n.substr(e,4),e+=4):(r=null,u('"sctp"')),r===null&&(n.substr(e,3).toLowerCase()==="tls"?(r=n.substr(e,3),e+=3):(r=null,u('"tls"')),r===null&&(r=I())))),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.transport=f.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function Yr(){var t,r,o,c;return o=e,c=e,n.substr(e,5).toLowerCase()==="user="?(t=n.substr(e,5),e+=5):(t=null,u('"user="')),t!==null?(n.substr(e,5).toLowerCase()==="phone"?(r=n.substr(e,5),e+=5):(r=null,u('"phone"')),r===null&&(n.substr(e,2).toLowerCase()==="ip"?(r=n.substr(e,2),e+=2):(r=null,u('"ip"')),r===null&&(r=I())),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.user=f.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function zr(){var t,r,o,c;return o=e,c=e,n.substr(e,7).toLowerCase()==="method="?(t=n.substr(e,7),e+=7):(t=null,u('"method="')),t!==null?(r=Mn(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.method=f}(o,t[1])),t===null&&(e=o),t}function Xr(){var t,r,o,c;return o=e,c=e,n.substr(e,4).toLowerCase()==="ttl="?(t=n.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=Ms(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.params||(v.params={}),v.params.ttl=f}(o,t[1])),t===null&&(e=o),t}function Qr(){var t,r,o,c;return o=e,c=e,n.substr(e,6).toLowerCase()==="maddr="?(t=n.substr(e,6),e+=6):(t=null,u('"maddr="')),t!==null?(r=nn(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.maddr=f}(o,t[1])),t===null&&(e=o),t}function Jr(){var t,r,o,c,h,f;return c=e,h=e,n.substr(e,2).toLowerCase()==="lr"?(t=n.substr(e,2),e+=2):(t=null,u('"lr"')),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=I(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.uri_params||(v.uri_params={}),v.uri_params.lr=void 0}()),t===null&&(e=c),t}function Zr(){var t,r,o,c,h,f;return c=e,h=e,t=ei(),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=ti(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.uri_params||(v.uri_params={}),typeof C>"u"?C=void 0:C=C[1],v.uri_params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function ei(){var t,r,o;if(o=e,r=on(),r!==null)for(t=[];r!==null;)t.push(r),r=on();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function ti(){var t,r,o;if(o=e,r=on(),r!==null)for(t=[];r!==null;)t.push(r),r=on();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function on(){var t;return t=ni(),t===null&&(t=O(),t===null&&(t=pe())),t}function ni(){var t;return n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function si(){var t,r,o,c,h,f,m;if(f=e,n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Dn(),r!==null){for(o=[],m=e,n.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Dn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);c!==null;)o.push(c),m=e,n.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Dn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);o!==null?t=[t,r,o]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t}function Dn(){var t,r,o,c,h;return c=e,h=e,t=ri(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=ii(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m,E){m=m.join("").toLowerCase(),E=E.join(""),v.uri_headers||(v.uri_headers={}),v.uri_headers[m]?v.uri_headers[m].push(E):v.uri_headers[m]=[E]}(c,t[0],t[2])),t===null&&(e=c),t}function ri(){var t,r;if(r=ln(),r===null&&(r=O(),r===null&&(r=pe())),r!==null)for(t=[];r!==null;)t.push(r),r=ln(),r===null&&(r=O(),r===null&&(r=pe()));else t=null;return t}function ii(){var t,r;for(t=[],r=ln(),r===null&&(r=O(),r===null&&(r=pe()));r!==null;)t.push(r),r=ln(),r===null&&(r=O(),r===null&&(r=pe()));return t}function ln(){var t;return n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Ou(){var t;return t=Ii(),t===null&&(t=oi()),t}function oi(){var t,r,o,c,h,f;return f=e,t=Mn(),t!==null?(r=b(),r!==null?(o=li(),o!==null?(c=b(),c!==null?(h=As(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function li(){var t;return t=De(),t===null&&(t=Es()),t}function Es(){var t,r,o,c;return c=e,t=_i(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=ai(),o===null&&(o=ci()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ai(){var t,r,o,c,h;return c=e,t=ui(),t===null&&(t=kn()),t!==null?(h=e,n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(o=gi(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function ui(){var t,r,o,c;return c=e,n.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=fi(),r!==null?(o=kn(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function kn(){var t,r,o;return o=e,n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=di(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function ci(){var t,r,o,c;if(c=e,t=hi(),t!==null){for(r=[],o=an();o!==null;)r.push(o),o=an();r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function an(){var t;return t=ye(),t===null&&(t=O(),t===null&&(t=pe())),t}function hi(){var t;return t=O(),t===null&&(t=pe(),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))))),t}function di(){var t,r,o,c,h,f;if(h=e,t=Un(),t!==null){for(r=[],f=e,n.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=Un(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=Un(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Un(){var t,r,o,c,h,f;for(h=e,t=[],r=un();r!==null;)t.push(r),r=un();if(t!==null){for(r=[],f=e,n.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ss(){var t,r;for(t=[],r=un();r!==null;)t.push(r),r=un();return t}function un(){var t;return t=O(),t===null&&(t=pe(),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))),t}function _i(){var t,r,o,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],o=T(),o===null&&(o=p(),o===null&&(n.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));o!==null;)r.push(o),o=T(),o===null&&(o=p(),o===null&&(n.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(f){v.scheme=n.substring(e,f)}(c)),t===null&&(e=c),t}function fi(){var t;return t=pi(),t===null&&(t=mi()),t}function pi(){var t,r,o,c;return o=e,c=e,t=Ft(),t!==null?(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t=t!==null?t:"",t!==null?(r=Nn(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t=t!==null?t:"",t}function mi(){var t,r;if(r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')))))))))));else t=null;return t}function gi(){var t,r;for(t=[],r=an();r!==null;)t.push(r),r=an();return t}function As(){var t,r,o,c,h,f,m,E;if(m=e,E=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t!==null)if(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;if(o!==null)if(n.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null){if(f=p(),f!==null)for(h=[];f!==null;)h.push(f),f=p();else h=null;h!==null?t=[t,r,o,c,h]:(t=null,e=E)}else t=null,e=E;else t=null,e=E}else t=null,e=E;else t=null,e=E;return t!==null&&(t=function(C){v.sip_version=n.substring(e,C)}(m)),t===null&&(e=m),t}function Ti(){var t;return n.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function vi(){var t;return n.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function yi(){var t;return n.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function Ei(){var t;return n.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function Si(){var t;return n.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function Ai(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function Ci(){var t;return n.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function bi(){var t;return n.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function Ri(){var t;return n.substr(e,5)==="REFER"?(t="REFER",e+=5):(t=null,u('"REFER"')),t}function Mn(){var t,r;return r=e,t=Ti(),t===null&&(t=vi(),t===null&&(t=yi(),t===null&&(t=Ei(),t===null&&(t=Si(),t===null&&(t=Ai(),t===null&&(t=Ci(),t===null&&(t=bi(),t===null&&(t=Ri(),t===null&&(t=I()))))))))),t!==null&&(t=function(o){return v.method=n.substring(e,o),v.method}(r)),t===null&&(e=r),t}function Ii(){var t,r,o,c,h,f;return f=e,t=As(),t!==null?(r=b(),r!==null?(o=wi(),o!==null?(c=b(),c!==null?(h=Ni(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function wi(){var t,r;return r=e,t=Oi(),t!==null&&(t=function(o,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Oi(){var t,r,o,c;return c=e,t=p(),t!==null?(r=p(),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ni(){var t,r,o;for(o=e,t=[],r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=W(),r===null&&(r=b(),r===null&&(r=G()))))));r!==null;)t.push(r),r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=W(),r===null&&(r=b(),r===null&&(r=G()))))));return t!==null&&(t=function(c){v.reason_phrase=n.substring(e,c)}(o)),t===null&&(e=o),t}function Nu(){var t,r,o,c,h,f;if(h=e,t=cn(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=cn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=cn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Du(){var t,r,o,c,h,f;return c=e,h=e,t=Ye(),t!==null?(f=e,n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ye(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v=n.substring(e,m)}(c)),t===null&&(e=c),t}function ku(){var t,r,o,c,h,f,m;if(h=e,t=ee(),t===null)if(f=e,t=xn(),t!==null){for(r=[],m=e,o=_e(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=_e(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C,z;for(z=v.multi_header.length,C=0;C<z;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function xn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Cs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Cs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Mt(){var t,r,o,c,h;return h=e,t=Pn(),t=t!==null?t:"",t!==null?(r=xe(),r!==null?(o=De(),o!==null?(c=Ie(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Pn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=I(),t!==null){for(r=[],m=e,o=Te(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=Te(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t===null&&(t=Ue()),t!==null&&(t=function(E,C){typeof C=="string"?v.display_name=C:v.display_name=C[1].reduce(function(z,be){return z+be[0]+be[1]},C[0])}(h,t)),t===null&&(e=h),t}function Cs(){var t;return t=Di(),t===null&&(t=ki(),t===null&&(t=Oe())),t}function Di(){var t,r,o,c,h;return c=e,h=e,n.substr(e,1).toLowerCase()==="q"?(t=n.substr(e,1),e++):(t=null,u('"q"')),t!==null?(r=k(),r!==null?(o=Ui(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.params||(v.params={}),v.params.q=m}(c,t[2])),t===null&&(e=c),t}function ki(){var t,r,o,c,h;return c=e,h=e,n.substr(e,7).toLowerCase()==="expires"?(t=n.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.params||(v.params={}),v.params.expires=m}(c,t[2])),t===null&&(e=c),t}function xt(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){return parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Ui(){var t,r,o,c,h,f,m,E;return f=e,m=e,n.charCodeAt(e)===48?(t="0",e++):(t=null,u('"0"')),t!==null?(E=e,n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?r=[r,o,c,h]:(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(C){return parseFloat(n.substring(e,C))}(f)),t===null&&(e=f),t}function Oe(){var t,r,o,c,h,f;return c=e,h=e,t=I(),t!==null?(f=e,r=k(),r!==null?(o=Mi(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.params||(v.params={}),typeof C>"u"?C=void 0:C=C[1],v.params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Mi(){var t;return t=I(),t===null&&(t=nn(),t===null&&(t=we())),t}function Uu(){var t,r,o,c,h,f;if(h=e,t=xi(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function xi(){var t;return n.substr(e,6).toLowerCase()==="render"?(t=n.substr(e,6),e+=6):(t=null,u('"render"')),t===null&&(n.substr(e,7).toLowerCase()==="session"?(t=n.substr(e,7),e+=7):(t=null,u('"session"')),t===null&&(n.substr(e,4).toLowerCase()==="icon"?(t=n.substr(e,4),e+=4):(t=null,u('"icon"')),t===null&&(n.substr(e,5).toLowerCase()==="alert"?(t=n.substr(e,5),e+=5):(t=null,u('"alert"')),t===null&&(t=I())))),t}function bs(){var t;return t=Pi(),t===null&&(t=Oe()),t}function Pi(){var t,r,o,c;return c=e,n.substr(e,8).toLowerCase()==="handling"?(t=n.substr(e,8),e+=8):(t=null,u('"handling"')),t!==null?(r=k(),r!==null?(n.substr(e,8).toLowerCase()==="optional"?(o=n.substr(e,8),e+=8):(o=null,u('"optional"')),o===null&&(n.substr(e,8).toLowerCase()==="required"?(o=n.substr(e,8),e+=8):(o=null,u('"required"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Mu(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function xu(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Pu(){var t,r;return r=e,t=Li(),t!==null&&(t=function(o){v=n.substring(e,o)}(r)),t===null&&(e=r),t}function Li(){var t,r,o,c,h,f,m,E;if(m=e,t=Hi(),t!==null)if(r=V(),r!==null)if(o=$i(),o!==null){for(c=[],E=e,h=le(),h!==null?(f=Rs(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=le(),h!==null?(f=Rs(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Hi(){var t;return t=qi(),t===null&&(t=Fi()),t}function qi(){var t;return n.substr(e,4).toLowerCase()==="text"?(t=n.substr(e,4),e+=4):(t=null,u('"text"')),t===null&&(n.substr(e,5).toLowerCase()==="image"?(t=n.substr(e,5),e+=5):(t=null,u('"image"')),t===null&&(n.substr(e,5).toLowerCase()==="audio"?(t=n.substr(e,5),e+=5):(t=null,u('"audio"')),t===null&&(n.substr(e,5).toLowerCase()==="video"?(t=n.substr(e,5),e+=5):(t=null,u('"video"')),t===null&&(n.substr(e,11).toLowerCase()==="application"?(t=n.substr(e,11),e+=11):(t=null,u('"application"')),t===null&&(t=Ln()))))),t}function Fi(){var t;return n.substr(e,7).toLowerCase()==="message"?(t=n.substr(e,7),e+=7):(t=null,u('"message"')),t===null&&(n.substr(e,9).toLowerCase()==="multipart"?(t=n.substr(e,9),e+=9):(t=null,u('"multipart"')),t===null&&(t=Ln())),t}function Ln(){var t;return t=I(),t===null&&(t=ji()),t}function ji(){var t,r,o;return o=e,n.substr(e,2).toLowerCase()==="x-"?(t=n.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function $i(){var t;return t=Ln(),t===null&&(t=I()),t}function Rs(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=Vi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Vi(){var t;return t=I(),t===null&&(t=we()),t}function Lu(){var t,r,o,c;return c=e,t=Bi(),t!==null?(r=Te(),r!==null?(o=Mn(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Bi(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v.value=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Hu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function qu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=cn(),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E,C){v.event=C.join("").toLowerCase()}(h,t[0])),t===null&&(e=h),t}function cn(){var t,r,o,c,h,f;if(h=e,t=J(),t!==null){for(r=[],f=e,n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=J(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=J(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Fu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch(z){v=-1}}()),t===null&&(e=h),t}function Is(){var t;return t=ws(),t===null&&(t=Oe()),t}function ws(){var t,r,o,c,h;return c=e,h=e,n.substr(e,3).toLowerCase()==="tag"?(t=n.substr(e,3),e+=3):(t=null,u('"tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.tag=m}(c,t[2])),t===null&&(e=c),t}function ju(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function $u(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Vu(){var t,r,o,c,h,f,m,E,C,z;for(E=e,C=e,t=[],r=Pn();r!==null;)t.push(r),r=Pn();if(t!==null)if(r=xe(),r!==null)if(o=De(),o!==null)if(c=Ie(),c!==null){for(h=[],z=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);f!==null;)h.push(f),z=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);h!==null?t=[t,r,o,c,h]:(t=null,e=C)}else t=null,e=C;else t=null,e=C;else t=null,e=C;else t=null,e=C;return t!==null&&(t=function(be){try{v=new Bt(v.uri,v.display_name,v.params)}catch(it){v=-1}}()),t===null&&(e=E),t}function Bu(){var t;return t=Os(),t}function Os(){var t,r,o,c,h,f,m,E;if(m=e,n.substr(e,6).toLowerCase()==="digest"?(t=n.substr(e,6),e+=6):(t=null,u('"Digest"')),t!==null)if(r=Te(),r!==null)if(o=Hn(),o!==null){for(c=[],E=e,h=_e(),h!==null?(f=Hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=_e(),h!==null?(f=Hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Ki()),t}function Ki(){var t,r,o,c,h,f,m,E;if(m=e,t=I(),t!==null)if(r=Te(),r!==null)if(o=hn(),o!==null){for(c=[],E=e,h=_e(),h!==null?(f=hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=_e(),h!==null?(f=hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function hn(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=I(),o===null&&(o=we()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Hn(){var t;return t=Gi(),t===null&&(t=Yi(),t===null&&(t=zi(),t===null&&(t=Qi(),t===null&&(t=Ji(),t===null&&(t=Zi(),t===null&&(t=eo(),t===null&&(t=hn()))))))),t}function Gi(){var t,r,o,c;return c=e,n.substr(e,5).toLowerCase()==="realm"?(t=n.substr(e,5),e+=5):(t=null,u('"realm"')),t!==null?(r=k(),r!==null?(o=Wi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Wi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(o,c){v.realm=c}(r,t)),t===null&&(e=r),t}function Yi(){var t,r,o,c,h,f,m,E,C;if(E=e,n.substr(e,6).toLowerCase()==="domain"?(t=n.substr(e,6),e+=6):(t=null,u('"domain"')),t!==null)if(r=k(),r!==null)if(o=rt(),o!==null)if(c=qn(),c!==null){if(h=[],C=e,m=b(),m!==null)for(f=[];m!==null;)f.push(m),m=b();else f=null;for(f!==null?(m=qn(),m!==null?f=[f,m]:(f=null,e=C)):(f=null,e=C);f!==null;){if(h.push(f),C=e,m=b(),m!==null)for(f=[];m!==null;)f.push(m),m=b();else f=null;f!==null?(m=qn(),m!==null?f=[f,m]:(f=null,e=C)):(f=null,e=C)}h!==null?(f=Ee(),f!==null?t=[t,r,o,c,h,f]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function qn(){var t;return t=Es(),t===null&&(t=kn()),t}function zi(){var t,r,o,c;return c=e,n.substr(e,5).toLowerCase()==="nonce"?(t=n.substr(e,5),e+=5):(t=null,u('"nonce"')),t!==null?(r=k(),r!==null?(o=Xi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Xi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(o,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Qi(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="opaque"?(t=n.substr(e,6),e+=6):(t=null,u('"opaque"')),t!==null?(r=k(),r!==null?(o=Ue(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.opaque=m}(c,t[2])),t===null&&(e=c),t}function Ji(){var t,r,o,c,h;return c=e,n.substr(e,5).toLowerCase()==="stale"?(t=n.substr(e,5),e+=5):(t=null,u('"stale"')),t!==null?(r=k(),r!==null?(h=e,n.substr(e,4).toLowerCase()==="true"?(o=n.substr(e,4),e+=4):(o=null,u('"true"')),o!==null&&(o=function(f){v.stale=!0}()),o===null&&(e=h),o===null&&(h=e,n.substr(e,5).toLowerCase()==="false"?(o=n.substr(e,5),e+=5):(o=null,u('"false"')),o!==null&&(o=function(f){v.stale=!1}()),o===null&&(e=h)),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Zi(){var t,r,o,c,h;return c=e,h=e,n.substr(e,9).toLowerCase()==="algorithm"?(t=n.substr(e,9),e+=9):(t=null,u('"algorithm"')),t!==null?(r=k(),r!==null?(n.substr(e,3).toLowerCase()==="md5"?(o=n.substr(e,3),e+=3):(o=null,u('"MD5"')),o===null&&(n.substr(e,8).toLowerCase()==="md5-sess"?(o=n.substr(e,8),e+=8):(o=null,u('"MD5-sess"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.algorithm=m.toUpperCase()}(c,t[2])),t===null&&(e=c),t}function eo(){var t,r,o,c,h,f,m,E,C,z;if(E=e,n.substr(e,3).toLowerCase()==="qop"?(t=n.substr(e,3),e+=3):(t=null,u('"qop"')),t!==null)if(r=k(),r!==null)if(o=rt(),o!==null){if(C=e,c=Fn(),c!==null){for(h=[],z=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);f!==null;)h.push(f),z=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=Ee(),h!==null?t=[t,r,o,c,h]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Fn(){var t,r;return r=e,n.substr(e,8).toLowerCase()==="auth-int"?(t=n.substr(e,8),e+=8):(t=null,u('"auth-int"')),t===null&&(n.substr(e,4).toLowerCase()==="auth"?(t=n.substr(e,4),e+=4):(t=null,u('"auth"')),t===null&&(t=I())),t!==null&&(t=function(o,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Ku(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Gu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=jn(),t!==null){for(r=[],m=e,o=_e(),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=_e(),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C,z;for(z=v.multi_header.length,C=0;C<z;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function jn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Mt(),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Wu(){var t,r,o,c,h,f,m;if(h=e,f=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E,C){if(v.protocol=C.toLowerCase(),v.params||(v.params={}),v.params.text&&v.params.text[0]==='"'){var z=v.params.text;v.text=z.substring(1,z.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function Ns(){var t;return t=to(),t===null&&(t=Oe()),t}function to(){var t,r,o,c,h,f;if(h=e,f=e,n.substr(e,5).toLowerCase()==="cause"?(t=n.substr(e,5),e+=5):(t=null,u('"cause"')),t!==null)if(r=k(),r!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;o!==null?t=[t,r,o]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m,E){v.cause=parseInt(E.join(""))}(h,t[2])),t===null&&(e=h),t}function Yu(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function zu(){var t,r,o,c,h,f;if(h=e,t=$n(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=$n(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=$n(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $n(){var t,r,o,c,h,f;if(h=e,t=Mt(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Xu(){var t,r,o,c,h,f;if(h=e,t=no(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function no(){var t,r;return r=e,n.substr(e,6).toLowerCase()==="active"?(t=n.substr(e,6),e+=6):(t=null,u('"active"')),t===null&&(n.substr(e,7).toLowerCase()==="pending"?(t=n.substr(e,7),e+=7):(t=null,u('"pending"')),t===null&&(n.substr(e,10).toLowerCase()==="terminated"?(t=n.substr(e,10),e+=10):(t=null,u('"terminated"')),t===null&&(t=I()))),t!==null&&(t=function(o){v.state=n.substring(e,o)}(r)),t===null&&(e=r),t}function Ds(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="reason"?(t=n.substr(e,6),e+=6):(t=null,u('"reason"')),t!==null?(r=k(),r!==null?(o=so(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.reason=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,n.substr(e,7).toLowerCase()==="expires"?(t=n.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.expires=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,n.substr(e,11).toLowerCase()==="retry_after"?(t=n.substr(e,11),e+=11):(t=null,u('"retry_after"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.retry_after=m)}(c,t[2])),t===null&&(e=c),t===null&&(t=Oe()))),t}function so(){var t;return n.substr(e,11).toLowerCase()==="deactivated"?(t=n.substr(e,11),e+=11):(t=null,u('"deactivated"')),t===null&&(n.substr(e,9).toLowerCase()==="probation"?(t=n.substr(e,9),e+=9):(t=null,u('"probation"')),t===null&&(n.substr(e,8).toLowerCase()==="rejected"?(t=n.substr(e,8),e+=8):(t=null,u('"rejected"')),t===null&&(n.substr(e,7).toLowerCase()==="timeout"?(t=n.substr(e,7),e+=7):(t=null,u('"timeout"')),t===null&&(n.substr(e,6).toLowerCase()==="giveup"?(t=n.substr(e,6),e+=6):(t=null,u('"giveup"')),t===null&&(n.substr(e,10).toLowerCase()==="noresource"?(t=n.substr(e,10),e+=10):(t=null,u('"noresource"')),t===null&&(n.substr(e,9).toLowerCase()==="invariant"?(t=n.substr(e,9),e+=9):(t=null,u('"invariant"')),t===null&&(t=I()))))))),t}function Qu(){var t;return t=$(),t=t!==null?t:"",t}function Ju(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function Zu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=ks(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=ks(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch(z){v=-1}}()),t===null&&(e=h),t}function ks(){var t;return t=ws(),t===null&&(t=Oe()),t}function ec(){var t,r,o,c,h,f;if(h=e,t=Vn(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=Vn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=Vn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Vn(){var t,r,o,c,h,f,m,E;if(m=e,t=co(),t!==null)if(r=Te(),r!==null)if(o=fo(),o!==null){for(c=[],E=e,h=le(),h!==null?(f=Us(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=le(),h!==null?(f=Us(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Us(){var t;return t=ro(),t===null&&(t=io(),t===null&&(t=oo(),t===null&&(t=lo(),t===null&&(t=ao(),t===null&&(t=Oe()))))),t}function ro(){var t,r,o,c,h;return c=e,h=e,n.substr(e,3).toLowerCase()==="ttl"?(t=n.substr(e,3),e+=3):(t=null,u('"ttl"')),t!==null?(r=k(),r!==null?(o=Ms(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.ttl=m}(c,t[2])),t===null&&(e=c),t}function io(){var t,r,o,c,h;return c=e,h=e,n.substr(e,5).toLowerCase()==="maddr"?(t=n.substr(e,5),e+=5):(t=null,u('"maddr"')),t!==null?(r=k(),r!==null?(o=nn(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.maddr=m}(c,t[2])),t===null&&(e=c),t}function oo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,8).toLowerCase()==="received"?(t=n.substr(e,8),e+=8):(t=null,u('"received"')),t!==null?(r=k(),r!==null?(o=sn(),o===null&&(o=vs()),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.received=m}(c,t[2])),t===null&&(e=c),t}function lo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="branch"?(t=n.substr(e,6),e+=6):(t=null,u('"branch"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.branch=m}(c,t[2])),t===null&&(e=c),t}function ao(){var t,r,o,c,h;return c=e,n.substr(e,5).toLowerCase()==="rport"?(t=n.substr(e,5),e+=5):(t=null,u('"rport"')),t!==null?(h=e,r=k(),r!==null?(o=uo(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function uo(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.rport=parseInt(C.join(""))}(f,t)),t===null&&(e=f),t}function co(){var t,r,o,c,h,f;return f=e,t=ho(),t!==null?(r=V(),r!==null?(o=I(),o!==null?(c=V(),c!==null?(h=_o(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function ho(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null&&(t=function(o,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function _o(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="udp"?(t=n.substr(e,3),e+=3):(t=null,u('"UDP"')),t===null&&(n.substr(e,3).toLowerCase()==="tcp"?(t=n.substr(e,3),e+=3):(t=null,u('"TCP"')),t===null&&(n.substr(e,3).toLowerCase()==="tls"?(t=n.substr(e,3),e+=3):(t=null,u('"TLS"')),t===null&&(n.substr(e,4).toLowerCase()==="sctp"?(t=n.substr(e,4),e+=4):(t=null,u('"SCTP"')),t===null&&(t=I())))),t!==null&&(t=function(o,c){v.transport=c}(r,t)),t===null&&(e=r),t}function fo(){var t,r,o,c,h;return c=e,t=po(),t!==null?(h=e,r=ze(),r!==null?(o=mo(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function po(){var t,r;return r=e,t=sn(),t===null&&(t=Ts(),t===null&&(t=ms())),t!==null&&(t=function(o){v.host=n.substring(e,o)}(r)),t===null&&(e=r),t}function mo(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.port=parseInt(C.join(""))}(f,t)),t===null&&(e=f),t}function Ms(){var t,r,o,c,h;return c=e,h=e,t=p(),t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){return parseInt(m.join(""))}(c,t)),t===null&&(e=c),t}function tc(){var t;return t=Os(),t}function nc(){var t,r,o,c,h,f;if(h=e,t=go(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=xs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=xs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function go(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v.expires=c}(r,t)),t===null&&(e=r),t}function xs(){var t;return t=To(),t===null&&(t=Oe()),t}function To(){var t,r,o,c,h;return c=e,h=e,n.substr(e,9).toLowerCase()==="refresher"?(t=n.substr(e,9),e+=9):(t=null,u('"refresher"')),t!==null?(r=k(),r!==null?(n.substr(e,3).toLowerCase()==="uac"?(o=n.substr(e,3),e+=3):(o=null,u('"uac"')),o===null&&(n.substr(e,3).toLowerCase()==="uas"?(o=n.substr(e,3),e+=3):(o=null,u('"uas"'))),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.refresher=m.toLowerCase()}(c,t[2])),t===null&&(e=c),t}function sc(){var t,r,o,c;return c=e,t=I(),t!==null?(r=H(),r!==null?(o=vo(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function vo(){var t,r;for(t=[],r=q(),r===null&&(r=W(),r===null&&(r=Te()));r!==null;)t.push(r),r=q(),r===null&&(r=W(),r===null&&(r=Te()));return t}function rc(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function ic(){var t,r,o;return o=e,n.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=yo(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function yo(){var t,r,o,c,h,f,m,E,C,z,be;return z=e,be=e,t=Eo(),t!==null?(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(o=dt(),o!==null?(n.charCodeAt(e)===45?(c="-",e++):(c=null,u('"-"')),c!==null?(h=dt(),h!==null?(n.charCodeAt(e)===45?(f="-",e++):(f=null,u('"-"')),f!==null?(m=dt(),m!==null?(n.charCodeAt(e)===45?(E="-",e++):(E=null,u('"-"')),E!==null?(C=So(),C!==null?t=[t,r,o,c,h,f,m,E,C]:(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be),t!==null&&(t=function(it,Bn){v=n.substring(e+5,it)}(z,t[0])),t===null&&(e=z),t}function dt(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(o=y(),o!==null?(c=y(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Eo(){var t,r,o;return o=e,t=dt(),t!==null?(r=dt(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function So(){var t,r,o,c;return c=e,t=dt(),t!==null?(r=dt(),r!==null?(o=dt(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function oc(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){try{v=new Bt(v.uri,v.display_name,v.params)}catch(C){v=-1}}()),t===null&&(e=h),t}function lc(){var t,r,o,c,h,f;if(h=e,t=Ao(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Ps(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Ps(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ao(){var t,r,o,c,h,f;return c=e,h=e,t=Ye(),t!==null?(f=e,n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ye(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.call_id=n.substring(e,m)}(c)),t===null&&(e=c),t}function Ps(){var t;return t=Co(),t===null&&(t=bo(),t===null&&(t=Ro(),t===null&&(t=Oe()))),t}function Co(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6)==="to-tag"?(t="to-tag",e+=6):(t=null,u('"to-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.to_tag=m}(c,t[2])),t===null&&(e=c),t}function bo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,8)==="from-tag"?(t="from-tag",e+=8):(t=null,u('"from-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.from_tag=m}(c,t[2])),t===null&&(e=c),t}function Ro(){var t,r;return r=e,n.substr(e,10)==="early-only"?(t="early-only",e+=10):(t=null,u('"early-only"')),t!==null&&(t=function(o){v.early_only=!0}()),t===null&&(e=r),t}function ac(t){t.sort();for(var r=null,o=[],c=0;c<t.length;c++)t[c]!==r&&(o.push(t[c]),r=t[c]);return o}function uc(){for(var t=1,r=1,o=!1,c=0;c<Math.max(e,d);c++){var h=n.charAt(c);h===`
4
- `?(o||t++,r=1,o=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(t++,r=1,o=!0):(r++,o=!1)}return{line:t,column:r}}var Io=Gn(),Bt=Bl(),v={},cc=a[i]();if(cc===null||e!==n.length){var Ls=Math.max(e,d),hc=Ls<n.length?n.charAt(Ls):null,wo=uc();return new this.SyntaxError(ac(_),hc,Ls,wo.line,wo.column),-1}return v},toSource:function(){return this._source}};return s.SyntaxError=function(n,i,a,e,d){function _(u,g){var p,T;switch(u.length){case 0:p="end of input";break;case 1:p=u[0];break;default:p=u.slice(0,u.length-1).join(", ")+" or "+u[u.length-1]}return T=g?l(g):"end of input","Expected "+p+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=i,this.message=_(n,i),this.offset=a,this.line=e,this.column=d},s.SyntaxError.prototype=Error.prototype,s}()),gc}var Kl,vc;function Gn(){if(vc)return Kl;vc=1;function l(g,p){var T;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(T=s(g))||p&&g&&typeof g.length=="number"){T&&(g=T);var y=0,A=function(){};return{s:A,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(G){throw G},f:A}}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 w=!0,R=!1,b;return{s:function(){T=g[Symbol.iterator]()},n:function(){var G=T.next();return w=G.done,G},e:function(G){R=!0,b=G},f:function(){try{!w&&T.return!=null&&T.return()}finally{if(R)throw b}}}}function s(g,p){if(g){if(typeof g=="string")return n(g,p);var T=Object.prototype.toString.call(g).slice(8,-1);if(T==="Object"&&g.constructor&&(T=g.constructor.name),T==="Map"||T==="Set")return Array.from(g);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return n(g,p)}}function n(g,p){(p==null||p>g.length)&&(p=g.length);for(var T=0,y=new Array(p);T<p;T++)y[T]=g[T];return y}function i(g,p){if(!(g instanceof p))throw new TypeError("Cannot call a class as a function")}function a(g,p){for(var T=0;T<p.length;T++){var y=p[T];y.enumerable=y.enumerable||!1,y.configurable=!0,"value"in y&&(y.writable=!0),Object.defineProperty(g,y.key,y)}}function e(g,p,T){return p&&a(g.prototype,p),T&&a(g,T),g}var d=lt,_=wt(),u=dn();return Kl=function(){e(g,null,[{key:"parse",value:function(p){if(p=u.parse(p,"SIP_URI"),p!==-1)return p}}]);function g(p,T,y,A){var w=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},R=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(i(this,g),!y)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=p||d.SIP,this._user=T,this._host=y,this._port=A;for(var b in w)Object.prototype.hasOwnProperty.call(w,b)&&this.setParam(b,w[b]);for(var G in R)Object.prototype.hasOwnProperty.call(R,G)&&this.setHeader(G,R[G])}return e(g,[{key:"setParam",value:function(p,T){p&&(this._parameters[p.toLowerCase()]=typeof T>"u"||T===null?null:T.toString())}},{key:"getParam",value:function(p){if(p)return this._parameters[p.toLowerCase()]}},{key:"hasParam",value:function(p){if(p)return this._parameters.hasOwnProperty(p.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(p){if(p=p.toLowerCase(),this._parameters.hasOwnProperty(p)){var T=this._parameters[p];return delete this._parameters[p],T}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(p,T){this._headers[_.headerize(p)]=Array.isArray(T)?T:[T]}},{key:"getHeader",value:function(p){if(p)return this._headers[_.headerize(p)]}},{key:"hasHeader",value:function(p){if(p)return this._headers.hasOwnProperty(_.headerize(p))&&!0||!1}},{key:"deleteHeader",value:function(p){if(p=_.headerize(p),this._headers.hasOwnProperty(p)){var T=this._headers[p];return delete this._headers[p],T}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new g(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 p=[],T="".concat(this._scheme,":");this._user&&(T+="".concat(_.escapeUser(this._user),"@")),T+=this._host,(this._port||this._port===0)&&(T+=":".concat(this._port));for(var y in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,y)&&(T+=";".concat(y),this._parameters[y]!==null&&(T+="=".concat(this._parameters[y])));for(var A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var w=l(this._headers[A]),R;try{for(w.s();!(R=w.n()).done;){var b=R.value;p.push("".concat(A,"=").concat(b))}}catch(G){w.e(G)}finally{w.f()}}return p.length>0&&(T+="?".concat(p.join("&"))),T}},{key:"toAor",value:function(p){var T="".concat(this._scheme,":");return this._user&&(T+="".concat(_.escapeUser(this._user),"@")),T+=this._host,p&&(this._port||this._port===0)&&(T+=":".concat(this._port)),T}},{key:"scheme",get:function(){return this._scheme},set:function(p){this._scheme=p.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(p){this._user=p}},{key:"host",get:function(){return this._host},set:function(p){this._host=p.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(p){this._port=p===0?p:parseInt(p,10)||null}}]),g}(),Kl}var yc;function wt(){if(yc)return tt;yc=1;function l(p){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?l=function(T){return typeof T}:l=function(T){return T&&typeof Symbol=="function"&&T.constructor===Symbol&&T!==Symbol.prototype?"symbol":typeof T},l(p)}function s(p,T){var y;if(typeof Symbol>"u"||p[Symbol.iterator]==null){if(Array.isArray(p)||(y=n(p))||T&&p&&typeof p.length=="number"){y&&(p=y);var A=0,w=function(){};return{s:w,n:function(){return A>=p.length?{done:!0}:{done:!1,value:p[A++]}},e:function(P){throw P},f:w}}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,b=!1,G;return{s:function(){y=p[Symbol.iterator]()},n:function(){var P=y.next();return R=P.done,P},e:function(P){b=!0,G=P},f:function(){try{!R&&y.return!=null&&y.return()}finally{if(b)throw G}}}}function n(p,T){if(p){if(typeof p=="string")return i(p,T);var y=Object.prototype.toString.call(p).slice(8,-1);if(y==="Object"&&p.constructor&&(y=p.constructor.name),y==="Map"||y==="Set")return Array.from(p);if(y==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(y))return i(p,T)}}function i(p,T){(T==null||T>p.length)&&(T=p.length);for(var y=0,A=new Array(T);y<T;y++)A[y]=p[y];return A}var a=lt,e=Gn(),d=dn();tt.str_utf8_length=function(p){return unescape(encodeURIComponent(p)).length};var _=tt.isFunction=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object Function]":!1};tt.isString=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object String]":!1},tt.isDecimal=function(p){return!isNaN(p)&&parseFloat(p)===parseInt(p,10)},tt.isEmpty=function(p){return p===null||p===""||p===void 0||Array.isArray(p)&&p.length===0||typeof p=="number"&&isNaN(p)},tt.hasMethods=function(p){for(var T=arguments.length,y=new Array(T>1?T-1:0),A=1;A<T;A++)y[A-1]=arguments[A];for(var w=0,R=y;w<R.length;w++){var b=R[w];if(_(p[b]))return!1}return!0};var u=tt.createRandomToken=function(p){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,y,A,w="";for(y=0;y<p;y++)A=Math.random()*T|0,w+=A.toString(T);return w};tt.newTag=function(){return u(10)},tt.newUUID=function(){var p="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var y=Math.random()*16|0,A=T==="x"?y:y&3|8;return A.toString(16)});return p},tt.hostType=function(p){if(p){if(p=d.parse(p,"host"),p!==-1)return p.host_type}else return};var g=tt.escapeUser=function(p){return encodeURIComponent(decodeURIComponent(p)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return tt.normalizeTarget=function(p,T){if(p){if(p instanceof e)return p;if(typeof p=="string"){var y=p.split("@"),A,w;switch(y.length){case 1:if(!T)return;A=p,w=T;break;case 2:A=y[0],w=y[1];break;default:A=y.slice(0,y.length-1).join("@"),w=y[y.length-1]}A=A.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(A)&&(A=A.replace(/[-.()]/g,"")),p="".concat(a.SIP,":").concat(g(A),"@").concat(w);var R;return(R=e.parse(p))?R:void 0}else return}else return},tt.headerize=function(p){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},y=p.toLowerCase().replace(/_/g,"-").split("-"),A="",w=y.length,R;for(R=0;R<w;R++)R!==0&&(A+="-"),A+=y[R].charAt(0).toUpperCase()+y[R].substring(1);return T[A]&&(A=T[A]),A},tt.sipErrorCause=function(p){for(var T in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[T].indexOf(p)!==-1)return a.causes[T];return a.causes.SIP_FAILURE_CODE},tt.getRandomTestNetIP=function(){function p(T,y){return Math.floor(Math.random()*(y-T+1)+T)}return"192.0.2.".concat(p(1,254))},tt.calculateMD5=function(p){function T(fe,ae){return fe<<ae|fe>>>32-ae}function y(fe,ae){var Se=fe&2147483648,De=ae&2147483648,Ke=fe&1073741824,ct=ae&1073741824,He=(fe&1073741823)+(ae&1073741823);return Ke&ct?He^2147483648^Se^De:Ke|ct?He&1073741824?He^3221225472^Se^De:He^1073741824^Se^De:He^Se^De}function A(fe,ae,Se){return fe&ae|~fe&Se}function w(fe,ae,Se){return fe&Se|ae&~Se}function R(fe,ae,Se){return fe^ae^Se}function b(fe,ae,Se){return ae^(fe|~Se)}function G(fe,ae,Se,De,Ke,ct,He){return fe=y(fe,y(y(A(ae,Se,De),Ke),He)),y(T(fe,ct),ae)}function P(fe,ae,Se,De,Ke,ct,He){return fe=y(fe,y(y(w(ae,Se,De),Ke),He)),y(T(fe,ct),ae)}function ye(fe,ae,Se,De,Ke,ct,He){return fe=y(fe,y(y(R(ae,Se,De),Ke),He)),y(T(fe,ct),ae)}function O(fe,ae,Se,De,Ke,ct,He){return fe=y(fe,y(y(b(ae,Se,De),Ke),He)),y(T(fe,ct),ae)}function j(fe){for(var ae,Se=fe.length,De=Se+8,Ke=(De-De%64)/64,ct=(Ke+1)*16,He=new Array(ct-1),Ft=0,Ut=0;Ut<Se;)ae=(Ut-Ut%4)/4,Ft=Ut%4*8,He[ae]=He[ae]|fe.charCodeAt(Ut)<<Ft,Ut++;return ae=(Ut-Ut%4)/4,Ft=Ut%4*8,He[ae]=He[ae]|128<<Ft,He[ct-2]=Se<<3,He[ct-1]=Se>>>29,He}function pe(fe){var ae="",Se="",De,Ke;for(Ke=0;Ke<=3;Ke++)De=fe>>>Ke*8&255,Se="0".concat(De.toString(16)),ae=ae+Se.substr(Se.length-2,2);return ae}function Te(fe){for(var ae="",Se=0;Se<fe.length;Se++){var De=fe.charCodeAt(Se);De<128?ae+=String.fromCharCode(De):De>127&&De<2048?(ae+=String.fromCharCode(De>>6|192),ae+=String.fromCharCode(De&63|128)):(ae+=String.fromCharCode(De>>12|224),ae+=String.fromCharCode(De>>6&63|128),ae+=String.fromCharCode(De&63|128))}return ae}var N=[],H,$,q,M,W,te,I,J,ne,Ye=7,ee=12,V=17,k=22,Ae=5,me=9,Ie=14,xe=20,_e=4,le=11,ze=16,rt=23,Ee=6,ge=10,Re=15,we=21;for(p=Te(p),N=j(p),te=1732584193,I=4023233417,J=2562383102,ne=271733878,H=0;H<N.length;H+=16)$=te,q=I,M=J,W=ne,te=G(te,I,J,ne,N[H+0],Ye,3614090360),ne=G(ne,te,I,J,N[H+1],ee,3905402710),J=G(J,ne,te,I,N[H+2],V,606105819),I=G(I,J,ne,te,N[H+3],k,3250441966),te=G(te,I,J,ne,N[H+4],Ye,4118548399),ne=G(ne,te,I,J,N[H+5],ee,1200080426),J=G(J,ne,te,I,N[H+6],V,2821735955),I=G(I,J,ne,te,N[H+7],k,4249261313),te=G(te,I,J,ne,N[H+8],Ye,1770035416),ne=G(ne,te,I,J,N[H+9],ee,2336552879),J=G(J,ne,te,I,N[H+10],V,4294925233),I=G(I,J,ne,te,N[H+11],k,2304563134),te=G(te,I,J,ne,N[H+12],Ye,1804603682),ne=G(ne,te,I,J,N[H+13],ee,4254626195),J=G(J,ne,te,I,N[H+14],V,2792965006),I=G(I,J,ne,te,N[H+15],k,1236535329),te=P(te,I,J,ne,N[H+1],Ae,4129170786),ne=P(ne,te,I,J,N[H+6],me,3225465664),J=P(J,ne,te,I,N[H+11],Ie,643717713),I=P(I,J,ne,te,N[H+0],xe,3921069994),te=P(te,I,J,ne,N[H+5],Ae,3593408605),ne=P(ne,te,I,J,N[H+10],me,38016083),J=P(J,ne,te,I,N[H+15],Ie,3634488961),I=P(I,J,ne,te,N[H+4],xe,3889429448),te=P(te,I,J,ne,N[H+9],Ae,568446438),ne=P(ne,te,I,J,N[H+14],me,3275163606),J=P(J,ne,te,I,N[H+3],Ie,4107603335),I=P(I,J,ne,te,N[H+8],xe,1163531501),te=P(te,I,J,ne,N[H+13],Ae,2850285829),ne=P(ne,te,I,J,N[H+2],me,4243563512),J=P(J,ne,te,I,N[H+7],Ie,1735328473),I=P(I,J,ne,te,N[H+12],xe,2368359562),te=ye(te,I,J,ne,N[H+5],_e,4294588738),ne=ye(ne,te,I,J,N[H+8],le,2272392833),J=ye(J,ne,te,I,N[H+11],ze,1839030562),I=ye(I,J,ne,te,N[H+14],rt,4259657740),te=ye(te,I,J,ne,N[H+1],_e,2763975236),ne=ye(ne,te,I,J,N[H+4],le,1272893353),J=ye(J,ne,te,I,N[H+7],ze,4139469664),I=ye(I,J,ne,te,N[H+10],rt,3200236656),te=ye(te,I,J,ne,N[H+13],_e,681279174),ne=ye(ne,te,I,J,N[H+0],le,3936430074),J=ye(J,ne,te,I,N[H+3],ze,3572445317),I=ye(I,J,ne,te,N[H+6],rt,76029189),te=ye(te,I,J,ne,N[H+9],_e,3654602809),ne=ye(ne,te,I,J,N[H+12],le,3873151461),J=ye(J,ne,te,I,N[H+15],ze,530742520),I=ye(I,J,ne,te,N[H+2],rt,3299628645),te=O(te,I,J,ne,N[H+0],Ee,4096336452),ne=O(ne,te,I,J,N[H+7],ge,1126891415),J=O(J,ne,te,I,N[H+14],Re,2878612391),I=O(I,J,ne,te,N[H+5],we,4237533241),te=O(te,I,J,ne,N[H+12],Ee,1700485571),ne=O(ne,te,I,J,N[H+3],ge,2399980690),J=O(J,ne,te,I,N[H+10],Re,4293915773),I=O(I,J,ne,te,N[H+1],we,2240044497),te=O(te,I,J,ne,N[H+8],Ee,1873313359),ne=O(ne,te,I,J,N[H+15],ge,4264355552),J=O(J,ne,te,I,N[H+6],Re,2734768916),I=O(I,J,ne,te,N[H+13],we,1309151649),te=O(te,I,J,ne,N[H+4],Ee,4149444226),ne=O(ne,te,I,J,N[H+11],ge,3174756917),J=O(J,ne,te,I,N[H+2],Re,718787259),I=O(I,J,ne,te,N[H+9],we,3951481745),te=y(te,$),I=y(I,q),J=y(J,M),ne=y(ne,W);var Ue=pe(te)+pe(I)+pe(J)+pe(ne);return Ue.toLowerCase()},tt.closeMediaStream=function(p){if(p)try{var T;if(p.getTracks){T=p.getTracks();var y=s(T),A;try{for(y.s();!(A=y.n()).done;){var w=A.value;w.stop()}}catch(j){y.e(j)}finally{y.f()}}else{T=p.getAudioTracks();var R=s(T),b;try{for(R.s();!(b=R.n()).done;){var G=b.value;G.stop()}}catch(j){R.e(j)}finally{R.f()}T=p.getVideoTracks();var P=s(T),ye;try{for(P.s();!(ye=P.n()).done;){var O=ye.value;O.stop()}}catch(j){P.e(j)}finally{P.f()}}}catch(j){(typeof p.stop=="function"||l(p.stop)==="object")&&p.stop()}},tt.cloneArray=function(p){return p&&p.slice()||[]},tt.cloneObject=function(p){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return p&&Object.assign({},p)||T},tt}var Gl={exports:{}},Fs=typeof Reflect=="object"?Reflect:null,Ec=Fs&&typeof Fs.apply=="function"?Fs.apply:function(l,s,n){return Function.prototype.apply.call(l,s,n)},xo;Fs&&typeof Fs.ownKeys=="function"?xo=Fs.ownKeys:Object.getOwnPropertySymbols?xo=function(l){return Object.getOwnPropertyNames(l).concat(Object.getOwnPropertySymbols(l))}:xo=function(l){return Object.getOwnPropertyNames(l)};function j_(l){console&&console.warn&&console.warn(l)}var Sc=Number.isNaN||function(l){return l!==l};function Pe(){Pe.init.call(this)}Gl.exports=Pe,Gl.exports.once=K_,Pe.EventEmitter=Pe,Pe.prototype._events=void 0,Pe.prototype._eventsCount=0,Pe.prototype._maxListeners=void 0;var Ac=10;function Po(l){if(typeof l!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof l)}Object.defineProperty(Pe,"defaultMaxListeners",{enumerable:!0,get:function(){return Ac},set:function(l){if(typeof l!="number"||l<0||Sc(l))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+l+".");Ac=l}}),Pe.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},Pe.prototype.setMaxListeners=function(l){if(typeof l!="number"||l<0||Sc(l))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+l+".");return this._maxListeners=l,this};function Cc(l){return l._maxListeners===void 0?Pe.defaultMaxListeners:l._maxListeners}Pe.prototype.getMaxListeners=function(){return Cc(this)},Pe.prototype.emit=function(l){for(var s=[],n=1;n<arguments.length;n++)s.push(arguments[n]);var i=l==="error",a=this._events;if(a!==void 0)i=i&&a.error===void 0;else if(!i)return!1;if(i){var e;if(s.length>0&&(e=s[0]),e instanceof Error)throw e;var d=new Error("Unhandled error."+(e?" ("+e.message+")":""));throw d.context=e,d}var _=a[l];if(_===void 0)return!1;if(typeof _=="function")Ec(_,this,s);else for(var u=_.length,g=Oc(_,u),n=0;n<u;++n)Ec(g[n],this,s);return!0};function bc(l,s,n,i){var a,e,d;if(Po(n),e=l._events,e===void 0?(e=l._events=Object.create(null),l._eventsCount=0):(e.newListener!==void 0&&(l.emit("newListener",s,n.listener?n.listener:n),e=l._events),d=e[s]),d===void 0)d=e[s]=n,++l._eventsCount;else if(typeof d=="function"?d=e[s]=i?[n,d]:[d,n]:i?d.unshift(n):d.push(n),a=Cc(l),a>0&&d.length>a&&!d.warned){d.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+d.length+" "+String(s)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=l,_.type=s,_.count=d.length,j_(_)}return l}Pe.prototype.addListener=function(l,s){return bc(this,l,s,!1)},Pe.prototype.on=Pe.prototype.addListener,Pe.prototype.prependListener=function(l,s){return bc(this,l,s,!0)};function $_(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Rc(l,s,n){var i={fired:!1,wrapFn:void 0,target:l,type:s,listener:n},a=$_.bind(i);return a.listener=n,i.wrapFn=a,a}Pe.prototype.once=function(l,s){return Po(s),this.on(l,Rc(this,l,s)),this},Pe.prototype.prependOnceListener=function(l,s){return Po(s),this.prependListener(l,Rc(this,l,s)),this},Pe.prototype.removeListener=function(l,s){var n,i,a,e,d;if(Po(s),i=this._events,i===void 0)return this;if(n=i[l],n===void 0)return this;if(n===s||n.listener===s)--this._eventsCount===0?this._events=Object.create(null):(delete i[l],i.removeListener&&this.emit("removeListener",l,n.listener||s));else if(typeof n!="function"){for(a=-1,e=n.length-1;e>=0;e--)if(n[e]===s||n[e].listener===s){d=n[e].listener,a=e;break}if(a<0)return this;a===0?n.shift():V_(n,a),n.length===1&&(i[l]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",l,d||s)}return this},Pe.prototype.off=Pe.prototype.removeListener,Pe.prototype.removeAllListeners=function(l){var s,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[l]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[l]),this;if(arguments.length===0){var a=Object.keys(n),e;for(i=0;i<a.length;++i)e=a[i],e!=="removeListener"&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(s=n[l],typeof s=="function")this.removeListener(l,s);else if(s!==void 0)for(i=s.length-1;i>=0;i--)this.removeListener(l,s[i]);return this};function Ic(l,s,n){var i=l._events;if(i===void 0)return[];var a=i[s];return a===void 0?[]:typeof a=="function"?n?[a.listener||a]:[a]:n?B_(a):Oc(a,a.length)}Pe.prototype.listeners=function(l){return Ic(this,l,!0)},Pe.prototype.rawListeners=function(l){return Ic(this,l,!1)},Pe.listenerCount=function(l,s){return typeof l.listenerCount=="function"?l.listenerCount(s):wc.call(l,s)},Pe.prototype.listenerCount=wc;function wc(l){var s=this._events;if(s!==void 0){var n=s[l];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Pe.prototype.eventNames=function(){return this._eventsCount>0?xo(this._events):[]};function Oc(l,s){for(var n=new Array(s),i=0;i<s;++i)n[i]=l[i];return n}function V_(l,s){for(;s+1<l.length;s++)l[s]=l[s+1];l.pop()}function B_(l){for(var s=new Array(l.length),n=0;n<s.length;++n)s[n]=l[n].listener||l[n];return s}function K_(l,s){return new Promise(function(n,i){function a(d){l.removeListener(s,e),i(d)}function e(){typeof l.removeListener=="function"&&l.removeListener("error",a),n([].slice.call(arguments))}Nc(l,s,e,{once:!0}),s!=="error"&&G_(l,a,{once:!0})})}function G_(l,s,n){typeof l.on=="function"&&Nc(l,"error",s,n)}function Nc(l,s,n,i){if(typeof l.on=="function")i.once?l.once(s,n):l.on(s,n);else if(typeof l.addEventListener=="function")l.addEventListener(s,function a(e){i.once&&l.removeEventListener(s,a),n(e)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof l)}var _t=Gl.exports,Wl={exports:{}},Yl,Dc;function W_(){if(Dc)return Yl;Dc=1;var l=1e3,s=l*60,n=s*60,i=n*24,a=i*7,e=i*365.25;Yl=function(p,T){T=T||{};var y=typeof p;if(y==="string"&&p.length>0)return d(p);if(y==="number"&&isFinite(p))return T.long?u(p):_(p);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(p))};function d(p){if(p=String(p),!(p.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(p);if(T){var y=parseFloat(T[1]),A=(T[2]||"ms").toLowerCase();switch(A){case"years":case"year":case"yrs":case"yr":case"y":return y*e;case"weeks":case"week":case"w":return y*a;case"days":case"day":case"d":return y*i;case"hours":case"hour":case"hrs":case"hr":case"h":return y*n;case"minutes":case"minute":case"mins":case"min":case"m":return y*s;case"seconds":case"second":case"secs":case"sec":case"s":return y*l;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return y;default:return}}}}function _(p){var T=Math.abs(p);return T>=i?Math.round(p/i)+"d":T>=n?Math.round(p/n)+"h":T>=s?Math.round(p/s)+"m":T>=l?Math.round(p/l)+"s":p+"ms"}function u(p){var T=Math.abs(p);return T>=i?g(p,T,i,"day"):T>=n?g(p,T,n,"hour"):T>=s?g(p,T,s,"minute"):T>=l?g(p,T,l,"second"):p+" ms"}function g(p,T,y,A){var w=T>=y*1.5;return Math.round(p/y)+" "+A+(w?"s":"")}return Yl}function Y_(l){n.debug=n,n.default=n,n.coerce=u,n.disable=e,n.enable=a,n.enabled=d,n.humanize=W_(),n.destroy=g,Object.keys(l).forEach(p=>{n[p]=l[p]}),n.names=[],n.skips=[],n.formatters={};function s(p){let T=0;for(let y=0;y<p.length;y++)T=(T<<5)-T+p.charCodeAt(y),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=s;function n(p){let T,y=null,A,w;function R(...b){if(!R.enabled)return;const G=R,P=Number(new Date),ye=P-(T||P);G.diff=ye,G.prev=T,G.curr=P,T=P,b[0]=n.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let O=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(j,pe)=>{if(j==="%%")return"%";O++;const Te=n.formatters[pe];if(typeof Te=="function"){const N=b[O];j=Te.call(G,N),b.splice(O,1),O--}return j}),n.formatArgs.call(G,b),(G.log||n.log).apply(G,b)}return R.namespace=p,R.useColors=n.useColors(),R.color=n.selectColor(p),R.extend=i,R.destroy=n.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(A!==n.namespaces&&(A=n.namespaces,w=n.enabled(p)),w),set:b=>{y=b}}),typeof n.init=="function"&&n.init(R),R}function i(p,T){const y=n(this.namespace+(typeof T>"u"?":":T)+p);return y.log=this.log,y}function a(p){n.save(p),n.namespaces=p,n.names=[],n.skips=[];let T;const y=(typeof p=="string"?p:"").split(/[\s,]+/),A=y.length;for(T=0;T<A;T++)y[T]&&(p=y[T].replace(/\*/g,".*?"),p[0]==="-"?n.skips.push(new RegExp("^"+p.slice(1)+"$")):n.names.push(new RegExp("^"+p+"$")))}function e(){const p=[...n.names.map(_),...n.skips.map(_).map(T=>"-"+T)].join(",");return n.enable(""),p}function d(p){if(p[p.length-1]==="*")return!0;let T,y;for(T=0,y=n.skips.length;T<y;T++)if(n.skips[T].test(p))return!1;for(T=0,y=n.names.length;T<y;T++)if(n.names[T].test(p))return!0;return!1}function _(p){return p.toString().substring(2,p.toString().length-2).replace(/\.\*\?$/,"*")}function u(p){return p instanceof Error?p.stack||p.message:p}function g(){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 z_=Y_;(function(l,s){s.formatArgs=i,s.save=a,s.load=e,s.useColors=n,s.storage=d(),s.destroy=(()=>{let u=!1;return()=>{u||(u=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),s.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function 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 i(u){if(u[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+u[0]+(this.useColors?"%c ":" ")+"+"+l.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;u.splice(1,0,g,"color: inherit");let p=0,T=0;u[0].replace(/%[a-zA-Z%]/g,y=>{y!=="%%"&&(p++,y==="%c"&&(T=p))}),u.splice(T,0,g)}s.log=console.debug||console.log||(()=>{});function a(u){try{u?s.storage.setItem("debug",u):s.storage.removeItem("debug")}catch(g){}}function e(){let u;try{u=s.storage.getItem("debug")}catch(g){}return!u&&typeof process<"u"&&"env"in process&&(u=process.env.DEBUG),u}function d(){try{return localStorage}catch(u){}}l.exports=z_(s);const{formatters:_}=l.exports;_.j=function(u){try{return JSON.stringify(u)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}})(Wl,Wl.exports);var js=Wl.exports;function X_(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function kc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Q_(l,s,n){return s&&kc(l.prototype,s),n&&kc(l,n),l}var $s=js,Vs="JsSIP",ft=function(){function l(s){X_(this,l),s?(this._debug=$s.default("".concat(Vs,":").concat(s)),this._warn=$s.default("".concat(Vs,":WARN:").concat(s)),this._error=$s.default("".concat(Vs,":ERROR:").concat(s))):(this._debug=$s.default(Vs),this._warn=$s.default("".concat(Vs,":WARN")),this._error=$s.default("".concat(Vs,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Q_(l,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),l}(),Pt={},Uc={},Mc={exports:{}},xc=Mc.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(l){return l.encoding?"rtpmap:%d %s/%s/%s":l.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(l){return l.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(l){return l.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(l){return"extmap:%d"+(l.direction?"/%s":"%v")+(l["encrypt-uri"]?" %s":"%v")+" %s"+(l.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(l){return l.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(l){var s="candidate:%s %d %s %d %s %d typ %s";return s+=l.raddr!=null?" raddr %s rport %d":"%v%v",s+=l.tcptype!=null?" tcptype %s":"%v",l.generation!=null&&(s+=" generation %d"),s+=l["network-id"]!=null?" network-id %d":"%v",s+=l["network-cost"]!=null?" network-cost %d":"%v",s}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(l){var s="ssrc:%d";return l.attribute!=null&&(s+=" %s",l.value!=null&&(s+=":%s")),s}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(l){return l.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(l){return l.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(l){return"imageattr:%s %s %s"+(l.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(l){return"simulcast:%s %s"+(l.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(l){return"ts-refclk:%s"+(l.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(l){var s="mediaclk:";return s+=l.id!=null?"id=%s %s":"%v%s",s+=l.mediaClockValue!=null?"=%s":"",s+=l.rateNumerator!=null?" rate=%s":"",s+=l.rateDenominator!=null?"/%s":"",s}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(xc).forEach(function(l){var s=xc[l];s.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Pc=Mc.exports;(function(l){var s=function(_){return String(Number(_))===_?Number(_):_},n=function(_,u,g,p){if(p&&!g)u[p]=s(_[1]);else for(var T=0;T<g.length;T+=1)_[T+1]!=null&&(u[g[T]]=s(_[T+1]))},i=function(_,u,g){var p=_.name&&_.names;_.push&&!u[_.push]?u[_.push]=[]:p&&!u[_.name]&&(u[_.name]={});var T=_.push?{}:p?u[_.name]:u;n(g.match(_.reg),T,_.names,_.name),_.push&&u[_.push].push(T)},a=Pc,e=RegExp.prototype.test.bind(/^([a-z])=(.*)/);l.parse=function(_){var u={},g=[],p=u;return _.split(/(\r\n|\r|\n)/).filter(e).forEach(function(T){var y=T[0],A=T.slice(2);y==="m"&&(g.push({rtp:[],fmtp:[]}),p=g[g.length-1]);for(var w=0;w<(a[y]||[]).length;w+=1){var R=a[y][w];if(R.reg.test(A))return i(R,p,A)}}),u.media=g,u};var d=function(_,u){var g=u.split(/=(.+)/,2);return g.length===2?_[g[0]]=s(g[1]):g.length===1&&u.length>1&&(_[g[0]]=void 0),_};l.parseParams=function(_){return _.split(/;\s?/).reduce(d,{})},l.parseFmtpConfig=l.parseParams,l.parsePayloads=function(_){return _.toString().split(" ").map(Number)},l.parseRemoteCandidates=function(_){for(var u=[],g=_.split(" ").map(s),p=0;p<g.length;p+=3)u.push({component:g[p],ip:g[p+1],port:g[p+2]});return u},l.parseImageAttributes=function(_){return _.split(" ").map(function(u){return u.substring(1,u.length-1).split(",").reduce(d,{})})},l.parseSimulcastStreamList=function(_){return _.split(";").map(function(u){return u.split(",").map(function(g){var p,T=!1;return g[0]!=="~"?p=s(g):(p=s(g.substring(1,g.length)),T=!0),{scid:p,paused:T}})})}})(Uc);var zl=Pc,J_=/%[sdv%]/g,Z_=function(l){var s=1,n=arguments,i=n.length;return l.replace(J_,function(a){if(s>=i)return a;var e=n[s];switch(s+=1,a){case"%%":return"%";case"%s":return String(e);case"%d":return Number(e);case"%v":return""}})},rr=function(l,s,n){var i=s.format instanceof Function?s.format(s.push?n:n[s.name]):s.format,a=[l+"="+i];if(s.names)for(var e=0;e<s.names.length;e+=1){var d=s.names[e];s.name?a.push(n[s.name][d]):a.push(n[s.names[e]])}else a.push(n[s.name]);return Z_.apply(null,a)},ef=["v","o","s","i","u","e","p","c","b","t","r","z","a"],tf=["i","c","b","a"],nf=function(l,s){s=s||{},l.version==null&&(l.version=0),l.name==null&&(l.name=" "),l.media.forEach(function(e){e.payloads==null&&(e.payloads="")});var n=s.outerOrder||ef,i=s.innerOrder||tf,a=[];return n.forEach(function(e){zl[e].forEach(function(d){d.name in l&&l[d.name]!=null?a.push(rr(e,d,l)):d.push in l&&l[d.push]!=null&&l[d.push].forEach(function(_){a.push(rr(e,d,_))})})}),l.media.forEach(function(e){a.push(rr("m",zl.m[0],e)),i.forEach(function(d){zl[d].forEach(function(_){_.name in e&&e[_.name]!=null?a.push(rr(d,_,e)):_.push in e&&e[_.push]!=null&&e[_.push].forEach(function(u){a.push(rr(d,_,u))})})})}),a.join(`\r
3
+ `,e+=2):(t=null,u('"\\r\\n"')),t}function f(){var t;return/^[0-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[0-9]")),t}function T(){var t;return/^[a-zA-Z]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-zA-Z]")),t}function y(){var t;return/^[0-9a-fA-F]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[0-9a-fA-F]")),t}function A(){var t;return t=R(),t===null&&(t=G()),t}function w(){var t;return/^[\0-\xFF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function b(){var t;return/^["]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u('["]')),t}function R(){var t;return s.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function G(){var t;return s.charCodeAt(e)===9?(t=" ",e++):(t=null,u('"\\t"')),t}function x(){var t;return/^[a-zA-Z0-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-zA-Z0-9]")),t}function me(){var t;return s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","'))))))))))),t}function O(){var t;return t=x(),t===null&&(t=$()),t}function $(){var t;return s.charCodeAt(e)===45?(t="-",e++):(t=null,u('"-"')),t===null&&(s.charCodeAt(e)===95?(t="_",e++):(t=null,u('"_"')),t===null&&(s.charCodeAt(e)===46?(t=".",e++):(t=null,u('"."')),t===null&&(s.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(s.charCodeAt(e)===126?(t="~",e++):(t=null,u('"~"')),t===null&&(s.charCodeAt(e)===42?(t="*",e++):(t=null,u('"*"')),t===null&&(s.charCodeAt(e)===39?(t="'",e++):(t=null,u(`"'"`)),t===null&&(s.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(s.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')))))))))),t}function de(){var t,r,o,c,h;return c=e,h=e,s.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(o=y(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){return m.join("")}(c,t)),t===null&&(e=c),t}function fe(){var t,r,o,c,h,p;for(c=e,h=e,p=e,t=[],r=A();r!==null;)t.push(r),r=A();if(t!==null?(r=g(),r!==null?t=[t,r]:(t=null,e=p)):(t=null,e=p),t=t!==null?t:"",t!==null){if(o=A(),o!==null)for(r=[];o!==null;)r.push(o),o=A();else r=null;r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(m){return" "}()),t===null&&(e=c),t}function N(){var t;return t=fe(),t=t!==null?t:"",t}function H(){var t,r,o,c,h;for(c=e,h=e,t=[],r=R(),r===null&&(r=G());r!==null;)t.push(r),r=R(),r===null&&(r=G());return t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return":"}()),t===null&&(e=c),t}function j(){var t,r,o,c,h,p,m;if(h=e,p=e,r=F(),r!==null)for(t=[];r!==null;)t.push(r),r=F();else t=null;if(t!==null){for(r=[],m=e,o=[],c=fe();c!==null;)o.push(c),c=fe();for(o!==null?(c=F(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;){for(r.push(o),m=e,o=[],c=fe();c!==null;)o.push(c),c=fe();o!==null?(c=F(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m)}r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){return s.substring(e,E)}(h)),t===null&&(e=h),t}function F(){var t;return/^[!-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[!-~]")),t===null&&(t=P()),t}function P(){var t;return/^[\x80-\uFFFF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\x80-\\uFFFF]")),t}function W(){var t;return/^[\x80-\xBF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\x80-\\xBF]")),t}function ee(){var t;return t=f(),t===null&&(/^[a-f]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-f]"))),t}function I(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function X(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function te(){var t;return s.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(s.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')),t===null&&(s.charCodeAt(e)===60?(t="<",e++):(t=null,u('"<"')),t===null&&(s.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t===null&&(t=b(),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===123?(t="{",e++):(t=null,u('"{"')),t===null&&(s.charCodeAt(e)===125?(t="}",e++):(t=null,u('"}"')),t===null&&(t=R(),t===null&&(t=G())))))))))))))))))),t}function Ke(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(s.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=b(),r===null&&(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(s.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(s.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(s.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(s.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"'))))))))))))))))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(s.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=b(),r===null&&(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(s.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(s.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(s.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(s.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"')))))))))))))))))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function Q(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"*"}()),t===null&&(e=c),t}function V(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"/"}()),t===null&&(e=c),t}function k(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"="}()),t===null&&(e=c),t}function ve(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"("}()),t===null&&(e=c),t}function _e(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return")"}()),t===null&&(e=c),t}function Ae(){var t,r,o,c;return o=e,c=e,s.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return">"}()),t===null&&(e=o),t}function Ue(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return"<"}()),t===null&&(e=o),t}function ce(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return","}()),t===null&&(e=c),t}function re(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return";"}()),t===null&&(e=c),t}function Ge(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return":"}()),t===null&&(e=c),t}function tt(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(r=b(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function ge(){var t,r,o,c;return o=e,c=e,t=b(),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function pe(){var t,r,o,c;if(c=e,t=ve(),t!==null){for(r=[],o=Se(),o===null&&(o=ie(),o===null&&(o=pe()));o!==null;)r.push(o),o=Se(),o===null&&(o=ie(),o===null&&(o=pe()));r!==null?(o=_e(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)}else t=null,e=c;return t}function Se(){var t;return/^[!-']/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[!-']")),t===null&&(/^[*-[]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[*-[]")),t===null&&(/^[\]-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=P(),t===null&&(t=fe())))),t}function be(){var t,r,o,c,h,p;if(h=e,p=e,t=N(),t!==null)if(r=b(),r!==null){for(o=[],c=he(),c===null&&(c=ie());c!==null;)o.push(c),c=he(),c===null&&(c=ie());o!==null?(c=b(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m){return s.substring(e,m)}(h)),t===null&&(e=h),t}function De(){var t,r,o,c,h,p;if(h=e,p=e,t=N(),t!==null)if(r=b(),r!==null){for(o=[],c=he(),c===null&&(c=ie());c!==null;)o.push(c),c=he(),c===null&&(c=ie());o!==null?(c=b(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m){var E=s.substring(e,m).trim();return E.substring(1,E.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(h)),t===null&&(e=h),t}function he(){var t;return t=fe(),t===null&&(s.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(/^[#-[]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[#-[]")),t===null&&(/^[\]-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=P())))),t}function ie(){var t,r,o;return o=e,s.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t!==null?(/^[\0-\t]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\0-\\t]")),r===null&&(/^[\x0B-\f]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\x0B-\\f]")),r===null&&(/^[\x0E-]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\x0E-]")))),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Te(){var t,r,o,c,h,p;return h=e,p=e,t=$e(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Pt(),o=o!==null?o:"",o!==null?(c=bn(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t!==null&&(t=function(m){try{v.uri=new yo(v.scheme,v.user,v.host,v.port),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port}catch{v=-1}}()),t===null&&(e=h),t}function we(){var t,r,o,c,h,p,m,E;return m=e,E=e,t=$e(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Pt(),o=o!==null?o:"",o!==null?(c=bn(),c!==null?(h=qr(),h!==null?(p=Jr(),p=p!==null?p:"",p!==null?t=[t,r,o,c,h,p]:(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E),t!==null&&(t=function(C){try{v.uri=new yo(v.scheme,v.user,v.host,v.port,v.uri_params,v.uri_headers),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port,delete v.uri_params,i==="SIP_URI"&&(v=v.uri)}catch{v=-1}}()),t===null&&(e=m),t}function $e(){var t;return t=it(),t===null&&(t=xe()),t}function it(){var t,r;return r=e,s.substr(e,4).toLowerCase()==="sips"?(t=s.substr(e,4),e+=4):(t=null,u('"sips"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function xe(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"sip"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Pt(){var t,r,o,c,h,p;return c=e,h=e,t=wt(),t!==null?(p=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=xr(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?(s.charCodeAt(e)===64?(o="@",e++):(o=null,u('"@"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.user=decodeURIComponent(s.substring(e-1,m))}(c)),t===null&&(e=c),t}function wt(){var t,r;if(r=O(),r===null&&(r=de(),r===null&&(r=cs())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(r=cs()));else t=null;return t}function cs(){var t;return s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"'))))))))),t}function xr(){var t,r,o;for(o=e,t=[],r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));return t!==null&&(t=function(c){v.password=s.substring(e,c)}(o)),t===null&&(e=o),t}function bn(){var t,r,o,c,h;return c=e,t=Jt(),t!==null?(h=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Hr(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function Jt(){var t,r;return r=e,t=hs(),t===null&&(t=Xt(),t===null&&(t=_s())),t!==null&&(t=function(o){return v.host=s.substring(e,o).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function hs(){var t,r,o,c,h,p;for(c=e,h=e,t=[],p=e,r=ds(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p);r!==null;)t.push(r),p=e,r=ds(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p);return t!==null?(r=Lr(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){return v.host_type="domain",s.substring(e,m)}(c)),t===null&&(e=c),t}function ds(){var t,r,o,c;if(c=e,t=x(),t!==null){for(r=[],o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Lr(){var t,r,o,c;if(c=e,t=T(),t!==null){for(r=[],o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function _s(){var t,r,o,c,h;return c=e,h=e,s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=ps(),r!==null?(s.charCodeAt(e)===93?(o="]",e++):(o=null,u('"]"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return v.host_type="IPv6",s.substring(e,p)}(c)),t===null&&(e=c),t}function ps(){var t,r,o,c,h,p,m,E,C,ne,Ee,at,qn,Us,S,L;return Us=e,S=e,t=M(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?(s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=M(),C!==null?(s.charCodeAt(e)===58?(ne=":",e++):(ne=null,u('":"')),ne!==null?(Ee=M(),Ee!==null?(s.charCodeAt(e)===58?(at=":",e++):(at=null,u('":"')),at!==null?(qn=Le(),qn!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee,at,qn]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=M(),ne!==null?(s.charCodeAt(e)===58?(Ee=":",e++):(Ee=null,u('":"')),Ee!==null?(at=Le(),at!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee,at]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=Le(),ne!==null?t=[t,r,o,c,h,p,m,E,C,ne]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=Le(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=Le(),p!==null?t=[t,r,o,c,h,p]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=Le(),c!==null?t=[t,r,o,c]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=Le(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(s.substr(e,2)==="::"?(r="::",e+=2):(r=null,u('"::"')),r!==null?(o=M(),o!==null?(s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=M(),C!==null?(s.charCodeAt(e)===58?(ne=":",e++):(ne=null,u('":"')),ne!==null?(Ee=Le(),Ee!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(s.substr(e,2)==="::"?(o="::",e+=2):(o=null,u('"::"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=Le(),ne!==null?t=[t,r,o,c,h,p,m,E,C,ne]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(s.substr(e,2)==="::"?(c="::",e+=2):(c=null,u('"::"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=Le(),C!==null?t=[t,r,o,c,h,p,m,E,C]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(s.substr(e,2)==="::"?(h="::",e+=2):(h=null,u('"::"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=Le(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(s.substr(e,2)==="::"?(p="::",e+=2):(p=null,u('"::"')),p!==null?(m=Le(),m!==null?t=[t,r,o,c,h,p,m]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?p=[p,m]:(p=null,e=L)):(p=null,e=L),p=p!==null?p:"",p!==null?(s.substr(e,2)==="::"?(m="::",e+=2):(m=null,u('"::"')),m!==null?(E=M(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?p=[p,m]:(p=null,e=L)):(p=null,e=L),p=p!==null?p:"",p!==null?(L=e,s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?m=[m,E]:(m=null,e=L)):(m=null,e=L),m=m!==null?m:"",m!==null?(s.substr(e,2)==="::"?(E="::",e+=2):(E=null,u('"::"')),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S))))))))))))))),t!==null&&(t=function(rc){return v.host_type="IPv6",s.substring(e,rc)}(Us)),t===null&&(e=Us),t}function M(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(o=y(),o=o!==null?o:"",o!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Le(){var t,r,o,c;return c=e,t=M(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=Xt()),t}function Xt(){var t,r,o,c,h,p,m,E,C;return E=e,C=e,t=Qt(),t!==null?(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=Qt(),o!==null?(s.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null?(h=Qt(),h!==null?(s.charCodeAt(e)===46?(p=".",e++):(p=null,u('"."')),p!==null?(m=Qt(),m!==null?t=[t,r,o,c,h,p,m]:(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C),t!==null&&(t=function(ne){return v.host_type="IPv4",s.substring(e,ne)}(E)),t===null&&(e=E),t}function Qt(){var t,r,o,c;return c=e,s.substr(e,2)==="25"?(t="25",e+=2):(t=null,u('"25"')),t!==null?(/^[0-5]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[0-5]")),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(c=e,s.charCodeAt(e)===50?(t="2",e++):(t=null,u('"2"')),t!==null?(/^[0-4]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[0-4]")),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,s.charCodeAt(e)===49?(t="1",e++):(t=null,u('"1"')),t!==null?(r=f(),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,/^[1-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[1-9]")),t!==null?(r=f(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(t=f())))),t}function Hr(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){return C=parseInt(C.join("")),v.port=C,C}(p,t)),t===null&&(e=p),t}function qr(){var t,r,o,c;for(t=[],c=e,s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=fs(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);r!==null;)t.push(r),c=e,s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=fs(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);return t}function fs(){var t;return t=Fr(),t===null&&(t=jr(),t===null&&(t=$r(),t===null&&(t=Vr(),t===null&&(t=Br(),t===null&&(t=Kr(),t===null&&(t=Gr())))))),t}function Fr(){var t,r,o,c;return o=e,c=e,s.substr(e,10).toLowerCase()==="transport="?(t=s.substr(e,10),e+=10):(t=null,u('"transport="')),t!==null?(s.substr(e,3).toLowerCase()==="udp"?(r=s.substr(e,3),e+=3):(r=null,u('"udp"')),r===null&&(s.substr(e,3).toLowerCase()==="tcp"?(r=s.substr(e,3),e+=3):(r=null,u('"tcp"')),r===null&&(s.substr(e,4).toLowerCase()==="sctp"?(r=s.substr(e,4),e+=4):(r=null,u('"sctp"')),r===null&&(s.substr(e,3).toLowerCase()==="tls"?(r=s.substr(e,3),e+=3):(r=null,u('"tls"')),r===null&&(r=I())))),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.transport=p.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function jr(){var t,r,o,c;return o=e,c=e,s.substr(e,5).toLowerCase()==="user="?(t=s.substr(e,5),e+=5):(t=null,u('"user="')),t!==null?(s.substr(e,5).toLowerCase()==="phone"?(r=s.substr(e,5),e+=5):(r=null,u('"phone"')),r===null&&(s.substr(e,2).toLowerCase()==="ip"?(r=s.substr(e,2),e+=2):(r=null,u('"ip"')),r===null&&(r=I())),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.user=p.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function $r(){var t,r,o,c;return o=e,c=e,s.substr(e,7).toLowerCase()==="method="?(t=s.substr(e,7),e+=7):(t=null,u('"method="')),t!==null?(r=On(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.method=p}(o,t[1])),t===null&&(e=o),t}function Vr(){var t,r,o,c;return o=e,c=e,s.substr(e,4).toLowerCase()==="ttl="?(t=s.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=Os(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.params||(v.params={}),v.params.ttl=p}(o,t[1])),t===null&&(e=o),t}function Br(){var t,r,o,c;return o=e,c=e,s.substr(e,6).toLowerCase()==="maddr="?(t=s.substr(e,6),e+=6):(t=null,u('"maddr="')),t!==null?(r=Jt(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.maddr=p}(o,t[1])),t===null&&(e=o),t}function Kr(){var t,r,o,c,h,p;return c=e,h=e,s.substr(e,2).toLowerCase()==="lr"?(t=s.substr(e,2),e+=2):(t=null,u('"lr"')),t!==null?(p=e,s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=I(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.uri_params||(v.uri_params={}),v.uri_params.lr=void 0}()),t===null&&(e=c),t}function Gr(){var t,r,o,c,h,p;return c=e,h=e,t=Wr(),t!==null?(p=e,s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=Yr(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.uri_params||(v.uri_params={}),typeof C>"u"?C=void 0:C=C[1],v.uri_params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Wr(){var t,r,o;if(o=e,r=Zt(),r!==null)for(t=[];r!==null;)t.push(r),r=Zt();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function Yr(){var t,r,o;if(o=e,r=Zt(),r!==null)for(t=[];r!==null;)t.push(r),r=Zt();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function Zt(){var t;return t=zr(),t===null&&(t=O(),t===null&&(t=de())),t}function zr(){var t;return s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Jr(){var t,r,o,c,h,p,m;if(p=e,s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Rn(),r!==null){for(o=[],m=e,s.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Rn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);c!==null;)o.push(c),m=e,s.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Rn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);o!==null?t=[t,r,o]:(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t}function Rn(){var t,r,o,c,h;return c=e,h=e,t=Xr(),t!==null?(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=Qr(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m,E){m=m.join("").toLowerCase(),E=E.join(""),v.uri_headers||(v.uri_headers={}),v.uri_headers[m]?v.uri_headers[m].push(E):v.uri_headers[m]=[E]}(c,t[0],t[2])),t===null&&(e=c),t}function Xr(){var t,r;if(r=en(),r===null&&(r=O(),r===null&&(r=de())),r!==null)for(t=[];r!==null;)t.push(r),r=en(),r===null&&(r=O(),r===null&&(r=de()));else t=null;return t}function Qr(){var t,r;for(t=[],r=en(),r===null&&(r=O(),r===null&&(r=de()));r!==null;)t.push(r),r=en(),r===null&&(r=O(),r===null&&(r=de()));return t}function en(){var t;return s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Eu(){var t;return t=yi(),t===null&&(t=Zr()),t}function Zr(){var t,r,o,c,h,p;return p=e,t=On(),t!==null?(r=R(),r!==null?(o=ei(),o!==null?(c=R(),c!==null?(h=Ts(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function ei(){var t;return t=we(),t===null&&(t=ms()),t}function ms(){var t,r,o,c;return c=e,t=oi(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=ti(),o===null&&(o=si()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ti(){var t,r,o,c,h;return c=e,t=ni(),t===null&&(t=In()),t!==null?(h=e,s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(o=ci(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function ni(){var t,r,o,c;return c=e,s.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=li(),r!==null?(o=In(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function In(){var t,r,o;return o=e,s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=ii(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function si(){var t,r,o,c;if(c=e,t=ri(),t!==null){for(r=[],o=tn();o!==null;)r.push(o),o=tn();r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function tn(){var t;return t=me(),t===null&&(t=O(),t===null&&(t=de())),t}function ri(){var t;return t=O(),t===null&&(t=de(),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))))),t}function ii(){var t,r,o,c,h,p;if(h=e,t=wn(),t!==null){for(r=[],p=e,s.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=wn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=wn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function wn(){var t,r,o,c,h,p;for(h=e,t=[],r=nn();r!==null;)t.push(r),r=nn();if(t!==null){for(r=[],p=e,s.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=gs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=gs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function gs(){var t,r;for(t=[],r=nn();r!==null;)t.push(r),r=nn();return t}function nn(){var t;return t=O(),t===null&&(t=de(),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))),t}function oi(){var t,r,o,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],o=T(),o===null&&(o=f(),o===null&&(s.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));o!==null;)r.push(o),o=T(),o===null&&(o=f(),o===null&&(s.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(p){v.scheme=s.substring(e,p)}(c)),t===null&&(e=c),t}function li(){var t;return t=ai(),t===null&&(t=ui()),t}function ai(){var t,r,o,c;return o=e,c=e,t=Pt(),t!==null?(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t=t!==null?t:"",t!==null?(r=bn(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t=t!==null?t:"",t}function ui(){var t,r;if(r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')))))))))));else t=null;return t}function ci(){var t,r;for(t=[],r=tn();r!==null;)t.push(r),r=tn();return t}function Ts(){var t,r,o,c,h,p,m,E;if(m=e,E=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t!==null)if(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null){if(c=f(),c!==null)for(o=[];c!==null;)o.push(c),c=f();else o=null;if(o!==null)if(s.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null){if(p=f(),p!==null)for(h=[];p!==null;)h.push(p),p=f();else h=null;h!==null?t=[t,r,o,c,h]:(t=null,e=E)}else t=null,e=E;else t=null,e=E}else t=null,e=E;else t=null,e=E;return t!==null&&(t=function(C){v.sip_version=s.substring(e,C)}(m)),t===null&&(e=m),t}function hi(){var t;return s.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function di(){var t;return s.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function _i(){var t;return s.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function pi(){var t;return s.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function fi(){var t;return s.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function mi(){var t;return s.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function gi(){var t;return s.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function Ti(){var t;return s.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function vi(){var t;return s.substr(e,5)==="REFER"?(t="REFER",e+=5):(t=null,u('"REFER"')),t}function On(){var t,r;return r=e,t=hi(),t===null&&(t=di(),t===null&&(t=_i(),t===null&&(t=pi(),t===null&&(t=fi(),t===null&&(t=mi(),t===null&&(t=gi(),t===null&&(t=Ti(),t===null&&(t=vi(),t===null&&(t=I()))))))))),t!==null&&(t=function(o){return v.method=s.substring(e,o),v.method}(r)),t===null&&(e=r),t}function yi(){var t,r,o,c,h,p;return p=e,t=Ts(),t!==null?(r=R(),r!==null?(o=Ei(),o!==null?(c=R(),c!==null?(h=Ai(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function Ei(){var t,r;return r=e,t=Si(),t!==null&&(t=function(o,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Si(){var t,r,o,c;return c=e,t=f(),t!==null?(r=f(),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ai(){var t,r,o;for(o=e,t=[],r=me(),r===null&&(r=O(),r===null&&(r=de(),r===null&&(r=P(),r===null&&(r=W(),r===null&&(r=R(),r===null&&(r=G()))))));r!==null;)t.push(r),r=me(),r===null&&(r=O(),r===null&&(r=de(),r===null&&(r=P(),r===null&&(r=W(),r===null&&(r=R(),r===null&&(r=G()))))));return t!==null&&(t=function(c){v.reason_phrase=s.substring(e,c)}(o)),t===null&&(e=o),t}function Su(){var t,r,o,c,h,p;if(h=e,t=sn(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=sn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=sn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Au(){var t,r,o,c,h,p;return c=e,h=e,t=Ke(),t!==null?(p=e,s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ke(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v=s.substring(e,m)}(c)),t===null&&(e=c),t}function Cu(){var t,r,o,c,h,p,m;if(h=e,t=Q(),t===null)if(p=e,t=Nn(),t!==null){for(r=[],m=e,o=ce(),o!==null?(c=Nn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=ce(),o!==null?(c=Nn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C,ne;for(ne=v.multi_header.length,C=0;C<ne;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function Nn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=vs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=vs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Ht(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch{C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Ot(){var t,r,o,c,h;return h=e,t=Dn(),t=t!==null?t:"",t!==null?(r=Ue(),r!==null?(o=we(),o!==null?(c=Ae(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Dn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=I(),t!==null){for(r=[],m=e,o=fe(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=fe(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t===null&&(t=De()),t!==null&&(t=function(E,C){typeof C=="string"?v.display_name=C:v.display_name=C[1].reduce(function(ne,Ee){return ne+Ee[0]+Ee[1]},C[0])}(h,t)),t===null&&(e=h),t}function vs(){var t;return t=Ci(),t===null&&(t=bi(),t===null&&(t=Re())),t}function Ci(){var t,r,o,c,h;return c=e,h=e,s.substr(e,1).toLowerCase()==="q"?(t=s.substr(e,1),e++):(t=null,u('"q"')),t!==null?(r=k(),r!==null?(o=Ri(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.params||(v.params={}),v.params.q=m}(c,t[2])),t===null&&(e=c),t}function bi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,7).toLowerCase()==="expires"?(t=s.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.params||(v.params={}),v.params.expires=m}(c,t[2])),t===null&&(e=c),t}function Nt(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){return parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Ri(){var t,r,o,c,h,p,m,E;return p=e,m=e,s.charCodeAt(e)===48?(t="0",e++):(t=null,u('"0"')),t!==null?(E=e,s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?r=[r,o,c,h]:(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(C){return parseFloat(s.substring(e,C))}(p)),t===null&&(e=p),t}function Re(){var t,r,o,c,h,p;return c=e,h=e,t=I(),t!==null?(p=e,r=k(),r!==null?(o=Ii(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.params||(v.params={}),typeof C>"u"?C=void 0:C=C[1],v.params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Ii(){var t;return t=I(),t===null&&(t=Jt(),t===null&&(t=be())),t}function bu(){var t,r,o,c,h,p;if(h=e,t=wi(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=ys(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=ys(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function wi(){var t;return s.substr(e,6).toLowerCase()==="render"?(t=s.substr(e,6),e+=6):(t=null,u('"render"')),t===null&&(s.substr(e,7).toLowerCase()==="session"?(t=s.substr(e,7),e+=7):(t=null,u('"session"')),t===null&&(s.substr(e,4).toLowerCase()==="icon"?(t=s.substr(e,4),e+=4):(t=null,u('"icon"')),t===null&&(s.substr(e,5).toLowerCase()==="alert"?(t=s.substr(e,5),e+=5):(t=null,u('"alert"')),t===null&&(t=I())))),t}function ys(){var t;return t=Oi(),t===null&&(t=Re()),t}function Oi(){var t,r,o,c;return c=e,s.substr(e,8).toLowerCase()==="handling"?(t=s.substr(e,8),e+=8):(t=null,u('"handling"')),t!==null?(r=k(),r!==null?(s.substr(e,8).toLowerCase()==="optional"?(o=s.substr(e,8),e+=8):(o=null,u('"optional"')),o===null&&(s.substr(e,8).toLowerCase()==="required"?(o=s.substr(e,8),e+=8):(o=null,u('"required"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ru(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Iu(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function wu(){var t,r;return r=e,t=Ni(),t!==null&&(t=function(o){v=s.substring(e,o)}(r)),t===null&&(e=r),t}function Ni(){var t,r,o,c,h,p,m,E;if(m=e,t=Di(),t!==null)if(r=V(),r!==null)if(o=Pi(),o!==null){for(c=[],E=e,h=re(),h!==null?(p=Es(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=re(),h!==null?(p=Es(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Di(){var t;return t=ki(),t===null&&(t=Ui()),t}function ki(){var t;return s.substr(e,4).toLowerCase()==="text"?(t=s.substr(e,4),e+=4):(t=null,u('"text"')),t===null&&(s.substr(e,5).toLowerCase()==="image"?(t=s.substr(e,5),e+=5):(t=null,u('"image"')),t===null&&(s.substr(e,5).toLowerCase()==="audio"?(t=s.substr(e,5),e+=5):(t=null,u('"audio"')),t===null&&(s.substr(e,5).toLowerCase()==="video"?(t=s.substr(e,5),e+=5):(t=null,u('"video"')),t===null&&(s.substr(e,11).toLowerCase()==="application"?(t=s.substr(e,11),e+=11):(t=null,u('"application"')),t===null&&(t=kn()))))),t}function Ui(){var t;return s.substr(e,7).toLowerCase()==="message"?(t=s.substr(e,7),e+=7):(t=null,u('"message"')),t===null&&(s.substr(e,9).toLowerCase()==="multipart"?(t=s.substr(e,9),e+=9):(t=null,u('"multipart"')),t===null&&(t=kn())),t}function kn(){var t;return t=I(),t===null&&(t=Mi()),t}function Mi(){var t,r,o;return o=e,s.substr(e,2).toLowerCase()==="x-"?(t=s.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Pi(){var t;return t=kn(),t===null&&(t=I()),t}function Es(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=xi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function xi(){var t;return t=I(),t===null&&(t=be()),t}function Ou(){var t,r,o,c;return c=e,t=Li(),t!==null?(r=fe(),r!==null?(o=On(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Li(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v.value=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Nu(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Du(){var t,r,o,c,h,p,m;if(h=e,p=e,t=sn(),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E,C){v.event=C.join("").toLowerCase()}(h,t[0])),t===null&&(e=h),t}function sn(){var t,r,o,c,h,p;if(h=e,t=X(),t!==null){for(r=[],p=e,s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=X(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=X(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ku(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C=v.tag;try{v=new Ht(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch{v=-1}}()),t===null&&(e=h),t}function Ss(){var t;return t=As(),t===null&&(t=Re()),t}function As(){var t,r,o,c,h;return c=e,h=e,s.substr(e,3).toLowerCase()==="tag"?(t=s.substr(e,3),e+=3):(t=null,u('"tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.tag=m}(c,t[2])),t===null&&(e=c),t}function Uu(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Mu(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Pu(){var t,r,o,c,h,p,m,E,C,ne;for(E=e,C=e,t=[],r=Dn();r!==null;)t.push(r),r=Dn();if(t!==null)if(r=Ue(),r!==null)if(o=we(),o!==null)if(c=Ae(),c!==null){for(h=[],ne=e,p=re(),p!==null?(m=Re(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);p!==null;)h.push(p),ne=e,p=re(),p!==null?(m=Re(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);h!==null?t=[t,r,o,c,h]:(t=null,e=C)}else t=null,e=C;else t=null,e=C;else t=null,e=C;else t=null,e=C;return t!==null&&(t=function(Ee){try{v=new Ht(v.uri,v.display_name,v.params)}catch{v=-1}}()),t===null&&(e=E),t}function xu(){var t;return t=Cs(),t}function Cs(){var t,r,o,c,h,p,m,E;if(m=e,s.substr(e,6).toLowerCase()==="digest"?(t=s.substr(e,6),e+=6):(t=null,u('"Digest"')),t!==null)if(r=fe(),r!==null)if(o=Un(),o!==null){for(c=[],E=e,h=ce(),h!==null?(p=Un(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=ce(),h!==null?(p=Un(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Hi()),t}function Hi(){var t,r,o,c,h,p,m,E;if(m=e,t=I(),t!==null)if(r=fe(),r!==null)if(o=rn(),o!==null){for(c=[],E=e,h=ce(),h!==null?(p=rn(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=ce(),h!==null?(p=rn(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function rn(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=I(),o===null&&(o=be()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Un(){var t;return t=qi(),t===null&&(t=ji(),t===null&&(t=$i(),t===null&&(t=Bi(),t===null&&(t=Ki(),t===null&&(t=Gi(),t===null&&(t=Wi(),t===null&&(t=rn()))))))),t}function qi(){var t,r,o,c;return c=e,s.substr(e,5).toLowerCase()==="realm"?(t=s.substr(e,5),e+=5):(t=null,u('"realm"')),t!==null?(r=k(),r!==null?(o=Fi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Fi(){var t,r;return r=e,t=De(),t!==null&&(t=function(o,c){v.realm=c}(r,t)),t===null&&(e=r),t}function ji(){var t,r,o,c,h,p,m,E,C;if(E=e,s.substr(e,6).toLowerCase()==="domain"?(t=s.substr(e,6),e+=6):(t=null,u('"domain"')),t!==null)if(r=k(),r!==null)if(o=tt(),o!==null)if(c=Mn(),c!==null){if(h=[],C=e,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;for(p!==null?(m=Mn(),m!==null?p=[p,m]:(p=null,e=C)):(p=null,e=C);p!==null;){if(h.push(p),C=e,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;p!==null?(m=Mn(),m!==null?p=[p,m]:(p=null,e=C)):(p=null,e=C)}h!==null?(p=ge(),p!==null?t=[t,r,o,c,h,p]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Mn(){var t;return t=ms(),t===null&&(t=In()),t}function $i(){var t,r,o,c;return c=e,s.substr(e,5).toLowerCase()==="nonce"?(t=s.substr(e,5),e+=5):(t=null,u('"nonce"')),t!==null?(r=k(),r!==null?(o=Vi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Vi(){var t,r;return r=e,t=De(),t!==null&&(t=function(o,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Bi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="opaque"?(t=s.substr(e,6),e+=6):(t=null,u('"opaque"')),t!==null?(r=k(),r!==null?(o=De(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.opaque=m}(c,t[2])),t===null&&(e=c),t}function Ki(){var t,r,o,c,h;return c=e,s.substr(e,5).toLowerCase()==="stale"?(t=s.substr(e,5),e+=5):(t=null,u('"stale"')),t!==null?(r=k(),r!==null?(h=e,s.substr(e,4).toLowerCase()==="true"?(o=s.substr(e,4),e+=4):(o=null,u('"true"')),o!==null&&(o=function(p){v.stale=!0}()),o===null&&(e=h),o===null&&(h=e,s.substr(e,5).toLowerCase()==="false"?(o=s.substr(e,5),e+=5):(o=null,u('"false"')),o!==null&&(o=function(p){v.stale=!1}()),o===null&&(e=h)),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Gi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,9).toLowerCase()==="algorithm"?(t=s.substr(e,9),e+=9):(t=null,u('"algorithm"')),t!==null?(r=k(),r!==null?(s.substr(e,3).toLowerCase()==="md5"?(o=s.substr(e,3),e+=3):(o=null,u('"MD5"')),o===null&&(s.substr(e,8).toLowerCase()==="md5-sess"?(o=s.substr(e,8),e+=8):(o=null,u('"MD5-sess"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.algorithm=m.toUpperCase()}(c,t[2])),t===null&&(e=c),t}function Wi(){var t,r,o,c,h,p,m,E,C,ne;if(E=e,s.substr(e,3).toLowerCase()==="qop"?(t=s.substr(e,3),e+=3):(t=null,u('"qop"')),t!==null)if(r=k(),r!==null)if(o=tt(),o!==null){if(C=e,c=Pn(),c!==null){for(h=[],ne=e,s.charCodeAt(e)===44?(p=",",e++):(p=null,u('","')),p!==null?(m=Pn(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);p!==null;)h.push(p),ne=e,s.charCodeAt(e)===44?(p=",",e++):(p=null,u('","')),p!==null?(m=Pn(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=ge(),h!==null?t=[t,r,o,c,h]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Pn(){var t,r;return r=e,s.substr(e,8).toLowerCase()==="auth-int"?(t=s.substr(e,8),e+=8):(t=null,u('"auth-int"')),t===null&&(s.substr(e,4).toLowerCase()==="auth"?(t=s.substr(e,4),e+=4):(t=null,u('"auth"')),t===null&&(t=I())),t!==null&&(t=function(o,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Lu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Hu(){var t,r,o,c,h,p,m;if(h=e,p=e,t=xn(),t!==null){for(r=[],m=e,o=ce(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=ce(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C,ne;for(ne=v.multi_header.length,C=0;C<ne;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function xn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Ot(),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Ht(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch{C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function qu(){var t,r,o,c,h,p,m;if(h=e,p=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E,C){if(v.protocol=C.toLowerCase(),v.params||(v.params={}),v.params.text&&v.params.text[0]==='"'){var ne=v.params.text;v.text=ne.substring(1,ne.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function bs(){var t;return t=Yi(),t===null&&(t=Re()),t}function Yi(){var t,r,o,c,h,p;if(h=e,p=e,s.substr(e,5).toLowerCase()==="cause"?(t=s.substr(e,5),e+=5):(t=null,u('"cause"')),t!==null)if(r=k(),r!==null){if(c=f(),c!==null)for(o=[];c!==null;)o.push(c),c=f();else o=null;o!==null?t=[t,r,o]:(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m,E){v.cause=parseInt(E.join(""))}(h,t[2])),t===null&&(e=h),t}function Fu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ju(){var t,r,o,c,h,p;if(h=e,t=Ln(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=Ln(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=Ln(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ln(){var t,r,o,c,h,p;if(h=e,t=Ot(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $u(){var t,r,o,c,h,p;if(h=e,t=zi(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Rs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Rs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function zi(){var t,r;return r=e,s.substr(e,6).toLowerCase()==="active"?(t=s.substr(e,6),e+=6):(t=null,u('"active"')),t===null&&(s.substr(e,7).toLowerCase()==="pending"?(t=s.substr(e,7),e+=7):(t=null,u('"pending"')),t===null&&(s.substr(e,10).toLowerCase()==="terminated"?(t=s.substr(e,10),e+=10):(t=null,u('"terminated"')),t===null&&(t=I()))),t!==null&&(t=function(o){v.state=s.substring(e,o)}(r)),t===null&&(e=r),t}function Rs(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="reason"?(t=s.substr(e,6),e+=6):(t=null,u('"reason"')),t!==null?(r=k(),r!==null?(o=Ji(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.reason=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,s.substr(e,7).toLowerCase()==="expires"?(t=s.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.expires=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,s.substr(e,11).toLowerCase()==="retry_after"?(t=s.substr(e,11),e+=11):(t=null,u('"retry_after"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.retry_after=m)}(c,t[2])),t===null&&(e=c),t===null&&(t=Re()))),t}function Ji(){var t;return s.substr(e,11).toLowerCase()==="deactivated"?(t=s.substr(e,11),e+=11):(t=null,u('"deactivated"')),t===null&&(s.substr(e,9).toLowerCase()==="probation"?(t=s.substr(e,9),e+=9):(t=null,u('"probation"')),t===null&&(s.substr(e,8).toLowerCase()==="rejected"?(t=s.substr(e,8),e+=8):(t=null,u('"rejected"')),t===null&&(s.substr(e,7).toLowerCase()==="timeout"?(t=s.substr(e,7),e+=7):(t=null,u('"timeout"')),t===null&&(s.substr(e,6).toLowerCase()==="giveup"?(t=s.substr(e,6),e+=6):(t=null,u('"giveup"')),t===null&&(s.substr(e,10).toLowerCase()==="noresource"?(t=s.substr(e,10),e+=10):(t=null,u('"noresource"')),t===null&&(s.substr(e,9).toLowerCase()==="invariant"?(t=s.substr(e,9),e+=9):(t=null,u('"invariant"')),t===null&&(t=I()))))))),t}function Vu(){var t;return t=j(),t=t!==null?t:"",t}function Bu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function Ku(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C=v.tag;try{v=new Ht(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch{v=-1}}()),t===null&&(e=h),t}function Is(){var t;return t=As(),t===null&&(t=Re()),t}function Gu(){var t,r,o,c,h,p;if(h=e,t=Hn(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=Hn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=Hn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Hn(){var t,r,o,c,h,p,m,E;if(m=e,t=so(),t!==null)if(r=fe(),r!==null)if(o=oo(),o!==null){for(c=[],E=e,h=re(),h!==null?(p=ws(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=re(),h!==null?(p=ws(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function ws(){var t;return t=Xi(),t===null&&(t=Qi(),t===null&&(t=Zi(),t===null&&(t=eo(),t===null&&(t=to(),t===null&&(t=Re()))))),t}function Xi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,3).toLowerCase()==="ttl"?(t=s.substr(e,3),e+=3):(t=null,u('"ttl"')),t!==null?(r=k(),r!==null?(o=Os(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.ttl=m}(c,t[2])),t===null&&(e=c),t}function Qi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,5).toLowerCase()==="maddr"?(t=s.substr(e,5),e+=5):(t=null,u('"maddr"')),t!==null?(r=k(),r!==null?(o=Jt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.maddr=m}(c,t[2])),t===null&&(e=c),t}function Zi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,8).toLowerCase()==="received"?(t=s.substr(e,8),e+=8):(t=null,u('"received"')),t!==null?(r=k(),r!==null?(o=Xt(),o===null&&(o=ps()),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.received=m}(c,t[2])),t===null&&(e=c),t}function eo(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="branch"?(t=s.substr(e,6),e+=6):(t=null,u('"branch"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.branch=m}(c,t[2])),t===null&&(e=c),t}function to(){var t,r,o,c,h;return c=e,s.substr(e,5).toLowerCase()==="rport"?(t=s.substr(e,5),e+=5):(t=null,u('"rport"')),t!==null?(h=e,r=k(),r!==null?(o=no(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function no(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.rport=parseInt(C.join(""))}(p,t)),t===null&&(e=p),t}function so(){var t,r,o,c,h,p;return p=e,t=ro(),t!==null?(r=V(),r!==null?(o=I(),o!==null?(c=V(),c!==null?(h=io(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function ro(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null&&(t=function(o,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function io(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="udp"?(t=s.substr(e,3),e+=3):(t=null,u('"UDP"')),t===null&&(s.substr(e,3).toLowerCase()==="tcp"?(t=s.substr(e,3),e+=3):(t=null,u('"TCP"')),t===null&&(s.substr(e,3).toLowerCase()==="tls"?(t=s.substr(e,3),e+=3):(t=null,u('"TLS"')),t===null&&(s.substr(e,4).toLowerCase()==="sctp"?(t=s.substr(e,4),e+=4):(t=null,u('"SCTP"')),t===null&&(t=I())))),t!==null&&(t=function(o,c){v.transport=c}(r,t)),t===null&&(e=r),t}function oo(){var t,r,o,c,h;return c=e,t=lo(),t!==null?(h=e,r=Ge(),r!==null?(o=ao(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function lo(){var t,r;return r=e,t=Xt(),t===null&&(t=_s(),t===null&&(t=hs())),t!==null&&(t=function(o){v.host=s.substring(e,o)}(r)),t===null&&(e=r),t}function ao(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.port=parseInt(C.join(""))}(p,t)),t===null&&(e=p),t}function Os(){var t,r,o,c,h;return c=e,h=e,t=f(),t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){return parseInt(m.join(""))}(c,t)),t===null&&(e=c),t}function Wu(){var t;return t=Cs(),t}function Yu(){var t,r,o,c,h,p;if(h=e,t=uo(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function uo(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v.expires=c}(r,t)),t===null&&(e=r),t}function Ns(){var t;return t=co(),t===null&&(t=Re()),t}function co(){var t,r,o,c,h;return c=e,h=e,s.substr(e,9).toLowerCase()==="refresher"?(t=s.substr(e,9),e+=9):(t=null,u('"refresher"')),t!==null?(r=k(),r!==null?(s.substr(e,3).toLowerCase()==="uac"?(o=s.substr(e,3),e+=3):(o=null,u('"uac"')),o===null&&(s.substr(e,3).toLowerCase()==="uas"?(o=s.substr(e,3),e+=3):(o=null,u('"uas"'))),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.refresher=m.toLowerCase()}(c,t[2])),t===null&&(e=c),t}function zu(){var t,r,o,c;return c=e,t=I(),t!==null?(r=H(),r!==null?(o=ho(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ho(){var t,r;for(t=[],r=F(),r===null&&(r=W(),r===null&&(r=fe()));r!==null;)t.push(r),r=F(),r===null&&(r=W(),r===null&&(r=fe()));return t}function Ju(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function Xu(){var t,r,o;return o=e,s.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=_o(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function _o(){var t,r,o,c,h,p,m,E,C,ne,Ee;return ne=e,Ee=e,t=po(),t!==null?(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(o=lt(),o!==null?(s.charCodeAt(e)===45?(c="-",e++):(c=null,u('"-"')),c!==null?(h=lt(),h!==null?(s.charCodeAt(e)===45?(p="-",e++):(p=null,u('"-"')),p!==null?(m=lt(),m!==null?(s.charCodeAt(e)===45?(E="-",e++):(E=null,u('"-"')),E!==null?(C=fo(),C!==null?t=[t,r,o,c,h,p,m,E,C]:(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee),t!==null&&(t=function(at,qn){v=s.substring(e+5,at)}(ne,t[0])),t===null&&(e=ne),t}function lt(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(o=y(),o!==null?(c=y(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function po(){var t,r,o;return o=e,t=lt(),t!==null?(r=lt(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function fo(){var t,r,o,c;return c=e,t=lt(),t!==null?(r=lt(),r!==null?(o=lt(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Qu(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){try{v=new Ht(v.uri,v.display_name,v.params)}catch{v=-1}}()),t===null&&(e=h),t}function Zu(){var t,r,o,c,h,p;if(h=e,t=mo(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function mo(){var t,r,o,c,h,p;return c=e,h=e,t=Ke(),t!==null?(p=e,s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ke(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.call_id=s.substring(e,m)}(c)),t===null&&(e=c),t}function Ds(){var t;return t=go(),t===null&&(t=To(),t===null&&(t=vo(),t===null&&(t=Re()))),t}function go(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6)==="to-tag"?(t="to-tag",e+=6):(t=null,u('"to-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.to_tag=m}(c,t[2])),t===null&&(e=c),t}function To(){var t,r,o,c,h;return c=e,h=e,s.substr(e,8)==="from-tag"?(t="from-tag",e+=8):(t=null,u('"from-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.from_tag=m}(c,t[2])),t===null&&(e=c),t}function vo(){var t,r;return r=e,s.substr(e,10)==="early-only"?(t="early-only",e+=10):(t=null,u('"early-only"')),t!==null&&(t=function(o){v.early_only=!0}()),t===null&&(e=r),t}function ec(t){t.sort();for(var r=null,o=[],c=0;c<t.length;c++)t[c]!==r&&(o.push(t[c]),r=t[c]);return o}function tc(){for(var t=1,r=1,o=!1,c=0;c<Math.max(e,d);c++){var h=s.charAt(c);h===`
4
+ `?(o||t++,r=1,o=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(t++,r=1,o=!0):(r++,o=!1)}return{line:t,column:r}}var yo=jn(),Ht=Pl(),v={},nc=a[i]();if(nc===null||e!==s.length){var ks=Math.max(e,d),sc=ks<s.length?s.charAt(ks):null,Eo=tc();return new this.SyntaxError(ec(_),sc,ks,Eo.line,Eo.column),-1}return v},toSource:function(){return this._source}};return n.SyntaxError=function(s,i,a,e,d){function _(u,g){var f,T;switch(u.length){case 0:f="end of input";break;case 1:f=u[0];break;default:f=u.slice(0,u.length-1).join(", ")+" or "+u[u.length-1]}return T=g?l(g):"end of input","Expected "+f+" but "+T+" found."}this.name="SyntaxError",this.expected=s,this.found=i,this.message=_(s,i),this.offset=a,this.line=e,this.column=d},n.SyntaxError.prototype=Error.prototype,n}()),uc}var xl,hc;function jn(){if(hc)return xl;hc=1;function l(g,f){var T;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(T=n(g))||f&&g&&typeof g.length=="number"){T&&(g=T);var y=0,A=function(){};return{s:A,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(G){throw G},f:A}}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 w=!0,b=!1,R;return{s:function(){T=g[Symbol.iterator]()},n:function(){var G=T.next();return w=G.done,G},e:function(G){b=!0,R=G},f:function(){try{!w&&T.return!=null&&T.return()}finally{if(b)throw R}}}}function n(g,f){if(g){if(typeof g=="string")return s(g,f);var T=Object.prototype.toString.call(g).slice(8,-1);if(T==="Object"&&g.constructor&&(T=g.constructor.name),T==="Map"||T==="Set")return Array.from(g);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return s(g,f)}}function s(g,f){(f==null||f>g.length)&&(f=g.length);for(var T=0,y=new Array(f);T<f;T++)y[T]=g[T];return y}function i(g,f){if(!(g instanceof f))throw new TypeError("Cannot call a class as a function")}function a(g,f){for(var T=0;T<f.length;T++){var y=f[T];y.enumerable=y.enumerable||!1,y.configurable=!0,"value"in y&&(y.writable=!0),Object.defineProperty(g,y.key,y)}}function e(g,f,T){return f&&a(g.prototype,f),T&&a(g,T),g}var d=nt,_=At(),u=ln();return xl=function(){e(g,null,[{key:"parse",value:function(f){if(f=u.parse(f,"SIP_URI"),f!==-1)return f}}]);function g(f,T,y,A){var w=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},b=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(i(this,g),!y)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=f||d.SIP,this._user=T,this._host=y,this._port=A;for(var R in w)Object.prototype.hasOwnProperty.call(w,R)&&this.setParam(R,w[R]);for(var G in b)Object.prototype.hasOwnProperty.call(b,G)&&this.setHeader(G,b[G])}return e(g,[{key:"setParam",value:function(f,T){f&&(this._parameters[f.toLowerCase()]=typeof T>"u"||T===null?null:T.toString())}},{key:"getParam",value:function(f){if(f)return this._parameters[f.toLowerCase()]}},{key:"hasParam",value:function(f){if(f)return this._parameters.hasOwnProperty(f.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(f){if(f=f.toLowerCase(),this._parameters.hasOwnProperty(f)){var T=this._parameters[f];return delete this._parameters[f],T}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(f,T){this._headers[_.headerize(f)]=Array.isArray(T)?T:[T]}},{key:"getHeader",value:function(f){if(f)return this._headers[_.headerize(f)]}},{key:"hasHeader",value:function(f){if(f)return this._headers.hasOwnProperty(_.headerize(f))&&!0||!1}},{key:"deleteHeader",value:function(f){if(f=_.headerize(f),this._headers.hasOwnProperty(f)){var T=this._headers[f];return delete this._headers[f],T}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new g(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 f=[],T="".concat(this._scheme,":");this._user&&(T+="".concat(_.escapeUser(this._user),"@")),T+=this._host,(this._port||this._port===0)&&(T+=":".concat(this._port));for(var y in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,y)&&(T+=";".concat(y),this._parameters[y]!==null&&(T+="=".concat(this._parameters[y])));for(var A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var w=l(this._headers[A]),b;try{for(w.s();!(b=w.n()).done;){var R=b.value;f.push("".concat(A,"=").concat(R))}}catch(G){w.e(G)}finally{w.f()}}return f.length>0&&(T+="?".concat(f.join("&"))),T}},{key:"toAor",value:function(f){var T="".concat(this._scheme,":");return this._user&&(T+="".concat(_.escapeUser(this._user),"@")),T+=this._host,f&&(this._port||this._port===0)&&(T+=":".concat(this._port)),T}},{key:"scheme",get:function(){return this._scheme},set:function(f){this._scheme=f.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(f){this._user=f}},{key:"host",get:function(){return this._host},set:function(f){this._host=f.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(f){this._port=f===0?f:parseInt(f,10)||null}}]),g}(),xl}var dc;function At(){if(dc)return Qe;dc=1;function l(f){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?l=function(T){return typeof T}:l=function(T){return T&&typeof Symbol=="function"&&T.constructor===Symbol&&T!==Symbol.prototype?"symbol":typeof T},l(f)}function n(f,T){var y;if(typeof Symbol>"u"||f[Symbol.iterator]==null){if(Array.isArray(f)||(y=s(f))||T&&f&&typeof f.length=="number"){y&&(f=y);var A=0,w=function(){};return{s:w,n:function(){return A>=f.length?{done:!0}:{done:!1,value:f[A++]}},e:function(x){throw x},f:w}}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 b=!0,R=!1,G;return{s:function(){y=f[Symbol.iterator]()},n:function(){var x=y.next();return b=x.done,x},e:function(x){R=!0,G=x},f:function(){try{!b&&y.return!=null&&y.return()}finally{if(R)throw G}}}}function s(f,T){if(f){if(typeof f=="string")return i(f,T);var y=Object.prototype.toString.call(f).slice(8,-1);if(y==="Object"&&f.constructor&&(y=f.constructor.name),y==="Map"||y==="Set")return Array.from(f);if(y==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(y))return i(f,T)}}function i(f,T){(T==null||T>f.length)&&(T=f.length);for(var y=0,A=new Array(T);y<T;y++)A[y]=f[y];return A}var a=nt,e=jn(),d=ln();Qe.str_utf8_length=function(f){return unescape(encodeURIComponent(f)).length};var _=Qe.isFunction=function(f){return f!==void 0?Object.prototype.toString.call(f)==="[object Function]":!1};Qe.isString=function(f){return f!==void 0?Object.prototype.toString.call(f)==="[object String]":!1},Qe.isDecimal=function(f){return!isNaN(f)&&parseFloat(f)===parseInt(f,10)},Qe.isEmpty=function(f){return f===null||f===""||f===void 0||Array.isArray(f)&&f.length===0||typeof f=="number"&&isNaN(f)},Qe.hasMethods=function(f){for(var T=arguments.length,y=new Array(T>1?T-1:0),A=1;A<T;A++)y[A-1]=arguments[A];for(var w=0,b=y;w<b.length;w++){var R=b[w];if(_(f[R]))return!1}return!0};var u=Qe.createRandomToken=function(f){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,y,A,w="";for(y=0;y<f;y++)A=Math.random()*T|0,w+=A.toString(T);return w};Qe.newTag=function(){return u(10)},Qe.newUUID=function(){var f="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var y=Math.random()*16|0,A=T==="x"?y:y&3|8;return A.toString(16)});return f},Qe.hostType=function(f){if(f){if(f=d.parse(f,"host"),f!==-1)return f.host_type}else return};var g=Qe.escapeUser=function(f){return encodeURIComponent(decodeURIComponent(f)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Qe.normalizeTarget=function(f,T){if(f){if(f instanceof e)return f;if(typeof f=="string"){var y=f.split("@"),A,w;switch(y.length){case 1:if(!T)return;A=f,w=T;break;case 2:A=y[0],w=y[1];break;default:A=y.slice(0,y.length-1).join("@"),w=y[y.length-1]}A=A.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(A)&&(A=A.replace(/[-.()]/g,"")),f="".concat(a.SIP,":").concat(g(A),"@").concat(w);var b;return(b=e.parse(f))?b:void 0}else return}else return},Qe.headerize=function(f){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},y=f.toLowerCase().replace(/_/g,"-").split("-"),A="",w=y.length,b;for(b=0;b<w;b++)b!==0&&(A+="-"),A+=y[b].charAt(0).toUpperCase()+y[b].substring(1);return T[A]&&(A=T[A]),A},Qe.sipErrorCause=function(f){for(var T in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[T].indexOf(f)!==-1)return a.causes[T];return a.causes.SIP_FAILURE_CODE},Qe.getRandomTestNetIP=function(){function f(T,y){return Math.floor(Math.random()*(y-T+1)+T)}return"192.0.2.".concat(f(1,254))},Qe.calculateMD5=function(f){function T(he,ie){return he<<ie|he>>>32-ie}function y(he,ie){var Te=he&2147483648,we=ie&2147483648,$e=he&1073741824,it=ie&1073741824,xe=(he&1073741823)+(ie&1073741823);return $e&it?xe^2147483648^Te^we:$e|it?xe&1073741824?xe^3221225472^Te^we:xe^1073741824^Te^we:xe^Te^we}function A(he,ie,Te){return he&ie|~he&Te}function w(he,ie,Te){return he&Te|ie&~Te}function b(he,ie,Te){return he^ie^Te}function R(he,ie,Te){return ie^(he|~Te)}function G(he,ie,Te,we,$e,it,xe){return he=y(he,y(y(A(ie,Te,we),$e),xe)),y(T(he,it),ie)}function x(he,ie,Te,we,$e,it,xe){return he=y(he,y(y(w(ie,Te,we),$e),xe)),y(T(he,it),ie)}function me(he,ie,Te,we,$e,it,xe){return he=y(he,y(y(b(ie,Te,we),$e),xe)),y(T(he,it),ie)}function O(he,ie,Te,we,$e,it,xe){return he=y(he,y(y(R(ie,Te,we),$e),xe)),y(T(he,it),ie)}function $(he){for(var ie,Te=he.length,we=Te+8,$e=(we-we%64)/64,it=($e+1)*16,xe=new Array(it-1),Pt=0,wt=0;wt<Te;)ie=(wt-wt%4)/4,Pt=wt%4*8,xe[ie]=xe[ie]|he.charCodeAt(wt)<<Pt,wt++;return ie=(wt-wt%4)/4,Pt=wt%4*8,xe[ie]=xe[ie]|128<<Pt,xe[it-2]=Te<<3,xe[it-1]=Te>>>29,xe}function de(he){var ie="",Te="",we,$e;for($e=0;$e<=3;$e++)we=he>>>$e*8&255,Te="0".concat(we.toString(16)),ie=ie+Te.substr(Te.length-2,2);return ie}function fe(he){for(var ie="",Te=0;Te<he.length;Te++){var we=he.charCodeAt(Te);we<128?ie+=String.fromCharCode(we):we>127&&we<2048?(ie+=String.fromCharCode(we>>6|192),ie+=String.fromCharCode(we&63|128)):(ie+=String.fromCharCode(we>>12|224),ie+=String.fromCharCode(we>>6&63|128),ie+=String.fromCharCode(we&63|128))}return ie}var N=[],H,j,F,P,W,ee,I,X,te,Ke=7,Q=12,V=17,k=22,ve=5,_e=9,Ae=14,Ue=20,ce=4,re=11,Ge=16,tt=23,ge=6,pe=10,Se=15,be=21;for(f=fe(f),N=$(f),ee=1732584193,I=4023233417,X=2562383102,te=271733878,H=0;H<N.length;H+=16)j=ee,F=I,P=X,W=te,ee=G(ee,I,X,te,N[H+0],Ke,3614090360),te=G(te,ee,I,X,N[H+1],Q,3905402710),X=G(X,te,ee,I,N[H+2],V,606105819),I=G(I,X,te,ee,N[H+3],k,3250441966),ee=G(ee,I,X,te,N[H+4],Ke,4118548399),te=G(te,ee,I,X,N[H+5],Q,1200080426),X=G(X,te,ee,I,N[H+6],V,2821735955),I=G(I,X,te,ee,N[H+7],k,4249261313),ee=G(ee,I,X,te,N[H+8],Ke,1770035416),te=G(te,ee,I,X,N[H+9],Q,2336552879),X=G(X,te,ee,I,N[H+10],V,4294925233),I=G(I,X,te,ee,N[H+11],k,2304563134),ee=G(ee,I,X,te,N[H+12],Ke,1804603682),te=G(te,ee,I,X,N[H+13],Q,4254626195),X=G(X,te,ee,I,N[H+14],V,2792965006),I=G(I,X,te,ee,N[H+15],k,1236535329),ee=x(ee,I,X,te,N[H+1],ve,4129170786),te=x(te,ee,I,X,N[H+6],_e,3225465664),X=x(X,te,ee,I,N[H+11],Ae,643717713),I=x(I,X,te,ee,N[H+0],Ue,3921069994),ee=x(ee,I,X,te,N[H+5],ve,3593408605),te=x(te,ee,I,X,N[H+10],_e,38016083),X=x(X,te,ee,I,N[H+15],Ae,3634488961),I=x(I,X,te,ee,N[H+4],Ue,3889429448),ee=x(ee,I,X,te,N[H+9],ve,568446438),te=x(te,ee,I,X,N[H+14],_e,3275163606),X=x(X,te,ee,I,N[H+3],Ae,4107603335),I=x(I,X,te,ee,N[H+8],Ue,1163531501),ee=x(ee,I,X,te,N[H+13],ve,2850285829),te=x(te,ee,I,X,N[H+2],_e,4243563512),X=x(X,te,ee,I,N[H+7],Ae,1735328473),I=x(I,X,te,ee,N[H+12],Ue,2368359562),ee=me(ee,I,X,te,N[H+5],ce,4294588738),te=me(te,ee,I,X,N[H+8],re,2272392833),X=me(X,te,ee,I,N[H+11],Ge,1839030562),I=me(I,X,te,ee,N[H+14],tt,4259657740),ee=me(ee,I,X,te,N[H+1],ce,2763975236),te=me(te,ee,I,X,N[H+4],re,1272893353),X=me(X,te,ee,I,N[H+7],Ge,4139469664),I=me(I,X,te,ee,N[H+10],tt,3200236656),ee=me(ee,I,X,te,N[H+13],ce,681279174),te=me(te,ee,I,X,N[H+0],re,3936430074),X=me(X,te,ee,I,N[H+3],Ge,3572445317),I=me(I,X,te,ee,N[H+6],tt,76029189),ee=me(ee,I,X,te,N[H+9],ce,3654602809),te=me(te,ee,I,X,N[H+12],re,3873151461),X=me(X,te,ee,I,N[H+15],Ge,530742520),I=me(I,X,te,ee,N[H+2],tt,3299628645),ee=O(ee,I,X,te,N[H+0],ge,4096336452),te=O(te,ee,I,X,N[H+7],pe,1126891415),X=O(X,te,ee,I,N[H+14],Se,2878612391),I=O(I,X,te,ee,N[H+5],be,4237533241),ee=O(ee,I,X,te,N[H+12],ge,1700485571),te=O(te,ee,I,X,N[H+3],pe,2399980690),X=O(X,te,ee,I,N[H+10],Se,4293915773),I=O(I,X,te,ee,N[H+1],be,2240044497),ee=O(ee,I,X,te,N[H+8],ge,1873313359),te=O(te,ee,I,X,N[H+15],pe,4264355552),X=O(X,te,ee,I,N[H+6],Se,2734768916),I=O(I,X,te,ee,N[H+13],be,1309151649),ee=O(ee,I,X,te,N[H+4],ge,4149444226),te=O(te,ee,I,X,N[H+11],pe,3174756917),X=O(X,te,ee,I,N[H+2],Se,718787259),I=O(I,X,te,ee,N[H+9],be,3951481745),ee=y(ee,j),I=y(I,F),X=y(X,P),te=y(te,W);var De=de(ee)+de(I)+de(X)+de(te);return De.toLowerCase()},Qe.closeMediaStream=function(f){if(f)try{var T;if(f.getTracks){T=f.getTracks();var y=n(T),A;try{for(y.s();!(A=y.n()).done;){var w=A.value;w.stop()}}catch($){y.e($)}finally{y.f()}}else{T=f.getAudioTracks();var b=n(T),R;try{for(b.s();!(R=b.n()).done;){var G=R.value;G.stop()}}catch($){b.e($)}finally{b.f()}T=f.getVideoTracks();var x=n(T),me;try{for(x.s();!(me=x.n()).done;){var O=me.value;O.stop()}}catch($){x.e($)}finally{x.f()}}}catch{(typeof f.stop=="function"||l(f.stop)==="object")&&f.stop()}},Qe.cloneArray=function(f){return f&&f.slice()||[]},Qe.cloneObject=function(f){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return f&&Object.assign({},f)||T},Qe}var Ll={exports:{}},Ps=typeof Reflect=="object"?Reflect:null,_c=Ps&&typeof Ps.apply=="function"?Ps.apply:function(l,n,s){return Function.prototype.apply.call(l,n,s)},wo;Ps&&typeof Ps.ownKeys=="function"?wo=Ps.ownKeys:Object.getOwnPropertySymbols?wo=function(l){return Object.getOwnPropertyNames(l).concat(Object.getOwnPropertySymbols(l))}:wo=function(l){return Object.getOwnPropertyNames(l)};function x_(l){console&&console.warn&&console.warn(l)}var pc=Number.isNaN||function(l){return l!==l};function Me(){Me.init.call(this)}Ll.exports=Me,Ll.exports.once=F_,Me.EventEmitter=Me,Me.prototype._events=void 0,Me.prototype._eventsCount=0,Me.prototype._maxListeners=void 0;var fc=10;function Oo(l){if(typeof l!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof l)}Object.defineProperty(Me,"defaultMaxListeners",{enumerable:!0,get:function(){return fc},set:function(l){if(typeof l!="number"||l<0||pc(l))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+l+".");fc=l}}),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(l){if(typeof l!="number"||l<0||pc(l))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+l+".");return this._maxListeners=l,this};function mc(l){return l._maxListeners===void 0?Me.defaultMaxListeners:l._maxListeners}Me.prototype.getMaxListeners=function(){return mc(this)},Me.prototype.emit=function(l){for(var n=[],s=1;s<arguments.length;s++)n.push(arguments[s]);var i=l==="error",a=this._events;if(a!==void 0)i=i&&a.error===void 0;else if(!i)return!1;if(i){var e;if(n.length>0&&(e=n[0]),e instanceof Error)throw e;var d=new Error("Unhandled error."+(e?" ("+e.message+")":""));throw d.context=e,d}var _=a[l];if(_===void 0)return!1;if(typeof _=="function")_c(_,this,n);else for(var u=_.length,g=Ec(_,u),s=0;s<u;++s)_c(g[s],this,n);return!0};function gc(l,n,s,i){var a,e,d;if(Oo(s),e=l._events,e===void 0?(e=l._events=Object.create(null),l._eventsCount=0):(e.newListener!==void 0&&(l.emit("newListener",n,s.listener?s.listener:s),e=l._events),d=e[n]),d===void 0)d=e[n]=s,++l._eventsCount;else if(typeof d=="function"?d=e[n]=i?[s,d]:[d,s]:i?d.unshift(s):d.push(s),a=mc(l),a>0&&d.length>a&&!d.warned){d.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+d.length+" "+String(n)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=l,_.type=n,_.count=d.length,x_(_)}return l}Me.prototype.addListener=function(l,n){return gc(this,l,n,!1)},Me.prototype.on=Me.prototype.addListener,Me.prototype.prependListener=function(l,n){return gc(this,l,n,!0)};function L_(){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 Tc(l,n,s){var i={fired:!1,wrapFn:void 0,target:l,type:n,listener:s},a=L_.bind(i);return a.listener=s,i.wrapFn=a,a}Me.prototype.once=function(l,n){return Oo(n),this.on(l,Tc(this,l,n)),this},Me.prototype.prependOnceListener=function(l,n){return Oo(n),this.prependListener(l,Tc(this,l,n)),this},Me.prototype.removeListener=function(l,n){var s,i,a,e,d;if(Oo(n),i=this._events,i===void 0)return this;if(s=i[l],s===void 0)return this;if(s===n||s.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[l],i.removeListener&&this.emit("removeListener",l,s.listener||n));else if(typeof s!="function"){for(a=-1,e=s.length-1;e>=0;e--)if(s[e]===n||s[e].listener===n){d=s[e].listener,a=e;break}if(a<0)return this;a===0?s.shift():H_(s,a),s.length===1&&(i[l]=s[0]),i.removeListener!==void 0&&this.emit("removeListener",l,d||n)}return this},Me.prototype.off=Me.prototype.removeListener,Me.prototype.removeAllListeners=function(l){var n,s,i;if(s=this._events,s===void 0)return this;if(s.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):s[l]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete s[l]),this;if(arguments.length===0){var a=Object.keys(s),e;for(i=0;i<a.length;++i)e=a[i],e!=="removeListener"&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=s[l],typeof n=="function")this.removeListener(l,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(l,n[i]);return this};function vc(l,n,s){var i=l._events;if(i===void 0)return[];var a=i[n];return a===void 0?[]:typeof a=="function"?s?[a.listener||a]:[a]:s?q_(a):Ec(a,a.length)}Me.prototype.listeners=function(l){return vc(this,l,!0)},Me.prototype.rawListeners=function(l){return vc(this,l,!1)},Me.listenerCount=function(l,n){return typeof l.listenerCount=="function"?l.listenerCount(n):yc.call(l,n)},Me.prototype.listenerCount=yc;function yc(l){var n=this._events;if(n!==void 0){var s=n[l];if(typeof s=="function")return 1;if(s!==void 0)return s.length}return 0}Me.prototype.eventNames=function(){return this._eventsCount>0?wo(this._events):[]};function Ec(l,n){for(var s=new Array(n),i=0;i<n;++i)s[i]=l[i];return s}function H_(l,n){for(;n+1<l.length;n++)l[n]=l[n+1];l.pop()}function q_(l){for(var n=new Array(l.length),s=0;s<n.length;++s)n[s]=l[s].listener||l[s];return n}function F_(l,n){return new Promise(function(s,i){function a(d){l.removeListener(n,e),i(d)}function e(){typeof l.removeListener=="function"&&l.removeListener("error",a),s([].slice.call(arguments))}Sc(l,n,e,{once:!0}),n!=="error"&&j_(l,a,{once:!0})})}function j_(l,n,s){typeof l.on=="function"&&Sc(l,"error",n,s)}function Sc(l,n,s,i){if(typeof l.on=="function")i.once?l.once(n,s):l.on(n,s);else if(typeof l.addEventListener=="function")l.addEventListener(n,function a(e){i.once&&l.removeEventListener(n,a),s(e)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof l)}var ut=Ll.exports,Hl={exports:{}},ql,Ac;function $_(){if(Ac)return ql;Ac=1;var l=1e3,n=l*60,s=n*60,i=s*24,a=i*7,e=i*365.25;ql=function(f,T){T=T||{};var y=typeof f;if(y==="string"&&f.length>0)return d(f);if(y==="number"&&isFinite(f))return T.long?u(f):_(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))};function d(f){if(f=String(f),!(f.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(f);if(T){var y=parseFloat(T[1]),A=(T[2]||"ms").toLowerCase();switch(A){case"years":case"year":case"yrs":case"yr":case"y":return y*e;case"weeks":case"week":case"w":return y*a;case"days":case"day":case"d":return y*i;case"hours":case"hour":case"hrs":case"hr":case"h":return y*s;case"minutes":case"minute":case"mins":case"min":case"m":return y*n;case"seconds":case"second":case"secs":case"sec":case"s":return y*l;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return y;default:return}}}}function _(f){var T=Math.abs(f);return T>=i?Math.round(f/i)+"d":T>=s?Math.round(f/s)+"h":T>=n?Math.round(f/n)+"m":T>=l?Math.round(f/l)+"s":f+"ms"}function u(f){var T=Math.abs(f);return T>=i?g(f,T,i,"day"):T>=s?g(f,T,s,"hour"):T>=n?g(f,T,n,"minute"):T>=l?g(f,T,l,"second"):f+" ms"}function g(f,T,y,A){var w=T>=y*1.5;return Math.round(f/y)+" "+A+(w?"s":"")}return ql}function V_(l){s.debug=s,s.default=s,s.coerce=u,s.disable=e,s.enable=a,s.enabled=d,s.humanize=$_(),s.destroy=g,Object.keys(l).forEach(f=>{s[f]=l[f]}),s.names=[],s.skips=[],s.formatters={};function n(f){let T=0;for(let y=0;y<f.length;y++)T=(T<<5)-T+f.charCodeAt(y),T|=0;return s.colors[Math.abs(T)%s.colors.length]}s.selectColor=n;function s(f){let T,y=null,A,w;function b(...R){if(!b.enabled)return;const G=b,x=Number(new Date),me=x-(T||x);G.diff=me,G.prev=T,G.curr=x,T=x,R[0]=s.coerce(R[0]),typeof R[0]!="string"&&R.unshift("%O");let O=0;R[0]=R[0].replace(/%([a-zA-Z%])/g,($,de)=>{if($==="%%")return"%";O++;const fe=s.formatters[de];if(typeof fe=="function"){const N=R[O];$=fe.call(G,N),R.splice(O,1),O--}return $}),s.formatArgs.call(G,R),(G.log||s.log).apply(G,R)}return b.namespace=f,b.useColors=s.useColors(),b.color=s.selectColor(f),b.extend=i,b.destroy=s.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(A!==s.namespaces&&(A=s.namespaces,w=s.enabled(f)),w),set:R=>{y=R}}),typeof s.init=="function"&&s.init(b),b}function i(f,T){const y=s(this.namespace+(typeof T>"u"?":":T)+f);return y.log=this.log,y}function a(f){s.save(f),s.namespaces=f,s.names=[],s.skips=[];let T;const y=(typeof f=="string"?f:"").split(/[\s,]+/),A=y.length;for(T=0;T<A;T++)y[T]&&(f=y[T].replace(/\*/g,".*?"),f[0]==="-"?s.skips.push(new RegExp("^"+f.slice(1)+"$")):s.names.push(new RegExp("^"+f+"$")))}function e(){const f=[...s.names.map(_),...s.skips.map(_).map(T=>"-"+T)].join(",");return s.enable(""),f}function d(f){if(f[f.length-1]==="*")return!0;let T,y;for(T=0,y=s.skips.length;T<y;T++)if(s.skips[T].test(f))return!1;for(T=0,y=s.names.length;T<y;T++)if(s.names[T].test(f))return!0;return!1}function _(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function u(f){return f instanceof Error?f.stack||f.message:f}function g(){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 s.enable(s.load()),s}var B_=V_;(function(l,n){n.formatArgs=i,n.save=a,n.load=e,n.useColors=s,n.storage=d(),n.destroy=(()=>{let u=!1;return()=>{u||(u=!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`."))}})(),n.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 s(){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 i(u){if(u[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+u[0]+(this.useColors?"%c ":" ")+"+"+l.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;u.splice(1,0,g,"color: inherit");let f=0,T=0;u[0].replace(/%[a-zA-Z%]/g,y=>{y!=="%%"&&(f++,y==="%c"&&(T=f))}),u.splice(T,0,g)}n.log=console.debug||console.log||(()=>{});function a(u){try{u?n.storage.setItem("debug",u):n.storage.removeItem("debug")}catch{}}function e(){let u;try{u=n.storage.getItem("debug")}catch{}return!u&&typeof process<"u"&&"env"in process&&(u=process.env.DEBUG),u}function d(){try{return localStorage}catch{}}l.exports=B_(n);const{formatters:_}=l.exports;_.j=function(u){try{return JSON.stringify(u)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}})(Hl,Hl.exports);var xs=Hl.exports;function K_(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Cc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function G_(l,n,s){return n&&Cc(l.prototype,n),s&&Cc(l,s),l}var Ls=xs,Hs="JsSIP",ct=function(){function l(n){K_(this,l),n?(this._debug=Ls.default("".concat(Hs,":").concat(n)),this._warn=Ls.default("".concat(Hs,":WARN:").concat(n)),this._error=Ls.default("".concat(Hs,":ERROR:").concat(n))):(this._debug=Ls.default(Hs),this._warn=Ls.default("".concat(Hs,":WARN")),this._error=Ls.default("".concat(Hs,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return G_(l,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),l}(),Dt={},bc={},Rc={exports:{}},Ic=Rc.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(l){return l.encoding?"rtpmap:%d %s/%s/%s":l.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(l){return l.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(l){return l.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(l){return"extmap:%d"+(l.direction?"/%s":"%v")+(l["encrypt-uri"]?" %s":"%v")+" %s"+(l.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(l){return l.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(l){var n="candidate:%s %d %s %d %s %d typ %s";return n+=l.raddr!=null?" raddr %s rport %d":"%v%v",n+=l.tcptype!=null?" tcptype %s":"%v",l.generation!=null&&(n+=" generation %d"),n+=l["network-id"]!=null?" network-id %d":"%v",n+=l["network-cost"]!=null?" network-cost %d":"%v",n}},{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(l){var n="ssrc:%d";return l.attribute!=null&&(n+=" %s",l.value!=null&&(n+=":%s")),n}},{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(l){return l.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(l){return l.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(l){return"imageattr:%s %s %s"+(l.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(l){return"simulcast:%s %s"+(l.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(l){return"ts-refclk:%s"+(l.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(l){var n="mediaclk:";return n+=l.id!=null?"id=%s %s":"%v%s",n+=l.mediaClockValue!=null?"=%s":"",n+=l.rateNumerator!=null?" rate=%s":"",n+=l.rateDenominator!=null?"/%s":"",n}},{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(Ic).forEach(function(l){var n=Ic[l];n.forEach(function(s){s.reg||(s.reg=/(.*)/),s.format||(s.format="%s")})});var wc=Rc.exports;(function(l){var n=function(_){return String(Number(_))===_?Number(_):_},s=function(_,u,g,f){if(f&&!g)u[f]=n(_[1]);else for(var T=0;T<g.length;T+=1)_[T+1]!=null&&(u[g[T]]=n(_[T+1]))},i=function(_,u,g){var f=_.name&&_.names;_.push&&!u[_.push]?u[_.push]=[]:f&&!u[_.name]&&(u[_.name]={});var T=_.push?{}:f?u[_.name]:u;s(g.match(_.reg),T,_.names,_.name),_.push&&u[_.push].push(T)},a=wc,e=RegExp.prototype.test.bind(/^([a-z])=(.*)/);l.parse=function(_){var u={},g=[],f=u;return _.split(/(\r\n|\r|\n)/).filter(e).forEach(function(T){var y=T[0],A=T.slice(2);y==="m"&&(g.push({rtp:[],fmtp:[]}),f=g[g.length-1]);for(var w=0;w<(a[y]||[]).length;w+=1){var b=a[y][w];if(b.reg.test(A))return i(b,f,A)}}),u.media=g,u};var d=function(_,u){var g=u.split(/=(.+)/,2);return g.length===2?_[g[0]]=n(g[1]):g.length===1&&u.length>1&&(_[g[0]]=void 0),_};l.parseParams=function(_){return _.split(/;\s?/).reduce(d,{})},l.parseFmtpConfig=l.parseParams,l.parsePayloads=function(_){return _.toString().split(" ").map(Number)},l.parseRemoteCandidates=function(_){for(var u=[],g=_.split(" ").map(n),f=0;f<g.length;f+=3)u.push({component:g[f],ip:g[f+1],port:g[f+2]});return u},l.parseImageAttributes=function(_){return _.split(" ").map(function(u){return u.substring(1,u.length-1).split(",").reduce(d,{})})},l.parseSimulcastStreamList=function(_){return _.split(";").map(function(u){return u.split(",").map(function(g){var f,T=!1;return g[0]!=="~"?f=n(g):(f=n(g.substring(1,g.length)),T=!0),{scid:f,paused:T}})})}})(bc);var Fl=wc,W_=/%[sdv%]/g,Y_=function(l){var n=1,s=arguments,i=s.length;return l.replace(W_,function(a){if(n>=i)return a;var e=s[n];switch(n+=1,a){case"%%":return"%";case"%s":return String(e);case"%d":return Number(e);case"%v":return""}})},Xs=function(l,n,s){var i=n.format instanceof Function?n.format(n.push?s:s[n.name]):n.format,a=[l+"="+i];if(n.names)for(var e=0;e<n.names.length;e+=1){var d=n.names[e];n.name?a.push(s[n.name][d]):a.push(s[n.names[e]])}else a.push(s[n.name]);return Y_.apply(null,a)},z_=["v","o","s","i","u","e","p","c","b","t","r","z","a"],J_=["i","c","b","a"],X_=function(l,n){n=n||{},l.version==null&&(l.version=0),l.name==null&&(l.name=" "),l.media.forEach(function(e){e.payloads==null&&(e.payloads="")});var s=n.outerOrder||z_,i=n.innerOrder||J_,a=[];return s.forEach(function(e){Fl[e].forEach(function(d){d.name in l&&l[d.name]!=null?a.push(Xs(e,d,l)):d.push in l&&l[d.push]!=null&&l[d.push].forEach(function(_){a.push(Xs(e,d,_))})})}),l.media.forEach(function(e){a.push(Xs("m",Fl.m[0],e)),i.forEach(function(d){Fl[d].forEach(function(_){_.name in e&&e[_.name]!=null?a.push(Xs(d,_,e)):_.push in e&&e[_.push]!=null&&e[_.push].forEach(function(u){a.push(Xs(d,_,u))})})})}),a.join(`\r
7
7
  `)+`\r
8
- `},ss=Uc,sf=nf;Pt.write=sf,Pt.parse=ss.parse,Pt.parseParams=ss.parseParams,Pt.parseFmtpConfig=ss.parseFmtpConfig,Pt.parsePayloads=ss.parsePayloads,Pt.parseRemoteCandidates=ss.parseRemoteCandidates,Pt.parseImageAttributes=ss.parseImageAttributes,Pt.parseSimulcastStreamList=ss.parseSimulcastStreamList;function Lo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Lo=function(s){return typeof s}:Lo=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Lo(l)}function Xl(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&Ql(l,s)}function Ql(l,s){return Ql=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},Ql(l,s)}function Jl(l){var s=lf();return function(){var n=Ho(l),i;if(s){var a=Ho(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return rf(this,i)}}function rf(l,s){return s&&(Lo(s)==="object"||typeof s=="function")?s:of(l)}function of(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function lf(){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(l){return!1}}function Ho(l){return Ho=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Ho(l)}function Kt(l,s){var n;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(n=af(l))||s&&l&&typeof l.length=="number"){n&&(l=n);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){n=l[Symbol.iterator]()},n:function(){var u=n.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&n.return!=null&&n.return()}finally{if(d)throw _}}}}function af(l,s){if(l){if(typeof l=="string")return Lc(l,s);var n=Object.prototype.toString.call(l).slice(8,-1);if(n==="Object"&&l.constructor&&(n=l.constructor.name),n==="Map"||n==="Set")return Array.from(l);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Lc(l,s)}}function Lc(l,s){(s==null||s>l.length)&&(s=l.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=l[n];return i}function ir(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Hc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function qo(l,s,n){return s&&Hc(l.prototype,s),n&&Hc(l,n),l}var qc=Pt,uf=ft,gt=lt,at=wt(),Fc=Bl(),cf=dn(),Zl=new uf("SIPMessage"),jc=function(){function l(s,n,i,a,e,d){if(ir(this,l),!s||!n||!i)return null;a=a||{},this.ua=i,this.headers={},this.method=s,this.ruri=n,this.body=d,this.extraHeaders=at.cloneArray(e),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):i.configuration.use_preloaded_route&&this.setHeader("route","<".concat(i.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",gt.MAX_FORWARDS);var _=a.to_uri||n,u=a.to_tag?{tag:a.to_tag}:null,g=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new Fc(_,g,u),this.setHeader("to",this.to.toString());var p=a.from_uri||i.configuration.uri,T={tag:a.from_tag||at.newTag()},y;typeof a.from_display_name<"u"?y=a.from_display_name:i.configuration.display_name?y=i.configuration.display_name:y=null,this.from=new Fc(p,y,T),this.setHeader("from",this.from.toString());var A=a.call_id||i.configuration.jssip_id+at.createRandomToken(15);this.call_id=A,this.setHeader("call-id",A);var w=a.cseq||Math.floor(Math.random()*1e4);this.cseq=w,this.setHeader("cseq","".concat(w," ").concat(s))}return qo(l,[{key:"setHeader",value:function(s,n){for(var i=new RegExp("^\\s*".concat(s,"\\s*:"),"i"),a=0;a<this.extraHeaders.length;a++)i.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[at.headerize(s)]=Array.isArray(n)?n:[n]}},{key:"getHeader",value:function(s){var n=this.headers[at.headerize(s)];if(n){if(n[0])return n[0]}else{var i=new RegExp("^\\s*".concat(s,"\\s*:"),"i"),a=Kt(this.extraHeaders),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;if(i.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(_){a.e(_)}finally{a.f()}}}},{key:"getHeaders",value:function(s){var n=this.headers[at.headerize(s)],i=[];if(n){var a=Kt(n),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i.push(d)}}catch(T){a.e(T)}finally{a.f()}return i}else{var _=new RegExp("^\\s*".concat(s,"\\s*:"),"i"),u=Kt(this.extraHeaders),g;try{for(u.s();!(g=u.n()).done;){var p=g.value;_.test(p)&&i.push(p.substring(p.indexOf(":")+1).trim())}}catch(T){u.e(T)}finally{u.f()}return i}}},{key:"hasHeader",value:function(s){if(this.headers[at.headerize(s)])return!0;var n=new RegExp("^\\s*".concat(s,"\\s*:"),"i"),i=Kt(this.extraHeaders),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;if(n.test(e))return!0}}catch(d){i.e(d)}finally{i.f()}return!1}},{key:"parseSDP",value:function(s){return!s&&this.sdp?this.sdp:(this.sdp=qc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var s="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
- `);for(var n in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,n)){var i=Kt(this.headers[n]),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;s+="".concat(n,": ").concat(e,`\r
11
- `)}}catch(y){i.e(y)}finally{i.f()}}var d=Kt(this.extraHeaders),_;try{for(d.s();!(_=d.n()).done;){var u=_.value;s+="".concat(u.trim(),`\r
12
- `)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case gt.REGISTER:g.push("path","gruu");break;case gt.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 gt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var p=this.ua.configuration.user_agent||gt.USER_AGENT;if(s+="Allow: ".concat(gt.ALLOWED_METHODS,`\r
13
- `),s+="Supported: ".concat(g,`\r
14
- `),s+="User-Agent: ".concat(p,`\r
15
- `),this.body){var T=at.str_utf8_length(this.body);s+="Content-Length: ".concat(T,`\r
8
+ `},Qn=bc,Q_=X_;Dt.write=Q_,Dt.parse=Qn.parse,Dt.parseParams=Qn.parseParams,Dt.parseFmtpConfig=Qn.parseFmtpConfig,Dt.parsePayloads=Qn.parsePayloads,Dt.parseRemoteCandidates=Qn.parseRemoteCandidates,Dt.parseImageAttributes=Qn.parseImageAttributes,Dt.parseSimulcastStreamList=Qn.parseSimulcastStreamList;function No(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?No=function(n){return typeof n}:No=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},No(l)}function jl(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&$l(l,n)}function $l(l,n){return $l=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},$l(l,n)}function Vl(l){var n=tp();return function(){var s=Do(l),i;if(n){var a=Do(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return Z_(this,i)}}function Z_(l,n){return n&&(No(n)==="object"||typeof n=="function")?n:ep(l)}function ep(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function tp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Do(l){return Do=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Do(l)}function qt(l,n){var s;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(s=np(l))||n&&l&&typeof l.length=="number"){s&&(l=s);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){s=l[Symbol.iterator]()},n:function(){var u=s.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&s.return!=null&&s.return()}finally{if(d)throw _}}}}function np(l,n){if(l){if(typeof l=="string")return Oc(l,n);var s=Object.prototype.toString.call(l).slice(8,-1);if(s==="Object"&&l.constructor&&(s=l.constructor.name),s==="Map"||s==="Set")return Array.from(l);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return Oc(l,n)}}function Oc(l,n){(n==null||n>l.length)&&(n=l.length);for(var s=0,i=new Array(n);s<n;s++)i[s]=l[s];return i}function Qs(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Nc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function ko(l,n,s){return n&&Nc(l.prototype,n),s&&Nc(l,s),l}var Dc=Dt,sp=ct,dt=nt,st=At(),kc=Pl(),rp=ln(),Bl=new sp("SIPMessage"),Uc=function(){function l(n,s,i,a,e,d){if(Qs(this,l),!n||!s||!i)return null;a=a||{},this.ua=i,this.headers={},this.method=n,this.ruri=s,this.body=d,this.extraHeaders=st.cloneArray(e),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):i.configuration.use_preloaded_route&&this.setHeader("route","<".concat(i.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",dt.MAX_FORWARDS);var _=a.to_uri||s,u=a.to_tag?{tag:a.to_tag}:null,g=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new kc(_,g,u),this.setHeader("to",this.to.toString());var f=a.from_uri||i.configuration.uri,T={tag:a.from_tag||st.newTag()},y;typeof a.from_display_name<"u"?y=a.from_display_name:i.configuration.display_name?y=i.configuration.display_name:y=null,this.from=new kc(f,y,T),this.setHeader("from",this.from.toString());var A=a.call_id||i.configuration.jssip_id+st.createRandomToken(15);this.call_id=A,this.setHeader("call-id",A);var w=a.cseq||Math.floor(Math.random()*1e4);this.cseq=w,this.setHeader("cseq","".concat(w," ").concat(n))}return ko(l,[{key:"setHeader",value:function(n,s){for(var i=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),a=0;a<this.extraHeaders.length;a++)i.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[st.headerize(n)]=Array.isArray(s)?s:[s]}},{key:"getHeader",value:function(n){var s=this.headers[st.headerize(n)];if(s){if(s[0])return s[0]}else{var i=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),a=qt(this.extraHeaders),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;if(i.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(_){a.e(_)}finally{a.f()}}}},{key:"getHeaders",value:function(n){var s=this.headers[st.headerize(n)],i=[];if(s){var a=qt(s),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i.push(d)}}catch(T){a.e(T)}finally{a.f()}return i}else{var _=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),u=qt(this.extraHeaders),g;try{for(u.s();!(g=u.n()).done;){var f=g.value;_.test(f)&&i.push(f.substring(f.indexOf(":")+1).trim())}}catch(T){u.e(T)}finally{u.f()}return i}}},{key:"hasHeader",value:function(n){if(this.headers[st.headerize(n)])return!0;var s=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),i=qt(this.extraHeaders),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;if(s.test(e))return!0}}catch(d){i.e(d)}finally{i.f()}return!1}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=Dc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var n="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
+ `);for(var s in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,s)){var i=qt(this.headers[s]),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;n+="".concat(s,": ").concat(e,`\r
11
+ `)}}catch(y){i.e(y)}finally{i.f()}}var d=qt(this.extraHeaders),_;try{for(d.s();!(_=d.n()).done;){var u=_.value;n+="".concat(u.trim(),`\r
12
+ `)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case dt.REGISTER:g.push("path","gruu");break;case dt.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case dt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var f=this.ua.configuration.user_agent||dt.USER_AGENT;if(n+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
13
+ `),n+="Supported: ".concat(g,`\r
14
+ `),n+="User-Agent: ".concat(f,`\r
15
+ `),this.body){var T=st.str_utf8_length(this.body);n+="Content-Length: ".concat(T,`\r
16
16
  \r
17
- `),s+=this.body}else s+=`Content-Length: 0\r
17
+ `),n+=this.body}else n+=`Content-Length: 0\r
18
18
  \r
19
- `;return s}},{key:"clone",value:function(){var s=new l(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){s.headers[n]=this.headers[n].slice()},this),s.body=this.body,s.extraHeaders=at.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s}}]),l}(),hf=function(l){Xl(n,l);var s=Jl(n);function n(i,a,e,d,_){var u;return ir(this,n),u=s.call(this,gt.INVITE,i,a,e,d,_),u.transaction=null,u}return qo(n,[{key:"cancel",value:function(i){this.transaction.cancel(i)}},{key:"clone",value:function(){var i=new n(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(a){i.headers[a]=this.headers[a].slice()},this),i.body=this.body,i.extraHeaders=at.cloneArray(this.extraHeaders),i.to=this.to,i.from=this.from,i.call_id=this.call_id,i.cseq=this.cseq,i.transaction=this.transaction,i}}]),n}(jc),$c=function(){function l(){ir(this,l),this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}return qo(l,[{key:"addHeader",value:function(s,n){var i={raw:n};s=at.headerize(s),this.headers[s]?this.headers[s].push(i):this.headers[s]=[i]}},{key:"getHeader",value:function(s){var n=this.headers[at.headerize(s)];if(n){if(n[0])return n[0].raw}else return}},{key:"getHeaders",value:function(s){var n=this.headers[at.headerize(s)],i=[];if(!n)return[];var a=Kt(n),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i.push(d.raw)}}catch(_){a.e(_)}finally{a.f()}return i}},{key:"hasHeader",value:function(s){return!!this.headers[at.headerize(s)]}},{key:"parseHeader",value:function(s){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(s=at.headerize(s),this.headers[s]){if(n>=this.headers[s].length){Zl.debug('not so many "'.concat(s,'" headers present'));return}}else{Zl.debug('header "'.concat(s,'" not present'));return}var i=this.headers[s][n],a=i.raw;if(i.parsed)return i.parsed;var e=cf.parse(a,s.replace(/-/g,"_"));if(e===-1){this.headers[s].splice(n,1),Zl.debug('error parsing "'.concat(s,'" header field with value "').concat(a,'"'));return}else return i.parsed=e,e}},{key:"s",value:function(s,n){return this.parseHeader(s,n)}},{key:"setHeader",value:function(s,n){var i={raw:n};this.headers[at.headerize(s)]=[i]}},{key:"parseSDP",value:function(s){return!s&&this.sdp?this.sdp:(this.sdp=qc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),l}(),df=function(l){Xl(n,l);var s=Jl(n);function n(i){var a;return ir(this,n),a=s.call(this),a.ua=i,a.headers={},a.ruri=null,a.transport=null,a.server_transaction=null,a}return qo(n,[{key:"reply",value:function(i,a,e,d,_,u){var g=[],p=this.getHeader("To");if(i=i||null,a=a||null,!i||i<100||i>699)throw new TypeError("Invalid status_code: ".concat(i));if(a&&typeof a!="string"&&!(a instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(a));a=a||gt.REASON_PHRASE[i]||"",e=at.cloneArray(e),this.ua.configuration.extra_headers&&(e=e.concat(this.ua.configuration.extra_headers));var T="SIP/2.0 ".concat(i," ").concat(a,`\r
20
- `);if(this.method===gt.INVITE&&i>100&&i<=200){var y=this.getHeaders("record-route"),A=Kt(y),w;try{for(A.s();!(w=A.n()).done;){var R=w.value;T+="Record-Route: ".concat(R,`\r
21
- `)}}catch(N){A.e(N)}finally{A.f()}}var b=this.getHeaders("via"),G=Kt(b),P;try{for(G.s();!(P=G.n()).done;){var ye=P.value;T+="Via: ".concat(ye,`\r
22
- `)}}catch(N){G.e(N)}finally{G.f()}!this.to_tag&&i>100?p+=";tag=".concat(at.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(p+=";tag=".concat(this.to_tag)),T+="To: ".concat(p,`\r
19
+ `;return n}},{key:"clone",value:function(){var n=new l(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){n.headers[s]=this.headers[s].slice()},this),n.body=this.body,n.extraHeaders=st.cloneArray(this.extraHeaders),n.to=this.to,n.from=this.from,n.call_id=this.call_id,n.cseq=this.cseq,n}}]),l}(),ip=function(l){jl(s,l);var n=Vl(s);function s(i,a,e,d,_){var u;return Qs(this,s),u=n.call(this,dt.INVITE,i,a,e,d,_),u.transaction=null,u}return ko(s,[{key:"cancel",value:function(i){this.transaction.cancel(i)}},{key:"clone",value:function(){var i=new s(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(a){i.headers[a]=this.headers[a].slice()},this),i.body=this.body,i.extraHeaders=st.cloneArray(this.extraHeaders),i.to=this.to,i.from=this.from,i.call_id=this.call_id,i.cseq=this.cseq,i.transaction=this.transaction,i}}]),s}(Uc),Mc=function(){function l(){Qs(this,l),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 ko(l,[{key:"addHeader",value:function(n,s){var i={raw:s};n=st.headerize(n),this.headers[n]?this.headers[n].push(i):this.headers[n]=[i]}},{key:"getHeader",value:function(n){var s=this.headers[st.headerize(n)];if(s){if(s[0])return s[0].raw}else return}},{key:"getHeaders",value:function(n){var s=this.headers[st.headerize(n)],i=[];if(!s)return[];var a=qt(s),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i.push(d.raw)}}catch(_){a.e(_)}finally{a.f()}return i}},{key:"hasHeader",value:function(n){return!!this.headers[st.headerize(n)]}},{key:"parseHeader",value:function(n){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=st.headerize(n),this.headers[n]){if(s>=this.headers[n].length){Bl.debug('not so many "'.concat(n,'" headers present'));return}}else{Bl.debug('header "'.concat(n,'" not present'));return}var i=this.headers[n][s],a=i.raw;if(i.parsed)return i.parsed;var e=rp.parse(a,n.replace(/-/g,"_"));if(e===-1){this.headers[n].splice(s,1),Bl.debug('error parsing "'.concat(n,'" header field with value "').concat(a,'"'));return}else return i.parsed=e,e}},{key:"s",value:function(n,s){return this.parseHeader(n,s)}},{key:"setHeader",value:function(n,s){var i={raw:s};this.headers[st.headerize(n)]=[i]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=Dc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),l}(),op=function(l){jl(s,l);var n=Vl(s);function s(i){var a;return Qs(this,s),a=n.call(this),a.ua=i,a.headers={},a.ruri=null,a.transport=null,a.server_transaction=null,a}return ko(s,[{key:"reply",value:function(i,a,e,d,_,u){var g=[],f=this.getHeader("To");if(i=i||null,a=a||null,!i||i<100||i>699)throw new TypeError("Invalid status_code: ".concat(i));if(a&&typeof a!="string"&&!(a instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(a));a=a||dt.REASON_PHRASE[i]||"",e=st.cloneArray(e),this.ua.configuration.extra_headers&&(e=e.concat(this.ua.configuration.extra_headers));var T="SIP/2.0 ".concat(i," ").concat(a,`\r
20
+ `);if(this.method===dt.INVITE&&i>100&&i<=200){var y=this.getHeaders("record-route"),A=qt(y),w;try{for(A.s();!(w=A.n()).done;){var b=w.value;T+="Record-Route: ".concat(b,`\r
21
+ `)}}catch(N){A.e(N)}finally{A.f()}}var R=this.getHeaders("via"),G=qt(R),x;try{for(G.s();!(x=G.n()).done;){var me=x.value;T+="Via: ".concat(me,`\r
22
+ `)}}catch(N){G.e(N)}finally{G.f()}!this.to_tag&&i>100?f+=";tag=".concat(st.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(f+=";tag=".concat(this.to_tag)),T+="To: ".concat(f,`\r
23
23
  `),T+="From: ".concat(this.getHeader("From"),`\r
24
24
  `),T+="Call-ID: ".concat(this.call_id,`\r
25
25
  `),T+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
26
- `);var O=Kt(e),j;try{for(O.s();!(j=O.n()).done;){var pe=j.value;T+="".concat(pe.trim(),`\r
27
- `)}}catch(N){O.e(N)}finally{O.f()}switch(this.method){case gt.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 gt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),d&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===gt.OPTIONS?(T+="Allow: ".concat(gt.ALLOWED_METHODS,`\r
28
- `),T+="Accept: ".concat(gt.ACCEPTED_BODY_TYPES,`\r
29
- `)):i===405?T+="Allow: ".concat(gt.ALLOWED_METHODS,`\r
30
- `):i===415&&(T+="Accept: ".concat(gt.ACCEPTED_BODY_TYPES,`\r
26
+ `);var O=qt(e),$;try{for(O.s();!($=O.n()).done;){var de=$.value;T+="".concat(de.trim(),`\r
27
+ `)}}catch(N){O.e(N)}finally{O.f()}switch(this.method){case dt.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case dt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),d&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===dt.OPTIONS?(T+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
28
+ `),T+="Accept: ".concat(dt.ACCEPTED_BODY_TYPES,`\r
29
+ `)):i===405?T+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
30
+ `):i===415&&(T+="Accept: ".concat(dt.ACCEPTED_BODY_TYPES,`\r
31
31
  `)),T+="Supported: ".concat(g,`\r
32
- `),d){var Te=at.str_utf8_length(d);T+=`Content-Type: application/sdp\r
33
- `,T+="Content-Length: ".concat(Te,`\r
32
+ `),d){var fe=st.str_utf8_length(d);T+=`Content-Type: application/sdp\r
33
+ `,T+="Content-Length: ".concat(fe,`\r
34
34
  \r
35
35
  `),T+=d}else T+="Content-Length: ".concat(0,`\r
36
36
  \r
37
- `);this.server_transaction.receiveResponse(i,T,_,u)}},{key:"reply_sl",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,e=this.getHeaders("via");if(!i||i<100||i>699)throw new TypeError("Invalid status_code: ".concat(i));if(a&&typeof a!="string"&&!(a instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(a));a=a||gt.REASON_PHRASE[i]||"";var d="SIP/2.0 ".concat(i," ").concat(a,`\r
38
- `),_=Kt(e),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;d+="Via: ".concat(g,`\r
39
- `)}}catch(w){_.e(w)}finally{_.f()}var p=this.getHeader("To");if(!this.to_tag&&i>100?p+=";tag=".concat(at.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(p+=";tag=".concat(this.to_tag)),d+="To: ".concat(p,`\r
37
+ `);this.server_transaction.receiveResponse(i,T,_,u)}},{key:"reply_sl",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,e=this.getHeaders("via");if(!i||i<100||i>699)throw new TypeError("Invalid status_code: ".concat(i));if(a&&typeof a!="string"&&!(a instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(a));a=a||dt.REASON_PHRASE[i]||"";var d="SIP/2.0 ".concat(i," ").concat(a,`\r
38
+ `),_=qt(e),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;d+="Via: ".concat(g,`\r
39
+ `)}}catch(w){_.e(w)}finally{_.f()}var f=this.getHeader("To");if(!this.to_tag&&i>100?f+=";tag=".concat(st.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(f+=";tag=".concat(this.to_tag)),d+="To: ".concat(f,`\r
40
40
  `),d+="From: ".concat(this.getHeader("From"),`\r
41
41
  `),d+="Call-ID: ".concat(this.call_id,`\r
42
42
  `),d+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
43
- `),this.ua.configuration.extra_headers){var T=Kt(this.ua.configuration.extra_headers),y;try{for(T.s();!(y=T.n()).done;){var A=y.value;d+="".concat(A.trim(),`\r
43
+ `),this.ua.configuration.extra_headers){var T=qt(this.ua.configuration.extra_headers),y;try{for(T.s();!(y=T.n()).done;){var A=y.value;d+="".concat(A.trim(),`\r
44
44
  `)}}catch(w){T.e(w)}finally{T.f()}}d+="Content-Length: ".concat(0,`\r
45
45
  \r
46
- `),this.transport.send(d)}}]),n}($c),_f=function(l){Xl(n,l);var s=Jl(n);function n(){var i;return ir(this,n),i=s.call(this),i.headers={},i.status_code=null,i.reason_phrase=null,i}return n}($c),Tn={OutgoingRequest:jc,InitialOutgoingInviteRequest:hf,IncomingRequest:df,IncomingResponse:_f};function ff(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Vc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function pf(l,s,n){return s&&Vc(l.prototype,s),n&&Vc(l,n),l}var mf=ft,vn=wt(),zt=new mf("DigestAuthentication"),gf=function(){function l(s){ff(this,l),this._credentials=s,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return pf(l,[{key:"get",value:function(s){switch(s){case"realm":return this._realm;case"ha1":return this._ha1;default:zt.warn('get() | cannot get "%s" parameter',s);return}}},{key:"authenticate",value:function(s,n){var i=s.method,a=s.ruri,e=s.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=n.algorithm,this._realm=n.realm,this._nonce=n.nonce,this._opaque=n.opaque,this._stale=n.stale,this._algorithm){if(this._algorithm!=="MD5")return zt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return zt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return zt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return zt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return zt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(n.qop)if(n.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(n.qop.indexOf("auth")>-1)this._qop="auth";else return zt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=i,this._uri=a,this._cnonce=d||vn.createRandomToken(12),this._nc+=1;var _=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-_.length)+_,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=vn.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var u,g;return this._qop==="auth"?(u="".concat(this._method,":").concat(this._uri),g=vn.calculateMD5(u),zt.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=vn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(u="".concat(this._method,":").concat(this._uri,":").concat(vn.calculateMD5(e||"")),g=vn.calculateMD5(u),zt.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=vn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(u="".concat(this._method,":").concat(this._uri),g=vn.calculateMD5(u),zt.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=vn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),zt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var s=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return s.push("algorithm=".concat(this._algorithm)),s.push('username="'.concat(this._credentials.username,'"')),s.push('realm="'.concat(this._realm,'"')),s.push('nonce="'.concat(this._nonce,'"')),s.push('uri="'.concat(this._uri,'"')),s.push('response="'.concat(this._response,'"')),this._opaque&&s.push('opaque="'.concat(this._opaque,'"')),this._qop&&(s.push("qop=".concat(this._qop)),s.push('cnonce="'.concat(this._cnonce,'"')),s.push("nc=".concat(this._ncHex))),"Digest ".concat(s.join(", "))}}]),l}(),yn=500,Tf=4e3,Bc=5e3,Kc={T1:yn,T2:Tf,T4:Bc,TIMER_B:64*yn,TIMER_D:0*yn,TIMER_F:64*yn,TIMER_H:64*yn,TIMER_I:0*yn,TIMER_J:0*yn,TIMER_K:0*Bc,TIMER_L:64*yn,TIMER_M:64*yn,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Fo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fo=function(s){return typeof s}:Fo=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Fo(l)}function or(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Gc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function lr(l,s,n){return s&&Gc(l.prototype,s),n&&Gc(l,n),l}function ar(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&ea(l,s)}function ea(l,s){return ea=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ea(l,s)}function ur(l){var s=yf();return function(){var n=jo(l),i;if(s){var a=jo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return vf(this,i)}}function vf(l,s){return s&&(Fo(s)==="object"||typeof s=="function")?s:Wn(l)}function Wn(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function yf(){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(l){return!1}}function jo(l){return jo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},jo(l)}var cr=_t.EventEmitter,hr=ft,dr=lt,Wc=Tn,_n=Kc,Yc=new hr("NonInviteClientTransaction"),$o=new hr("InviteClientTransaction"),Ef=new hr("AckClientTransaction"),zc=new hr("NonInviteServerTransaction"),Vo=new hr("InviteServerTransaction"),ue={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},Sf=function(l){ar(n,l);var s=ur(n);function n(i,a,e,d){var _;or(this,n),_=s.call(this),_.type=ue.NON_INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=i,_.transport=a,_.request=e,_.eventHandlers=d;var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_.ua.newTransaction(Wn(_)),_}return lr(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"send",value:function(){var i=this;this.stateChanged(ue.STATUS_TRYING),this.F=setTimeout(function(){i.timer_F()},_n.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Yc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Yc.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(i){var a=this,e=i.status_code;if(e<200)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(i);break}else switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),clearTimeout(this.F),e===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(i),this.K=setTimeout(function(){a.timer_K()},_n.TIMER_K);break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(cr),Af=function(l){ar(n,l);var s=ur(n);function n(i,a,e,d){var _;or(this,n),_=s.call(this),_.type=ue.INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=i,_.transport=a,_.request=e,_.eventHandlers=d,e.transaction=Wn(_);var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_.ua.newTransaction(Wn(_)),_}return lr(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"send",value:function(){var i=this;this.stateChanged(ue.STATUS_CALLING),this.B=setTimeout(function(){i.timer_B()},_n.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ue.STATUS_ACCEPTED&&($o.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){$o.debug("Timer M expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){$o.debug("Timer B expired for transaction ".concat(this.id)),this.state===ue.STATUS_CALLING&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){$o.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(i){var a=this,e=new Wc.OutgoingRequest(dr.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});e.setHeader("from",this.request.getHeader("from")),e.setHeader("via",this.request.getHeader("via")),e.setHeader("to",i.getHeader("to")),this.D=setTimeout(function(){a.timer_D()},_n.TIMER_D),this.transport.send(e)}},{key:"cancel",value:function(i){if(this.state===ue.STATUS_PROCEEDING){var a=new Wc.OutgoingRequest(dr.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});a.setHeader("from",this.request.getHeader("from")),a.setHeader("via",this.request.getHeader("via")),a.setHeader("to",this.request.getHeader("to")),i&&a.setHeader("reason",i),this.transport.send(a)}}},{key:"receiveResponse",value:function(i){var a=this,e=i.status_code;if(e>=100&&e<=199)switch(this.state){case ue.STATUS_CALLING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(i);break;case ue.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(i);break}else if(e>=200&&e<=299)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.M=setTimeout(function(){a.timer_M()},_n.TIMER_M),this.eventHandlers.onReceiveResponse(i);break;case ue.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(i);break}else if(e>=300&&e<=699)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.sendACK(i),this.eventHandlers.onReceiveResponse(i);break;case ue.STATUS_COMPLETED:this.sendACK(i);break}}},{key:"C",get:function(){return ue}}]),n}(cr),Cf=function(l){ar(n,l);var s=ur(n);function n(i,a,e,d){var _;or(this,n),_=s.call(this),_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.transport=a,_.request=e,_.eventHandlers=d;var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_}return lr(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Ef.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ue}}]),n}(cr),bf=function(l){ar(n,l);var s=ur(n);function n(i,a,e){var d;return or(this,n),d=s.call(this),d.type=ue.NON_INVITE_SERVER,d.id=e.via_branch,d.ua=i,d.transport=a,d.request=e,d.last_response="",e.server_transaction=Wn(d),d.state=ue.STATUS_TRYING,i.newTransaction(Wn(d)),d}return lr(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_J",value:function(){zc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,zc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(i,a,e,d){var _=this;if(i===100)switch(this.state){case ue.STATUS_TRYING:this.stateChanged(ue.STATUS_PROCEEDING),this.transport.send(a)||this.onTransportError();break;case ue.STATUS_PROCEEDING:this.last_response=a,this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break}else if(i>=200&&i<=699)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.last_response=a,this.J=setTimeout(function(){_.timer_J()},_n.TIMER_J),this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(cr),Rf=function(l){ar(n,l);var s=ur(n);function n(i,a,e){var d;return or(this,n),d=s.call(this),d.type=ue.INVITE_SERVER,d.id=e.via_branch,d.ua=i,d.transport=a,d.request=e,d.last_response="",e.server_transaction=Wn(d),d.state=ue.STATUS_PROCEEDING,i.newTransaction(Wn(d)),d.resendProvisionalTimer=null,e.reply(100),d}return lr(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_H",value:function(){Vo.debug("Timer H expired for transaction ".concat(this.id)),this.state===ue.STATUS_COMPLETED&&Vo.debug("ACK not received, dialog will be terminated"),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Vo.debug("Timer L expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Vo.debug("transport error occurred, deleting transaction ".concat(this.id)),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(i,a,e,d){var _=this;if(i>=100&&i<=199)switch(this.state){case ue.STATUS_PROCEEDING:this.transport.send(a)||this.onTransportError(),this.last_response=a;break}if(i>100&&i<=199&&this.state===ue.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){_.resend_provisional()},_n.PROVISIONAL_RESPONSE_INTERVAL));else if(i>=200&&i<=299)switch(this.state){case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.last_response=a,this.L=setTimeout(function(){_.timer_L()},_n.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ue.STATUS_ACCEPTED:this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break}else if(i>=300&&i<=699)switch(this.state){case ue.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(a)?(this.stateChanged(ue.STATUS_COMPLETED),this.H=setTimeout(function(){_.timer_H()},_n.TIMER_H),e&&e()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return ue}}]),n}(cr);function If(l,s){var n=l._transactions,i;switch(s.method){case dr.INVITE:if(i=n.ist[s.via_branch],i){switch(i.state){case ue.STATUS_PROCEEDING:i.transport.send(i.last_response);break;case ue.STATUS_ACCEPTED:break}return!0}break;case dr.ACK:if(i=n.ist[s.via_branch],i){if(i.state===ue.STATUS_ACCEPTED)return!1;if(i.state===ue.STATUS_COMPLETED)return i.state=ue.STATUS_CONFIRMED,i.I=setTimeout(function(){i.timer_I()},_n.TIMER_I),!0}else return!1;break;case dr.CANCEL:return i=n.ist[s.via_branch],i?(s.reply_sl(200),i.state!==ue.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(i=n.nist[s.via_branch],i){switch(i.state){case ue.STATUS_TRYING:break;case ue.STATUS_PROCEEDING:case ue.STATUS_COMPLETED:i.transport.send(i.last_response);break}return!0}break}}var _r={C:ue,NonInviteClientTransaction:Sf,InviteClientTransaction:Af,AckClientTransaction:Cf,NonInviteServerTransaction:bf,InviteServerTransaction:Rf,checkTransaction:If};function wf(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Xc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Of(l,s,n){return s&&Xc(l.prototype,s),n&&Xc(l,n),l}var Nf=ft,Qc=lt,Df=gf,ta=_r,kf=new Nf("RequestSender"),na={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},fr=function(){function l(s,n,i){wf(this,l),this._ua=s,this._eventHandlers=i,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var a in na)Object.prototype.hasOwnProperty.call(na,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=na[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==Qc.BYE||this._method!==Qc.ACK)&&this._eventHandlers.onTransportError()}return Of(l,[{key:"send",value:function(){var s=this,n={onRequestTimeout:function(){s._eventHandlers.onRequestTimeout()},onTransportError:function(){s._eventHandlers.onTransportError()},onReceiveResponse:function(i){s._receiveResponse(i)}};switch(this._method){case"INVITE":this.clientTransaction=new ta.InviteClientTransaction(this._ua,this._ua.transport,this._request,n);break;case"ACK":this.clientTransaction=new ta.AckClientTransaction(this._ua,this._ua.transport,this._request,n);break;default:this.clientTransaction=new ta.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,n)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(s){var n,i,a=s.status_code;if((a===401||a===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(s.status_code===401?(n=s.parseHeader("www-authenticate"),i="authorization"):(n=s.parseHeader("proxy-authenticate"),i="proxy-authorization"),!n){kf.debug("".concat(s.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(s);return}if(!this._challenged||!this._staled&&n.stale===!0){if(this._auth||(this._auth=new Df({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(s);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","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(i,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(s)}else this._eventHandlers.onReceiveResponse(s)}}]),l}();function Uf(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Jc(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Mf(l,s,n){return s&&Jc(l.prototype,s),n&&Jc(l,n),l}var xf=ft,sa=wt(),rs=lt,Zc=Tn,eh=fr,pr=new xf("Registrator"),Bo=10,Pf=function(){function l(s,n){Uf(this,l),this._reg_id=1,this._ua=s,this._transport=n,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=sa.createRandomToken(22),this._cseq=0,this._to_uri=s.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return Mf(l,[{key:"setExtraHeaders",value:function(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}},{key:"setExtraContactParams",value:function(s){s instanceof Object||(s={}),this._extraContactParams="";for(var n in s)if(Object.prototype.hasOwnProperty.call(s,n)){var i=s[n];this._extraContactParams+=";".concat(n),i&&(this._extraContactParams+="=".concat(i))}}},{key:"register",value:function(){var s=this;if(this._registering){pr.debug("Register request in progress...");return}var n=this._extraHeaders.slice();n.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),n.push("Expires: ".concat(this._expires));var i=new Zc.OutgoingRequest(rs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n),a=new eh(this._ua,i,{onRequestTimeout:function(){s._registrationFailure(null,rs.causes.REQUEST_TIMEOUT)},onTransportError:function(){s._registrationFailure(null,rs.causes.CONNECTION_ERROR)},onAuthenticated:function(){s._cseq+=1},onReceiveResponse:function(e){if(e.cseq===s._cseq)switch(s._registrationTimer!==null&&(clearTimeout(s._registrationTimer),s._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):{if(s._registering=!1,!e.hasHeader("Contact")){pr.debug("no Contact header in response to REGISTER, response ignored");break}var d=e.headers.Contact.reduce(function(T,y){return T.concat(y.parsed)},[]),_=d.find(function(T){return s._sipInstance===T.getParam("+sip.instance")&&s._reg_id===parseInt(T.getParam("reg-id"))});if(_||(_=d.find(function(T){return T.uri.user===s._ua.contact.uri.user})),!_){pr.debug("no Contact header pointing to us, response ignored");break}var u=_.getParam("expires");!u&&e.hasHeader("expires")&&(u=e.getHeader("expires")),u||(u=s._expires),u=Number(u),u<Bo&&(u=Bo);var g=u>64?u*1e3/2+Math.floor((u/2-32)*1e3*Math.random()):u*1e3-5e3;s._registrationTimer=setTimeout(function(){s._registrationTimer=null,s._ua.listeners("registrationExpiring").length===0?s.register():s._ua.emit("registrationExpiring")},g),_.hasParam("temp-gruu")&&(s._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(s._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),s._registered||(s._registered=!0,s._ua.registered({response:e}));break}case/^423$/.test(e.status_code):{e.hasHeader("min-expires")?(s._expires=Number(e.getHeader("min-expires")),s._expires<Bo&&(s._expires=Bo),s.register()):(pr.debug("423 response received for REGISTER without Min-Expires"),s._registrationFailure(e,rs.causes.SIP_FAILURE_CODE));break}default:{var p=sa.sipErrorCause(e.status_code);s._registrationFailure(e,p)}}}});this._registering=!0,a.send()}},{key:"unregister",value:function(){var s=this,n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){pr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var i=this._extraHeaders.slice();n.all?i.push("Contact: *".concat(this._extraContactParams)):i.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),i.push("Expires: 0");var a=new Zc.OutgoingRequest(rs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},i),e=new eh(this._ua,a,{onRequestTimeout:function(){s._unregistered(null,rs.causes.REQUEST_TIMEOUT)},onTransportError:function(){s._unregistered(null,rs.causes.CONNECTION_ERROR)},onAuthenticated:function(){s._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):s._unregistered(d);break;default:{var _=sa.sipErrorCause(d.status_code);s._unregistered(d,_)}}}});e.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(s,n){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:n}))}},{key:"_unregistered",value:function(s,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:n||null})}},{key:"registered",get:function(){return this._registered}}]),l}();function Lf(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function th(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Hf(l,s,n){return s&&th(l.prototype,s),n&&th(l,n),l}var ra=lt,Ko=_r,qf=fr,ia={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},Ff=function(){function l(s,n,i){Lf(this,l),this._dialog=s,this._ua=s._ua,this._request=n,this._eventHandlers=i,this._reattempt=!1,this._reattemptTimer=null;for(var a in ia)Object.prototype.hasOwnProperty.call(ia,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=ia[a]))}return Hf(l,[{key:"send",value:function(){var s=this,n=new qf(this._ua,this._request,{onRequestTimeout:function(){s._eventHandlers.onRequestTimeout()},onTransportError:function(){s._eventHandlers.onTransportError()},onAuthenticated:function(a){s._eventHandlers.onAuthenticated(a)},onReceiveResponse:function(a){s._receiveResponse(a)}});if(n.send(),(this._request.method===ra.INVITE||this._request.method===ra.UPDATE&&this._request.body)&&n.clientTransaction.state!==Ko.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var i=function a(){(n.clientTransaction.state===Ko.C.STATUS_ACCEPTED||n.clientTransaction.state===Ko.C.STATUS_COMPLETED||n.clientTransaction.state===Ko.C.STATUS_TERMINATED)&&(n.clientTransaction.removeListener("stateChanged",a),s._dialog.uac_pending_reply=!1)};n.clientTransaction.on("stateChanged",i)}}},{key:"_receiveResponse",value:function(s){var n=this;s.status_code===408||s.status_code===481?this._eventHandlers.onDialogError(s):s.method===ra.INVITE&&s.status_code===491?this._reattempt?s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){n._dialog.isTerminated()||(n._reattempt=!0,n.send())},1e3)):s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s)}},{key:"request",get:function(){return this._request}}]),l}();function jf(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function nh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function sh(l,s,n){return s&&nh(l.prototype,s),n&&nh(l,n),l}var $f=ft,rh=Tn,Yn=lt,mr=_r,Vf=Ff,oa=wt(),la=new $f("Dialog"),zn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Bf=function(){sh(l,null,[{key:"C",get:function(){return zn}}]);function l(s,n,i){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:zn.STATUS_CONFIRMED;if(jf(this,l),this._owner=s,this._ua=s._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 rh.IncomingResponse&&(a=n.status_code<200?zn.STATUS_EARLY:zn.STATUS_CONFIRMED);var e=n.parseHeader("contact");i==="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=e.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):i==="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=e.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),la.debug("new ".concat(i," dialog created with status ").concat(this._state===zn.STATUS_EARLY?"EARLY":"CONFIRMED"))}return sh(l,[{key:"isTerminated",value:function(){return this._status===zn.STATUS_TERMINATED}},{key:"update",value:function(s,n){this._state=zn.STATUS_CONFIRMED,la.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),n==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){la.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=zn.STATUS_TERMINATED}},{key:"sendRequest",value:function(s){var n=this,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=oa.cloneArray(i.extraHeaders),e=oa.cloneObject(i.eventHandlers),d=i.body||null,_=this._createRequest(s,a,d);e.onAuthenticated=function(){n._local_seqnum+=1};var u=new Vf(this,_,e);return u.send(),_}},{key:"receiveRequest",value:function(s){this._checkInDialogRequest(s)&&(s.method===Yn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===Yn.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}},{key:"_createRequest",value:function(s,n,i){n=oa.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var a=s===Yn.CANCEL||s===Yn.ACK?this._local_seqnum:this._local_seqnum+=1,e=new rh.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,i);return e}},{key:"_checkInDialogRequest",value:function(s){var n=this;if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===Yn.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===Yn.INVITE||s.method===Yn.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){var i=(Math.random()*10|0)+1;return s.reply(500,null,["Retry-After:".concat(i)]),!1}else{this._uas_pending_reply=!0;var a=function e(){(s.server_transaction.state===mr.C.STATUS_ACCEPTED||s.server_transaction.state===mr.C.STATUS_COMPLETED||s.server_transaction.state===mr.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",e),n._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",a)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",function(){s.server_transaction.state===mr.C.STATUS_ACCEPTED&&(n._remote_target=s.parseHeader("contact").uri)})}else s.method===Yn.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",function(){s.server_transaction.state===mr.C.STATUS_COMPLETED&&(n._remote_target=s.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(s){this._local_seqnum=s}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(s){this._uac_pending_reply=s}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),l}(),aa={exports:{}};function Go(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Go=function(s){return typeof s}:Go=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Go(l)}function Kf(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function ih(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Gf(l,s,n){return s&&ih(l.prototype,s),n&&ih(l,n),l}function Wf(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&ua(l,s)}function ua(l,s){return ua=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ua(l,s)}function Yf(l){var s=Qf();return function(){var n=Wo(l),i;if(s){var a=Wo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return zf(this,i)}}function zf(l,s){return s&&(Go(s)==="object"||typeof s=="function")?s:Xf(l)}function Xf(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Qf(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(l){return!1}}function Wo(l){return Wo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Wo(l)}var Jf=_t.EventEmitter,Zf=ft,ep=lt,tp=Kn,oh=wt(),np=new Zf("RTCSession:DTMF"),lh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};aa.exports=function(l){Wf(n,l);var s=Yf(n);function n(i){var a;return Kf(this,n),a=s.call(this),a._session=i,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return Gf(n,[{key:"send",value:function(i){var a=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(i===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 tp.InvalidStateError(this._session.status);var d=oh.cloneArray(e.extraHeaders);if(this.eventHandlers=oh.cloneObject(e.eventHandlers),typeof i=="string")i=i.toUpperCase();else if(typeof i=="number")i=i.toString();else throw new TypeError("Invalid tone: ".concat(i));if(i.match(/^[0-9A-DR#*]$/))this._tone=i;else throw new TypeError("Invalid tone: ".concat(i));this._duration=e.duration,d.push("Content-Type: application/dtmf-relay");var _="Signal=".concat(this._tone,`\r
47
- `);_+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(ep.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(u){a.emit("succeeded",{originator:"remote",response:u})},onErrorResponse:function(u){a.eventHandlers.onFailed&&a.eventHandlers.onFailed(),a.emit("failed",{originator:"remote",response:u})},onRequestTimeout:function(){a._session.onRequestTimeout()},onTransportError:function(){a._session.onTransportError()},onDialogError:function(){a._session.onDialogError()}},body:_})}},{key:"init_incoming",value:function(i){var a=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,e=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=i,i.reply(200),i.body){var d=i.body.split(`
48
- `);d.length>=1&&a.test(d[0])&&(this._tone=d[0].replace(a,"$2")),d.length>=2&&e.test(d[1])&&(this._duration=parseInt(d[1].replace(e,"$2"),10))}this._duration||(this._duration=lh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:i}):np.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(Jf),aa.exports.C=lh;var sp=aa.exports;function Yo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Yo=function(s){return typeof s}:Yo=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Yo(l)}function rp(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function ah(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function ip(l,s,n){return s&&ah(l.prototype,s),n&&ah(l,n),l}function op(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&ca(l,s)}function ca(l,s){return ca=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ca(l,s)}function lp(l){var s=cp();return function(){var n=zo(l),i;if(s){var a=zo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return ap(this,i)}}function ap(l,s){return s&&(Yo(s)==="object"||typeof s=="function")?s:up(l)}function up(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function cp(){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(l){return!1}}function zo(l){return zo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},zo(l)}var hp=_t.EventEmitter,dp=lt,_p=Kn,fp=wt(),pp=function(l){op(n,l);var s=lp(n);function n(i){var a;return rp(this,n),a=s.call(this),a._session=i,a._direction=null,a._contentType=null,a._body=null,a}return ip(n,[{key:"send",value:function(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",i===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=i,this._body=a;var _=fp.cloneArray(d.extraHeaders);_.push("Content-Type: ".concat(i)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(dp.INFO,{extraHeaders:_,eventHandlers:{onSuccessResponse:function(u){e.emit("succeeded",{originator:"remote",response:u})},onErrorResponse:function(u){e.emit("failed",{originator:"remote",response:u})},onTransportError:function(){e._session.onTransportError()},onRequestTimeout:function(){e._session.onRequestTimeout()},onDialogError:function(){e._session.onDialogError()}},body:a})}},{key:"init_incoming",value:function(i){this._direction="incoming",this.request=i,i.reply(200),this._contentType=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,this._body=i.body,this._session.newInfo({originator:"remote",info:this,request:i})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(hp);function mp(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function uh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function gp(l,s,n){return s&&uh(l.prototype,s),n&&uh(l,n),l}var Tp=ft,ch=lt,vp=new Tp("RTCSession:ReferNotifier"),ha={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},yp=function(){function l(s,n,i){mp(this,l),this._session=s,this._id=n,this._expires=i||ha.expires,this._active=!0,this.notify(100)}return gp(l,[{key:"notify",value:function(s,n){if(vp.debug("notify()"),this._active!==!1){n=n||ch.REASON_PHRASE[s]||"";var i;s>=200?i="terminated;reason=noresource":i="active;expires=".concat(this._expires),this._session.sendRequest(ch.NOTIFY,{extraHeaders:["Event: ".concat(ha.event_type,";id=").concat(this._id),"Subscription-State: ".concat(i),"Content-Type: ".concat(ha.body_type)],body:"SIP/2.0 ".concat(s," ").concat(n),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),l}();function Xo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Xo=function(s){return typeof s}:Xo=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Xo(l)}function Ep(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function hh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Sp(l,s,n){return s&&hh(l.prototype,s),n&&hh(l,n),l}function Ap(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&da(l,s)}function da(l,s){return da=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},da(l,s)}function Cp(l){var s=Ip();return function(){var n=Qo(l),i;if(s){var a=Qo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return bp(this,i)}}function bp(l,s){return s&&(Xo(s)==="object"||typeof s=="function")?s:Rp(l)}function Rp(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}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(l){return!1}}function Qo(l){return Qo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Qo(l)}var wp=_t.EventEmitter,Op=ft,gr=lt,Np=dn(),dh=wt(),is=new Op("RTCSession:ReferSubscriber"),Dp=function(l){Ap(n,l);var s=Cp(n);function n(i){var a;return Ep(this,n),a=s.call(this),a._id=null,a._session=i,a}return Sp(n,[{key:"sendRefer",value:function(i){var a=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};is.debug("sendRefer()");var d=dh.cloneArray(e.extraHeaders),_=dh.cloneObject(e.eventHandlers);for(var u in _)Object.prototype.hasOwnProperty.call(_,u)&&this.on(u,_[u]);var g=null;e.replaces&&(g=e.replaces._request.call_id,g+=";to-tag=".concat(e.replaces._to_tag),g+=";from-tag=".concat(e.replaces._from_tag),g=encodeURIComponent(g));var p="Refer-To: <".concat(i).concat(g?"?Replaces=".concat(g):"",">");if(d.push(p),!d.some(function(A){return A.toLowerCase().startsWith("referred-by:")})){var T="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");d.push(T)}d.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(gr.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(A){a._requestSucceeded(A)},onErrorResponse:function(A){a._requestFailed(A,gr.causes.REJECTED)},onTransportError:function(){a._requestFailed(null,gr.causes.CONNECTION_ERROR)},onRequestTimeout:function(){a._requestFailed(null,gr.causes.REQUEST_TIMEOUT)},onDialogError:function(){a._requestFailed(null,gr.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(i){if(is.debug("receiveNotify()"),!!i.body){var a=Np.parse(i.body.trim().split(`\r
49
- `,1)[0],"Status_Line");if(a===-1){is.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(i.body,'"'));return}switch(!0){case/^100$/.test(a.status_code):this.emit("trying",{request:i,status_line:a});break;case/^1[0-9]{2}$/.test(a.status_code):this.emit("progress",{request:i,status_line:a});break;case/^2[0-9]{2}$/.test(a.status_code):this.emit("accepted",{request:i,status_line:a});break;default:this.emit("failed",{request:i,status_line:a});break}}}},{key:"_requestSucceeded",value:function(i){is.debug("REFER succeeded"),is.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:i})}},{key:"_requestFailed",value:function(i,a){is.debug("REFER failed"),is.debug('emit "requestFailed"'),this.emit("requestFailed",{response:i||null,cause:a})}},{key:"id",get:function(){return this._id}}]),n}(wp);function Jo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Jo=function(s){return typeof s}:Jo=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Jo(l)}function En(l,s){var n;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(n=kp(l))||s&&l&&typeof l.length=="number"){n&&(l=n);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){n=l[Symbol.iterator]()},n:function(){var u=n.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&n.return!=null&&n.return()}finally{if(d)throw _}}}}function kp(l,s){if(l){if(typeof l=="string")return _h(l,s);var n=Object.prototype.toString.call(l).slice(8,-1);if(n==="Object"&&l.constructor&&(n=l.constructor.name),n==="Map"||n==="Set")return Array.from(l);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _h(l,s)}}function _h(l,s){(s==null||s>l.length)&&(s=l.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=l[n];return i}function Up(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function fh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function ph(l,s,n){return s&&fh(l.prototype,s),n&&fh(l,n),l}function Mp(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&_a(l,s)}function _a(l,s){return _a=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},_a(l,s)}function xp(l){var s=Hp();return function(){var n=Zo(l),i;if(s){var a=Zo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Pp(this,i)}}function Pp(l,s){return s&&(Jo(s)==="object"||typeof s=="function")?s:Lp(l)}function Lp(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Hp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(l){return!1}}function Zo(l){return Zo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Zo(l)}var qp=_t.EventEmitter,mh=Pt,Fp=ft,ce=lt,os=Kn,gh=_r,Ge=wt(),Tr=Kc,jp=Tn,el=Bf,$p=fr,$t=sp,Th=pp,Vp=yp,Bp=Dp,vh=Gn(),B=new Fp("RTCSession"),X={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},tl=["audio","video"],Kp=function(l){Mp(n,l);var s=xp(n);ph(n,null,[{key:"C",get:function(){return X}}]);function n(i){var a;return Up(this,n),B.debug("new"),a=s.call(this),a._id=null,a._ua=i,a._status=X.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 ph(n,[{key:"isInProgress",value:function(){switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:case X.STATUS_INVITE_RECEIVED:case X.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case X.STATUS_ANSWERED:case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case X.STATUS_CANCELED:case X.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(i){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},e=arguments.length>2?arguments[2]:void 0;B.debug("connect()");var d=i,_=Ge.cloneObject(a.eventHandlers),u=Ge.cloneArray(a.extraHeaders),g=Ge.cloneObject(a.mediaConstraints,{audio:!0,video:!0}),p=a.mediaStream||null,T=Ge.cloneObject(a.pcConfig,{iceServers:[]}),y=a.rtcConstraints||null,A=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,i===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_NULL)throw new os.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new os.NotSupportedError("WebRTC not supported");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ge.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var w in _)Object.prototype.hasOwnProperty.call(_,w)&&this.on(w,_[w]);this._from_tag=Ge.newTag();var R=a.anonymous||!1,b={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:R,outbound:!0}),R?(b.from_display_name="Anonymous",b.from_uri=new vh("sip","anonymous","anonymous.invalid"),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),u.push("Privacy: id")):a.fromUserName&&(b.from_uri=new vh("sip",a.fromUserName,this._ua.configuration.uri.host),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),a.fromDisplayName&&(b.from_display_name=a.fromDisplayName),u.push("Contact: ".concat(this._contact)),u.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&u.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new jp.InitialOutgoingInviteRequest(i,this._ua,b,u),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(T,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,e&&e(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,p)}},{key:"init_incoming",value:function(i,a){var e=this;B.debug("init_incoming()");var d,_=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0;if(i.body&&_!=="application/sdp"){i.reply(415);return}if(this._status=X.STATUS_INVITE_RECEIVED,this._from_tag=i.from_tag,this._id=i.call_id+this._from_tag,this._request=i,this._contact=this._ua.contact.toString(),i.hasHeader("expires")&&(d=i.getHeader("expires")*1e3),i.to_tag=Ge.newTag(),!this._createDialog(i,"UAS",!0)){i.reply(500,"Missing Contact header field");return}i.body?this._late_sdp=!1:this._late_sdp=!0,this._status=X.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){i.reply(408),e._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){e._status===X.STATUS_WAITING_FOR_ANSWER&&(i.reply(487),e._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=i.to,this._remote_identity=i.from,a&&a(this),this._newRTCSession("remote",i),this._status!==X.STATUS_TERMINATED&&(i.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("answer()");var e=this._request,d=Ge.cloneArray(a.extraHeaders),_=Ge.cloneObject(a.mediaConstraints),u=a.mediaStream||null,g=Ge.cloneObject(a.pcConfig,{iceServers:[]}),p=a.rtcConstraints||null,T=a.rtcAnswerConstraints||null,y=Ge.cloneObject(a.rtcOfferConstraints),A,w=!1,R=!1,b=!1,G=!1;if(this._rtcAnswerConstraints=T,this._rtcOfferConstraints=a.rtcOfferConstraints||null,this._data=a.data||this._data,this._direction!=="incoming")throw new os.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==X.STATUS_WAITING_FOR_ANSWER)throw new os.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ge.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=X.STATUS_ANSWERED,!this._createDialog(e,"UAS")){e.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var P=e.parseSDP();Array.isArray(P.media)||(P.media=[P.media]);var ye=En(P.media),O;try{for(ye.s();!(O=ye.n()).done;){var j=O.value;j.type==="audio"&&(w=!0,(!j.direction||j.direction==="sendrecv")&&(b=!0)),j.type==="video"&&(R=!0,(!j.direction||j.direction==="sendrecv")&&(G=!0))}}catch(M){ye.e(M)}finally{ye.f()}if(u&&_.audio===!1){A=u.getAudioTracks();var pe=En(A),Te;try{for(pe.s();!(Te=pe.n()).done;){var N=Te.value;u.removeTrack(N)}}catch(M){pe.e(M)}finally{pe.f()}}if(u&&_.video===!1){A=u.getVideoTracks();var H=En(A),$;try{for(H.s();!($=H.n()).done;){var q=$.value;u.removeTrack(q)}}catch(M){H.e(M)}finally{H.f()}}!u&&_.audio===void 0&&(_.audio=b),!u&&_.video===void 0&&(_.video=G),!u&&!w&&!y.offerToReceiveAudio&&(_.audio=!1),!u&&!R&&!y.offerToReceiveVideo&&(_.video=!1),this._createRTCConnection(g,p),Promise.resolve().then(function(){if(u)return u;if(_.audio||_.video)return i._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(_).catch(function(M){throw i._status===X.STATUS_TERMINATED?new Error("terminated"):(e.reply(480),i._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),B.warn('emit "getusermediafailed" [error:%o]',M),i.emit("getusermediafailed",M),new Error("getUserMedia() failed"))})}).then(function(M){if(i._status===X.STATUS_TERMINATED)throw new Error("terminated");i._localMediaStream=M,M&&M.getTracks().forEach(function(W){i._connection.addTrack(W,M)})}).then(function(){if(!i._late_sdp){var M={originator:"remote",type:"offer",sdp:e.body};B.debug('emit "sdp"'),i.emit("sdp",M);var W=new RTCSessionDescription({type:"offer",sdp:M.sdp});return i._connectionPromiseQueue=i._connectionPromiseQueue.then(function(){return i._connection.setRemoteDescription(W)}).catch(function(te){throw e.reply(488),i._failed("system",null,ce.causes.WEBRTC_ERROR),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',te),i.emit("peerconnection:setremotedescriptionfailed",te),new Error("peerconnection.setRemoteDescription() failed")}),i._connectionPromiseQueue}}).then(function(){if(i._status===X.STATUS_TERMINATED)throw new Error("terminated");return i._connecting(e),i._late_sdp?i._createLocalDescription("offer",i._rtcOfferConstraints).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")}):i._createLocalDescription("answer",T).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")})}).then(function(M){if(i._status===X.STATUS_TERMINATED)throw new Error("terminated");i._handleSessionTimersInIncomingRequest(e,d),e.reply(200,null,d,M,function(){i._status=X.STATUS_WAITING_FOR_ACK,i._setInvite2xxTimer(e,M),i._setACKTimer(),i._accepted("local")},function(){i._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(M){i._status!==X.STATUS_TERMINATED&&B.warn(M)})}},{key:"terminate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("terminate()");var e=a.cause||ce.causes.BYE,d=Ge.cloneArray(a.extraHeaders),_=a.body,u,g=a.status_code,p=a.reason_phrase;if(this._status===X.STATUS_TERMINATED)throw new os.InvalidStateError(this._status);switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:if(B.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(p=p||ce.REASON_PHRASE[g]||"",u="SIP ;cause=".concat(g,' ;text="').concat(p,'"')),this._status===X.STATUS_NULL||this._status===X.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=u):this._status===X.STATUS_1XX_RECEIVED&&this._request.cancel(u),this._status=X.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case X.STATUS_WAITING_FOR_ANSWER:case X.STATUS_ANSWERED:if(B.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,p,d,_),this._failed("local",null,ce.causes.REJECTED);break;case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:if(B.debug("terminating session"),p=a.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(p,'"')),this._status===X.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==gh.C.STATUS_TERMINATED){var T=this._dialog;this.receiveRequest=function(y){var A=y.method;A===ce.ACK&&(i.sendRequest(ce.BYE,{extraHeaders:d,body:_}),T.terminate())},this._request.server_transaction.on("stateChanged",function(){i._request.server_transaction.state===gh.C.STATUS_TERMINATED&&(i.sendRequest(ce.BYE,{extraHeaders:d,body:_}),T.terminate())}),this._ended("local",null,e),this._dialog=T,this._ua.newDialog(T)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:_}),this._ended("local",null,e)}}},{key:"sendDTMF",value:function(i){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};B.debug("sendDTMF() | tones: %s",i);var e=0,d=a.duration||null,_=a.interToneGap||null,u=a.transportType||ce.DTMF_TRANSPORT.INFO;if(i===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new os.InvalidStateError(this._status);if(u!==ce.DTMF_TRANSPORT.INFO&&u!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(u));if(typeof i=="number"&&(i=i.toString()),!i||typeof i!="string"||!i.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(i));if(d&&!Ge.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<$t.C.MIN_DURATION?(B.debug('"duration" value is lower than the minimum allowed, setting it to '.concat($t.C.MIN_DURATION," milliseconds")),d=$t.C.MIN_DURATION):d>$t.C.MAX_DURATION?(B.debug('"duration" value is greater than the maximum allowed, setting it to '.concat($t.C.MAX_DURATION," milliseconds")),d=$t.C.MAX_DURATION):d=Math.abs(d):d=$t.C.DEFAULT_DURATION,a.duration=d,_&&!Ge.isDecimal(_))throw new TypeError("Invalid interToneGap: ".concat(_));if(_?_<$t.C.MIN_INTER_TONE_GAP?(B.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat($t.C.MIN_INTER_TONE_GAP," milliseconds")),_=$t.C.MIN_INTER_TONE_GAP):_=Math.abs(_):_=$t.C.DEFAULT_INTER_TONE_GAP,u===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(i=g.toneBuffer+i,g.insertDTMF(i,d,_));return}if(this._tones){this._tones+=i;return}this._tones=i,p.call(this);function p(){var T=this,y;if(this._status===X.STATUS_TERMINATED||!this._tones||e>=this._tones.length){this._tones=null;return}var A=this._tones[e];if(e+=1,A===",")y=2e3;else{var w=new $t(this);a.eventHandlers={onFailed:function(){T._tones=null}},w.send(A,a),y=d+_}setTimeout(p.bind(this),y)}}},{key:"sendInfo",value:function(i,a){var e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(B.debug("sendInfo()"),this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new os.InvalidStateError(this._status);var d=new Th(this);d.send(i,a,e)}},{key:"mute",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};B.debug("mute()");var a=!1,e=!1;this._audioMuted===!1&&i.audio&&(a=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&i.video&&(e=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(a===!0||e===!0)&&this._onmute({audio:a,video:e})}},{key:"unmute",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};B.debug("unmute()");var a=!1,e=!1;this._audioMuted===!0&&i.audio&&(a=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&i.video&&(e=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(a===!0||e===!0)&&this._onunmute({audio:a,video:e})}},{key:"hold",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(B.debug("hold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var d={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:a.extraHeaders}),!0}},{key:"unhold",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(B.debug("unhold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var d={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:a.extraHeaders}),!0}},{key:"renegotiate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;B.debug("renegotiate()");var d=a.rtcOfferConstraints||null;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var _={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:_,rtcOfferConstraints:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:_,rtcOfferConstraints:d,extraHeaders:a.extraHeaders}),!0}},{key:"refer",value:function(i,a){var e=this;B.debug("refer()");var d=i;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(d));var _=new Bp(this);_.sendRefer(i,a);var u=_.id;return this._referSubscribers[u]=_,_.on("requestFailed",function(){delete e._referSubscribers[u]}),_.on("accepted",function(){delete e._referSubscribers[u]}),_.on("failed",function(){delete e._referSubscribers[u]}),_}},{key:"sendRequest",value:function(i,a){return B.debug("sendRequest()"),this._dialog.sendRequest(i,a)}},{key:"receiveRequest",value:function(i){var a=this;if(B.debug("receiveRequest()"),i.method===ce.CANCEL)(this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED)&&(this._status=X.STATUS_CANCELED,this._request.reply(487),this._failed("remote",i,ce.causes.CANCELED));else switch(i.method){case ce.ACK:if(this._status!==X.STATUS_WAITING_FOR_ACK)return;if(this._status=X.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!i.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var e={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",e);var d=new RTCSessionDescription({type:"answer",sdp:e.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(d)}).then(function(){a._is_confirmed||a._confirmed("remote",i)}).catch(function(u){a.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',u),a.emit("peerconnection:setremotedescriptionfailed",u)})}else this._is_confirmed||this._confirmed("remote",i);break;case ce.BYE:this._status===X.STATUS_CONFIRMED||this._status===X.STATUS_WAITING_FOR_ACK?(i.reply(200),this._ended("remote",i,ce.causes.BYE)):this._status===X.STATUS_INVITE_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER?(i.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",i,ce.causes.BYE)):i.reply(403,"Wrong Status");break;case ce.INVITE:this._status===X.STATUS_CONFIRMED?i.hasHeader("replaces")?this._receiveReplaces(i):this._receiveReinvite(i):i.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===X.STATUS_1XX_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED||this._status===X.STATUS_WAITING_FOR_ACK||this._status===X.STATUS_CONFIRMED){var _=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0;_&&_.match(/^application\/dtmf-relay/i)?new $t(this).init_incoming(i):_!==void 0?new Th(this).init_incoming(i):i.reply(415)}else i.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===X.STATUS_CONFIRMED?this._receiveUpdate(i):i.reply(403,"Wrong Status");break;case ce.REFER:this._status===X.STATUS_CONFIRMED?this._receiveRefer(i):i.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===X.STATUS_CONFIRMED?this._receiveNotify(i):i.reply(403,"Wrong Status");break;default:i.reply(501)}}},{key:"onTransportError",value:function(){B.warn("onTransportError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){B.warn("onRequestTimeout()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){B.warn("onDialogError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(i){B.debug("newDTMF()"),this.emit("newDTMF",i)}},{key:"newInfo",value:function(i){B.debug("newInfo()"),this.emit("newInfo",i)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(B.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(B.debug("_isReadyToReOffer() | session not established yet"),!1):(B.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(B.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(B.debug("close() | closing local MediaStream"),Ge.closeMediaStream(this._localMediaStream)),this._status!==X.STATUS_TERMINATED){if(this._status=X.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){B.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var i in this._timers)Object.prototype.hasOwnProperty.call(this._timers,i)&&clearTimeout(this._timers[i]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var a in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,a)&&(this._earlyDialogs[a].terminate(),delete this._earlyDialogs[a]);for(var e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(i,a){var e=Tr.T1;function d(){this._status===X.STATUS_WAITING_FOR_ACK&&(i.reply(200,null,["Contact: ".concat(this._contact)],a),e<Tr.T2&&(e=e*2,e>Tr.T2&&(e=Tr.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),e))}this._timers.invite2xxTimer=setTimeout(d.bind(this),e)}},{key:"_setACKTimer",value:function(){var i=this;this._timers.ackTimer=setTimeout(function(){i._status===X.STATUS_WAITING_FOR_ACK&&(B.debug("no ACK received, terminating the session"),clearTimeout(i._timers.invite2xxTimer),i.sendRequest(ce.BYE),i._ended("remote",null,ce.causes.NO_ACK))},Tr.TIMER_H)}},{key:"_createRTCConnection",value:function(i,a){var e=this;this._connection=new RTCPeerConnection(i,a),this._connection.addEventListener("iceconnectionstatechange",function(){var d=e._connection.iceConnectionState;d==="failed"&&e.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),B.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(i,a){var e=this;if(B.debug("createLocalDescription()"),i!=="offer"&&i!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(i,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return i==="offer"?d.createOffer(a).catch(function(_){return B.warn('emit "peerconnection:createofferfailed" [error:%o]',_),e.emit("peerconnection:createofferfailed",_),Promise.reject(_)}):d.createAnswer(a).catch(function(_){return B.warn('emit "peerconnection:createanswerfailed" [error:%o]',_),e.emit("peerconnection:createanswerfailed",_),Promise.reject(_)})}).then(function(_){return d.setLocalDescription(_).catch(function(u){return e._rtcReady=!0,B.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',u),e.emit("peerconnection:setlocaldescriptionfailed",u),Promise.reject(u)})}).then(function(){var _=a&&a.iceRestart;if(d.iceGatheringState==="complete"&&!_||d.iceGatheringState==="gathering"&&e._iceReady){e._rtcReady=!0;var u={originator:"local",type:i,sdp:d.localDescription.sdp};return B.debug('emit "sdp"'),e.emit("sdp",u),Promise.resolve(u.sdp)}return new Promise(function(g){var p=!1,T,y;e._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",T),d.removeEventListener("icegatheringstatechange",y),p=!0,e._rtcReady=!0,e._iceReady=!0;var w={originator:"local",type:i,sdp:d.localDescription.sdp};B.debug('emit "sdp"'),e.emit("sdp",w),g(w.sdp)};d.addEventListener("icecandidate",T=function(w){var R=w.candidate;R?e.emit("icecandidate",{candidate:R,ready:A}):p||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!p&&A()})})})}},{key:"_createDialog",value:function(i,a,e){var d=a==="UAS"?i.to_tag:i.from_tag,_=a==="UAS"?i.from_tag:i.to_tag,u=i.call_id+d+_,g=this._earlyDialogs[u];if(e)return g?!0:(g=new el(this,i,a,el.C.STATUS_EARLY),g.error?(B.debug(g.error),this._failed("remote",i,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[u]=g,!0));if(this._from_tag=i.from_tag,this._to_tag=i.to_tag,g)return g.update(i,a),this._dialog=g,delete this._earlyDialogs[u],!0;var p=new el(this,i,a);return p.error?(B.debug(p.error),this._failed("remote",i,ce.causes.INTERNAL_ERROR),!1):(this._dialog=p,!0)}},{key:"_receiveReinvite",value:function(i){var a=this;B.debug("receiveReinvite()");var e=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,d={request:i,callback:void 0,reject:u.bind(this)},_=!1;function u(){var p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var T=p.status_code||403,y=p.reason_phrase||"",A=Ge.cloneArray(p.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));i.reply(T,y,A)}if(this.emit("reinvite",d),_)return;if(this._late_sdp=!1,!i.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",a._rtcOfferConstraints)}).then(function(p){g.call(a,p)}).catch(function(){i.reply(500)});return}if(e!=="application/sdp"){B.debug("invalid Content-Type"),i.reply(415);return}this._processInDialogSdpOffer(i).then(function(p){a._status!==X.STATUS_TERMINATED&&g.call(a,p)}).catch(function(p){B.warn(p)});function g(p){var T=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(i,y),this._late_sdp&&(p=this._mangleOffer(p)),i.reply(200,null,y,p,function(){T._status=X.STATUS_WAITING_FOR_ACK,T._setInvite2xxTimer(i,p),T._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(i){var a=this;B.debug("receiveUpdate()");var e=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,d={request:i,callback:void 0,reject:u.bind(this)},_=!1;function u(){var p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var T=p.status_code||403,y=p.reason_phrase||"",A=Ge.cloneArray(p.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));i.reply(T,y,A)}if(this.emit("update",d),_)return;if(!i.body){g.call(this,null);return}if(e!=="application/sdp"){B.debug("invalid Content-Type"),i.reply(415);return}this._processInDialogSdpOffer(i).then(function(p){a._status!==X.STATUS_TERMINATED&&g.call(a,p)}).catch(function(p){B.warn(p)});function g(p){var T=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(i,T),i.reply(200,null,T,p),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(i){var a=this;B.debug("_processInDialogSdpOffer()");var e=i.parseSDP(),d=!1,_=En(e.media),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;if(tl.indexOf(g.type)!==-1){var p=g.direction||e.direction||"sendrecv";if(p==="sendonly"||p==="inactive")d=!0;else{d=!1;break}}}}catch(A){_.e(A)}finally{_.f()}var T={originator:"remote",type:"offer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",T);var y=new RTCSessionDescription({type:"offer",sdp:T.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(a._status===X.STATUS_TERMINATED)throw new Error("terminated");return a._connection.setRemoteDescription(y).catch(function(A){throw i.reply(488),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),a.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(a._status===X.STATUS_TERMINATED)throw new Error("terminated");a._remoteHold===!0&&d===!1?(a._remoteHold=!1,a._onunhold("remote")):a._remoteHold===!1&&d===!0&&(a._remoteHold=!0,a._onhold("remote"))}).then(function(){if(a._status===X.STATUS_TERMINATED)throw new Error("terminated");return a._createLocalDescription("answer",a._rtcAnswerConstraints).catch(function(A){throw i.reply(500),B.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){B.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(i){var a=this;if(B.debug("receiveRefer()"),!i.refer_to){B.debug("no Refer-To header field present in REFER"),i.reply(400);return}if(i.refer_to.uri.scheme!==ce.SIP){B.debug("Refer-To header field points to a non-SIP URI scheme"),i.reply(416);return}i.reply(202);var e=new Vp(this,i.cseq);B.debug('emit "refer"'),this.emit("refer",{request:i,accept:function(u,g){d.call(a,u,g)},reject:function(){_.call(a)}});function d(u){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(u=typeof u=="function"?u:null,this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var p=new n(this._ua);if(p.on("progress",function(y){var A=y.response;e.notify(A.status_code,A.reason_phrase)}),p.on("accepted",function(y){var A=y.response;e.notify(A.status_code,A.reason_phrase)}),p.on("_failed",function(y){var A=y.message,w=y.cause;A?e.notify(A.status_code,A.reason_phrase):e.notify(487,w)}),i.refer_to.uri.hasHeader("replaces")){var T=decodeURIComponent(i.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ge.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(T))}p.connect(i.refer_to.uri.toAor(),g,u)}function _(){e.notify(603)}}},{key:"_receiveNotify",value:function(i){switch(B.debug("receiveNotify()"),i.event||i.reply(400),i.event.event){case"refer":{var a,e;if(i.event.params&&i.event.params.id)a=i.event.params.id,e=this._referSubscribers[a];else if(Object.keys(this._referSubscribers).length===1)e=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{i.reply(400,"Missing event id parameter");return}if(!e){i.reply(481,"Subscription does not exist");return}e.receiveNotify(i),i.reply(200);break}default:i.reply(489)}}},{key:"_receiveReplaces",value:function(i){var a=this;B.debug("receiveReplaces()");function e(_){var u=this;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){u.terminate()}),g.init_incoming(i,_)}function d(){B.debug("Replaced INVITE rejected by the user"),i.reply(486)}this.emit("replaces",{request:i,accept:function(_){e.call(a,_)},reject:function(){d.call(a)}})}},{key:"_sendInitialRequest",value:function(i,a,e){var d=this,_=new $p(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(u){d._request=u},onReceiveResponse:function(u){d._receiveInviteResponse(u)}});Promise.resolve().then(function(){if(e)return e;if(i.audio||i.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(u){throw d._status===X.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),B.warn('emit "getusermediafailed" [error:%o]',u),d.emit("getusermediafailed",u),u)})}).then(function(u){if(d._status===X.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=u,u&&u.getTracks().forEach(function(g){d._connection.addTrack(g,u)}),d._connecting(d._request),d._createLocalDescription("offer",a).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(u){if(d._is_canceled||d._status===X.STATUS_TERMINATED)throw new Error("terminated");d._request.body=u,d._status=X.STATUS_INVITE_SENT,B.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),_.send()}).catch(function(u){d._status!==X.STATUS_TERMINATED&&B.warn(u)})}},{key:"_getDTMFRTPSender",value:function(){var i=this._connection.getSenders().find(function(a){return a.track&&a.track.kind==="audio"});if(!(i&&i.dtmf)){B.warn("sendDTMF() | no local audio track to send DTMF with");return}return i.dtmf}},{key:"_receiveInviteResponse",value:function(i){var a=this;if(B.debug("receiveInviteResponse()"),this._dialog&&i.status_code>=200&&i.status_code<=299)if(this._dialog.id.call_id===i.call_id&&this._dialog.id.local_tag===i.from_tag&&this._dialog.id.remote_tag===i.to_tag){this.sendRequest(ce.ACK);return}else{var e=new el(this,i,"UAC");if(e.error!==void 0){B.debug(e.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){i.status_code>=100&&i.status_code<200?this._request.cancel(this._cancel_reason):i.status_code>=200&&i.status_code<299&&this._acceptAndTerminate(i);return}if(!(this._status!==X.STATUS_INVITE_SENT&&this._status!==X.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(i.status_code):this._status=X.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(i.status_code):{if(!i.to_tag){B.debug("1xx response received without to tag");break}if(i.hasHeader("contact")&&!this._createDialog(i,"UAC",!0))break;if(this._status=X.STATUS_1XX_RECEIVED,!i.body){this._progress("remote",i);break}var d={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",d);var _=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(_)}).then(function(){return a._progress("remote",i)}).catch(function(T){B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),a.emit("peerconnection:setremotedescriptionfailed",T)});break}case/^2[0-9]{2}$/.test(i.status_code):{if(this._status=X.STATUS_CONFIRMED,!i.body){this._acceptAndTerminate(i,400,ce.causes.MISSING_SDP),this._failed("remote",i,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(i,"UAC"))break;var u={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",u);var g=new RTCSessionDescription({type:"answer",sdp:u.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(a._connection.signalingState==="stable")return a._connection.createOffer(a._rtcOfferConstraints).then(function(T){return a._connection.setLocalDescription(T)}).catch(function(T){a._acceptAndTerminate(i,500,T.toString()),a._failed("local",i,ce.causes.WEBRTC_ERROR)})}).then(function(){a._connection.setRemoteDescription(g).then(function(){a._handleSessionTimersInIncomingResponse(i),a._accepted("remote",i),a.sendRequest(ce.ACK),a._confirmed("local",null)}).catch(function(T){a._acceptAndTerminate(i,488,"Not Acceptable Here"),a._failed("remote",i,ce.causes.BAD_MEDIA_DESCRIPTION),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),a.emit("peerconnection:setremotedescriptionfailed",T)})});break}default:{var p=Ge.sipErrorCause(i.status_code);this._failed("remote",i,p)}}}},{key:"_sendReinvite",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("sendReinvite()");var e=Ge.cloneArray(a.extraHeaders),d=Ge.cloneObject(a.eventHandlers),_=a.rtcOfferConstraints||this._rtcOfferConstraints||null,u=!1;e.push("Contact: ".concat(this._contact)),e.push("Content-Type: application/sdp"),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return i._createLocalDescription("offer",_)}).then(function(T){T=i._mangleOffer(T);var y={originator:"local",type:"offer",sdp:T};B.debug('emit "sdp"'),i.emit("sdp",y),i.sendRequest(ce.INVITE,{extraHeaders:e,body:T,eventHandlers:{onSuccessResponse:function(A){g.call(i,A),u=!0},onErrorResponse:function(A){p.call(i,A)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}})}).catch(function(){p()});function g(T){var y=this;if(this._status!==X.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!u)){if(this._handleSessionTimersInIncomingResponse(T),T.body){if(!T.hasHeader("Content-Type")||T.getHeader("Content-Type").toLowerCase()!=="application/sdp"){p.call(this);return}}else{p.call(this);return}var A={originator:"remote",type:"answer",sdp:T.body};B.debug('emit "sdp"'),this.emit("sdp",A);var w=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(w)}).then(function(){d.succeeded&&d.succeeded(T)}).catch(function(R){p.call(y),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',R),y.emit("peerconnection:setremotedescriptionfailed",R)})}}function p(T){d.failed&&d.failed(T)}}},{key:"_sendUpdate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("sendUpdate()");var e=Ge.cloneArray(a.extraHeaders),d=Ge.cloneObject(a.eventHandlers),_=a.rtcOfferConstraints||this._rtcOfferConstraints||null,u=a.sdpOffer||!1,g=!1;e.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),u?(e.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return i._createLocalDescription("offer",_)}).then(function(y){y=i._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};B.debug('emit "sdp"'),i.emit("sdp",A),i.sendRequest(ce.UPDATE,{extraHeaders:e,body:y,eventHandlers:{onSuccessResponse:function(w){p.call(i,w),g=!0},onErrorResponse:function(w){T.call(i,w)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}})}).catch(function(){T.call(i)})):this.sendRequest(ce.UPDATE,{extraHeaders:e,eventHandlers:{onSuccessResponse:function(y){p.call(i,y)},onErrorResponse:function(y){T.call(i,y)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}});function p(y){var A=this;if(this._status!==X.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),u){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var w={originator:"remote",type:"answer",sdp:y.body};B.debug('emit "sdp"'),this.emit("sdp",w);var R=new RTCSessionDescription({type:"answer",sdp:w.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(R)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(b){T.call(A),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',b),A.emit("peerconnection:setremotedescriptionfailed",b)})}else d.succeeded&&d.succeeded(y)}function T(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(i,a,e){B.debug("acceptAndTerminate()");var d=[];a&&(e=e||ce.REASON_PHRASE[a]||"",d.push("Reason: SIP ;cause=".concat(a,'; text="').concat(e,'"'))),(this._dialog||this._createDialog(i,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=X.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(i){if(!this._localHold&&!this._remoteHold)return i;if(i=mh.parse(i),this._localHold&&!this._remoteHold){B.debug("mangleOffer() | me on hold, mangling offer");var a=En(i.media),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;tl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){a.e(A)}finally{a.f()}}else if(this._localHold&&this._remoteHold){B.debug("mangleOffer() | both on hold, mangling offer");var _=En(i.media),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;tl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){_.e(A)}finally{_.f()}}else if(this._remoteHold){B.debug("mangleOffer() | remote on hold, mangling offer");var p=En(i.media),T;try{for(p.s();!(T=p.n()).done;){var y=T.value;tl.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(A){p.e(A)}finally{p.f()}}return mh.write(i)}},{key:"_setLocalMediaStatus",value:function(){var i=!0,a=!0;(this._localHold||this._remoteHold)&&(i=!1,a=!1),this._audioMuted&&(i=!1),this._videoMuted&&(a=!1),this._toggleMuteAudio(!i),this._toggleMuteVideo(!a)}},{key:"_handleSessionTimersInIncomingRequest",value:function(i,a){if(this._sessionTimers.enabled){var e;i.session_expires&&i.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=i.session_expires,e=i.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,e="uas"),a.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(e)),this._sessionTimers.refresher=e==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(i){if(this._sessionTimers.enabled){var a;i.session_expires&&i.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=i.session_expires,a=i.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uac"),this._sessionTimers.refresher=a==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var i=this,a=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){i._status!==X.STATUS_TERMINATED&&i._isReadyToReOffer()&&(B.debug("runSessionTimer() | sending session refresh request"),i._sessionTimers.refreshMethod===ce.UPDATE?i._sendUpdate():i._sendReinvite())},a*500):this._sessionTimers.timer=setTimeout(function(){i._status!==X.STATUS_TERMINATED&&(B.warn("runSessionTimer() | timer expired, terminating the session"),i.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},a*1100)}},{key:"_toggleMuteAudio",value:function(i){var a=this._connection.getSenders().filter(function(u){return u.track&&u.track.kind==="audio"}),e=En(a),d;try{for(e.s();!(d=e.n()).done;){var _=d.value;_.track.enabled=!i}}catch(u){e.e(u)}finally{e.f()}}},{key:"_toggleMuteVideo",value:function(i){var a=this._connection.getSenders().filter(function(u){return u.track&&u.track.kind==="video"}),e=En(a),d;try{for(e.s();!(d=e.n()).done;){var _=d.value;_.track.enabled=!i}}catch(u){e.e(u)}finally{e.f()}}},{key:"_newRTCSession",value:function(i,a){B.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:i,session:this,request:a})}},{key:"_connecting",value:function(i){B.debug("session connecting"),B.debug('emit "connecting"'),this.emit("connecting",{request:i})}},{key:"_progress",value:function(i,a){B.debug("session progress"),B.debug('emit "progress"'),this.emit("progress",{originator:i,response:a||null})}},{key:"_accepted",value:function(i,a){B.debug("session accepted"),this._start_time=new Date,B.debug('emit "accepted"'),this.emit("accepted",{originator:i,response:a||null})}},{key:"_confirmed",value:function(i,a){B.debug("session confirmed"),this._is_confirmed=!0,B.debug('emit "confirmed"'),this.emit("confirmed",{originator:i,ack:a||null})}},{key:"_ended",value:function(i,a,e){B.debug("session ended"),this._end_time=new Date,this._close(),B.debug('emit "ended"'),this.emit("ended",{originator:i,message:a||null,cause:e})}},{key:"_failed",value:function(i,a,e){B.debug("session failed"),B.debug('emit "_failed"'),this.emit("_failed",{originator:i,message:a||null,cause:e}),this._close(),B.debug('emit "failed"'),this.emit("failed",{originator:i,message:a||null,cause:e})}},{key:"_onhold",value:function(i){B.debug("session onhold"),this._setLocalMediaStatus(),B.debug('emit "hold"'),this.emit("hold",{originator:i})}},{key:"_onunhold",value:function(i){B.debug("session onunhold"),this._setLocalMediaStatus(),B.debug('emit "unhold"'),this.emit("unhold",{originator:i})}},{key:"_onmute",value:function(i){var a=i.audio,e=i.video;B.debug("session onmute"),this._setLocalMediaStatus(),B.debug('emit "muted"'),this.emit("muted",{audio:a,video:e})}},{key:"_onunmute",value:function(i){var a=i.audio,e=i.video;B.debug("session onunmute"),this._setLocalMediaStatus(),B.debug('emit "unmuted"'),this.emit("unmuted",{audio:a,video:e})}},{key:"C",get:function(){return X}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(i){this._data=i}},{key:"status",get:function(){return this._status}}]),n}(qp);function nl(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?nl=function(s){return typeof s}:nl=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},nl(l)}function Gp(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function yh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Wp(l,s,n){return s&&yh(l.prototype,s),n&&yh(l,n),l}function Yp(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&fa(l,s)}function fa(l,s){return fa=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},fa(l,s)}function zp(l){var s=Jp();return function(){var n=sl(l),i;if(s){var a=sl(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Xp(this,i)}}function Xp(l,s){return s&&(nl(s)==="object"||typeof s=="function")?s:Qp(l)}function Qp(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Jp(){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(l){return!1}}function sl(l){return sl=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},sl(l)}var Zp=_t.EventEmitter,em=ft,pa=lt,tm=Tn,vr=wt(),nm=fr,Eh=Kn,sm=Gn(),rl=new em("Message"),rm=function(l){Yp(n,l);var s=zp(n);function n(i){var a;return Gp(this,n),a=s.call(this),a._ua=i,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(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=i;if(i===void 0||a===void 0)throw new TypeError("Not enough arguments");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(_));var u=vr.cloneArray(d.extraHeaders),g=vr.cloneObject(d.eventHandlers),p=d.contentType||"text/plain",T={};d.fromUserName&&(T.from_uri=new sm("sip",d.fromUserName,this._ua.configuration.uri.host),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(T.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);u.push("Content-Type: ".concat(p)),this._request=new tm.OutgoingRequest(pa.MESSAGE,i,this._ua,T,u),a&&(this._request.body=a);var A=new nm(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(w){e._receiveResponse(w)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(i){this._request=i,this._newMessage("remote",i),this._is_replied||(this._is_replied=!0,i.reply(200)),this._close()}},{key:"accept",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=vr.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new Eh.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,a,e)}},{key:"reject",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=i.status_code||480,e=i.reason_phrase,d=vr.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new Eh.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(a<300||a>=700)throw new TypeError("Invalid status_code: ".concat(a));this._is_replied=!0,this._request.reply(a,e,d,_)}},{key:"_receiveResponse",value:function(i){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._succeeded("remote",i);break;default:{var a=vr.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,pa.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,pa.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(i,a){i==="remote"?(this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from):i==="local"&&(this._direction="outgoing",this._local_identity=a.from,this._remote_identity=a.to),this._ua.newMessage(this,{originator:i,message:this,request:a})}},{key:"_failed",value:function(i,a,e){rl.debug("MESSAGE failed"),this._close(),rl.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){rl.debug("MESSAGE succeeded"),this._close(),rl.debug('emit "succeeded"'),this.emit("succeeded",{originator:i,response:a})}},{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}(Zp);function il(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?il=function(s){return typeof s}:il=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},il(l)}function im(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Sh(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function om(l,s,n){return s&&Sh(l.prototype,s),n&&Sh(l,n),l}function lm(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&ma(l,s)}function ma(l,s){return ma=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ma(l,s)}function am(l){var s=hm();return function(){var n=ol(l),i;if(s){var a=ol(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return um(this,i)}}function um(l,s){return s&&(il(s)==="object"||typeof s=="function")?s:cm(l)}function cm(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function hm(){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(l){return!1}}function ol(l){return ol=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},ol(l)}var dm=_t.EventEmitter,_m=ft,ga=lt,fm=Tn,yr=wt(),pm=fr,Ah=Kn,ll=new _m("Options"),mm=function(l){lm(n,l);var s=am(n);function n(i){var a;return im(this,n),a=s.call(this),a._ua=i,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 om(n,[{key:"send",value:function(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=i;if(i===void 0)throw new TypeError("A target is required for OPTIONS");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(_));var u=yr.cloneArray(d.extraHeaders),g=yr.cloneObject(d.eventHandlers),p=d.contentType||"application/sdp";for(var T in g)Object.prototype.hasOwnProperty.call(g,T)&&this.on(T,g[T]);u.push("Content-Type: ".concat(p)),this._request=new fm.OutgoingRequest(ga.OPTIONS,i,this._ua,null,u),a&&(this._request.body=a);var y=new pm(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(A){e._receiveResponse(A)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(i){this._request=i,this._newOptions("remote",i),this._is_replied||(this._is_replied=!0,i.reply(200)),this._close()}},{key:"accept",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=yr.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new Ah.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,a,e)}},{key:"reject",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=i.status_code||480,e=i.reason_phrase,d=yr.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new Ah.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(a<300||a>=700)throw new TypeError("Invalid status_code: ".concat(a));this._is_replied=!0,this._request.reply(a,e,d,_)}},{key:"_receiveResponse",value:function(i){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._succeeded("remote",i);break;default:{var a=yr.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,ga.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,ga.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(i,a){i==="remote"?(this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from):i==="local"&&(this._direction="outgoing",this._local_identity=a.from,this._remote_identity=a.to),this._ua.newOptions(this,{originator:i,message:this,request:a})}},{key:"_failed",value:function(i,a,e){ll.debug("OPTIONS failed"),this._close(),ll.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){ll.debug("OPTIONS succeeded"),this._close(),ll.debug('emit "succeeded"'),this.emit("succeeded",{originator:i,response:a})}},{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}(dm),Ta={},gm=ft,va=wt(),Tm=dn(),Er=new gm("Socket");Ta.isSocket=function(l){if(Array.isArray(l))return!1;if(typeof l>"u")return Er.warn("undefined JsSIP.Socket instance"),!1;try{if(!va.isString(l.url))throw Er.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!va.isString(l.via_transport))throw Er.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Tm.parse(l.sip_uri,"SIP_URI")===-1)throw Er.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(s){return!1}try{["connect","disconnect","send"].forEach(function(s){if(!va.isFunction(l[s]))throw Er.warn("missing or invalid JsSIP.Socket method: ".concat(s)),new Error("Missing or invalid JsSIP.Socket method: ".concat(s))})}catch(s){return!1}return!0};function vm(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Ch(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function ym(l,s,n){return s&&Ch(l.prototype,s),n&&Ch(l,n),l}var Em=ft,Sm=Ta,bh=lt,Lt=new Em("Transport"),Gt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:bh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:bh.CONNECTION_RECOVERY_MAX_INTERVAL}},Am=function(){function l(s){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Gt.recovery_options;vm(this,l),Lt.debug("new()"),this.status=Gt.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(i){Lt.warn("cannot use TextDecoder: ".concat(i))}if(typeof s>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");s instanceof Array||(s=[s]),s.forEach(function(i){if(!Sm.isSocket(i.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(i.weight&&!Number(i.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:i.socket,weight:i.weight||0,status:Gt.SOCKET_STATUS_READY})},this),this._getSocket()}return ym(l,[{key:"connect",value:function(){if(Lt.debug("connect()"),this.isConnected()){Lt.debug("Transport is already connected");return}else if(this.isConnecting()){Lt.debug("Transport is connecting");return}this.close_requested=!1,this.status=Gt.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(){Lt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Gt.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(s){if(Lt.debug("send()"),!this.isConnected())return Lt.warn("unable to send message, transport is not connected"),!1;var n=s.toString();return Lt.debug(`sending message:
51
-
52
- `.concat(n,`
53
- `)),this.socket.send(n)}},{key:"isConnected",value:function(){return this.status===Gt.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===Gt.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var s=this;this.recover_attempts+=1;var n=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);n<this.recovery_options.min_interval?n=this.recovery_options.min_interval:n>this.recovery_options.max_interval&&(n=this.recovery_options.max_interval),Lt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(n," seconds")),this.recovery_timer=setTimeout(function(){!s.close_requested&&!(s.isConnected()||s.isConnecting())&&(s._getSocket(),s.connect())},n*1e3)}},{key:"_getSocket",value:function(){var s=[];if(this.sockets.forEach(function(i){i.status!==Gt.SOCKET_STATUS_ERROR&&(s.length===0?s.push(i):i.weight>s[0].weight?s=[i]:i.weight===s[0].weight&&s.push(i))}),s.length===0){this.sockets.forEach(function(i){i.status=Gt.SOCKET_STATUS_READY}),this._getSocket();return}var n=Math.floor(Math.random()*s.length);this.socket=s[n].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=Gt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(s,n,i){this.status=Gt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:s,code:n,reason:i}),!this.close_requested&&(this.sockets.forEach(function(a){this.socket===a.socket&&(a.status=Gt.SOCKET_STATUS_ERROR)},this),this._reconnect(s))}},{key:"_onData",value:function(s){if(s===`\r
54
- `){Lt.debug("received message with CRLF Keep Alive response");return}else if(typeof s!="string"){try{this.textDecoder?s=this.textDecoder.decode(s):s=String.fromCharCode.apply(null,new Uint8Array(s))}catch(n){Lt.debug("received binary message failed to be converted into string, message discarded");return}Lt.debug(`received binary message:
46
+ `),this.transport.send(d)}}]),s}(Mc),lp=function(l){jl(s,l);var n=Vl(s);function s(){var i;return Qs(this,s),i=n.call(this),i.headers={},i.status_code=null,i.reason_phrase=null,i}return s}(Mc),_n={OutgoingRequest:Uc,InitialOutgoingInviteRequest:ip,IncomingRequest:op,IncomingResponse:lp};function ap(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Pc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function up(l,n,s){return n&&Pc(l.prototype,n),s&&Pc(l,s),l}var cp=ct,pn=At(),Vt=new cp("DigestAuthentication"),hp=function(){function l(n){ap(this,l),this._credentials=n,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 up(l,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Vt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,s){var i=n.method,a=n.ruri,e=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=s.algorithm,this._realm=s.realm,this._nonce=s.nonce,this._opaque=s.opaque,this._stale=s.stale,this._algorithm){if(this._algorithm!=="MD5")return Vt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Vt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Vt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Vt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Vt.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(s.qop)if(s.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(s.qop.indexOf("auth")>-1)this._qop="auth";else return Vt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=i,this._uri=a,this._cnonce=d||pn.createRandomToken(12),this._nc+=1;var _=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-_.length)+_,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=pn.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var u,g;return this._qop==="auth"?(u="".concat(this._method,":").concat(this._uri),g=pn.calculateMD5(u),Vt.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=pn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(u="".concat(this._method,":").concat(this._uri,":").concat(pn.calculateMD5(e||"")),g=pn.calculateMD5(u),Vt.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=pn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(u="".concat(this._method,":").concat(this._uri),g=pn.calculateMD5(u),Vt.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=pn.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Vt.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(", "))}}]),l}(),fn=500,dp=4e3,xc=5e3,Lc={T1:fn,T2:dp,T4:xc,TIMER_B:64*fn,TIMER_D:0*fn,TIMER_F:64*fn,TIMER_H:64*fn,TIMER_I:0*fn,TIMER_J:0*fn,TIMER_K:0*xc,TIMER_L:64*fn,TIMER_M:64*fn,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Uo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Uo=function(n){return typeof n}:Uo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Uo(l)}function Zs(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Hc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function er(l,n,s){return n&&Hc(l.prototype,n),s&&Hc(l,s),l}function tr(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&Kl(l,n)}function Kl(l,n){return Kl=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},Kl(l,n)}function nr(l){var n=pp();return function(){var s=Mo(l),i;if(n){var a=Mo(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return _p(this,i)}}function _p(l,n){return n&&(Uo(n)==="object"||typeof n=="function")?n:$n(l)}function $n(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function pp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Mo(l){return Mo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Mo(l)}var sr=ut.EventEmitter,rr=ct,ir=nt,qc=_n,an=Lc,Fc=new rr("NonInviteClientTransaction"),Po=new rr("InviteClientTransaction"),fp=new rr("AckClientTransaction"),jc=new rr("NonInviteServerTransaction"),xo=new rr("InviteServerTransaction"),oe={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"},mp=function(l){tr(s,l);var n=nr(s);function s(i,a,e,d){var _;Zs(this,s),_=n.call(this),_.type=oe.NON_INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=i,_.transport=a,_.request=e,_.eventHandlers=d;var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_.ua.newTransaction($n(_)),_}return er(s,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"send",value:function(){var i=this;this.stateChanged(oe.STATUS_TRYING),this.F=setTimeout(function(){i.timer_F()},an.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Fc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Fc.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(i){var a=this,e=i.status_code;if(e<200)switch(this.state){case oe.STATUS_TRYING:case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(i);break}else switch(this.state){case oe.STATUS_TRYING:case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_COMPLETED),clearTimeout(this.F),e===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(i),this.K=setTimeout(function(){a.timer_K()},an.TIMER_K);break;case oe.STATUS_COMPLETED:break}}},{key:"C",get:function(){return oe}}]),s}(sr),gp=function(l){tr(s,l);var n=nr(s);function s(i,a,e,d){var _;Zs(this,s),_=n.call(this),_.type=oe.INVITE_CLIENT,_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.ua=i,_.transport=a,_.request=e,_.eventHandlers=d,e.transaction=$n(_);var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_.ua.newTransaction($n(_)),_}return er(s,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"send",value:function(){var i=this;this.stateChanged(oe.STATUS_CALLING),this.B=setTimeout(function(){i.timer_B()},an.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==oe.STATUS_ACCEPTED&&(Po.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Po.debug("Timer M expired for transaction ".concat(this.id)),this.state===oe.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Po.debug("Timer B expired for transaction ".concat(this.id)),this.state===oe.STATUS_CALLING&&(this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Po.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(i){var a=this,e=new qc.OutgoingRequest(ir.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});e.setHeader("from",this.request.getHeader("from")),e.setHeader("via",this.request.getHeader("via")),e.setHeader("to",i.getHeader("to")),this.D=setTimeout(function(){a.timer_D()},an.TIMER_D),this.transport.send(e)}},{key:"cancel",value:function(i){if(this.state===oe.STATUS_PROCEEDING){var a=new qc.OutgoingRequest(ir.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});a.setHeader("from",this.request.getHeader("from")),a.setHeader("via",this.request.getHeader("via")),a.setHeader("to",this.request.getHeader("to")),i&&a.setHeader("reason",i),this.transport.send(a)}}},{key:"receiveResponse",value:function(i){var a=this,e=i.status_code;if(e>=100&&e<=199)switch(this.state){case oe.STATUS_CALLING:this.stateChanged(oe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(i);break;case oe.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(i);break}else if(e>=200&&e<=299)switch(this.state){case oe.STATUS_CALLING:case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_ACCEPTED),this.M=setTimeout(function(){a.timer_M()},an.TIMER_M),this.eventHandlers.onReceiveResponse(i);break;case oe.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(i);break}else if(e>=300&&e<=699)switch(this.state){case oe.STATUS_CALLING:case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_COMPLETED),this.sendACK(i),this.eventHandlers.onReceiveResponse(i);break;case oe.STATUS_COMPLETED:this.sendACK(i);break}}},{key:"C",get:function(){return oe}}]),s}(sr),Tp=function(l){tr(s,l);var n=nr(s);function s(i,a,e,d){var _;Zs(this,s),_=n.call(this),_.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),_.transport=a,_.request=e,_.eventHandlers=d;var u="SIP/2.0/".concat(a.via_transport);return u+=" ".concat(i.configuration.via_host,";branch=").concat(_.id),_.request.setHeader("via",u),_}return er(s,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){fp.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return oe}}]),s}(sr),vp=function(l){tr(s,l);var n=nr(s);function s(i,a,e){var d;return Zs(this,s),d=n.call(this),d.type=oe.NON_INVITE_SERVER,d.id=e.via_branch,d.ua=i,d.transport=a,d.request=e,d.last_response="",e.server_transaction=$n(d),d.state=oe.STATUS_TRYING,i.newTransaction($n(d)),d}return er(s,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_J",value:function(){jc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,jc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(i,a,e,d){var _=this;if(i===100)switch(this.state){case oe.STATUS_TRYING:this.stateChanged(oe.STATUS_PROCEEDING),this.transport.send(a)||this.onTransportError();break;case oe.STATUS_PROCEEDING:this.last_response=a,this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break}else if(i>=200&&i<=699)switch(this.state){case oe.STATUS_TRYING:case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_COMPLETED),this.last_response=a,this.J=setTimeout(function(){_.timer_J()},an.TIMER_J),this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break;case oe.STATUS_COMPLETED:break}}},{key:"C",get:function(){return oe}}]),s}(sr),yp=function(l){tr(s,l);var n=nr(s);function s(i,a,e){var d;return Zs(this,s),d=n.call(this),d.type=oe.INVITE_SERVER,d.id=e.via_branch,d.ua=i,d.transport=a,d.request=e,d.last_response="",e.server_transaction=$n(d),d.state=oe.STATUS_PROCEEDING,i.newTransaction($n(d)),d.resendProvisionalTimer=null,e.reply(100),d}return er(s,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_H",value:function(){xo.debug("Timer H expired for transaction ".concat(this.id)),this.state===oe.STATUS_COMPLETED&&xo.debug("ACK not received, dialog will be terminated"),this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){xo.debug("Timer L expired for transaction ".concat(this.id)),this.state===oe.STATUS_ACCEPTED&&(this.stateChanged(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,xo.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(oe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(i,a,e,d){var _=this;if(i>=100&&i<=199)switch(this.state){case oe.STATUS_PROCEEDING:this.transport.send(a)||this.onTransportError(),this.last_response=a;break}if(i>100&&i<=199&&this.state===oe.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){_.resend_provisional()},an.PROVISIONAL_RESPONSE_INTERVAL));else if(i>=200&&i<=299)switch(this.state){case oe.STATUS_PROCEEDING:this.stateChanged(oe.STATUS_ACCEPTED),this.last_response=a,this.L=setTimeout(function(){_.timer_L()},an.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case oe.STATUS_ACCEPTED:this.transport.send(a)?e&&e():(this.onTransportError(),d&&d());break}else if(i>=300&&i<=699)switch(this.state){case oe.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(a)?(this.stateChanged(oe.STATUS_COMPLETED),this.H=setTimeout(function(){_.timer_H()},an.TIMER_H),e&&e()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return oe}}]),s}(sr);function Ep(l,n){var s=l._transactions,i;switch(n.method){case ir.INVITE:if(i=s.ist[n.via_branch],i){switch(i.state){case oe.STATUS_PROCEEDING:i.transport.send(i.last_response);break;case oe.STATUS_ACCEPTED:break}return!0}break;case ir.ACK:if(i=s.ist[n.via_branch],i){if(i.state===oe.STATUS_ACCEPTED)return!1;if(i.state===oe.STATUS_COMPLETED)return i.state=oe.STATUS_CONFIRMED,i.I=setTimeout(function(){i.timer_I()},an.TIMER_I),!0}else return!1;break;case ir.CANCEL:return i=s.ist[n.via_branch],i?(n.reply_sl(200),i.state!==oe.STATUS_PROCEEDING):(n.reply_sl(481),!0);default:if(i=s.nist[n.via_branch],i){switch(i.state){case oe.STATUS_TRYING:break;case oe.STATUS_PROCEEDING:case oe.STATUS_COMPLETED:i.transport.send(i.last_response);break}return!0}break}}var or={C:oe,NonInviteClientTransaction:mp,InviteClientTransaction:gp,AckClientTransaction:Tp,NonInviteServerTransaction:vp,InviteServerTransaction:yp,checkTransaction:Ep};function Sp(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function $c(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Ap(l,n,s){return n&&$c(l.prototype,n),s&&$c(l,s),l}var Cp=ct,Vc=nt,bp=hp,Gl=or,Rp=new Cp("RequestSender"),Wl={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},lr=function(){function l(n,s,i){Sp(this,l),this._ua=n,this._eventHandlers=i,this._method=s.method,this._request=s,this._auth=null,this._challenged=!1,this._staled=!1;for(var a in Wl)Object.prototype.hasOwnProperty.call(Wl,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=Wl[a]));n.status===n.C.STATUS_USER_CLOSED&&(this._method!==Vc.BYE||this._method!==Vc.ACK)&&this._eventHandlers.onTransportError()}return Ap(l,[{key:"send",value:function(){var n=this,s={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(i){n._receiveResponse(i)}};switch(this._method){case"INVITE":this.clientTransaction=new Gl.InviteClientTransaction(this._ua,this._ua.transport,this._request,s);break;case"ACK":this.clientTransaction=new Gl.AckClientTransaction(this._ua,this._ua.transport,this._request,s);break;default:this.clientTransaction=new Gl.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,s)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var s,i,a=n.status_code;if((a===401||a===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(s=n.parseHeader("www-authenticate"),i="authorization"):(s=n.parseHeader("proxy-authenticate"),i="proxy-authorization"),!s){Rp.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&s.stale===!0){if(this._auth||(this._auth=new bp({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,s)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),s.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(i,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),l}();function Ip(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Bc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function wp(l,n,s){return n&&Bc(l.prototype,n),s&&Bc(l,s),l}var Op=ct,Yl=At(),Zn=nt,Kc=_n,Gc=lr,ar=new Op("Registrator"),Lo=10,Np=function(){function l(n,s){Ip(this,l),this._reg_id=1,this._ua=n,this._transport=s,this._registrar=n.configuration.registrar_server,this._expires=n.configuration.register_expires,this._call_id=Yl.createRandomToken(22),this._cseq=0,this._to_uri=n.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 wp(l,[{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 s in n)if(Object.prototype.hasOwnProperty.call(n,s)){var i=n[s];this._extraContactParams+=";".concat(s),i&&(this._extraContactParams+="=".concat(i))}}},{key:"register",value:function(){var n=this;if(this._registering){ar.debug("Register request in progress...");return}var s=this._extraHeaders.slice();s.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),s.push("Expires: ".concat(this._expires));var i=new Kc.OutgoingRequest(Zn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),a=new Gc(this._ua,i,{onRequestTimeout:function(){n._registrationFailure(null,Zn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,Zn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(e){if(e.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):{if(n._registering=!1,!e.hasHeader("Contact")){ar.debug("no Contact header in response to REGISTER, response ignored");break}var d=e.headers.Contact.reduce(function(T,y){return T.concat(y.parsed)},[]),_=d.find(function(T){return n._sipInstance===T.getParam("+sip.instance")&&n._reg_id===parseInt(T.getParam("reg-id"))});if(_||(_=d.find(function(T){return T.uri.user===n._ua.contact.uri.user})),!_){ar.debug("no Contact header pointing to us, response ignored");break}var u=_.getParam("expires");!u&&e.hasHeader("expires")&&(u=e.getHeader("expires")),u||(u=n._expires),u=Number(u),u<Lo&&(u=Lo);var g=u>64?u*1e3/2+Math.floor((u/2-32)*1e3*Math.random()):u*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},g),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:e}));break}case/^423$/.test(e.status_code):{e.hasHeader("min-expires")?(n._expires=Number(e.getHeader("min-expires")),n._expires<Lo&&(n._expires=Lo),n.register()):(ar.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(e,Zn.causes.SIP_FAILURE_CODE));break}default:{var f=Yl.sipErrorCause(e.status_code);n._registrationFailure(e,f)}}}});this._registering=!0,a.send()}},{key:"unregister",value:function(){var n=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){ar.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var i=this._extraHeaders.slice();s.all?i.push("Contact: *".concat(this._extraContactParams)):i.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),i.push("Expires: 0");var a=new Kc.OutgoingRequest(Zn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},i),e=new Gc(this._ua,a,{onRequestTimeout:function(){n._unregistered(null,Zn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,Zn.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 _=Yl.sipErrorCause(d.status_code);n._unregistered(d,_)}}}});e.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,s){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:s}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:s}))}},{key:"_unregistered",value:function(n,s){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:s||null})}},{key:"registered",get:function(){return this._registered}}]),l}();function Dp(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Wc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function kp(l,n,s){return n&&Wc(l.prototype,n),s&&Wc(l,s),l}var zl=nt,Ho=or,Up=lr,Jl={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},Mp=function(){function l(n,s,i){Dp(this,l),this._dialog=n,this._ua=n._ua,this._request=s,this._eventHandlers=i,this._reattempt=!1,this._reattemptTimer=null;for(var a in Jl)Object.prototype.hasOwnProperty.call(Jl,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=Jl[a]))}return kp(l,[{key:"send",value:function(){var n=this,s=new Up(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(a){n._eventHandlers.onAuthenticated(a)},onReceiveResponse:function(a){n._receiveResponse(a)}});if(s.send(),(this._request.method===zl.INVITE||this._request.method===zl.UPDATE&&this._request.body)&&s.clientTransaction.state!==Ho.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var i=function a(){(s.clientTransaction.state===Ho.C.STATUS_ACCEPTED||s.clientTransaction.state===Ho.C.STATUS_COMPLETED||s.clientTransaction.state===Ho.C.STATUS_TERMINATED)&&(s.clientTransaction.removeListener("stateChanged",a),n._dialog.uac_pending_reply=!1)};s.clientTransaction.on("stateChanged",i)}}},{key:"_receiveResponse",value:function(n){var s=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===zl.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(){s._dialog.isTerminated()||(s._reattempt=!0,s.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}}]),l}();function Pp(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Yc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function zc(l,n,s){return n&&Yc(l.prototype,n),s&&Yc(l,s),l}var xp=ct,Jc=_n,Vn=nt,ur=or,Lp=Mp,Xl=At(),Ql=new xp("Dialog"),Bn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Hp=function(){zc(l,null,[{key:"C",get:function(){return Bn}}]);function l(n,s,i){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Bn.STATUS_CONFIRMED;if(Pp(this,l),this._owner=n,this._ua=n._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!s.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};s instanceof Jc.IncomingResponse&&(a=s.status_code<200?Bn.STATUS_EARLY:Bn.STATUS_CONFIRMED);var e=s.parseHeader("contact");i==="UAS"?(this._id={call_id:s.call_id,local_tag:s.to_tag,remote_tag:s.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=s.cseq,this._local_uri=s.parseHeader("to").uri,this._remote_uri=s.parseHeader("from").uri,this._remote_target=e.uri,this._route_set=s.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):i==="UAC"&&(this._id={call_id:s.call_id,local_tag:s.from_tag,remote_tag:s.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=s.cseq,this._local_uri=s.parseHeader("from").uri,this._remote_uri=s.parseHeader("to").uri,this._remote_target=e.uri,this._route_set=s.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Ql.debug("new ".concat(i," dialog created with status ").concat(this._state===Bn.STATUS_EARLY?"EARLY":"CONFIRMED"))}return zc(l,[{key:"isTerminated",value:function(){return this._status===Bn.STATUS_TERMINATED}},{key:"update",value:function(n,s){this._state=Bn.STATUS_CONFIRMED,Ql.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),s==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Ql.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Bn.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var s=this,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=Xl.cloneArray(i.extraHeaders),e=Xl.cloneObject(i.eventHandlers),d=i.body||null,_=this._createRequest(n,a,d);e.onAuthenticated=function(){s._local_seqnum+=1};var u=new Lp(this,_,e);return u.send(),_}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Vn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Vn.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,s,i){s=Xl.cloneArray(s),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var a=n===Vn.CANCEL||n===Vn.ACK?this._local_seqnum:this._local_seqnum+=1,e=new Jc.OutgoingRequest(n,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},s,i);return e}},{key:"_checkInDialogRequest",value:function(n){var s=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Vn.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===Vn.INVITE||n.method===Vn.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var i=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(i)]),!1}else{this._uas_pending_reply=!0;var a=function e(){(n.server_transaction.state===ur.C.STATUS_ACCEPTED||n.server_transaction.state===ur.C.STATUS_COMPLETED||n.server_transaction.state===ur.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",e),s._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",a)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===ur.C.STATUS_ACCEPTED&&(s._remote_target=n.parseHeader("contact").uri)})}else n.method===Vn.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===ur.C.STATUS_COMPLETED&&(s._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}}]),l}(),Zl={exports:{}};function qo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?qo=function(n){return typeof n}:qo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},qo(l)}function qp(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Xc(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Fp(l,n,s){return n&&Xc(l.prototype,n),s&&Xc(l,s),l}function jp(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&ea(l,n)}function ea(l,n){return ea=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},ea(l,n)}function $p(l){var n=Kp();return function(){var s=Fo(l),i;if(n){var a=Fo(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return Vp(this,i)}}function Vp(l,n){return n&&(qo(n)==="object"||typeof n=="function")?n:Bp(l)}function Bp(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Kp(){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 Fo(l){return Fo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Fo(l)}var Gp=ut.EventEmitter,Wp=ct,Yp=nt,zp=Fn,Qc=At(),Jp=new Wp("RTCSession:DTMF"),Zc={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Zl.exports=function(l){jp(s,l);var n=$p(s);function s(i){var a;return qp(this,s),a=n.call(this),a._session=i,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return Fp(s,[{key:"send",value:function(i){var a=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(i===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 zp.InvalidStateError(this._session.status);var d=Qc.cloneArray(e.extraHeaders);if(this.eventHandlers=Qc.cloneObject(e.eventHandlers),typeof i=="string")i=i.toUpperCase();else if(typeof i=="number")i=i.toString();else throw new TypeError("Invalid tone: ".concat(i));if(i.match(/^[0-9A-DR#*]$/))this._tone=i;else throw new TypeError("Invalid tone: ".concat(i));this._duration=e.duration,d.push("Content-Type: application/dtmf-relay");var _="Signal=".concat(this._tone,`\r
47
+ `);_+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(Yp.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(u){a.emit("succeeded",{originator:"remote",response:u})},onErrorResponse:function(u){a.eventHandlers.onFailed&&a.eventHandlers.onFailed(),a.emit("failed",{originator:"remote",response:u})},onRequestTimeout:function(){a._session.onRequestTimeout()},onTransportError:function(){a._session.onTransportError()},onDialogError:function(){a._session.onDialogError()}},body:_})}},{key:"init_incoming",value:function(i){var a=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,e=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=i,i.reply(200),i.body){var d=i.body.split(`
48
+ `);d.length>=1&&a.test(d[0])&&(this._tone=d[0].replace(a,"$2")),d.length>=2&&e.test(d[1])&&(this._duration=parseInt(d[1].replace(e,"$2"),10))}this._duration||(this._duration=Zc.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:i}):Jp.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),s}(Gp),Zl.exports.C=Zc;var Xp=Zl.exports;function jo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?jo=function(n){return typeof n}:jo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},jo(l)}function Qp(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function eh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Zp(l,n,s){return n&&eh(l.prototype,n),s&&eh(l,s),l}function ef(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&ta(l,n)}function ta(l,n){return ta=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},ta(l,n)}function tf(l){var n=rf();return function(){var s=$o(l),i;if(n){var a=$o(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return nf(this,i)}}function nf(l,n){return n&&(jo(n)==="object"||typeof n=="function")?n:sf(l)}function sf(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function rf(){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(l){return $o=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},$o(l)}var of=ut.EventEmitter,lf=nt,af=Fn,uf=At(),cf=function(l){ef(s,l);var n=tf(s);function s(i){var a;return Qp(this,s),a=n.call(this),a._session=i,a._direction=null,a._contentType=null,a._body=null,a}return Zp(s,[{key:"send",value:function(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",i===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 af.InvalidStateError(this._session.status);this._contentType=i,this._body=a;var _=uf.cloneArray(d.extraHeaders);_.push("Content-Type: ".concat(i)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(lf.INFO,{extraHeaders:_,eventHandlers:{onSuccessResponse:function(u){e.emit("succeeded",{originator:"remote",response:u})},onErrorResponse:function(u){e.emit("failed",{originator:"remote",response:u})},onTransportError:function(){e._session.onTransportError()},onRequestTimeout:function(){e._session.onRequestTimeout()},onDialogError:function(){e._session.onDialogError()}},body:a})}},{key:"init_incoming",value:function(i){this._direction="incoming",this.request=i,i.reply(200),this._contentType=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,this._body=i.body,this._session.newInfo({originator:"remote",info:this,request:i})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),s}(of);function hf(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function th(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function df(l,n,s){return n&&th(l.prototype,n),s&&th(l,s),l}var _f=ct,nh=nt,pf=new _f("RTCSession:ReferNotifier"),na={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},ff=function(){function l(n,s,i){hf(this,l),this._session=n,this._id=s,this._expires=i||na.expires,this._active=!0,this.notify(100)}return df(l,[{key:"notify",value:function(n,s){if(pf.debug("notify()"),this._active!==!1){s=s||nh.REASON_PHRASE[n]||"";var i;n>=200?i="terminated;reason=noresource":i="active;expires=".concat(this._expires),this._session.sendRequest(nh.NOTIFY,{extraHeaders:["Event: ".concat(na.event_type,";id=").concat(this._id),"Subscription-State: ".concat(i),"Content-Type: ".concat(na.body_type)],body:"SIP/2.0 ".concat(n," ").concat(s),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),l}();function Vo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Vo=function(n){return typeof n}:Vo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Vo(l)}function mf(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function sh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function gf(l,n,s){return n&&sh(l.prototype,n),s&&sh(l,s),l}function Tf(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&sa(l,n)}function sa(l,n){return sa=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},sa(l,n)}function vf(l){var n=Sf();return function(){var s=Bo(l),i;if(n){var a=Bo(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return yf(this,i)}}function yf(l,n){return n&&(Vo(n)==="object"||typeof n=="function")?n:Ef(l)}function Ef(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Sf(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Bo(l){return Bo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Bo(l)}var Af=ut.EventEmitter,Cf=ct,cr=nt,bf=ln(),rh=At(),es=new Cf("RTCSession:ReferSubscriber"),Rf=function(l){Tf(s,l);var n=vf(s);function s(i){var a;return mf(this,s),a=n.call(this),a._id=null,a._session=i,a}return gf(s,[{key:"sendRefer",value:function(i){var a=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};es.debug("sendRefer()");var d=rh.cloneArray(e.extraHeaders),_=rh.cloneObject(e.eventHandlers);for(var u in _)Object.prototype.hasOwnProperty.call(_,u)&&this.on(u,_[u]);var g=null;e.replaces&&(g=e.replaces._request.call_id,g+=";to-tag=".concat(e.replaces._to_tag),g+=";from-tag=".concat(e.replaces._from_tag),g=encodeURIComponent(g));var f="Refer-To: <".concat(i).concat(g?"?Replaces=".concat(g):"",">");if(d.push(f),!d.some(function(A){return A.toLowerCase().startsWith("referred-by:")})){var T="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");d.push(T)}d.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(cr.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(A){a._requestSucceeded(A)},onErrorResponse:function(A){a._requestFailed(A,cr.causes.REJECTED)},onTransportError:function(){a._requestFailed(null,cr.causes.CONNECTION_ERROR)},onRequestTimeout:function(){a._requestFailed(null,cr.causes.REQUEST_TIMEOUT)},onDialogError:function(){a._requestFailed(null,cr.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(i){if(es.debug("receiveNotify()"),!!i.body){var a=bf.parse(i.body.trim().split(`\r
49
+ `,1)[0],"Status_Line");if(a===-1){es.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(i.body,'"'));return}switch(!0){case/^100$/.test(a.status_code):this.emit("trying",{request:i,status_line:a});break;case/^1[0-9]{2}$/.test(a.status_code):this.emit("progress",{request:i,status_line:a});break;case/^2[0-9]{2}$/.test(a.status_code):this.emit("accepted",{request:i,status_line:a});break;default:this.emit("failed",{request:i,status_line:a});break}}}},{key:"_requestSucceeded",value:function(i){es.debug("REFER succeeded"),es.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:i})}},{key:"_requestFailed",value:function(i,a){es.debug("REFER failed"),es.debug('emit "requestFailed"'),this.emit("requestFailed",{response:i||null,cause:a})}},{key:"id",get:function(){return this._id}}]),s}(Af);function Ko(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ko=function(n){return typeof n}:Ko=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ko(l)}function mn(l,n){var s;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(s=If(l))||n&&l&&typeof l.length=="number"){s&&(l=s);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){s=l[Symbol.iterator]()},n:function(){var u=s.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&s.return!=null&&s.return()}finally{if(d)throw _}}}}function If(l,n){if(l){if(typeof l=="string")return ih(l,n);var s=Object.prototype.toString.call(l).slice(8,-1);if(s==="Object"&&l.constructor&&(s=l.constructor.name),s==="Map"||s==="Set")return Array.from(l);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return ih(l,n)}}function ih(l,n){(n==null||n>l.length)&&(n=l.length);for(var s=0,i=new Array(n);s<n;s++)i[s]=l[s];return i}function wf(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function oh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function lh(l,n,s){return n&&oh(l.prototype,n),s&&oh(l,s),l}function Of(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&ra(l,n)}function ra(l,n){return ra=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},ra(l,n)}function Nf(l){var n=Uf();return function(){var s=Go(l),i;if(n){var a=Go(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return Df(this,i)}}function Df(l,n){return n&&(Ko(n)==="object"||typeof n=="function")?n:kf(l)}function kf(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Uf(){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 Go(l){return Go=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Go(l)}var Mf=ut.EventEmitter,ah=Dt,Pf=ct,le=nt,ts=Fn,uh=or,Ve=At(),hr=Lc,xf=_n,Wo=Hp,Lf=lr,xt=Xp,ch=cf,Hf=ff,qf=Rf,hh=jn(),B=new Pf("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},Yo=["audio","video"],Ff=function(l){Of(s,l);var n=Nf(s);lh(s,null,[{key:"C",get:function(){return z}}]);function s(i){var a;return wf(this,s),B.debug("new"),a=n.call(this),a._id=null,a._ua=i,a._status=z.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:le.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},a._referSubscribers={},a._data={},a}return lh(s,[{key:"isInProgress",value:function(){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}}},{key:"isEstablished",value:function(){switch(this._status){case z.STATUS_ANSWERED:case z.STATUS_WAITING_FOR_ACK:case z.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case z.STATUS_CANCELED:case z.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(i){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},e=arguments.length>2?arguments[2]:void 0;B.debug("connect()");var d=i,_=Ve.cloneObject(a.eventHandlers),u=Ve.cloneArray(a.extraHeaders),g=Ve.cloneObject(a.mediaConstraints,{audio:!0,video:!0}),f=a.mediaStream||null,T=Ve.cloneObject(a.pcConfig,{iceServers:[]}),y=a.rtcConstraints||null,A=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,i===void 0)throw new TypeError("Not enough arguments");if(this._status!==z.STATUS_NULL)throw new ts.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new ts.NotSupportedError("WebRTC not supported");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ve.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=le.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=le.SESSION_EXPIRES);for(var w in _)Object.prototype.hasOwnProperty.call(_,w)&&this.on(w,_[w]);this._from_tag=Ve.newTag();var b=a.anonymous||!1,R={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:b,outbound:!0}),b?(R.from_display_name="Anonymous",R.from_uri=new hh("sip","anonymous","anonymous.invalid"),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),u.push("Privacy: id")):a.fromUserName&&(R.from_uri=new hh("sip",a.fromUserName,this._ua.configuration.uri.host),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),a.fromDisplayName&&(R.from_display_name=a.fromDisplayName),u.push("Contact: ".concat(this._contact)),u.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&u.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new xf.InitialOutgoingInviteRequest(i,this._ua,R,u),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(T,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,e&&e(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,f)}},{key:"init_incoming",value:function(i,a){var e=this;B.debug("init_incoming()");var d,_=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0;if(i.body&&_!=="application/sdp"){i.reply(415);return}if(this._status=z.STATUS_INVITE_RECEIVED,this._from_tag=i.from_tag,this._id=i.call_id+this._from_tag,this._request=i,this._contact=this._ua.contact.toString(),i.hasHeader("expires")&&(d=i.getHeader("expires")*1e3),i.to_tag=Ve.newTag(),!this._createDialog(i,"UAS",!0)){i.reply(500,"Missing Contact header field");return}i.body?this._late_sdp=!1:this._late_sdp=!0,this._status=z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){i.reply(408),e._failed("local",null,le.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){e._status===z.STATUS_WAITING_FOR_ANSWER&&(i.reply(487),e._failed("system",null,le.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=i.to,this._remote_identity=i.from,a&&a(this),this._newRTCSession("remote",i),this._status!==z.STATUS_TERMINATED&&(i.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("answer()");var e=this._request,d=Ve.cloneArray(a.extraHeaders),_=Ve.cloneObject(a.mediaConstraints),u=a.mediaStream||null,g=Ve.cloneObject(a.pcConfig,{iceServers:[]}),f=a.rtcConstraints||null,T=a.rtcAnswerConstraints||null,y=Ve.cloneObject(a.rtcOfferConstraints),A,w=!1,b=!1,R=!1,G=!1;if(this._rtcAnswerConstraints=T,this._rtcOfferConstraints=a.rtcOfferConstraints||null,this._data=a.data||this._data,this._direction!=="incoming")throw new ts.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==z.STATUS_WAITING_FOR_ANSWER)throw new ts.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ve.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=le.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=le.SESSION_EXPIRES),this._status=z.STATUS_ANSWERED,!this._createDialog(e,"UAS")){e.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var x=e.parseSDP();Array.isArray(x.media)||(x.media=[x.media]);var me=mn(x.media),O;try{for(me.s();!(O=me.n()).done;){var $=O.value;$.type==="audio"&&(w=!0,(!$.direction||$.direction==="sendrecv")&&(R=!0)),$.type==="video"&&(b=!0,(!$.direction||$.direction==="sendrecv")&&(G=!0))}}catch(P){me.e(P)}finally{me.f()}if(u&&_.audio===!1){A=u.getAudioTracks();var de=mn(A),fe;try{for(de.s();!(fe=de.n()).done;){var N=fe.value;u.removeTrack(N)}}catch(P){de.e(P)}finally{de.f()}}if(u&&_.video===!1){A=u.getVideoTracks();var H=mn(A),j;try{for(H.s();!(j=H.n()).done;){var F=j.value;u.removeTrack(F)}}catch(P){H.e(P)}finally{H.f()}}!u&&_.audio===void 0&&(_.audio=R),!u&&_.video===void 0&&(_.video=G),!u&&!w&&!y.offerToReceiveAudio&&(_.audio=!1),!u&&!b&&!y.offerToReceiveVideo&&(_.video=!1),this._createRTCConnection(g,f),Promise.resolve().then(function(){if(u)return u;if(_.audio||_.video)return i._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(_).catch(function(P){throw i._status===z.STATUS_TERMINATED?new Error("terminated"):(e.reply(480),i._failed("local",null,le.causes.USER_DENIED_MEDIA_ACCESS),B.warn('emit "getusermediafailed" [error:%o]',P),i.emit("getusermediafailed",P),new Error("getUserMedia() failed"))})}).then(function(P){if(i._status===z.STATUS_TERMINATED)throw new Error("terminated");i._localMediaStream=P,P&&P.getTracks().forEach(function(W){i._connection.addTrack(W,P)})}).then(function(){if(!i._late_sdp){var P={originator:"remote",type:"offer",sdp:e.body};B.debug('emit "sdp"'),i.emit("sdp",P);var W=new RTCSessionDescription({type:"offer",sdp:P.sdp});return i._connectionPromiseQueue=i._connectionPromiseQueue.then(function(){return i._connection.setRemoteDescription(W)}).catch(function(ee){throw e.reply(488),i._failed("system",null,le.causes.WEBRTC_ERROR),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',ee),i.emit("peerconnection:setremotedescriptionfailed",ee),new Error("peerconnection.setRemoteDescription() failed")}),i._connectionPromiseQueue}}).then(function(){if(i._status===z.STATUS_TERMINATED)throw new Error("terminated");return i._connecting(e),i._late_sdp?i._createLocalDescription("offer",i._rtcOfferConstraints).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")}):i._createLocalDescription("answer",T).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")})}).then(function(P){if(i._status===z.STATUS_TERMINATED)throw new Error("terminated");i._handleSessionTimersInIncomingRequest(e,d),e.reply(200,null,d,P,function(){i._status=z.STATUS_WAITING_FOR_ACK,i._setInvite2xxTimer(e,P),i._setACKTimer(),i._accepted("local")},function(){i._failed("system",null,le.causes.CONNECTION_ERROR)})}).catch(function(P){i._status!==z.STATUS_TERMINATED&&B.warn(P)})}},{key:"terminate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("terminate()");var e=a.cause||le.causes.BYE,d=Ve.cloneArray(a.extraHeaders),_=a.body,u,g=a.status_code,f=a.reason_phrase;if(this._status===z.STATUS_TERMINATED)throw new ts.InvalidStateError(this._status);switch(this._status){case z.STATUS_NULL:case z.STATUS_INVITE_SENT:case z.STATUS_1XX_RECEIVED:if(B.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(f=f||le.REASON_PHRASE[g]||"",u="SIP ;cause=".concat(g,' ;text="').concat(f,'"')),this._status===z.STATUS_NULL||this._status===z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=u):this._status===z.STATUS_1XX_RECEIVED&&this._request.cancel(u),this._status=z.STATUS_CANCELED,this._failed("local",null,le.causes.CANCELED);break;case z.STATUS_WAITING_FOR_ANSWER:case z.STATUS_ANSWERED:if(B.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,f,d,_),this._failed("local",null,le.causes.REJECTED);break;case z.STATUS_WAITING_FOR_ACK:case z.STATUS_CONFIRMED:if(B.debug("terminating session"),f=a.reason_phrase||le.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(f,'"')),this._status===z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==uh.C.STATUS_TERMINATED){var T=this._dialog;this.receiveRequest=function(y){var A=y.method;A===le.ACK&&(i.sendRequest(le.BYE,{extraHeaders:d,body:_}),T.terminate())},this._request.server_transaction.on("stateChanged",function(){i._request.server_transaction.state===uh.C.STATUS_TERMINATED&&(i.sendRequest(le.BYE,{extraHeaders:d,body:_}),T.terminate())}),this._ended("local",null,e),this._dialog=T,this._ua.newDialog(T)}else this.sendRequest(le.BYE,{extraHeaders:d,body:_}),this._ended("local",null,e)}}},{key:"sendDTMF",value:function(i){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};B.debug("sendDTMF() | tones: %s",i);var e=0,d=a.duration||null,_=a.interToneGap||null,u=a.transportType||le.DTMF_TRANSPORT.INFO;if(i===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 ts.InvalidStateError(this._status);if(u!==le.DTMF_TRANSPORT.INFO&&u!==le.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(u));if(typeof i=="number"&&(i=i.toString()),!i||typeof i!="string"||!i.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(i));if(d&&!Ve.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<xt.C.MIN_DURATION?(B.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(xt.C.MIN_DURATION," milliseconds")),d=xt.C.MIN_DURATION):d>xt.C.MAX_DURATION?(B.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(xt.C.MAX_DURATION," milliseconds")),d=xt.C.MAX_DURATION):d=Math.abs(d):d=xt.C.DEFAULT_DURATION,a.duration=d,_&&!Ve.isDecimal(_))throw new TypeError("Invalid interToneGap: ".concat(_));if(_?_<xt.C.MIN_INTER_TONE_GAP?(B.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(xt.C.MIN_INTER_TONE_GAP," milliseconds")),_=xt.C.MIN_INTER_TONE_GAP):_=Math.abs(_):_=xt.C.DEFAULT_INTER_TONE_GAP,u===le.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(i=g.toneBuffer+i,g.insertDTMF(i,d,_));return}if(this._tones){this._tones+=i;return}this._tones=i,f.call(this);function f(){var T=this,y;if(this._status===z.STATUS_TERMINATED||!this._tones||e>=this._tones.length){this._tones=null;return}var A=this._tones[e];if(e+=1,A===",")y=2e3;else{var w=new xt(this);a.eventHandlers={onFailed:function(){T._tones=null}},w.send(A,a),y=d+_}setTimeout(f.bind(this),y)}}},{key:"sendInfo",value:function(i,a){var e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(B.debug("sendInfo()"),this._status!==z.STATUS_CONFIRMED&&this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_1XX_RECEIVED)throw new ts.InvalidStateError(this._status);var d=new ch(this);d.send(i,a,e)}},{key:"mute",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};B.debug("mute()");var a=!1,e=!1;this._audioMuted===!1&&i.audio&&(a=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&i.video&&(e=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(a===!0||e===!0)&&this._onmute({audio:a,video:e})}},{key:"unmute",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};B.debug("unmute()");var a=!1,e=!1;this._audioMuted===!0&&i.audio&&(a=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&i.video&&(e=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(a===!0||e===!0)&&this._onunmute({audio:a,video:e})}},{key:"hold",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(B.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");var d={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:le.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:a.extraHeaders}),!0}},{key:"unhold",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(B.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");var d={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:le.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:a.extraHeaders}),!0}},{key:"renegotiate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;B.debug("renegotiate()");var d=a.rtcOfferConstraints||null;if(this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var _={succeeded:function(){e&&e()},failed:function(){i.terminate({cause:le.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),a.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:_,rtcOfferConstraints:d,extraHeaders:a.extraHeaders}):this._sendReinvite({eventHandlers:_,rtcOfferConstraints:d,extraHeaders:a.extraHeaders}),!0}},{key:"refer",value:function(i,a){var e=this;B.debug("refer()");var d=i;if(this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_CONFIRMED)return!1;if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(d));var _=new qf(this);_.sendRefer(i,a);var u=_.id;return this._referSubscribers[u]=_,_.on("requestFailed",function(){delete e._referSubscribers[u]}),_.on("accepted",function(){delete e._referSubscribers[u]}),_.on("failed",function(){delete e._referSubscribers[u]}),_}},{key:"sendRequest",value:function(i,a){return B.debug("sendRequest()"),this._dialog.sendRequest(i,a)}},{key:"receiveRequest",value:function(i){var a=this;if(B.debug("receiveRequest()"),i.method===le.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",i,le.causes.CANCELED));else switch(i.method){case le.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(!i.body){this.terminate({cause:le.causes.MISSING_SDP,status_code:400});break}var e={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",e);var d=new RTCSessionDescription({type:"answer",sdp:e.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(d)}).then(function(){a._is_confirmed||a._confirmed("remote",i)}).catch(function(u){a.terminate({cause:le.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',u),a.emit("peerconnection:setremotedescriptionfailed",u)})}else this._is_confirmed||this._confirmed("remote",i);break;case le.BYE:this._status===z.STATUS_CONFIRMED||this._status===z.STATUS_WAITING_FOR_ACK?(i.reply(200),this._ended("remote",i,le.causes.BYE)):this._status===z.STATUS_INVITE_RECEIVED||this._status===z.STATUS_WAITING_FOR_ANSWER?(i.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",i,le.causes.BYE)):i.reply(403,"Wrong Status");break;case le.INVITE:this._status===z.STATUS_CONFIRMED?i.hasHeader("replaces")?this._receiveReplaces(i):this._receiveReinvite(i):i.reply(403,"Wrong Status");break;case le.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){var _=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0;_&&_.match(/^application\/dtmf-relay/i)?new xt(this).init_incoming(i):_!==void 0?new ch(this).init_incoming(i):i.reply(415)}else i.reply(403,"Wrong Status");break;case le.UPDATE:this._status===z.STATUS_CONFIRMED?this._receiveUpdate(i):i.reply(403,"Wrong Status");break;case le.REFER:this._status===z.STATUS_CONFIRMED?this._receiveRefer(i):i.reply(403,"Wrong Status");break;case le.NOTIFY:this._status===z.STATUS_CONFIRMED?this._receiveNotify(i):i.reply(403,"Wrong Status");break;default:i.reply(501)}}},{key:"onTransportError",value:function(){B.warn("onTransportError()"),this._status!==z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:le.causes.CONNECTION_ERROR,cause:le.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){B.warn("onRequestTimeout()"),this._status!==z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:le.causes.REQUEST_TIMEOUT,cause:le.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){B.warn("onDialogError()"),this._status!==z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:le.causes.DIALOG_ERROR,cause:le.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(i){B.debug("newDTMF()"),this.emit("newDTMF",i)}},{key:"newInfo",value:function(i){B.debug("newInfo()"),this.emit("newInfo",i)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(B.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(B.debug("_isReadyToReOffer() | session not established yet"),!1):(B.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(B.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(B.debug("close() | closing local MediaStream"),Ve.closeMediaStream(this._localMediaStream)),this._status!==z.STATUS_TERMINATED){if(this._status=z.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){B.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var i in this._timers)Object.prototype.hasOwnProperty.call(this._timers,i)&&clearTimeout(this._timers[i]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var a in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,a)&&(this._earlyDialogs[a].terminate(),delete this._earlyDialogs[a]);for(var e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(i,a){var e=hr.T1;function d(){this._status===z.STATUS_WAITING_FOR_ACK&&(i.reply(200,null,["Contact: ".concat(this._contact)],a),e<hr.T2&&(e=e*2,e>hr.T2&&(e=hr.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),e))}this._timers.invite2xxTimer=setTimeout(d.bind(this),e)}},{key:"_setACKTimer",value:function(){var i=this;this._timers.ackTimer=setTimeout(function(){i._status===z.STATUS_WAITING_FOR_ACK&&(B.debug("no ACK received, terminating the session"),clearTimeout(i._timers.invite2xxTimer),i.sendRequest(le.BYE),i._ended("remote",null,le.causes.NO_ACK))},hr.TIMER_H)}},{key:"_createRTCConnection",value:function(i,a){var e=this;this._connection=new RTCPeerConnection(i,a),this._connection.addEventListener("iceconnectionstatechange",function(){var d=e._connection.iceConnectionState;d==="failed"&&e.terminate({cause:le.causes.RTP_TIMEOUT,status_code:408,reason_phrase:le.causes.RTP_TIMEOUT})}),B.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(i,a){var e=this;if(B.debug("createLocalDescription()"),i!=="offer"&&i!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(i,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return i==="offer"?d.createOffer(a).catch(function(_){return B.warn('emit "peerconnection:createofferfailed" [error:%o]',_),e.emit("peerconnection:createofferfailed",_),Promise.reject(_)}):d.createAnswer(a).catch(function(_){return B.warn('emit "peerconnection:createanswerfailed" [error:%o]',_),e.emit("peerconnection:createanswerfailed",_),Promise.reject(_)})}).then(function(_){return d.setLocalDescription(_).catch(function(u){return e._rtcReady=!0,B.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',u),e.emit("peerconnection:setlocaldescriptionfailed",u),Promise.reject(u)})}).then(function(){var _=a&&a.iceRestart;if(d.iceGatheringState==="complete"&&!_||d.iceGatheringState==="gathering"&&e._iceReady){e._rtcReady=!0;var u={originator:"local",type:i,sdp:d.localDescription.sdp};return B.debug('emit "sdp"'),e.emit("sdp",u),Promise.resolve(u.sdp)}return new Promise(function(g){var f=!1,T,y;e._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",T),d.removeEventListener("icegatheringstatechange",y),f=!0,e._rtcReady=!0,e._iceReady=!0;var w={originator:"local",type:i,sdp:d.localDescription.sdp};B.debug('emit "sdp"'),e.emit("sdp",w),g(w.sdp)};d.addEventListener("icecandidate",T=function(w){var b=w.candidate;b?e.emit("icecandidate",{candidate:b,ready:A}):f||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!f&&A()})})})}},{key:"_createDialog",value:function(i,a,e){var d=a==="UAS"?i.to_tag:i.from_tag,_=a==="UAS"?i.from_tag:i.to_tag,u=i.call_id+d+_,g=this._earlyDialogs[u];if(e)return g?!0:(g=new Wo(this,i,a,Wo.C.STATUS_EARLY),g.error?(B.debug(g.error),this._failed("remote",i,le.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[u]=g,!0));if(this._from_tag=i.from_tag,this._to_tag=i.to_tag,g)return g.update(i,a),this._dialog=g,delete this._earlyDialogs[u],!0;var f=new Wo(this,i,a);return f.error?(B.debug(f.error),this._failed("remote",i,le.causes.INTERNAL_ERROR),!1):(this._dialog=f,!0)}},{key:"_receiveReinvite",value:function(i){var a=this;B.debug("receiveReinvite()");var e=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,d={request:i,callback:void 0,reject:u.bind(this)},_=!1;function u(){var f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var T=f.status_code||403,y=f.reason_phrase||"",A=Ve.cloneArray(f.extraHeaders);if(this._status!==z.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));i.reply(T,y,A)}if(this.emit("reinvite",d),_)return;if(this._late_sdp=!1,!i.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",a._rtcOfferConstraints)}).then(function(f){g.call(a,f)}).catch(function(){i.reply(500)});return}if(e!=="application/sdp"){B.debug("invalid Content-Type"),i.reply(415);return}this._processInDialogSdpOffer(i).then(function(f){a._status!==z.STATUS_TERMINATED&&g.call(a,f)}).catch(function(f){B.warn(f)});function g(f){var T=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(i,y),this._late_sdp&&(f=this._mangleOffer(f)),i.reply(200,null,y,f,function(){T._status=z.STATUS_WAITING_FOR_ACK,T._setInvite2xxTimer(i,f),T._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(i){var a=this;B.debug("receiveUpdate()");var e=i.hasHeader("Content-Type")?i.getHeader("Content-Type").toLowerCase():void 0,d={request:i,callback:void 0,reject:u.bind(this)},_=!1;function u(){var f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var T=f.status_code||403,y=f.reason_phrase||"",A=Ve.cloneArray(f.extraHeaders);if(this._status!==z.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));i.reply(T,y,A)}if(this.emit("update",d),_)return;if(!i.body){g.call(this,null);return}if(e!=="application/sdp"){B.debug("invalid Content-Type"),i.reply(415);return}this._processInDialogSdpOffer(i).then(function(f){a._status!==z.STATUS_TERMINATED&&g.call(a,f)}).catch(function(f){B.warn(f)});function g(f){var T=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(i,T),i.reply(200,null,T,f),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(i){var a=this;B.debug("_processInDialogSdpOffer()");var e=i.parseSDP(),d=!1,_=mn(e.media),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;if(Yo.indexOf(g.type)!==-1){var f=g.direction||e.direction||"sendrecv";if(f==="sendonly"||f==="inactive")d=!0;else{d=!1;break}}}}catch(A){_.e(A)}finally{_.f()}var T={originator:"remote",type:"offer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",T);var y=new RTCSessionDescription({type:"offer",sdp:T.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(a._status===z.STATUS_TERMINATED)throw new Error("terminated");return a._connection.setRemoteDescription(y).catch(function(A){throw i.reply(488),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),a.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(a._status===z.STATUS_TERMINATED)throw new Error("terminated");a._remoteHold===!0&&d===!1?(a._remoteHold=!1,a._onunhold("remote")):a._remoteHold===!1&&d===!0&&(a._remoteHold=!0,a._onhold("remote"))}).then(function(){if(a._status===z.STATUS_TERMINATED)throw new Error("terminated");return a._createLocalDescription("answer",a._rtcAnswerConstraints).catch(function(A){throw i.reply(500),B.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){B.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(i){var a=this;if(B.debug("receiveRefer()"),!i.refer_to){B.debug("no Refer-To header field present in REFER"),i.reply(400);return}if(i.refer_to.uri.scheme!==le.SIP){B.debug("Refer-To header field points to a non-SIP URI scheme"),i.reply(416);return}i.reply(202);var e=new Hf(this,i.cseq);B.debug('emit "refer"'),this.emit("refer",{request:i,accept:function(u,g){d.call(a,u,g)},reject:function(){_.call(a)}});function d(u){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(u=typeof u=="function"?u:null,this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_CONFIRMED)return!1;var f=new s(this._ua);if(f.on("progress",function(y){var A=y.response;e.notify(A.status_code,A.reason_phrase)}),f.on("accepted",function(y){var A=y.response;e.notify(A.status_code,A.reason_phrase)}),f.on("_failed",function(y){var A=y.message,w=y.cause;A?e.notify(A.status_code,A.reason_phrase):e.notify(487,w)}),i.refer_to.uri.hasHeader("replaces")){var T=decodeURIComponent(i.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ve.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(T))}f.connect(i.refer_to.uri.toAor(),g,u)}function _(){e.notify(603)}}},{key:"_receiveNotify",value:function(i){switch(B.debug("receiveNotify()"),i.event||i.reply(400),i.event.event){case"refer":{var a,e;if(i.event.params&&i.event.params.id)a=i.event.params.id,e=this._referSubscribers[a];else if(Object.keys(this._referSubscribers).length===1)e=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{i.reply(400,"Missing event id parameter");return}if(!e){i.reply(481,"Subscription does not exist");return}e.receiveNotify(i),i.reply(200);break}default:i.reply(489)}}},{key:"_receiveReplaces",value:function(i){var a=this;B.debug("receiveReplaces()");function e(_){var u=this;if(this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_CONFIRMED)return!1;var g=new s(this._ua);g.on("confirmed",function(){u.terminate()}),g.init_incoming(i,_)}function d(){B.debug("Replaced INVITE rejected by the user"),i.reply(486)}this.emit("replaces",{request:i,accept:function(_){e.call(a,_)},reject:function(){d.call(a)}})}},{key:"_sendInitialRequest",value:function(i,a,e){var d=this,_=new Lf(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(u){d._request=u},onReceiveResponse:function(u){d._receiveInviteResponse(u)}});Promise.resolve().then(function(){if(e)return e;if(i.audio||i.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(u){throw d._status===z.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,le.causes.USER_DENIED_MEDIA_ACCESS),B.warn('emit "getusermediafailed" [error:%o]',u),d.emit("getusermediafailed",u),u)})}).then(function(u){if(d._status===z.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=u,u&&u.getTracks().forEach(function(g){d._connection.addTrack(g,u)}),d._connecting(d._request),d._createLocalDescription("offer",a).catch(function(g){throw d._failed("local",null,le.causes.WEBRTC_ERROR),g})}).then(function(u){if(d._is_canceled||d._status===z.STATUS_TERMINATED)throw new Error("terminated");d._request.body=u,d._status=z.STATUS_INVITE_SENT,B.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),_.send()}).catch(function(u){d._status!==z.STATUS_TERMINATED&&B.warn(u)})}},{key:"_getDTMFRTPSender",value:function(){var i=this._connection.getSenders().find(function(a){return a.track&&a.track.kind==="audio"});if(!(i&&i.dtmf)){B.warn("sendDTMF() | no local audio track to send DTMF with");return}return i.dtmf}},{key:"_receiveInviteResponse",value:function(i){var a=this;if(B.debug("receiveInviteResponse()"),this._dialog&&i.status_code>=200&&i.status_code<=299)if(this._dialog.id.call_id===i.call_id&&this._dialog.id.local_tag===i.from_tag&&this._dialog.id.remote_tag===i.to_tag){this.sendRequest(le.ACK);return}else{var e=new Wo(this,i,"UAC");if(e.error!==void 0){B.debug(e.error);return}this.sendRequest(le.ACK),this.sendRequest(le.BYE);return}if(this._is_canceled){i.status_code>=100&&i.status_code<200?this._request.cancel(this._cancel_reason):i.status_code>=200&&i.status_code<299&&this._acceptAndTerminate(i);return}if(!(this._status!==z.STATUS_INVITE_SENT&&this._status!==z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(i.status_code):this._status=z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(i.status_code):{if(!i.to_tag){B.debug("1xx response received without to tag");break}if(i.hasHeader("contact")&&!this._createDialog(i,"UAC",!0))break;if(this._status=z.STATUS_1XX_RECEIVED,!i.body){this._progress("remote",i);break}var d={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",d);var _=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(_)}).then(function(){return a._progress("remote",i)}).catch(function(T){B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),a.emit("peerconnection:setremotedescriptionfailed",T)});break}case/^2[0-9]{2}$/.test(i.status_code):{if(this._status=z.STATUS_CONFIRMED,!i.body){this._acceptAndTerminate(i,400,le.causes.MISSING_SDP),this._failed("remote",i,le.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(i,"UAC"))break;var u={originator:"remote",type:"answer",sdp:i.body};B.debug('emit "sdp"'),this.emit("sdp",u);var g=new RTCSessionDescription({type:"answer",sdp:u.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(a._connection.signalingState==="stable")return a._connection.createOffer(a._rtcOfferConstraints).then(function(T){return a._connection.setLocalDescription(T)}).catch(function(T){a._acceptAndTerminate(i,500,T.toString()),a._failed("local",i,le.causes.WEBRTC_ERROR)})}).then(function(){a._connection.setRemoteDescription(g).then(function(){a._handleSessionTimersInIncomingResponse(i),a._accepted("remote",i),a.sendRequest(le.ACK),a._confirmed("local",null)}).catch(function(T){a._acceptAndTerminate(i,488,"Not Acceptable Here"),a._failed("remote",i,le.causes.BAD_MEDIA_DESCRIPTION),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),a.emit("peerconnection:setremotedescriptionfailed",T)})});break}default:{var f=Ve.sipErrorCause(i.status_code);this._failed("remote",i,f)}}}},{key:"_sendReinvite",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("sendReinvite()");var e=Ve.cloneArray(a.extraHeaders),d=Ve.cloneObject(a.eventHandlers),_=a.rtcOfferConstraints||this._rtcOfferConstraints||null,u=!1;e.push("Contact: ".concat(this._contact)),e.push("Content-Type: application/sdp"),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return i._createLocalDescription("offer",_)}).then(function(T){T=i._mangleOffer(T);var y={originator:"local",type:"offer",sdp:T};B.debug('emit "sdp"'),i.emit("sdp",y),i.sendRequest(le.INVITE,{extraHeaders:e,body:T,eventHandlers:{onSuccessResponse:function(A){g.call(i,A),u=!0},onErrorResponse:function(A){f.call(i,A)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}})}).catch(function(){f()});function g(T){var y=this;if(this._status!==z.STATUS_TERMINATED&&(this.sendRequest(le.ACK),!u)){if(this._handleSessionTimersInIncomingResponse(T),T.body){if(!T.hasHeader("Content-Type")||T.getHeader("Content-Type").toLowerCase()!=="application/sdp"){f.call(this);return}}else{f.call(this);return}var A={originator:"remote",type:"answer",sdp:T.body};B.debug('emit "sdp"'),this.emit("sdp",A);var w=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(w)}).then(function(){d.succeeded&&d.succeeded(T)}).catch(function(b){f.call(y),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',b),y.emit("peerconnection:setremotedescriptionfailed",b)})}}function f(T){d.failed&&d.failed(T)}}},{key:"_sendUpdate",value:function(){var i=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};B.debug("sendUpdate()");var e=Ve.cloneArray(a.extraHeaders),d=Ve.cloneObject(a.eventHandlers),_=a.rtcOfferConstraints||this._rtcOfferConstraints||null,u=a.sdpOffer||!1,g=!1;e.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),u?(e.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return i._createLocalDescription("offer",_)}).then(function(y){y=i._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};B.debug('emit "sdp"'),i.emit("sdp",A),i.sendRequest(le.UPDATE,{extraHeaders:e,body:y,eventHandlers:{onSuccessResponse:function(w){f.call(i,w),g=!0},onErrorResponse:function(w){T.call(i,w)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}})}).catch(function(){T.call(i)})):this.sendRequest(le.UPDATE,{extraHeaders:e,eventHandlers:{onSuccessResponse:function(y){f.call(i,y)},onErrorResponse:function(y){T.call(i,y)},onTransportError:function(){i.onTransportError()},onRequestTimeout:function(){i.onRequestTimeout()},onDialogError:function(){i.onDialogError()}}});function f(y){var A=this;if(this._status!==z.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),u){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var w={originator:"remote",type:"answer",sdp:y.body};B.debug('emit "sdp"'),this.emit("sdp",w);var b=new RTCSessionDescription({type:"answer",sdp:w.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(b)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(R){T.call(A),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',R),A.emit("peerconnection:setremotedescriptionfailed",R)})}else d.succeeded&&d.succeeded(y)}function T(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(i,a,e){B.debug("acceptAndTerminate()");var d=[];a&&(e=e||le.REASON_PHRASE[a]||"",d.push("Reason: SIP ;cause=".concat(a,'; text="').concat(e,'"'))),(this._dialog||this._createDialog(i,"UAC"))&&(this.sendRequest(le.ACK),this.sendRequest(le.BYE,{extraHeaders:d})),this._status=z.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(i){if(!this._localHold&&!this._remoteHold)return i;if(i=ah.parse(i),this._localHold&&!this._remoteHold){B.debug("mangleOffer() | me on hold, mangling offer");var a=mn(i.media),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;Yo.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){a.e(A)}finally{a.f()}}else if(this._localHold&&this._remoteHold){B.debug("mangleOffer() | both on hold, mangling offer");var _=mn(i.media),u;try{for(_.s();!(u=_.n()).done;){var g=u.value;Yo.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){_.e(A)}finally{_.f()}}else if(this._remoteHold){B.debug("mangleOffer() | remote on hold, mangling offer");var f=mn(i.media),T;try{for(f.s();!(T=f.n()).done;){var y=T.value;Yo.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(A){f.e(A)}finally{f.f()}}return ah.write(i)}},{key:"_setLocalMediaStatus",value:function(){var i=!0,a=!0;(this._localHold||this._remoteHold)&&(i=!1,a=!1),this._audioMuted&&(i=!1),this._videoMuted&&(a=!1),this._toggleMuteAudio(!i),this._toggleMuteVideo(!a)}},{key:"_handleSessionTimersInIncomingRequest",value:function(i,a){if(this._sessionTimers.enabled){var e;i.session_expires&&i.session_expires>=le.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=i.session_expires,e=i.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,e="uas"),a.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(e)),this._sessionTimers.refresher=e==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(i){if(this._sessionTimers.enabled){var a;i.session_expires&&i.session_expires>=le.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=i.session_expires,a=i.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uac"),this._sessionTimers.refresher=a==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var i=this,a=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){i._status!==z.STATUS_TERMINATED&&i._isReadyToReOffer()&&(B.debug("runSessionTimer() | sending session refresh request"),i._sessionTimers.refreshMethod===le.UPDATE?i._sendUpdate():i._sendReinvite())},a*500):this._sessionTimers.timer=setTimeout(function(){i._status!==z.STATUS_TERMINATED&&(B.warn("runSessionTimer() | timer expired, terminating the session"),i.terminate({cause:le.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},a*1100)}},{key:"_toggleMuteAudio",value:function(i){var a=this._connection.getSenders().filter(function(u){return u.track&&u.track.kind==="audio"}),e=mn(a),d;try{for(e.s();!(d=e.n()).done;){var _=d.value;_.track.enabled=!i}}catch(u){e.e(u)}finally{e.f()}}},{key:"_toggleMuteVideo",value:function(i){var a=this._connection.getSenders().filter(function(u){return u.track&&u.track.kind==="video"}),e=mn(a),d;try{for(e.s();!(d=e.n()).done;){var _=d.value;_.track.enabled=!i}}catch(u){e.e(u)}finally{e.f()}}},{key:"_newRTCSession",value:function(i,a){B.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:i,session:this,request:a})}},{key:"_connecting",value:function(i){B.debug("session connecting"),B.debug('emit "connecting"'),this.emit("connecting",{request:i})}},{key:"_progress",value:function(i,a){B.debug("session progress"),B.debug('emit "progress"'),this.emit("progress",{originator:i,response:a||null})}},{key:"_accepted",value:function(i,a){B.debug("session accepted"),this._start_time=new Date,B.debug('emit "accepted"'),this.emit("accepted",{originator:i,response:a||null})}},{key:"_confirmed",value:function(i,a){B.debug("session confirmed"),this._is_confirmed=!0,B.debug('emit "confirmed"'),this.emit("confirmed",{originator:i,ack:a||null})}},{key:"_ended",value:function(i,a,e){B.debug("session ended"),this._end_time=new Date,this._close(),B.debug('emit "ended"'),this.emit("ended",{originator:i,message:a||null,cause:e})}},{key:"_failed",value:function(i,a,e){B.debug("session failed"),B.debug('emit "_failed"'),this.emit("_failed",{originator:i,message:a||null,cause:e}),this._close(),B.debug('emit "failed"'),this.emit("failed",{originator:i,message:a||null,cause:e})}},{key:"_onhold",value:function(i){B.debug("session onhold"),this._setLocalMediaStatus(),B.debug('emit "hold"'),this.emit("hold",{originator:i})}},{key:"_onunhold",value:function(i){B.debug("session onunhold"),this._setLocalMediaStatus(),B.debug('emit "unhold"'),this.emit("unhold",{originator:i})}},{key:"_onmute",value:function(i){var a=i.audio,e=i.video;B.debug("session onmute"),this._setLocalMediaStatus(),B.debug('emit "muted"'),this.emit("muted",{audio:a,video:e})}},{key:"_onunmute",value:function(i){var a=i.audio,e=i.video;B.debug("session onunmute"),this._setLocalMediaStatus(),B.debug('emit "unmuted"'),this.emit("unmuted",{audio:a,video:e})}},{key:"C",get:function(){return z}},{key:"causes",get:function(){return le.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(i){this._data=i}},{key:"status",get:function(){return this._status}}]),s}(Mf);function zo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?zo=function(n){return typeof n}:zo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},zo(l)}function jf(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function dh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function $f(l,n,s){return n&&dh(l.prototype,n),s&&dh(l,s),l}function Vf(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&ia(l,n)}function ia(l,n){return ia=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},ia(l,n)}function Bf(l){var n=Wf();return function(){var s=Jo(l),i;if(n){var a=Jo(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return Kf(this,i)}}function Kf(l,n){return n&&(zo(n)==="object"||typeof n=="function")?n:Gf(l)}function Gf(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Wf(){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 Jo(l){return Jo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Jo(l)}var Yf=ut.EventEmitter,zf=ct,oa=nt,Jf=_n,dr=At(),Xf=lr,_h=Fn,Qf=jn(),Xo=new zf("Message"),Zf=function(l){Vf(s,l);var n=Bf(s);function s(i){var a;return jf(this,s),a=n.call(this),a._ua=i,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 $f(s,[{key:"send",value:function(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=i;if(i===void 0||a===void 0)throw new TypeError("Not enough arguments");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(_));var u=dr.cloneArray(d.extraHeaders),g=dr.cloneObject(d.eventHandlers),f=d.contentType||"text/plain",T={};d.fromUserName&&(T.from_uri=new Qf("sip",d.fromUserName,this._ua.configuration.uri.host),u.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(T.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);u.push("Content-Type: ".concat(f)),this._request=new Jf.OutgoingRequest(oa.MESSAGE,i,this._ua,T,u),a&&(this._request.body=a);var A=new Xf(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(w){e._receiveResponse(w)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(i){this._request=i,this._newMessage("remote",i),this._is_replied||(this._is_replied=!0,i.reply(200)),this._close()}},{key:"accept",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=dr.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new _h.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,a,e)}},{key:"reject",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=i.status_code||480,e=i.reason_phrase,d=dr.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new _h.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(a<300||a>=700)throw new TypeError("Invalid status_code: ".concat(a));this._is_replied=!0,this._request.reply(a,e,d,_)}},{key:"_receiveResponse",value:function(i){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._succeeded("remote",i);break;default:{var a=dr.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,oa.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,oa.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(i,a){i==="remote"?(this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from):i==="local"&&(this._direction="outgoing",this._local_identity=a.from,this._remote_identity=a.to),this._ua.newMessage(this,{originator:i,message:this,request:a})}},{key:"_failed",value:function(i,a,e){Xo.debug("MESSAGE failed"),this._close(),Xo.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){Xo.debug("MESSAGE succeeded"),this._close(),Xo.debug('emit "succeeded"'),this.emit("succeeded",{originator:i,response:a})}},{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}}]),s}(Yf);function Qo(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Qo=function(n){return typeof n}:Qo=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Qo(l)}function em(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function ph(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function tm(l,n,s){return n&&ph(l.prototype,n),s&&ph(l,s),l}function nm(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&la(l,n)}function la(l,n){return la=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},la(l,n)}function sm(l){var n=om();return function(){var s=Zo(l),i;if(n){var a=Zo(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return rm(this,i)}}function rm(l,n){return n&&(Qo(n)==="object"||typeof n=="function")?n:im(l)}function im(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function om(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Zo(l){return Zo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Zo(l)}var lm=ut.EventEmitter,am=ct,aa=nt,um=_n,_r=At(),cm=lr,fh=Fn,el=new am("Options"),hm=function(l){nm(s,l);var n=sm(s);function s(i){var a;return em(this,s),a=n.call(this),a._ua=i,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 tm(s,[{key:"send",value:function(i,a){var e=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=i;if(i===void 0)throw new TypeError("A target is required for OPTIONS");if(i=this._ua.normalizeTarget(i),!i)throw new TypeError("Invalid target: ".concat(_));var u=_r.cloneArray(d.extraHeaders),g=_r.cloneObject(d.eventHandlers),f=d.contentType||"application/sdp";for(var T in g)Object.prototype.hasOwnProperty.call(g,T)&&this.on(T,g[T]);u.push("Content-Type: ".concat(f)),this._request=new um.OutgoingRequest(aa.OPTIONS,i,this._ua,null,u),a&&(this._request.body=a);var y=new cm(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(A){e._receiveResponse(A)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(i){this._request=i,this._newOptions("remote",i),this._is_replied||(this._is_replied=!0,i.reply(200)),this._close()}},{key:"accept",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=_r.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new fh.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,a,e)}},{key:"reject",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},a=i.status_code||480,e=i.reason_phrase,d=_r.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new fh.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(a<300||a>=700)throw new TypeError("Invalid status_code: ".concat(a));this._is_replied=!0,this._request.reply(a,e,d,_)}},{key:"_receiveResponse",value:function(i){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._succeeded("remote",i);break;default:{var a=_r.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,aa.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,aa.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(i,a){i==="remote"?(this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from):i==="local"&&(this._direction="outgoing",this._local_identity=a.from,this._remote_identity=a.to),this._ua.newOptions(this,{originator:i,message:this,request:a})}},{key:"_failed",value:function(i,a,e){el.debug("OPTIONS failed"),this._close(),el.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){el.debug("OPTIONS succeeded"),this._close(),el.debug('emit "succeeded"'),this.emit("succeeded",{originator:i,response:a})}},{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}}]),s}(lm),ua={},dm=ct,ca=At(),_m=ln(),pr=new dm("Socket");ua.isSocket=function(l){if(Array.isArray(l))return!1;if(typeof l>"u")return pr.warn("undefined JsSIP.Socket instance"),!1;try{if(!ca.isString(l.url))throw pr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!ca.isString(l.via_transport))throw pr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(_m.parse(l.sip_uri,"SIP_URI")===-1)throw pr.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(n){if(!ca.isFunction(l[n]))throw pr.warn("missing or invalid JsSIP.Socket method: ".concat(n)),new Error("Missing or invalid JsSIP.Socket method: ".concat(n))})}catch{return!1}return!0};function pm(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function mh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function fm(l,n,s){return n&&mh(l.prototype,n),s&&mh(l,s),l}var mm=ct,gm=ua,gh=nt,kt=new mm("Transport"),Ft={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:gh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:gh.CONNECTION_RECOVERY_MAX_INTERVAL}},Tm=function(){function l(n){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ft.recovery_options;pm(this,l),kt.debug("new()"),this.status=Ft.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=s,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(i){kt.warn("cannot use TextDecoder: ".concat(i))}if(typeof n>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");n instanceof Array||(n=[n]),n.forEach(function(i){if(!gm.isSocket(i.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(i.weight&&!Number(i.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:i.socket,weight:i.weight||0,status:Ft.SOCKET_STATUS_READY})},this),this._getSocket()}return fm(l,[{key:"connect",value:function(){if(kt.debug("connect()"),this.isConnected()){kt.debug("Transport is already connected");return}else if(this.isConnecting()){kt.debug("Transport is connecting");return}this.close_requested=!1,this.status=Ft.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){kt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Ft.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(kt.debug("send()"),!this.isConnected())return kt.warn("unable to send message, transport is not connected"),!1;var s=n.toString();return kt.debug(`sending message:
55
51
 
56
52
  `.concat(s,`
57
- `))}else Lt.debug(`received text message:
53
+ `)),this.socket.send(s)}},{key:"isConnected",value:function(){return this.status===Ft.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===Ft.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var n=this;this.recover_attempts+=1;var s=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);s<this.recovery_options.min_interval?s=this.recovery_options.min_interval:s>this.recovery_options.max_interval&&(s=this.recovery_options.max_interval),kt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(s," seconds")),this.recovery_timer=setTimeout(function(){!n.close_requested&&!(n.isConnected()||n.isConnecting())&&(n._getSocket(),n.connect())},s*1e3)}},{key:"_getSocket",value:function(){var n=[];if(this.sockets.forEach(function(i){i.status!==Ft.SOCKET_STATUS_ERROR&&(n.length===0?n.push(i):i.weight>n[0].weight?n=[i]:i.weight===n[0].weight&&n.push(i))}),n.length===0){this.sockets.forEach(function(i){i.status=Ft.SOCKET_STATUS_READY}),this._getSocket();return}var s=Math.floor(Math.random()*n.length);this.socket=n[s].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=Ft.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(n,s,i){this.status=Ft.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:n,code:s,reason:i}),!this.close_requested&&(this.sockets.forEach(function(a){this.socket===a.socket&&(a.status=Ft.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
54
+ `){kt.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{kt.debug("received binary message failed to be converted into string, message discarded");return}kt.debug(`received binary message:
58
55
 
59
- `.concat(s,`
60
- `));this.ondata({transport:this,message:s})}},{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}}]),l}(),Rh={};function Ih(l,s){var n;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(n=Cm(l))||s&&l&&typeof l.length=="number"){n&&(l=n);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){n=l[Symbol.iterator]()},n:function(){var u=n.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&n.return!=null&&n.return()}finally{if(d)throw _}}}}function Cm(l,s){if(l){if(typeof l=="string")return wh(l,s);var n=Object.prototype.toString.call(l).slice(8,-1);if(n==="Object"&&l.constructor&&(n=l.constructor.name),n==="Map"||n==="Set")return Array.from(l);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return wh(l,s)}}function wh(l,s){(s==null||s>l.length)&&(s=l.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=l[n];return i}var bm=ft,ya=dn(),Ea=Tn,al=new bm("Parser");Rh.parseMessage=function(l,s){var n,i,a=l.indexOf(`\r
62
- `);if(a===-1){al.warn("parseMessage() | no CRLF found, not a SIP message");return}var e=l.substring(0,a),d=ya.parse(e,"Request_Response");if(d===-1){al.warn('parseMessage() | error parsing first line of SIP message: "'.concat(e,'"'));return}else d.status_code?(n=new Ea.IncomingResponse,n.status_code=d.status_code,n.reason_phrase=d.reason_phrase):(n=new Ea.IncomingRequest(s),n.method=d.method,n.ruri=d.uri);n.data=l;for(var _=a+2;;){if(a=Rm(l,_),a===-2){i=_+2;break}else if(a===-1){al.warn("parseMessage() | malformed message");return}if(d=Im(n,l,_,a),d!==!0){al.warn("parseMessage() |",d.error);return}_=a+2}if(n.hasHeader("content-length")){var u=n.getHeader("content-length");n.body=l.substr(i,u)}else n.body=l.substring(i);return n};function Rm(l,s){var n=s,i=0,a=0;if(l.substring(n,n+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
63
- `,n),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?n=a+2:i=a}return i}function Im(l,s,n,i){var a,e=s.indexOf(":",n),d=s.substring(n,e).trim(),_=s.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=ya.parse(_,"Record_Route"),a===-1)a=void 0;else{var u=Ih(a),g;try{for(u.s();!(g=u.n()).done;){var p=g.value;l.addHeader("record-route",_.substring(p.possition,p.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=p.parsed}}catch(w){u.e(w)}finally{u.f()}}break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=ya.parse(_,"Contact"),a===-1)a=void 0;else{var T=Ih(a),y;try{for(T.s();!(y=T.n()).done;){var A=y.value;l.addHeader("contact",_.substring(A.possition,A.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=A.parsed}}catch(w){T.e(w)}finally{T.f()}}break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof Ea.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:'error parsing header "'.concat(d,'"')}:!0}function ul(l,s){var n;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(n=wm(l))||s&&l&&typeof l.length=="number"){n&&(l=n);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){n=l[Symbol.iterator]()},n:function(){var u=n.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&n.return!=null&&n.return()}finally{if(d)throw _}}}}function wm(l,s){if(l){if(typeof l=="string")return Oh(l,s);var n=Object.prototype.toString.call(l).slice(8,-1);if(n==="Object"&&l.constructor&&(n=l.constructor.name),n==="Map"||n==="Set")return Array.from(l);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Oh(l,s)}}function Oh(l,s){(s==null||s>l.length)&&(s=l.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=l[n];return i}var Om=ft,Nh=lt,Dh=Tn,Sa=wt(),Aa=new Om("sanityCheck"),Nm=[Fm],Dm=[Mm,xm,Pm,Lm],km=[Hm,qm],Fe,fn,kh,Um=function(l,s,n){Fe=l,fn=s,kh=n;var i=ul(Nm),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;if(e()===!1)return!1}}catch(y){i.e(y)}finally{i.f()}if(Fe instanceof Dh.IncomingRequest){var d=ul(Dm),_;try{for(d.s();!(_=d.n()).done;){var u=_.value;if(u()===!1)return!1}}catch(y){d.e(y)}finally{d.f()}}else if(Fe instanceof Dh.IncomingResponse){var g=ul(km),p;try{for(g.s();!(p=g.n()).done;){var T=p.value;if(T()===!1)return!1}}catch(y){g.e(y)}finally{g.f()}}return!0};function Mm(){if(Fe.s("to").uri.scheme!=="sip")return Sr(416),!1}function xm(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===fn.configuration.jssip_id)return Sr(482),!1}function Pm(){var l=Sa.str_utf8_length(Fe.body),s=Fe.getHeader("content-length");if(l<s)return Sr(400),!1}function Lm(){var l=Fe.from_tag,s=Fe.call_id,n=Fe.cseq,i;if(!Fe.to_tag)if(Fe.method===Nh.INVITE){if(fn._transactions.ist[Fe.via_branch])return!1;for(var a in fn._transactions.ist)if(Object.prototype.hasOwnProperty.call(fn._transactions.ist,a)&&(i=fn._transactions.ist[a],i.request.from_tag===l&&i.request.call_id===s&&i.request.cseq===n))return Sr(482),!1}else{if(fn._transactions.nist[Fe.via_branch])return!1;for(var e in fn._transactions.nist)if(Object.prototype.hasOwnProperty.call(fn._transactions.nist,e)&&(i=fn._transactions.nist[e],i.request.from_tag===l&&i.request.call_id===s&&i.request.cseq===n))return Sr(482),!1}}function Hm(){if(Fe.getHeaders("via").length>1)return Aa.debug("more than one Via header field present in the response, dropping the response"),!1}function qm(){var l=Sa.str_utf8_length(Fe.body),s=Fe.getHeader("content-length");if(l<s)return Aa.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function Fm(){for(var l=["from","to","call_id","cseq","via"],s=0,n=l;s<n.length;s++){var i=n[s];if(!Fe.hasHeader(i))return Aa.debug("missing mandatory header field : ".concat(i,", dropping the response")),!1}}function Sr(l){var s=Fe.getHeaders("via"),n,i="SIP/2.0 ".concat(l," ").concat(Nh.REASON_PHRASE[l],`\r
65
- `),a=ul(s),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i+="Via: ".concat(d,`\r
66
- `)}}catch(_){a.e(_)}finally{a.f()}n=Fe.getHeader("To"),Fe.to_tag||(n+=";tag=".concat(Sa.newTag())),i+="To: ".concat(n,`\r
67
- `),i+="From: ".concat(Fe.getHeader("From"),`\r
68
- `),i+="Call-ID: ".concat(Fe.call_id,`\r
69
- `),i+="CSeq: ".concat(Fe.cseq," ").concat(Fe.method,`\r
56
+ `.concat(n,`
57
+ `))}else kt.debug(`received text message:
58
+
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}}]),l}(),Th={};function vh(l,n){var s;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(s=vm(l))||n&&l&&typeof l.length=="number"){s&&(l=s);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){s=l[Symbol.iterator]()},n:function(){var u=s.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&s.return!=null&&s.return()}finally{if(d)throw _}}}}function vm(l,n){if(l){if(typeof l=="string")return yh(l,n);var s=Object.prototype.toString.call(l).slice(8,-1);if(s==="Object"&&l.constructor&&(s=l.constructor.name),s==="Map"||s==="Set")return Array.from(l);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return yh(l,n)}}function yh(l,n){(n==null||n>l.length)&&(n=l.length);for(var s=0,i=new Array(n);s<n;s++)i[s]=l[s];return i}var ym=ct,ha=ln(),da=_n,tl=new ym("Parser");Th.parseMessage=function(l,n){var s,i,a=l.indexOf(`\r
62
+ `);if(a===-1){tl.warn("parseMessage() | no CRLF found, not a SIP message");return}var e=l.substring(0,a),d=ha.parse(e,"Request_Response");if(d===-1){tl.warn('parseMessage() | error parsing first line of SIP message: "'.concat(e,'"'));return}else d.status_code?(s=new da.IncomingResponse,s.status_code=d.status_code,s.reason_phrase=d.reason_phrase):(s=new da.IncomingRequest(n),s.method=d.method,s.ruri=d.uri);s.data=l;for(var _=a+2;;){if(a=Em(l,_),a===-2){i=_+2;break}else if(a===-1){tl.warn("parseMessage() | malformed message");return}if(d=Sm(s,l,_,a),d!==!0){tl.warn("parseMessage() |",d.error);return}_=a+2}if(s.hasHeader("content-length")){var u=s.getHeader("content-length");s.body=l.substr(i,u)}else s.body=l.substring(i);return s};function Em(l,n){var s=n,i=0,a=0;if(l.substring(s,s+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
63
+ `,s),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?s=a+2:i=a}return i}function Sm(l,n,s,i){var a,e=n.indexOf(":",s),d=n.substring(s,e).trim(),_=n.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=ha.parse(_,"Record_Route"),a===-1)a=void 0;else{var u=vh(a),g;try{for(u.s();!(g=u.n()).done;){var f=g.value;l.addHeader("record-route",_.substring(f.possition,f.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=f.parsed}}catch(w){u.e(w)}finally{u.f()}}break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=ha.parse(_,"Contact"),a===-1)a=void 0;else{var T=vh(a),y;try{for(T.s();!(y=T.n()).done;){var A=y.value;l.addHeader("contact",_.substring(A.possition,A.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=A.parsed}}catch(w){T.e(w)}finally{T.f()}}break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof da.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:'error parsing header "'.concat(d,'"')}:!0}function nl(l,n){var s;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(s=Am(l))||n&&l&&typeof l.length=="number"){s&&(l=s);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){s=l[Symbol.iterator]()},n:function(){var u=s.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&s.return!=null&&s.return()}finally{if(d)throw _}}}}function Am(l,n){if(l){if(typeof l=="string")return Eh(l,n);var s=Object.prototype.toString.call(l).slice(8,-1);if(s==="Object"&&l.constructor&&(s=l.constructor.name),s==="Map"||s==="Set")return Array.from(l);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return Eh(l,n)}}function Eh(l,n){(n==null||n>l.length)&&(n=l.length);for(var s=0,i=new Array(n);s<n;s++)i[s]=l[s];return i}var Cm=ct,Sh=nt,Ah=_n,_a=At(),pa=new Cm("sanityCheck"),bm=[Pm],Rm=[Om,Nm,Dm,km],Im=[Um,Mm],He,un,Ch,wm=function(l,n,s){He=l,un=n,Ch=s;var i=nl(bm),a;try{for(i.s();!(a=i.n()).done;){var e=a.value;if(e()===!1)return!1}}catch(y){i.e(y)}finally{i.f()}if(He instanceof Ah.IncomingRequest){var d=nl(Rm),_;try{for(d.s();!(_=d.n()).done;){var u=_.value;if(u()===!1)return!1}}catch(y){d.e(y)}finally{d.f()}}else if(He instanceof Ah.IncomingResponse){var g=nl(Im),f;try{for(g.s();!(f=g.n()).done;){var T=f.value;if(T()===!1)return!1}}catch(y){g.e(y)}finally{g.f()}}return!0};function Om(){if(He.s("to").uri.scheme!=="sip")return fr(416),!1}function Nm(){if(!He.to_tag&&He.call_id.substr(0,5)===un.configuration.jssip_id)return fr(482),!1}function Dm(){var l=_a.str_utf8_length(He.body),n=He.getHeader("content-length");if(l<n)return fr(400),!1}function km(){var l=He.from_tag,n=He.call_id,s=He.cseq,i;if(!He.to_tag)if(He.method===Sh.INVITE){if(un._transactions.ist[He.via_branch])return!1;for(var a in un._transactions.ist)if(Object.prototype.hasOwnProperty.call(un._transactions.ist,a)&&(i=un._transactions.ist[a],i.request.from_tag===l&&i.request.call_id===n&&i.request.cseq===s))return fr(482),!1}else{if(un._transactions.nist[He.via_branch])return!1;for(var e in un._transactions.nist)if(Object.prototype.hasOwnProperty.call(un._transactions.nist,e)&&(i=un._transactions.nist[e],i.request.from_tag===l&&i.request.call_id===n&&i.request.cseq===s))return fr(482),!1}}function Um(){if(He.getHeaders("via").length>1)return pa.debug("more than one Via header field present in the response, dropping the response"),!1}function Mm(){var l=_a.str_utf8_length(He.body),n=He.getHeader("content-length");if(l<n)return pa.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function Pm(){for(var l=["from","to","call_id","cseq","via"],n=0,s=l;n<s.length;n++){var i=s[n];if(!He.hasHeader(i))return pa.debug("missing mandatory header field : ".concat(i,", dropping the response")),!1}}function fr(l){var n=He.getHeaders("via"),s,i="SIP/2.0 ".concat(l," ").concat(Sh.REASON_PHRASE[l],`\r
65
+ `),a=nl(n),e;try{for(a.s();!(e=a.n()).done;){var d=e.value;i+="Via: ".concat(d,`\r
66
+ `)}}catch(_){a.e(_)}finally{a.f()}s=He.getHeader("To"),He.to_tag||(s+=";tag=".concat(_a.newTag())),i+="To: ".concat(s,`\r
67
+ `),i+="From: ".concat(He.getHeader("From"),`\r
68
+ `),i+="Call-ID: ".concat(He.call_id,`\r
69
+ `),i+="CSeq: ".concat(He.cseq," ").concat(He.method,`\r
70
70
  `),i+=`\r
71
- `,kh.send(i)}var Ca={};function Uh(l,s){var n;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(n=jm(l))||s&&l&&typeof l.length=="number"){n&&(l=n);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){n=l[Symbol.iterator]()},n:function(){var u=n.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&n.return!=null&&n.return()}finally{if(d)throw _}}}}function jm(l,s){if(l){if(typeof l=="string")return Mh(l,s);var n=Object.prototype.toString.call(l).slice(8,-1);if(n==="Object"&&l.constructor&&(n=l.constructor.name),n==="Map"||n==="Set")return Array.from(l);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Mh(l,s)}}function Mh(l,s){(s==null||s>l.length)&&(s=l.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=l[n];return i}var Bs=wt(),ls=lt,ba=dn(),xh=Gn(),Ra=Ta,Ia=Kn;Ca.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:ls.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:ls.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:ls.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(Bs.createRandomToken(12),".invalid")};var cl={mandatory:{sockets:function(l){var s=[];if(Ra.isSocket(l))s.push({socket:l});else if(Array.isArray(l)&&l.length){var n=Uh(l),i;try{for(n.s();!(i=n.n()).done;){var a=i.value;Object.prototype.hasOwnProperty.call(a,"socket")&&Ra.isSocket(a.socket)?s.push(a):Ra.isSocket(a)&&s.push({socket:a})}}catch(e){n.e(e)}finally{n.f()}}else return;return s},uri:function(l){/^sip:/i.test(l)||(l="".concat(ls.SIP,":").concat(l));var s=xh.parse(l);if(s)return s.user?s:void 0}},optional:{authorization_user:function(l){if(ba.parse('"'.concat(l,'"'),"quoted_string")!==-1)return l},authorization_jwt:function(l){if(typeof l=="string")return l},user_agent:function(l){if(typeof l=="string")return l},connection_recovery_max_interval:function(l){if(Bs.isDecimal(l)){var s=Number(l);if(s>0)return s}},connection_recovery_min_interval:function(l){if(Bs.isDecimal(l)){var s=Number(l);if(s>0)return s}},contact_uri:function(l){if(typeof l=="string"){var s=ba.parse(l,"SIP_URI");if(s!==-1)return s}},display_name:function(l){return l},instance_id:function(l){if(/^uuid:/i.test(l)&&(l=l.substr(5)),ba.parse(l,"uuid")!==-1)return l},no_answer_timeout:function(l){if(Bs.isDecimal(l)){var s=Number(l);if(s>0)return s}},session_timers:function(l){if(typeof l=="boolean")return l},session_timers_refresh_method:function(l){if(typeof l=="string"&&(l=l.toUpperCase(),l===ls.INVITE||l===ls.UPDATE))return l},session_timers_force_refresher:function(l){if(typeof l=="boolean")return l},password:function(l){return String(l)},realm:function(l){return String(l)},ha1:function(l){return String(l)},register:function(l){if(typeof l=="boolean")return l},register_expires:function(l){if(Bs.isDecimal(l)){var s=Number(l);if(s>0)return s}},registrar_server:function(l){/^sip:/i.test(l)||(l="".concat(ls.SIP,":").concat(l));var s=xh.parse(l);if(s)return s.user?void 0:s},use_preloaded_route:function(l){if(typeof l=="boolean")return l},extra_headers:function(l){var s=[];if(Array.isArray(l)&&l.length){var n=Uh(l),i;try{for(n.s();!(i=n.n()).done;){var a=i.value;typeof a=="string"&&s.push(a)}}catch(e){n.e(e)}finally{n.f()}}else return;return s}}};Ca.load=function(l,s){for(var n in cl.mandatory)if(s.hasOwnProperty(n)){var i=s[n],a=cl.mandatory[n](i);if(a!==void 0)l[n]=a;else throw new Ia.ConfigurationError(n,i)}else throw new Ia.ConfigurationError(n);for(var e in cl.optional)if(s.hasOwnProperty(e)){var d=s[e];if(Bs.isEmpty(d))continue;var _=cl.optional[e](d);if(_!==void 0)l[e]=_;else throw new Ia.ConfigurationError(e,d)}};function hl(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?hl=function(s){return typeof s}:hl=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},hl(l)}function $m(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function Ph(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Lh(l,s,n){return s&&Ph(l.prototype,s),n&&Ph(l,n),l}function Vm(l,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(s&&s.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),s&&wa(l,s)}function wa(l,s){return wa=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},wa(l,s)}function Bm(l){var s=Gm();return function(){var n=dl(l),i;if(s){var a=dl(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Km(this,i)}}function Km(l,s){return s&&(hl(s)==="object"||typeof s=="function")?s:Hh(l)}function Hh(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function Gm(){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(l){return!1}}function dl(l){return dl=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},dl(l)}var Wm=_t.EventEmitter,Ym=ft,Tt=lt,zm=Pf,qh=Kp,Fh=rm,jh=mm,Oa=_r,Xm=Am,_l=wt(),Qm=Kn,Jm=Gn(),Zm=Rh,Na=Tn,eg=Um,Da=Ca,Ve=new Ym("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},tg=function(l){Vm(n,l);var s=Bm(n);Lh(n,null,[{key:"C",get:function(){return vt}}]);function n(i){var a;if($m(this,n),Ve.debug("new() [configuration:%o]",i),a=s.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},Da.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=vt.STATUS_INIT,a._error=null,a._transactions={nist:{},nict:{},ist:{},ict:{}},a._data={},a._closeTimer=null,i===void 0)throw new TypeError("Not enough arguments");try{a._loadConfig(i)}catch(e){throw a._status=vt.STATUS_NOT_READY,a._error=vt.CONFIGURATION_ERROR,e}return a._registrator=new zm(Hh(a)),a}return Lh(n,[{key:"start",value:function(){Ve.debug("start()"),this._status===vt.STATUS_INIT?this._transport.connect():this._status===vt.STATUS_USER_CLOSED?(Ve.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?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(i){Ve.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(i)}},{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(i,a){Ve.debug("call()");var e=new qh(this);return e.connect(i,a),e}},{key:"sendMessage",value:function(i,a,e){Ve.debug("sendMessage()");var d=new Fh(this);return d.send(i,a,e),d}},{key:"sendOptions",value:function(i,a,e){Ve.debug("sendOptions()");var d=new jh(this);return d.send(i,a,e),d}},{key:"terminateSessions",value:function(i){Ve.debug("terminateSessions()");for(var a in this._sessions)this._sessions[a].isEnded()||this._sessions[a].terminate(i)}},{key:"stop",value:function(){var i=this;if(Ve.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){Ve.debug("UA already closed");return}this._registrator.close();var a=Object.keys(this._sessions).length;for(var e in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,e)){Ve.debug("closing session ".concat(e));try{this._sessions[e].terminate()}catch(u){}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch(u){}this._status=vt.STATUS_USER_CLOSED;var _=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;_===0&&a===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){i._closeTimer=null,i._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(i){return _l.normalizeTarget(i,this._configuration.hostport_params)}},{key:"get",value:function(i){switch(i){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',i);return}}},{key:"set",value:function(i,a){switch(i){case"authorization_user":{this._configuration.authorization_user=String(a);break}case"password":{this._configuration.password=String(a);break}case"realm":{this._configuration.realm=String(a);break}case"ha1":{this._configuration.ha1=String(a),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(a);break}case"display_name":{this._configuration.display_name=a;break}default:return Ve.warn('set() | cannot set "%s" parameter in runtime',i),!1}return!0}},{key:"newTransaction",value:function(i){this._transactions[i.type][i.id]=i,this.emit("newTransaction",{transaction:i})}},{key:"destroyTransaction",value:function(i){delete this._transactions[i.type][i.id],this.emit("transactionDestroyed",{transaction:i})}},{key:"newDialog",value:function(i){this._dialogs[i.id]=i}},{key:"destroyDialog",value:function(i){delete this._dialogs[i.id]}},{key:"newMessage",value:function(i,a){this._applicants[i]=i,this.emit("newMessage",a)}},{key:"newOptions",value:function(i,a){this._applicants[i]=i,this.emit("newOptions",a)}},{key:"destroyMessage",value:function(i){delete this._applicants[i]}},{key:"newRTCSession",value:function(i,a){this._sessions[i.id]=i,this.emit("newRTCSession",a)}},{key:"destroyRTCSession",value:function(i){delete this._sessions[i.id]}},{key:"registered",value:function(i){this.emit("registered",i)}},{key:"unregistered",value:function(i){this.emit("unregistered",i)}},{key:"registrationFailed",value:function(i){this.emit("registrationFailed",i)}},{key:"receiveRequest",value:function(i){var a=i.method;if(i.ruri.user!==this._configuration.uri.user&&i.ruri.user!==this._contact.uri.user){Ve.debug("Request-URI does not point to us"),i.method!==Tt.ACK&&i.reply_sl(404);return}if(i.ruri.scheme===Tt.SIPS){i.reply_sl(416);return}if(!Oa.checkTransaction(this,i)){if(a===Tt.INVITE?new Oa.InviteServerTransaction(this,this._transport,i):a!==Tt.ACK&&a!==Tt.CANCEL&&new Oa.NonInviteServerTransaction(this,this._transport,i),a===Tt.OPTIONS){if(this.listeners("newOptions").length===0){i.reply(200);return}var e=new jh(this);e.init_incoming(i)}else if(a===Tt.MESSAGE){if(this.listeners("newMessage").length===0){i.reply(405);return}var d=new Fh(this);d.init_incoming(i)}else if(a===Tt.INVITE&&!i.to_tag&&this.listeners("newRTCSession").length===0){i.reply(405);return}var _,u;if(i.to_tag)_=this._findDialog(i.call_id,i.from_tag,i.to_tag),_?_.receiveRequest(i):a===Tt.NOTIFY?(u=this._findSession(i),u?u.receiveRequest(i):(Ve.debug("received NOTIFY request for a non existent subscription"),i.reply(481,"Subscription does not exist"))):a!==Tt.ACK&&i.reply(481);else switch(a){case Tt.INVITE:if(window.RTCPeerConnection)if(i.hasHeader("replaces")){var g=i.replaces;_=this._findDialog(g.call_id,g.from_tag,g.to_tag),_?(u=_.owner,u.isEnded()?i.reply(603):u.receiveRequest(i)):i.reply(481)}else u=new qh(this),u.init_incoming(i);else Ve.warn("INVITE received but WebRTC is not supported"),i.reply(488);break;case Tt.BYE:i.reply(481);break;case Tt.CANCEL:u=this._findSession(i),u?u.receiveRequest(i):Ve.debug("received CANCEL request for a non existent session");break;case Tt.ACK:break;case Tt.NOTIFY:this.emit("sipEvent",{event:i.event,request:i}),i.reply(200);break;default:i.reply(405);break}}}},{key:"_findSession",value:function(i){var a=i.call_id,e=i.from_tag,d=i.to_tag,_=a+e,u=this._sessions[_],g=a+d,p=this._sessions[g];return u||p||null}},{key:"_findDialog",value:function(i,a,e){var d=i+a+e,_=this._dialogs[d];return _||(d=i+e+a,_=this._dialogs[d],_||null)}},{key:"_loadConfig",value:function(i){try{Da.load(this._configuration,i)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=_l.newUUID()),this._configuration.jssip_id=_l.createRandomToken(5);var a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Xm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=ng.bind(this),this._transport.onconnect=sg.bind(this),this._transport.ondisconnect=rg.bind(this),this._transport.ondata=ig.bind(this)}catch(g){throw Ve.warn(g),new Qm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Jm("sip",_l.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 g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},p=g.anonymous||null,T=g.outbound||null,y="<";return p?y+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":y+=this.pub_gruu||this.uri.toString(),T&&(p?!this.temp_gruu:!this.pub_gruu)&&(y+=";ob"),y+=">",y}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var _ in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,_)&&(d.indexOf(_)!==-1?Object.defineProperty(this._configuration,_,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,_,{writable:!1,configurable:!1}));Ve.debug("configuration parameters after validation:");for(var u in this._configuration)if(Object.prototype.hasOwnProperty.call(Da.settings,u))switch(u){case"uri":case"registrar_server":Ve.debug("- ".concat(u,": ").concat(this._configuration[u]));break;case"password":case"ha1":case"authorization_jwt":Ve.debug("- ".concat(u,": NOT SHOWN"));break;default:Ve.debug("- ".concat(u,": ").concat(JSON.stringify(this._configuration[u])))}}},{key:"C",get:function(){return vt}},{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}(Wm);function ng(l){this.emit("connecting",l)}function sg(l){this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function rg(l){for(var s=["nict","ict","nist","ist"],n=0,i=s;n<i.length;n++){var a=i[n];for(var e in this._transactions[a])Object.prototype.hasOwnProperty.call(this._transactions[a],e)&&this._transactions[a][e].onTransportError()}this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function ig(l){var s=l.transport,n=l.message;if(n=Zm.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof Na.IncomingRequest)&&eg(n,this,s)){if(n instanceof Na.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof Na.IncomingResponse){var i;switch(n.method){case Tt.INVITE:i=this._transactions.ict[n.via_branch],i&&i.receiveResponse(n);break;case Tt.ACK:break;default:i=this._transactions.nict[n.via_branch],i&&i.receiveResponse(n);break}}}}function og(l,s){if(!(l instanceof s))throw new TypeError("Cannot call a class as a function")}function $h(l,s){for(var n=0;n<s.length;n++){var i=s[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function lg(l,s,n){return s&&$h(l.prototype,s),n&&$h(l,n),l}var ag=ft,ug=dn(),Dt=new ag("WebSocketInterface"),cg=function(){function l(s){og(this,l),Dt.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=ug.parse(s,"absoluteURI");if(n===-1)throw Dt.warn("invalid WebSocket URI: ".concat(s)),new TypeError("Invalid argument: ".concat(s));if(n.scheme!=="wss"&&n.scheme!=="ws")throw Dt.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(s));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return lg(l,[{key:"connect",value:function(){if(Dt.debug("connect()"),this.isConnected()){Dt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Dt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Dt.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(s){this._onError(s)}}},{key:"disconnect",value:function(){Dt.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(s){return Dt.debug("send()"),this.isConnected()?(this._ws.send(s),!0):(Dt.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(){Dt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(s){var n=s.wasClean,i=s.code,a=s.reason;Dt.debug("WebSocket ".concat(this._url," closed")),n===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!n,i,a)}},{key:"_onMessage",value:function(s){var n=s.data;Dt.debug("received WebSocket message"),this.ondata(n)}},{key:"_onError",value:function(s){Dt.warn("WebSocket ".concat(this._url," error: "),s)}},{key:"via_transport",get:function(){return this._via_transport},set:function(s){this._via_transport=s.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),l}(),ka=Oo,hg=lt,dg=Kn,_g=wt(),fg=tg,pg=Gn(),mg=Bl(),gg=dn(),Tg=cg,vg=js("JsSIP");vg("version %s",ka.version);var Vh={C:hg,Exceptions:dg,Utils:_g,UA:fg,URI:pg,NameAddrHeader:mg,WebSocketInterface:Tg,Grammar:gg,debug:js,get name(){return ka.title},get version(){return ka.version}};const Ks=js,Gs="JsSIP";var ht=class{constructor(l){l?(this._debug=Ks.default(`${Gs}:${l}`),this._warn=Ks.default(`${Gs}:WARN:${l}`),this._error=Ks.default(`${Gs}:ERROR:${l}`)):(this._debug=Ks.default(Gs),this._warn=Ks.default(`${Gs}:WARN`),this._error=Ks.default(`${Gs}: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 fl=$e(ht),Bh=Oo;var Ne={USER_AGENT:`${Bh.title} ${Bh.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 U=$e(Ne);var nt={},Ua,Kh;function Ma(){if(Kh)return Ua;Kh=1;const l=Sn(),s=Xt();return Ua=class y_{static parse(i){if(i=s.parse(i,"Name_Addr_Header"),i!==-1)return i}constructor(i,a,e){if(!i||!(i instanceof l))throw new TypeError('missing or invalid "uri" parameter');this._uri=i,this._parameters={},this.display_name=a;for(const d in e)Object.prototype.hasOwnProperty.call(e,d)&&this.setParam(d,e[d])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(i){this._display_name=i===0?"0":i}setParam(i,a){i&&(this._parameters[i.toLowerCase()]=typeof a>"u"||a===null?null:a.toString())}getParam(i){if(i)return this._parameters[i.toLowerCase()]}hasParam(i){if(i)return this._parameters.hasOwnProperty(i.toLowerCase())&&!0||!1}deleteParam(i){if(i=i.toLowerCase(),this._parameters.hasOwnProperty(i)){const a=this._parameters[i];return delete this._parameters[i],a}}clearParams(){this._parameters={}}clone(){return new y_(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let i=this._display_name?`"${this._quote(this._display_name)}" `:"";i+=`<${this._uri.toString()}>`;for(const a in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,a)&&(i+=`;${a}`,this._parameters[a]!==null&&(i+=`=${this._parameters[a]}`));return i}},Ua}var Gh,Wh;function Xt(){return Wh||(Wh=1,Gh=function(){function l(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 s={parse:function(n,i){var a={CRLF:g,DIGIT:p,ALPHA:T,HEXDIG:y,WSP:A,OCTET:w,DQUOTE:R,SP:b,HTAB:G,alphanum:P,reserved:ye,unreserved:O,mark:j,escaped:pe,LWS:Te,SWS:N,HCOLON:H,TEXT_UTF8_TRIM:$,TEXT_UTF8char:q,UTF8_NONASCII:M,UTF8_CONT:W,LHEX:te,token:I,token_nodot:J,separators:ne,word:Ye,STAR:ee,SLASH:V,EQUAL:k,LPAREN:Ae,RPAREN:me,RAQUOT:Ie,LAQUOT:xe,COMMA:_e,SEMI:le,COLON:ze,LDQUOT:rt,RDQUOT:Ee,comment:ge,ctext:Re,quoted_string:we,quoted_string_clean:Ue,qdtext:fe,quoted_pair:ae,SIP_URI_noparams:Se,SIP_URI:De,uri_scheme:Ke,uri_scheme_sips:ct,uri_scheme_sip:He,userinfo:Ft,user:Ut,user_unreserved:ps,password:Vr,hostport:Nn,host:nn,hostname:ms,domainlabel:gs,toplabel:Br,IPv6reference:Ts,IPv6address:vs,h16:x,ls32:qe,IPv4address:sn,dec_octet:rn,port:Kr,uri_parameters:Gr,uri_parameter:ys,transport_param:Wr,user_param:Yr,method_param:zr,ttl_param:Xr,maddr_param:Qr,lr_param:Jr,other_param:Zr,pname:ei,pvalue:ti,paramchar:on,param_unreserved:ni,headers:si,header:Dn,hname:ri,hvalue:ii,hnv_unreserved:ln,Request_Response:Ou,Request_Line:oi,Request_URI:li,absoluteURI:Es,hier_part:ai,net_path:ui,abs_path:kn,opaque_part:ci,uric:an,uric_no_slash:hi,path_segments:di,segment:Un,param:Ss,pchar:un,scheme:_i,authority:fi,srvr:pi,reg_name:mi,query:gi,SIP_Version:As,INVITEm:Ti,ACKm:vi,OPTIONSm:yi,BYEm:Ei,CANCELm:Si,REGISTERm:Ai,SUBSCRIBEm:Ci,NOTIFYm:bi,REFERm:Ri,Method:Mn,Status_Line:Ii,Status_Code:wi,extension_code:Oi,Reason_Phrase:Ni,Allow_Events:Nu,Call_ID:Du,Contact:ku,contact_param:xn,name_addr:Mt,display_name:Pn,contact_params:Cs,c_p_q:Di,c_p_expires:ki,delta_seconds:xt,qvalue:Ui,generic_param:Oe,gen_value:Mi,Content_Disposition:Uu,disp_type:xi,disp_param:bs,handling_param:Pi,Content_Encoding:Mu,Content_Length:xu,Content_Type:Pu,media_type:Li,m_type:Hi,discrete_type:qi,composite_type:Fi,extension_token:Ln,x_token:ji,m_subtype:$i,m_parameter:Rs,m_value:Vi,CSeq:Lu,CSeq_value:Bi,Expires:Hu,Event:qu,event_type:cn,From:Fu,from_param:Is,tag_param:ws,Max_Forwards:ju,Min_Expires:$u,Name_Addr_Header:Vu,Proxy_Authenticate:Bu,challenge:Os,other_challenge:Ki,auth_param:hn,digest_cln:Hn,realm:Gi,realm_value:Wi,domain:Yi,URI:qn,nonce:zi,nonce_value:Xi,opaque:Qi,stale:Ji,algorithm:Zi,qop_options:eo,qop_value:Fn,Proxy_Require:Ku,Record_Route:Gu,rec_route:jn,Reason:Wu,reason_param:Ns,reason_cause:to,Require:Yu,Route:zu,route_param:$n,Subscription_State:Xu,substate_value:no,subexp_params:Ds,event_reason_value:so,Subject:Qu,Supported:Ju,To:Zu,to_param:ks,Via:ec,via_param:Vn,via_params:Us,via_ttl:ro,via_maddr:io,via_received:oo,via_branch:lo,response_port:ao,rport:uo,sent_protocol:co,protocol_name:ho,transport:_o,sent_by:fo,via_host:po,via_port:mo,ttl:Ms,WWW_Authenticate:tc,Session_Expires:nc,s_e_expires:go,s_e_params:xs,s_e_refresher:To,extension_header:sc,header_value:vo,message_body:rc,uuid_URI:ic,uuid:yo,hex4:dt,hex8:Eo,hex12:So,Refer_To:oc,Replaces:lc,call_id:Ao,replaces_param:Ps,to_tag:Co,from_tag:bo,early_flag:Ro};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+l(i)+".")}else i="CRLF";var e=0,d=0,_=[];function u(t){e<d||(e>d&&(d=e,_=[]),_.push(t))}function g(){var t;return n.substr(e,2)===`\r
71
+ `,Ch.send(i)}var fa={};function bh(l,n){var s;if(typeof Symbol>"u"||l[Symbol.iterator]==null){if(Array.isArray(l)||(s=xm(l))||n&&l&&typeof l.length=="number"){s&&(l=s);var i=0,a=function(){};return{s:a,n:function(){return i>=l.length?{done:!0}:{done:!1,value:l[i++]}},e:function(u){throw u},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 e=!0,d=!1,_;return{s:function(){s=l[Symbol.iterator]()},n:function(){var u=s.next();return e=u.done,u},e:function(u){d=!0,_=u},f:function(){try{!e&&s.return!=null&&s.return()}finally{if(d)throw _}}}}function xm(l,n){if(l){if(typeof l=="string")return Rh(l,n);var s=Object.prototype.toString.call(l).slice(8,-1);if(s==="Object"&&l.constructor&&(s=l.constructor.name),s==="Map"||s==="Set")return Array.from(l);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return Rh(l,n)}}function Rh(l,n){(n==null||n>l.length)&&(n=l.length);for(var s=0,i=new Array(n);s<n;s++)i[s]=l[s];return i}var qs=At(),ns=nt,ma=ln(),Ih=jn(),ga=ua,Ta=Fn;fa.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:ns.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:ns.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:ns.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(qs.createRandomToken(12),".invalid")};var sl={mandatory:{sockets:function(l){var n=[];if(ga.isSocket(l))n.push({socket:l});else if(Array.isArray(l)&&l.length){var s=bh(l),i;try{for(s.s();!(i=s.n()).done;){var a=i.value;Object.prototype.hasOwnProperty.call(a,"socket")&&ga.isSocket(a.socket)?n.push(a):ga.isSocket(a)&&n.push({socket:a})}}catch(e){s.e(e)}finally{s.f()}}else return;return n},uri:function(l){/^sip:/i.test(l)||(l="".concat(ns.SIP,":").concat(l));var n=Ih.parse(l);if(n)return n.user?n:void 0}},optional:{authorization_user:function(l){if(ma.parse('"'.concat(l,'"'),"quoted_string")!==-1)return l},authorization_jwt:function(l){if(typeof l=="string")return l},user_agent:function(l){if(typeof l=="string")return l},connection_recovery_max_interval:function(l){if(qs.isDecimal(l)){var n=Number(l);if(n>0)return n}},connection_recovery_min_interval:function(l){if(qs.isDecimal(l)){var n=Number(l);if(n>0)return n}},contact_uri:function(l){if(typeof l=="string"){var n=ma.parse(l,"SIP_URI");if(n!==-1)return n}},display_name:function(l){return l},instance_id:function(l){if(/^uuid:/i.test(l)&&(l=l.substr(5)),ma.parse(l,"uuid")!==-1)return l},no_answer_timeout:function(l){if(qs.isDecimal(l)){var n=Number(l);if(n>0)return n}},session_timers:function(l){if(typeof l=="boolean")return l},session_timers_refresh_method:function(l){if(typeof l=="string"&&(l=l.toUpperCase(),l===ns.INVITE||l===ns.UPDATE))return l},session_timers_force_refresher:function(l){if(typeof l=="boolean")return l},password:function(l){return String(l)},realm:function(l){return String(l)},ha1:function(l){return String(l)},register:function(l){if(typeof l=="boolean")return l},register_expires:function(l){if(qs.isDecimal(l)){var n=Number(l);if(n>0)return n}},registrar_server:function(l){/^sip:/i.test(l)||(l="".concat(ns.SIP,":").concat(l));var n=Ih.parse(l);if(n)return n.user?void 0:n},use_preloaded_route:function(l){if(typeof l=="boolean")return l},extra_headers:function(l){var n=[];if(Array.isArray(l)&&l.length){var s=bh(l),i;try{for(s.s();!(i=s.n()).done;){var a=i.value;typeof a=="string"&&n.push(a)}}catch(e){s.e(e)}finally{s.f()}}else return;return n}}};fa.load=function(l,n){for(var s in sl.mandatory)if(n.hasOwnProperty(s)){var i=n[s],a=sl.mandatory[s](i);if(a!==void 0)l[s]=a;else throw new Ta.ConfigurationError(s,i)}else throw new Ta.ConfigurationError(s);for(var e in sl.optional)if(n.hasOwnProperty(e)){var d=n[e];if(qs.isEmpty(d))continue;var _=sl.optional[e](d);if(_!==void 0)l[e]=_;else throw new Ta.ConfigurationError(e,d)}};function rl(l){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?rl=function(n){return typeof n}:rl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},rl(l)}function Lm(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function wh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function Oh(l,n,s){return n&&wh(l.prototype,n),s&&wh(l,s),l}function Hm(l,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");l.prototype=Object.create(n&&n.prototype,{constructor:{value:l,writable:!0,configurable:!0}}),n&&va(l,n)}function va(l,n){return va=Object.setPrototypeOf||function(s,i){return s.__proto__=i,s},va(l,n)}function qm(l){var n=jm();return function(){var s=il(l),i;if(n){var a=il(this).constructor;i=Reflect.construct(s,arguments,a)}else i=s.apply(this,arguments);return Fm(this,i)}}function Fm(l,n){return n&&(rl(n)==="object"||typeof n=="function")?n:Nh(l)}function Nh(l){if(l===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return l}function jm(){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 il(l){return il=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},il(l)}var $m=ut.EventEmitter,Vm=ct,_t=nt,Bm=Np,Dh=Ff,kh=Zf,Uh=hm,ya=or,Km=Tm,ol=At(),Gm=Fn,Wm=jn(),Ym=Th,Ea=_n,zm=wm,Sa=fa,Fe=new Vm("UA"),pt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Jm=function(l){Hm(s,l);var n=qm(s);Oh(s,null,[{key:"C",get:function(){return pt}}]);function s(i){var a;if(Lm(this,s),Fe.debug("new() [configuration:%o]",i),a=n.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},Sa.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=pt.STATUS_INIT,a._error=null,a._transactions={nist:{},nict:{},ist:{},ict:{}},a._data={},a._closeTimer=null,i===void 0)throw new TypeError("Not enough arguments");try{a._loadConfig(i)}catch(e){throw a._status=pt.STATUS_NOT_READY,a._error=pt.CONFIGURATION_ERROR,e}return a._registrator=new Bm(Nh(a)),a}return Oh(s,[{key:"start",value:function(){Fe.debug("start()"),this._status===pt.STATUS_INIT?this._transport.connect():this._status===pt.STATUS_USER_CLOSED?(Fe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=pt.STATUS_INIT,this._transport.connect()):this._status===pt.STATUS_READY?Fe.debug("UA is in READY status, not restarted"):Fe.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){Fe.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(i){Fe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(i)}},{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(i,a){Fe.debug("call()");var e=new Dh(this);return e.connect(i,a),e}},{key:"sendMessage",value:function(i,a,e){Fe.debug("sendMessage()");var d=new kh(this);return d.send(i,a,e),d}},{key:"sendOptions",value:function(i,a,e){Fe.debug("sendOptions()");var d=new Uh(this);return d.send(i,a,e),d}},{key:"terminateSessions",value:function(i){Fe.debug("terminateSessions()");for(var a in this._sessions)this._sessions[a].isEnded()||this._sessions[a].terminate(i)}},{key:"stop",value:function(){var i=this;if(Fe.debug("stop()"),this._dynConfiguration={},this._status===pt.STATUS_USER_CLOSED){Fe.debug("UA already closed");return}this._registrator.close();var a=Object.keys(this._sessions).length;for(var e in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,e)){Fe.debug("closing session ".concat(e));try{this._sessions[e].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=pt.STATUS_USER_CLOSED;var _=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&&a===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){i._closeTimer=null,i._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(i){return ol.normalizeTarget(i,this._configuration.hostport_params)}},{key:"get",value:function(i){switch(i){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:Fe.warn('get() | cannot get "%s" parameter in runtime',i);return}}},{key:"set",value:function(i,a){switch(i){case"authorization_user":{this._configuration.authorization_user=String(a);break}case"password":{this._configuration.password=String(a);break}case"realm":{this._configuration.realm=String(a);break}case"ha1":{this._configuration.ha1=String(a),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(a);break}case"display_name":{this._configuration.display_name=a;break}default:return Fe.warn('set() | cannot set "%s" parameter in runtime',i),!1}return!0}},{key:"newTransaction",value:function(i){this._transactions[i.type][i.id]=i,this.emit("newTransaction",{transaction:i})}},{key:"destroyTransaction",value:function(i){delete this._transactions[i.type][i.id],this.emit("transactionDestroyed",{transaction:i})}},{key:"newDialog",value:function(i){this._dialogs[i.id]=i}},{key:"destroyDialog",value:function(i){delete this._dialogs[i.id]}},{key:"newMessage",value:function(i,a){this._applicants[i]=i,this.emit("newMessage",a)}},{key:"newOptions",value:function(i,a){this._applicants[i]=i,this.emit("newOptions",a)}},{key:"destroyMessage",value:function(i){delete this._applicants[i]}},{key:"newRTCSession",value:function(i,a){this._sessions[i.id]=i,this.emit("newRTCSession",a)}},{key:"destroyRTCSession",value:function(i){delete this._sessions[i.id]}},{key:"registered",value:function(i){this.emit("registered",i)}},{key:"unregistered",value:function(i){this.emit("unregistered",i)}},{key:"registrationFailed",value:function(i){this.emit("registrationFailed",i)}},{key:"receiveRequest",value:function(i){var a=i.method;if(i.ruri.user!==this._configuration.uri.user&&i.ruri.user!==this._contact.uri.user){Fe.debug("Request-URI does not point to us"),i.method!==_t.ACK&&i.reply_sl(404);return}if(i.ruri.scheme===_t.SIPS){i.reply_sl(416);return}if(!ya.checkTransaction(this,i)){if(a===_t.INVITE?new ya.InviteServerTransaction(this,this._transport,i):a!==_t.ACK&&a!==_t.CANCEL&&new ya.NonInviteServerTransaction(this,this._transport,i),a===_t.OPTIONS){if(this.listeners("newOptions").length===0){i.reply(200);return}var e=new Uh(this);e.init_incoming(i)}else if(a===_t.MESSAGE){if(this.listeners("newMessage").length===0){i.reply(405);return}var d=new kh(this);d.init_incoming(i)}else if(a===_t.INVITE&&!i.to_tag&&this.listeners("newRTCSession").length===0){i.reply(405);return}var _,u;if(i.to_tag)_=this._findDialog(i.call_id,i.from_tag,i.to_tag),_?_.receiveRequest(i):a===_t.NOTIFY?(u=this._findSession(i),u?u.receiveRequest(i):(Fe.debug("received NOTIFY request for a non existent subscription"),i.reply(481,"Subscription does not exist"))):a!==_t.ACK&&i.reply(481);else switch(a){case _t.INVITE:if(window.RTCPeerConnection)if(i.hasHeader("replaces")){var g=i.replaces;_=this._findDialog(g.call_id,g.from_tag,g.to_tag),_?(u=_.owner,u.isEnded()?i.reply(603):u.receiveRequest(i)):i.reply(481)}else u=new Dh(this),u.init_incoming(i);else Fe.warn("INVITE received but WebRTC is not supported"),i.reply(488);break;case _t.BYE:i.reply(481);break;case _t.CANCEL:u=this._findSession(i),u?u.receiveRequest(i):Fe.debug("received CANCEL request for a non existent session");break;case _t.ACK:break;case _t.NOTIFY:this.emit("sipEvent",{event:i.event,request:i}),i.reply(200);break;default:i.reply(405);break}}}},{key:"_findSession",value:function(i){var a=i.call_id,e=i.from_tag,d=i.to_tag,_=a+e,u=this._sessions[_],g=a+d,f=this._sessions[g];return u||f||null}},{key:"_findDialog",value:function(i,a,e){var d=i+a+e,_=this._dialogs[d];return _||(d=i+e+a,_=this._dialogs[d],_||null)}},{key:"_loadConfig",value:function(i){try{Sa.load(this._configuration,i)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ol.newUUID()),this._configuration.jssip_id=ol.createRandomToken(5);var a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Km(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Xm.bind(this),this._transport.onconnect=Qm.bind(this),this._transport.ondisconnect=Zm.bind(this),this._transport.ondata=eg.bind(this)}catch(g){throw Fe.warn(g),new Gm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Wm("sip",ol.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 g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},f=g.anonymous||null,T=g.outbound||null,y="<";return f?y+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":y+=this.pub_gruu||this.uri.toString(),T&&(f?!this.temp_gruu:!this.pub_gruu)&&(y+=";ob"),y+=">",y}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var _ in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,_)&&(d.indexOf(_)!==-1?Object.defineProperty(this._configuration,_,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,_,{writable:!1,configurable:!1}));Fe.debug("configuration parameters after validation:");for(var u in this._configuration)if(Object.prototype.hasOwnProperty.call(Sa.settings,u))switch(u){case"uri":case"registrar_server":Fe.debug("- ".concat(u,": ").concat(this._configuration[u]));break;case"password":case"ha1":case"authorization_jwt":Fe.debug("- ".concat(u,": NOT SHOWN"));break;default:Fe.debug("- ".concat(u,": ").concat(JSON.stringify(this._configuration[u])))}}},{key:"C",get:function(){return pt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),s}($m);function Xm(l){this.emit("connecting",l)}function Qm(l){this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function Zm(l){for(var n=["nict","ict","nist","ist"],s=0,i=n;s<i.length;s++){var a=i[s];for(var e in this._transactions[a])Object.prototype.hasOwnProperty.call(this._transactions[a],e)&&this._transactions[a][e].onTransportError()}this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_NOT_READY,this._error=pt.NETWORK_ERROR)}function eg(l){var n=l.transport,s=l.message;if(s=Ym.parseMessage(s,this),!!s&&!(this._status===pt.STATUS_USER_CLOSED&&s instanceof Ea.IncomingRequest)&&zm(s,this,n)){if(s instanceof Ea.IncomingRequest)s.transport=n,this.receiveRequest(s);else if(s instanceof Ea.IncomingResponse){var i;switch(s.method){case _t.INVITE:i=this._transactions.ict[s.via_branch],i&&i.receiveResponse(s);break;case _t.ACK:break;default:i=this._transactions.nict[s.via_branch],i&&i.receiveResponse(s);break}}}}function tg(l,n){if(!(l instanceof n))throw new TypeError("Cannot call a class as a function")}function Mh(l,n){for(var s=0;s<n.length;s++){var i=n[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(l,i.key,i)}}function ng(l,n,s){return n&&Mh(l.prototype,n),s&&Mh(l,s),l}var sg=ct,rg=ln(),Rt=new sg("WebSocketInterface"),ig=function(){function l(n){tg(this,l),Rt.debug('new() [url:"%s"]',n),this._url=n,this._sip_uri=null,this._via_transport=null,this._ws=null;var s=rg.parse(n,"absoluteURI");if(s===-1)throw Rt.warn("invalid WebSocket URI: ".concat(n)),new TypeError("Invalid argument: ".concat(n));if(s.scheme!=="wss"&&s.scheme!=="ws")throw Rt.warn("invalid WebSocket URI scheme: ".concat(s.scheme)),new TypeError("Invalid argument: ".concat(n));this._sip_uri="sip:".concat(s.host).concat(s.port?":".concat(s.port):"",";transport=ws"),this._via_transport=s.scheme.toUpperCase()}return ng(l,[{key:"connect",value:function(){if(Rt.debug("connect()"),this.isConnected()){Rt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Rt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Rt.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(){Rt.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 Rt.debug("send()"),this.isConnected()?(this._ws.send(n),!0):(Rt.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(){Rt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(n){var s=n.wasClean,i=n.code,a=n.reason;Rt.debug("WebSocket ".concat(this._url," closed")),s===!1&&Rt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!s,i,a)}},{key:"_onMessage",value:function(n){var s=n.data;Rt.debug("received WebSocket message"),this.ondata(s)}},{key:"_onError",value:function(n){Rt.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}}]),l}(),Aa=So,og=nt,lg=Fn,ag=At(),ug=Jm,cg=jn(),hg=Pl(),dg=ln(),_g=ig,pg=xs("JsSIP");pg("version %s",Aa.version);var Ph={C:og,Exceptions:lg,Utils:ag,UA:ug,URI:cg,NameAddrHeader:hg,WebSocketInterface:_g,Grammar:dg,debug:xs,get name(){return Aa.title},get version(){return Aa.version}};const Fs=xs,js="JsSIP";var ot=class{constructor(l){l?(this._debug=Fs.default(`${js}:${l}`),this._warn=Fs.default(`${js}:WARN:${l}`),this._error=Fs.default(`${js}:ERROR:${l}`)):(this._debug=Fs.default(js),this._warn=Fs.default(`${js}:WARN`),this._error=Fs.default(`${js}: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 ll=We(ot),xh=So;var Ie={USER_AGENT:`${xh.title} ${xh.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 U=We(Ie);var Ze={},Ca,Lh;function ba(){if(Lh)return Ca;Lh=1;const l=gn(),n=Bt();return Ca=class u_{static parse(i){if(i=n.parse(i,"Name_Addr_Header"),i!==-1)return i}constructor(i,a,e){if(!i||!(i instanceof l))throw new TypeError('missing or invalid "uri" parameter');this._uri=i,this._parameters={},this.display_name=a;for(const d in e)Object.prototype.hasOwnProperty.call(e,d)&&this.setParam(d,e[d])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(i){this._display_name=i===0?"0":i}setParam(i,a){i&&(this._parameters[i.toLowerCase()]=typeof a>"u"||a===null?null:a.toString())}getParam(i){if(i)return this._parameters[i.toLowerCase()]}hasParam(i){if(i)return this._parameters.hasOwnProperty(i.toLowerCase())&&!0||!1}deleteParam(i){if(i=i.toLowerCase(),this._parameters.hasOwnProperty(i)){const a=this._parameters[i];return delete this._parameters[i],a}}clearParams(){this._parameters={}}clone(){return new u_(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let i=this._display_name?`"${this._quote(this._display_name)}" `:"";i+=`<${this._uri.toString()}>`;for(const a in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,a)&&(i+=`;${a}`,this._parameters[a]!==null&&(i+=`=${this._parameters[a]}`));return i}},Ca}var Hh,qh;function Bt(){return qh||(qh=1,Hh=function(){function l(s){return'"'+s.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 n={parse:function(s,i){var a={CRLF:g,DIGIT:f,ALPHA:T,HEXDIG:y,WSP:A,OCTET:w,DQUOTE:b,SP:R,HTAB:G,alphanum:x,reserved:me,unreserved:O,mark:$,escaped:de,LWS:fe,SWS:N,HCOLON:H,TEXT_UTF8_TRIM:j,TEXT_UTF8char:F,UTF8_NONASCII:P,UTF8_CONT:W,LHEX:ee,token:I,token_nodot:X,separators:te,word:Ke,STAR:Q,SLASH:V,EQUAL:k,LPAREN:ve,RPAREN:_e,RAQUOT:Ae,LAQUOT:Ue,COMMA:ce,SEMI:re,COLON:Ge,LDQUOT:tt,RDQUOT:ge,comment:pe,ctext:Se,quoted_string:be,quoted_string_clean:De,qdtext:he,quoted_pair:ie,SIP_URI_noparams:Te,SIP_URI:we,uri_scheme:$e,uri_scheme_sips:it,uri_scheme_sip:xe,userinfo:Pt,user:wt,user_unreserved:cs,password:xr,hostport:bn,host:Jt,hostname:hs,domainlabel:ds,toplabel:Lr,IPv6reference:_s,IPv6address:ps,h16:M,ls32:Le,IPv4address:Xt,dec_octet:Qt,port:Hr,uri_parameters:qr,uri_parameter:fs,transport_param:Fr,user_param:jr,method_param:$r,ttl_param:Vr,maddr_param:Br,lr_param:Kr,other_param:Gr,pname:Wr,pvalue:Yr,paramchar:Zt,param_unreserved:zr,headers:Jr,header:Rn,hname:Xr,hvalue:Qr,hnv_unreserved:en,Request_Response:Eu,Request_Line:Zr,Request_URI:ei,absoluteURI:ms,hier_part:ti,net_path:ni,abs_path:In,opaque_part:si,uric:tn,uric_no_slash:ri,path_segments:ii,segment:wn,param:gs,pchar:nn,scheme:oi,authority:li,srvr:ai,reg_name:ui,query:ci,SIP_Version:Ts,INVITEm:hi,ACKm:di,OPTIONSm:_i,BYEm:pi,CANCELm:fi,REGISTERm:mi,SUBSCRIBEm:gi,NOTIFYm:Ti,REFERm:vi,Method:On,Status_Line:yi,Status_Code:Ei,extension_code:Si,Reason_Phrase:Ai,Allow_Events:Su,Call_ID:Au,Contact:Cu,contact_param:Nn,name_addr:Ot,display_name:Dn,contact_params:vs,c_p_q:Ci,c_p_expires:bi,delta_seconds:Nt,qvalue:Ri,generic_param:Re,gen_value:Ii,Content_Disposition:bu,disp_type:wi,disp_param:ys,handling_param:Oi,Content_Encoding:Ru,Content_Length:Iu,Content_Type:wu,media_type:Ni,m_type:Di,discrete_type:ki,composite_type:Ui,extension_token:kn,x_token:Mi,m_subtype:Pi,m_parameter:Es,m_value:xi,CSeq:Ou,CSeq_value:Li,Expires:Nu,Event:Du,event_type:sn,From:ku,from_param:Ss,tag_param:As,Max_Forwards:Uu,Min_Expires:Mu,Name_Addr_Header:Pu,Proxy_Authenticate:xu,challenge:Cs,other_challenge:Hi,auth_param:rn,digest_cln:Un,realm:qi,realm_value:Fi,domain:ji,URI:Mn,nonce:$i,nonce_value:Vi,opaque:Bi,stale:Ki,algorithm:Gi,qop_options:Wi,qop_value:Pn,Proxy_Require:Lu,Record_Route:Hu,rec_route:xn,Reason:qu,reason_param:bs,reason_cause:Yi,Require:Fu,Route:ju,route_param:Ln,Subscription_State:$u,substate_value:zi,subexp_params:Rs,event_reason_value:Ji,Subject:Vu,Supported:Bu,To:Ku,to_param:Is,Via:Gu,via_param:Hn,via_params:ws,via_ttl:Xi,via_maddr:Qi,via_received:Zi,via_branch:eo,response_port:to,rport:no,sent_protocol:so,protocol_name:ro,transport:io,sent_by:oo,via_host:lo,via_port:ao,ttl:Os,WWW_Authenticate:Wu,Session_Expires:Yu,s_e_expires:uo,s_e_params:Ns,s_e_refresher:co,extension_header:zu,header_value:ho,message_body:Ju,uuid_URI:Xu,uuid:_o,hex4:lt,hex8:po,hex12:fo,Refer_To:Qu,Replaces:Zu,call_id:mo,replaces_param:Ds,to_tag:go,from_tag:To,early_flag:vo};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+l(i)+".")}else i="CRLF";var e=0,d=0,_=[];function u(t){e<d||(e>d&&(d=e,_=[]),_.push(t))}function g(){var t;return s.substr(e,2)===`\r
73
73
  `?(t=`\r
74
- `,e+=2):(t=null,u('"\\r\\n"')),t}function p(){var t;return/^[0-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[0-9]")),t}function T(){var t;return/^[a-zA-Z]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-zA-Z]")),t}function y(){var t;return/^[0-9a-fA-F]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[0-9a-fA-F]")),t}function A(){var t;return t=b(),t===null&&(t=G()),t}function w(){var t;return/^[\0-\xFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function R(){var t;return/^["]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u('["]')),t}function b(){var t;return n.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function G(){var t;return n.charCodeAt(e)===9?(t=" ",e++):(t=null,u('"\\t"')),t}function P(){var t;return/^[a-zA-Z0-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-zA-Z0-9]")),t}function ye(){var t;return n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","'))))))))))),t}function O(){var t;return t=P(),t===null&&(t=j()),t}function j(){var t;return n.charCodeAt(e)===45?(t="-",e++):(t=null,u('"-"')),t===null&&(n.charCodeAt(e)===95?(t="_",e++):(t=null,u('"_"')),t===null&&(n.charCodeAt(e)===46?(t=".",e++):(t=null,u('"."')),t===null&&(n.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(n.charCodeAt(e)===126?(t="~",e++):(t=null,u('"~"')),t===null&&(n.charCodeAt(e)===42?(t="*",e++):(t=null,u('"*"')),t===null&&(n.charCodeAt(e)===39?(t="'",e++):(t=null,u(`"'"`)),t===null&&(n.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(n.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')))))))))),t}function pe(){var t,r,o,c,h;return c=e,h=e,n.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(o=y(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){return m.join("")}(c,t)),t===null&&(e=c),t}function Te(){var t,r,o,c,h,f;for(c=e,h=e,f=e,t=[],r=A();r!==null;)t.push(r),r=A();if(t!==null?(r=g(),r!==null?t=[t,r]:(t=null,e=f)):(t=null,e=f),t=t!==null?t:"",t!==null){if(o=A(),o!==null)for(r=[];o!==null;)r.push(o),o=A();else r=null;r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(m){return" "}()),t===null&&(e=c),t}function N(){var t;return t=Te(),t=t!==null?t:"",t}function H(){var t,r,o,c,h;for(c=e,h=e,t=[],r=b(),r===null&&(r=G());r!==null;)t.push(r),r=b(),r===null&&(r=G());return t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return":"}()),t===null&&(e=c),t}function $(){var t,r,o,c,h,f,m;if(h=e,f=e,r=q(),r!==null)for(t=[];r!==null;)t.push(r),r=q();else t=null;if(t!==null){for(r=[],m=e,o=[],c=Te();c!==null;)o.push(c),c=Te();for(o!==null?(c=q(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;){for(r.push(o),m=e,o=[],c=Te();c!==null;)o.push(c),c=Te();o!==null?(c=q(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m)}r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){return n.substring(e,E)}(h)),t===null&&(e=h),t}function q(){var t;return/^[!-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[!-~]")),t===null&&(t=M()),t}function M(){var t;return/^[\x80-\uFFFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\x80-\\uFFFF]")),t}function W(){var t;return/^[\x80-\xBF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\x80-\\xBF]")),t}function te(){var t;return t=p(),t===null&&(/^[a-f]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[a-f]"))),t}function I(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function J(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function ne(){var t;return n.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(n.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')),t===null&&(n.charCodeAt(e)===60?(t="<",e++):(t=null,u('"<"')),t===null&&(n.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t===null&&(t=R(),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===123?(t="{",e++):(t=null,u('"{"')),t===null&&(n.charCodeAt(e)===125?(t="}",e++):(t=null,u('"}"')),t===null&&(t=b(),t===null&&(t=G())))))))))))))))))),t}function Ye(){var t,r,o;if(o=e,r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(n.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=R(),r===null&&(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(n.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(n.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(n.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(n.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"'))))))))))))))))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=P(),r===null&&(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(n.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(n.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(n.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(n.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(n.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(n.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=R(),r===null&&(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(n.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(n.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(n.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(n.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"')))))))))))))))))))))))));else t=null;return t!==null&&(t=function(c){return n.substring(e,c)}(o)),t===null&&(e=o),t}function ee(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"*"}()),t===null&&(e=c),t}function V(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"/"}()),t===null&&(e=c),t}function k(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"="}()),t===null&&(e=c),t}function Ae(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return"("}()),t===null&&(e=c),t}function me(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return")"}()),t===null&&(e=c),t}function Ie(){var t,r,o,c;return o=e,c=e,n.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return">"}()),t===null&&(e=o),t}function xe(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(n.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return"<"}()),t===null&&(e=o),t}function _e(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return","}()),t===null&&(e=c),t}function le(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return";"}()),t===null&&(e=c),t}function ze(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return":"}()),t===null&&(e=c),t}function rt(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(r=R(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function Ee(){var t,r,o,c;return o=e,c=e,t=R(),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function ge(){var t,r,o,c;if(c=e,t=Ae(),t!==null){for(r=[],o=Re(),o===null&&(o=ae(),o===null&&(o=ge()));o!==null;)r.push(o),o=Re(),o===null&&(o=ae(),o===null&&(o=ge()));r!==null?(o=me(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)}else t=null,e=c;return t}function Re(){var t;return/^[!-']/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[!-']")),t===null&&(/^[*-[]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[*-[]")),t===null&&(/^[\]-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=M(),t===null&&(t=Te())))),t}function we(){var t,r,o,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=R(),r!==null){for(o=[],c=fe(),c===null&&(c=ae());c!==null;)o.push(c),c=fe(),c===null&&(c=ae());o!==null?(c=R(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m){return n.substring(e,m)}(h)),t===null&&(e=h),t}function Ue(){var t,r,o,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=R(),r!==null){for(o=[],c=fe(),c===null&&(c=ae());c!==null;)o.push(c),c=fe(),c===null&&(c=ae());o!==null?(c=R(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m){var E=n.substring(e,m).trim();return E.substring(1,E.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(h)),t===null&&(e=h),t}function fe(){var t;return t=Te(),t===null&&(n.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(/^[#-[]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[#-[]")),t===null&&(/^[\]-~]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=M())))),t}function ae(){var t,r,o;return o=e,n.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t!==null?(/^[\0-\t]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\0-\\t]")),r===null&&(/^[\x0B-\f]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\x0B-\\f]")),r===null&&(/^[\x0E-]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[\\x0E-]")))),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Se(){var t,r,o,c,h,f;return h=e,f=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Ft(),o=o!==null?o:"",o!==null?(c=Nn(),c!==null?t=[t,r,o,c]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t!==null&&(t=function(m){try{v.uri=new Io(v.scheme,v.user,v.host,v.port),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port}catch(E){v=-1}}()),t===null&&(e=h),t}function De(){var t,r,o,c,h,f,m,E;return m=e,E=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Ft(),o=o!==null?o:"",o!==null?(c=Nn(),c!==null?(h=Gr(),h!==null?(f=si(),f=f!==null?f:"",f!==null?t=[t,r,o,c,h,f]:(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E),t!==null&&(t=function(C){try{v.uri=new Io(v.scheme,v.user,v.host,v.port,v.uri_params,v.uri_headers),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port,delete v.uri_params,i==="SIP_URI"&&(v=v.uri)}catch(z){v=-1}}()),t===null&&(e=m),t}function Ke(){var t;return t=ct(),t===null&&(t=He()),t}function ct(){var t,r;return r=e,n.substr(e,4).toLowerCase()==="sips"?(t=n.substr(e,4),e+=4):(t=null,u('"sips"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function He(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"sip"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Ft(){var t,r,o,c,h,f;return c=e,h=e,t=Ut(),t!==null?(f=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Vr(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?(n.charCodeAt(e)===64?(o="@",e++):(o=null,u('"@"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.user=decodeURIComponent(n.substring(e-1,m))}(c)),t===null&&(e=c),t}function Ut(){var t,r;if(r=O(),r===null&&(r=pe(),r===null&&(r=ps())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(r=ps()));else t=null;return t}function ps(){var t;return n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"'))))))))),t}function Vr(){var t,r,o;for(o=e,t=[],r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));return t!==null&&(t=function(c){v.password=n.substring(e,c)}(o)),t===null&&(e=o),t}function Nn(){var t,r,o,c,h;return c=e,t=nn(),t!==null?(h=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Kr(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function nn(){var t,r;return r=e,t=ms(),t===null&&(t=sn(),t===null&&(t=Ts())),t!==null&&(t=function(o){return v.host=n.substring(e,o).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function ms(){var t,r,o,c,h,f;for(c=e,h=e,t=[],f=e,r=gs(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f);r!==null;)t.push(r),f=e,r=gs(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f);return t!==null?(r=Br(),r!==null?(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){return v.host_type="domain",n.substring(e,m)}(c)),t===null&&(e=c),t}function gs(){var t,r,o,c;if(c=e,t=P(),t!==null){for(r=[],o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Br(){var t,r,o,c;if(c=e,t=T(),t!==null){for(r=[],o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=P(),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Ts(){var t,r,o,c,h;return c=e,h=e,n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=vs(),r!==null?(n.charCodeAt(e)===93?(o="]",e++):(o=null,u('"]"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f){return v.host_type="IPv6",n.substring(e,f)}(c)),t===null&&(e=c),t}function vs(){var t,r,o,c,h,f,m,E,C,z,be,it,Bn,Hs,S,L;return Hs=e,S=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?(n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=x(),C!==null?(n.charCodeAt(e)===58?(z=":",e++):(z=null,u('":"')),z!==null?(be=x(),be!==null?(n.charCodeAt(e)===58?(it=":",e++):(it=null,u('":"')),it!==null?(Bn=qe(),Bn!==null?t=[t,r,o,c,h,f,m,E,C,z,be,it,Bn]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=x(),z!==null?(n.charCodeAt(e)===58?(be=":",e++):(be=null,u('":"')),be!==null?(it=qe(),it!==null?t=[t,r,o,c,h,f,m,E,C,z,be,it]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,C,z]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=qe(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=qe(),f!==null?t=[t,r,o,c,h,f]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?(n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=qe(),c!==null?t=[t,r,o,c]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=qe(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,n.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=x(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(n.substr(e,2)==="::"?(r="::",e+=2):(r=null,u('"::"')),r!==null?(o=x(),o!==null?(n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=x(),C!==null?(n.charCodeAt(e)===58?(z=":",e++):(z=null,u('":"')),z!==null?(be=qe(),be!==null?t=[t,r,o,c,h,f,m,E,C,z,be]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(n.substr(e,2)==="::"?(o="::",e+=2):(o=null,u('"::"')),o!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?(n.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,C,z]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(n.substr(e,2)==="::"?(c="::",e+=2):(c=null,u('"::"')),c!==null?(h=x(),h!==null?(n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?(n.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=qe(),C!==null?t=[t,r,o,c,h,f,m,E,C]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(n.substr(e,2)==="::"?(h="::",e+=2):(h=null,u('"::"')),h!==null?(f=x(),f!==null?(n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=qe(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(n.substr(e,2)==="::"?(f="::",e+=2):(f=null,u('"::"')),f!==null?(m=qe(),m!==null?t=[t,r,o,c,h,f,m]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?f=[f,m]:(f=null,e=L)):(f=null,e=L),f=f!==null?f:"",f!==null?(n.substr(e,2)==="::"?(m="::",e+=2):(m=null,u('"::"')),m!==null?(E=x(),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=x(),t!==null?(L=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=x(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,n.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=x(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=x(),f!==null?h=[h,f]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,n.charCodeAt(e)===58?(f=":",e++):(f=null,u('":"')),f!==null?(m=x(),m!==null?f=[f,m]:(f=null,e=L)):(f=null,e=L),f=f!==null?f:"",f!==null?(L=e,n.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=x(),E!==null?m=[m,E]:(m=null,e=L)):(m=null,e=L),m=m!==null?m:"",m!==null?(n.substr(e,2)==="::"?(E="::",e+=2):(E=null,u('"::"')),E!==null?t=[t,r,o,c,h,f,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S))))))))))))))),t!==null&&(t=function(dc){return v.host_type="IPv6",n.substring(e,dc)}(Hs)),t===null&&(e=Hs),t}function x(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(o=y(),o=o!==null?o:"",o!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function qe(){var t,r,o,c;return c=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=x(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=sn()),t}function sn(){var t,r,o,c,h,f,m,E,C;return E=e,C=e,t=rn(),t!==null?(n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=rn(),o!==null?(n.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null?(h=rn(),h!==null?(n.charCodeAt(e)===46?(f=".",e++):(f=null,u('"."')),f!==null?(m=rn(),m!==null?t=[t,r,o,c,h,f,m]:(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C),t!==null&&(t=function(z){return v.host_type="IPv4",n.substring(e,z)}(E)),t===null&&(e=E),t}function rn(){var t,r,o,c;return c=e,n.substr(e,2)==="25"?(t="25",e+=2):(t=null,u('"25"')),t!==null?(/^[0-5]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[0-5]")),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(c=e,n.charCodeAt(e)===50?(t="2",e++):(t=null,u('"2"')),t!==null?(/^[0-4]/.test(n.charAt(e))?(r=n.charAt(e),e++):(r=null,u("[0-4]")),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,n.charCodeAt(e)===49?(t="1",e++):(t=null,u('"1"')),t!==null?(r=p(),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,/^[1-9]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[1-9]")),t!==null?(r=p(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(t=p())))),t}function Kr(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){return C=parseInt(C.join("")),v.port=C,C}(f,t)),t===null&&(e=f),t}function Gr(){var t,r,o,c;for(t=[],c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=ys(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);r!==null;)t.push(r),c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=ys(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);return t}function ys(){var t;return t=Wr(),t===null&&(t=Yr(),t===null&&(t=zr(),t===null&&(t=Xr(),t===null&&(t=Qr(),t===null&&(t=Jr(),t===null&&(t=Zr())))))),t}function Wr(){var t,r,o,c;return o=e,c=e,n.substr(e,10).toLowerCase()==="transport="?(t=n.substr(e,10),e+=10):(t=null,u('"transport="')),t!==null?(n.substr(e,3).toLowerCase()==="udp"?(r=n.substr(e,3),e+=3):(r=null,u('"udp"')),r===null&&(n.substr(e,3).toLowerCase()==="tcp"?(r=n.substr(e,3),e+=3):(r=null,u('"tcp"')),r===null&&(n.substr(e,4).toLowerCase()==="sctp"?(r=n.substr(e,4),e+=4):(r=null,u('"sctp"')),r===null&&(n.substr(e,3).toLowerCase()==="tls"?(r=n.substr(e,3),e+=3):(r=null,u('"tls"')),r===null&&(r=I())))),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.transport=f.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function Yr(){var t,r,o,c;return o=e,c=e,n.substr(e,5).toLowerCase()==="user="?(t=n.substr(e,5),e+=5):(t=null,u('"user="')),t!==null?(n.substr(e,5).toLowerCase()==="phone"?(r=n.substr(e,5),e+=5):(r=null,u('"phone"')),r===null&&(n.substr(e,2).toLowerCase()==="ip"?(r=n.substr(e,2),e+=2):(r=null,u('"ip"')),r===null&&(r=I())),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.user=f.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function zr(){var t,r,o,c;return o=e,c=e,n.substr(e,7).toLowerCase()==="method="?(t=n.substr(e,7),e+=7):(t=null,u('"method="')),t!==null?(r=Mn(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.method=f}(o,t[1])),t===null&&(e=o),t}function Xr(){var t,r,o,c;return o=e,c=e,n.substr(e,4).toLowerCase()==="ttl="?(t=n.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=Ms(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.params||(v.params={}),v.params.ttl=f}(o,t[1])),t===null&&(e=o),t}function Qr(){var t,r,o,c;return o=e,c=e,n.substr(e,6).toLowerCase()==="maddr="?(t=n.substr(e,6),e+=6):(t=null,u('"maddr="')),t!==null?(r=nn(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,f){v.uri_params||(v.uri_params={}),v.uri_params.maddr=f}(o,t[1])),t===null&&(e=o),t}function Jr(){var t,r,o,c,h,f;return c=e,h=e,n.substr(e,2).toLowerCase()==="lr"?(t=n.substr(e,2),e+=2):(t=null,u('"lr"')),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=I(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.uri_params||(v.uri_params={}),v.uri_params.lr=void 0}()),t===null&&(e=c),t}function Zr(){var t,r,o,c,h,f;return c=e,h=e,t=ei(),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=ti(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.uri_params||(v.uri_params={}),typeof C>"u"?C=void 0:C=C[1],v.uri_params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function ei(){var t,r,o;if(o=e,r=on(),r!==null)for(t=[];r!==null;)t.push(r),r=on();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function ti(){var t,r,o;if(o=e,r=on(),r!==null)for(t=[];r!==null;)t.push(r),r=on();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function on(){var t;return t=ni(),t===null&&(t=O(),t===null&&(t=pe())),t}function ni(){var t;return n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function si(){var t,r,o,c,h,f,m;if(f=e,n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Dn(),r!==null){for(o=[],m=e,n.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Dn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);c!==null;)o.push(c),m=e,n.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Dn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);o!==null?t=[t,r,o]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t}function Dn(){var t,r,o,c,h;return c=e,h=e,t=ri(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=ii(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m,E){m=m.join("").toLowerCase(),E=E.join(""),v.uri_headers||(v.uri_headers={}),v.uri_headers[m]?v.uri_headers[m].push(E):v.uri_headers[m]=[E]}(c,t[0],t[2])),t===null&&(e=c),t}function ri(){var t,r;if(r=ln(),r===null&&(r=O(),r===null&&(r=pe())),r!==null)for(t=[];r!==null;)t.push(r),r=ln(),r===null&&(r=O(),r===null&&(r=pe()));else t=null;return t}function ii(){var t,r;for(t=[],r=ln(),r===null&&(r=O(),r===null&&(r=pe()));r!==null;)t.push(r),r=ln(),r===null&&(r=O(),r===null&&(r=pe()));return t}function ln(){var t;return n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(n.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Ou(){var t;return t=Ii(),t===null&&(t=oi()),t}function oi(){var t,r,o,c,h,f;return f=e,t=Mn(),t!==null?(r=b(),r!==null?(o=li(),o!==null?(c=b(),c!==null?(h=As(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function li(){var t;return t=De(),t===null&&(t=Es()),t}function Es(){var t,r,o,c;return c=e,t=_i(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=ai(),o===null&&(o=ci()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ai(){var t,r,o,c,h;return c=e,t=ui(),t===null&&(t=kn()),t!==null?(h=e,n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(o=gi(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function ui(){var t,r,o,c;return c=e,n.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=fi(),r!==null?(o=kn(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function kn(){var t,r,o;return o=e,n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=di(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function ci(){var t,r,o,c;if(c=e,t=hi(),t!==null){for(r=[],o=an();o!==null;)r.push(o),o=an();r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function an(){var t;return t=ye(),t===null&&(t=O(),t===null&&(t=pe())),t}function hi(){var t;return t=O(),t===null&&(t=pe(),t===null&&(n.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))))),t}function di(){var t,r,o,c,h,f;if(h=e,t=Un(),t!==null){for(r=[],f=e,n.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=Un(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=Un(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Un(){var t,r,o,c,h,f;for(h=e,t=[],r=un();r!==null;)t.push(r),r=un();if(t!==null){for(r=[],f=e,n.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ss(){var t,r;for(t=[],r=un();r!==null;)t.push(r),r=un();return t}function un(){var t;return t=O(),t===null&&(t=pe(),t===null&&(n.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(n.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(n.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(n.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(n.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(n.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(n.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))),t}function _i(){var t,r,o,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],o=T(),o===null&&(o=p(),o===null&&(n.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));o!==null;)r.push(o),o=T(),o===null&&(o=p(),o===null&&(n.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(n.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(f){v.scheme=n.substring(e,f)}(c)),t===null&&(e=c),t}function fi(){var t;return t=pi(),t===null&&(t=mi()),t}function pi(){var t,r,o,c;return o=e,c=e,t=Ft(),t!==null?(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t=t!==null?t:"",t!==null?(r=Nn(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t=t!==null?t:"",t}function mi(){var t,r;if(r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(n.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(n.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(n.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')))))))))));else t=null;return t}function gi(){var t,r;for(t=[],r=an();r!==null;)t.push(r),r=an();return t}function As(){var t,r,o,c,h,f,m,E;if(m=e,E=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t!==null)if(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;if(o!==null)if(n.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null){if(f=p(),f!==null)for(h=[];f!==null;)h.push(f),f=p();else h=null;h!==null?t=[t,r,o,c,h]:(t=null,e=E)}else t=null,e=E;else t=null,e=E}else t=null,e=E;else t=null,e=E;return t!==null&&(t=function(C){v.sip_version=n.substring(e,C)}(m)),t===null&&(e=m),t}function Ti(){var t;return n.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function vi(){var t;return n.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function yi(){var t;return n.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function Ei(){var t;return n.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function Si(){var t;return n.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function Ai(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function Ci(){var t;return n.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function bi(){var t;return n.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function Ri(){var t;return n.substr(e,5)==="REFER"?(t="REFER",e+=5):(t=null,u('"REFER"')),t}function Mn(){var t,r;return r=e,t=Ti(),t===null&&(t=vi(),t===null&&(t=yi(),t===null&&(t=Ei(),t===null&&(t=Si(),t===null&&(t=Ai(),t===null&&(t=Ci(),t===null&&(t=bi(),t===null&&(t=Ri(),t===null&&(t=I()))))))))),t!==null&&(t=function(o){return v.method=n.substring(e,o),v.method}(r)),t===null&&(e=r),t}function Ii(){var t,r,o,c,h,f;return f=e,t=As(),t!==null?(r=b(),r!==null?(o=wi(),o!==null?(c=b(),c!==null?(h=Ni(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function wi(){var t,r;return r=e,t=Oi(),t!==null&&(t=function(o,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Oi(){var t,r,o,c;return c=e,t=p(),t!==null?(r=p(),r!==null?(o=p(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ni(){var t,r,o;for(o=e,t=[],r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=W(),r===null&&(r=b(),r===null&&(r=G()))))));r!==null;)t.push(r),r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=W(),r===null&&(r=b(),r===null&&(r=G()))))));return t!==null&&(t=function(c){v.reason_phrase=n.substring(e,c)}(o)),t===null&&(e=o),t}function Nu(){var t,r,o,c,h,f;if(h=e,t=cn(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=cn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=cn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Du(){var t,r,o,c,h,f;return c=e,h=e,t=Ye(),t!==null?(f=e,n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ye(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v=n.substring(e,m)}(c)),t===null&&(e=c),t}function ku(){var t,r,o,c,h,f,m;if(h=e,t=ee(),t===null)if(f=e,t=xn(),t!==null){for(r=[],m=e,o=_e(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=_e(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C,z;for(z=v.multi_header.length,C=0;C<z;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function xn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Cs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Cs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Mt(){var t,r,o,c,h;return h=e,t=Pn(),t=t!==null?t:"",t!==null?(r=xe(),r!==null?(o=De(),o!==null?(c=Ie(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Pn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=I(),t!==null){for(r=[],m=e,o=Te(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=Te(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t===null&&(t=Ue()),t!==null&&(t=function(E,C){typeof C=="string"?v.display_name=C:v.display_name=C[1].reduce(function(z,be){return z+be[0]+be[1]},C[0])}(h,t)),t===null&&(e=h),t}function Cs(){var t;return t=Di(),t===null&&(t=ki(),t===null&&(t=Oe())),t}function Di(){var t,r,o,c,h;return c=e,h=e,n.substr(e,1).toLowerCase()==="q"?(t=n.substr(e,1),e++):(t=null,u('"q"')),t!==null?(r=k(),r!==null?(o=Ui(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.params||(v.params={}),v.params.q=m}(c,t[2])),t===null&&(e=c),t}function ki(){var t,r,o,c,h;return c=e,h=e,n.substr(e,7).toLowerCase()==="expires"?(t=n.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.params||(v.params={}),v.params.expires=m}(c,t[2])),t===null&&(e=c),t}function xt(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){return parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Ui(){var t,r,o,c,h,f,m,E;return f=e,m=e,n.charCodeAt(e)===48?(t="0",e++):(t=null,u('"0"')),t!==null?(E=e,n.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?r=[r,o,c,h]:(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(C){return parseFloat(n.substring(e,C))}(f)),t===null&&(e=f),t}function Oe(){var t,r,o,c,h,f;return c=e,h=e,t=I(),t!==null?(f=e,r=k(),r!==null?(o=Mi(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.params||(v.params={}),typeof C>"u"?C=void 0:C=C[1],v.params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Mi(){var t;return t=I(),t===null&&(t=nn(),t===null&&(t=we())),t}function Uu(){var t,r,o,c,h,f;if(h=e,t=xi(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function xi(){var t;return n.substr(e,6).toLowerCase()==="render"?(t=n.substr(e,6),e+=6):(t=null,u('"render"')),t===null&&(n.substr(e,7).toLowerCase()==="session"?(t=n.substr(e,7),e+=7):(t=null,u('"session"')),t===null&&(n.substr(e,4).toLowerCase()==="icon"?(t=n.substr(e,4),e+=4):(t=null,u('"icon"')),t===null&&(n.substr(e,5).toLowerCase()==="alert"?(t=n.substr(e,5),e+=5):(t=null,u('"alert"')),t===null&&(t=I())))),t}function bs(){var t;return t=Pi(),t===null&&(t=Oe()),t}function Pi(){var t,r,o,c;return c=e,n.substr(e,8).toLowerCase()==="handling"?(t=n.substr(e,8),e+=8):(t=null,u('"handling"')),t!==null?(r=k(),r!==null?(n.substr(e,8).toLowerCase()==="optional"?(o=n.substr(e,8),e+=8):(o=null,u('"optional"')),o===null&&(n.substr(e,8).toLowerCase()==="required"?(o=n.substr(e,8),e+=8):(o=null,u('"required"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Mu(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function xu(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Pu(){var t,r;return r=e,t=Li(),t!==null&&(t=function(o){v=n.substring(e,o)}(r)),t===null&&(e=r),t}function Li(){var t,r,o,c,h,f,m,E;if(m=e,t=Hi(),t!==null)if(r=V(),r!==null)if(o=$i(),o!==null){for(c=[],E=e,h=le(),h!==null?(f=Rs(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=le(),h!==null?(f=Rs(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Hi(){var t;return t=qi(),t===null&&(t=Fi()),t}function qi(){var t;return n.substr(e,4).toLowerCase()==="text"?(t=n.substr(e,4),e+=4):(t=null,u('"text"')),t===null&&(n.substr(e,5).toLowerCase()==="image"?(t=n.substr(e,5),e+=5):(t=null,u('"image"')),t===null&&(n.substr(e,5).toLowerCase()==="audio"?(t=n.substr(e,5),e+=5):(t=null,u('"audio"')),t===null&&(n.substr(e,5).toLowerCase()==="video"?(t=n.substr(e,5),e+=5):(t=null,u('"video"')),t===null&&(n.substr(e,11).toLowerCase()==="application"?(t=n.substr(e,11),e+=11):(t=null,u('"application"')),t===null&&(t=Ln()))))),t}function Fi(){var t;return n.substr(e,7).toLowerCase()==="message"?(t=n.substr(e,7),e+=7):(t=null,u('"message"')),t===null&&(n.substr(e,9).toLowerCase()==="multipart"?(t=n.substr(e,9),e+=9):(t=null,u('"multipart"')),t===null&&(t=Ln())),t}function Ln(){var t;return t=I(),t===null&&(t=ji()),t}function ji(){var t,r,o;return o=e,n.substr(e,2).toLowerCase()==="x-"?(t=n.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function $i(){var t;return t=Ln(),t===null&&(t=I()),t}function Rs(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=Vi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Vi(){var t;return t=I(),t===null&&(t=we()),t}function Lu(){var t,r,o,c;return c=e,t=Bi(),t!==null?(r=Te(),r!==null?(o=Mn(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Bi(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v.value=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Hu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function qu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=cn(),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E,C){v.event=C.join("").toLowerCase()}(h,t[0])),t===null&&(e=h),t}function cn(){var t,r,o,c,h,f;if(h=e,t=J(),t!==null){for(r=[],f=e,n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=J(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,n.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=J(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Fu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch(z){v=-1}}()),t===null&&(e=h),t}function Is(){var t;return t=ws(),t===null&&(t=Oe()),t}function ws(){var t,r,o,c,h;return c=e,h=e,n.substr(e,3).toLowerCase()==="tag"?(t=n.substr(e,3),e+=3):(t=null,u('"tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.tag=m}(c,t[2])),t===null&&(e=c),t}function ju(){var t,r,o;if(o=e,r=p(),r!==null)for(t=[];r!==null;)t.push(r),r=p();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function $u(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Vu(){var t,r,o,c,h,f,m,E,C,z;for(E=e,C=e,t=[],r=Pn();r!==null;)t.push(r),r=Pn();if(t!==null)if(r=xe(),r!==null)if(o=De(),o!==null)if(c=Ie(),c!==null){for(h=[],z=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);f!==null;)h.push(f),z=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);h!==null?t=[t,r,o,c,h]:(t=null,e=C)}else t=null,e=C;else t=null,e=C;else t=null,e=C;else t=null,e=C;return t!==null&&(t=function(be){try{v=new Bt(v.uri,v.display_name,v.params)}catch(it){v=-1}}()),t===null&&(e=E),t}function Bu(){var t;return t=Os(),t}function Os(){var t,r,o,c,h,f,m,E;if(m=e,n.substr(e,6).toLowerCase()==="digest"?(t=n.substr(e,6),e+=6):(t=null,u('"Digest"')),t!==null)if(r=Te(),r!==null)if(o=Hn(),o!==null){for(c=[],E=e,h=_e(),h!==null?(f=Hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=_e(),h!==null?(f=Hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Ki()),t}function Ki(){var t,r,o,c,h,f,m,E;if(m=e,t=I(),t!==null)if(r=Te(),r!==null)if(o=hn(),o!==null){for(c=[],E=e,h=_e(),h!==null?(f=hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=_e(),h!==null?(f=hn(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function hn(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=I(),o===null&&(o=we()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Hn(){var t;return t=Gi(),t===null&&(t=Yi(),t===null&&(t=zi(),t===null&&(t=Qi(),t===null&&(t=Ji(),t===null&&(t=Zi(),t===null&&(t=eo(),t===null&&(t=hn()))))))),t}function Gi(){var t,r,o,c;return c=e,n.substr(e,5).toLowerCase()==="realm"?(t=n.substr(e,5),e+=5):(t=null,u('"realm"')),t!==null?(r=k(),r!==null?(o=Wi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Wi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(o,c){v.realm=c}(r,t)),t===null&&(e=r),t}function Yi(){var t,r,o,c,h,f,m,E,C;if(E=e,n.substr(e,6).toLowerCase()==="domain"?(t=n.substr(e,6),e+=6):(t=null,u('"domain"')),t!==null)if(r=k(),r!==null)if(o=rt(),o!==null)if(c=qn(),c!==null){if(h=[],C=e,m=b(),m!==null)for(f=[];m!==null;)f.push(m),m=b();else f=null;for(f!==null?(m=qn(),m!==null?f=[f,m]:(f=null,e=C)):(f=null,e=C);f!==null;){if(h.push(f),C=e,m=b(),m!==null)for(f=[];m!==null;)f.push(m),m=b();else f=null;f!==null?(m=qn(),m!==null?f=[f,m]:(f=null,e=C)):(f=null,e=C)}h!==null?(f=Ee(),f!==null?t=[t,r,o,c,h,f]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function qn(){var t;return t=Es(),t===null&&(t=kn()),t}function zi(){var t,r,o,c;return c=e,n.substr(e,5).toLowerCase()==="nonce"?(t=n.substr(e,5),e+=5):(t=null,u('"nonce"')),t!==null?(r=k(),r!==null?(o=Xi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Xi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(o,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Qi(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="opaque"?(t=n.substr(e,6),e+=6):(t=null,u('"opaque"')),t!==null?(r=k(),r!==null?(o=Ue(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.opaque=m}(c,t[2])),t===null&&(e=c),t}function Ji(){var t,r,o,c,h;return c=e,n.substr(e,5).toLowerCase()==="stale"?(t=n.substr(e,5),e+=5):(t=null,u('"stale"')),t!==null?(r=k(),r!==null?(h=e,n.substr(e,4).toLowerCase()==="true"?(o=n.substr(e,4),e+=4):(o=null,u('"true"')),o!==null&&(o=function(f){v.stale=!0}()),o===null&&(e=h),o===null&&(h=e,n.substr(e,5).toLowerCase()==="false"?(o=n.substr(e,5),e+=5):(o=null,u('"false"')),o!==null&&(o=function(f){v.stale=!1}()),o===null&&(e=h)),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Zi(){var t,r,o,c,h;return c=e,h=e,n.substr(e,9).toLowerCase()==="algorithm"?(t=n.substr(e,9),e+=9):(t=null,u('"algorithm"')),t!==null?(r=k(),r!==null?(n.substr(e,3).toLowerCase()==="md5"?(o=n.substr(e,3),e+=3):(o=null,u('"MD5"')),o===null&&(n.substr(e,8).toLowerCase()==="md5-sess"?(o=n.substr(e,8),e+=8):(o=null,u('"MD5-sess"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.algorithm=m.toUpperCase()}(c,t[2])),t===null&&(e=c),t}function eo(){var t,r,o,c,h,f,m,E,C,z;if(E=e,n.substr(e,3).toLowerCase()==="qop"?(t=n.substr(e,3),e+=3):(t=null,u('"qop"')),t!==null)if(r=k(),r!==null)if(o=rt(),o!==null){if(C=e,c=Fn(),c!==null){for(h=[],z=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);f!==null;)h.push(f),z=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=z)):(f=null,e=z);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=Ee(),h!==null?t=[t,r,o,c,h]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Fn(){var t,r;return r=e,n.substr(e,8).toLowerCase()==="auth-int"?(t=n.substr(e,8),e+=8):(t=null,u('"auth-int"')),t===null&&(n.substr(e,4).toLowerCase()==="auth"?(t=n.substr(e,4),e+=4):(t=null,u('"auth"')),t===null&&(t=I())),t!==null&&(t=function(o,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Ku(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Gu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=jn(),t!==null){for(r=[],m=e,o=_e(),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=_e(),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C,z;for(z=v.multi_header.length,C=0;C<z;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function jn(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Mt(),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Wu(){var t,r,o,c,h,f,m;if(h=e,f=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E,C){if(v.protocol=C.toLowerCase(),v.params||(v.params={}),v.params.text&&v.params.text[0]==='"'){var z=v.params.text;v.text=z.substring(1,z.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function Ns(){var t;return t=to(),t===null&&(t=Oe()),t}function to(){var t,r,o,c,h,f;if(h=e,f=e,n.substr(e,5).toLowerCase()==="cause"?(t=n.substr(e,5),e+=5):(t=null,u('"cause"')),t!==null)if(r=k(),r!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;o!==null?t=[t,r,o]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t!==null&&(t=function(m,E){v.cause=parseInt(E.join(""))}(h,t[2])),t===null&&(e=h),t}function Yu(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function zu(){var t,r,o,c,h,f;if(h=e,t=$n(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=$n(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=$n(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $n(){var t,r,o,c,h,f;if(h=e,t=Mt(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Xu(){var t,r,o,c,h,f;if(h=e,t=no(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function no(){var t,r;return r=e,n.substr(e,6).toLowerCase()==="active"?(t=n.substr(e,6),e+=6):(t=null,u('"active"')),t===null&&(n.substr(e,7).toLowerCase()==="pending"?(t=n.substr(e,7),e+=7):(t=null,u('"pending"')),t===null&&(n.substr(e,10).toLowerCase()==="terminated"?(t=n.substr(e,10),e+=10):(t=null,u('"terminated"')),t===null&&(t=I()))),t!==null&&(t=function(o){v.state=n.substring(e,o)}(r)),t===null&&(e=r),t}function Ds(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="reason"?(t=n.substr(e,6),e+=6):(t=null,u('"reason"')),t!==null?(r=k(),r!==null?(o=so(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.reason=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,n.substr(e,7).toLowerCase()==="expires"?(t=n.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.expires=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,n.substr(e,11).toLowerCase()==="retry_after"?(t=n.substr(e,11),e+=11):(t=null,u('"retry_after"')),t!==null?(r=k(),r!==null?(o=xt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){typeof m<"u"&&(v.retry_after=m)}(c,t[2])),t===null&&(e=c),t===null&&(t=Oe()))),t}function so(){var t;return n.substr(e,11).toLowerCase()==="deactivated"?(t=n.substr(e,11),e+=11):(t=null,u('"deactivated"')),t===null&&(n.substr(e,9).toLowerCase()==="probation"?(t=n.substr(e,9),e+=9):(t=null,u('"probation"')),t===null&&(n.substr(e,8).toLowerCase()==="rejected"?(t=n.substr(e,8),e+=8):(t=null,u('"rejected"')),t===null&&(n.substr(e,7).toLowerCase()==="timeout"?(t=n.substr(e,7),e+=7):(t=null,u('"timeout"')),t===null&&(n.substr(e,6).toLowerCase()==="giveup"?(t=n.substr(e,6),e+=6):(t=null,u('"giveup"')),t===null&&(n.substr(e,10).toLowerCase()==="noresource"?(t=n.substr(e,10),e+=10):(t=null,u('"noresource"')),t===null&&(n.substr(e,9).toLowerCase()==="invariant"?(t=n.substr(e,9),e+=9):(t=null,u('"invariant"')),t===null&&(t=I()))))))),t}function Qu(){var t;return t=$(),t=t!==null?t:"",t}function Ju(){var t,r,o,c,h,f;if(h=e,t=I(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function Zu(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=ks(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=ks(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){var C=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch(z){v=-1}}()),t===null&&(e=h),t}function ks(){var t;return t=ws(),t===null&&(t=Oe()),t}function ec(){var t,r,o,c,h,f;if(h=e,t=Vn(),t!==null){for(r=[],f=e,o=_e(),o!==null?(c=Vn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=_e(),o!==null?(c=Vn(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Vn(){var t,r,o,c,h,f,m,E;if(m=e,t=co(),t!==null)if(r=Te(),r!==null)if(o=fo(),o!==null){for(c=[],E=e,h=le(),h!==null?(f=Us(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=le(),h!==null?(f=Us(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Us(){var t;return t=ro(),t===null&&(t=io(),t===null&&(t=oo(),t===null&&(t=lo(),t===null&&(t=ao(),t===null&&(t=Oe()))))),t}function ro(){var t,r,o,c,h;return c=e,h=e,n.substr(e,3).toLowerCase()==="ttl"?(t=n.substr(e,3),e+=3):(t=null,u('"ttl"')),t!==null?(r=k(),r!==null?(o=Ms(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.ttl=m}(c,t[2])),t===null&&(e=c),t}function io(){var t,r,o,c,h;return c=e,h=e,n.substr(e,5).toLowerCase()==="maddr"?(t=n.substr(e,5),e+=5):(t=null,u('"maddr"')),t!==null?(r=k(),r!==null?(o=nn(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.maddr=m}(c,t[2])),t===null&&(e=c),t}function oo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,8).toLowerCase()==="received"?(t=n.substr(e,8),e+=8):(t=null,u('"received"')),t!==null?(r=k(),r!==null?(o=sn(),o===null&&(o=vs()),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.received=m}(c,t[2])),t===null&&(e=c),t}function lo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6).toLowerCase()==="branch"?(t=n.substr(e,6),e+=6):(t=null,u('"branch"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.branch=m}(c,t[2])),t===null&&(e=c),t}function ao(){var t,r,o,c,h;return c=e,n.substr(e,5).toLowerCase()==="rport"?(t=n.substr(e,5),e+=5):(t=null,u('"rport"')),t!==null?(h=e,r=k(),r!==null?(o=uo(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function uo(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.rport=parseInt(C.join(""))}(f,t)),t===null&&(e=f),t}function co(){var t,r,o,c,h,f;return f=e,t=ho(),t!==null?(r=V(),r!==null?(o=I(),o!==null?(c=V(),c!==null?(h=_o(),h!==null?t=[t,r,o,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function ho(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="sip"?(t=n.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null&&(t=function(o,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function _o(){var t,r;return r=e,n.substr(e,3).toLowerCase()==="udp"?(t=n.substr(e,3),e+=3):(t=null,u('"UDP"')),t===null&&(n.substr(e,3).toLowerCase()==="tcp"?(t=n.substr(e,3),e+=3):(t=null,u('"TCP"')),t===null&&(n.substr(e,3).toLowerCase()==="tls"?(t=n.substr(e,3),e+=3):(t=null,u('"TLS"')),t===null&&(n.substr(e,4).toLowerCase()==="sctp"?(t=n.substr(e,4),e+=4):(t=null,u('"SCTP"')),t===null&&(t=I())))),t!==null&&(t=function(o,c){v.transport=c}(r,t)),t===null&&(e=r),t}function fo(){var t,r,o,c,h;return c=e,t=po(),t!==null?(h=e,r=ze(),r!==null?(o=mo(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function po(){var t,r;return r=e,t=sn(),t===null&&(t=Ts(),t===null&&(t=ms())),t!==null&&(t=function(o){v.host=n.substring(e,o)}(r)),t===null&&(e=r),t}function mo(){var t,r,o,c,h,f,m;return f=e,m=e,t=p(),t=t!==null?t:"",t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.port=parseInt(C.join(""))}(f,t)),t===null&&(e=f),t}function Ms(){var t,r,o,c,h;return c=e,h=e,t=p(),t!==null?(r=p(),r=r!==null?r:"",r!==null?(o=p(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){return parseInt(m.join(""))}(c,t)),t===null&&(e=c),t}function tc(){var t;return t=Os(),t}function nc(){var t,r,o,c,h,f;if(h=e,t=go(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=xs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=xs(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function go(){var t,r;return r=e,t=xt(),t!==null&&(t=function(o,c){v.expires=c}(r,t)),t===null&&(e=r),t}function xs(){var t;return t=To(),t===null&&(t=Oe()),t}function To(){var t,r,o,c,h;return c=e,h=e,n.substr(e,9).toLowerCase()==="refresher"?(t=n.substr(e,9),e+=9):(t=null,u('"refresher"')),t!==null?(r=k(),r!==null?(n.substr(e,3).toLowerCase()==="uac"?(o=n.substr(e,3),e+=3):(o=null,u('"uac"')),o===null&&(n.substr(e,3).toLowerCase()==="uas"?(o=n.substr(e,3),e+=3):(o=null,u('"uas"'))),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.refresher=m.toLowerCase()}(c,t[2])),t===null&&(e=c),t}function sc(){var t,r,o,c;return c=e,t=I(),t!==null?(r=H(),r!==null?(o=vo(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function vo(){var t,r;for(t=[],r=q(),r===null&&(r=W(),r===null&&(r=Te()));r!==null;)t.push(r),r=q(),r===null&&(r=W(),r===null&&(r=Te()));return t}function rc(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function ic(){var t,r,o;return o=e,n.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=yo(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function yo(){var t,r,o,c,h,f,m,E,C,z,be;return z=e,be=e,t=Eo(),t!==null?(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(o=dt(),o!==null?(n.charCodeAt(e)===45?(c="-",e++):(c=null,u('"-"')),c!==null?(h=dt(),h!==null?(n.charCodeAt(e)===45?(f="-",e++):(f=null,u('"-"')),f!==null?(m=dt(),m!==null?(n.charCodeAt(e)===45?(E="-",e++):(E=null,u('"-"')),E!==null?(C=So(),C!==null?t=[t,r,o,c,h,f,m,E,C]:(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be)):(t=null,e=be),t!==null&&(t=function(it,Bn){v=n.substring(e+5,it)}(z,t[0])),t===null&&(e=z),t}function dt(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(o=y(),o!==null?(c=y(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Eo(){var t,r,o;return o=e,t=dt(),t!==null?(r=dt(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function So(){var t,r,o,c;return c=e,t=dt(),t!==null?(r=dt(),r!==null?(o=dt(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function oc(){var t,r,o,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=le(),o!==null?(c=Oe(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=f)}else t=null,e=f;return t!==null&&(t=function(E){try{v=new Bt(v.uri,v.display_name,v.params)}catch(C){v=-1}}()),t===null&&(e=h),t}function lc(){var t,r,o,c,h,f;if(h=e,t=Ao(),t!==null){for(r=[],f=e,o=le(),o!==null?(c=Ps(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);o!==null;)r.push(o),f=e,o=le(),o!==null?(c=Ps(),c!==null?o=[o,c]:(o=null,e=f)):(o=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ao(){var t,r,o,c,h,f;return c=e,h=e,t=Ye(),t!==null?(f=e,n.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ye(),o!==null?r=[r,o]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.call_id=n.substring(e,m)}(c)),t===null&&(e=c),t}function Ps(){var t;return t=Co(),t===null&&(t=bo(),t===null&&(t=Ro(),t===null&&(t=Oe()))),t}function Co(){var t,r,o,c,h;return c=e,h=e,n.substr(e,6)==="to-tag"?(t="to-tag",e+=6):(t=null,u('"to-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.to_tag=m}(c,t[2])),t===null&&(e=c),t}function bo(){var t,r,o,c,h;return c=e,h=e,n.substr(e,8)==="from-tag"?(t="from-tag",e+=8):(t=null,u('"from-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(f,m){v.from_tag=m}(c,t[2])),t===null&&(e=c),t}function Ro(){var t,r;return r=e,n.substr(e,10)==="early-only"?(t="early-only",e+=10):(t=null,u('"early-only"')),t!==null&&(t=function(o){v.early_only=!0}()),t===null&&(e=r),t}function ac(t){t.sort();for(var r=null,o=[],c=0;c<t.length;c++)t[c]!==r&&(o.push(t[c]),r=t[c]);return o}function uc(){for(var t=1,r=1,o=!1,c=0;c<Math.max(e,d);c++){var h=n.charAt(c);h===`
75
- `?(o||t++,r=1,o=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(t++,r=1,o=!0):(r++,o=!1)}return{line:t,column:r}}var Io=Sn(),Bt=Ma(),v={},cc=a[i]();if(cc===null||e!==n.length){var Ls=Math.max(e,d),hc=Ls<n.length?n.charAt(Ls):null,wo=uc();return new this.SyntaxError(ac(_),hc,Ls,wo.line,wo.column),-1}return v},toSource:function(){return this._source}};return s.SyntaxError=function(n,i,a,e,d){function _(u,g){var p,T;switch(u.length){case 0:p="end of input";break;case 1:p=u[0];break;default:p=u.slice(0,u.length-1).join(", ")+" or "+u[u.length-1]}return T=g?l(g):"end of input","Expected "+p+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=i,this.message=_(n,i),this.offset=a,this.line=e,this.column=d},s.SyntaxError.prototype=Error.prototype,s}()),Gh}var xa,Yh;function Sn(){if(Yh)return xa;Yh=1;const l=Ne,s=yt(),n=Xt();return xa=class E_{static parse(a){if(a=n.parse(a,"SIP_URI"),a!==-1)return a}constructor(a,e,d,_,u={},g={}){if(!d)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=a||l.SIP,this._user=e,this._host=d,this._port=_;for(const p in u)Object.prototype.hasOwnProperty.call(u,p)&&this.setParam(p,u[p]);for(const p in g)Object.prototype.hasOwnProperty.call(g,p)&&this.setHeader(p,g[p])}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,e){a&&(this._parameters[a.toLowerCase()]=typeof e>"u"||e===null?null:e.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 e=this._parameters[a];return delete this._parameters[a],e}}clearParams(){this._parameters={}}setHeader(a,e){this._headers[s.headerize(a)]=Array.isArray(e)?e:[e]}getHeader(a){if(a)return this._headers[s.headerize(a)]}hasHeader(a){if(a)return this._headers.hasOwnProperty(s.headerize(a))&&!0||!1}deleteHeader(a){if(a=s.headerize(a),this._headers.hasOwnProperty(a)){const e=this._headers[a];return delete this._headers[a],e}}clearHeaders(){this._headers={}}clone(){return new E_(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const a=[];let e=`${this._scheme}:`;this._user&&(e+=`${s.escapeUser(this._user)}@`),e+=this._host,(this._port||this._port===0)&&(e+=`:${this._port}`);for(const d in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,d)&&(e+=`;${d}`,this._parameters[d]!==null&&(e+=`=${this._parameters[d]}`));for(const d in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,d))for(const _ of this._headers[d])a.push(`${d}=${_}`);return a.length>0&&(e+=`?${a.join("&")}`),e}toAor(a){let e=`${this._scheme}:`;return this._user&&(e+=`${s.escapeUser(this._user)}@`),e+=this._host,a&&(this._port||this._port===0)&&(e+=`:${this._port}`),e}},xa}var zh;function yt(){if(zh)return nt;zh=1;const l=Ne,s=Sn(),n=Xt();nt.str_utf8_length=d=>unescape(encodeURIComponent(d)).length;const i=nt.isFunction=d=>d!==void 0?Object.prototype.toString.call(d)==="[object Function]":!1;nt.isString=d=>d!==void 0?Object.prototype.toString.call(d)==="[object String]":!1,nt.isDecimal=d=>!isNaN(d)&&parseFloat(d)===parseInt(d,10),nt.isEmpty=d=>d===null||d===""||d===void 0||Array.isArray(d)&&d.length===0||typeof d=="number"&&isNaN(d),nt.hasMethods=function(d,..._){for(const u of _)if(i(d[u]))return!1;return!0};const a=nt.createRandomToken=(d,_=32)=>{let u,g,p="";for(u=0;u<d;u++)g=Math.random()*_|0,p+=g.toString(_);return p};nt.newTag=()=>a(10),nt.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const _=Math.random()*16|0;return(d==="x"?_:_&3|8).toString(16)}),nt.hostType=d=>{if(d){if(d=n.parse(d,"host"),d!==-1)return d.host_type}else return};const e=nt.escapeUser=d=>encodeURIComponent(decodeURIComponent(d)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return nt.normalizeTarget=(d,_)=>{if(d){if(d instanceof s)return d;if(typeof d=="string"){const u=d.split("@");let g,p;switch(u.length){case 1:if(!_)return;g=d,p=_;break;case 2:g=u[0],p=u[1];break;default:g=u.slice(0,u.length-1).join("@"),p=u[u.length-1]}g=g.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(g)&&(g=g.replace(/[-.()]/g,"")),d=`${l.SIP}:${e(g)}@${p}`;let T;return(T=s.parse(d))?T:void 0}else return}else return},nt.headerize=d=>{const _={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},u=d.toLowerCase().replace(/_/g,"-").split("-");let g="";const p=u.length;let T;for(T=0;T<p;T++)T!==0&&(g+="-"),g+=u[T].charAt(0).toUpperCase()+u[T].substring(1);return _[g]&&(g=_[g]),g},nt.sipErrorCause=d=>{for(const _ in l.SIP_ERROR_CAUSES)if(l.SIP_ERROR_CAUSES[_].indexOf(d)!==-1)return l.causes[_];return l.causes.SIP_FAILURE_CODE},nt.getRandomTestNetIP=()=>{function d(_,u){return Math.floor(Math.random()*(u-_+1)+_)}return`192.0.2.${d(1,254)}`},nt.calculateMD5=d=>{function _(Ee,ge){return Ee<<ge|Ee>>>32-ge}function u(Ee,ge){const Re=Ee&2147483648,we=ge&2147483648,Ue=Ee&1073741824,fe=ge&1073741824,ae=(Ee&1073741823)+(ge&1073741823);return Ue&fe?ae^2147483648^Re^we:Ue|fe?ae&1073741824?ae^3221225472^Re^we:ae^1073741824^Re^we:ae^Re^we}function g(Ee,ge,Re){return Ee&ge|~Ee&Re}function p(Ee,ge,Re){return Ee&Re|ge&~Re}function T(Ee,ge,Re){return Ee^ge^Re}function y(Ee,ge,Re){return ge^(Ee|~Re)}function A(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(g(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function w(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(p(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function R(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(T(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function b(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(y(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function G(Ee){let ge;const Re=Ee.length,we=Re+8,Ue=((we-we%64)/64+1)*16,fe=new Array(Ue-1);let ae=0,Se=0;for(;Se<Re;)ge=(Se-Se%4)/4,ae=Se%4*8,fe[ge]=fe[ge]|Ee.charCodeAt(Se)<<ae,Se++;return ge=(Se-Se%4)/4,ae=Se%4*8,fe[ge]=fe[ge]|128<<ae,fe[Ue-2]=Re<<3,fe[Ue-1]=Re>>>29,fe}function P(Ee){let ge="",Re="",we,Ue;for(Ue=0;Ue<=3;Ue++)we=Ee>>>Ue*8&255,Re=`0${we.toString(16)}`,ge=ge+Re.substr(Re.length-2,2);return ge}function ye(Ee){let ge="";for(let Re=0;Re<Ee.length;Re++){const we=Ee.charCodeAt(Re);we<128?ge+=String.fromCharCode(we):we>127&&we<2048?(ge+=String.fromCharCode(we>>6|192),ge+=String.fromCharCode(we&63|128)):(ge+=String.fromCharCode(we>>12|224),ge+=String.fromCharCode(we>>6&63|128),ge+=String.fromCharCode(we&63|128))}return ge}let O=[],j,pe,Te,N,H,$,q,M,W;const te=7,I=12,J=17,ne=22,Ye=5,ee=9,V=14,k=20,Ae=4,me=11,Ie=16,xe=23,_e=6,le=10,ze=15,rt=21;for(d=ye(d),O=G(d),$=1732584193,q=4023233417,M=2562383102,W=271733878,j=0;j<O.length;j+=16)pe=$,Te=q,N=M,H=W,$=A($,q,M,W,O[j+0],te,3614090360),W=A(W,$,q,M,O[j+1],I,3905402710),M=A(M,W,$,q,O[j+2],J,606105819),q=A(q,M,W,$,O[j+3],ne,3250441966),$=A($,q,M,W,O[j+4],te,4118548399),W=A(W,$,q,M,O[j+5],I,1200080426),M=A(M,W,$,q,O[j+6],J,2821735955),q=A(q,M,W,$,O[j+7],ne,4249261313),$=A($,q,M,W,O[j+8],te,1770035416),W=A(W,$,q,M,O[j+9],I,2336552879),M=A(M,W,$,q,O[j+10],J,4294925233),q=A(q,M,W,$,O[j+11],ne,2304563134),$=A($,q,M,W,O[j+12],te,1804603682),W=A(W,$,q,M,O[j+13],I,4254626195),M=A(M,W,$,q,O[j+14],J,2792965006),q=A(q,M,W,$,O[j+15],ne,1236535329),$=w($,q,M,W,O[j+1],Ye,4129170786),W=w(W,$,q,M,O[j+6],ee,3225465664),M=w(M,W,$,q,O[j+11],V,643717713),q=w(q,M,W,$,O[j+0],k,3921069994),$=w($,q,M,W,O[j+5],Ye,3593408605),W=w(W,$,q,M,O[j+10],ee,38016083),M=w(M,W,$,q,O[j+15],V,3634488961),q=w(q,M,W,$,O[j+4],k,3889429448),$=w($,q,M,W,O[j+9],Ye,568446438),W=w(W,$,q,M,O[j+14],ee,3275163606),M=w(M,W,$,q,O[j+3],V,4107603335),q=w(q,M,W,$,O[j+8],k,1163531501),$=w($,q,M,W,O[j+13],Ye,2850285829),W=w(W,$,q,M,O[j+2],ee,4243563512),M=w(M,W,$,q,O[j+7],V,1735328473),q=w(q,M,W,$,O[j+12],k,2368359562),$=R($,q,M,W,O[j+5],Ae,4294588738),W=R(W,$,q,M,O[j+8],me,2272392833),M=R(M,W,$,q,O[j+11],Ie,1839030562),q=R(q,M,W,$,O[j+14],xe,4259657740),$=R($,q,M,W,O[j+1],Ae,2763975236),W=R(W,$,q,M,O[j+4],me,1272893353),M=R(M,W,$,q,O[j+7],Ie,4139469664),q=R(q,M,W,$,O[j+10],xe,3200236656),$=R($,q,M,W,O[j+13],Ae,681279174),W=R(W,$,q,M,O[j+0],me,3936430074),M=R(M,W,$,q,O[j+3],Ie,3572445317),q=R(q,M,W,$,O[j+6],xe,76029189),$=R($,q,M,W,O[j+9],Ae,3654602809),W=R(W,$,q,M,O[j+12],me,3873151461),M=R(M,W,$,q,O[j+15],Ie,530742520),q=R(q,M,W,$,O[j+2],xe,3299628645),$=b($,q,M,W,O[j+0],_e,4096336452),W=b(W,$,q,M,O[j+7],le,1126891415),M=b(M,W,$,q,O[j+14],ze,2878612391),q=b(q,M,W,$,O[j+5],rt,4237533241),$=b($,q,M,W,O[j+12],_e,1700485571),W=b(W,$,q,M,O[j+3],le,2399980690),M=b(M,W,$,q,O[j+10],ze,4293915773),q=b(q,M,W,$,O[j+1],rt,2240044497),$=b($,q,M,W,O[j+8],_e,1873313359),W=b(W,$,q,M,O[j+15],le,4264355552),M=b(M,W,$,q,O[j+6],ze,2734768916),q=b(q,M,W,$,O[j+13],rt,1309151649),$=b($,q,M,W,O[j+4],_e,4149444226),W=b(W,$,q,M,O[j+11],le,3174756917),M=b(M,W,$,q,O[j+2],ze,718787259),q=b(q,M,W,$,O[j+9],rt,3951481745),$=u($,pe),q=u(q,Te),M=u(M,N),W=u(W,H);return(P($)+P(q)+P(M)+P(W)).toLowerCase()},nt.closeMediaStream=d=>{if(d)try{let _;if(d.getTracks){_=d.getTracks();for(const u of _)u.stop()}else{_=d.getAudioTracks();for(const u of _)u.stop();_=d.getVideoTracks();for(const u of _)u.stop()}}catch(_){(typeof d.stop=="function"||typeof d.stop=="object")&&d.stop()}},nt.cloneArray=d=>d&&d.slice()||[],nt.cloneObject=(d,_={})=>d&&Object.assign({},d)||_,nt}const Xh=Pt,yg=ht,Et=Ne,ut=yt(),Qh=Ma(),Eg=Xt(),Pa=new yg("SIPMessage");class pl{constructor(s,n,i,a,e,d){if(!s||!n||!i)return null;a=a||{},this.ua=i,this.headers={},this.method=s,this.ruri=n,this.body=d,this.extraHeaders=ut.cloneArray(e),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):i.configuration.use_preloaded_route&&this.setHeader("route",`<${i.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);const _=a.to_uri||n,u=a.to_tag?{tag:a.to_tag}:null,g=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new Qh(_,g,u),this.setHeader("to",this.to.toString());const p=a.from_uri||i.configuration.uri,T={tag:a.from_tag||ut.newTag()};let y;typeof a.from_display_name<"u"?y=a.from_display_name:i.configuration.display_name?y=i.configuration.display_name:y=null,this.from=new Qh(p,y,T),this.setHeader("from",this.from.toString());const A=a.call_id||i.configuration.jssip_id+ut.createRandomToken(15);this.call_id=A,this.setHeader("call-id",A);const w=a.cseq||Math.floor(Math.random()*1e4);this.cseq=w,this.setHeader("cseq",`${w} ${s}`)}setHeader(s,n){const i=new RegExp(`^\\s*${s}\\s*:`,"i");for(let a=0;a<this.extraHeaders.length;a++)i.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[ut.headerize(s)]=Array.isArray(n)?n:[n]}getHeader(s){const n=this.headers[ut.headerize(s)];if(n){if(n[0])return n[0]}else{const i=new RegExp(`^\\s*${s}\\s*:`,"i");for(const a of this.extraHeaders)if(i.test(a))return a.substring(a.indexOf(":")+1).trim()}}getHeaders(s){const n=this.headers[ut.headerize(s)],i=[];if(n){for(const a of n)i.push(a);return i}else{const a=new RegExp(`^\\s*${s}\\s*:`,"i");for(const e of this.extraHeaders)a.test(e)&&i.push(e.substring(e.indexOf(":")+1).trim());return i}}hasHeader(s){if(this.headers[ut.headerize(s)])return!0;{const n=new RegExp(`^\\s*${s}\\s*:`,"i");for(const i of this.extraHeaders)if(n.test(i))return!0}return!1}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=Xh.parse(this.body||""),this.sdp)}toString(){let s=`${this.method} ${this.ruri} SIP/2.0\r
76
- `;for(const a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a))for(const e of this.headers[a])s+=`${a}: ${e}\r
77
- `;for(const a of this.extraHeaders)s+=`${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 i=this.ua.configuration.user_agent||Et.USER_AGENT;if(s+=`Allow: ${Et.ALLOWED_METHODS}\r
79
- `,s+=`Supported: ${n}\r
80
- `,s+=`User-Agent: ${i}\r
81
- `,this.body){const a=ut.str_utf8_length(this.body);s+=`Content-Length: ${a}\r
74
+ `,e+=2):(t=null,u('"\\r\\n"')),t}function f(){var t;return/^[0-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[0-9]")),t}function T(){var t;return/^[a-zA-Z]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-zA-Z]")),t}function y(){var t;return/^[0-9a-fA-F]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[0-9a-fA-F]")),t}function A(){var t;return t=R(),t===null&&(t=G()),t}function w(){var t;return/^[\0-\xFF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function b(){var t;return/^["]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u('["]')),t}function R(){var t;return s.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function G(){var t;return s.charCodeAt(e)===9?(t=" ",e++):(t=null,u('"\\t"')),t}function x(){var t;return/^[a-zA-Z0-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-zA-Z0-9]")),t}function me(){var t;return s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","'))))))))))),t}function O(){var t;return t=x(),t===null&&(t=$()),t}function $(){var t;return s.charCodeAt(e)===45?(t="-",e++):(t=null,u('"-"')),t===null&&(s.charCodeAt(e)===95?(t="_",e++):(t=null,u('"_"')),t===null&&(s.charCodeAt(e)===46?(t=".",e++):(t=null,u('"."')),t===null&&(s.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(s.charCodeAt(e)===126?(t="~",e++):(t=null,u('"~"')),t===null&&(s.charCodeAt(e)===42?(t="*",e++):(t=null,u('"*"')),t===null&&(s.charCodeAt(e)===39?(t="'",e++):(t=null,u(`"'"`)),t===null&&(s.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(s.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')))))))))),t}function de(){var t,r,o,c,h;return c=e,h=e,s.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(o=y(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){return m.join("")}(c,t)),t===null&&(e=c),t}function fe(){var t,r,o,c,h,p;for(c=e,h=e,p=e,t=[],r=A();r!==null;)t.push(r),r=A();if(t!==null?(r=g(),r!==null?t=[t,r]:(t=null,e=p)):(t=null,e=p),t=t!==null?t:"",t!==null){if(o=A(),o!==null)for(r=[];o!==null;)r.push(o),o=A();else r=null;r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(m){return" "}()),t===null&&(e=c),t}function N(){var t;return t=fe(),t=t!==null?t:"",t}function H(){var t,r,o,c,h;for(c=e,h=e,t=[],r=R(),r===null&&(r=G());r!==null;)t.push(r),r=R(),r===null&&(r=G());return t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return":"}()),t===null&&(e=c),t}function j(){var t,r,o,c,h,p,m;if(h=e,p=e,r=F(),r!==null)for(t=[];r!==null;)t.push(r),r=F();else t=null;if(t!==null){for(r=[],m=e,o=[],c=fe();c!==null;)o.push(c),c=fe();for(o!==null?(c=F(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;){for(r.push(o),m=e,o=[],c=fe();c!==null;)o.push(c),c=fe();o!==null?(c=F(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m)}r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){return s.substring(e,E)}(h)),t===null&&(e=h),t}function F(){var t;return/^[!-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[!-~]")),t===null&&(t=P()),t}function P(){var t;return/^[\x80-\uFFFF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\x80-\\uFFFF]")),t}function W(){var t;return/^[\x80-\xBF]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\x80-\\xBF]")),t}function ee(){var t;return t=f(),t===null&&(/^[a-f]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[a-f]"))),t}function I(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function X(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function te(){var t;return s.charCodeAt(e)===40?(t="(",e++):(t=null,u('"("')),t===null&&(s.charCodeAt(e)===41?(t=")",e++):(t=null,u('")"')),t===null&&(s.charCodeAt(e)===60?(t="<",e++):(t=null,u('"<"')),t===null&&(s.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t===null&&(t=b(),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===123?(t="{",e++):(t=null,u('"{"')),t===null&&(s.charCodeAt(e)===125?(t="}",e++):(t=null,u('"}"')),t===null&&(t=R(),t===null&&(t=G())))))))))))))))))),t}function Ke(){var t,r,o;if(o=e,r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(s.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=b(),r===null&&(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(s.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(s.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(s.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(s.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"'))))))))))))))))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=x(),r===null&&(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r===null&&(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r===null&&(s.charCodeAt(e)===33?(r="!",e++):(r=null,u('"!"')),r===null&&(s.charCodeAt(e)===37?(r="%",e++):(r=null,u('"%"')),r===null&&(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r===null&&(s.charCodeAt(e)===95?(r="_",e++):(r=null,u('"_"')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===96?(r="`",e++):(r=null,u('"`"')),r===null&&(s.charCodeAt(e)===39?(r="'",e++):(r=null,u(`"'"`)),r===null&&(s.charCodeAt(e)===126?(r="~",e++):(r=null,u('"~"')),r===null&&(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r===null&&(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r===null&&(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r===null&&(s.charCodeAt(e)===62?(r=">",e++):(r=null,u('">"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===92?(r="\\",e++):(r=null,u('"\\\\"')),r===null&&(r=b(),r===null&&(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r===null&&(s.charCodeAt(e)===91?(r="[",e++):(r=null,u('"["')),r===null&&(s.charCodeAt(e)===93?(r="]",e++):(r=null,u('"]"')),r===null&&(s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r===null&&(s.charCodeAt(e)===123?(r="{",e++):(r=null,u('"{"')),r===null&&(s.charCodeAt(e)===125?(r="}",e++):(r=null,u('"}"')))))))))))))))))))))))));else t=null;return t!==null&&(t=function(c){return s.substring(e,c)}(o)),t===null&&(e=o),t}function Q(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"*"}()),t===null&&(e=c),t}function V(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"/"}()),t===null&&(e=c),t}function k(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"="}()),t===null&&(e=c),t}function ve(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return"("}()),t===null&&(e=c),t}function _e(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return")"}()),t===null&&(e=c),t}function Ae(){var t,r,o,c;return o=e,c=e,s.charCodeAt(e)===62?(t=">",e++):(t=null,u('">"')),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return">"}()),t===null&&(e=o),t}function Ue(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(s.charCodeAt(e)===60?(r="<",e++):(r=null,u('"<"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return"<"}()),t===null&&(e=o),t}function ce(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return","}()),t===null&&(e=c),t}function re(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return";"}()),t===null&&(e=c),t}function Ge(){var t,r,o,c,h;return c=e,h=e,t=N(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=N(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return":"}()),t===null&&(e=c),t}function tt(){var t,r,o,c;return o=e,c=e,t=N(),t!==null?(r=b(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function ge(){var t,r,o,c;return o=e,c=e,t=b(),t!==null?(r=N(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=o),t}function pe(){var t,r,o,c;if(c=e,t=ve(),t!==null){for(r=[],o=Se(),o===null&&(o=ie(),o===null&&(o=pe()));o!==null;)r.push(o),o=Se(),o===null&&(o=ie(),o===null&&(o=pe()));r!==null?(o=_e(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)}else t=null,e=c;return t}function Se(){var t;return/^[!-']/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[!-']")),t===null&&(/^[*-[]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[*-[]")),t===null&&(/^[\]-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=P(),t===null&&(t=fe())))),t}function be(){var t,r,o,c,h,p;if(h=e,p=e,t=N(),t!==null)if(r=b(),r!==null){for(o=[],c=he(),c===null&&(c=ie());c!==null;)o.push(c),c=he(),c===null&&(c=ie());o!==null?(c=b(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m){return s.substring(e,m)}(h)),t===null&&(e=h),t}function De(){var t,r,o,c,h,p;if(h=e,p=e,t=N(),t!==null)if(r=b(),r!==null){for(o=[],c=he(),c===null&&(c=ie());c!==null;)o.push(c),c=he(),c===null&&(c=ie());o!==null?(c=b(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m){var E=s.substring(e,m).trim();return E.substring(1,E.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(h)),t===null&&(e=h),t}function he(){var t;return t=fe(),t===null&&(s.charCodeAt(e)===33?(t="!",e++):(t=null,u('"!"')),t===null&&(/^[#-[]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[#-[]")),t===null&&(/^[\]-~]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[\\]-~]")),t===null&&(t=P())))),t}function ie(){var t,r,o;return o=e,s.charCodeAt(e)===92?(t="\\",e++):(t=null,u('"\\\\"')),t!==null?(/^[\0-\t]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\0-\\t]")),r===null&&(/^[\x0B-\f]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\x0B-\\f]")),r===null&&(/^[\x0E-]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[\\x0E-]")))),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Te(){var t,r,o,c,h,p;return h=e,p=e,t=$e(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Pt(),o=o!==null?o:"",o!==null?(c=bn(),c!==null?t=[t,r,o,c]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t!==null&&(t=function(m){try{v.uri=new yo(v.scheme,v.user,v.host,v.port),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port}catch{v=-1}}()),t===null&&(e=h),t}function we(){var t,r,o,c,h,p,m,E;return m=e,E=e,t=$e(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Pt(),o=o!==null?o:"",o!==null?(c=bn(),c!==null?(h=qr(),h!==null?(p=Jr(),p=p!==null?p:"",p!==null?t=[t,r,o,c,h,p]:(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E)):(t=null,e=E),t!==null&&(t=function(C){try{v.uri=new yo(v.scheme,v.user,v.host,v.port,v.uri_params,v.uri_headers),delete v.scheme,delete v.user,delete v.host,delete v.host_type,delete v.port,delete v.uri_params,i==="SIP_URI"&&(v=v.uri)}catch{v=-1}}()),t===null&&(e=m),t}function $e(){var t;return t=it(),t===null&&(t=xe()),t}function it(){var t,r;return r=e,s.substr(e,4).toLowerCase()==="sips"?(t=s.substr(e,4),e+=4):(t=null,u('"sips"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function xe(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"sip"')),t!==null&&(t=function(o,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Pt(){var t,r,o,c,h,p;return c=e,h=e,t=wt(),t!==null?(p=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=xr(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?(s.charCodeAt(e)===64?(o="@",e++):(o=null,u('"@"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.user=decodeURIComponent(s.substring(e-1,m))}(c)),t===null&&(e=c),t}function wt(){var t,r;if(r=O(),r===null&&(r=de(),r===null&&(r=cs())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(r=cs()));else t=null;return t}function cs(){var t;return s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"'))))))))),t}function xr(){var t,r,o;for(o=e,t=[],r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","'))))))));return t!==null&&(t=function(c){v.password=s.substring(e,c)}(o)),t===null&&(e=o),t}function bn(){var t,r,o,c,h;return c=e,t=Jt(),t!==null?(h=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=Hr(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function Jt(){var t,r;return r=e,t=hs(),t===null&&(t=Xt(),t===null&&(t=_s())),t!==null&&(t=function(o){return v.host=s.substring(e,o).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function hs(){var t,r,o,c,h,p;for(c=e,h=e,t=[],p=e,r=ds(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p);r!==null;)t.push(r),p=e,r=ds(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p);return t!==null?(r=Lr(),r!==null?(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){return v.host_type="domain",s.substring(e,m)}(c)),t===null&&(e=c),t}function ds(){var t,r,o,c;if(c=e,t=x(),t!==null){for(r=[],o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Lr(){var t,r,o,c;if(c=e,t=T(),t!==null){for(r=[],o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));o!==null;)r.push(o),o=x(),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===95?(o="_",e++):(o=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function _s(){var t,r,o,c,h;return c=e,h=e,s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=ps(),r!==null?(s.charCodeAt(e)===93?(o="]",e++):(o=null,u('"]"')),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p){return v.host_type="IPv6",s.substring(e,p)}(c)),t===null&&(e=c),t}function ps(){var t,r,o,c,h,p,m,E,C,ne,Ee,at,qn,Us,S,L;return Us=e,S=e,t=M(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?(s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=M(),C!==null?(s.charCodeAt(e)===58?(ne=":",e++):(ne=null,u('":"')),ne!==null?(Ee=M(),Ee!==null?(s.charCodeAt(e)===58?(at=":",e++):(at=null,u('":"')),at!==null?(qn=Le(),qn!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee,at,qn]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=M(),ne!==null?(s.charCodeAt(e)===58?(Ee=":",e++):(Ee=null,u('":"')),Ee!==null?(at=Le(),at!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee,at]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=Le(),ne!==null?t=[t,r,o,c,h,p,m,E,C,ne]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=Le(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=Le(),p!==null?t=[t,r,o,c,h,p]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?(s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=Le(),c!==null?t=[t,r,o,c]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=Le(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,s.substr(e,2)==="::"?(t="::",e+=2):(t=null,u('"::"')),t!==null?(r=M(),r!==null?t=[t,r]:(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(s.substr(e,2)==="::"?(r="::",e+=2):(r=null,u('"::"')),r!==null?(o=M(),o!==null?(s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=M(),C!==null?(s.charCodeAt(e)===58?(ne=":",e++):(ne=null,u('":"')),ne!==null?(Ee=Le(),Ee!==null?t=[t,r,o,c,h,p,m,E,C,ne,Ee]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(s.substr(e,2)==="::"?(o="::",e+=2):(o=null,u('"::"')),o!==null?(c=M(),c!==null?(s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?(s.charCodeAt(e)===58?(C=":",e++):(C=null,u('":"')),C!==null?(ne=Le(),ne!==null?t=[t,r,o,c,h,p,m,E,C,ne]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(s.substr(e,2)==="::"?(c="::",e+=2):(c=null,u('"::"')),c!==null?(h=M(),h!==null?(s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?(s.charCodeAt(e)===58?(E=":",e++):(E=null,u('":"')),E!==null?(C=Le(),C!==null?t=[t,r,o,c,h,p,m,E,C]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(s.substr(e,2)==="::"?(h="::",e+=2):(h=null,u('"::"')),h!==null?(p=M(),p!==null?(s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=Le(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(s.substr(e,2)==="::"?(p="::",e+=2):(p=null,u('"::"')),p!==null?(m=Le(),m!==null?t=[t,r,o,c,h,p,m]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?p=[p,m]:(p=null,e=L)):(p=null,e=L),p=p!==null?p:"",p!==null?(s.substr(e,2)==="::"?(m="::",e+=2):(m=null,u('"::"')),m!==null?(E=M(),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S),t===null&&(S=e,t=M(),t!==null?(L=e,s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?r=[r,o]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,s.charCodeAt(e)===58?(o=":",e++):(o=null,u('":"')),o!==null?(c=M(),c!==null?o=[o,c]:(o=null,e=L)):(o=null,e=L),o=o!==null?o:"",o!==null?(L=e,s.charCodeAt(e)===58?(c=":",e++):(c=null,u('":"')),c!==null?(h=M(),h!==null?c=[c,h]:(c=null,e=L)):(c=null,e=L),c=c!==null?c:"",c!==null?(L=e,s.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(p=M(),p!==null?h=[h,p]:(h=null,e=L)):(h=null,e=L),h=h!==null?h:"",h!==null?(L=e,s.charCodeAt(e)===58?(p=":",e++):(p=null,u('":"')),p!==null?(m=M(),m!==null?p=[p,m]:(p=null,e=L)):(p=null,e=L),p=p!==null?p:"",p!==null?(L=e,s.charCodeAt(e)===58?(m=":",e++):(m=null,u('":"')),m!==null?(E=M(),E!==null?m=[m,E]:(m=null,e=L)):(m=null,e=L),m=m!==null?m:"",m!==null?(s.substr(e,2)==="::"?(E="::",e+=2):(E=null,u('"::"')),E!==null?t=[t,r,o,c,h,p,m,E]:(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S)):(t=null,e=S))))))))))))))),t!==null&&(t=function(rc){return v.host_type="IPv6",s.substring(e,rc)}(Us)),t===null&&(e=Us),t}function M(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(o=y(),o=o!==null?o:"",o!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Le(){var t,r,o,c;return c=e,t=M(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=M(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=Xt()),t}function Xt(){var t,r,o,c,h,p,m,E,C;return E=e,C=e,t=Qt(),t!==null?(s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=Qt(),o!==null?(s.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null?(h=Qt(),h!==null?(s.charCodeAt(e)===46?(p=".",e++):(p=null,u('"."')),p!==null?(m=Qt(),m!==null?t=[t,r,o,c,h,p,m]:(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C)):(t=null,e=C),t!==null&&(t=function(ne){return v.host_type="IPv4",s.substring(e,ne)}(E)),t===null&&(e=E),t}function Qt(){var t,r,o,c;return c=e,s.substr(e,2)==="25"?(t="25",e+=2):(t=null,u('"25"')),t!==null?(/^[0-5]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[0-5]")),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(c=e,s.charCodeAt(e)===50?(t="2",e++):(t=null,u('"2"')),t!==null?(/^[0-4]/.test(s.charAt(e))?(r=s.charAt(e),e++):(r=null,u("[0-4]")),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,s.charCodeAt(e)===49?(t="1",e++):(t=null,u('"1"')),t!==null?(r=f(),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(c=e,/^[1-9]/.test(s.charAt(e))?(t=s.charAt(e),e++):(t=null,u("[1-9]")),t!==null?(r=f(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t===null&&(t=f())))),t}function Hr(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){return C=parseInt(C.join("")),v.port=C,C}(p,t)),t===null&&(e=p),t}function qr(){var t,r,o,c;for(t=[],c=e,s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=fs(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);r!==null;)t.push(r),c=e,s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(o=fs(),o!==null?r=[r,o]:(r=null,e=c)):(r=null,e=c);return t}function fs(){var t;return t=Fr(),t===null&&(t=jr(),t===null&&(t=$r(),t===null&&(t=Vr(),t===null&&(t=Br(),t===null&&(t=Kr(),t===null&&(t=Gr())))))),t}function Fr(){var t,r,o,c;return o=e,c=e,s.substr(e,10).toLowerCase()==="transport="?(t=s.substr(e,10),e+=10):(t=null,u('"transport="')),t!==null?(s.substr(e,3).toLowerCase()==="udp"?(r=s.substr(e,3),e+=3):(r=null,u('"udp"')),r===null&&(s.substr(e,3).toLowerCase()==="tcp"?(r=s.substr(e,3),e+=3):(r=null,u('"tcp"')),r===null&&(s.substr(e,4).toLowerCase()==="sctp"?(r=s.substr(e,4),e+=4):(r=null,u('"sctp"')),r===null&&(s.substr(e,3).toLowerCase()==="tls"?(r=s.substr(e,3),e+=3):(r=null,u('"tls"')),r===null&&(r=I())))),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.transport=p.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function jr(){var t,r,o,c;return o=e,c=e,s.substr(e,5).toLowerCase()==="user="?(t=s.substr(e,5),e+=5):(t=null,u('"user="')),t!==null?(s.substr(e,5).toLowerCase()==="phone"?(r=s.substr(e,5),e+=5):(r=null,u('"phone"')),r===null&&(s.substr(e,2).toLowerCase()==="ip"?(r=s.substr(e,2),e+=2):(r=null,u('"ip"')),r===null&&(r=I())),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.user=p.toLowerCase()}(o,t[1])),t===null&&(e=o),t}function $r(){var t,r,o,c;return o=e,c=e,s.substr(e,7).toLowerCase()==="method="?(t=s.substr(e,7),e+=7):(t=null,u('"method="')),t!==null?(r=On(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.method=p}(o,t[1])),t===null&&(e=o),t}function Vr(){var t,r,o,c;return o=e,c=e,s.substr(e,4).toLowerCase()==="ttl="?(t=s.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=Os(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.params||(v.params={}),v.params.ttl=p}(o,t[1])),t===null&&(e=o),t}function Br(){var t,r,o,c;return o=e,c=e,s.substr(e,6).toLowerCase()==="maddr="?(t=s.substr(e,6),e+=6):(t=null,u('"maddr="')),t!==null?(r=Jt(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h,p){v.uri_params||(v.uri_params={}),v.uri_params.maddr=p}(o,t[1])),t===null&&(e=o),t}function Kr(){var t,r,o,c,h,p;return c=e,h=e,s.substr(e,2).toLowerCase()==="lr"?(t=s.substr(e,2),e+=2):(t=null,u('"lr"')),t!==null?(p=e,s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=I(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.uri_params||(v.uri_params={}),v.uri_params.lr=void 0}()),t===null&&(e=c),t}function Gr(){var t,r,o,c,h,p;return c=e,h=e,t=Wr(),t!==null?(p=e,s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=Yr(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.uri_params||(v.uri_params={}),typeof C>"u"?C=void 0:C=C[1],v.uri_params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Wr(){var t,r,o;if(o=e,r=Zt(),r!==null)for(t=[];r!==null;)t.push(r),r=Zt();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function Yr(){var t,r,o;if(o=e,r=Zt(),r!==null)for(t=[];r!==null;)t.push(r),r=Zt();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(o,t)),t===null&&(e=o),t}function Zt(){var t;return t=zr(),t===null&&(t=O(),t===null&&(t=de())),t}function zr(){var t;return s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Jr(){var t,r,o,c,h,p,m;if(p=e,s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Rn(),r!==null){for(o=[],m=e,s.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Rn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);c!==null;)o.push(c),m=e,s.charCodeAt(e)===38?(c="&",e++):(c=null,u('"&"')),c!==null?(h=Rn(),h!==null?c=[c,h]:(c=null,e=m)):(c=null,e=m);o!==null?t=[t,r,o]:(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t}function Rn(){var t,r,o,c,h;return c=e,h=e,t=Xr(),t!==null?(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(o=Qr(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m,E){m=m.join("").toLowerCase(),E=E.join(""),v.uri_headers||(v.uri_headers={}),v.uri_headers[m]?v.uri_headers[m].push(E):v.uri_headers[m]=[E]}(c,t[0],t[2])),t===null&&(e=c),t}function Xr(){var t,r;if(r=en(),r===null&&(r=O(),r===null&&(r=de())),r!==null)for(t=[];r!==null;)t.push(r),r=en(),r===null&&(r=O(),r===null&&(r=de()));else t=null;return t}function Qr(){var t,r;for(t=[],r=en(),r===null&&(r=O(),r===null&&(r=de()));r!==null;)t.push(r),r=en(),r===null&&(r=O(),r===null&&(r=de()));return t}function en(){var t;return s.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t===null&&(s.charCodeAt(e)===93?(t="]",e++):(t=null,u('"]"')),t===null&&(s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')))))))),t}function Eu(){var t;return t=yi(),t===null&&(t=Zr()),t}function Zr(){var t,r,o,c,h,p;return p=e,t=On(),t!==null?(r=R(),r!==null?(o=ei(),o!==null?(c=R(),c!==null?(h=Ts(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function ei(){var t;return t=we(),t===null&&(t=ms()),t}function ms(){var t,r,o,c;return c=e,t=oi(),t!==null?(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(o=ti(),o===null&&(o=si()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ti(){var t,r,o,c,h;return c=e,t=ni(),t===null&&(t=In()),t!==null?(h=e,s.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(o=ci(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function ni(){var t,r,o,c;return c=e,s.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=li(),r!==null?(o=In(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function In(){var t,r,o;return o=e,s.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=ii(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function si(){var t,r,o,c;if(c=e,t=ri(),t!==null){for(r=[],o=tn();o!==null;)r.push(o),o=tn();r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function tn(){var t;return t=me(),t===null&&(t=O(),t===null&&(t=de())),t}function ri(){var t;return t=O(),t===null&&(t=de(),t===null&&(s.charCodeAt(e)===59?(t=";",e++):(t=null,u('";"')),t===null&&(s.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))))),t}function ii(){var t,r,o,c,h,p;if(h=e,t=wn(),t!==null){for(r=[],p=e,s.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=wn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===47?(o="/",e++):(o=null,u('"/"')),o!==null?(c=wn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function wn(){var t,r,o,c,h,p;for(h=e,t=[],r=nn();r!==null;)t.push(r),r=nn();if(t!==null){for(r=[],p=e,s.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=gs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===59?(o=";",e++):(o=null,u('";"')),o!==null?(c=gs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function gs(){var t,r;for(t=[],r=nn();r!==null;)t.push(r),r=nn();return t}function nn(){var t;return t=O(),t===null&&(t=de(),t===null&&(s.charCodeAt(e)===58?(t=":",e++):(t=null,u('":"')),t===null&&(s.charCodeAt(e)===64?(t="@",e++):(t=null,u('"@"')),t===null&&(s.charCodeAt(e)===38?(t="&",e++):(t=null,u('"&"')),t===null&&(s.charCodeAt(e)===61?(t="=",e++):(t=null,u('"="')),t===null&&(s.charCodeAt(e)===43?(t="+",e++):(t=null,u('"+"')),t===null&&(s.charCodeAt(e)===36?(t="$",e++):(t=null,u('"$"')),t===null&&(s.charCodeAt(e)===44?(t=",",e++):(t=null,u('","')))))))))),t}function oi(){var t,r,o,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],o=T(),o===null&&(o=f(),o===null&&(s.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));o!==null;)r.push(o),o=T(),o===null&&(o=f(),o===null&&(s.charCodeAt(e)===43?(o="+",e++):(o=null,u('"+"')),o===null&&(s.charCodeAt(e)===45?(o="-",e++):(o=null,u('"-"')),o===null&&(s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."'))))));r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t!==null&&(t=function(p){v.scheme=s.substring(e,p)}(c)),t===null&&(e=c),t}function li(){var t;return t=ai(),t===null&&(t=ui()),t}function ai(){var t,r,o,c;return o=e,c=e,t=Pt(),t!==null?(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t=t!==null?t:"",t!==null?(r=bn(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t=t!==null?t:"",t}function ui(){var t,r;if(r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"'))))))))))),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=de(),r===null&&(s.charCodeAt(e)===36?(r="$",e++):(r=null,u('"$"')),r===null&&(s.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r===null&&(s.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r===null&&(s.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r===null&&(s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r===null&&(s.charCodeAt(e)===38?(r="&",e++):(r=null,u('"&"')),r===null&&(s.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r===null&&(s.charCodeAt(e)===43?(r="+",e++):(r=null,u('"+"')))))))))));else t=null;return t}function ci(){var t,r;for(t=[],r=tn();r!==null;)t.push(r),r=tn();return t}function Ts(){var t,r,o,c,h,p,m,E;if(m=e,E=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t!==null)if(s.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null){if(c=f(),c!==null)for(o=[];c!==null;)o.push(c),c=f();else o=null;if(o!==null)if(s.charCodeAt(e)===46?(c=".",e++):(c=null,u('"."')),c!==null){if(p=f(),p!==null)for(h=[];p!==null;)h.push(p),p=f();else h=null;h!==null?t=[t,r,o,c,h]:(t=null,e=E)}else t=null,e=E;else t=null,e=E}else t=null,e=E;else t=null,e=E;return t!==null&&(t=function(C){v.sip_version=s.substring(e,C)}(m)),t===null&&(e=m),t}function hi(){var t;return s.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function di(){var t;return s.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function _i(){var t;return s.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function pi(){var t;return s.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function fi(){var t;return s.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function mi(){var t;return s.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function gi(){var t;return s.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function Ti(){var t;return s.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function vi(){var t;return s.substr(e,5)==="REFER"?(t="REFER",e+=5):(t=null,u('"REFER"')),t}function On(){var t,r;return r=e,t=hi(),t===null&&(t=di(),t===null&&(t=_i(),t===null&&(t=pi(),t===null&&(t=fi(),t===null&&(t=mi(),t===null&&(t=gi(),t===null&&(t=Ti(),t===null&&(t=vi(),t===null&&(t=I()))))))))),t!==null&&(t=function(o){return v.method=s.substring(e,o),v.method}(r)),t===null&&(e=r),t}function yi(){var t,r,o,c,h,p;return p=e,t=Ts(),t!==null?(r=R(),r!==null?(o=Ei(),o!==null?(c=R(),c!==null?(h=Ai(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function Ei(){var t,r;return r=e,t=Si(),t!==null&&(t=function(o,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Si(){var t,r,o,c;return c=e,t=f(),t!==null?(r=f(),r!==null?(o=f(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ai(){var t,r,o;for(o=e,t=[],r=me(),r===null&&(r=O(),r===null&&(r=de(),r===null&&(r=P(),r===null&&(r=W(),r===null&&(r=R(),r===null&&(r=G()))))));r!==null;)t.push(r),r=me(),r===null&&(r=O(),r===null&&(r=de(),r===null&&(r=P(),r===null&&(r=W(),r===null&&(r=R(),r===null&&(r=G()))))));return t!==null&&(t=function(c){v.reason_phrase=s.substring(e,c)}(o)),t===null&&(e=o),t}function Su(){var t,r,o,c,h,p;if(h=e,t=sn(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=sn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=sn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Au(){var t,r,o,c,h,p;return c=e,h=e,t=Ke(),t!==null?(p=e,s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ke(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v=s.substring(e,m)}(c)),t===null&&(e=c),t}function Cu(){var t,r,o,c,h,p,m;if(h=e,t=Q(),t===null)if(p=e,t=Nn(),t!==null){for(r=[],m=e,o=ce(),o!==null?(c=Nn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=ce(),o!==null?(c=Nn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C,ne;for(ne=v.multi_header.length,C=0;C<ne;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function Nn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=vs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=vs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Ht(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch{C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Ot(){var t,r,o,c,h;return h=e,t=Dn(),t=t!==null?t:"",t!==null?(r=Ue(),r!==null?(o=we(),o!==null?(c=Ae(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Dn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=I(),t!==null){for(r=[],m=e,o=fe(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=fe(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t===null&&(t=De()),t!==null&&(t=function(E,C){typeof C=="string"?v.display_name=C:v.display_name=C[1].reduce(function(ne,Ee){return ne+Ee[0]+Ee[1]},C[0])}(h,t)),t===null&&(e=h),t}function vs(){var t;return t=Ci(),t===null&&(t=bi(),t===null&&(t=Re())),t}function Ci(){var t,r,o,c,h;return c=e,h=e,s.substr(e,1).toLowerCase()==="q"?(t=s.substr(e,1),e++):(t=null,u('"q"')),t!==null?(r=k(),r!==null?(o=Ri(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.params||(v.params={}),v.params.q=m}(c,t[2])),t===null&&(e=c),t}function bi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,7).toLowerCase()==="expires"?(t=s.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.params||(v.params={}),v.params.expires=m}(c,t[2])),t===null&&(e=c),t}function Nt(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){return parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Ri(){var t,r,o,c,h,p,m,E;return p=e,m=e,s.charCodeAt(e)===48?(t="0",e++):(t=null,u('"0"')),t!==null?(E=e,s.charCodeAt(e)===46?(r=".",e++):(r=null,u('"."')),r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?r=[r,o,c,h]:(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(C){return parseFloat(s.substring(e,C))}(p)),t===null&&(e=p),t}function Re(){var t,r,o,c,h,p;return c=e,h=e,t=I(),t!==null?(p=e,r=k(),r!==null?(o=Ii(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m,E,C){v.params||(v.params={}),typeof C>"u"?C=void 0:C=C[1],v.params[E.toLowerCase()]=C}(c,t[0],t[1])),t===null&&(e=c),t}function Ii(){var t;return t=I(),t===null&&(t=Jt(),t===null&&(t=be())),t}function bu(){var t,r,o,c,h,p;if(h=e,t=wi(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=ys(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=ys(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function wi(){var t;return s.substr(e,6).toLowerCase()==="render"?(t=s.substr(e,6),e+=6):(t=null,u('"render"')),t===null&&(s.substr(e,7).toLowerCase()==="session"?(t=s.substr(e,7),e+=7):(t=null,u('"session"')),t===null&&(s.substr(e,4).toLowerCase()==="icon"?(t=s.substr(e,4),e+=4):(t=null,u('"icon"')),t===null&&(s.substr(e,5).toLowerCase()==="alert"?(t=s.substr(e,5),e+=5):(t=null,u('"alert"')),t===null&&(t=I())))),t}function ys(){var t;return t=Oi(),t===null&&(t=Re()),t}function Oi(){var t,r,o,c;return c=e,s.substr(e,8).toLowerCase()==="handling"?(t=s.substr(e,8),e+=8):(t=null,u('"handling"')),t!==null?(r=k(),r!==null?(s.substr(e,8).toLowerCase()==="optional"?(o=s.substr(e,8),e+=8):(o=null,u('"optional"')),o===null&&(s.substr(e,8).toLowerCase()==="required"?(o=s.substr(e,8),e+=8):(o=null,u('"required"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ru(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Iu(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function wu(){var t,r;return r=e,t=Ni(),t!==null&&(t=function(o){v=s.substring(e,o)}(r)),t===null&&(e=r),t}function Ni(){var t,r,o,c,h,p,m,E;if(m=e,t=Di(),t!==null)if(r=V(),r!==null)if(o=Pi(),o!==null){for(c=[],E=e,h=re(),h!==null?(p=Es(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=re(),h!==null?(p=Es(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Di(){var t;return t=ki(),t===null&&(t=Ui()),t}function ki(){var t;return s.substr(e,4).toLowerCase()==="text"?(t=s.substr(e,4),e+=4):(t=null,u('"text"')),t===null&&(s.substr(e,5).toLowerCase()==="image"?(t=s.substr(e,5),e+=5):(t=null,u('"image"')),t===null&&(s.substr(e,5).toLowerCase()==="audio"?(t=s.substr(e,5),e+=5):(t=null,u('"audio"')),t===null&&(s.substr(e,5).toLowerCase()==="video"?(t=s.substr(e,5),e+=5):(t=null,u('"video"')),t===null&&(s.substr(e,11).toLowerCase()==="application"?(t=s.substr(e,11),e+=11):(t=null,u('"application"')),t===null&&(t=kn()))))),t}function Ui(){var t;return s.substr(e,7).toLowerCase()==="message"?(t=s.substr(e,7),e+=7):(t=null,u('"message"')),t===null&&(s.substr(e,9).toLowerCase()==="multipart"?(t=s.substr(e,9),e+=9):(t=null,u('"multipart"')),t===null&&(t=kn())),t}function kn(){var t;return t=I(),t===null&&(t=Mi()),t}function Mi(){var t,r,o;return o=e,s.substr(e,2).toLowerCase()==="x-"?(t=s.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function Pi(){var t;return t=kn(),t===null&&(t=I()),t}function Es(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=xi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function xi(){var t;return t=I(),t===null&&(t=be()),t}function Ou(){var t,r,o,c;return c=e,t=Li(),t!==null?(r=fe(),r!==null?(o=On(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Li(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v.value=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Nu(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Du(){var t,r,o,c,h,p,m;if(h=e,p=e,t=sn(),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E,C){v.event=C.join("").toLowerCase()}(h,t[0])),t===null&&(e=h),t}function sn(){var t,r,o,c,h,p;if(h=e,t=X(),t!==null){for(r=[],p=e,s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=X(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,s.charCodeAt(e)===46?(o=".",e++):(o=null,u('"."')),o!==null?(c=X(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ku(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Ss(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C=v.tag;try{v=new Ht(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch{v=-1}}()),t===null&&(e=h),t}function Ss(){var t;return t=As(),t===null&&(t=Re()),t}function As(){var t,r,o,c,h;return c=e,h=e,s.substr(e,3).toLowerCase()==="tag"?(t=s.substr(e,3),e+=3):(t=null,u('"tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.tag=m}(c,t[2])),t===null&&(e=c),t}function Uu(){var t,r,o;if(o=e,r=f(),r!==null)for(t=[];r!==null;)t.push(r),r=f();else t=null;return t!==null&&(t=function(c,h){v=parseInt(h.join(""))}(o,t)),t===null&&(e=o),t}function Mu(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v=c}(r,t)),t===null&&(e=r),t}function Pu(){var t,r,o,c,h,p,m,E,C,ne;for(E=e,C=e,t=[],r=Dn();r!==null;)t.push(r),r=Dn();if(t!==null)if(r=Ue(),r!==null)if(o=we(),o!==null)if(c=Ae(),c!==null){for(h=[],ne=e,p=re(),p!==null?(m=Re(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);p!==null;)h.push(p),ne=e,p=re(),p!==null?(m=Re(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);h!==null?t=[t,r,o,c,h]:(t=null,e=C)}else t=null,e=C;else t=null,e=C;else t=null,e=C;else t=null,e=C;return t!==null&&(t=function(Ee){try{v=new Ht(v.uri,v.display_name,v.params)}catch{v=-1}}()),t===null&&(e=E),t}function xu(){var t;return t=Cs(),t}function Cs(){var t,r,o,c,h,p,m,E;if(m=e,s.substr(e,6).toLowerCase()==="digest"?(t=s.substr(e,6),e+=6):(t=null,u('"Digest"')),t!==null)if(r=fe(),r!==null)if(o=Un(),o!==null){for(c=[],E=e,h=ce(),h!==null?(p=Un(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=ce(),h!==null?(p=Un(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Hi()),t}function Hi(){var t,r,o,c,h,p,m,E;if(m=e,t=I(),t!==null)if(r=fe(),r!==null)if(o=rn(),o!==null){for(c=[],E=e,h=ce(),h!==null?(p=rn(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=ce(),h!==null?(p=rn(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function rn(){var t,r,o,c;return c=e,t=I(),t!==null?(r=k(),r!==null?(o=I(),o===null&&(o=be()),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Un(){var t;return t=qi(),t===null&&(t=ji(),t===null&&(t=$i(),t===null&&(t=Bi(),t===null&&(t=Ki(),t===null&&(t=Gi(),t===null&&(t=Wi(),t===null&&(t=rn()))))))),t}function qi(){var t,r,o,c;return c=e,s.substr(e,5).toLowerCase()==="realm"?(t=s.substr(e,5),e+=5):(t=null,u('"realm"')),t!==null?(r=k(),r!==null?(o=Fi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Fi(){var t,r;return r=e,t=De(),t!==null&&(t=function(o,c){v.realm=c}(r,t)),t===null&&(e=r),t}function ji(){var t,r,o,c,h,p,m,E,C;if(E=e,s.substr(e,6).toLowerCase()==="domain"?(t=s.substr(e,6),e+=6):(t=null,u('"domain"')),t!==null)if(r=k(),r!==null)if(o=tt(),o!==null)if(c=Mn(),c!==null){if(h=[],C=e,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;for(p!==null?(m=Mn(),m!==null?p=[p,m]:(p=null,e=C)):(p=null,e=C);p!==null;){if(h.push(p),C=e,m=R(),m!==null)for(p=[];m!==null;)p.push(m),m=R();else p=null;p!==null?(m=Mn(),m!==null?p=[p,m]:(p=null,e=C)):(p=null,e=C)}h!==null?(p=ge(),p!==null?t=[t,r,o,c,h,p]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Mn(){var t;return t=ms(),t===null&&(t=In()),t}function $i(){var t,r,o,c;return c=e,s.substr(e,5).toLowerCase()==="nonce"?(t=s.substr(e,5),e+=5):(t=null,u('"nonce"')),t!==null?(r=k(),r!==null?(o=Vi(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Vi(){var t,r;return r=e,t=De(),t!==null&&(t=function(o,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Bi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="opaque"?(t=s.substr(e,6),e+=6):(t=null,u('"opaque"')),t!==null?(r=k(),r!==null?(o=De(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.opaque=m}(c,t[2])),t===null&&(e=c),t}function Ki(){var t,r,o,c,h;return c=e,s.substr(e,5).toLowerCase()==="stale"?(t=s.substr(e,5),e+=5):(t=null,u('"stale"')),t!==null?(r=k(),r!==null?(h=e,s.substr(e,4).toLowerCase()==="true"?(o=s.substr(e,4),e+=4):(o=null,u('"true"')),o!==null&&(o=function(p){v.stale=!0}()),o===null&&(e=h),o===null&&(h=e,s.substr(e,5).toLowerCase()==="false"?(o=s.substr(e,5),e+=5):(o=null,u('"false"')),o!==null&&(o=function(p){v.stale=!1}()),o===null&&(e=h)),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Gi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,9).toLowerCase()==="algorithm"?(t=s.substr(e,9),e+=9):(t=null,u('"algorithm"')),t!==null?(r=k(),r!==null?(s.substr(e,3).toLowerCase()==="md5"?(o=s.substr(e,3),e+=3):(o=null,u('"MD5"')),o===null&&(s.substr(e,8).toLowerCase()==="md5-sess"?(o=s.substr(e,8),e+=8):(o=null,u('"MD5-sess"')),o===null&&(o=I())),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.algorithm=m.toUpperCase()}(c,t[2])),t===null&&(e=c),t}function Wi(){var t,r,o,c,h,p,m,E,C,ne;if(E=e,s.substr(e,3).toLowerCase()==="qop"?(t=s.substr(e,3),e+=3):(t=null,u('"qop"')),t!==null)if(r=k(),r!==null)if(o=tt(),o!==null){if(C=e,c=Pn(),c!==null){for(h=[],ne=e,s.charCodeAt(e)===44?(p=",",e++):(p=null,u('","')),p!==null?(m=Pn(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);p!==null;)h.push(p),ne=e,s.charCodeAt(e)===44?(p=",",e++):(p=null,u('","')),p!==null?(m=Pn(),m!==null?p=[p,m]:(p=null,e=ne)):(p=null,e=ne);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=ge(),h!==null?t=[t,r,o,c,h]:(t=null,e=E)):(t=null,e=E)}else t=null,e=E;else t=null,e=E;else t=null,e=E;return t}function Pn(){var t,r;return r=e,s.substr(e,8).toLowerCase()==="auth-int"?(t=s.substr(e,8),e+=8):(t=null,u('"auth-int"')),t===null&&(s.substr(e,4).toLowerCase()==="auth"?(t=s.substr(e,4),e+=4):(t=null,u('"auth"')),t===null&&(t=I())),t!==null&&(t=function(o,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Lu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Hu(){var t,r,o,c,h,p,m;if(h=e,p=e,t=xn(),t!==null){for(r=[],m=e,o=ce(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=ce(),o!==null?(c=xn(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C,ne;for(ne=v.multi_header.length,C=0;C<ne;C++)if(v.multi_header[C].parsed===null){v=null;break}v!==null?v=v.multi_header:v=-1}()),t===null&&(e=h),t}function xn(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Ot(),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C;v.multi_header||(v.multi_header=[]);try{C=new Ht(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch{C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function qu(){var t,r,o,c,h,p,m;if(h=e,p=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=bs(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E,C){if(v.protocol=C.toLowerCase(),v.params||(v.params={}),v.params.text&&v.params.text[0]==='"'){var ne=v.params.text;v.text=ne.substring(1,ne.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function bs(){var t;return t=Yi(),t===null&&(t=Re()),t}function Yi(){var t,r,o,c,h,p;if(h=e,p=e,s.substr(e,5).toLowerCase()==="cause"?(t=s.substr(e,5),e+=5):(t=null,u('"cause"')),t!==null)if(r=k(),r!==null){if(c=f(),c!==null)for(o=[];c!==null;)o.push(c),c=f();else o=null;o!==null?t=[t,r,o]:(t=null,e=p)}else t=null,e=p;else t=null,e=p;return t!==null&&(t=function(m,E){v.cause=parseInt(E.join(""))}(h,t[2])),t===null&&(e=h),t}function Fu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ju(){var t,r,o,c,h,p;if(h=e,t=Ln(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=Ln(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=Ln(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Ln(){var t,r,o,c,h,p;if(h=e,t=Ot(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $u(){var t,r,o,c,h,p;if(h=e,t=zi(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Rs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Rs(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function zi(){var t,r;return r=e,s.substr(e,6).toLowerCase()==="active"?(t=s.substr(e,6),e+=6):(t=null,u('"active"')),t===null&&(s.substr(e,7).toLowerCase()==="pending"?(t=s.substr(e,7),e+=7):(t=null,u('"pending"')),t===null&&(s.substr(e,10).toLowerCase()==="terminated"?(t=s.substr(e,10),e+=10):(t=null,u('"terminated"')),t===null&&(t=I()))),t!==null&&(t=function(o){v.state=s.substring(e,o)}(r)),t===null&&(e=r),t}function Rs(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="reason"?(t=s.substr(e,6),e+=6):(t=null,u('"reason"')),t!==null?(r=k(),r!==null?(o=Ji(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.reason=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,s.substr(e,7).toLowerCase()==="expires"?(t=s.substr(e,7),e+=7):(t=null,u('"expires"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.expires=m)}(c,t[2])),t===null&&(e=c),t===null&&(c=e,h=e,s.substr(e,11).toLowerCase()==="retry_after"?(t=s.substr(e,11),e+=11):(t=null,u('"retry_after"')),t!==null?(r=k(),r!==null?(o=Nt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){typeof m<"u"&&(v.retry_after=m)}(c,t[2])),t===null&&(e=c),t===null&&(t=Re()))),t}function Ji(){var t;return s.substr(e,11).toLowerCase()==="deactivated"?(t=s.substr(e,11),e+=11):(t=null,u('"deactivated"')),t===null&&(s.substr(e,9).toLowerCase()==="probation"?(t=s.substr(e,9),e+=9):(t=null,u('"probation"')),t===null&&(s.substr(e,8).toLowerCase()==="rejected"?(t=s.substr(e,8),e+=8):(t=null,u('"rejected"')),t===null&&(s.substr(e,7).toLowerCase()==="timeout"?(t=s.substr(e,7),e+=7):(t=null,u('"timeout"')),t===null&&(s.substr(e,6).toLowerCase()==="giveup"?(t=s.substr(e,6),e+=6):(t=null,u('"giveup"')),t===null&&(s.substr(e,10).toLowerCase()==="noresource"?(t=s.substr(e,10),e+=10):(t=null,u('"noresource"')),t===null&&(s.substr(e,9).toLowerCase()==="invariant"?(t=s.substr(e,9),e+=9):(t=null,u('"invariant"')),t===null&&(t=I()))))))),t}function Vu(){var t;return t=j(),t=t!==null?t:"",t}function Bu(){var t,r,o,c,h,p;if(h=e,t=I(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=I(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function Ku(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Is(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){var C=v.tag;try{v=new Ht(v.uri,v.display_name,v.params),C&&v.setParam("tag",C)}catch{v=-1}}()),t===null&&(e=h),t}function Is(){var t;return t=As(),t===null&&(t=Re()),t}function Gu(){var t,r,o,c,h,p;if(h=e,t=Hn(),t!==null){for(r=[],p=e,o=ce(),o!==null?(c=Hn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=ce(),o!==null?(c=Hn(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Hn(){var t,r,o,c,h,p,m,E;if(m=e,t=so(),t!==null)if(r=fe(),r!==null)if(o=oo(),o!==null){for(c=[],E=e,h=re(),h!==null?(p=ws(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);h!==null;)c.push(h),E=e,h=re(),h!==null?(p=ws(),p!==null?h=[h,p]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,o,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function ws(){var t;return t=Xi(),t===null&&(t=Qi(),t===null&&(t=Zi(),t===null&&(t=eo(),t===null&&(t=to(),t===null&&(t=Re()))))),t}function Xi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,3).toLowerCase()==="ttl"?(t=s.substr(e,3),e+=3):(t=null,u('"ttl"')),t!==null?(r=k(),r!==null?(o=Os(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.ttl=m}(c,t[2])),t===null&&(e=c),t}function Qi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,5).toLowerCase()==="maddr"?(t=s.substr(e,5),e+=5):(t=null,u('"maddr"')),t!==null?(r=k(),r!==null?(o=Jt(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.maddr=m}(c,t[2])),t===null&&(e=c),t}function Zi(){var t,r,o,c,h;return c=e,h=e,s.substr(e,8).toLowerCase()==="received"?(t=s.substr(e,8),e+=8):(t=null,u('"received"')),t!==null?(r=k(),r!==null?(o=Xt(),o===null&&(o=ps()),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.received=m}(c,t[2])),t===null&&(e=c),t}function eo(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6).toLowerCase()==="branch"?(t=s.substr(e,6),e+=6):(t=null,u('"branch"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.branch=m}(c,t[2])),t===null&&(e=c),t}function to(){var t,r,o,c,h;return c=e,s.substr(e,5).toLowerCase()==="rport"?(t=s.substr(e,5),e+=5):(t=null,u('"rport"')),t!==null?(h=e,r=k(),r!==null?(o=no(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function no(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.rport=parseInt(C.join(""))}(p,t)),t===null&&(e=p),t}function so(){var t,r,o,c,h,p;return p=e,t=ro(),t!==null?(r=V(),r!==null?(o=I(),o!==null?(c=V(),c!==null?(h=io(),h!==null?t=[t,r,o,c,h]:(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p)):(t=null,e=p),t}function ro(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="sip"?(t=s.substr(e,3),e+=3):(t=null,u('"SIP"')),t===null&&(t=I()),t!==null&&(t=function(o,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function io(){var t,r;return r=e,s.substr(e,3).toLowerCase()==="udp"?(t=s.substr(e,3),e+=3):(t=null,u('"UDP"')),t===null&&(s.substr(e,3).toLowerCase()==="tcp"?(t=s.substr(e,3),e+=3):(t=null,u('"TCP"')),t===null&&(s.substr(e,3).toLowerCase()==="tls"?(t=s.substr(e,3),e+=3):(t=null,u('"TLS"')),t===null&&(s.substr(e,4).toLowerCase()==="sctp"?(t=s.substr(e,4),e+=4):(t=null,u('"SCTP"')),t===null&&(t=I())))),t!==null&&(t=function(o,c){v.transport=c}(r,t)),t===null&&(e=r),t}function oo(){var t,r,o,c,h;return c=e,t=lo(),t!==null?(h=e,r=Ge(),r!==null?(o=ao(),o!==null?r=[r,o]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t}function lo(){var t,r;return r=e,t=Xt(),t===null&&(t=_s(),t===null&&(t=hs())),t!==null&&(t=function(o){v.host=s.substring(e,o)}(r)),t===null&&(e=r),t}function ao(){var t,r,o,c,h,p,m;return p=e,m=e,t=f(),t=t!==null?t:"",t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?(c=f(),c=c!==null?c:"",c!==null?(h=f(),h=h!==null?h:"",h!==null?t=[t,r,o,c,h]:(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m)):(t=null,e=m),t!==null&&(t=function(E,C){v.port=parseInt(C.join(""))}(p,t)),t===null&&(e=p),t}function Os(){var t,r,o,c,h;return c=e,h=e,t=f(),t!==null?(r=f(),r=r!==null?r:"",r!==null?(o=f(),o=o!==null?o:"",o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){return parseInt(m.join(""))}(c,t)),t===null&&(e=c),t}function Wu(){var t;return t=Cs(),t}function Yu(){var t,r,o,c,h,p;if(h=e,t=uo(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Ns(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function uo(){var t,r;return r=e,t=Nt(),t!==null&&(t=function(o,c){v.expires=c}(r,t)),t===null&&(e=r),t}function Ns(){var t;return t=co(),t===null&&(t=Re()),t}function co(){var t,r,o,c,h;return c=e,h=e,s.substr(e,9).toLowerCase()==="refresher"?(t=s.substr(e,9),e+=9):(t=null,u('"refresher"')),t!==null?(r=k(),r!==null?(s.substr(e,3).toLowerCase()==="uac"?(o=s.substr(e,3),e+=3):(o=null,u('"uac"')),o===null&&(s.substr(e,3).toLowerCase()==="uas"?(o=s.substr(e,3),e+=3):(o=null,u('"uas"'))),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.refresher=m.toLowerCase()}(c,t[2])),t===null&&(e=c),t}function zu(){var t,r,o,c;return c=e,t=I(),t!==null?(r=H(),r!==null?(o=ho(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ho(){var t,r;for(t=[],r=F(),r===null&&(r=W(),r===null&&(r=fe()));r!==null;)t.push(r),r=F(),r===null&&(r=W(),r===null&&(r=fe()));return t}function Ju(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function Xu(){var t,r,o;return o=e,s.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=_o(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function _o(){var t,r,o,c,h,p,m,E,C,ne,Ee;return ne=e,Ee=e,t=po(),t!==null?(s.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(o=lt(),o!==null?(s.charCodeAt(e)===45?(c="-",e++):(c=null,u('"-"')),c!==null?(h=lt(),h!==null?(s.charCodeAt(e)===45?(p="-",e++):(p=null,u('"-"')),p!==null?(m=lt(),m!==null?(s.charCodeAt(e)===45?(E="-",e++):(E=null,u('"-"')),E!==null?(C=fo(),C!==null?t=[t,r,o,c,h,p,m,E,C]:(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee)):(t=null,e=Ee),t!==null&&(t=function(at,qn){v=s.substring(e+5,at)}(ne,t[0])),t===null&&(e=ne),t}function lt(){var t,r,o,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(o=y(),o!==null?(c=y(),c!==null?t=[t,r,o,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function po(){var t,r,o;return o=e,t=lt(),t!==null?(r=lt(),r!==null?t=[t,r]:(t=null,e=o)):(t=null,e=o),t}function fo(){var t,r,o,c;return c=e,t=lt(),t!==null?(r=lt(),r!==null?(o=lt(),o!==null?t=[t,r,o]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Qu(){var t,r,o,c,h,p,m;if(h=e,p=e,t=Te(),t===null&&(t=Ot()),t!==null){for(r=[],m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);o!==null;)r.push(o),m=e,o=re(),o!==null?(c=Re(),c!==null?o=[o,c]:(o=null,e=m)):(o=null,e=m);r!==null?t=[t,r]:(t=null,e=p)}else t=null,e=p;return t!==null&&(t=function(E){try{v=new Ht(v.uri,v.display_name,v.params)}catch{v=-1}}()),t===null&&(e=h),t}function Zu(){var t,r,o,c,h,p;if(h=e,t=mo(),t!==null){for(r=[],p=e,o=re(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);o!==null;)r.push(o),p=e,o=re(),o!==null?(c=Ds(),c!==null?o=[o,c]:(o=null,e=p)):(o=null,e=p);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function mo(){var t,r,o,c,h,p;return c=e,h=e,t=Ke(),t!==null?(p=e,s.charCodeAt(e)===64?(r="@",e++):(r=null,u('"@"')),r!==null?(o=Ke(),o!==null?r=[r,o]:(r=null,e=p)):(r=null,e=p),r=r!==null?r:"",r!==null?t=[t,r]:(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(m){v.call_id=s.substring(e,m)}(c)),t===null&&(e=c),t}function Ds(){var t;return t=go(),t===null&&(t=To(),t===null&&(t=vo(),t===null&&(t=Re()))),t}function go(){var t,r,o,c,h;return c=e,h=e,s.substr(e,6)==="to-tag"?(t="to-tag",e+=6):(t=null,u('"to-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.to_tag=m}(c,t[2])),t===null&&(e=c),t}function To(){var t,r,o,c,h;return c=e,h=e,s.substr(e,8)==="from-tag"?(t="from-tag",e+=8):(t=null,u('"from-tag"')),t!==null?(r=k(),r!==null?(o=I(),o!==null?t=[t,r,o]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t!==null&&(t=function(p,m){v.from_tag=m}(c,t[2])),t===null&&(e=c),t}function vo(){var t,r;return r=e,s.substr(e,10)==="early-only"?(t="early-only",e+=10):(t=null,u('"early-only"')),t!==null&&(t=function(o){v.early_only=!0}()),t===null&&(e=r),t}function ec(t){t.sort();for(var r=null,o=[],c=0;c<t.length;c++)t[c]!==r&&(o.push(t[c]),r=t[c]);return o}function tc(){for(var t=1,r=1,o=!1,c=0;c<Math.max(e,d);c++){var h=s.charAt(c);h===`
75
+ `?(o||t++,r=1,o=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(t++,r=1,o=!0):(r++,o=!1)}return{line:t,column:r}}var yo=gn(),Ht=ba(),v={},nc=a[i]();if(nc===null||e!==s.length){var ks=Math.max(e,d),sc=ks<s.length?s.charAt(ks):null,Eo=tc();return new this.SyntaxError(ec(_),sc,ks,Eo.line,Eo.column),-1}return v},toSource:function(){return this._source}};return n.SyntaxError=function(s,i,a,e,d){function _(u,g){var f,T;switch(u.length){case 0:f="end of input";break;case 1:f=u[0];break;default:f=u.slice(0,u.length-1).join(", ")+" or "+u[u.length-1]}return T=g?l(g):"end of input","Expected "+f+" but "+T+" found."}this.name="SyntaxError",this.expected=s,this.found=i,this.message=_(s,i),this.offset=a,this.line=e,this.column=d},n.SyntaxError.prototype=Error.prototype,n}()),Hh}var Ra,Fh;function gn(){if(Fh)return Ra;Fh=1;const l=Ie,n=ft(),s=Bt();return Ra=class c_{static parse(a){if(a=s.parse(a,"SIP_URI"),a!==-1)return a}constructor(a,e,d,_,u={},g={}){if(!d)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=a||l.SIP,this._user=e,this._host=d,this._port=_;for(const f in u)Object.prototype.hasOwnProperty.call(u,f)&&this.setParam(f,u[f]);for(const f in g)Object.prototype.hasOwnProperty.call(g,f)&&this.setHeader(f,g[f])}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,e){a&&(this._parameters[a.toLowerCase()]=typeof e>"u"||e===null?null:e.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 e=this._parameters[a];return delete this._parameters[a],e}}clearParams(){this._parameters={}}setHeader(a,e){this._headers[n.headerize(a)]=Array.isArray(e)?e:[e]}getHeader(a){if(a)return this._headers[n.headerize(a)]}hasHeader(a){if(a)return this._headers.hasOwnProperty(n.headerize(a))&&!0||!1}deleteHeader(a){if(a=n.headerize(a),this._headers.hasOwnProperty(a)){const e=this._headers[a];return delete this._headers[a],e}}clearHeaders(){this._headers={}}clone(){return new c_(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const a=[];let e=`${this._scheme}:`;this._user&&(e+=`${n.escapeUser(this._user)}@`),e+=this._host,(this._port||this._port===0)&&(e+=`:${this._port}`);for(const d in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,d)&&(e+=`;${d}`,this._parameters[d]!==null&&(e+=`=${this._parameters[d]}`));for(const d in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,d))for(const _ of this._headers[d])a.push(`${d}=${_}`);return a.length>0&&(e+=`?${a.join("&")}`),e}toAor(a){let e=`${this._scheme}:`;return this._user&&(e+=`${n.escapeUser(this._user)}@`),e+=this._host,a&&(this._port||this._port===0)&&(e+=`:${this._port}`),e}},Ra}var jh;function ft(){if(jh)return Ze;jh=1;const l=Ie,n=gn(),s=Bt();Ze.str_utf8_length=d=>unescape(encodeURIComponent(d)).length;const i=Ze.isFunction=d=>d!==void 0?Object.prototype.toString.call(d)==="[object Function]":!1;Ze.isString=d=>d!==void 0?Object.prototype.toString.call(d)==="[object String]":!1,Ze.isDecimal=d=>!isNaN(d)&&parseFloat(d)===parseInt(d,10),Ze.isEmpty=d=>d===null||d===""||d===void 0||Array.isArray(d)&&d.length===0||typeof d=="number"&&isNaN(d),Ze.hasMethods=function(d,..._){for(const u of _)if(i(d[u]))return!1;return!0};const a=Ze.createRandomToken=(d,_=32)=>{let u,g,f="";for(u=0;u<d;u++)g=Math.random()*_|0,f+=g.toString(_);return f};Ze.newTag=()=>a(10),Ze.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const _=Math.random()*16|0;return(d==="x"?_:_&3|8).toString(16)}),Ze.hostType=d=>{if(d){if(d=s.parse(d,"host"),d!==-1)return d.host_type}else return};const e=Ze.escapeUser=d=>encodeURIComponent(decodeURIComponent(d)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return Ze.normalizeTarget=(d,_)=>{if(d){if(d instanceof n)return d;if(typeof d=="string"){const u=d.split("@");let g,f;switch(u.length){case 1:if(!_)return;g=d,f=_;break;case 2:g=u[0],f=u[1];break;default:g=u.slice(0,u.length-1).join("@"),f=u[u.length-1]}g=g.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(g)&&(g=g.replace(/[-.()]/g,"")),d=`${l.SIP}:${e(g)}@${f}`;let T;return(T=n.parse(d))?T:void 0}else return}else return},Ze.headerize=d=>{const _={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},u=d.toLowerCase().replace(/_/g,"-").split("-");let g="";const f=u.length;let T;for(T=0;T<f;T++)T!==0&&(g+="-"),g+=u[T].charAt(0).toUpperCase()+u[T].substring(1);return _[g]&&(g=_[g]),g},Ze.sipErrorCause=d=>{for(const _ in l.SIP_ERROR_CAUSES)if(l.SIP_ERROR_CAUSES[_].indexOf(d)!==-1)return l.causes[_];return l.causes.SIP_FAILURE_CODE},Ze.getRandomTestNetIP=()=>{function d(_,u){return Math.floor(Math.random()*(u-_+1)+_)}return`192.0.2.${d(1,254)}`},Ze.calculateMD5=d=>{function _(ge,pe){return ge<<pe|ge>>>32-pe}function u(ge,pe){const Se=ge&2147483648,be=pe&2147483648,De=ge&1073741824,he=pe&1073741824,ie=(ge&1073741823)+(pe&1073741823);return De&he?ie^2147483648^Se^be:De|he?ie&1073741824?ie^3221225472^Se^be:ie^1073741824^Se^be:ie^Se^be}function g(ge,pe,Se){return ge&pe|~ge&Se}function f(ge,pe,Se){return ge&Se|pe&~Se}function T(ge,pe,Se){return ge^pe^Se}function y(ge,pe,Se){return pe^(ge|~Se)}function A(ge,pe,Se,be,De,he,ie){return ge=u(ge,u(u(g(pe,Se,be),De),ie)),u(_(ge,he),pe)}function w(ge,pe,Se,be,De,he,ie){return ge=u(ge,u(u(f(pe,Se,be),De),ie)),u(_(ge,he),pe)}function b(ge,pe,Se,be,De,he,ie){return ge=u(ge,u(u(T(pe,Se,be),De),ie)),u(_(ge,he),pe)}function R(ge,pe,Se,be,De,he,ie){return ge=u(ge,u(u(y(pe,Se,be),De),ie)),u(_(ge,he),pe)}function G(ge){let pe;const Se=ge.length,be=Se+8,De=((be-be%64)/64+1)*16,he=new Array(De-1);let ie=0,Te=0;for(;Te<Se;)pe=(Te-Te%4)/4,ie=Te%4*8,he[pe]=he[pe]|ge.charCodeAt(Te)<<ie,Te++;return pe=(Te-Te%4)/4,ie=Te%4*8,he[pe]=he[pe]|128<<ie,he[De-2]=Se<<3,he[De-1]=Se>>>29,he}function x(ge){let pe="",Se="",be,De;for(De=0;De<=3;De++)be=ge>>>De*8&255,Se=`0${be.toString(16)}`,pe=pe+Se.substr(Se.length-2,2);return pe}function me(ge){let pe="";for(let Se=0;Se<ge.length;Se++){const be=ge.charCodeAt(Se);be<128?pe+=String.fromCharCode(be):be>127&&be<2048?(pe+=String.fromCharCode(be>>6|192),pe+=String.fromCharCode(be&63|128)):(pe+=String.fromCharCode(be>>12|224),pe+=String.fromCharCode(be>>6&63|128),pe+=String.fromCharCode(be&63|128))}return pe}let O=[],$,de,fe,N,H,j,F,P,W;const ee=7,I=12,X=17,te=22,Ke=5,Q=9,V=14,k=20,ve=4,_e=11,Ae=16,Ue=23,ce=6,re=10,Ge=15,tt=21;for(d=me(d),O=G(d),j=1732584193,F=4023233417,P=2562383102,W=271733878,$=0;$<O.length;$+=16)de=j,fe=F,N=P,H=W,j=A(j,F,P,W,O[$+0],ee,3614090360),W=A(W,j,F,P,O[$+1],I,3905402710),P=A(P,W,j,F,O[$+2],X,606105819),F=A(F,P,W,j,O[$+3],te,3250441966),j=A(j,F,P,W,O[$+4],ee,4118548399),W=A(W,j,F,P,O[$+5],I,1200080426),P=A(P,W,j,F,O[$+6],X,2821735955),F=A(F,P,W,j,O[$+7],te,4249261313),j=A(j,F,P,W,O[$+8],ee,1770035416),W=A(W,j,F,P,O[$+9],I,2336552879),P=A(P,W,j,F,O[$+10],X,4294925233),F=A(F,P,W,j,O[$+11],te,2304563134),j=A(j,F,P,W,O[$+12],ee,1804603682),W=A(W,j,F,P,O[$+13],I,4254626195),P=A(P,W,j,F,O[$+14],X,2792965006),F=A(F,P,W,j,O[$+15],te,1236535329),j=w(j,F,P,W,O[$+1],Ke,4129170786),W=w(W,j,F,P,O[$+6],Q,3225465664),P=w(P,W,j,F,O[$+11],V,643717713),F=w(F,P,W,j,O[$+0],k,3921069994),j=w(j,F,P,W,O[$+5],Ke,3593408605),W=w(W,j,F,P,O[$+10],Q,38016083),P=w(P,W,j,F,O[$+15],V,3634488961),F=w(F,P,W,j,O[$+4],k,3889429448),j=w(j,F,P,W,O[$+9],Ke,568446438),W=w(W,j,F,P,O[$+14],Q,3275163606),P=w(P,W,j,F,O[$+3],V,4107603335),F=w(F,P,W,j,O[$+8],k,1163531501),j=w(j,F,P,W,O[$+13],Ke,2850285829),W=w(W,j,F,P,O[$+2],Q,4243563512),P=w(P,W,j,F,O[$+7],V,1735328473),F=w(F,P,W,j,O[$+12],k,2368359562),j=b(j,F,P,W,O[$+5],ve,4294588738),W=b(W,j,F,P,O[$+8],_e,2272392833),P=b(P,W,j,F,O[$+11],Ae,1839030562),F=b(F,P,W,j,O[$+14],Ue,4259657740),j=b(j,F,P,W,O[$+1],ve,2763975236),W=b(W,j,F,P,O[$+4],_e,1272893353),P=b(P,W,j,F,O[$+7],Ae,4139469664),F=b(F,P,W,j,O[$+10],Ue,3200236656),j=b(j,F,P,W,O[$+13],ve,681279174),W=b(W,j,F,P,O[$+0],_e,3936430074),P=b(P,W,j,F,O[$+3],Ae,3572445317),F=b(F,P,W,j,O[$+6],Ue,76029189),j=b(j,F,P,W,O[$+9],ve,3654602809),W=b(W,j,F,P,O[$+12],_e,3873151461),P=b(P,W,j,F,O[$+15],Ae,530742520),F=b(F,P,W,j,O[$+2],Ue,3299628645),j=R(j,F,P,W,O[$+0],ce,4096336452),W=R(W,j,F,P,O[$+7],re,1126891415),P=R(P,W,j,F,O[$+14],Ge,2878612391),F=R(F,P,W,j,O[$+5],tt,4237533241),j=R(j,F,P,W,O[$+12],ce,1700485571),W=R(W,j,F,P,O[$+3],re,2399980690),P=R(P,W,j,F,O[$+10],Ge,4293915773),F=R(F,P,W,j,O[$+1],tt,2240044497),j=R(j,F,P,W,O[$+8],ce,1873313359),W=R(W,j,F,P,O[$+15],re,4264355552),P=R(P,W,j,F,O[$+6],Ge,2734768916),F=R(F,P,W,j,O[$+13],tt,1309151649),j=R(j,F,P,W,O[$+4],ce,4149444226),W=R(W,j,F,P,O[$+11],re,3174756917),P=R(P,W,j,F,O[$+2],Ge,718787259),F=R(F,P,W,j,O[$+9],tt,3951481745),j=u(j,de),F=u(F,fe),P=u(P,N),W=u(W,H);return(x(j)+x(F)+x(P)+x(W)).toLowerCase()},Ze.closeMediaStream=d=>{if(d)try{let _;if(d.getTracks){_=d.getTracks();for(const u of _)u.stop()}else{_=d.getAudioTracks();for(const u of _)u.stop();_=d.getVideoTracks();for(const u of _)u.stop()}}catch{(typeof d.stop=="function"||typeof d.stop=="object")&&d.stop()}},Ze.cloneArray=d=>d&&d.slice()||[],Ze.cloneObject=(d,_={})=>d&&Object.assign({},d)||_,Ze}const $h=Dt,fg=ot,mt=Ie,rt=ft(),Vh=ba(),mg=Bt(),Ia=new fg("SIPMessage");class al{constructor(n,s,i,a,e,d){if(!n||!s||!i)return null;a=a||{},this.ua=i,this.headers={},this.method=n,this.ruri=s,this.body=d,this.extraHeaders=rt.cloneArray(e),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):i.configuration.use_preloaded_route&&this.setHeader("route",`<${i.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",mt.MAX_FORWARDS);const _=a.to_uri||s,u=a.to_tag?{tag:a.to_tag}:null,g=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new Vh(_,g,u),this.setHeader("to",this.to.toString());const f=a.from_uri||i.configuration.uri,T={tag:a.from_tag||rt.newTag()};let y;typeof a.from_display_name<"u"?y=a.from_display_name:i.configuration.display_name?y=i.configuration.display_name:y=null,this.from=new Vh(f,y,T),this.setHeader("from",this.from.toString());const A=a.call_id||i.configuration.jssip_id+rt.createRandomToken(15);this.call_id=A,this.setHeader("call-id",A);const w=a.cseq||Math.floor(Math.random()*1e4);this.cseq=w,this.setHeader("cseq",`${w} ${n}`)}setHeader(n,s){const i=new RegExp(`^\\s*${n}\\s*:`,"i");for(let a=0;a<this.extraHeaders.length;a++)i.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[rt.headerize(n)]=Array.isArray(s)?s:[s]}getHeader(n){const s=this.headers[rt.headerize(n)];if(s){if(s[0])return s[0]}else{const i=new RegExp(`^\\s*${n}\\s*:`,"i");for(const a of this.extraHeaders)if(i.test(a))return a.substring(a.indexOf(":")+1).trim()}}getHeaders(n){const s=this.headers[rt.headerize(n)],i=[];if(s){for(const a of s)i.push(a);return i}else{const a=new RegExp(`^\\s*${n}\\s*:`,"i");for(const e of this.extraHeaders)a.test(e)&&i.push(e.substring(e.indexOf(":")+1).trim());return i}}hasHeader(n){if(this.headers[rt.headerize(n)])return!0;{const s=new RegExp(`^\\s*${n}\\s*:`,"i");for(const i of this.extraHeaders)if(s.test(i))return!0}return!1}parseSDP(n){return!n&&this.sdp?this.sdp:(this.sdp=$h.parse(this.body||""),this.sdp)}toString(){let n=`${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 e of this.headers[a])n+=`${a}: ${e}\r
77
+ `;for(const a of this.extraHeaders)n+=`${a.trim()}\r
78
+ `;const s=[];switch(this.method){case mt.REGISTER:s.push("path","gruu");break;case mt.INVITE:this.ua.configuration.session_timers&&s.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&s.push("gruu"),s.push("ice","replaces");break;case mt.UPDATE:this.ua.configuration.session_timers&&s.push("timer"),s.push("ice");break}s.push("outbound");const i=this.ua.configuration.user_agent||mt.USER_AGENT;if(n+=`Allow: ${mt.ALLOWED_METHODS}\r
79
+ `,n+=`Supported: ${s}\r
80
+ `,n+=`User-Agent: ${i}\r
81
+ `,this.body){const a=rt.str_utf8_length(this.body);n+=`Content-Length: ${a}\r
82
82
  \r
83
- `,s+=this.body}else s+=`Content-Length: 0\r
83
+ `,n+=this.body}else n+=`Content-Length: 0\r
84
84
  \r
85
- `;return s}clone(){const s=new pl(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){s.headers[n]=this.headers[n].slice()},this),s.body=this.body,s.extraHeaders=ut.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s}}class La extends pl{constructor(s,n,i,a,e){super(Et.INVITE,s,n,i,a,e),this.transaction=null}cancel(s){this.transaction.cancel(s)}clone(){const s=new La(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){s.headers[n]=this.headers[n].slice()},this),s.body=this.body,s.extraHeaders=ut.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s.transaction=this.transaction,s}}class Jh{constructor(){this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}addHeader(s,n){const i={raw:n};s=ut.headerize(s),this.headers[s]?this.headers[s].push(i):this.headers[s]=[i]}getHeader(s){const n=this.headers[ut.headerize(s)];if(n){if(n[0])return n[0].raw}else return}getHeaders(s){const n=this.headers[ut.headerize(s)],i=[];if(!n)return[];for(const a of n)i.push(a.raw);return i}hasHeader(s){return!!this.headers[ut.headerize(s)]}parseHeader(s,n=0){if(s=ut.headerize(s),this.headers[s]){if(n>=this.headers[s].length){Pa.debug(`not so many "${s}" headers present`);return}}else{Pa.debug(`header "${s}" not present`);return}const i=this.headers[s][n],a=i.raw;if(i.parsed)return i.parsed;const e=Eg.parse(a,s.replace(/-/g,"_"));if(e===-1){this.headers[s].splice(n,1),Pa.debug(`error parsing "${s}" header field with value "${a}"`);return}else return i.parsed=e,e}s(s,n){return this.parseHeader(s,n)}setHeader(s,n){const i={raw:n};this.headers[ut.headerize(s)]=[i]}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=Xh.parse(this.body||""),this.sdp)}toString(){return this.data}}class Sg extends Jh{constructor(s){super(),this.ua=s,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(s,n,i,a,e,d){const _=[];let u=this.getHeader("To");if(s=s||null,n=n||null,!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||Et.REASON_PHRASE[s]||"",i=ut.cloneArray(i),this.ua.configuration.extra_headers&&(i=i.concat(this.ua.configuration.extra_headers));let g=`SIP/2.0 ${s} ${n}\r
86
- `;if(this.method===Et.INVITE&&s>100&&s<=200){const T=this.getHeaders("record-route");for(const y of T)g+=`Record-Route: ${y}\r
87
- `}const p=this.getHeaders("via");for(const T of p)g+=`Via: ${T}\r
88
- `;!this.to_tag&&s>100?u+=`;tag=${ut.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(u+=`;tag=${this.to_tag}`),g+=`To: ${u}\r
85
+ `;return n}clone(){const n=new al(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){n.headers[s]=this.headers[s].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}}class wa extends al{constructor(n,s,i,a,e){super(mt.INVITE,n,s,i,a,e),this.transaction=null}cancel(n){this.transaction.cancel(n)}clone(){const n=new wa(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){n.headers[s]=this.headers[s].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.transaction=this.transaction,n}}class Bh{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(n,s){const i={raw:s};n=rt.headerize(n),this.headers[n]?this.headers[n].push(i):this.headers[n]=[i]}getHeader(n){const s=this.headers[rt.headerize(n)];if(s){if(s[0])return s[0].raw}else return}getHeaders(n){const s=this.headers[rt.headerize(n)],i=[];if(!s)return[];for(const a of s)i.push(a.raw);return i}hasHeader(n){return!!this.headers[rt.headerize(n)]}parseHeader(n,s=0){if(n=rt.headerize(n),this.headers[n]){if(s>=this.headers[n].length){Ia.debug(`not so many "${n}" headers present`);return}}else{Ia.debug(`header "${n}" not present`);return}const i=this.headers[n][s],a=i.raw;if(i.parsed)return i.parsed;const e=mg.parse(a,n.replace(/-/g,"_"));if(e===-1){this.headers[n].splice(s,1),Ia.debug(`error parsing "${n}" header field with value "${a}"`);return}else return i.parsed=e,e}s(n,s){return this.parseHeader(n,s)}setHeader(n,s){const i={raw:s};this.headers[rt.headerize(n)]=[i]}parseSDP(n){return!n&&this.sdp?this.sdp:(this.sdp=$h.parse(this.body||""),this.sdp)}toString(){return this.data}}class gg extends Bh{constructor(n){super(),this.ua=n,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(n,s,i,a,e,d){const _=[];let u=this.getHeader("To");if(n=n||null,s=s||null,!n||n<100||n>699)throw new TypeError(`Invalid status_code: ${n}`);if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError(`Invalid reason_phrase: ${s}`);s=s||mt.REASON_PHRASE[n]||"",i=rt.cloneArray(i),this.ua.configuration.extra_headers&&(i=i.concat(this.ua.configuration.extra_headers));let g=`SIP/2.0 ${n} ${s}\r
86
+ `;if(this.method===mt.INVITE&&n>100&&n<=200){const T=this.getHeaders("record-route");for(const y of T)g+=`Record-Route: ${y}\r
87
+ `}const f=this.getHeaders("via");for(const T of f)g+=`Via: ${T}\r
88
+ `;!this.to_tag&&n>100?u+=`;tag=${rt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(u+=`;tag=${this.to_tag}`),g+=`To: ${u}\r
89
89
  `,g+=`From: ${this.getHeader("From")}\r
90
90
  `,g+=`Call-ID: ${this.call_id}\r
91
91
  `,g+=`CSeq: ${this.cseq} ${this.method}\r
92
92
  `;for(const T of i)g+=`${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?(g+=`Allow: ${Et.ALLOWED_METHODS}\r
94
- `,g+=`Accept: ${Et.ACCEPTED_BODY_TYPES}\r
95
- `):s===405?g+=`Allow: ${Et.ALLOWED_METHODS}\r
96
- `:s===415&&(g+=`Accept: ${Et.ACCEPTED_BODY_TYPES}\r
93
+ `;switch(this.method){case mt.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 mt.UPDATE:this.ua.configuration.session_timers&&_.push("timer"),a&&_.push("ice"),_.push("replaces")}if(_.push("outbound"),this.method===mt.OPTIONS?(g+=`Allow: ${mt.ALLOWED_METHODS}\r
94
+ `,g+=`Accept: ${mt.ACCEPTED_BODY_TYPES}\r
95
+ `):n===405?g+=`Allow: ${mt.ALLOWED_METHODS}\r
96
+ `:n===415&&(g+=`Accept: ${mt.ACCEPTED_BODY_TYPES}\r
97
97
  `),g+=`Supported: ${_}\r
98
- `,a){const T=ut.str_utf8_length(a);g+=`Content-Type: application/sdp\r
98
+ `,a){const T=rt.str_utf8_length(a);g+=`Content-Type: application/sdp\r
99
99
  `,g+=`Content-Length: ${T}\r
100
100
  \r
101
101
  `,g+=a}else g+=`Content-Length: 0\r
102
102
  \r
103
- `;this.server_transaction.receiveResponse(s,g,e,d)}reply_sl(s=null,n=null){const i=this.getHeaders("via");if(!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||Et.REASON_PHRASE[s]||"";let a=`SIP/2.0 ${s} ${n}\r
103
+ `;this.server_transaction.receiveResponse(n,g,e,d)}reply_sl(n=null,s=null){const i=this.getHeaders("via");if(!n||n<100||n>699)throw new TypeError(`Invalid status_code: ${n}`);if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError(`Invalid reason_phrase: ${s}`);s=s||mt.REASON_PHRASE[n]||"";let a=`SIP/2.0 ${n} ${s}\r
104
104
  `;for(const d of i)a+=`Via: ${d}\r
105
- `;let e=this.getHeader("To");if(!this.to_tag&&s>100?e+=`;tag=${ut.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(e+=`;tag=${this.to_tag}`),a+=`To: ${e}\r
105
+ `;let e=this.getHeader("To");if(!this.to_tag&&n>100?e+=`;tag=${rt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(e+=`;tag=${this.to_tag}`),a+=`To: ${e}\r
106
106
  `,a+=`From: ${this.getHeader("From")}\r
107
107
  `,a+=`Call-ID: ${this.call_id}\r
108
108
  `,a+=`CSeq: ${this.cseq} ${this.method}\r
109
109
  `,this.ua.configuration.extra_headers)for(const d of this.ua.configuration.extra_headers)a+=`${d.trim()}\r
110
110
  `;a+=`Content-Length: 0\r
111
111
  \r
112
- `,this.transport.send(a)}}class Ag extends Jh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var St={OutgoingRequest:pl,InitialOutgoingInviteRequest:La,IncomingRequest:Sg,IncomingResponse:Ag};const Ws=$e(St),Cg=ht,An=yt(),Qt=new Cg("DigestAuthentication");var Zh=class{constructor(l){this._credentials=l,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(l){switch(l){case"realm":return this._realm;case"ha1":return this._ha1;default:Qt.warn('get() | cannot get "%s" parameter',l);return}}authenticate({method:l,ruri:s,body:n},i,a=null){if(this._algorithm=i.algorithm,this._realm=i.realm,this._nonce=i.nonce,this._opaque=i.opaque,this._stale=i.stale,this._algorithm){if(this._algorithm!=="MD5")return Qt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Qt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Qt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Qt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Qt.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(i.qop)if(i.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(i.qop.indexOf("auth")>-1)this._qop="auth";else return Qt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=l,this._uri=s,this._cnonce=a||An.createRandomToken(12),this._nc+=1;const e=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-e.length)+e,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=An.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,_;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,_=An.calculateMD5(d),Qt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=An.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${_}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${An.calculateMD5(n||"")}`,_=An.calculateMD5(d),Qt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=An.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${_}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,_=An.calculateMD5(d),Qt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=An.calculateMD5(`${this._ha1}:${this._nonce}:${_}`)),Qt.debug("authenticate() | response generated"),!0}toString(){const l=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return l.push(`algorithm=${this._algorithm}`),l.push(`username="${this._credentials.username}"`),l.push(`realm="${this._realm}"`),l.push(`nonce="${this._nonce}"`),l.push(`uri="${this._uri}"`),l.push(`response="${this._response}"`),this._opaque&&l.push(`opaque="${this._opaque}"`),this._qop&&(l.push(`qop=${this._qop}`),l.push(`cnonce="${this._cnonce}"`),l.push(`nc=${this._ncHex}`)),`Digest ${l.join(", ")}`}};const bg=$e(Zh),Cn=500,Rg=4e3,ed=5e3;var Ha={T1:Cn,T2:Rg,T4:ed,TIMER_B:64*Cn,TIMER_D:0*Cn,TIMER_F:64*Cn,TIMER_H:64*Cn,TIMER_I:0*Cn,TIMER_J:0*Cn,TIMER_K:0*ed,TIMER_L:64*Cn,TIMER_M:64*Cn,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Ar=$e(Ha),Cr=_t.EventEmitter,br=ht,Rr=Ne,td=St,pn=Ha,nd=new br("NonInviteClientTransaction"),ml=new br("InviteClientTransaction"),Ig=new br("AckClientTransaction"),sd=new br("NonInviteServerTransaction"),gl=new br("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 wg extends Cr{constructor(s,n,i,a){super(),this.type=he.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=n,this.request=i,this.eventHandlers=a;let e=`SIP/2.0/${n.via_transport}`;e+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e),this.ua.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},pn.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){nd.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(){nd.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(s){const n=s.status_code;if(n<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break}else switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(s),this.K=setTimeout(()=>{this.timer_K()},pn.TIMER_K);break;case he.STATUS_COMPLETED:break}}}class Og extends Cr{constructor(s,n,i,a){super(),this.type=he.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=n,this.request=i,this.eventHandlers=a,i.transaction=this;let e=`SIP/2.0/${n.via_transport}`;e+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e),this.ua.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},pn.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(ml.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){ml.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(){ml.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(){ml.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(s){const n=new td.OutgoingRequest(Rr.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",s.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},pn.TIMER_D),this.transport.send(n)}cancel(s){if(this.state!==he.STATUS_PROCEEDING)return;const n=new td.OutgoingRequest(Rr.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")),s&&n.setHeader("reason",s),this.transport.send(n)}receiveResponse(s){const n=s.status_code;if(n>=100&&n<=199)switch(this.state){case he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(s);break}else if(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()},pn.TIMER_M),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(s);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(s),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_COMPLETED:this.sendACK(s);break}}}class Ng extends Cr{constructor(s,n,i,a){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=i,this.eventHandlers=a;let e=`SIP/2.0/${n.via_transport}`;e+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e)}get C(){return he}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Ig.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Dg extends Cr{constructor(s,n,i){super(),this.type=he.NON_INVITE_SERVER,this.id=i.via_branch,this.ua=s,this.transport=n,this.request=i,this.last_response="",i.server_transaction=this,this.state=he.STATUS_TRYING,s.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_J(){sd.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,sd.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(s,n,i,a){if(s===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)?i&&i():(this.onTransportError(),a&&a());break}else if(s>=200&&s<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},pn.TIMER_J),this.transport.send(n)?i&&i():(this.onTransportError(),a&&a());break;case he.STATUS_COMPLETED:break}}}class kg extends Cr{constructor(s,n,i){super(),this.type=he.INVITE_SERVER,this.id=i.via_branch,this.ua=s,this.transport=n,this.request=i,this.last_response="",i.server_transaction=this,this.state=he.STATUS_PROCEEDING,s.newTransaction(this),this.resendProvisionalTimer=null,i.reply(100)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_H(){gl.debug(`Timer H expired for transaction ${this.id}`),this.state===he.STATUS_COMPLETED&&gl.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(){gl.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,gl.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(s,n,i,a){if(s>=100&&s<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(s>100&&s<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},pn.PROVISIONAL_RESPONSE_INTERVAL));else if(s>=200&&s<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},pn.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(n)?i&&i():(this.onTransportError(),a&&a());break}else if(s>=300&&s<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},pn.TIMER_H),i&&i()):(this.onTransportError(),a&&a());break}}}function Ug({_transactions:l},s){let n;switch(s.method){case Rr.INVITE:if(n=l.ist[s.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 Rr.ACK:if(n=l.ist[s.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()},pn.TIMER_I),!0}else return!1;break;case Rr.CANCEL:return n=l.ist[s.via_branch],n?(s.reply_sl(200),n.state!==he.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(n=l.nist[s.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 Ys={C:he,NonInviteClientTransaction:wg,InviteClientTransaction:Og,AckClientTransaction:Ng,NonInviteServerTransaction:Dg,InviteServerTransaction:kg,checkTransaction:Ug};const Wt=$e(Ys),Mg=ht,rd=Ne,xg=Zh,qa=Ys,Pg=new Mg("RequestSender"),Fa={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var zs=class{constructor(l,s,n){this._ua=l,this._eventHandlers=n,this._method=s.method,this._request=s,this._auth=null,this._challenged=!1,this._staled=!1;for(const i in Fa)Object.prototype.hasOwnProperty.call(Fa,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=Fa[i]));l.status===l.C.STATUS_USER_CLOSED&&(this._method!==rd.BYE||this._method!==rd.ACK)&&this._eventHandlers.onTransportError()}send(){const l={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:s=>{this._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new qa.InviteClientTransaction(this._ua,this._ua.transport,this._request,l);break;case"ACK":this.clientTransaction=new qa.AckClientTransaction(this._ua,this._ua.transport,this._request,l);break;default:this.clientTransaction=new qa.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,l)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(l){let s,n;const i=l.status_code;if((i===401||i===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(l.status_code===401?(s=l.parseHeader("www-authenticate"),n="authorization"):(s=l.parseHeader("proxy-authenticate"),n="proxy-authorization"),!s){Pg.debug(`${l.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(l);return}if(!this._challenged||!this._staled&&s.stale===!0){if(this._auth||(this._auth=new xg({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,s)){this._eventHandlers.onReceiveResponse(l);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),s.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(n,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(l)}else this._eventHandlers.onReceiveResponse(l)}};const Ir=$e(zs),Lg=ht,ja=yt(),as=Ne,id=St,od=zs,wr=new Lg("Registrator"),Tl=10;var Hg=class{constructor(l,s){this._reg_id=1,this._ua=l,this._transport=s,this._registrar=l.configuration.registrar_server,this._expires=l.configuration.register_expires,this._call_id=ja.createRandomToken(22),this._cseq=0,this._to_uri=l.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(l){Array.isArray(l)||(l=[]),this._extraHeaders=l.slice()}setExtraContactParams(l){l instanceof Object||(l={}),this._extraContactParams="";for(const s in l)if(Object.prototype.hasOwnProperty.call(l,s)){const n=l[s];this._extraContactParams+=`;${s}`,n&&(this._extraContactParams+=`=${n}`)}}register(){if(this._registering){wr.debug("Register request in progress...");return}const l=this._extraHeaders.slice();l.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),l.push(`Expires: ${this._expires}`);const s=new id.OutgoingRequest(as.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l),n=new od(this._ua,s,{onRequestTimeout:()=>{this._registrationFailure(null,as.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,as.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:i=>{if(i.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):{if(this._registering=!1,!i.hasHeader("Contact")){wr.debug("no Contact header in response to REGISTER, response ignored");break}const a=i.headers.Contact.reduce((u,g)=>u.concat(g.parsed),[]);let e=a.find(u=>this._sipInstance===u.getParam("+sip.instance")&&this._reg_id===parseInt(u.getParam("reg-id")));if(e||(e=a.find(u=>u.uri.user===this._ua.contact.uri.user)),!e){wr.debug("no Contact header pointing to us, response ignored");break}let d=e.getParam("expires");!d&&i.hasHeader("expires")&&(d=i.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Tl&&(d=Tl);const _=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},_),e.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=e.getParam("temp-gruu").replace(/"/g,"")),e.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=e.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:i}));break}case/^423$/.test(i.status_code):{i.hasHeader("min-expires")?(this._expires=Number(i.getHeader("min-expires")),this._expires<Tl&&(this._expires=Tl),this.register()):(wr.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(i,as.causes.SIP_FAILURE_CODE));break}default:{const a=ja.sipErrorCause(i.status_code);this._registrationFailure(i,a)}}}});this._registering=!0,n.send()}unregister(l={}){if(!this._registered){wr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const s=this._extraHeaders.slice();l.all?s.push(`Contact: *${this._extraContactParams}`):s.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),s.push("Expires: 0");const n=new id.OutgoingRequest(as.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s);new od(this._ua,n,{onRequestTimeout:()=>{this._unregistered(null,as.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,as.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:i=>{switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._unregistered(i);break;default:{const a=ja.sipErrorCause(i.status_code);this._unregistered(i,a)}}}}).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(l,s){this._registering=!1,this._ua.registrationFailed({response:l||null,cause:s}),this._registered&&(this._registered=!1,this._ua.unregistered({response:l||null,cause:s}))}_unregistered(l,s){this._registering=!1,this._registered=!1,this._ua.unregistered({response:l||null,cause:s||null})}};class qg extends Error{constructor(s,n){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=s,this.value=n,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class Fg extends Error{constructor(s){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=s,this.message=`Invalid status: ${s}`}}class jg extends Error{constructor(s){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=s}}class $g extends Error{constructor(s){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=s}}var bn={ConfigurationError:qg,InvalidStateError:Fg,NotSupportedError:jg,NotReadyError:$g};const Xn=$e(bn),$a=Ne,vl=Ys,Vg=zs,Va={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var ld=class{constructor(l,s,n){this._dialog=l,this._ua=l._ua,this._request=s,this._eventHandlers=n,this._reattempt=!1,this._reattemptTimer=null;for(const i in Va)Object.prototype.hasOwnProperty.call(Va,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=Va[i]))}get request(){return this._request}send(){const l=new Vg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:s=>{this._eventHandlers.onAuthenticated(s)},onReceiveResponse:s=>{this._receiveResponse(s)}});if(l.send(),(this._request.method===$a.INVITE||this._request.method===$a.UPDATE&&this._request.body)&&l.clientTransaction.state!==vl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const s=()=>{(l.clientTransaction.state===vl.C.STATUS_ACCEPTED||l.clientTransaction.state===vl.C.STATUS_COMPLETED||l.clientTransaction.state===vl.C.STATUS_TERMINATED)&&(l.clientTransaction.removeListener("stateChanged",s),this._dialog.uac_pending_reply=!1)};l.clientTransaction.on("stateChanged",s)}}_receiveResponse(l){l.status_code===408||l.status_code===481?this._eventHandlers.onDialogError(l):l.method===$a.INVITE&&l.status_code===491?this._reattempt?l.status_code>=200&&l.status_code<300?this._eventHandlers.onSuccessResponse(l):l.status_code>=300&&this._eventHandlers.onErrorResponse(l):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):l.status_code>=200&&l.status_code<300?this._eventHandlers.onSuccessResponse(l):l.status_code>=300&&this._eventHandlers.onErrorResponse(l)}};const Bg=$e(ld),Kg=ht,ad=St,Qn=Ne,Or=Ys,Gg=ld,Ba=yt(),Ka=new Kg("Dialog"),Jn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var ud=class{static get C(){return Jn}constructor(l,s,n,i=Jn.STATUS_CONFIRMED){if(this._owner=l,this._ua=l._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!s.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};s instanceof ad.IncomingResponse&&(i=s.status_code<200?Jn.STATUS_EARLY:Jn.STATUS_CONFIRMED);const a=s.parseHeader("contact");n==="UAS"?(this._id={call_id:s.call_id,local_tag:s.to_tag,remote_tag:s.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=i,this._remote_seqnum=s.cseq,this._local_uri=s.parseHeader("to").uri,this._remote_uri=s.parseHeader("from").uri,this._remote_target=a.uri,this._route_set=s.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):n==="UAC"&&(this._id={call_id:s.call_id,local_tag:s.from_tag,remote_tag:s.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=i,this._local_seqnum=s.cseq,this._local_uri=s.parseHeader("from").uri,this._remote_uri=s.parseHeader("to").uri,this._remote_target=a.uri,this._route_set=s.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Ka.debug(`new ${n} dialog created with status ${this._state===Jn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(l){this._local_seqnum=l}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(l){this._uac_pending_reply=l}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Jn.STATUS_TERMINATED}update(l,s){this._state=Jn.STATUS_CONFIRMED,Ka.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),s==="UAC"&&(this._route_set=l.getHeaders("record-route").reverse())}terminate(){Ka.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Jn.STATUS_TERMINATED}sendRequest(l,s={}){const n=Ba.cloneArray(s.extraHeaders),i=Ba.cloneObject(s.eventHandlers),a=s.body||null,e=this._createRequest(l,n,a);return i.onAuthenticated=()=>{this._local_seqnum+=1},new Gg(this,e,i).send(),e}receiveRequest(l){this._checkInDialogRequest(l)&&(l.method===Qn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:l.method===Qn.INVITE&&(this._ack_seqnum=l.cseq),this._owner.receiveRequest(l))}_createRequest(l,s,n){s=Ba.cloneArray(s),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const i=l===Qn.CANCEL||l===Qn.ACK?this._local_seqnum:this._local_seqnum+=1;return new ad.OutgoingRequest(l,this._remote_target,this._ua,{cseq:i,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},s,n)}_checkInDialogRequest(l){if(!this._remote_seqnum)this._remote_seqnum=l.cseq;else if(l.cseq<this._remote_seqnum)if(l.method===Qn.ACK){if(this._ack_seqnum===null||l.cseq!==this._ack_seqnum)return!1}else return l.reply(500),!1;else l.cseq>this._remote_seqnum&&(this._remote_seqnum=l.cseq);if(l.method===Qn.INVITE||l.method===Qn.UPDATE&&l.body){if(this._uac_pending_reply===!0)l.reply(491);else if(this._uas_pending_reply===!0){const s=(Math.random()*10|0)+1;return l.reply(500,null,[`Retry-After:${s}`]),!1}else{this._uas_pending_reply=!0;const s=()=>{(l.server_transaction.state===Or.C.STATUS_ACCEPTED||l.server_transaction.state===Or.C.STATUS_COMPLETED||l.server_transaction.state===Or.C.STATUS_TERMINATED)&&(l.server_transaction.removeListener("stateChanged",s),this._uas_pending_reply=!1)};l.server_transaction.on("stateChanged",s)}l.hasHeader("contact")&&l.server_transaction.on("stateChanged",()=>{l.server_transaction.state===Or.C.STATUS_ACCEPTED&&(this._remote_target=l.parseHeader("contact").uri)})}else l.method===Qn.NOTIFY&&l.hasHeader("contact")&&l.server_transaction.on("stateChanged",()=>{l.server_transaction.state===Or.C.STATUS_COMPLETED&&(this._remote_target=l.parseHeader("contact").uri)});return!0}};const yl=$e(ud);var Ga={exports:{}};const Wg=_t.EventEmitter,Yg=ht,zg=Ne,Xg=bn,cd=yt(),Qg=new Yg("RTCSession:DTMF"),hd={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Ga.exports=class extends Wg{constructor(l){super(),this._session=l,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(l,s={}){if(l===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 Xg.InvalidStateError(this._session.status);const n=cd.cloneArray(s.extraHeaders);if(this.eventHandlers=cd.cloneObject(s.eventHandlers),typeof l=="string")l=l.toUpperCase();else if(typeof l=="number")l=l.toString();else throw new TypeError(`Invalid tone: ${l}`);if(l.match(/^[0-9A-DR#*]$/))this._tone=l;else throw new TypeError(`Invalid tone: ${l}`);this._duration=s.duration,n.push("Content-Type: application/dtmf-relay");let i=`Signal=${this._tone}\r
113
- `;i+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(zg.INFO,{extraHeaders:n,eventHandlers:{onSuccessResponse:a=>{this.emit("succeeded",{originator:"remote",response:a})},onErrorResponse:a=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:a})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:i})}init_incoming(l){const s=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=l,l.reply(200),l.body){const i=l.body.split(`
114
- `);i.length>=1&&s.test(i[0])&&(this._tone=i[0].replace(s,"$2")),i.length>=2&&n.test(i[1])&&(this._duration=parseInt(i[1].replace(n,"$2"),10))}this._duration||(this._duration=hd.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:l}):Qg.debug("invalid INFO DTMF received, discarded")}},Ga.exports.C=hd;var dd=Ga.exports;const Jg=$e(dd),Zg=_t.EventEmitter,eT=Ne,tT=bn,nT=yt();var _d=class extends Zg{constructor(l){super(),this._session=l,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(l,s,n={}){if(this._direction="outgoing",l===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 tT.InvalidStateError(this._session.status);this._contentType=l,this._body=s;const i=nT.cloneArray(n.extraHeaders);i.push(`Content-Type: ${l}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(eT.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:a=>{this.emit("succeeded",{originator:"remote",response:a})},onErrorResponse:a=>{this.emit("failed",{originator:"remote",response:a})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:s})}init_incoming(l){this._direction="incoming",this.request=l,l.reply(200),this._contentType=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0,this._body=l.body,this._session.newInfo({originator:"remote",info:this,request:l})}};const Wa=$e(_d),sT=ht,fd=Ne,rT=new sT("RTCSession:ReferNotifier"),Ya={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var pd=class{constructor(l,s,n){this._session=l,this._id=s,this._expires=n||Ya.expires,this._active=!0,this.notify(100)}notify(l,s){if(rT.debug("notify()"),this._active===!1)return;s=s||fd.REASON_PHRASE[l]||"";let n;l>=200?n="terminated;reason=noresource":n=`active;expires=${this._expires}`,this._session.sendRequest(fd.NOTIFY,{extraHeaders:[`Event: ${Ya.event_type};id=${this._id}`,`Subscription-State: ${n}`,`Content-Type: ${Ya.body_type}`],body:`SIP/2.0 ${l} ${s}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const iT=$e(pd),oT=_t.EventEmitter,lT=ht,Nr=Ne,aT=Xt(),md=yt(),us=new lT("RTCSession:ReferSubscriber");var gd=class extends oT{constructor(l){super(),this._id=null,this._session=l}get id(){return this._id}sendRefer(l,s={}){us.debug("sendRefer()");const n=md.cloneArray(s.extraHeaders),i=md.cloneObject(s.eventHandlers);for(const _ in i)Object.prototype.hasOwnProperty.call(i,_)&&this.on(_,i[_]);let a=null;s.replaces&&(a=s.replaces._request.call_id,a+=`;to-tag=${s.replaces._to_tag}`,a+=`;from-tag=${s.replaces._from_tag}`,a=encodeURIComponent(a));const e=`Refer-To: <${l}${a?`?Replaces=${a}`:""}>`;if(n.push(e),!n.some(_=>_.toLowerCase().startsWith("referred-by:"))){const _=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;n.push(_)}n.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest(Nr.REFER,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{this._requestSucceeded(_)},onErrorResponse:_=>{this._requestFailed(_,Nr.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,Nr.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,Nr.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,Nr.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(l){if(us.debug("receiveNotify()"),!l.body)return;const s=aT.parse(l.body.trim().split(`\r
115
- `,1)[0],"Status_Line");if(s===-1){us.debug(`receiveNotify() | error parsing NOTIFY body: "${l.body}"`);return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:l,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:l,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:l,status_line:s});break;default:this.emit("failed",{request:l,status_line:s});break}}_requestSucceeded(l){us.debug("REFER succeeded"),us.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:l})}_requestFailed(l,s){us.debug("REFER failed"),us.debug('emit "requestFailed"'),this.emit("requestFailed",{response:l||null,cause:s})}};const uT=$e(gd),cT=_t.EventEmitter,Td=Pt,hT=ht,de=Ne,cs=bn,vd=Ys,We=yt(),Dr=Ha,dT=St,El=ud,_T=zs,Vt=dd,yd=_d,fT=pd,pT=gd,Ed=Sn(),K=new hT("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},Sl=["audio","video"];var Sd=class _c extends cT{static get C(){return Q}constructor(s){K.debug("new"),super(),this._id=null,this._ua=s,this._status=Q.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:de.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Q}get causes(){return de.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(s){this._data=s}get status(){return this._status}isInProgress(){switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:case Q.STATUS_INVITE_RECEIVED:case Q.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Q.STATUS_CANCELED:case Q.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(s,n={},i){K.debug("connect()");const a=s,e=We.cloneObject(n.eventHandlers),d=We.cloneArray(n.extraHeaders),_=We.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),u=n.mediaStream||null,g=We.cloneObject(n.pcConfig,{iceServers:[]}),p=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new cs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new cs.NotSupportedError("WebRTC not supported");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);this._sessionTimers.enabled&&We.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=de.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=de.SESSION_EXPIRES);for(const w in e)Object.prototype.hasOwnProperty.call(e,w)&&this.on(w,e[w]);this._from_tag=We.newTag();const y=n.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(A.from_display_name="Anonymous",A.from_uri=new Ed("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):n.fromUserName&&(A.from_uri=new Ed("sip",n.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(A.from_display_name=n.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new dT.InitialOutgoingInviteRequest(s,this._ua,A,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,p),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,i&&i(this),this._newRTCSession("local",this._request),this._sendInitialRequest(_,T,u)}init_incoming(s,n){K.debug("init_incoming()");let i;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(i=s.getHeader("expires")*1e3),s.to_tag=We.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,de.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,de.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,n&&n(this),this._newRTCSession("remote",s),this._status!==Q.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){K.debug("answer()");const n=this._request,i=We.cloneArray(s.extraHeaders),a=We.cloneObject(s.mediaConstraints),e=s.mediaStream||null,d=We.cloneObject(s.pcConfig,{iceServers:[]}),_=s.rtcConstraints||null,u=s.rtcAnswerConstraints||null,g=We.cloneObject(s.rtcOfferConstraints);let p,T=!1,y=!1,A=!1,w=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new cs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new cs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&We.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=de.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=de.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);const R=n.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const b of R.media)b.type==="audio"&&(T=!0,(!b.direction||b.direction==="sendrecv")&&(A=!0)),b.type==="video"&&(y=!0,(!b.direction||b.direction==="sendrecv")&&(w=!0));if(e&&a.audio===!1){p=e.getAudioTracks();for(const b of p)e.removeTrack(b)}if(e&&a.video===!1){p=e.getVideoTracks();for(const b of p)e.removeTrack(b)}!e&&a.audio===void 0&&(a.audio=A),!e&&a.video===void 0&&(a.video=w),!e&&!T&&!g.offerToReceiveAudio&&(a.audio=!1),!e&&!y&&!g.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(d,_),Promise.resolve().then(()=>{if(e)return e;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(b=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,de.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',b),this.emit("getusermediafailed",b),new Error("getUserMedia() failed"))})}).then(b=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=b,b&&b.getTracks().forEach(G=>{this._connection.addTrack(G,b)})}).then(()=>{if(this._late_sdp)return;const b={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",b);const G=new RTCSessionDescription({type:"offer",sdp:b.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(G)).catch(P=>{throw n.reply(488),this._failed("system",null,de.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',P),this.emit("peerconnection:setremotedescriptionfailed",P),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",u).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(b=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,b,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,b),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,de.causes.CONNECTION_ERROR)})}).catch(b=>{this._status!==Q.STATUS_TERMINATED&&K.warn(b)})}terminate(s={}){K.debug("terminate()");const n=s.cause||de.causes.BYE,i=We.cloneArray(s.extraHeaders),a=s.body;let e,d=s.status_code,_=s.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new cs.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"),d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||de.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=Q.STATUS_CANCELED,this._failed("local",null,de.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.debug("rejecting session"),d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,de.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),_=s.reason_phrase||de.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==vd.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===de.ACK&&(this.sendRequest(de.BYE,{extraHeaders:i,body:a}),u.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===vd.C.STATUS_TERMINATED&&(this.sendRequest(de.BYE,{extraHeaders:i,body:a}),u.terminate())}),this._ended("local",null,n),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(de.BYE,{extraHeaders:i,body:a}),this._ended("local",null,n)}}sendDTMF(s,n={}){K.debug("sendDTMF() | tones: %s",s);let i=0,a=n.duration||null,e=n.interToneGap||null;const d=n.transportType||de.DTMF_TRANSPORT.INFO;if(s===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 cs.InvalidStateError(this._status);if(d!==de.DTMF_TRANSPORT.INFO&&d!==de.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${d}`);if(typeof s=="number"&&(s=s.toString()),!s||typeof s!="string"||!s.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${s}`);if(a&&!We.isDecimal(a))throw new TypeError(`Invalid tone duration: ${a}`);if(a?a<Vt.C.MIN_DURATION?(K.debug(`"duration" value is lower than the minimum allowed, setting it to ${Vt.C.MIN_DURATION} milliseconds`),a=Vt.C.MIN_DURATION):a>Vt.C.MAX_DURATION?(K.debug(`"duration" value is greater than the maximum allowed, setting it to ${Vt.C.MAX_DURATION} milliseconds`),a=Vt.C.MAX_DURATION):a=Math.abs(a):a=Vt.C.DEFAULT_DURATION,n.duration=a,e&&!We.isDecimal(e))throw new TypeError(`Invalid interToneGap: ${e}`);if(e?e<Vt.C.MIN_INTER_TONE_GAP?(K.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${Vt.C.MIN_INTER_TONE_GAP} milliseconds`),e=Vt.C.MIN_INTER_TONE_GAP):e=Math.abs(e):e=Vt.C.DEFAULT_INTER_TONE_GAP,d===de.DTMF_TRANSPORT.RFC2833){const u=this._getDTMFRTPSender();u&&(s=u.toneBuffer+s,u.insertDTMF(s,a,e));return}if(this._tones){this._tones+=s;return}this._tones=s,_.call(this);function _(){let u;if(this._status===Q.STATUS_TERMINATED||!this._tones||i>=this._tones.length){this._tones=null;return}const g=this._tones[i];if(i+=1,g===",")u=2e3;else{const p=new Vt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},p.send(g,n),u=a+e}setTimeout(_.bind(this),u)}}sendInfo(s,n,i={}){if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new cs.InvalidStateError(this._status);new yd(this).send(s,n,i)}mute(s={audio:!0,video:!1}){K.debug("mute()");let n=!1,i=!1;this._audioMuted===!1&&s.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(i=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||i===!0)&&this._onmute({audio:n,video:i})}unmute(s={audio:!0,video:!0}){K.debug("unmute()");let n=!1,i=!1;this._audioMuted===!0&&s.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(i=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||i===!0)&&this._onunmute({audio:n,video:i})}hold(s={},n){if(K.debug("hold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const i={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:de.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:s.extraHeaders}),!0}unhold(s={},n){if(K.debug("unhold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const i={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:de.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},n){K.debug("renegotiate()");const i=s.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:de.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:i,extraHeaders:s.extraHeaders}),!0}refer(s,n){K.debug("refer()");const i=s;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${i}`);const a=new pT(this);a.sendRefer(s,n);const e=a.id;return this._referSubscribers[e]=a,a.on("requestFailed",()=>{delete this._referSubscribers[e]}),a.on("accepted",()=>{delete this._referSubscribers[e]}),a.on("failed",()=>{delete this._referSubscribers[e]}),a}sendRequest(s,n){return K.debug("sendRequest()"),this._dialog.sendRequest(s,n)}receiveRequest(s){if(K.debug("receiveRequest()"),s.method===de.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",s,de.causes.CANCELED));else switch(s.method){case de.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(!s.body){this.terminate({cause:de.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:s.body};K.debug('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:de.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case de.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,de.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,de.causes.BYE)):s.reply(403,"Wrong Status");break;case de.INVITE:this._status===Q.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case de.INFO:if(this._status===Q.STATUS_1XX_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED||this._status===Q.STATUS_WAITING_FOR_ACK||this._status===Q.STATUS_CONFIRMED){const n=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Vt(this).init_incoming(s):n!==void 0?new yd(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case de.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case de.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case de.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:de.causes.CONNECTION_ERROR,cause:de.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:de.causes.REQUEST_TIMEOUT,cause:de.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:de.causes.DIALOG_ERROR,cause:de.causes.DIALOG_ERROR})}newDTMF(s){K.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){K.debug("newInfo()"),this.emit("newInfo",s)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),We.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){K.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,n){let i=Dr.T1;function a(){this._status===Q.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],n),i<Dr.T2&&(i=i*2,i>Dr.T2&&(i=Dr.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),i))}this._timers.invite2xxTimer=setTimeout(a.bind(this),i)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(de.BYE),this._ended("remote",null,de.causes.NO_ACK))},Dr.TIMER_H)}_createRTCConnection(s,n){this._connection=new RTCPeerConnection(s,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:de.causes.RTP_TIMEOUT,status_code:408,reason_phrase:de.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,n){if(K.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const i=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?i.createOffer(n).catch(a=>(K.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):i.createAnswer(n).catch(a=>(K.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>i.setLocalDescription(a).catch(e=>(this._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),this.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)))).then(()=>{const a=n&&n.iceRestart;if(i.iceGatheringState==="complete"&&!a||i.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const e={originator:"local",type:s,sdp:i.localDescription.sdp};return K.debug('emit "sdp"'),this.emit("sdp",e),Promise.resolve(e.sdp)}return new Promise(e=>{let d=!1,_,u;this._iceReady=!1;const g=()=>{i.removeEventListener("icecandidate",_),i.removeEventListener("icegatheringstatechange",u),d=!0,this._rtcReady=!0,this._iceReady=!0;const p={originator:"local",type:s,sdp:i.localDescription.sdp};K.debug('emit "sdp"'),this.emit("sdp",p),e(p.sdp)};i.addEventListener("icecandidate",_=p=>{const T=p.candidate;T?this.emit("icecandidate",{candidate:T,ready:g}):d||g()}),i.addEventListener("icegatheringstatechange",u=()=>{i.iceGatheringState==="complete"&&!d&&g()})})})}_createDialog(s,n,i){const a=n==="UAS"?s.to_tag:s.from_tag,e=n==="UAS"?s.from_tag:s.to_tag,d=s.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new El(this,s,n,El.C.STATUS_EARLY),_.error?(K.debug(_.error),this._failed("remote",s,de.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,_)return _.update(s,n),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new El(this,s,n);return u.error?(K.debug(u.error),this._failed("remote",s,de.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_receiveReinvite(s){K.debug("receiveReinvite()");const n=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,i={request:s,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",p=We.cloneArray(_.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);s.reply(u,g,p)}if(this.emit("reinvite",i),a)return;if(this._late_sdp=!1,!s.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(_=>{d.call(this,_)}).catch(()=>{s.reply(500)});return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Q.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{K.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,u),this._late_sdp&&(_=this._mangleOffer(_)),s.reply(200,null,u,_,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,_),this._setACKTimer()}),typeof i.callback=="function"&&i.callback()}}_receiveUpdate(s){K.debug("receiveUpdate()");const n=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,i={request:s,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",p=We.cloneArray(_.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);s.reply(u,g,p)}if(this.emit("update",i),a)return;if(!s.body){d.call(this,null);return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Q.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{K.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,u),s.reply(200,null,u,_),typeof i.callback=="function"&&i.callback()}}_processInDialogSdpOffer(s){K.debug("_processInDialogSdpOffer()");const n=s.parseSDP();let i=!1;for(const d of n.media){if(Sl.indexOf(d.type)===-1)continue;const _=d.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="inactive")i=!0;else{i=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};K.debug('emit "sdp"'),this.emit("sdp",a);const e=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(e).catch(d=>{throw s.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),this.emit("peerconnection:setremotedescriptionfailed",d),d})}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&i===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&i===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(d=>{throw s.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',d),d})}).catch(d=>{K.warn("_processInDialogSdpOffer() failed [error: %o]",d)}),this._connectionPromiseQueue}_receiveRefer(s){if(K.debug("receiveRefer()"),!s.refer_to){K.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==de.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const n=new fT(this,s.cseq);K.debug('emit "refer"'),this.emit("refer",{request:s,accept:(e,d)=>{i.call(this,e,d)},reject:()=>{a.call(this)}});function i(e,d={}){if(e=typeof e=="function"?e:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const _=new _c(this._ua);if(_.on("progress",({response:u})=>{n.notify(u.status_code,u.reason_phrase)}),_.on("accepted",({response:u})=>{n.notify(u.status_code,u.reason_phrase)}),_.on("_failed",({message:u,cause:g})=>{u?n.notify(u.status_code,u.reason_phrase):n.notify(487,g)}),s.refer_to.uri.hasHeader("replaces")){const u=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));d.extraHeaders=We.cloneArray(d.extraHeaders),d.extraHeaders.push(`Replaces: ${u}`)}_.connect(s.refer_to.uri.toAor(),d,e)}function a(){n.notify(603)}}_receiveNotify(s){switch(K.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let n,i;if(s.event.params&&s.event.params.id)n=s.event.params.id,i=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)i=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!i){s.reply(481,"Subscription does not exist");return}i.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){K.debug("receiveReplaces()");function n(a){if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const e=new _c(this._ua);e.on("confirmed",()=>{this.terminate()}),e.init_incoming(s,a)}function i(){K.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{n.call(this,a)},reject:()=>{i.call(this)}})}_sendInitialRequest(s,n,i){const a=new _T(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});Promise.resolve().then(()=>{if(i)return i;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(e=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,de.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),e)})}).then(e=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=e,e&&e.getTracks().forEach(d=>{this._connection.addTrack(d,e)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(d=>{throw this._failed("local",null,de.causes.WEBRTC_ERROR),d})}).then(e=>{if(this._is_canceled||this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._request.body=e,this._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==Q.STATUS_TERMINATED&&K.warn(e)})}_getDTMFRTPSender(){const s=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(s&&s.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return s.dtmf}_receiveInviteResponse(s){if(K.debug("receiveInviteResponse()"),this._dialog&&s.status_code>=200&&s.status_code<=299)if(this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest(de.ACK);return}else{const n=new El(this,s,"UAC");if(n.error!==void 0){K.debug(n.error);return}this.sendRequest(de.ACK),this.sendRequest(de.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){K.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const n={originator:"remote",type:"answer",sdp:s.body};K.debug('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",s)).catch(a=>{K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=Q.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,de.causes.MISSING_SDP),this._failed("remote",s,de.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const n={originator:"remote",type:"answer",sdp:s.body};K.debug('emit "sdp"'),this.emit("sdp",n);const i=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(s,500,a.toString()),this._failed("local",s,de.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(i).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest(de.ACK),this._confirmed("local",null)}).catch(a=>{this._acceptAndTerminate(s,488,"Not Acceptable Here"),this._failed("remote",s,de.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})});break}default:{const n=We.sipErrorCause(s.status_code);this._failed("remote",s,n)}}}_sendReinvite(s={}){K.debug("sendReinvite()");const n=We.cloneArray(s.extraHeaders),i=We.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let e=!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(u=>{u=this._mangleOffer(u);const g={originator:"local",type:"offer",sdp:u};K.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(de.INVITE,{extraHeaders:n,body:u,eventHandlers:{onSuccessResponse:p=>{d.call(this,p),e=!0},onErrorResponse:p=>{_.call(this,p)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function d(u){if(this._status===Q.STATUS_TERMINATED||(this.sendRequest(de.ACK),e))return;if(this._handleSessionTimersInIncomingResponse(u),u.body){if(!u.hasHeader("Content-Type")||u.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:u.body};K.debug('emit "sdp"'),this.emit("sdp",g);const p=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(p)).then(()=>{i.succeeded&&i.succeeded(u)}).catch(T=>{_.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(u){i.failed&&i.failed(u)}}_sendUpdate(s={}){K.debug("sendUpdate()");const n=We.cloneArray(s.extraHeaders),i=We.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,e=s.sdpOffer||!1;let d=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),e?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const p={originator:"local",type:"offer",sdp:g};K.debug('emit "sdp"'),this.emit("sdp",p),this.sendRequest(de.UPDATE,{extraHeaders:n,body:g,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),d=!0},onErrorResponse:T=>{u.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{u.call(this)})):this.sendRequest(de.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:g=>{_.call(this,g)},onErrorResponse:g=>{u.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(g){if(this._status!==Q.STATUS_TERMINATED&&!d)if(this._handleSessionTimersInIncomingResponse(g),e){if(g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){u.call(this);return}}else{u.call(this);return}const p={originator:"remote",type:"answer",sdp:g.body};K.debug('emit "sdp"'),this.emit("sdp",p);const T=new RTCSessionDescription({type:"answer",sdp:p.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{i.succeeded&&i.succeeded(g)}).catch(y=>{u.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',y),this.emit("peerconnection:setremotedescriptionfailed",y)})}else i.succeeded&&i.succeeded(g)}function u(g){i.failed&&i.failed(g)}}_acceptAndTerminate(s,n,i){K.debug("acceptAndTerminate()");const a=[];n&&(i=i||de.REASON_PHRASE[n]||"",a.push(`Reason: SIP ;cause=${n}; text="${i}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest(de.ACK),this.sendRequest(de.BYE,{extraHeaders:a})),this._status=Q.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=Td.parse(s),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const n of s.media)Sl.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");for(const n of s.media)Sl.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");for(const n of s.media)Sl.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Td.write(s)}_setLocalMediaStatus(){let s=!0,n=!0;(this._localHold||this._remoteHold)&&(s=!1,n=!1),this._audioMuted&&(s=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(s,n){if(!this._sessionTimers.enabled)return;let i;s.session_expires&&s.session_expires>=de.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,i=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${i}`),this._sessionTimers.refresher=i==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let n;s.session_expires&&s.session_expires>=de.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,n=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&this._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===de.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:de.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const n=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="audio");for(const i of n)i.track.enabled=!s}_toggleMuteVideo(s){const n=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="video");for(const i of n)i.track.enabled=!s}_newRTCSession(s,n){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:s,session:this,request:n})}_connecting(s){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,n){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:s,response:n||null})}_accepted(s,n){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:n||null})}_confirmed(s,n){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:n||null})}_ended(s,n,i){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:s,message:n||null,cause:i})}_failed(s,n,i){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:n||null,cause:i}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:s,message:n||null,cause:i})}_onhold(s){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:n}){K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:s,video:n})}_onunmute({audio:s,video:n}){K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:n})}};const mT=$e(Sd),gT=_t.EventEmitter,TT=ht,za=Ne,vT=St,kr=yt(),yT=zs,Ad=bn,ET=Sn(),Al=new TT("Message");var ST=class extends gT{constructor(l){super(),this._ua=l,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(l,s,n={}){const i=l;if(l===void 0||s===void 0)throw new TypeError("Not enough arguments");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError(`Invalid target: ${i}`);const a=kr.cloneArray(n.extraHeaders),e=kr.cloneObject(n.eventHandlers),d=n.contentType||"text/plain",_={};n.fromUserName&&(_.from_uri=new ET("sip",n.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(_.from_display_name=n.fromDisplayName);for(const g in e)Object.prototype.hasOwnProperty.call(e,g)&&this.on(g,e[g]);a.push(`Content-Type: ${d}`),this._request=new vT.OutgoingRequest(za.MESSAGE,l,this._ua,_,a),s&&(this._request.body=s);const u=new yT(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),u.send()}init_incoming(l){this._request=l,this._newMessage("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}accept(l={}){const s=kr.cloneArray(l.extraHeaders),n=l.body;if(this._direction!=="incoming")throw new Ad.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,n)}reject(l={}){const s=l.status_code||480,n=l.reason_phrase,i=kr.cloneArray(l.extraHeaders),a=l.body;if(this._direction!=="incoming")throw new Ad.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: ${s}`);this._is_replied=!0,this._request.reply(s,n,i,a)}_receiveResponse(l){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):this._succeeded("remote",l);break;default:{const s=kr.sipErrorCause(l.status_code);this._failed("remote",l,s);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,za.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,za.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(l,s){l==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):l==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:l,message:this,request:s})}_failed(l,s,n){Al.debug("MESSAGE failed"),this._close(),Al.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:n})}_succeeded(l,s){Al.debug("MESSAGE succeeded"),this._close(),Al.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:s})}};const AT=_t.EventEmitter,CT=ht,Xa=Ne,bT=St,Ur=yt(),RT=zs,Cd=bn,Cl=new CT("Options");var IT=class extends AT{constructor(l){super(),this._ua=l,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(l,s,n={}){const i=l;if(l===void 0)throw new TypeError("A target is required for OPTIONS");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError(`Invalid target: ${i}`);const a=Ur.cloneArray(n.extraHeaders),e=Ur.cloneObject(n.eventHandlers),d=n.contentType||"application/sdp";for(const u in e)Object.prototype.hasOwnProperty.call(e,u)&&this.on(u,e[u]);a.push(`Content-Type: ${d}`),this._request=new bT.OutgoingRequest(Xa.OPTIONS,l,this._ua,null,a),s&&(this._request.body=s);const _=new RT(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:u=>{this._receiveResponse(u)}});this._newOptions("local",this._request),_.send()}init_incoming(l){this._request=l,this._newOptions("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}accept(l={}){const s=Ur.cloneArray(l.extraHeaders),n=l.body;if(this._direction!=="incoming")throw new Cd.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,n)}reject(l={}){const s=l.status_code||480,n=l.reason_phrase,i=Ur.cloneArray(l.extraHeaders),a=l.body;if(this._direction!=="incoming")throw new Cd.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: ${s}`);this._is_replied=!0,this._request.reply(s,n,i,a)}_receiveResponse(l){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):this._succeeded("remote",l);break;default:{const s=Ur.sipErrorCause(l.status_code);this._failed("remote",l,s);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Xa.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Xa.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(l,s){l==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):l==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:l,message:this,request:s})}_failed(l,s,n){Cl.debug("OPTIONS failed"),this._close(),Cl.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:n})}_succeeded(l,s){Cl.debug("OPTIONS succeeded"),this._close(),Cl.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:s})}},Qa={};const wT=ht,Ja=yt(),OT=Xt(),Mr=new wT("Socket");Qa.isSocket=l=>{if(Array.isArray(l))return!1;if(typeof l>"u")return Mr.warn("undefined JsSIP.Socket instance"),!1;try{if(!Ja.isString(l.url))throw Mr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Ja.isString(l.via_transport))throw Mr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(OT.parse(l.sip_uri,"SIP_URI")===-1)throw Mr.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(s){return!1}try{["connect","disconnect","send"].forEach(s=>{if(!Ja.isFunction(l[s]))throw Mr.warn(`missing or invalid JsSIP.Socket method: ${s}`),new Error(`Missing or invalid JsSIP.Socket method: ${s}`)})}catch(s){return!1}return!0};const NT=ht,DT=Qa,bd=Ne,Ht=new NT("Transport"),Yt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:bd.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:bd.CONNECTION_RECOVERY_MAX_INTERVAL}};var Rd=class{constructor(l,s=Yt.recovery_options){Ht.debug("new()"),this.status=Yt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=s,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(n){Ht.warn(`cannot use TextDecoder: ${n}`)}if(typeof l>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");l instanceof Array||(l=[l]),l.forEach(function(n){if(!DT.isSocket(n.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(n.weight&&!Number(n.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:n.socket,weight:n.weight||0,status:Yt.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(Ht.debug("connect()"),this.isConnected()){Ht.debug("Transport is already connected");return}else if(this.isConnecting()){Ht.debug("Transport is connecting");return}this.close_requested=!1,this.status=Yt.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(){Ht.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Yt.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(l){if(Ht.debug("send()"),!this.isConnected())return Ht.warn("unable to send message, transport is not connected"),!1;const s=l.toString();return Ht.debug(`sending message:
112
+ `,this.transport.send(a)}}class Tg extends Bh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var gt={OutgoingRequest:al,InitialOutgoingInviteRequest:wa,IncomingRequest:gg,IncomingResponse:Tg};const $s=We(gt),vg=ot,Tn=ft(),Kt=new vg("DigestAuthentication");var Kh=class{constructor(l){this._credentials=l,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(l){switch(l){case"realm":return this._realm;case"ha1":return this._ha1;default:Kt.warn('get() | cannot get "%s" parameter',l);return}}authenticate({method:l,ruri:n,body:s},i,a=null){if(this._algorithm=i.algorithm,this._realm=i.realm,this._nonce=i.nonce,this._opaque=i.opaque,this._stale=i.stale,this._algorithm){if(this._algorithm!=="MD5")return Kt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Kt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Kt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Kt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Kt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(i.qop)if(i.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(i.qop.indexOf("auth")>-1)this._qop="auth";else return Kt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=l,this._uri=n,this._cnonce=a||Tn.createRandomToken(12),this._nc+=1;const e=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-e.length)+e,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=Tn.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,_;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,_=Tn.calculateMD5(d),Kt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=Tn.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${_}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${Tn.calculateMD5(s||"")}`,_=Tn.calculateMD5(d),Kt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=Tn.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${_}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,_=Tn.calculateMD5(d),Kt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=Tn.calculateMD5(`${this._ha1}:${this._nonce}:${_}`)),Kt.debug("authenticate() | response generated"),!0}toString(){const l=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return l.push(`algorithm=${this._algorithm}`),l.push(`username="${this._credentials.username}"`),l.push(`realm="${this._realm}"`),l.push(`nonce="${this._nonce}"`),l.push(`uri="${this._uri}"`),l.push(`response="${this._response}"`),this._opaque&&l.push(`opaque="${this._opaque}"`),this._qop&&(l.push(`qop=${this._qop}`),l.push(`cnonce="${this._cnonce}"`),l.push(`nc=${this._ncHex}`)),`Digest ${l.join(", ")}`}};const yg=We(Kh),vn=500,Eg=4e3,Gh=5e3;var Oa={T1:vn,T2:Eg,T4:Gh,TIMER_B:64*vn,TIMER_D:0*vn,TIMER_F:64*vn,TIMER_H:64*vn,TIMER_I:0*vn,TIMER_J:0*vn,TIMER_K:0*Gh,TIMER_L:64*vn,TIMER_M:64*vn,PROVISIONAL_RESPONSE_INTERVAL:6e4};const mr=We(Oa),gr=ut.EventEmitter,Tr=ot,vr=Ie,Wh=gt,cn=Oa,Yh=new Tr("NonInviteClientTransaction"),ul=new Tr("InviteClientTransaction"),Sg=new Tr("AckClientTransaction"),zh=new Tr("NonInviteServerTransaction"),cl=new Tr("InviteServerTransaction"),ae={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 Ag extends gr{constructor(n,s,i,a){super(),this.type=ae.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=n,this.transport=s,this.request=i,this.eventHandlers=a;let e=`SIP/2.0/${s.via_transport}`;e+=` ${n.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e),this.ua.newTransaction(this)}get C(){return ae}stateChanged(n){this.state=n,this.emit("stateChanged")}send(){this.stateChanged(ae.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},cn.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){Yh.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){Yh.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(n){const s=n.status_code;if(s<200)switch(this.state){case ae.STATUS_TRYING:case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(n);break}else switch(this.state){case ae.STATUS_TRYING:case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_COMPLETED),clearTimeout(this.F),s===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(n),this.K=setTimeout(()=>{this.timer_K()},cn.TIMER_K);break;case ae.STATUS_COMPLETED:break}}}class Cg extends gr{constructor(n,s,i,a){super(),this.type=ae.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=n,this.transport=s,this.request=i,this.eventHandlers=a,i.transaction=this;let e=`SIP/2.0/${s.via_transport}`;e+=` ${n.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e),this.ua.newTransaction(this)}get C(){return ae}stateChanged(n){this.state=n,this.emit("stateChanged")}send(){this.stateChanged(ae.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},cn.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ae.STATUS_ACCEPTED&&(ul.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){ul.debug(`Timer M expired for transaction ${this.id}`),this.state===ae.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){ul.debug(`Timer B expired for transaction ${this.id}`),this.state===ae.STATUS_CALLING&&(this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){ul.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(n){const s=new Wh.OutgoingRequest(vr.ACK,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",n.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},cn.TIMER_D),this.transport.send(s)}cancel(n){if(this.state!==ae.STATUS_PROCEEDING)return;const s=new Wh.OutgoingRequest(vr.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")),n&&s.setHeader("reason",n),this.transport.send(s)}receiveResponse(n){const s=n.status_code;if(s>=100&&s<=199)switch(this.state){case ae.STATUS_CALLING:this.stateChanged(ae.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(n);break;case ae.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(n);break}else if(s>=200&&s<=299)switch(this.state){case ae.STATUS_CALLING:case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},cn.TIMER_M),this.eventHandlers.onReceiveResponse(n);break;case ae.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(n);break}else if(s>=300&&s<=699)switch(this.state){case ae.STATUS_CALLING:case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_COMPLETED),this.sendACK(n),this.eventHandlers.onReceiveResponse(n);break;case ae.STATUS_COMPLETED:this.sendACK(n);break}}}class bg extends gr{constructor(n,s,i,a){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=s,this.request=i,this.eventHandlers=a;let e=`SIP/2.0/${s.via_transport}`;e+=` ${n.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",e)}get C(){return ae}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Sg.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Rg extends gr{constructor(n,s,i){super(),this.type=ae.NON_INVITE_SERVER,this.id=i.via_branch,this.ua=n,this.transport=s,this.request=i,this.last_response="",i.server_transaction=this,this.state=ae.STATUS_TRYING,n.newTransaction(this)}get C(){return ae}stateChanged(n){this.state=n,this.emit("stateChanged")}timer_J(){zh.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,zh.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(n,s,i,a){if(n===100)switch(this.state){case ae.STATUS_TRYING:this.stateChanged(ae.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ae.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?i&&i():(this.onTransportError(),a&&a());break}else if(n>=200&&n<=699)switch(this.state){case ae.STATUS_TRYING:case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(()=>{this.timer_J()},cn.TIMER_J),this.transport.send(s)?i&&i():(this.onTransportError(),a&&a());break;case ae.STATUS_COMPLETED:break}}}class Ig extends gr{constructor(n,s,i){super(),this.type=ae.INVITE_SERVER,this.id=i.via_branch,this.ua=n,this.transport=s,this.request=i,this.last_response="",i.server_transaction=this,this.state=ae.STATUS_PROCEEDING,n.newTransaction(this),this.resendProvisionalTimer=null,i.reply(100)}get C(){return ae}stateChanged(n){this.state=n,this.emit("stateChanged")}timer_H(){cl.debug(`Timer H expired for transaction ${this.id}`),this.state===ae.STATUS_COMPLETED&&cl.debug("ACK not received, dialog will be terminated"),this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){cl.debug(`Timer L expired for transaction ${this.id}`),this.state===ae.STATUS_ACCEPTED&&(this.stateChanged(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,cl.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(ae.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(n,s,i,a){if(n>=100&&n<=199)switch(this.state){case ae.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(n>100&&n<=199&&this.state===ae.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},cn.PROVISIONAL_RESPONSE_INTERVAL));else if(n>=200&&n<=299)switch(this.state){case ae.STATUS_PROCEEDING:this.stateChanged(ae.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(()=>{this.timer_L()},cn.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ae.STATUS_ACCEPTED:this.transport.send(s)?i&&i():(this.onTransportError(),a&&a());break}else if(n>=300&&n<=699)switch(this.state){case ae.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ae.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},cn.TIMER_H),i&&i()):(this.onTransportError(),a&&a());break}}}function wg({_transactions:l},n){let s;switch(n.method){case vr.INVITE:if(s=l.ist[n.via_branch],s){switch(s.state){case ae.STATUS_PROCEEDING:s.transport.send(s.last_response);break;case ae.STATUS_ACCEPTED:break}return!0}break;case vr.ACK:if(s=l.ist[n.via_branch],s){if(s.state===ae.STATUS_ACCEPTED)return!1;if(s.state===ae.STATUS_COMPLETED)return s.state=ae.STATUS_CONFIRMED,s.I=setTimeout(()=>{s.timer_I()},cn.TIMER_I),!0}else return!1;break;case vr.CANCEL:return s=l.ist[n.via_branch],s?(n.reply_sl(200),s.state!==ae.STATUS_PROCEEDING):(n.reply_sl(481),!0);default:if(s=l.nist[n.via_branch],s){switch(s.state){case ae.STATUS_TRYING:break;case ae.STATUS_PROCEEDING:case ae.STATUS_COMPLETED:s.transport.send(s.last_response);break}return!0}break}}var Vs={C:ae,NonInviteClientTransaction:Ag,InviteClientTransaction:Cg,AckClientTransaction:bg,NonInviteServerTransaction:Rg,InviteServerTransaction:Ig,checkTransaction:wg};const jt=We(Vs),Og=ot,Jh=Ie,Ng=Kh,Na=Vs,Dg=new Og("RequestSender"),Da={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Bs=class{constructor(l,n,s){this._ua=l,this._eventHandlers=s,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const i in Da)Object.prototype.hasOwnProperty.call(Da,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=Da[i]));l.status===l.C.STATUS_USER_CLOSED&&(this._method!==Jh.BYE||this._method!==Jh.ACK)&&this._eventHandlers.onTransportError()}send(){const l={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}};switch(this._method){case"INVITE":this.clientTransaction=new Na.InviteClientTransaction(this._ua,this._ua.transport,this._request,l);break;case"ACK":this.clientTransaction=new Na.AckClientTransaction(this._ua,this._ua.transport,this._request,l);break;default:this.clientTransaction=new Na.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,l)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(l){let n,s;const i=l.status_code;if((i===401||i===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(l.status_code===401?(n=l.parseHeader("www-authenticate"),s="authorization"):(n=l.parseHeader("proxy-authenticate"),s="proxy-authorization"),!n){Dg.debug(`${l.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(l);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(l);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(s,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(l)}else this._eventHandlers.onReceiveResponse(l)}};const yr=We(Bs),kg=ot,ka=ft(),ss=Ie,Xh=gt,Qh=Bs,Er=new kg("Registrator"),hl=10;var Ug=class{constructor(l,n){this._reg_id=1,this._ua=l,this._transport=n,this._registrar=l.configuration.registrar_server,this._expires=l.configuration.register_expires,this._call_id=ka.createRandomToken(22),this._cseq=0,this._to_uri=l.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(l){Array.isArray(l)||(l=[]),this._extraHeaders=l.slice()}setExtraContactParams(l){l instanceof Object||(l={}),this._extraContactParams="";for(const n in l)if(Object.prototype.hasOwnProperty.call(l,n)){const s=l[n];this._extraContactParams+=`;${n}`,s&&(this._extraContactParams+=`=${s}`)}}register(){if(this._registering){Er.debug("Register request in progress...");return}const l=this._extraHeaders.slice();l.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),l.push(`Expires: ${this._expires}`);const n=new Xh.OutgoingRequest(ss.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l),s=new Qh(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,ss.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,ss.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:i=>{if(i.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):{if(this._registering=!1,!i.hasHeader("Contact")){Er.debug("no Contact header in response to REGISTER, response ignored");break}const a=i.headers.Contact.reduce((u,g)=>u.concat(g.parsed),[]);let e=a.find(u=>this._sipInstance===u.getParam("+sip.instance")&&this._reg_id===parseInt(u.getParam("reg-id")));if(e||(e=a.find(u=>u.uri.user===this._ua.contact.uri.user)),!e){Er.debug("no Contact header pointing to us, response ignored");break}let d=e.getParam("expires");!d&&i.hasHeader("expires")&&(d=i.getHeader("expires")),d||(d=this._expires),d=Number(d),d<hl&&(d=hl);const _=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},_),e.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=e.getParam("temp-gruu").replace(/"/g,"")),e.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=e.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:i}));break}case/^423$/.test(i.status_code):{i.hasHeader("min-expires")?(this._expires=Number(i.getHeader("min-expires")),this._expires<hl&&(this._expires=hl),this.register()):(Er.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(i,ss.causes.SIP_FAILURE_CODE));break}default:{const a=ka.sipErrorCause(i.status_code);this._registrationFailure(i,a)}}}});this._registering=!0,s.send()}unregister(l={}){if(!this._registered){Er.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();l.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push("Expires: 0");const s=new Xh.OutgoingRequest(ss.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new Qh(this._ua,s,{onRequestTimeout:()=>{this._unregistered(null,ss.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,ss.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:i=>{switch(!0){case/^1[0-9]{2}$/.test(i.status_code):break;case/^2[0-9]{2}$/.test(i.status_code):this._unregistered(i);break;default:{const a=ka.sipErrorCause(i.status_code);this._unregistered(i,a)}}}}).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(l,n){this._registering=!1,this._ua.registrationFailed({response:l||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:l||null,cause:n}))}_unregistered(l,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:l||null,cause:n||null})}};class Mg extends Error{constructor(n,s){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=n,this.value=s,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class Pg extends Error{constructor(n){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=n,this.message=`Invalid status: ${n}`}}class xg extends Error{constructor(n){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=n}}class Lg extends Error{constructor(n){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=n}}var yn={ConfigurationError:Mg,InvalidStateError:Pg,NotSupportedError:xg,NotReadyError:Lg};const Kn=We(yn),Ua=Ie,dl=Vs,Hg=Bs,Ma={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var Zh=class{constructor(l,n,s){this._dialog=l,this._ua=l._ua,this._request=n,this._eventHandlers=s,this._reattempt=!1,this._reattemptTimer=null;for(const i in Ma)Object.prototype.hasOwnProperty.call(Ma,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=Ma[i]))}get request(){return this._request}send(){const l=new Hg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(l.send(),(this._request.method===Ua.INVITE||this._request.method===Ua.UPDATE&&this._request.body)&&l.clientTransaction.state!==dl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(l.clientTransaction.state===dl.C.STATUS_ACCEPTED||l.clientTransaction.state===dl.C.STATUS_COMPLETED||l.clientTransaction.state===dl.C.STATUS_TERMINATED)&&(l.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};l.clientTransaction.on("stateChanged",n)}}_receiveResponse(l){l.status_code===408||l.status_code===481?this._eventHandlers.onDialogError(l):l.method===Ua.INVITE&&l.status_code===491?this._reattempt?l.status_code>=200&&l.status_code<300?this._eventHandlers.onSuccessResponse(l):l.status_code>=300&&this._eventHandlers.onErrorResponse(l):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):l.status_code>=200&&l.status_code<300?this._eventHandlers.onSuccessResponse(l):l.status_code>=300&&this._eventHandlers.onErrorResponse(l)}};const qg=We(Zh),Fg=ot,ed=gt,Gn=Ie,Sr=Vs,jg=Zh,Pa=ft(),xa=new Fg("Dialog"),Wn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var td=class{static get C(){return Wn}constructor(l,n,s,i=Wn.STATUS_CONFIRMED){if(this._owner=l,this._ua=l._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 ed.IncomingResponse&&(i=n.status_code<200?Wn.STATUS_EARLY:Wn.STATUS_CONFIRMED);const a=n.parseHeader("contact");s==="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=i,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=a.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):s==="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=i,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=a.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),xa.debug(`new ${s} dialog created with status ${this._state===Wn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(l){this._local_seqnum=l}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(l){this._uac_pending_reply=l}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Wn.STATUS_TERMINATED}update(l,n){this._state=Wn.STATUS_CONFIRMED,xa.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=l.getHeaders("record-route").reverse())}terminate(){xa.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Wn.STATUS_TERMINATED}sendRequest(l,n={}){const s=Pa.cloneArray(n.extraHeaders),i=Pa.cloneObject(n.eventHandlers),a=n.body||null,e=this._createRequest(l,s,a);return i.onAuthenticated=()=>{this._local_seqnum+=1},new jg(this,e,i).send(),e}receiveRequest(l){this._checkInDialogRequest(l)&&(l.method===Gn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:l.method===Gn.INVITE&&(this._ack_seqnum=l.cseq),this._owner.receiveRequest(l))}_createRequest(l,n,s){n=Pa.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const i=l===Gn.CANCEL||l===Gn.ACK?this._local_seqnum:this._local_seqnum+=1;return new ed.OutgoingRequest(l,this._remote_target,this._ua,{cseq:i,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,s)}_checkInDialogRequest(l){if(!this._remote_seqnum)this._remote_seqnum=l.cseq;else if(l.cseq<this._remote_seqnum)if(l.method===Gn.ACK){if(this._ack_seqnum===null||l.cseq!==this._ack_seqnum)return!1}else return l.reply(500),!1;else l.cseq>this._remote_seqnum&&(this._remote_seqnum=l.cseq);if(l.method===Gn.INVITE||l.method===Gn.UPDATE&&l.body){if(this._uac_pending_reply===!0)l.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return l.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(l.server_transaction.state===Sr.C.STATUS_ACCEPTED||l.server_transaction.state===Sr.C.STATUS_COMPLETED||l.server_transaction.state===Sr.C.STATUS_TERMINATED)&&(l.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};l.server_transaction.on("stateChanged",n)}l.hasHeader("contact")&&l.server_transaction.on("stateChanged",()=>{l.server_transaction.state===Sr.C.STATUS_ACCEPTED&&(this._remote_target=l.parseHeader("contact").uri)})}else l.method===Gn.NOTIFY&&l.hasHeader("contact")&&l.server_transaction.on("stateChanged",()=>{l.server_transaction.state===Sr.C.STATUS_COMPLETED&&(this._remote_target=l.parseHeader("contact").uri)});return!0}};const _l=We(td);var La={exports:{}};const $g=ut.EventEmitter,Vg=ot,Bg=Ie,Kg=yn,nd=ft(),Gg=new Vg("RTCSession:DTMF"),sd={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};La.exports=class extends $g{constructor(l){super(),this._session=l,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(l,n={}){if(l===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 Kg.InvalidStateError(this._session.status);const s=nd.cloneArray(n.extraHeaders);if(this.eventHandlers=nd.cloneObject(n.eventHandlers),typeof l=="string")l=l.toUpperCase();else if(typeof l=="number")l=l.toString();else throw new TypeError(`Invalid tone: ${l}`);if(l.match(/^[0-9A-DR#*]$/))this._tone=l;else throw new TypeError(`Invalid tone: ${l}`);this._duration=n.duration,s.push("Content-Type: application/dtmf-relay");let i=`Signal=${this._tone}\r
113
+ `;i+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(Bg.INFO,{extraHeaders:s,eventHandlers:{onSuccessResponse:a=>{this.emit("succeeded",{originator:"remote",response:a})},onErrorResponse:a=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:a})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:i})}init_incoming(l){const n=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,s=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=l,l.reply(200),l.body){const i=l.body.split(`
114
+ `);i.length>=1&&n.test(i[0])&&(this._tone=i[0].replace(n,"$2")),i.length>=2&&s.test(i[1])&&(this._duration=parseInt(i[1].replace(s,"$2"),10))}this._duration||(this._duration=sd.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:l}):Gg.debug("invalid INFO DTMF received, discarded")}},La.exports.C=sd;var rd=La.exports;const Wg=We(rd),Yg=ut.EventEmitter,zg=Ie,Jg=yn,Xg=ft();var id=class extends Yg{constructor(l){super(),this._session=l,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(l,n,s={}){if(this._direction="outgoing",l===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 Jg.InvalidStateError(this._session.status);this._contentType=l,this._body=n;const i=Xg.cloneArray(s.extraHeaders);i.push(`Content-Type: ${l}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(zg.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:a=>{this.emit("succeeded",{originator:"remote",response:a})},onErrorResponse:a=>{this.emit("failed",{originator:"remote",response:a})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:n})}init_incoming(l){this._direction="incoming",this.request=l,l.reply(200),this._contentType=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0,this._body=l.body,this._session.newInfo({originator:"remote",info:this,request:l})}};const Ha=We(id),Qg=ot,od=Ie,Zg=new Qg("RTCSession:ReferNotifier"),qa={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var ld=class{constructor(l,n,s){this._session=l,this._id=n,this._expires=s||qa.expires,this._active=!0,this.notify(100)}notify(l,n){if(Zg.debug("notify()"),this._active===!1)return;n=n||od.REASON_PHRASE[l]||"";let s;l>=200?s="terminated;reason=noresource":s=`active;expires=${this._expires}`,this._session.sendRequest(od.NOTIFY,{extraHeaders:[`Event: ${qa.event_type};id=${this._id}`,`Subscription-State: ${s}`,`Content-Type: ${qa.body_type}`],body:`SIP/2.0 ${l} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const eT=We(ld),tT=ut.EventEmitter,nT=ot,Ar=Ie,sT=Bt(),ad=ft(),rs=new nT("RTCSession:ReferSubscriber");var ud=class extends tT{constructor(l){super(),this._id=null,this._session=l}get id(){return this._id}sendRefer(l,n={}){rs.debug("sendRefer()");const s=ad.cloneArray(n.extraHeaders),i=ad.cloneObject(n.eventHandlers);for(const _ in i)Object.prototype.hasOwnProperty.call(i,_)&&this.on(_,i[_]);let a=null;n.replaces&&(a=n.replaces._request.call_id,a+=`;to-tag=${n.replaces._to_tag}`,a+=`;from-tag=${n.replaces._from_tag}`,a=encodeURIComponent(a));const e=`Refer-To: <${l}${a?`?Replaces=${a}`:""}>`;if(s.push(e),!s.some(_=>_.toLowerCase().startsWith("referred-by:"))){const _=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;s.push(_)}s.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest(Ar.REFER,{extraHeaders:s,eventHandlers:{onSuccessResponse:_=>{this._requestSucceeded(_)},onErrorResponse:_=>{this._requestFailed(_,Ar.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,Ar.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,Ar.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,Ar.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(l){if(rs.debug("receiveNotify()"),!l.body)return;const n=sT.parse(l.body.trim().split(`\r
115
+ `,1)[0],"Status_Line");if(n===-1){rs.debug(`receiveNotify() | error parsing NOTIFY body: "${l.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:l,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:l,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:l,status_line:n});break;default:this.emit("failed",{request:l,status_line:n});break}}_requestSucceeded(l){rs.debug("REFER succeeded"),rs.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:l})}_requestFailed(l,n){rs.debug("REFER failed"),rs.debug('emit "requestFailed"'),this.emit("requestFailed",{response:l||null,cause:n})}};const rT=We(ud),iT=ut.EventEmitter,cd=Dt,oT=ot,ue=Ie,is=yn,hd=Vs,Be=ft(),Cr=Oa,lT=gt,pl=td,aT=Bs,Lt=rd,dd=id,uT=ld,cT=ud,_d=gn(),K=new oT("RTCSession"),J={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},fl=["audio","video"];var pd=class ic extends iT{static get C(){return J}constructor(n){K.debug("new"),super(),this._id=null,this._ua=n,this._status=J.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:ue.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return J}get causes(){return ue.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(n){this._data=n}get status(){return this._status}isInProgress(){switch(this._status){case J.STATUS_NULL:case J.STATUS_INVITE_SENT:case J.STATUS_1XX_RECEIVED:case J.STATUS_INVITE_RECEIVED:case J.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case J.STATUS_ANSWERED:case J.STATUS_WAITING_FOR_ACK:case J.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case J.STATUS_CANCELED:case J.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(n,s={},i){K.debug("connect()");const a=n,e=Be.cloneObject(s.eventHandlers),d=Be.cloneArray(s.extraHeaders),_=Be.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),u=s.mediaStream||null,g=Be.cloneObject(s.pcConfig,{iceServers:[]}),f=s.rtcConstraints||null,T=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,n===void 0)throw new TypeError("Not enough arguments");if(this._status!==J.STATUS_NULL)throw new is.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new is.NotSupportedError("WebRTC not supported");if(n=this._ua.normalizeTarget(n),!n)throw new TypeError(`Invalid target: ${a}`);this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ue.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ue.SESSION_EXPIRES);for(const w in e)Object.prototype.hasOwnProperty.call(e,w)&&this.on(w,e[w]);this._from_tag=Be.newTag();const y=s.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(A.from_display_name="Anonymous",A.from_uri=new _d("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):s.fromUserName&&(A.from_uri=new _d("sip",s.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),s.fromDisplayName&&(A.from_display_name=s.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new lT.InitialOutgoingInviteRequest(n,this._ua,A,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,f),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,i&&i(this),this._newRTCSession("local",this._request),this._sendInitialRequest(_,T,u)}init_incoming(n,s){K.debug("init_incoming()");let i;const a=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0;if(n.body&&a!=="application/sdp"){n.reply(415);return}if(this._status=J.STATUS_INVITE_RECEIVED,this._from_tag=n.from_tag,this._id=n.call_id+this._from_tag,this._request=n,this._contact=this._ua.contact.toString(),n.hasHeader("expires")&&(i=n.getHeader("expires")*1e3),n.to_tag=Be.newTag(),!this._createDialog(n,"UAS",!0)){n.reply(500,"Missing Contact header field");return}n.body?this._late_sdp=!1:this._late_sdp=!0,this._status=J.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{n.reply(408),this._failed("local",null,ue.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===J.STATUS_WAITING_FOR_ANSWER&&(n.reply(487),this._failed("system",null,ue.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from,s&&s(this),this._newRTCSession("remote",n),this._status!==J.STATUS_TERMINATED&&(n.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(n={}){K.debug("answer()");const s=this._request,i=Be.cloneArray(n.extraHeaders),a=Be.cloneObject(n.mediaConstraints),e=n.mediaStream||null,d=Be.cloneObject(n.pcConfig,{iceServers:[]}),_=n.rtcConstraints||null,u=n.rtcAnswerConstraints||null,g=Be.cloneObject(n.rtcOfferConstraints);let f,T=!1,y=!1,A=!1,w=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=n.rtcOfferConstraints||null,this._data=n.data||this._data,this._direction!=="incoming")throw new is.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==J.STATUS_WAITING_FOR_ANSWER)throw new is.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=ue.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=ue.SESSION_EXPIRES),this._status=J.STATUS_ANSWERED,!this._createDialog(s,"UAS")){s.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);const b=s.parseSDP();Array.isArray(b.media)||(b.media=[b.media]);for(const R of b.media)R.type==="audio"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(A=!0)),R.type==="video"&&(y=!0,(!R.direction||R.direction==="sendrecv")&&(w=!0));if(e&&a.audio===!1){f=e.getAudioTracks();for(const R of f)e.removeTrack(R)}if(e&&a.video===!1){f=e.getVideoTracks();for(const R of f)e.removeTrack(R)}!e&&a.audio===void 0&&(a.audio=A),!e&&a.video===void 0&&(a.video=w),!e&&!T&&!g.offerToReceiveAudio&&(a.audio=!1),!e&&!y&&!g.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(d,_),Promise.resolve().then(()=>{if(e)return e;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(R=>{throw this._status===J.STATUS_TERMINATED?new Error("terminated"):(s.reply(480),this._failed("local",null,ue.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',R),this.emit("getusermediafailed",R),new Error("getUserMedia() failed"))})}).then(R=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(G=>{this._connection.addTrack(G,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:s.body};K.debug('emit "sdp"'),this.emit("sdp",R);const G=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(G)).catch(x=>{throw s.reply(488),this._failed("system",null,ue.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',x),this.emit("peerconnection:setremotedescriptionfailed",x),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(s),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw s.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",u).catch(()=>{throw s.reply(500),new Error("_createLocalDescription() failed")})}).then(R=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(s,i),s.reply(200,null,i,R,()=>{this._status=J.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,ue.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==J.STATUS_TERMINATED&&K.warn(R)})}terminate(n={}){K.debug("terminate()");const s=n.cause||ue.causes.BYE,i=Be.cloneArray(n.extraHeaders),a=n.body;let e,d=n.status_code,_=n.reason_phrase;if(this._status===J.STATUS_TERMINATED)throw new is.InvalidStateError(this._status);switch(this._status){case J.STATUS_NULL:case J.STATUS_INVITE_SENT:case J.STATUS_1XX_RECEIVED:if(K.debug("canceling session"),d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||ue.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===J.STATUS_NULL||this._status===J.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===J.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=J.STATUS_CANCELED,this._failed("local",null,ue.causes.CANCELED);break;case J.STATUS_WAITING_FOR_ANSWER:case J.STATUS_ANSWERED:if(K.debug("rejecting session"),d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,ue.causes.REJECTED);break;case J.STATUS_WAITING_FOR_ACK:case J.STATUS_CONFIRMED:if(K.debug("terminating session"),_=n.reason_phrase||ue.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===J.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==hd.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===ue.ACK&&(this.sendRequest(ue.BYE,{extraHeaders:i,body:a}),u.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===hd.C.STATUS_TERMINATED&&(this.sendRequest(ue.BYE,{extraHeaders:i,body:a}),u.terminate())}),this._ended("local",null,s),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(ue.BYE,{extraHeaders:i,body:a}),this._ended("local",null,s)}}sendDTMF(n,s={}){K.debug("sendDTMF() | tones: %s",n);let i=0,a=s.duration||null,e=s.interToneGap||null;const d=s.transportType||ue.DTMF_TRANSPORT.INFO;if(n===void 0)throw new TypeError("Not enough arguments");if(this._status!==J.STATUS_CONFIRMED&&this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_1XX_RECEIVED)throw new is.InvalidStateError(this._status);if(d!==ue.DTMF_TRANSPORT.INFO&&d!==ue.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${d}`);if(typeof n=="number"&&(n=n.toString()),!n||typeof n!="string"||!n.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${n}`);if(a&&!Be.isDecimal(a))throw new TypeError(`Invalid tone duration: ${a}`);if(a?a<Lt.C.MIN_DURATION?(K.debug(`"duration" value is lower than the minimum allowed, setting it to ${Lt.C.MIN_DURATION} milliseconds`),a=Lt.C.MIN_DURATION):a>Lt.C.MAX_DURATION?(K.debug(`"duration" value is greater than the maximum allowed, setting it to ${Lt.C.MAX_DURATION} milliseconds`),a=Lt.C.MAX_DURATION):a=Math.abs(a):a=Lt.C.DEFAULT_DURATION,s.duration=a,e&&!Be.isDecimal(e))throw new TypeError(`Invalid interToneGap: ${e}`);if(e?e<Lt.C.MIN_INTER_TONE_GAP?(K.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${Lt.C.MIN_INTER_TONE_GAP} milliseconds`),e=Lt.C.MIN_INTER_TONE_GAP):e=Math.abs(e):e=Lt.C.DEFAULT_INTER_TONE_GAP,d===ue.DTMF_TRANSPORT.RFC2833){const u=this._getDTMFRTPSender();u&&(n=u.toneBuffer+n,u.insertDTMF(n,a,e));return}if(this._tones){this._tones+=n;return}this._tones=n,_.call(this);function _(){let u;if(this._status===J.STATUS_TERMINATED||!this._tones||i>=this._tones.length){this._tones=null;return}const g=this._tones[i];if(i+=1,g===",")u=2e3;else{const f=new Lt(this);s.eventHandlers={onFailed:()=>{this._tones=null}},f.send(g,s),u=a+e}setTimeout(_.bind(this),u)}}sendInfo(n,s,i={}){if(K.debug("sendInfo()"),this._status!==J.STATUS_CONFIRMED&&this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_1XX_RECEIVED)throw new is.InvalidStateError(this._status);new dd(this).send(n,s,i)}mute(n={audio:!0,video:!1}){K.debug("mute()");let s=!1,i=!1;this._audioMuted===!1&&n.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&n.video&&(i=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||i===!0)&&this._onmute({audio:s,video:i})}unmute(n={audio:!0,video:!0}){K.debug("unmute()");let s=!1,i=!1;this._audioMuted===!0&&n.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&n.video&&(i=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||i===!0)&&this._onunmute({audio:s,video:i})}hold(n={},s){if(K.debug("hold()"),this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const i={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:n.extraHeaders}),!0}unhold(n={},s){if(K.debug("unhold()"),this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const i={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:n.extraHeaders}),!0}renegotiate(n={},s){K.debug("renegotiate()");const i=n.rtcOfferConstraints||null;if(this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:i,extraHeaders:n.extraHeaders}),!0}refer(n,s){K.debug("refer()");const i=n;if(this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED)return!1;if(n=this._ua.normalizeTarget(n),!n)throw new TypeError(`Invalid target: ${i}`);const a=new cT(this);a.sendRefer(n,s);const e=a.id;return this._referSubscribers[e]=a,a.on("requestFailed",()=>{delete this._referSubscribers[e]}),a.on("accepted",()=>{delete this._referSubscribers[e]}),a.on("failed",()=>{delete this._referSubscribers[e]}),a}sendRequest(n,s){return K.debug("sendRequest()"),this._dialog.sendRequest(n,s)}receiveRequest(n){if(K.debug("receiveRequest()"),n.method===ue.CANCEL)(this._status===J.STATUS_WAITING_FOR_ANSWER||this._status===J.STATUS_ANSWERED)&&(this._status=J.STATUS_CANCELED,this._request.reply(487),this._failed("remote",n,ue.causes.CANCELED));else switch(n.method){case ue.ACK:if(this._status!==J.STATUS_WAITING_FOR_ACK)return;if(this._status=J.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!n.body){this.terminate({cause:ue.causes.MISSING_SDP,status_code:400});break}const s={originator:"remote",type:"answer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",n)}).catch(a=>{this.terminate({cause:ue.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",n);break;case ue.BYE:this._status===J.STATUS_CONFIRMED||this._status===J.STATUS_WAITING_FOR_ACK?(n.reply(200),this._ended("remote",n,ue.causes.BYE)):this._status===J.STATUS_INVITE_RECEIVED||this._status===J.STATUS_WAITING_FOR_ANSWER?(n.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",n,ue.causes.BYE)):n.reply(403,"Wrong Status");break;case ue.INVITE:this._status===J.STATUS_CONFIRMED?n.hasHeader("replaces")?this._receiveReplaces(n):this._receiveReinvite(n):n.reply(403,"Wrong Status");break;case ue.INFO:if(this._status===J.STATUS_1XX_RECEIVED||this._status===J.STATUS_WAITING_FOR_ANSWER||this._status===J.STATUS_ANSWERED||this._status===J.STATUS_WAITING_FOR_ACK||this._status===J.STATUS_CONFIRMED){const s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new Lt(this).init_incoming(n):s!==void 0?new dd(this).init_incoming(n):n.reply(415)}else n.reply(403,"Wrong Status");break;case ue.UPDATE:this._status===J.STATUS_CONFIRMED?this._receiveUpdate(n):n.reply(403,"Wrong Status");break;case ue.REFER:this._status===J.STATUS_CONFIRMED?this._receiveRefer(n):n.reply(403,"Wrong Status");break;case ue.NOTIFY:this._status===J.STATUS_CONFIRMED?this._receiveNotify(n):n.reply(403,"Wrong Status");break;default:n.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==J.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ue.causes.CONNECTION_ERROR,cause:ue.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==J.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ue.causes.REQUEST_TIMEOUT,cause:ue.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==J.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ue.causes.DIALOG_ERROR,cause:ue.causes.DIALOG_ERROR})}newDTMF(n){K.debug("newDTMF()"),this.emit("newDTMF",n)}newInfo(n){K.debug("newInfo()"),this.emit("newInfo",n)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==J.STATUS_TERMINATED){if(this._status=J.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(n){K.warn("close() | error closing the RTCPeerConnection: %o",n)}for(const n in this._timers)Object.prototype.hasOwnProperty.call(this._timers,n)&&clearTimeout(this._timers[n]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const n in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,n)&&(this._earlyDialogs[n].terminate(),delete this._earlyDialogs[n]);for(const n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(n,s){let i=Cr.T1;function a(){this._status===J.STATUS_WAITING_FOR_ACK&&(n.reply(200,null,[`Contact: ${this._contact}`],s),i<Cr.T2&&(i=i*2,i>Cr.T2&&(i=Cr.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),i))}this._timers.invite2xxTimer=setTimeout(a.bind(this),i)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===J.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(ue.BYE),this._ended("remote",null,ue.causes.NO_ACK))},Cr.TIMER_H)}_createRTCConnection(n,s){this._connection=new RTCPeerConnection(n,s),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:ue.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ue.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(n,s){if(K.debug("createLocalDescription()"),n!=="offer"&&n!=="answer")throw new Error(`createLocalDescription() | invalid type "${n}"`);const i=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>n==="offer"?i.createOffer(s).catch(a=>(K.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):i.createAnswer(s).catch(a=>(K.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>i.setLocalDescription(a).catch(e=>(this._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),this.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)))).then(()=>{const a=s&&s.iceRestart;if(i.iceGatheringState==="complete"&&!a||i.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const e={originator:"local",type:n,sdp:i.localDescription.sdp};return K.debug('emit "sdp"'),this.emit("sdp",e),Promise.resolve(e.sdp)}return new Promise(e=>{let d=!1,_,u;this._iceReady=!1;const g=()=>{i.removeEventListener("icecandidate",_),i.removeEventListener("icegatheringstatechange",u),d=!0,this._rtcReady=!0,this._iceReady=!0;const f={originator:"local",type:n,sdp:i.localDescription.sdp};K.debug('emit "sdp"'),this.emit("sdp",f),e(f.sdp)};i.addEventListener("icecandidate",_=f=>{const T=f.candidate;T?this.emit("icecandidate",{candidate:T,ready:g}):d||g()}),i.addEventListener("icegatheringstatechange",u=()=>{i.iceGatheringState==="complete"&&!d&&g()})})})}_createDialog(n,s,i){const a=s==="UAS"?n.to_tag:n.from_tag,e=s==="UAS"?n.from_tag:n.to_tag,d=n.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new pl(this,n,s,pl.C.STATUS_EARLY),_.error?(K.debug(_.error),this._failed("remote",n,ue.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=n.from_tag,this._to_tag=n.to_tag,_)return _.update(n,s),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new pl(this,n,s);return u.error?(K.debug(u.error),this._failed("remote",n,ue.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_receiveReinvite(n){K.debug("receiveReinvite()");const s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0,i={request:n,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",f=Be.cloneArray(_.extraHeaders);if(this._status!==J.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);n.reply(u,g,f)}if(this.emit("reinvite",i),a)return;if(this._late_sdp=!1,!n.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(_=>{d.call(this,_)}).catch(()=>{n.reply(500)});return}if(s!=="application/sdp"){K.debug("invalid Content-Type"),n.reply(415);return}this._processInDialogSdpOffer(n).then(_=>{this._status!==J.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{K.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(n,u),this._late_sdp&&(_=this._mangleOffer(_)),n.reply(200,null,u,_,()=>{this._status=J.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,_),this._setACKTimer()}),typeof i.callback=="function"&&i.callback()}}_receiveUpdate(n){K.debug("receiveUpdate()");const s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0,i={request:n,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",f=Be.cloneArray(_.extraHeaders);if(this._status!==J.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);n.reply(u,g,f)}if(this.emit("update",i),a)return;if(!n.body){d.call(this,null);return}if(s!=="application/sdp"){K.debug("invalid Content-Type"),n.reply(415);return}this._processInDialogSdpOffer(n).then(_=>{this._status!==J.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{K.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(n,u),n.reply(200,null,u,_),typeof i.callback=="function"&&i.callback()}}_processInDialogSdpOffer(n){K.debug("_processInDialogSdpOffer()");const s=n.parseSDP();let i=!1;for(const d of s.media){if(fl.indexOf(d.type)===-1)continue;const _=d.direction||s.direction||"sendrecv";if(_==="sendonly"||_==="inactive")i=!0;else{i=!1;break}}const a={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",a);const e=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(e).catch(d=>{throw n.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),this.emit("peerconnection:setremotedescriptionfailed",d),d})}).then(()=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&i===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&i===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(d=>{throw n.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',d),d})}).catch(d=>{K.warn("_processInDialogSdpOffer() failed [error: %o]",d)}),this._connectionPromiseQueue}_receiveRefer(n){if(K.debug("receiveRefer()"),!n.refer_to){K.debug("no Refer-To header field present in REFER"),n.reply(400);return}if(n.refer_to.uri.scheme!==ue.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),n.reply(416);return}n.reply(202);const s=new uT(this,n.cseq);K.debug('emit "refer"'),this.emit("refer",{request:n,accept:(e,d)=>{i.call(this,e,d)},reject:()=>{a.call(this)}});function i(e,d={}){if(e=typeof e=="function"?e:null,this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED)return!1;const _=new ic(this._ua);if(_.on("progress",({response:u})=>{s.notify(u.status_code,u.reason_phrase)}),_.on("accepted",({response:u})=>{s.notify(u.status_code,u.reason_phrase)}),_.on("_failed",({message:u,cause:g})=>{u?s.notify(u.status_code,u.reason_phrase):s.notify(487,g)}),n.refer_to.uri.hasHeader("replaces")){const u=decodeURIComponent(n.refer_to.uri.getHeader("replaces"));d.extraHeaders=Be.cloneArray(d.extraHeaders),d.extraHeaders.push(`Replaces: ${u}`)}_.connect(n.refer_to.uri.toAor(),d,e)}function a(){s.notify(603)}}_receiveNotify(n){switch(K.debug("receiveNotify()"),n.event||n.reply(400),n.event.event){case"refer":{let s,i;if(n.event.params&&n.event.params.id)s=n.event.params.id,i=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)i=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{n.reply(400,"Missing event id parameter");return}if(!i){n.reply(481,"Subscription does not exist");return}i.receiveNotify(n),n.reply(200);break}default:n.reply(489)}}_receiveReplaces(n){K.debug("receiveReplaces()");function s(a){if(this._status!==J.STATUS_WAITING_FOR_ACK&&this._status!==J.STATUS_CONFIRMED)return!1;const e=new ic(this._ua);e.on("confirmed",()=>{this.terminate()}),e.init_incoming(n,a)}function i(){K.debug("Replaced INVITE rejected by the user"),n.reply(486)}this.emit("replaces",{request:n,accept:a=>{s.call(this,a)},reject:()=>{i.call(this)}})}_sendInitialRequest(n,s,i){const a=new aT(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});Promise.resolve().then(()=>{if(i)return i;if(n.audio||n.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(n).catch(e=>{throw this._status===J.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,ue.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),e)})}).then(e=>{if(this._status===J.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=e,e&&e.getTracks().forEach(d=>{this._connection.addTrack(d,e)}),this._connecting(this._request),this._createLocalDescription("offer",s).catch(d=>{throw this._failed("local",null,ue.causes.WEBRTC_ERROR),d})}).then(e=>{if(this._is_canceled||this._status===J.STATUS_TERMINATED)throw new Error("terminated");this._request.body=e,this._status=J.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==J.STATUS_TERMINATED&&K.warn(e)})}_getDTMFRTPSender(){const n=this._connection.getSenders().find(s=>s.track&&s.track.kind==="audio");if(!(n&&n.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return n.dtmf}_receiveInviteResponse(n){if(K.debug("receiveInviteResponse()"),this._dialog&&n.status_code>=200&&n.status_code<=299)if(this._dialog.id.call_id===n.call_id&&this._dialog.id.local_tag===n.from_tag&&this._dialog.id.remote_tag===n.to_tag){this.sendRequest(ue.ACK);return}else{const s=new pl(this,n,"UAC");if(s.error!==void 0){K.debug(s.error);return}this.sendRequest(ue.ACK),this.sendRequest(ue.BYE);return}if(this._is_canceled){n.status_code>=100&&n.status_code<200?this._request.cancel(this._cancel_reason):n.status_code>=200&&n.status_code<299&&this._acceptAndTerminate(n);return}if(!(this._status!==J.STATUS_INVITE_SENT&&this._status!==J.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(n.status_code):this._status=J.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(n.status_code):{if(!n.to_tag){K.debug("1xx response received without to tag");break}if(n.hasHeader("contact")&&!this._createDialog(n,"UAC",!0))break;if(this._status=J.STATUS_1XX_RECEIVED,!n.body){this._progress("remote",n);break}const s={originator:"remote",type:"answer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",n)).catch(a=>{K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(n.status_code):{if(this._status=J.STATUS_CONFIRMED,!n.body){this._acceptAndTerminate(n,400,ue.causes.MISSING_SDP),this._failed("remote",n,ue.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(n,"UAC"))break;const s={originator:"remote",type:"answer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.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(n,500,a.toString()),this._failed("local",n,ue.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(i).then(()=>{this._handleSessionTimersInIncomingResponse(n),this._accepted("remote",n),this.sendRequest(ue.ACK),this._confirmed("local",null)}).catch(a=>{this._acceptAndTerminate(n,488,"Not Acceptable Here"),this._failed("remote",n,ue.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})});break}default:{const s=Be.sipErrorCause(n.status_code);this._failed("remote",n,s)}}}_sendReinvite(n={}){K.debug("sendReinvite()");const s=Be.cloneArray(n.extraHeaders),i=Be.cloneObject(n.eventHandlers),a=n.rtcOfferConstraints||this._rtcOfferConstraints||null;let e=!1;s.push(`Contact: ${this._contact}`),s.push("Content-Type: application/sdp"),this._sessionTimers.running&&s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(u=>{u=this._mangleOffer(u);const g={originator:"local",type:"offer",sdp:u};K.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(ue.INVITE,{extraHeaders:s,body:u,eventHandlers:{onSuccessResponse:f=>{d.call(this,f),e=!0},onErrorResponse:f=>{_.call(this,f)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function d(u){if(this._status===J.STATUS_TERMINATED||(this.sendRequest(ue.ACK),e))return;if(this._handleSessionTimersInIncomingResponse(u),u.body){if(!u.hasHeader("Content-Type")||u.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:u.body};K.debug('emit "sdp"'),this.emit("sdp",g);const f=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(f)).then(()=>{i.succeeded&&i.succeeded(u)}).catch(T=>{_.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(u){i.failed&&i.failed(u)}}_sendUpdate(n={}){K.debug("sendUpdate()");const s=Be.cloneArray(n.extraHeaders),i=Be.cloneObject(n.eventHandlers),a=n.rtcOfferConstraints||this._rtcOfferConstraints||null,e=n.sdpOffer||!1;let d=!1;s.push(`Contact: ${this._contact}`),this._sessionTimers.running&&s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),e?(s.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const f={originator:"local",type:"offer",sdp:g};K.debug('emit "sdp"'),this.emit("sdp",f),this.sendRequest(ue.UPDATE,{extraHeaders:s,body:g,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),d=!0},onErrorResponse:T=>{u.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{u.call(this)})):this.sendRequest(ue.UPDATE,{extraHeaders:s,eventHandlers:{onSuccessResponse:g=>{_.call(this,g)},onErrorResponse:g=>{u.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(g){if(this._status!==J.STATUS_TERMINATED&&!d)if(this._handleSessionTimersInIncomingResponse(g),e){if(g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){u.call(this);return}}else{u.call(this);return}const f={originator:"remote",type:"answer",sdp:g.body};K.debug('emit "sdp"'),this.emit("sdp",f);const T=new RTCSessionDescription({type:"answer",sdp:f.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{i.succeeded&&i.succeeded(g)}).catch(y=>{u.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',y),this.emit("peerconnection:setremotedescriptionfailed",y)})}else i.succeeded&&i.succeeded(g)}function u(g){i.failed&&i.failed(g)}}_acceptAndTerminate(n,s,i){K.debug("acceptAndTerminate()");const a=[];s&&(i=i||ue.REASON_PHRASE[s]||"",a.push(`Reason: SIP ;cause=${s}; text="${i}"`)),(this._dialog||this._createDialog(n,"UAC"))&&(this.sendRequest(ue.ACK),this.sendRequest(ue.BYE,{extraHeaders:a})),this._status=J.STATUS_TERMINATED}_mangleOffer(n){if(!this._localHold&&!this._remoteHold)return n;if(n=cd.parse(n),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const s of n.media)fl.indexOf(s.type)!==-1&&(s.direction?s.direction==="sendrecv"?s.direction="sendonly":s.direction==="recvonly"&&(s.direction="inactive"):s.direction="sendonly")}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");for(const s of n.media)fl.indexOf(s.type)!==-1&&(s.direction="inactive")}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");for(const s of n.media)fl.indexOf(s.type)!==-1&&(s.direction?s.direction==="sendrecv"?s.direction="recvonly":s.direction==="recvonly"&&(s.direction="inactive"):s.direction="recvonly")}return cd.write(n)}_setLocalMediaStatus(){let n=!0,s=!0;(this._localHold||this._remoteHold)&&(n=!1,s=!1),this._audioMuted&&(n=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!n),this._toggleMuteVideo(!s)}_handleSessionTimersInIncomingRequest(n,s){if(!this._sessionTimers.enabled)return;let i;n.session_expires&&n.session_expires>=ue.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=n.session_expires,i=n.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uas"),s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${i}`),this._sessionTimers.refresher=i==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(n){if(!this._sessionTimers.enabled)return;let s;n.session_expires&&n.session_expires>=ue.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=n.session_expires,s=n.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}_runSessionTimer(){const n=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==J.STATUS_TERMINATED&&this._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===ue.UPDATE?this._sendUpdate():this._sendReinvite())},n*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==J.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:ue.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},n*1100)}_toggleMuteAudio(n){const s=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="audio");for(const i of s)i.track.enabled=!n}_toggleMuteVideo(n){const s=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="video");for(const i of s)i.track.enabled=!n}_newRTCSession(n,s){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:n,session:this,request:s})}_connecting(n){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:n})}_progress(n,s){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:n,response:s||null})}_accepted(n,s){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:n,response:s||null})}_confirmed(n,s){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:n,ack:s||null})}_ended(n,s,i){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:n,message:s||null,cause:i})}_failed(n,s,i){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:n,message:s||null,cause:i}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:n,message:s||null,cause:i})}_onhold(n){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:n})}_onunhold(n){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:n})}_onmute({audio:n,video:s}){K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:n,video:s})}_onunmute({audio:n,video:s}){K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:n,video:s})}};const hT=We(pd),dT=ut.EventEmitter,_T=ot,Fa=Ie,pT=gt,br=ft(),fT=Bs,fd=yn,mT=gn(),ml=new _T("Message");var gT=class extends dT{constructor(l){super(),this._ua=l,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(l,n,s={}){const i=l;if(l===void 0||n===void 0)throw new TypeError("Not enough arguments");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError(`Invalid target: ${i}`);const a=br.cloneArray(s.extraHeaders),e=br.cloneObject(s.eventHandlers),d=s.contentType||"text/plain",_={};s.fromUserName&&(_.from_uri=new mT("sip",s.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),s.fromDisplayName&&(_.from_display_name=s.fromDisplayName);for(const g in e)Object.prototype.hasOwnProperty.call(e,g)&&this.on(g,e[g]);a.push(`Content-Type: ${d}`),this._request=new pT.OutgoingRequest(Fa.MESSAGE,l,this._ua,_,a),n&&(this._request.body=n);const u=new fT(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),u.send()}init_incoming(l){this._request=l,this._newMessage("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}accept(l={}){const n=br.cloneArray(l.extraHeaders),s=l.body;if(this._direction!=="incoming")throw new fd.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,s)}reject(l={}){const n=l.status_code||480,s=l.reason_phrase,i=br.cloneArray(l.extraHeaders),a=l.body;if(this._direction!=="incoming")throw new fd.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,s,i,a)}_receiveResponse(l){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):this._succeeded("remote",l);break;default:{const n=br.sipErrorCause(l.status_code);this._failed("remote",l,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Fa.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Fa.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(l,n){l==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):l==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:l,message:this,request:n})}_failed(l,n,s){ml.debug("MESSAGE failed"),this._close(),ml.debug('emit "failed"'),this.emit("failed",{originator:l,response:n||null,cause:s})}_succeeded(l,n){ml.debug("MESSAGE succeeded"),this._close(),ml.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:n})}};const TT=ut.EventEmitter,vT=ot,ja=Ie,yT=gt,Rr=ft(),ET=Bs,md=yn,gl=new vT("Options");var ST=class extends TT{constructor(l){super(),this._ua=l,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(l,n,s={}){const i=l;if(l===void 0)throw new TypeError("A target is required for OPTIONS");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError(`Invalid target: ${i}`);const a=Rr.cloneArray(s.extraHeaders),e=Rr.cloneObject(s.eventHandlers),d=s.contentType||"application/sdp";for(const u in e)Object.prototype.hasOwnProperty.call(e,u)&&this.on(u,e[u]);a.push(`Content-Type: ${d}`),this._request=new yT.OutgoingRequest(ja.OPTIONS,l,this._ua,null,a),n&&(this._request.body=n);const _=new ET(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:u=>{this._receiveResponse(u)}});this._newOptions("local",this._request),_.send()}init_incoming(l){this._request=l,this._newOptions("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}accept(l={}){const n=Rr.cloneArray(l.extraHeaders),s=l.body;if(this._direction!=="incoming")throw new md.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,s)}reject(l={}){const n=l.status_code||480,s=l.reason_phrase,i=Rr.cloneArray(l.extraHeaders),a=l.body;if(this._direction!=="incoming")throw new md.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,s,i,a)}_receiveResponse(l){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):this._succeeded("remote",l);break;default:{const n=Rr.sipErrorCause(l.status_code);this._failed("remote",l,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,ja.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,ja.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(l,n){l==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):l==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:l,message:this,request:n})}_failed(l,n,s){gl.debug("OPTIONS failed"),this._close(),gl.debug('emit "failed"'),this.emit("failed",{originator:l,response:n||null,cause:s})}_succeeded(l,n){gl.debug("OPTIONS succeeded"),this._close(),gl.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:n})}},$a={};const AT=ot,Va=ft(),CT=Bt(),Ir=new AT("Socket");$a.isSocket=l=>{if(Array.isArray(l))return!1;if(typeof l>"u")return Ir.warn("undefined JsSIP.Socket instance"),!1;try{if(!Va.isString(l.url))throw Ir.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Va.isString(l.via_transport))throw Ir.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(CT.parse(l.sip_uri,"SIP_URI")===-1)throw Ir.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(n=>{if(!Va.isFunction(l[n]))throw Ir.warn(`missing or invalid JsSIP.Socket method: ${n}`),new Error(`Missing or invalid JsSIP.Socket method: ${n}`)})}catch{return!1}return!0};const bT=ot,RT=$a,gd=Ie,Ut=new bT("Transport"),$t={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:gd.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:gd.CONNECTION_RECOVERY_MAX_INTERVAL}};var Td=class{constructor(l,n=$t.recovery_options){Ut.debug("new()"),this.status=$t.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(s){Ut.warn(`cannot use TextDecoder: ${s}`)}if(typeof l>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");l instanceof Array||(l=[l]),l.forEach(function(s){if(!RT.isSocket(s.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(s.weight&&!Number(s.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:s.socket,weight:s.weight||0,status:$t.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=$t.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=$t.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(l){if(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;const n=l.toString();return Ut.debug(`sending message:
116
116
 
117
- ${s}
118
- `),this.socket.send(s)}isConnected(){return this.status===Yt.STATUS_CONNECTED}isConnecting(){return this.status===Yt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let l=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);l<this.recovery_options.min_interval?l=this.recovery_options.min_interval:l>this.recovery_options.max_interval&&(l=this.recovery_options.max_interval),Ht.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${l} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},l*1e3)}_getSocket(){let l=[];if(this.sockets.forEach(n=>{n.status!==Yt.SOCKET_STATUS_ERROR&&(l.length===0?l.push(n):n.weight>l[0].weight?l=[n]:n.weight===l[0].weight&&l.push(n))}),l.length===0){this.sockets.forEach(n=>{n.status=Yt.SOCKET_STATUS_READY}),this._getSocket();return}const s=Math.floor(Math.random()*l.length);this.socket=l[s].socket}_onConnect(){this.recover_attempts=0,this.status=Yt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(l,s,n){this.status=Yt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:l,code:s,reason:n}),!this.close_requested&&(this.sockets.forEach(function(i){this.socket===i.socket&&(i.status=Yt.SOCKET_STATUS_ERROR)},this),this._reconnect(l))}_onData(l){if(l===`\r
119
- `){Ht.debug("received message with CRLF Keep Alive response");return}else if(typeof l!="string"){try{this.textDecoder?l=this.textDecoder.decode(l):l=String.fromCharCode.apply(null,new Uint8Array(l))}catch(s){Ht.debug("received binary message failed to be converted into string, message discarded");return}Ht.debug(`received binary message:
117
+ ${n}
118
+ `),this.socket.send(n)}isConnected(){return this.status===$t.STATUS_CONNECTED}isConnecting(){return this.status===$t.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let l=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);l<this.recovery_options.min_interval?l=this.recovery_options.min_interval:l>this.recovery_options.max_interval&&(l=this.recovery_options.max_interval),Ut.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${l} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},l*1e3)}_getSocket(){let l=[];if(this.sockets.forEach(s=>{s.status!==$t.SOCKET_STATUS_ERROR&&(l.length===0?l.push(s):s.weight>l[0].weight?l=[s]:s.weight===l[0].weight&&l.push(s))}),l.length===0){this.sockets.forEach(s=>{s.status=$t.SOCKET_STATUS_READY}),this._getSocket();return}const n=Math.floor(Math.random()*l.length);this.socket=l[n].socket}_onConnect(){this.recover_attempts=0,this.status=$t.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(l,n,s){this.status=$t.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:l,code:n,reason:s}),!this.close_requested&&(this.sockets.forEach(function(i){this.socket===i.socket&&(i.status=$t.SOCKET_STATUS_ERROR)},this),this._reconnect(l))}_onData(l){if(l===`\r
119
+ `){Ut.debug("received message with CRLF Keep Alive response");return}else if(typeof l!="string"){try{this.textDecoder?l=this.textDecoder.decode(l):l=String.fromCharCode.apply(null,new Uint8Array(l))}catch{Ut.debug("received binary message failed to be converted into string, message discarded");return}Ut.debug(`received binary message:
120
120
 
121
121
  ${l}
122
- `)}else Ht.debug(`received text message:
122
+ `)}else Ut.debug(`received text message:
123
123
 
124
124
  ${l}
125
- `);this.ondata({transport:this,message:l})}};const kT=$e(Rd);var Id={};const UT=ht,Za=Xt(),eu=St,bl=new UT("Parser");Id.parseMessage=(l,s)=>{let n,i,a=l.indexOf(`\r
126
- `);if(a===-1){bl.warn("parseMessage() | no CRLF found, not a SIP message");return}const e=l.substring(0,a);let d=Za.parse(e,"Request_Response");if(d===-1){bl.warn(`parseMessage() | error parsing first line of SIP message: "${e}"`);return}else d.status_code?(n=new eu.IncomingResponse,n.status_code=d.status_code,n.reason_phrase=d.reason_phrase):(n=new eu.IncomingRequest(s),n.method=d.method,n.ruri=d.uri);n.data=l;let _=a+2;for(;;){if(a=MT(l,_),a===-2){i=_+2;break}else if(a===-1){bl.warn("parseMessage() | malformed message");return}if(d=xT(n,l,_,a),d!==!0){bl.warn("parseMessage() |",d.error);return}_=a+2}if(n.hasHeader("content-length")){const u=n.getHeader("content-length");n.body=l.substr(i,u)}else n.body=l.substring(i);return n};function MT(l,s){let n=s,i=0,a=0;if(l.substring(n,n+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
127
- `,n),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?n=a+2:i=a}return i}function xT(l,s,n,i){let a;const e=s.indexOf(":",n),d=s.substring(n,e).trim(),_=s.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=Za.parse(_,"Record_Route"),a===-1)a=void 0;else for(const u of a)l.addHeader("record-route",_.substring(u.possition,u.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=u.parsed;break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=Za.parse(_,"Contact"),a===-1)a=void 0;else for(const u of a)l.addHeader("contact",_.substring(u.possition,u.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=u.parsed;break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof eu.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:`error parsing header "${d}"`}:!0}const PT=ht,wd=Ne,Od=St,tu=yt(),nu=new PT("sanityCheck"),LT=[GT],HT=[FT,jT,$T,VT],qT=[BT,KT];let je,mn,Nd;var Dd=(l,s,n)=>{je=l,mn=s,Nd=n;for(const i of LT)if(i()===!1)return!1;if(je instanceof Od.IncomingRequest){for(const i of HT)if(i()===!1)return!1}else if(je instanceof Od.IncomingResponse){for(const i of qT)if(i()===!1)return!1}return!0};function FT(){if(je.s("to").uri.scheme!=="sip")return xr(416),!1}function jT(){if(!je.to_tag&&je.call_id.substr(0,5)===mn.configuration.jssip_id)return xr(482),!1}function $T(){const l=tu.str_utf8_length(je.body),s=je.getHeader("content-length");if(l<s)return xr(400),!1}function VT(){const l=je.from_tag,s=je.call_id,n=je.cseq;let i;if(!je.to_tag)if(je.method===wd.INVITE){if(mn._transactions.ist[je.via_branch])return!1;for(const a in mn._transactions.ist)if(Object.prototype.hasOwnProperty.call(mn._transactions.ist,a)&&(i=mn._transactions.ist[a],i.request.from_tag===l&&i.request.call_id===s&&i.request.cseq===n))return xr(482),!1}else{if(mn._transactions.nist[je.via_branch])return!1;for(const a in mn._transactions.nist)if(Object.prototype.hasOwnProperty.call(mn._transactions.nist,a)&&(i=mn._transactions.nist[a],i.request.from_tag===l&&i.request.call_id===s&&i.request.cseq===n))return xr(482),!1}}function BT(){if(je.getHeaders("via").length>1)return nu.debug("more than one Via header field present in the response, dropping the response"),!1}function KT(){const l=tu.str_utf8_length(je.body),s=je.getHeader("content-length");if(l<s)return nu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function GT(){const l=["from","to","call_id","cseq","via"];for(const s of l)if(!je.hasHeader(s))return nu.debug(`missing mandatory header field : ${s}, dropping the response`),!1}function xr(l){const s=je.getHeaders("via");let n,i=`SIP/2.0 ${l} ${wd.REASON_PHRASE[l]}\r
128
- `;for(const a of s)i+=`Via: ${a}\r
129
- `;n=je.getHeader("To"),je.to_tag||(n+=`;tag=${tu.newTag()}`),i+=`To: ${n}\r
130
- `,i+=`From: ${je.getHeader("From")}\r
131
- `,i+=`Call-ID: ${je.call_id}\r
132
- `,i+=`CSeq: ${je.cseq} ${je.method}\r
125
+ `);this.ondata({transport:this,message:l})}};const IT=We(Td);var vd={};const wT=ot,Ba=Bt(),Ka=gt,Tl=new wT("Parser");vd.parseMessage=(l,n)=>{let s,i,a=l.indexOf(`\r
126
+ `);if(a===-1){Tl.warn("parseMessage() | no CRLF found, not a SIP message");return}const e=l.substring(0,a);let d=Ba.parse(e,"Request_Response");if(d===-1){Tl.warn(`parseMessage() | error parsing first line of SIP message: "${e}"`);return}else d.status_code?(s=new Ka.IncomingResponse,s.status_code=d.status_code,s.reason_phrase=d.reason_phrase):(s=new Ka.IncomingRequest(n),s.method=d.method,s.ruri=d.uri);s.data=l;let _=a+2;for(;;){if(a=OT(l,_),a===-2){i=_+2;break}else if(a===-1){Tl.warn("parseMessage() | malformed message");return}if(d=NT(s,l,_,a),d!==!0){Tl.warn("parseMessage() |",d.error);return}_=a+2}if(s.hasHeader("content-length")){const u=s.getHeader("content-length");s.body=l.substr(i,u)}else s.body=l.substring(i);return s};function OT(l,n){let s=n,i=0,a=0;if(l.substring(s,s+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
127
+ `,s),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?s=a+2:i=a}return i}function NT(l,n,s,i){let a;const e=n.indexOf(":",s),d=n.substring(s,e).trim(),_=n.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=Ba.parse(_,"Record_Route"),a===-1)a=void 0;else for(const u of a)l.addHeader("record-route",_.substring(u.possition,u.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=u.parsed;break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=Ba.parse(_,"Contact"),a===-1)a=void 0;else for(const u of a)l.addHeader("contact",_.substring(u.possition,u.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=u.parsed;break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof Ka.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:`error parsing header "${d}"`}:!0}const DT=ot,yd=Ie,Ed=gt,Ga=ft(),Wa=new DT("sanityCheck"),kT=[jT],UT=[PT,xT,LT,HT],MT=[qT,FT];let qe,hn,Sd;var Ad=(l,n,s)=>{qe=l,hn=n,Sd=s;for(const i of kT)if(i()===!1)return!1;if(qe instanceof Ed.IncomingRequest){for(const i of UT)if(i()===!1)return!1}else if(qe instanceof Ed.IncomingResponse){for(const i of MT)if(i()===!1)return!1}return!0};function PT(){if(qe.s("to").uri.scheme!=="sip")return wr(416),!1}function xT(){if(!qe.to_tag&&qe.call_id.substr(0,5)===hn.configuration.jssip_id)return wr(482),!1}function LT(){const l=Ga.str_utf8_length(qe.body),n=qe.getHeader("content-length");if(l<n)return wr(400),!1}function HT(){const l=qe.from_tag,n=qe.call_id,s=qe.cseq;let i;if(!qe.to_tag)if(qe.method===yd.INVITE){if(hn._transactions.ist[qe.via_branch])return!1;for(const a in hn._transactions.ist)if(Object.prototype.hasOwnProperty.call(hn._transactions.ist,a)&&(i=hn._transactions.ist[a],i.request.from_tag===l&&i.request.call_id===n&&i.request.cseq===s))return wr(482),!1}else{if(hn._transactions.nist[qe.via_branch])return!1;for(const a in hn._transactions.nist)if(Object.prototype.hasOwnProperty.call(hn._transactions.nist,a)&&(i=hn._transactions.nist[a],i.request.from_tag===l&&i.request.call_id===n&&i.request.cseq===s))return wr(482),!1}}function qT(){if(qe.getHeaders("via").length>1)return Wa.debug("more than one Via header field present in the response, dropping the response"),!1}function FT(){const l=Ga.str_utf8_length(qe.body),n=qe.getHeader("content-length");if(l<n)return Wa.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function jT(){const l=["from","to","call_id","cseq","via"];for(const n of l)if(!qe.hasHeader(n))return Wa.debug(`missing mandatory header field : ${n}, dropping the response`),!1}function wr(l){const n=qe.getHeaders("via");let s,i=`SIP/2.0 ${l} ${yd.REASON_PHRASE[l]}\r
128
+ `;for(const a of n)i+=`Via: ${a}\r
129
+ `;s=qe.getHeader("To"),qe.to_tag||(s+=`;tag=${Ga.newTag()}`),i+=`To: ${s}\r
130
+ `,i+=`From: ${qe.getHeader("From")}\r
131
+ `,i+=`Call-ID: ${qe.call_id}\r
132
+ `,i+=`CSeq: ${qe.cseq} ${qe.method}\r
133
133
  `,i+=`\r
134
- `,Nd.send(i)}const WT=$e(Dd);var Pr={};const Xs=yt(),hs=Ne,su=Xt(),kd=Sn(),ru=Qa,iu=bn;Pr.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:hs.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:hs.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:hs.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${Xs.createRandomToken(12)}.invalid`};const Rl={mandatory:{sockets(l){const s=[];if(ru.isSocket(l))s.push({socket:l});else if(Array.isArray(l)&&l.length)for(const n of l)Object.prototype.hasOwnProperty.call(n,"socket")&&ru.isSocket(n.socket)?s.push(n):ru.isSocket(n)&&s.push({socket:n});else return;return s},uri(l){/^sip:/i.test(l)||(l=`${hs.SIP}:${l}`);const s=kd.parse(l);if(s)return s.user?s:void 0}},optional:{authorization_user(l){if(su.parse(`"${l}"`,"quoted_string")!==-1)return l},authorization_jwt(l){if(typeof l=="string")return l},user_agent(l){if(typeof l=="string")return l},connection_recovery_max_interval(l){if(Xs.isDecimal(l)){const s=Number(l);if(s>0)return s}},connection_recovery_min_interval(l){if(Xs.isDecimal(l)){const s=Number(l);if(s>0)return s}},contact_uri(l){if(typeof l=="string"){const s=su.parse(l,"SIP_URI");if(s!==-1)return s}},display_name(l){return l},instance_id(l){if(/^uuid:/i.test(l)&&(l=l.substr(5)),su.parse(l,"uuid")!==-1)return l},no_answer_timeout(l){if(Xs.isDecimal(l)){const s=Number(l);if(s>0)return s}},session_timers(l){if(typeof l=="boolean")return l},session_timers_refresh_method(l){if(typeof l=="string"&&(l=l.toUpperCase(),l===hs.INVITE||l===hs.UPDATE))return l},session_timers_force_refresher(l){if(typeof l=="boolean")return l},password(l){return String(l)},realm(l){return String(l)},ha1(l){return String(l)},register(l){if(typeof l=="boolean")return l},register_expires(l){if(Xs.isDecimal(l)){const s=Number(l);if(s>0)return s}},registrar_server(l){/^sip:/i.test(l)||(l=`${hs.SIP}:${l}`);const s=kd.parse(l);if(s)return s.user?void 0:s},use_preloaded_route(l){if(typeof l=="boolean")return l},extra_headers(l){const s=[];if(Array.isArray(l)&&l.length)for(const n of l)typeof n=="string"&&s.push(n);else return;return s}}};Pr.load=(l,s)=>{for(const n in Rl.mandatory)if(s.hasOwnProperty(n)){const i=s[n],a=Rl.mandatory[n](i);if(a!==void 0)l[n]=a;else throw new iu.ConfigurationError(n,i)}else throw new iu.ConfigurationError(n);for(const n in Rl.optional)if(s.hasOwnProperty(n)){const i=s[n];if(Xs.isEmpty(i))continue;const a=Rl.optional[n](i);if(a!==void 0)l[n]=a;else throw new iu.ConfigurationError(n,i)}};const YT=_t.EventEmitter,zT=ht,At=Ne,XT=Hg,Ud=Sd,Md=ST,xd=IT,ou=Ys,QT=Rd,Il=yt(),JT=bn,ZT=Sn(),ev=Id,lu=St,tv=Dd,au=Pr,Be=new zT("UA"),Ct={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var Pd=class extends YT{static get C(){return Ct}constructor(l){if(Be.debug("new() [configuration:%o]",l),super(),this._cache={credentials:{}},this._configuration=Object.assign({},au.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=Ct.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,l===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(l)}catch(s){throw this._status=Ct.STATUS_NOT_READY,this._error=Ct.CONFIGURATION_ERROR,s}this._registrator=new XT(this)}get C(){return Ct}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){Be.debug("start()"),this._status===Ct.STATUS_INIT?this._transport.connect():this._status===Ct.STATUS_USER_CLOSED?(Be.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Ct.STATUS_INIT,this._transport.connect()):this._status===Ct.STATUS_READY?Be.debug("UA is in READY status, not restarted"):Be.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){Be.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(l){Be.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(l)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(l,s){Be.debug("call()");const n=new Ud(this);return n.connect(l,s),n}sendMessage(l,s,n){Be.debug("sendMessage()");const i=new Md(this);return i.send(l,s,n),i}sendOptions(l,s,n){Be.debug("sendOptions()");const i=new xd(this);return i.send(l,s,n),i}terminateSessions(l){Be.debug("terminateSessions()");for(const s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(l)}stop(){if(Be.debug("stop()"),this._dynConfiguration={},this._status===Ct.STATUS_USER_CLOSED){Be.debug("UA already closed");return}this._registrator.close();const l=Object.keys(this._sessions).length;for(const s in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,s)){Be.debug(`closing session ${s}`);try{this._sessions[s].terminate()}catch(n){}}for(const s in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,s))try{this._applicants[s].close()}catch(n){}this._status=Ct.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&&l===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(l){return Il.normalizeTarget(l,this._configuration.hostport_params)}get(l){switch(l){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:Be.warn('get() | cannot get "%s" parameter in runtime',l);return}}set(l,s){switch(l){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 Be.warn('set() | cannot set "%s" parameter in runtime',l),!1}return!0}newTransaction(l){this._transactions[l.type][l.id]=l,this.emit("newTransaction",{transaction:l})}destroyTransaction(l){delete this._transactions[l.type][l.id],this.emit("transactionDestroyed",{transaction:l})}newDialog(l){this._dialogs[l.id]=l}destroyDialog(l){delete this._dialogs[l.id]}newMessage(l,s){this._applicants[l]=l,this.emit("newMessage",s)}newOptions(l,s){this._applicants[l]=l,this.emit("newOptions",s)}destroyMessage(l){delete this._applicants[l]}newRTCSession(l,s){this._sessions[l.id]=l,this.emit("newRTCSession",s)}destroyRTCSession(l){delete this._sessions[l.id]}registered(l){this.emit("registered",l)}unregistered(l){this.emit("unregistered",l)}registrationFailed(l){this.emit("registrationFailed",l)}receiveRequest(l){const s=l.method;if(l.ruri.user!==this._configuration.uri.user&&l.ruri.user!==this._contact.uri.user){Be.debug("Request-URI does not point to us"),l.method!==At.ACK&&l.reply_sl(404);return}if(l.ruri.scheme===At.SIPS){l.reply_sl(416);return}if(ou.checkTransaction(this,l))return;if(s===At.INVITE?new ou.InviteServerTransaction(this,this._transport,l):s!==At.ACK&&s!==At.CANCEL&&new ou.NonInviteServerTransaction(this,this._transport,l),s===At.OPTIONS){if(this.listeners("newOptions").length===0){l.reply(200);return}new xd(this).init_incoming(l)}else if(s===At.MESSAGE){if(this.listeners("newMessage").length===0){l.reply(405);return}new Md(this).init_incoming(l)}else if(s===At.INVITE&&!l.to_tag&&this.listeners("newRTCSession").length===0){l.reply(405);return}let n,i;if(l.to_tag)n=this._findDialog(l.call_id,l.from_tag,l.to_tag),n?n.receiveRequest(l):s===At.NOTIFY?(i=this._findSession(l),i?i.receiveRequest(l):(Be.debug("received NOTIFY request for a non existent subscription"),l.reply(481,"Subscription does not exist"))):s!==At.ACK&&l.reply(481);else switch(s){case At.INVITE:if(window.RTCPeerConnection)if(l.hasHeader("replaces")){const a=l.replaces;n=this._findDialog(a.call_id,a.from_tag,a.to_tag),n?(i=n.owner,i.isEnded()?l.reply(603):i.receiveRequest(l)):l.reply(481)}else i=new Ud(this),i.init_incoming(l);else Be.warn("INVITE received but WebRTC is not supported"),l.reply(488);break;case At.BYE:l.reply(481);break;case At.CANCEL:i=this._findSession(l),i?i.receiveRequest(l):Be.debug("received CANCEL request for a non existent session");break;case At.ACK:break;case At.NOTIFY:this.emit("sipEvent",{event:l.event,request:l}),l.reply(200);break;default:l.reply(405);break}}_findSession({call_id:l,from_tag:s,to_tag:n}){const i=l+s,a=this._sessions[i],e=l+n,d=this._sessions[e];return a||d||null}_findDialog(l,s,n){let i=l+s+n,a=this._dialogs[i];return a||(i=l+n+s,a=this._dialogs[i],a||null)}_loadConfig(l){try{au.load(this._configuration,l)}catch(i){throw i}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Il.newUUID()),this._configuration.jssip_id=Il.createRandomToken(5);const s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new QT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=nv.bind(this),this._transport.onconnect=sv.bind(this),this._transport.ondisconnect=rv.bind(this),this._transport.ondata=iv.bind(this)}catch(i){throw Be.warn(i),new JT.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 i=this._configuration.uri.clone();i.user=null,i.clearParams(),i.clearHeaders(),this._configuration.registrar_server=i}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ZT("sip",Il.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(i={}){const a=i.anonymous||null,e=i.outbound||null;let d="<";return a?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),e&&(a?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const n=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const i in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,i)&&(n.indexOf(i)!==-1?Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}));Be.debug("configuration parameters after validation:");for(const i in this._configuration)if(Object.prototype.hasOwnProperty.call(au.settings,i))switch(i){case"uri":case"registrar_server":Be.debug(`- ${i}: ${this._configuration[i]}`);break;case"password":case"ha1":case"authorization_jwt":Be.debug(`- ${i}: NOT SHOWN`);break;default:Be.debug(`- ${i}: ${JSON.stringify(this._configuration[i])}`)}}};function nv(l){this.emit("connecting",l)}function sv(l){this._status!==Ct.STATUS_USER_CLOSED&&(this._status=Ct.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function rv(l){const s=["nict","ict","nist","ist"];for(const n of s)for(const i in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],i)&&this._transactions[n][i].onTransportError();this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==Ct.STATUS_USER_CLOSED&&(this._status=Ct.STATUS_NOT_READY,this._error=Ct.NETWORK_ERROR)}function iv(l){const s=l.transport;let n=l.message;if(n=ev.parseMessage(n,this),!!n&&!(this._status===Ct.STATUS_USER_CLOSED&&n instanceof lu.IncomingRequest)&&tv(n,this,s)){if(n instanceof lu.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof lu.IncomingResponse){let i;switch(n.method){case At.INVITE:i=this._transactions.ict[n.via_branch],i&&i.receiveResponse(n);break;case At.ACK:break;default:i=this._transactions.nict[n.via_branch],i&&i.receiveResponse(n);break}}}}const ov=$e(Pd);for(var bt=[],uu=0;uu<256;++uu)bt.push((uu+256).toString(16).slice(1));function lv(l,s=0){return(bt[l[s+0]]+bt[l[s+1]]+bt[l[s+2]]+bt[l[s+3]]+"-"+bt[l[s+4]]+bt[l[s+5]]+"-"+bt[l[s+6]]+bt[l[s+7]]+"-"+bt[l[s+8]]+bt[l[s+9]]+"-"+bt[l[s+10]]+bt[l[s+11]]+bt[l[s+12]]+bt[l[s+13]]+bt[l[s+14]]+bt[l[s+15]]).toLowerCase()}var wl,av=new Uint8Array(16);function uv(){if(!wl&&(wl=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!wl))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return wl(av)}var cv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ld={randomUUID:cv};function Hd(l,s,n){if(Ld.randomUUID&&!s&&!l)return Ld.randomUUID();l=l||{};var i=l.random||(l.rng||uv)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,s){n=n||0;for(var a=0;a<16;++a)s[n+a]=i[a];return s}return lv(i)}var Me=yt();const Rn=$e(Me),cu=new fl("Dialog"),Zn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class Ol{static get C(){return Zn}constructor(s,n,i,a=Zn.STATUS_CONFIRMED){if(this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof St.IncomingResponse&&(a=n.status_code<200?Zn.STATUS_EARLY:Zn.STATUS_CONFIRMED),i==="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 e=n.getHeaders("to")[0].split(";")[0];e=e.match(/<([^>]*)>/)[1],this._remote_target=e,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(i==="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 e=n.getHeaders("to")[0].split(";")[0];e=e.match(/<([^>]*)>/)[1],this._remote_target=e,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),cu.debug(`new ${i} dialog created with status ${this._state===Zn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(s){this._local_seqnum=s}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(s){this._uac_pending_reply=s}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Zn.STATUS_TERMINATED}update(s,n){this._state=Zn.STATUS_CONFIRMED,cu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){cu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Zn.STATUS_TERMINATED}sendRequest(s,n={}){const i=Rn.cloneArray(n.extraHeaders),a=Rn.cloneObject(n.eventHandlers),e=n.body||null,d=this._createRequest(s,i,e);return a.onAuthenticated=()=>{this._local_seqnum+=1},new Bg(this,d,a).send(),d}receiveRequest(s){this._checkInDialogRequest(s)&&(s.method===U.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===U.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}_createRequest(s,n,i){n=Rn.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=s===U.CANCEL||s===U.ACK?this._local_seqnum:this._local_seqnum+=1;return new St.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,i)}_checkInDialogRequest(s){if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===U.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===U.INVITE||s.method===U.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return s.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(s.server_transaction.state===Wt.C.STATUS_ACCEPTED||s.server_transaction.state===Wt.C.STATUS_COMPLETED||s.server_transaction.state===Wt.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",n)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Wt.C.STATUS_ACCEPTED&&(this._remote_target=s.parseHeader("contact").uri)})}else s.method===U.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Wt.C.STATUS_COMPLETED&&(this._remote_target=s.parseHeader("contact").uri)});return!0}}class hv{constructor(s,n){jt(this,"plugin",null),jt(this,"rtcpPeer",null),jt(this,"handleId",0),jt(this,"info",null),jt(this,"joinResult",null),jt(this,"state",{}),jt(this,"stream",null),jt(this,"loaded",!1),jt(this,"aTracks",[]),jt(this,"vTracks",[]),this.info=s,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(s){var n;this.state=oe(oe({},this.state),s||{}),(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(s){var n,i,a,e;const d=(i=(n=s==null?void 0:s.plugindata)==null?void 0:n.data)==null?void 0:i.newStatePublisher,_=((e=(a=s==null?void 0:s.plugindata)==null?void 0:a.data)==null?void 0:e.publisher_state).find(u=>u.id===d);this.updateMemberState(_==null?void 0:_.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(s=>{s.stop()})}}class Jt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static getDevices(s){return re(this,null,function*(){return Jt.canGetMediaDevices()?(yield navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind===s):[]})}static getMicrophoneList(){return re(this,null,function*(){return(yield Jt.getDevices("audioinput")).map((s,n)=>ot(oe({},s),{deviceId:s.deviceId,label:s.label||`microphone ${n+1}`,kind:s.kind,groupId:s.groupId}))})}static getSpeakerList(){return re(this,null,function*(){return(yield Jt.getDevices("audiooutput")).map((s,n)=>ot(oe({},s),{deviceId:s.deviceId,label:s.label||`speaker ${n+1}`,kind:s.kind,groupId:s.groupId}))})}static getCameraList(){return re(this,null,function*(){return(yield Jt.getDevices("videoinput")).map((s,n)=>ot(oe({},s),{deviceId:s.deviceId,label:s.label||`camera ${n+1}`,kind:s.kind,groupId:s.groupId}))})}static stopStreamTracks(s){s&&s.getTracks().forEach(n=>{n.stop()})}static getMediaFromInputs(i){return re(this,arguments,function*({videoInput:s,audioInput:n}){let a,e;s==="default"?a=!0:s&&s!=="default"&&(a={deviceId:{exact:s}}),n==="default"?e=!0:n&&n!=="default"&&(e={deviceId:{exact:n}});const d={audio:e,video:a};return Jt.getUserMedia(d)})}static getUserMedia(s){return re(this,null,function*(){return yield navigator.mediaDevices.getUserMedia(s)})}static changeAudioOutput(s,n){return re(this,null,function*(){if(!(!s||!n))if(typeof s.sinkId<"u")try{yield s.setSinkId(n)}catch(i){let a=i;i.name==="SecurityError"&&(a=`You need to use HTTPS for selecting audio output device: ${i}`),console.error(a)}else console.warn("Browser does not support output device selection.")})}static toggleAudioMute(s){const n=s.getAudioTracks();if(n.length!==0)return n.forEach(i=>{i.enabled=!i.enabled}),n[0].enabled}static toggleVideoMute(s){const n=s.getVideoTracks();if(n.length!==0)return n.forEach(i=>{i.enabled=!i.enabled}),n[0].enabled}static getStream(){return re(this,arguments,function*(s={video:!0,audio:!0}){try{const n=yield navigator.mediaDevices.getUserMedia(s);let i=n.getTracks();return s.video?i=n.getVideoTracks():s.audio&&(i=n.getAudioTracks()),i.length===0?{stream:n,track:null}:{stream:n,track:i[0]}}catch(n){return console.warn(n),{stream:null,track:null}}})}}var dv=Sn();const ds=$e(dv),qt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},Y=new fl("JanusSession"),_v="/opt/recordings/",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},Nl=["audio","video"];class Dl extends _t.EventEmitter{static get C(){return Z}constructor(s){Y.debug("new"),super(),this._id=null,this._ua=s,this._status=Z.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.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:U.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 Z}get causes(){return U.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(s){this._data=s}get status(){return this._status}isInProgress(){switch(this._status){case Z.STATUS_NULL:case Z.STATUS_INVITE_SENT:case Z.STATUS_1XX_RECEIVED:case Z.STATUS_INVITE_RECEIVED:case Z.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Z.STATUS_ANSWERED:case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Z.STATUS_CANCELED:case Z.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(s){return`PTYPE: ${s}`}generateOpaqueId(){return`videoroomtest-${Hd().replace(/-/g,"").slice(0,12)}`}connect(s,n,i={},a){Y.debug("connect()"),this.display_name=n;const e=s,d=Me.cloneObject(i.eventHandlers),_=Me.cloneArray(i.extraHeaders),u=Me.cloneObject(i.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints=oe({},u);const g=i.mediaStream||null,p=Me.cloneObject(i.pcConfig,{iceServers:[]}),T=i.rtcConstraints||null,y=i.rtcOfferConstraints||null;if(this._rtcOfferConstraints=y,this._rtcAnswerConstraints=i.rtcAnswerConstraints||null,this._data=i.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new Xn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Xn.NotSupportedError("WebRTC not supported");if(s=this._ua.normalizeTarget(s),this.room_id=s.user,this.target=s,!s)throw new TypeError(`Invalid target: ${e}`);this._sessionTimers.enabled&&Me.isDecimal(i.sessionTimersExpires)&&(i.sessionTimersExpires>=U.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=i.sessionTimersExpires:this._sessionTimers.defaultExpires=U.SESSION_EXPIRES);for(const R in d)Object.prototype.hasOwnProperty.call(d,R)&&this.on(R,d[R]);this._from_tag=Me.newTag();const A=i.anonymous||!1,w={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:A,outbound:!0}),A?(w.from_display_name="Anonymous",w.from_uri=new ds("sip","anonymous","anonymous.invalid"),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),_.push("Privacy: id")):i.fromUserName&&(w.from_uri=new ds("sip",i.fromUserName,this._ua.configuration.uri.host),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),i.fromDisplayName&&(w.from_display_name=i.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 St.InitialOutgoingInviteRequest(s,this._ua,w,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(p,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(u,y,g)}_overrideSenderTracks(s,n){s.getTracks().forEach(i=>{n.getSenders().forEach(a=>re(this,null,function*(){a.track.kind===i.kind&&(i.kind==="audio"&&!this.isAudioOn&&(i.enabled=!1),i.kind==="video"&&!this.isVideoOn&&(i.enabled=!1),yield a.replaceTrack(i))}))})}init_incoming(s,n){Y.debug("init_incoming()");let i;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(i=s.getHeader("expires")*1e3),s.to_tag=Me.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,U.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,U.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,n&&n(this),this._newJanusSession("remote",s),this._status!==Z.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){Y.debug("answer()");const n=this._request,i=Me.cloneArray(s.extraHeaders),a=Me.cloneObject(s.mediaConstraints),e=s.mediaStream||null,d=Me.cloneObject(s.pcConfig,{iceServers:[]}),_=s.rtcConstraints||null,u=s.rtcAnswerConstraints||null,g=Me.cloneObject(s.rtcOfferConstraints);let p,T=!1,y=!1,A=!1,w=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new Xn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new Xn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Me.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=U.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=U.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);const R=n.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const b of R.media)b.type==="audio"&&(T=!0,(!b.direction||b.direction==="sendrecv")&&(A=!0)),b.type==="video"&&(y=!0,(!b.direction||b.direction==="sendrecv")&&(w=!0));if(e&&a.audio===!1){p=e.getAudioTracks();for(const b of p)e.removeTrack(b)}if(e&&a.video===!1){p=e.getVideoTracks();for(const b of p)e.removeTrack(b)}!e&&a.audio===void 0&&(a.audio=A),!e&&a.video===void 0&&(a.video=w),!e&&!T&&!g.offerToReceiveAudio&&(a.audio=!1),!e&&!y&&!g.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(d,_),Promise.resolve().then(()=>{if(e)return e;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(b=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,U.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',b),this.emit("getusermediafailed",b),new Error("getUserMedia() failed"))})}).then(b=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=b,b&&b.getTracks().forEach(G=>{this._connection.addTrack(G,b)})}).then(()=>{if(this._late_sdp)return;const b={originator:"remote",type:"offer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",b);const G=new RTCSessionDescription({type:"offer",sdp:b.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(G)).catch(P=>{throw n.reply(488),this._failed("system",null,U.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',P),this.emit("peerconnection:setremotedescriptionfailed",P),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",u).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(b=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,b,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,b),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,U.causes.CONNECTION_ERROR)})}).catch(b=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(b)})}terminate(s={}){Y.debug("terminate()");const n=s.cause||U.causes.BYE,i=Me.cloneArray(s.extraHeaders),a=s.body;let e,d=s.status_code,_=s.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new Xn.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"),d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||U.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=Z.STATUS_CANCELED,this._failed("local",null,U.causes.CANCELED);break;case Z.STATUS_WAITING_FOR_ANSWER:case Z.STATUS_ANSWERED:if(Y.debug("rejecting session"),d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,U.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(Y.debug("terminating session"),_=s.reason_phrase||U.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Wt.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===U.ACK&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Wt.C.STATUS_TERMINATED&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=u,this._ua.newDialog(u)}else{const u={janus:"leave"},g=["Content-Type: application/json",this.getPTypeHeader(qt.LEAVE)];this.sendRequest(U.BYE,{extraHeaders:g,body:JSON.stringify(u)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(s){this.isAudioOn=s.audio,this.isVideoOn=s.video}enableAudio(s){const n={janus:"message",body:{audio:s},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(qt.AUDIO_CHANGE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:a=>re(this,null,function*(){a.status_code===200&&(this._ua.emit("changeAudioState",s),this.sendStateMessage({audio:s}))})}})}startAudio(){Jt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Jt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(s){const n={janus:"message",body:{video:s},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(qt.VIDEO_CHANGE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:a=>re(this,null,function*(){a.status_code===200&&(this._ua.emit("changeVideoState",s),this.sendStateMessage({video:s}))})}})}startVideo(){Jt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Jt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(s){const n={janus:"message",body:{request:"state",data:s},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(qt.STATE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n)})}sendInfo(s,n,i={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new Xn.InvalidStateError(this._status);new Wa(this).send(s,n,i)}mute(s={audio:!0,video:!1}){Y.debug("mute()");let n=!1,i=!1;this._audioMuted===!1&&s.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(i=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||i===!0)&&this._onmute({audio:n,video:i})}unmute(s={audio:!0,video:!0}){Y.debug("unmute()");let n=!1,i=!1;this._audioMuted===!0&&s.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(i=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||i===!0)&&this._onunmute({audio:n,video:i})}hold(s={},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 i={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:s.extraHeaders}),!0}unhold(s={},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 i={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},n){Y.debug("renegotiate()");const i=s.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:i,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:i,extraHeaders:s.extraHeaders}),!0}refer(s,n){Y.debug("refer()");const i=s;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${i}`);const a=new uT(this);a.sendRefer(s,n);const e=a.id;return this._referSubscribers[e]=a,a.on("requestFailed",()=>{delete this._referSubscribers[e]}),a.on("accepted",()=>{delete this._referSubscribers[e]}),a.on("failed",()=>{delete this._referSubscribers[e]}),a}sendRequest(s,n){return Y.debug("sendRequest()"),this._dialog.sendRequest(s,n)}receiveNotify(s){Y.debug("receiveRequest()")}receiveRequest(s){if(Y.debug("receiveRequest()"),s.method===U.CANCEL)(this._status===Z.STATUS_WAITING_FOR_ANSWER||this._status===Z.STATUS_ANSWERED)&&(this._status=Z.STATUS_CANCELED,this._request.reply(487),this._failed("remote",s,U.causes.CANCELED));else switch(s.method){case U.ACK:if(this._status!==Z.STATUS_WAITING_FOR_ACK)return;if(this._status=Z.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:U.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:U.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case U.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,U.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,U.causes.BYE)):s.reply(403,"Wrong Status");break;case U.INVITE:this._status===Z.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case U.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=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Jg(this).init_incoming(s):n!==void 0?new Wa(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case U.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case U.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case U.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){Y.warn("onTransportError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){Y.warn("onRequestTimeout()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){Y.warn("onDialogError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.DIALOG_ERROR,cause:U.causes.DIALOG_ERROR})}newDTMF(s){Y.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){Y.debug("newInfo()"),this.emit("newInfo",s)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(Y.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(Y.debug("_isReadyToReOffer() | session not established yet"),!1):(Y.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(Y.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(Y.debug("close() | closing local MediaStream"),Me.closeMediaStream(this._localMediaStream)),this._status!==Z.STATUS_TERMINATED){if(this._status=Z.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){Y.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,n){let i=Ar.T1;function a(){this._status===Z.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],n),i<Ar.T2&&(i=i*2,i>Ar.T2&&(i=Ar.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),i))}this._timers.invite2xxTimer=setTimeout(a.bind(this),i)}_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(U.BYE),this._ended("remote",null,U.causes.NO_ACK))},Ar.TIMER_H)}_createRTCConnection(s,n){this.stunServers,this._connection=new RTCPeerConnection(s,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:U.causes.RTP_TIMEOUT,status_code:408,reason_phrase:U.causes.RTP_TIMEOUT})});let i;const a=e=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||e.candidate&&(this._candidates.push(e.candidate),clearTimeout(i),i=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,Y.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,n){if(Y.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const i=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?i.createOffer(n).catch(a=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):i.createAnswer(n).catch(a=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>(this.jsepOffer=a,i.setLocalDescription(a).catch(e=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),this.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e))))).then(()=>{const a=n&&n.iceRestart;if(i.iceGatheringState==="complete"&&!a||i.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const e={originator:"local",type:s,sdp:i.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",e),Promise.resolve(e.sdp)}return new Promise(e=>{let d=!1,_,u;this._iceReady=!1;const g=()=>{i.removeEventListener("icecandidate",_),i.removeEventListener("icegatheringstatechange",u),d=!0,this._rtcReady=!0,this._iceReady=!0;const p={originator:"local",type:s,sdp:i.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",p),e(p.sdp)};i.addEventListener("icecandidate",_=p=>{const T=p.candidate;T?this.emit("icecandidate",{candidate:T,ready:g}):d||g()}),i.addEventListener("icegatheringstatechange",u=()=>{i.iceGatheringState==="complete"&&!d&&g()})})})}_createDialog(s,n,i){const a=n==="UAS"?s.to_tag:s.from_tag,e=n==="UAS"?s.from_tag:s.to_tag,d=s.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new Ol(this,s,n,Ol.C.STATUS_EARLY),_.error?(Y.debug(_.error),this._failed("remote",s,U.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,_)return _.update(s,n),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new Ol(this,s,n);return u.error?(Y.debug(u.error),this._failed("remote",s,U.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_receiveReinvite(s){Y.debug("receiveReinvite()");const n=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,i={request:s,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",p=Me.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);s.reply(u,g,p)}if(this.emit("reinvite",i),a)return;if(this._late_sdp=!1,!s.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(_=>{d.call(this,_)}).catch(()=>{s.reply(500)});return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{Y.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,u),this._late_sdp&&(_=this._mangleOffer(_)),s.reply(200,null,u,_,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,_),this._setACKTimer()}),typeof i.callback=="function"&&i.callback()}}_receiveUpdate(s){Y.debug("receiveUpdate()");const n=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,i={request:s,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",p=Me.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);s.reply(u,g,p)}if(this.emit("update",i),a)return;if(!s.body){d.call(this,null);return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{Y.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,u),s.reply(200,null,u,_),typeof i.callback=="function"&&i.callback()}}_processInDialogSdpOffer(s){Y.debug("_processInDialogSdpOffer()");const n=s.parseSDP();let i=!1;for(const d of n.media){if(Nl.indexOf(d.type)===-1)continue;const _=d.direction||n.direction||"sendrecv";if(_==="sendonly"||_==="inactive")i=!0;else{i=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",a);const e=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(e).catch(d=>{throw s.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),this.emit("peerconnection:setremotedescriptionfailed",d),d})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&i===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&i===!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(d=>{throw s.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',d),d})}).catch(d=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",d)}),this._connectionPromiseQueue}_receiveRefer(s){if(Y.debug("receiveRefer()"),!s.refer_to){Y.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==U.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const n=new iT(this,s.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:s,accept:(e,d)=>{i.call(this,e,d)},reject:()=>{a.call(this)}});function i(e,d={}){if(e=typeof e=="function"?e:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const _=new Dl(this._ua);if(_.on("progress",({response:u})=>{n.notify(u.status_code,u.reason_phrase)}),_.on("accepted",({response:u})=>{n.notify(u.status_code,u.reason_phrase)}),_.on("_failed",({message:u,cause:g})=>{u?n.notify(u.status_code,u.reason_phrase):n.notify(487,g)}),s.refer_to.uri.hasHeader("replaces")){const u=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));d.extraHeaders=Me.cloneArray(d.extraHeaders),d.extraHeaders.push(`Replaces: ${u}`)}_.connect(s.refer_to.uri.toAor(),d,e)}function a(){n.notify(603)}}_receiveNotify(s){switch(Y.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let n,i;if(s.event.params&&s.event.params.id)n=s.event.params.id,i=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)i=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!i){s.reply(481,"Subscription does not exist");return}i.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){Y.debug("receiveReplaces()");function n(a){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const e=new Dl(this._ua);e.on("confirmed",()=>{this.terminate()}),e.init_incoming(s,a)}function i(){Y.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{n.call(this,a)},reject:()=>{i.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(s,n,i){this.ackSent=!1,this.publisherSubscribeSent=!1;const a=new Ir(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});Promise.resolve().then(()=>{if(i)return i;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(e=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,U.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),e)})}).then(e=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=e,e&&e.getTracks().forEach(d=>{this._connection.addTrack(d,e)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(d=>{throw this._failed("local",null,U.causes.WEBRTC_ERROR),d})}).then(e=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");const d={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},_=JSON.stringify(d);this._request.body=_,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(e)})}requestAudioAndVideoPermissions(){return re(this,null,function*(){this.stream=yield this.loadStream()})}setupMediaStream(){return re(this,null,function*(){yield this.requestAudioAndVideoPermissions(),yield this.processPlugins()})}changeMediaConstraints(s){return re(this,null,function*(){this.mediaConstraints=oe({},s),yield this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})})}loadStream(){return re(this,null,function*(){const s={};this.isAudioOn?this.mediaConstraints.audio?s.audio=this.mediaConstraints.audio:s.audio=!0:s.audio=!1,this.isVideoOn?this.mediaConstraints.video?s.video=this.mediaConstraints.video:s.video=!0:s.video=!1;let n=null;try{n=yield navigator.mediaDevices.getUserMedia(s)}catch(i){try{s.video=!1,n=yield navigator.mediaDevices.getUserMedia(s)}catch(a){s.audio=!1,s.video=!1,n=yield navigator.mediaDevices.getUserMedia(s)}}return n})}addTracks(s){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),s.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return _v+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}processIceCandidates(){return re(this,null,function*(){for(let s=0;s<this.iceCandidates.length;s++)yield this._connection.addIceCandidate(this.iceCandidates[s]);this.iceCandidates=[]})}_sendConfigureMessage(s){return re(this,null,function*(){const n=this._candidates.map(e=>({janus:"trickle",candidate:e,handle_id:this.handle_id,session_id:this.session_id})),i={configure:{janus:"message",body:oe({request:"configure",record:!0,filename:this.getRecordFileName()},s),jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},a=["Content-Type: application/json",this.getPTypeHeader(qt.ICE)];this.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:e=>re(this,null,function*(){this.isConfigureSent=!0;const d=e.data.split(`\r
135
- `),_=d[d.length-1],u=JSON.parse(_);yield this._connection.setRemoteDescription(u.jsep),this._candidates=[]})}})})}_sendMemberStartMessage(s,n){const i={janus:"message",body:{request:"start",room:this.room_id},handle_id:s.handleId,session_id:this.session_id,jsep:n},a=["Content-Type: application/json",this.getPTypeHeader(qt.CONFIGURE)];this.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:e=>re(this,null,function*(){e.status_code===200&&(yield s.rtcpPeer.setLocalDescription(n))})}})}_sendTrickleMessage(s){const n={trickles:[...s.map(a=>({janus:"trickle",candidate:a,handle_id:this.handle_id,session_id:this.session_id}))]},i=[this.getPTypeHeader(qt.TRICKLE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:a=>re(this,null,function*(){})}})}_answerAttachedStream(s,n){return re(this,null,function*(){let i=null;const a=u=>re(this,null,function*(){if(!s.rtcpPeer||s.loaded)return;{s.loaded=!0;const A={audio:!0,video:!0};yield new Promise(w=>{setTimeout(w,100)}),i=yield s.rtcpPeer.createAnswer(A),this._sendMemberStartMessage(s,i)}const g=u.streams[0].getAudioTracks(),p=u.streams[0].getVideoTracks(),T=[];g[0]&&T.push(g[0]),p[0]&&T.push(p[0]);const y=new MediaStream(T);s.stream=y,this._ua.emit("memberJoin",s.memberInfo)});let e,d=[];const _=u=>{s.rtcpPeer.signalingState!=="stable"&&s.rtcpPeer.signalingState!=="have-local-offer"||(d.push(u.candidate||null),clearTimeout(e),e=setTimeout(()=>{this._sendTrickleMessage(d)},500))};s.rtcpPeer=new RTCPeerConnection,s.rtcpPeer.ontrack=a,s.rtcpPeer.onicecandidate=_,s.rtcpPeer.sender=n.sender,yield s.rtcpPeer.setRemoteDescription(n.jsep)})}_sendJoinMemberRequest(s){const n={janus:"message",body:{request:"join",room:this.room_id,feed:s.info.id,ptype:"subscriber"},handle_id:s.handleId,session_id:this.session_id},i=[this.getPTypeHeader(qt.SUBSCRIBER)];this.sendRequest(U.SUBSCRIBE,{extraHeaders:i,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:a=>re(this,null,function*(){var e,d;if(a.status_code===200){const _=JSON.parse(a.body);(d=(e=_==null?void 0:_.plugindata)==null?void 0:e.data)!=null&&d.id&&(yield this._answerAttachedStream(s,_))}})}})}_attachMember(s){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},i=[this.getPTypeHeader(qt.SUBSCRIBER)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:a=>re(this,null,function*(){if(a.status_code===200){const e=JSON.parse(a.body).data.id;s.handleId=e,this._sendJoinMemberRequest(s)}})}})}_detachMember(s){const n={janus:"detach",handle_id:s.handleId,session_id:this.session_id},i=[this.getPTypeHeader(qt.SUBSCRIBER)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(n)}),Jt.stopStreamTracks(s.memberInfo.stream),this._ua.emit("memberHangup",s.memberInfo)}receivePublishers(s){var n,i,a,e,d,_,u,g;const p=oe({},this.memberList);(i=(n=s==null?void 0:s.plugindata)==null?void 0:n.data)==null||i.publishers.forEach(T=>{delete p[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new hv(T,this),this._attachMember(this.memberList[T.id]))}),((e=(a=s==null?void 0:s.plugindata)==null?void 0:a.data)==null?void 0:e.videoroom)==="synced"&&Object.keys(p).forEach(T=>{p[T].hangup(),delete this.memberList[T]}),this.publishers=(_=(d=s==null?void 0:s.plugindata)==null?void 0:d.data)==null?void 0:_.publishers,this.private_id=(g=(u=s==null?void 0:s.plugindata)==null?void 0:u.data)==null?void 0:g.private_id}receiveUnpublished(s){const n=this.memberList[s];n&&(n.hangup(),this._detachMember(n),delete this.memberList[s])}closeSession(){this.stream&&this.stream.getTracks().forEach(s=>{s.stop()}),Object.values(this.memberList).forEach(s=>{s.hangup(),this._detachMember(s)}),this._ua.emit("conferenceEnd",this.id)}processPlugins(){return re(this,null,function*(){const s=this._ua.processStreamPlugins;let n=yield this.loadStream();for(const i of s)n=yield i.process(n);this.stream.getTracks().forEach(i=>{this.stream.removeTrack(i),i.stop()}),n.getTracks().forEach(i=>{this.stream.addTrack(i)})})}resyncPlugins(s){return re(this,null,function*(){const n=this._ua.processStreamPlugins.filter(i=>i.type===s);for(const i of n)i.running&&i.terminate();if(s==="video"){let i=yield this.loadStream();for(const a of n)a.running&&(i=yield a.start(i));this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),i.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 i=this._ua.newStreamPlugins.find(d=>d.type===s);let a=i.getStream().clone();for(const d of n)d.running&&(a=yield d.start(a));const e=i.getConnection();this._overrideSenderTracks(a,e),this._ua.emit("changePluginStream",{type:s,stream:a})}})}stopProcessPlugins(s){const n=this._ua.processStreamPlugins.filter(i=>i.type===s);for(const i of n)i.running&&i.kill()}_receiveInviteResponse(s){if(Y.debug("receiveInviteResponse()"),this._dialog&&s.status_code>=200&&s.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.ackSent=!0,this.sendRequest(U.ACK);return}else{const n=new Ol(this,s,"UAC");if(n.error!==void 0){Y.debug(n.error);return}this.sendRequest(U.ACK),this.sendRequest(U.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(s.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=Hd();const i={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(qt.PUBLISHER)];this.sendRequest(U.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:e=>re(this,null,function*(){var d,_,u,g;if(e.status_code===200){if(this.subscribeSent=!0,e.body)try{const p=JSON.parse(e.body)||{};((_=(d=p.plugindata)==null?void 0:d.data)==null?void 0:_.videoroom)==="joined"&&this.myFeedList.push(p.plugindata.data.id),(g=(u=p.plugindata)==null?void 0:u.data)!=null&&g.publishers&&this.receivePublishers(p)}catch(p){console.error(p)}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){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){Y.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const n={originator:"remote",type:"answer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",s)).catch(a=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=Z.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,U.causes.MISSING_SDP),this._failed("remote",s,U.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;break}default:{const n=Me.sipErrorCause(s.status_code);this._failed("remote",s,n)}}}_sendReinvite(s={}){Y.debug("sendReinvite()");const n=Me.cloneArray(s.extraHeaders),i=Me.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let e=!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(u=>{u=this._mangleOffer(u);const g={originator:"local",type:"offer",sdp:u};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(U.INVITE,{extraHeaders:n,body:u,eventHandlers:{onSuccessResponse:p=>{d.call(this,p),e=!0},onErrorResponse:p=>{_.call(this,p)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function d(u){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(U.ACK),e))return;if(this._handleSessionTimersInIncomingResponse(u),u.body){if(!u.hasHeader("Content-Type")||u.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:u.body};Y.debug('emit "sdp"'),this.emit("sdp",g);const p=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(p)).then(()=>{i.succeeded&&i.succeeded(u)}).catch(T=>{_.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(u){i.failed&&i.failed(u)}}_sendUpdate(s={}){Y.debug("sendUpdate()");const n=Me.cloneArray(s.extraHeaders),i=Me.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,e=s.sdpOffer||!1;let d=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),e?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const p={originator:"local",type:"offer",sdp:g};Y.debug('emit "sdp"'),this.emit("sdp",p),this.sendRequest(U.UPDATE,{extraHeaders:n,body:g,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),d=!0},onErrorResponse:T=>{u.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{u.call(this)})):this.sendRequest(U.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:g=>{_.call(this,g)},onErrorResponse:g=>{u.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(g){if(this._status!==Z.STATUS_TERMINATED&&!d)if(this._handleSessionTimersInIncomingResponse(g),e){if(g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){u.call(this);return}}else{u.call(this);return}const p={originator:"remote",type:"answer",sdp:g.body};Y.debug('emit "sdp"'),this.emit("sdp",p);const T=new RTCSessionDescription({type:"answer",sdp:p.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{i.succeeded&&i.succeeded(g)}).catch(y=>{u.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',y),this.emit("peerconnection:setremotedescriptionfailed",y)})}else i.succeeded&&i.succeeded(g)}function u(g){i.failed&&i.failed(g)}}_acceptAndTerminate(s,n,i){Y.debug("acceptAndTerminate()");const a=[];n&&(i=i||U.REASON_PHRASE[n]||"",a.push(`Reason: SIP ;cause=${n}; text="${i}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest(U.ACK),this.sendRequest(U.BYE,{extraHeaders:a})),this._status=Z.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=Pt.parse(s),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const n of s.media)Nl.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 s.media)Nl.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const n of s.media)Nl.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Pt.write(s)}_setLocalMediaStatus(){let s=!0,n=!0;(this._localHold||this._remoteHold)&&(s=!1,n=!1),this._audioMuted&&(s=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(s,n){if(!this._sessionTimers.enabled)return;let i;s.session_expires&&s.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,i=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${i}`),this._sessionTimers.refresher=i==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let n;s.session_expires&&s.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,n=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===U.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&(Y.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:U.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const n=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="audio");for(const i of n)i.track.enabled=!s}_toggleMuteVideo(s){const n=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="video");for(const i of n)i.track.enabled=!s}_newJanusSession(s,n){Y.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:s,session:this,request:n})}_connecting(s){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,n){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:s,response:n||null})}_accepted(s,n){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:n||null})}_confirmed(s,n){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:n||null})}_ended(s,n,i){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:s,message:n||null,cause:i})}_failed(s,n,i){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:n||null,cause:i}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:s,message:n||null,cause:i})}_onhold(s){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:n}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:s,video:n})}_onunmute({audio:s,video:n}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:n})}}class Qs{constructor(s){if(this.headers={},s.length>0){let n=!1;const i=s.split(`\r
136
- `),a=i.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 e of i){if(e==`-------${this.ident}$`)break;if(e===""){n=!0;continue}if(e&&n)this.body+=`${e}\r
137
- `;else{const d=e.split(": ");this.addHeader(d[0],d[1].trim())}}}else this.ident=Me.createRandomToken(12),this.protocol="MSRP"}addHeader(s,n){this.headers[s]=n}getHeader(s){return this.headers[s]}toString(){let s=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
- `;for(const n in this.headers)s+=`${n}: ${this.headers[n]}\r
139
- `;return this.body&&(s+=`\r
134
+ `,Sd.send(i)}const $T=We(Ad);var Or={};const Ks=ft(),os=Ie,Ya=Bt(),Cd=gn(),za=$a,Ja=yn;Or.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:os.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:os.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:os.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${Ks.createRandomToken(12)}.invalid`};const vl={mandatory:{sockets(l){const n=[];if(za.isSocket(l))n.push({socket:l});else if(Array.isArray(l)&&l.length)for(const s of l)Object.prototype.hasOwnProperty.call(s,"socket")&&za.isSocket(s.socket)?n.push(s):za.isSocket(s)&&n.push({socket:s});else return;return n},uri(l){/^sip:/i.test(l)||(l=`${os.SIP}:${l}`);const n=Cd.parse(l);if(n)return n.user?n:void 0}},optional:{authorization_user(l){if(Ya.parse(`"${l}"`,"quoted_string")!==-1)return l},authorization_jwt(l){if(typeof l=="string")return l},user_agent(l){if(typeof l=="string")return l},connection_recovery_max_interval(l){if(Ks.isDecimal(l)){const n=Number(l);if(n>0)return n}},connection_recovery_min_interval(l){if(Ks.isDecimal(l)){const n=Number(l);if(n>0)return n}},contact_uri(l){if(typeof l=="string"){const n=Ya.parse(l,"SIP_URI");if(n!==-1)return n}},display_name(l){return l},instance_id(l){if(/^uuid:/i.test(l)&&(l=l.substr(5)),Ya.parse(l,"uuid")!==-1)return l},no_answer_timeout(l){if(Ks.isDecimal(l)){const n=Number(l);if(n>0)return n}},session_timers(l){if(typeof l=="boolean")return l},session_timers_refresh_method(l){if(typeof l=="string"&&(l=l.toUpperCase(),l===os.INVITE||l===os.UPDATE))return l},session_timers_force_refresher(l){if(typeof l=="boolean")return l},password(l){return String(l)},realm(l){return String(l)},ha1(l){return String(l)},register(l){if(typeof l=="boolean")return l},register_expires(l){if(Ks.isDecimal(l)){const n=Number(l);if(n>0)return n}},registrar_server(l){/^sip:/i.test(l)||(l=`${os.SIP}:${l}`);const n=Cd.parse(l);if(n)return n.user?void 0:n},use_preloaded_route(l){if(typeof l=="boolean")return l},extra_headers(l){const n=[];if(Array.isArray(l)&&l.length)for(const s of l)typeof s=="string"&&n.push(s);else return;return n}}};Or.load=(l,n)=>{for(const s in vl.mandatory)if(n.hasOwnProperty(s)){const i=n[s],a=vl.mandatory[s](i);if(a!==void 0)l[s]=a;else throw new Ja.ConfigurationError(s,i)}else throw new Ja.ConfigurationError(s);for(const s in vl.optional)if(n.hasOwnProperty(s)){const i=n[s];if(Ks.isEmpty(i))continue;const a=vl.optional[s](i);if(a!==void 0)l[s]=a;else throw new Ja.ConfigurationError(s,i)}};const VT=ut.EventEmitter,BT=ot,Tt=Ie,KT=Ug,bd=pd,Rd=gT,Id=ST,Xa=Vs,GT=Td,yl=ft(),WT=yn,YT=gn(),zT=vd,Qa=gt,JT=Ad,Za=Or,je=new BT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var wd=class extends VT{static get C(){return vt}constructor(l){if(je.debug("new() [configuration:%o]",l),super(),this._cache={credentials:{}},this._configuration=Object.assign({},Za.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=vt.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,l===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(l)}catch(n){throw this._status=vt.STATUS_NOT_READY,this._error=vt.CONFIGURATION_ERROR,n}this._registrator=new KT(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(l){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(l)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(l,n){je.debug("call()");const s=new bd(this);return s.connect(l,n),s}sendMessage(l,n,s){je.debug("sendMessage()");const i=new Rd(this);return i.send(l,n,s),i}sendOptions(l,n,s){je.debug("sendOptions()");const i=new Id(this);return i.send(l,n,s),i}terminateSessions(l){je.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(l)}stop(){if(je.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();const l=Object.keys(this._sessions).length;for(const n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){je.debug(`closing session ${n}`);try{this._sessions[n].terminate()}catch{}}for(const n in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,n))try{this._applicants[n].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&&l===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(l){return yl.normalizeTarget(l,this._configuration.hostport_params)}get(l){switch(l){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',l);return}}set(l,n){switch(l){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',l),!1}return!0}newTransaction(l){this._transactions[l.type][l.id]=l,this.emit("newTransaction",{transaction:l})}destroyTransaction(l){delete this._transactions[l.type][l.id],this.emit("transactionDestroyed",{transaction:l})}newDialog(l){this._dialogs[l.id]=l}destroyDialog(l){delete this._dialogs[l.id]}newMessage(l,n){this._applicants[l]=l,this.emit("newMessage",n)}newOptions(l,n){this._applicants[l]=l,this.emit("newOptions",n)}destroyMessage(l){delete this._applicants[l]}newRTCSession(l,n){this._sessions[l.id]=l,this.emit("newRTCSession",n)}destroyRTCSession(l){delete this._sessions[l.id]}registered(l){this.emit("registered",l)}unregistered(l){this.emit("unregistered",l)}registrationFailed(l){this.emit("registrationFailed",l)}receiveRequest(l){const n=l.method;if(l.ruri.user!==this._configuration.uri.user&&l.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),l.method!==Tt.ACK&&l.reply_sl(404);return}if(l.ruri.scheme===Tt.SIPS){l.reply_sl(416);return}if(Xa.checkTransaction(this,l))return;if(n===Tt.INVITE?new Xa.InviteServerTransaction(this,this._transport,l):n!==Tt.ACK&&n!==Tt.CANCEL&&new Xa.NonInviteServerTransaction(this,this._transport,l),n===Tt.OPTIONS){if(this.listeners("newOptions").length===0){l.reply(200);return}new Id(this).init_incoming(l)}else if(n===Tt.MESSAGE){if(this.listeners("newMessage").length===0){l.reply(405);return}new Rd(this).init_incoming(l)}else if(n===Tt.INVITE&&!l.to_tag&&this.listeners("newRTCSession").length===0){l.reply(405);return}let s,i;if(l.to_tag)s=this._findDialog(l.call_id,l.from_tag,l.to_tag),s?s.receiveRequest(l):n===Tt.NOTIFY?(i=this._findSession(l),i?i.receiveRequest(l):(je.debug("received NOTIFY request for a non existent subscription"),l.reply(481,"Subscription does not exist"))):n!==Tt.ACK&&l.reply(481);else switch(n){case Tt.INVITE:if(window.RTCPeerConnection)if(l.hasHeader("replaces")){const a=l.replaces;s=this._findDialog(a.call_id,a.from_tag,a.to_tag),s?(i=s.owner,i.isEnded()?l.reply(603):i.receiveRequest(l)):l.reply(481)}else i=new bd(this),i.init_incoming(l);else je.warn("INVITE received but WebRTC is not supported"),l.reply(488);break;case Tt.BYE:l.reply(481);break;case Tt.CANCEL:i=this._findSession(l),i?i.receiveRequest(l):je.debug("received CANCEL request for a non existent session");break;case Tt.ACK:break;case Tt.NOTIFY:this.emit("sipEvent",{event:l.event,request:l}),l.reply(200);break;default:l.reply(405);break}}_findSession({call_id:l,from_tag:n,to_tag:s}){const i=l+n,a=this._sessions[i],e=l+s,d=this._sessions[e];return a||d||null}_findDialog(l,n,s){let i=l+n+s,a=this._dialogs[i];return a||(i=l+s+n,a=this._dialogs[i],a||null)}_loadConfig(l){try{Za.load(this._configuration,l)}catch(i){throw i}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);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new GT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=XT.bind(this),this._transport.onconnect=QT.bind(this),this._transport.ondisconnect=ZT.bind(this),this._transport.ondata=ev.bind(this)}catch(i){throw je.warn(i),new WT.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 i=this._configuration.uri.clone();i.user=null,i.clearParams(),i.clearHeaders(),this._configuration.registrar_server=i}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new YT("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(i={}){const a=i.anonymous||null,e=i.outbound||null;let d="<";return a?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),e&&(a?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const s=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const i in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,i)&&(s.indexOf(i)!==-1?Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(const i in this._configuration)if(Object.prototype.hasOwnProperty.call(Za.settings,i))switch(i){case"uri":case"registrar_server":je.debug(`- ${i}: ${this._configuration[i]}`);break;case"password":case"ha1":case"authorization_jwt":je.debug(`- ${i}: NOT SHOWN`);break;default:je.debug(`- ${i}: ${JSON.stringify(this._configuration[i])}`)}}};function XT(l){this.emit("connecting",l)}function QT(l){this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function ZT(l){const n=["nict","ict","nist","ist"];for(const s of n)for(const i in this._transactions[s])Object.prototype.hasOwnProperty.call(this._transactions[s],i)&&this._transactions[s][i].onTransportError();this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function ev(l){const n=l.transport;let s=l.message;if(s=zT.parseMessage(s,this),!!s&&!(this._status===vt.STATUS_USER_CLOSED&&s instanceof Qa.IncomingRequest)&&JT(s,this,n)){if(s instanceof Qa.IncomingRequest)s.transport=n,this.receiveRequest(s);else if(s instanceof Qa.IncomingResponse){let i;switch(s.method){case Tt.INVITE:i=this._transactions.ict[s.via_branch],i&&i.receiveResponse(s);break;case Tt.ACK:break;default:i=this._transactions.nict[s.via_branch],i&&i.receiveResponse(s);break}}}}const tv=We(wd);for(var yt=[],eu=0;eu<256;++eu)yt.push((eu+256).toString(16).slice(1));function nv(l,n=0){return(yt[l[n+0]]+yt[l[n+1]]+yt[l[n+2]]+yt[l[n+3]]+"-"+yt[l[n+4]]+yt[l[n+5]]+"-"+yt[l[n+6]]+yt[l[n+7]]+"-"+yt[l[n+8]]+yt[l[n+9]]+"-"+yt[l[n+10]]+yt[l[n+11]]+yt[l[n+12]]+yt[l[n+13]]+yt[l[n+14]]+yt[l[n+15]]).toLowerCase()}var El,sv=new Uint8Array(16);function rv(){if(!El&&(El=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!El))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return El(sv)}var iv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Od={randomUUID:iv};function Nd(l,n,s){if(Od.randomUUID&&!n&&!l)return Od.randomUUID();l=l||{};var i=l.random||(l.rng||rv)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,n){s=s||0;for(var a=0;a<16;++a)n[s+a]=i[a];return n}return nv(i)}var ke=ft();const En=We(ke),tu=new ll("Dialog"),Yn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class Sl{static get C(){return Yn}constructor(n,s,i,a=Yn.STATUS_CONFIRMED){if(this._owner=n,this._ua=n._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,s instanceof gt.IncomingResponse&&(a=s.status_code<200?Yn.STATUS_EARLY:Yn.STATUS_CONFIRMED),i==="UAS"){this._id={call_id:s.call_id,local_tag:s.to_tag,remote_tag:s.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=s.cseq,this._local_uri=s.parseHeader("to").uri,this._remote_uri=s.parseHeader("from").uri;let e=s.getHeaders("to")[0].split(";")[0];e=e.match(/<([^>]*)>/)[1],this._remote_target=e,this._route_set=s.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(i==="UAC"){this._id={call_id:s.call_id,local_tag:s.from_tag,remote_tag:s.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=s.cseq,this._local_uri=s.parseHeader("from").uri,this._remote_uri=s.parseHeader("to").uri;let e=s.getHeaders("to")[0].split(";")[0];e=e.match(/<([^>]*)>/)[1],this._remote_target=e,this._route_set=s.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),tu.debug(`new ${i} dialog created with status ${this._state===Yn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(n){this._local_seqnum=n}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(n){this._uac_pending_reply=n}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Yn.STATUS_TERMINATED}update(n,s){this._state=Yn.STATUS_CONFIRMED,tu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),s==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}terminate(){tu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Yn.STATUS_TERMINATED}sendRequest(n,s={}){const i=En.cloneArray(s.extraHeaders),a=En.cloneObject(s.eventHandlers),e=s.body||null,d=this._createRequest(n,i,e);return a.onAuthenticated=()=>{this._local_seqnum+=1},new qg(this,d,a).send(),d}receiveRequest(n){this._checkInDialogRequest(n)&&(n.method===U.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===U.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}_createRequest(n,s,i){s=En.cloneArray(s),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=n===U.CANCEL||n===U.ACK?this._local_seqnum:this._local_seqnum+=1;return new gt.OutgoingRequest(n,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},s,i)}_checkInDialogRequest(n){if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===U.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===U.INVITE||n.method===U.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){const s=(Math.random()*10|0)+1;return n.reply(500,null,[`Retry-After:${s}`]),!1}else{this._uas_pending_reply=!0;const s=()=>{(n.server_transaction.state===jt.C.STATUS_ACCEPTED||n.server_transaction.state===jt.C.STATUS_COMPLETED||n.server_transaction.state===jt.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",s),this._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",()=>{n.server_transaction.state===jt.C.STATUS_ACCEPTED&&(this._remote_target=n.parseHeader("contact").uri)})}else n.method===U.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",()=>{n.server_transaction.state===jt.C.STATUS_COMPLETED&&(this._remote_target=n.parseHeader("contact").uri)});return!0}}class ov{constructor(n,s){on(this,"plugin",null),on(this,"rtcpPeer",null),on(this,"handleId",0),on(this,"info",null),on(this,"joinResult",null),on(this,"state",{}),on(this,"stream",null),on(this,"loaded",!1),on(this,"aTracks",[]),on(this,"vTracks",[]),this.info=n,this.plugin=s,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(n){var s;this.state={...this.state,...n||{}},(s=this.plugin)==null||s.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(n){var s,i,a,e;const d=(i=(s=n?.plugindata)==null?void 0:s.data)==null?void 0:i.newStatePublisher,_=((e=(a=n?.plugindata)==null?void 0:a.data)==null?void 0:e.publisher_state).find(u=>u.id===d);this.updateMemberState(_?.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(n=>{n.stop()})}}class Gt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(n){return Gt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(s=>s.kind===n):[]}static async getMicrophoneList(){return(await Gt.getDevices("audioinput")).map((n,s)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${s+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Gt.getDevices("audiooutput")).map((n,s)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${s+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Gt.getDevices("videoinput")).map((n,s)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${s+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(n){n&&n.getTracks().forEach(s=>{s.stop()})}static async getMediaFromInputs({videoInput:n,audioInput:s}){let i,a;n==="default"?i=!0:n&&n!=="default"&&(i={deviceId:{exact:n}}),s==="default"?a=!0:s&&s!=="default"&&(a={deviceId:{exact:s}});const e={audio:a,video:i};return Gt.getUserMedia(e)}static async getUserMedia(n){return await navigator.mediaDevices.getUserMedia(n)}static async changeAudioOutput(n,s){if(!(!n||!s))if(typeof n.sinkId<"u")try{await n.setSinkId(s)}catch(i){let a=i;i.name==="SecurityError"&&(a=`You need to use HTTPS for selecting audio output device: ${i}`),console.error(a)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(n){const s=n.getAudioTracks();if(s.length!==0)return s.forEach(i=>{i.enabled=!i.enabled}),s[0].enabled}static toggleVideoMute(n){const s=n.getVideoTracks();if(s.length!==0)return s.forEach(i=>{i.enabled=!i.enabled}),s[0].enabled}static async getStream(n={video:!0,audio:!0}){try{const s=await navigator.mediaDevices.getUserMedia(n);let i=s.getTracks();return n.video?i=s.getVideoTracks():n.audio&&(i=s.getAudioTracks()),i.length===0?{stream:s,track:null}:{stream:s,track:i[0]}}catch(s){return console.warn(s),{stream:null,track:null}}}}var lv=gn();const ls=We(lv),Mt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},Y=new ll("JanusSession"),av="/opt/recordings/",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},Al=["audio","video"];class Cl extends ut.EventEmitter{static get C(){return Z}constructor(n){Y.debug("new"),super(),this._id=null,this._ua=n,this._status=Z.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:U.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 Z}get causes(){return U.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(n){this._data=n}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}}getPTypeHeader(n){return`PTYPE: ${n}`}generateOpaqueId(){return`videoroomtest-${Nd().replace(/-/g,"").slice(0,12)}`}connect(n,s,i={},a){Y.debug("connect()"),this.display_name=s;const e=n,d=ke.cloneObject(i.eventHandlers),_=ke.cloneArray(i.extraHeaders),u=ke.cloneObject(i.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...u};const g=i.mediaStream||null,f=ke.cloneObject(i.pcConfig,{iceServers:[]}),T=i.rtcConstraints||null,y=i.rtcOfferConstraints||null;if(this._rtcOfferConstraints=y,this._rtcAnswerConstraints=i.rtcAnswerConstraints||null,this._data=i.data||this._data,n===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new Kn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Kn.NotSupportedError("WebRTC not supported");if(n=this._ua.normalizeTarget(n),this.room_id=n.user,this.target=n,!n)throw new TypeError(`Invalid target: ${e}`);this._sessionTimers.enabled&&ke.isDecimal(i.sessionTimersExpires)&&(i.sessionTimersExpires>=U.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=i.sessionTimersExpires:this._sessionTimers.defaultExpires=U.SESSION_EXPIRES);for(const b in d)Object.prototype.hasOwnProperty.call(d,b)&&this.on(b,d[b]);this._from_tag=ke.newTag();const A=i.anonymous||!1,w={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:A,outbound:!0}),A?(w.from_display_name="Anonymous",w.from_uri=new ls("sip","anonymous","anonymous.invalid"),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),_.push("Privacy: id")):i.fromUserName&&(w.from_uri=new ls("sip",i.fromUserName,this._ua.configuration.uri.host),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),i.fromDisplayName&&(w.from_display_name=i.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 gt.InitialOutgoingInviteRequest(n,this._ua,w,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(f,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(u,y,g)}_overrideSenderTracks(n,s){n.getTracks().forEach(i=>{s.getSenders().forEach(async a=>{a.track.kind===i.kind&&(i.kind==="audio"&&!this.isAudioOn&&(i.enabled=!1),i.kind==="video"&&!this.isVideoOn&&(i.enabled=!1),await a.replaceTrack(i))})})}init_incoming(n,s){Y.debug("init_incoming()");let i;const a=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0;if(n.body&&a!=="application/sdp"){n.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=n.from_tag,this._id=n.call_id+this._from_tag,this._request=n,this._contact=this._ua.contact.toString(),n.hasHeader("expires")&&(i=n.getHeader("expires")*1e3),n.to_tag=ke.newTag(),!this._createDialog(n,"UAS",!0)){n.reply(500,"Missing Contact header field");return}n.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{n.reply(408),this._failed("local",null,U.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(n.reply(487),this._failed("system",null,U.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from,s&&s(this),this._newJanusSession("remote",n),this._status!==Z.STATUS_TERMINATED&&(n.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(n={}){Y.debug("answer()");const s=this._request,i=ke.cloneArray(n.extraHeaders),a=ke.cloneObject(n.mediaConstraints),e=n.mediaStream||null,d=ke.cloneObject(n.pcConfig,{iceServers:[]}),_=n.rtcConstraints||null,u=n.rtcAnswerConstraints||null,g=ke.cloneObject(n.rtcOfferConstraints);let f,T=!1,y=!1,A=!1,w=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=n.rtcOfferConstraints||null,this._data=n.data||this._data,this._direction!=="incoming")throw new Kn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new Kn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&ke.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=U.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=U.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(s,"UAS")){s.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);const b=s.parseSDP();Array.isArray(b.media)||(b.media=[b.media]);for(const R of b.media)R.type==="audio"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(A=!0)),R.type==="video"&&(y=!0,(!R.direction||R.direction==="sendrecv")&&(w=!0));if(e&&a.audio===!1){f=e.getAudioTracks();for(const R of f)e.removeTrack(R)}if(e&&a.video===!1){f=e.getVideoTracks();for(const R of f)e.removeTrack(R)}!e&&a.audio===void 0&&(a.audio=A),!e&&a.video===void 0&&(a.video=w),!e&&!T&&!g.offerToReceiveAudio&&(a.audio=!1),!e&&!y&&!g.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(d,_),Promise.resolve().then(()=>{if(e)return e;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(R=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(s.reply(480),this._failed("local",null,U.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(G=>{this._connection.addTrack(G,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",R);const G=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(G)).catch(x=>{throw s.reply(488),this._failed("system",null,U.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',x),this.emit("peerconnection:setremotedescriptionfailed",x),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(s),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw s.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",u).catch(()=>{throw s.reply(500),new Error("_createLocalDescription() failed")})}).then(R=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(s,i),s.reply(200,null,i,R,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,U.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(R)})}terminate(n={}){Y.debug("terminate()");const s=n.cause||U.causes.BYE,i=ke.cloneArray(n.extraHeaders),a=n.body;let e,d=n.status_code,_=n.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new Kn.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"),d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||U.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=Z.STATUS_CANCELED,this._failed("local",null,U.causes.CANCELED);break;case Z.STATUS_WAITING_FOR_ANSWER:case Z.STATUS_ANSWERED:if(Y.debug("rejecting session"),d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,U.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(Y.debug("terminating session"),_=n.reason_phrase||U.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===U.ACK&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate(),this.closeSession())}),this._ended("local",null,s),this._dialog=u,this._ua.newDialog(u)}else{const u={janus:"leave"},g=["Content-Type: application/json",this.getPTypeHeader(Mt.LEAVE)];this.sendRequest(U.BYE,{extraHeaders:g,body:JSON.stringify(u)}),this.closeSession(),this._ended("local",null,s)}}}configureMedia(n){this.isAudioOn=n.audio,this.isVideoOn=n.video}enableAudio(n){const s={janus:"message",body:{audio:n},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(Mt.AUDIO_CHANGE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s),eventHandlers:{onSuccessResponse:async a=>{a.status_code===200&&(this._ua.emit("changeAudioState",n),this.sendStateMessage({audio:n}))}}})}startAudio(){Gt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Gt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(n){const s={janus:"message",body:{video:n},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(Mt.VIDEO_CHANGE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s),eventHandlers:{onSuccessResponse:async a=>{a.status_code===200&&(this._ua.emit("changeVideoState",n),this.sendStateMessage({video:n}))}}})}startVideo(){Gt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Gt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(n){const s={janus:"message",body:{request:"state",data:n},handle_id:this.handle_id,session_id:this.session_id},i=["Content-Type: application/json",this.getPTypeHeader(Mt.STATE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s)})}sendInfo(n,s,i={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new Kn.InvalidStateError(this._status);new Ha(this).send(n,s,i)}mute(n={audio:!0,video:!1}){Y.debug("mute()");let s=!1,i=!1;this._audioMuted===!1&&n.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&n.video&&(i=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||i===!0)&&this._onmute({audio:s,video:i})}unmute(n={audio:!0,video:!0}){Y.debug("unmute()");let s=!1,i=!1;this._audioMuted===!0&&n.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&n.video&&(i=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||i===!0)&&this._onunmute({audio:s,video:i})}hold(n={},s){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 i={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:n.extraHeaders}),!0}unhold(n={},s){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 i={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:i,extraHeaders:n.extraHeaders}),!0}renegotiate(n={},s){Y.debug("renegotiate()");const i=n.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{s&&s()},failed:()=>{this.terminate({cause:U.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),n.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:i,extraHeaders:n.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:i,extraHeaders:n.extraHeaders}),!0}refer(n,s){Y.debug("refer()");const i=n;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(n=this._ua.normalizeTarget(n),!n)throw new TypeError(`Invalid target: ${i}`);const a=new rT(this);a.sendRefer(n,s);const e=a.id;return this._referSubscribers[e]=a,a.on("requestFailed",()=>{delete this._referSubscribers[e]}),a.on("accepted",()=>{delete this._referSubscribers[e]}),a.on("failed",()=>{delete this._referSubscribers[e]}),a}sendRequest(n,s){return Y.debug("sendRequest()"),this._dialog.sendRequest(n,s)}receiveNotify(n){Y.debug("receiveRequest()")}receiveRequest(n){if(Y.debug("receiveRequest()"),n.method===U.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",n,U.causes.CANCELED));else switch(n.method){case U.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(!n.body){this.terminate({cause:U.causes.MISSING_SDP,status_code:400});break}const s={originator:"remote",type:"answer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",n)}).catch(a=>{this.terminate({cause:U.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",n);break;case U.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(n.reply(200),this._ended("remote",n,U.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(n.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",n,U.causes.BYE)):n.reply(403,"Wrong Status");break;case U.INVITE:this._status===Z.STATUS_CONFIRMED?n.hasHeader("replaces")?this._receiveReplaces(n):this._receiveReinvite(n):n.reply(403,"Wrong Status");break;case U.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 s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new Wg(this).init_incoming(n):s!==void 0?new Ha(this).init_incoming(n):n.reply(415)}else n.reply(403,"Wrong Status");break;case U.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(n):n.reply(403,"Wrong Status");break;case U.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(n):n.reply(403,"Wrong Status");break;case U.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(n):n.reply(403,"Wrong Status");break;default:n.reply(501)}}onTransportError(){Y.warn("onTransportError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){Y.warn("onRequestTimeout()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){Y.warn("onDialogError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.DIALOG_ERROR,cause:U.causes.DIALOG_ERROR})}newDTMF(n){Y.debug("newDTMF()"),this.emit("newDTMF",n)}newInfo(n){Y.debug("newInfo()"),this.emit("newInfo",n)}_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"),ke.closeMediaStream(this._localMediaStream)),this._status!==Z.STATUS_TERMINATED){if(this._status=Z.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(n){Y.warn("close() | error closing the RTCPeerConnection: %o",n)}for(const n in this._timers)Object.prototype.hasOwnProperty.call(this._timers,n)&&clearTimeout(this._timers[n]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const n in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,n)&&(this._earlyDialogs[n].terminate(),delete this._earlyDialogs[n]);for(const n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(n,s){let i=mr.T1;function a(){this._status===Z.STATUS_WAITING_FOR_ACK&&(n.reply(200,null,[`Contact: ${this._contact}`],s),i<mr.T2&&(i=i*2,i>mr.T2&&(i=mr.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),i))}this._timers.invite2xxTimer=setTimeout(a.bind(this),i)}_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(U.BYE),this._ended("remote",null,U.causes.NO_ACK))},mr.TIMER_H)}_createRTCConnection(n,s){this.stunServers,this._connection=new RTCPeerConnection(n,s),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:U.causes.RTP_TIMEOUT,status_code:408,reason_phrase:U.causes.RTP_TIMEOUT})});let i;const a=e=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||e.candidate&&(this._candidates.push(e.candidate),clearTimeout(i),i=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,Y.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(n,s){if(Y.debug("createLocalDescription()"),n!=="offer"&&n!=="answer")throw new Error(`createLocalDescription() | invalid type "${n}"`);const i=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>n==="offer"?i.createOffer(s).catch(a=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):i.createAnswer(s).catch(a=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>(this.jsepOffer=a,i.setLocalDescription(a).catch(e=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),this.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e))))).then(()=>{const a=s&&s.iceRestart;if(i.iceGatheringState==="complete"&&!a||i.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const e={originator:"local",type:n,sdp:i.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",e),Promise.resolve(e.sdp)}return new Promise(e=>{let d=!1,_,u;this._iceReady=!1;const g=()=>{i.removeEventListener("icecandidate",_),i.removeEventListener("icegatheringstatechange",u),d=!0,this._rtcReady=!0,this._iceReady=!0;const f={originator:"local",type:n,sdp:i.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",f),e(f.sdp)};i.addEventListener("icecandidate",_=f=>{const T=f.candidate;T?this.emit("icecandidate",{candidate:T,ready:g}):d||g()}),i.addEventListener("icegatheringstatechange",u=()=>{i.iceGatheringState==="complete"&&!d&&g()})})})}_createDialog(n,s,i){const a=s==="UAS"?n.to_tag:n.from_tag,e=s==="UAS"?n.from_tag:n.to_tag,d=n.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new Sl(this,n,s,Sl.C.STATUS_EARLY),_.error?(Y.debug(_.error),this._failed("remote",n,U.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=n.from_tag,this._to_tag=n.to_tag,_)return _.update(n,s),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new Sl(this,n,s);return u.error?(Y.debug(u.error),this._failed("remote",n,U.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_receiveReinvite(n){Y.debug("receiveReinvite()");const s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0,i={request:n,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",f=ke.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);n.reply(u,g,f)}if(this.emit("reinvite",i),a)return;if(this._late_sdp=!1,!n.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(_=>{d.call(this,_)}).catch(()=>{n.reply(500)});return}if(s!=="application/sdp"){Y.debug("invalid Content-Type"),n.reply(415);return}this._processInDialogSdpOffer(n).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{Y.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(n,u),this._late_sdp&&(_=this._mangleOffer(_)),n.reply(200,null,u,_,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,_),this._setACKTimer()}),typeof i.callback=="function"&&i.callback()}}_receiveUpdate(n){Y.debug("receiveUpdate()");const s=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0,i={request:n,callback:void 0,reject:e.bind(this)};let a=!1;function e(_={}){a=!0;const u=_.status_code||403,g=_.reason_phrase||"",f=ke.cloneArray(_.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);n.reply(u,g,f)}if(this.emit("update",i),a)return;if(!n.body){d.call(this,null);return}if(s!=="application/sdp"){Y.debug("invalid Content-Type"),n.reply(415);return}this._processInDialogSdpOffer(n).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{Y.warn(_)});function d(_){const u=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(n,u),n.reply(200,null,u,_),typeof i.callback=="function"&&i.callback()}}_processInDialogSdpOffer(n){Y.debug("_processInDialogSdpOffer()");const s=n.parseSDP();let i=!1;for(const d of s.media){if(Al.indexOf(d.type)===-1)continue;const _=d.direction||s.direction||"sendrecv";if(_==="sendonly"||_==="inactive")i=!0;else{i=!1;break}}const a={originator:"remote",type:"offer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",a);const e=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(e).catch(d=>{throw n.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),this.emit("peerconnection:setremotedescriptionfailed",d),d})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&i===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&i===!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(d=>{throw n.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',d),d})}).catch(d=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",d)}),this._connectionPromiseQueue}_receiveRefer(n){if(Y.debug("receiveRefer()"),!n.refer_to){Y.debug("no Refer-To header field present in REFER"),n.reply(400);return}if(n.refer_to.uri.scheme!==U.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),n.reply(416);return}n.reply(202);const s=new eT(this,n.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:n,accept:(e,d)=>{i.call(this,e,d)},reject:()=>{a.call(this)}});function i(e,d={}){if(e=typeof e=="function"?e:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const _=new Cl(this._ua);if(_.on("progress",({response:u})=>{s.notify(u.status_code,u.reason_phrase)}),_.on("accepted",({response:u})=>{s.notify(u.status_code,u.reason_phrase)}),_.on("_failed",({message:u,cause:g})=>{u?s.notify(u.status_code,u.reason_phrase):s.notify(487,g)}),n.refer_to.uri.hasHeader("replaces")){const u=decodeURIComponent(n.refer_to.uri.getHeader("replaces"));d.extraHeaders=ke.cloneArray(d.extraHeaders),d.extraHeaders.push(`Replaces: ${u}`)}_.connect(n.refer_to.uri.toAor(),d,e)}function a(){s.notify(603)}}_receiveNotify(n){switch(Y.debug("receiveNotify()"),n.event||n.reply(400),n.event.event){case"refer":{let s,i;if(n.event.params&&n.event.params.id)s=n.event.params.id,i=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)i=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{n.reply(400,"Missing event id parameter");return}if(!i){n.reply(481,"Subscription does not exist");return}i.receiveNotify(n),n.reply(200);break}default:n.reply(489)}}_receiveReplaces(n){Y.debug("receiveReplaces()");function s(a){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const e=new Cl(this._ua);e.on("confirmed",()=>{this.terminate()}),e.init_incoming(n,a)}function i(){Y.debug("Replaced INVITE rejected by the user"),n.reply(486)}this.emit("replaces",{request:n,accept:a=>{s.call(this,a)},reject:()=>{i.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(n,s,i){this.ackSent=!1,this.publisherSubscribeSent=!1;const a=new yr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});Promise.resolve().then(()=>{if(i)return i;if(n.audio||n.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(e=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,U.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),e)})}).then(e=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=e,e&&e.getTracks().forEach(d=>{this._connection.addTrack(d,e)}),this._connecting(this._request),this._createLocalDescription("offer",s).catch(d=>{throw this._failed("local",null,U.causes.WEBRTC_ERROR),d})}).then(e=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");const d={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},_=JSON.stringify(d);this._request.body=_,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(e)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(n){this.mediaConstraints={...n},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const n={};this.isAudioOn?this.mediaConstraints.audio?n.audio=this.mediaConstraints.audio:n.audio=!0:n.audio=!1,this.isVideoOn?this.mediaConstraints.video?n.video=this.mediaConstraints.video:n.video=!0:n.video=!1;let s=null;try{s=await navigator.mediaDevices.getUserMedia(n)}catch{try{n.video=!1,s=await navigator.mediaDevices.getUserMedia(n)}catch{n.audio=!1,n.video=!1,s=await navigator.mediaDevices.getUserMedia(n)}}return s}addTracks(n){this._connection.getSenders().forEach(s=>{this._connection.removeTrack(s)}),n.forEach(s=>{this._connection.addTrack(s)})}getRecordFileName(){return av+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let n=0;n<this.iceCandidates.length;n++)await this._connection.addIceCandidate(this.iceCandidates[n]);this.iceCandidates=[]}async _sendConfigureMessage(n){const s=this._candidates.map(e=>({janus:"trickle",candidate:e,handle_id:this.handle_id,session_id:this.session_id})),i={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...n},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...s]},a=["Content-Type: application/json",this.getPTypeHeader(Mt.ICE)];this.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async e=>{this.isConfigureSent=!0;const d=e.data.split(`\r
135
+ `),_=d[d.length-1],u=JSON.parse(_);await this._connection.setRemoteDescription(u.jsep),this._candidates=[]}}})}_sendMemberStartMessage(n,s){const i={janus:"message",body:{request:"start",room:this.room_id},handle_id:n.handleId,session_id:this.session_id,jsep:s},a=["Content-Type: application/json",this.getPTypeHeader(Mt.CONFIGURE)];this.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async e=>{e.status_code===200&&await n.rtcpPeer.setLocalDescription(s)}}})}_sendTrickleMessage(n){const s={trickles:[...n.map(a=>({janus:"trickle",candidate:a,handle_id:this.handle_id,session_id:this.session_id}))]},i=[this.getPTypeHeader(Mt.TRICKLE)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s),eventHandlers:{onSuccessResponse:async a=>{}}})}async _answerAttachedStream(n,s){let i=null;const a=async u=>{if(!n.rtcpPeer||n.loaded)return;{n.loaded=!0;const A={audio:!0,video:!0};await new Promise(w=>{setTimeout(w,100)}),i=await n.rtcpPeer.createAnswer(A),this._sendMemberStartMessage(n,i)}const g=u.streams[0].getAudioTracks(),f=u.streams[0].getVideoTracks(),T=[];g[0]&&T.push(g[0]),f[0]&&T.push(f[0]);const y=new MediaStream(T);n.stream=y,this._ua.emit("memberJoin",n.memberInfo)};let e,d=[];const _=u=>{n.rtcpPeer.signalingState!=="stable"&&n.rtcpPeer.signalingState!=="have-local-offer"||(d.push(u.candidate||null),clearTimeout(e),e=setTimeout(()=>{this._sendTrickleMessage(d)},500))};n.rtcpPeer=new RTCPeerConnection,n.rtcpPeer.ontrack=a,n.rtcpPeer.onicecandidate=_,n.rtcpPeer.sender=s.sender,await n.rtcpPeer.setRemoteDescription(s.jsep)}_sendJoinMemberRequest(n){const s={janus:"message",body:{request:"join",room:this.room_id,feed:n.info.id,ptype:"subscriber"},handle_id:n.handleId,session_id:this.session_id},i=[this.getPTypeHeader(Mt.SUBSCRIBER)];this.sendRequest(U.SUBSCRIBE,{extraHeaders:i,body:JSON.stringify(s),eventHandlers:{onSuccessResponse:async a=>{var e,d;if(a.status_code===200){const _=JSON.parse(a.body);(d=(e=_?.plugindata)==null?void 0:e.data)!=null&&d.id&&await this._answerAttachedStream(n,_)}}}})}_attachMember(n){const s={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},i=[this.getPTypeHeader(Mt.SUBSCRIBER)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s),eventHandlers:{onSuccessResponse:async a=>{if(a.status_code===200){const e=JSON.parse(a.body).data.id;n.handleId=e,this._sendJoinMemberRequest(n)}}}})}_detachMember(n){const s={janus:"detach",handle_id:n.handleId,session_id:this.session_id},i=[this.getPTypeHeader(Mt.SUBSCRIBER)];this.sendRequest(U.INFO,{extraHeaders:i,body:JSON.stringify(s)}),Gt.stopStreamTracks(n.memberInfo.stream),this._ua.emit("memberHangup",n.memberInfo)}receivePublishers(n){var s,i,a,e,d,_,u,g;const f={...this.memberList};(i=(s=n?.plugindata)==null?void 0:s.data)==null||i.publishers.forEach(T=>{delete f[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new ov(T,this),this._attachMember(this.memberList[T.id]))}),((e=(a=n?.plugindata)==null?void 0:a.data)==null?void 0:e.videoroom)==="synced"&&Object.keys(f).forEach(T=>{f[T].hangup(),delete this.memberList[T]}),this.publishers=(_=(d=n?.plugindata)==null?void 0:d.data)==null?void 0:_.publishers,this.private_id=(g=(u=n?.plugindata)==null?void 0:u.data)==null?void 0:g.private_id}receiveUnpublished(n){const s=this.memberList[n];s&&(s.hangup(),this._detachMember(s),delete this.memberList[n])}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 n=this._ua.processStreamPlugins;let s=await this.loadStream();for(const i of n)s=await i.process(s);this.stream.getTracks().forEach(i=>{this.stream.removeTrack(i),i.stop()}),s.getTracks().forEach(i=>{this.stream.addTrack(i)})}async resyncPlugins(n){const s=this._ua.processStreamPlugins.filter(i=>i.type===n);for(const i of s)i.running&&i.terminate();if(n==="video"){let i=await this.loadStream();for(const a of s)a.running&&(i=await a.start(i));this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),i.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 i=this._ua.newStreamPlugins.find(d=>d.type===n);let a=i.getStream().clone();for(const d of s)d.running&&(a=await d.start(a));const e=i.getConnection();this._overrideSenderTracks(a,e),this._ua.emit("changePluginStream",{type:n,stream:a})}}stopProcessPlugins(n){const s=this._ua.processStreamPlugins.filter(i=>i.type===n);for(const i of s)i.running&&i.kill()}_receiveInviteResponse(n){if(Y.debug("receiveInviteResponse()"),this._dialog&&n.status_code>=200&&n.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===n.call_id&&this._dialog.id.local_tag===n.from_tag&&this._dialog.id.remote_tag===n.to_tag){this.ackSent=!0,this.sendRequest(U.ACK);return}else{const s=new Sl(this,n,"UAC");if(s.error!==void 0){Y.debug(s.error);return}this.sendRequest(U.ACK),this.sendRequest(U.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const s=JSON.parse(n.body);this.setupMediaStream().then(()=>{this.session_id=s.session_id,this.handle_id=s.data.id,this.client_id=Nd();const i={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(Mt.PUBLISHER)];this.sendRequest(U.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async e=>{var d,_,u,g;if(e.status_code===200){if(this.subscribeSent=!0,e.body)try{const f=JSON.parse(e.body)||{};((_=(d=f.plugindata)==null?void 0:d.data)==null?void 0:_.videoroom)==="joined"&&this.myFeedList.push(f.plugindata.data.id),(g=(u=f.plugindata)==null?void 0:u.data)!=null&&g.publishers&&this.receivePublishers(f)}catch(f){console.error(f)}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){n.status_code>=100&&n.status_code<200?this._request.cancel(this._cancel_reason):n.status_code>=200&&n.status_code<299&&this._acceptAndTerminate(n);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(n.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(n.status_code):{if(!n.to_tag){Y.debug("1xx response received without to tag");break}if(n.hasHeader("contact")&&!this._createDialog(n,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!n.body){this._progress("remote",n);break}const s={originator:"remote",type:"answer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",n)).catch(a=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(n.status_code):{if(this._status=Z.STATUS_CONFIRMED,!n.body){this._acceptAndTerminate(n,400,U.causes.MISSING_SDP),this._failed("remote",n,U.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(n,"UAC"))break;break}default:{const s=ke.sipErrorCause(n.status_code);this._failed("remote",n,s)}}}_sendReinvite(n={}){Y.debug("sendReinvite()");const s=ke.cloneArray(n.extraHeaders),i=ke.cloneObject(n.eventHandlers),a=n.rtcOfferConstraints||this._rtcOfferConstraints||null;let e=!1;s.push(`Contact: ${this._contact}`),s.push("Content-Type: application/sdp"),this._sessionTimers.running&&s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(u=>{u=this._mangleOffer(u);const g={originator:"local",type:"offer",sdp:u};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(U.INVITE,{extraHeaders:s,body:u,eventHandlers:{onSuccessResponse:f=>{d.call(this,f),e=!0},onErrorResponse:f=>{_.call(this,f)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_()});function d(u){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(U.ACK),e))return;if(this._handleSessionTimersInIncomingResponse(u),u.body){if(!u.hasHeader("Content-Type")||u.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:u.body};Y.debug('emit "sdp"'),this.emit("sdp",g);const f=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(f)).then(()=>{i.succeeded&&i.succeeded(u)}).catch(T=>{_.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(u){i.failed&&i.failed(u)}}_sendUpdate(n={}){Y.debug("sendUpdate()");const s=ke.cloneArray(n.extraHeaders),i=ke.cloneObject(n.eventHandlers),a=n.rtcOfferConstraints||this._rtcOfferConstraints||null,e=n.sdpOffer||!1;let d=!1;s.push(`Contact: ${this._contact}`),this._sessionTimers.running&&s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),e?(s.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const f={originator:"local",type:"offer",sdp:g};Y.debug('emit "sdp"'),this.emit("sdp",f),this.sendRequest(U.UPDATE,{extraHeaders:s,body:g,eventHandlers:{onSuccessResponse:T=>{_.call(this,T),d=!0},onErrorResponse:T=>{u.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{u.call(this)})):this.sendRequest(U.UPDATE,{extraHeaders:s,eventHandlers:{onSuccessResponse:g=>{_.call(this,g)},onErrorResponse:g=>{u.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function _(g){if(this._status!==Z.STATUS_TERMINATED&&!d)if(this._handleSessionTimersInIncomingResponse(g),e){if(g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){u.call(this);return}}else{u.call(this);return}const f={originator:"remote",type:"answer",sdp:g.body};Y.debug('emit "sdp"'),this.emit("sdp",f);const T=new RTCSessionDescription({type:"answer",sdp:f.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{i.succeeded&&i.succeeded(g)}).catch(y=>{u.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',y),this.emit("peerconnection:setremotedescriptionfailed",y)})}else i.succeeded&&i.succeeded(g)}function u(g){i.failed&&i.failed(g)}}_acceptAndTerminate(n,s,i){Y.debug("acceptAndTerminate()");const a=[];s&&(i=i||U.REASON_PHRASE[s]||"",a.push(`Reason: SIP ;cause=${s}; text="${i}"`)),(this._dialog||this._createDialog(n,"UAC"))&&(this.sendRequest(U.ACK),this.sendRequest(U.BYE,{extraHeaders:a})),this._status=Z.STATUS_TERMINATED}_mangleOffer(n){if(!this._localHold&&!this._remoteHold)return n;if(n=Dt.parse(n),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const s of n.media)Al.indexOf(s.type)!==-1&&(s.direction?s.direction==="sendrecv"?s.direction="sendonly":s.direction==="recvonly"&&(s.direction="inactive"):s.direction="sendonly")}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");for(const s of n.media)Al.indexOf(s.type)!==-1&&(s.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const s of n.media)Al.indexOf(s.type)!==-1&&(s.direction?s.direction==="sendrecv"?s.direction="recvonly":s.direction==="recvonly"&&(s.direction="inactive"):s.direction="recvonly")}return Dt.write(n)}_setLocalMediaStatus(){let n=!0,s=!0;(this._localHold||this._remoteHold)&&(n=!1,s=!1),this._audioMuted&&(n=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!n),this._toggleMuteVideo(!s)}_handleSessionTimersInIncomingRequest(n,s){if(!this._sessionTimers.enabled)return;let i;n.session_expires&&n.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=n.session_expires,i=n.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uas"),s.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${i}`),this._sessionTimers.refresher=i==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(n){if(!this._sessionTimers.enabled)return;let s;n.session_expires&&n.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=n.session_expires,s=n.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}_runSessionTimer(){const n=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===U.UPDATE?this._sendUpdate():this._sendReinvite())},n*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&(Y.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:U.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},n*1100)}_toggleMuteAudio(n){const s=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="audio");for(const i of s)i.track.enabled=!n}_toggleMuteVideo(n){const s=this._connection.getSenders().filter(i=>i.track&&i.track.kind==="video");for(const i of s)i.track.enabled=!n}_newJanusSession(n,s){Y.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:n,session:this,request:s})}_connecting(n){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:n})}_progress(n,s){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:n,response:s||null})}_accepted(n,s){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:n,response:s||null})}_confirmed(n,s){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:n,ack:s||null})}_ended(n,s,i){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:n,message:s||null,cause:i})}_failed(n,s,i){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:n,message:s||null,cause:i}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:n,message:s||null,cause:i})}_onhold(n){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:n})}_onunhold(n){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:n})}_onmute({audio:n,video:s}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:n,video:s})}_onunmute({audio:n,video:s}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:n,video:s})}}class Gs{constructor(n){if(this.headers={},n.length>0){let s=!1;const i=n.split(`\r
136
+ `),a=i.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 e of i){if(e==`-------${this.ident}$`)break;if(e===""){s=!0;continue}if(e&&s)this.body+=`${e}\r
137
+ `;else{const d=e.split(": ");this.addHeader(d[0],d[1].trim())}}}else this.ident=ke.createRandomToken(12),this.protocol="MSRP"}addHeader(n,s){this.headers[n]=s}getHeader(n){return this.headers[n]}toString(){let n=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
+ `;for(const s in this.headers)n+=`${s}: ${this.headers[s]}\r
139
+ `;return this.body&&(n+=`\r
140
140
  ${this.body}\r
141
- `),s+=`-------${this.ident}$\r
142
- `,s}}const Ce={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 hu extends _t.EventEmitter{constructor(s){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=s,this.auth_id=Me.createRandomToken(10),this._status=Ce.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username:s._configuration.authorization_user,ha1:s._configuration.ha1,realm:s._configuration.realm},this._request=null,this.status="new",this.target="",this.message="",this._connectionPromiseQueue=Promise.resolve(),this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:U.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Ce}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(s=""){s!==""&&(this._direction="outgoing"),this.target=s,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=n=>{console.log("open",n),this.onopen()},this._connection.onclose=n=>{console.log("close",n),this.onclose()},this._connection.onmessage=n=>{console.log("msg",n),this.onmessage(n)},this._connection.onerror=n=>{console.log("error",n),this.onerror()}}_sendKeepAlive(){const s=new Qs("");s.method="SEND",s.addHeader("To-Path",`${this.my_addr[1]}`),s.addHeader("From-Path",`${this.my_addr[0]}`),s.addHeader("Message-ID",Me.createRandomToken(10)),this._connection.send(s.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Ce.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(s){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
141
+ `),n+=`-------${this.ident}$\r
142
+ `,n}}const ye={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class nu extends ut.EventEmitter{constructor(n){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=n,this.auth_id=ke.createRandomToken(10),this._status=ye.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:n._configuration.authorization_user,ha1:n._configuration.ha1,realm:n._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:U.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return ye}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(n=""){n!==""&&(this._direction="outgoing"),this.target=n,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=s=>{console.log("open",s),this.onopen()},this._connection.onclose=s=>{console.log("close",s),this.onclose()},this._connection.onmessage=s=>{console.log("msg",s),this.onmessage(s)},this._connection.onerror=s=>{console.log("error",s),this.onerror()}}_sendKeepAlive(){const n=new Gs("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",ke.createRandomToken(10)),this._connection.send(n.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=ye.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(n){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
- a=path: ${s.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
149
- `)}inviteParty(s){const n={},i=[];n.to_uri=new ds("sip",this.target,this._ua._configuration.realm),n.from_uri=new ds("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),i.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),i.push("Content-Type: application/sdp"),this._request=new St.InitialOutgoingInviteRequest(new ds("sip",this.target,this._ua._configuration.realm).clone(),this._ua,n,i,`v=0
148
+ a=path: ${n.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
149
+ `)}inviteParty(n){const s={},i=[];s.to_uri=new ls("sip",this.target,this._ua._configuration.realm),s.from_uri=new ls("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),i.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),i.push("Content-Type: application/sdp"),this._request=new gt.InitialOutgoingInviteRequest(new ls("sip",this.target,this._ua._configuration.realm).clone(),this._ua,s,i,`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
- a=path:${s.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
156
- `),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new Ir(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:a=>{this.onTransportError(),console.log(a)},onAuthenticated:a=>{this._request=a},onReceiveResponse:a=>{this._receiveInviteResponse(a),a.status_code===200&&(a.parseSDP(!0),this._status=Ce.STATUS_CONFIRMED,this.target_addr=a.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Ce.STATUS_INVITE_SENT}terminate(s={}){const n=s.cause||U.causes.BYE,i=Me.cloneArray(s.extraHeaders),a=s.body;let e,d=s.status_code,_=s.reason_phrase;if(this._status===Ce.STATUS_TERMINATED)throw new Xn.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ce.STATUS_NULL:case Ce.STATUS_INVITE_SENT:case Ce.STATUS_1XX_RECEIVED:if(d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||U.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===Ce.STATUS_NULL||this._status===Ce.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===Ce.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=Ce.STATUS_CANCELED,this._failed("local",null,U.causes.CANCELED);break;case Ce.STATUS_WAITING_FOR_ANSWER:case Ce.STATUS_ANSWERED:if(d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,U.causes.REJECTED);break;case Ce.STATUS_WAITING_FOR_ACK:case Ce.STATUS_CONFIRMED:if(_=s.reason_phrase||U.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===Ce.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Wt.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===U.ACK&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Wt.C.STATUS_TERMINATED&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate())}),this._ended("local",null,n),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(U.BYE,{extraHeaders:i,body:a}),this._ended("local",null,n)}}sendRequest(s,n){return this._dialog.sendRequest(s,n)}authenticate(s){this.status="auth";let n=new Qs("");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`),s&&n.addHeader("Authorization",s.toString());let i=n.toString(),a=[];for(var e=0;e<i.length;e++)a.push(i.charCodeAt(e).toString(16));this._connection.send(n.toString())}onmessage(s){const n=new Qs(s.data);if(this.status==="auth"&&n.code===401){const i=this.parseAuth(n.getHeader("WWW-Authenticate")),a=new bg(this.credentials);a.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},i,Me.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 s=new RTCPeerConnection({iceServers:[]});s.createDataChannel(""),s.createOffer().then(s.setLocalDescription.bind(s)),s.onicecandidate=n=>{if(!n||!n.candidate||!n.candidate.candidate)return;const i=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,a=n.candidate.candidate.match(i);this.my_ip=a&&a[1],s.onicecandidate=()=>{},this.authenticate(null)}}onerror(s){console.log(s)}_receiveInviteResponse(s){if(console.log("resp0000000000000",s),this._dialog&&s.status_code>=200&&s.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest(U.ACK);return}else{const n=new yl(this,s,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(U.ACK),this.sendRequest(U.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==Ce.STATUS_INVITE_SENT&&this._status!==Ce.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(s.status_code):this._status=Ce.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){console.log("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=Ce.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const n={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",s)).catch(a=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(console.log("maybe here???"),this._status=Ce.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,U.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",s,U.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const n={originator:"remote",type:"answer",sdp:s.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(i=>this._connection.setLocalDescription(i)).catch(i=>{this._acceptAndTerminate(s,500,i.toString()),console.log("failed 4"),this._failed("local",s,U.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest(U.ACK),this._confirmed("local",null)});break}default:{const n=Me.sipErrorCause(s.status_code);console.log("failed 5"),this._failed("remote",s,n)}}}sendMSRP(s){const n=new Qs("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",Me.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=s;let i=n.toString();console.log(i);let a=[];for(var e=0;e<i.length;e++)a.push(i.charCodeAt(e).toString(16));console.log(a),this._connection.send(n.toString()),n.direction="outgoing",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(s){let n=s.ident,i=s.getHeader("Message-ID"),a=new Qs("");a.method="200 OK",a.addHeader("To-Path",`${this.my_addr[1]}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",i),a.ident=n;let e=a.toString();console.log(e);let d=[];for(var _=0;_<e.length;_++)d.push(e.charCodeAt(_).toString(16));console.log(d),this._connection.send(a.toString())}_sendReport(s){let n=s.ident,i=s.getHeader("Message-ID"),a=new Qs("");a.method="REPORT",a.addHeader("To-Path",`${s.getHeader("From-Path")}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",i),a.addHeader("Byte-Range","1-25/25"),a.addHeader("Status","000 200 OK"),a.ident=n;let e=a.toString();console.log(e);let d=[];for(var _=0;_<e.length;_++)d.push(e.charCodeAt(_).toString(16));console.log(d),this._connection.send(a.toString())}parseAuth(s){const n={},i=s.replace("Digest","").split(",");for(const a of i){const e=a.trim().split("=");n[e[0]]=e[1].match('^"(.+)"$')[1]}return n}init_incoming(s,n){let i;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=Ce.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(i=s.getHeader("expires")*1e3),s.to_tag=Me.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Ce.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),console.log("failed 6"),this._failed("local",null,U.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Ce.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),console.log("failed 7"),this._failed("system",null,U.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,n&&n(this),s.parseSDP(!0),this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",s),this._status!==Ce.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(s,n,i){this.emit("_failed",{originator:s,message:n||null,cause:i}),this._close(),this.emit("failed",{originator:s,message:n||null,cause:i})}_close(){if(console.log("CLOSE SESSION"),this._status!==Ce.STATUS_TERMINATED){if(this._status=Ce.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){console.log("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyMSRPSession(this)}}_createDialog(s,n,i){const a=n==="UAS"?s.to_tag:s.from_tag,e=n==="UAS"?s.from_tag:s.to_tag,d=s.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new yl(this,s,n,yl.C.STATUS_EARLY),_.error?(console.log("failed 8"),this._failed("remote",s,U.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,_)return _.update(s,n),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new yl(this,s,n);return u.error?(console.log("failed 9"),this._failed("remote",s,U.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_newMSRPSession(s,n){this._ua.newMSRPSession(this,{originator:s,session:this,request:n})}_progress(s,n){this.emit("progress",{originator:s,response:n||null})}isEnded(){switch(this._status){case Ce.STATUS_CANCELED:case Ce.STATUS_TERMINATED:return!0;default:return!1}}_accepted(s,n){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:s,response:n||null})}_confirmed(s,n){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:n||null})}_ended(s,n,i){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:s,message:n||null,cause:i})}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let n;s.session_expires&&s.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,n=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}receiveRequest(s){if(console.log("receiveRequest()"),s.method===U.CANCEL)(this._status===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED)&&(this._status=Ce.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",s,U.causes.CANCELED));else switch(s.method){case U.ACK:if(this._status!==Ce.STATUS_WAITING_FOR_ACK)return;if(this._status=Ce.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:U.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",n);const i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:U.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case U.BYE:this._status===Ce.STATUS_CONFIRMED||this._status===Ce.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,U.causes.BYE)):this._status===Ce.STATUS_INVITE_RECEIVED||this._status===Ce.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,U.causes.BYE)):s.reply(403,"Wrong Status");break;case U.INVITE:this._status===Ce.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case U.INFO:this._status===Ce.STATUS_1XX_RECEIVED||this._status===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED||this._status===Ce.STATUS_WAITING_FOR_ACK||this._status===Ce.STATUS_CONFIRMED?(s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new Wa(this).init_incoming(s):s.reply(415):s.reply(403,"Wrong Status");break;case U.UPDATE:this._status===Ce.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case U.REFER:this._status===Ce.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case U.NOTIFY:this._status===Ce.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.DIALOG_ERROR,cause:U.causes.DIALOG_ERROR})}}var fv=Xt();const du=$e(fv),kl=new fl("Parser"),pv=(l,s)=>{let n,i,a=l.indexOf(`\r
157
- `);if(a===-1){kl.warn("parseMessage() | no CRLF found, not a SIP message");return}const e=l.substring(0,a);let d=du.parse(e,"Request_Response");if(d===-1){kl.warn(`parseMessage() | error parsing first line of SIP message: "${e}"`);return}else d.status_code?(n=new Ws.IncomingResponse,n.status_code=d.status_code,n.reason_phrase=d.reason_phrase):(n=new Ws.IncomingRequest(s),n.method=d.method,n.ruri=d.uri);n.data=l;let _=a+2;for(;;){if(a=mv(l,_),a===-2){i=_+2;break}else if(a===-1){kl.warn("parseMessage() | malformed message");return}if(d=gv(n,l,_,a),d!==!0){kl.warn("parseMessage() |",d.error);return}_=a+2}if(n.hasHeader("content-length")){const u=n.getHeader("content-length");n.body=l.substr(i,u)}else n.body=l.substring(i);return n};function mv(l,s){let n=s,i=0,a=0;if(l.substring(n,n+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
158
- `,n),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?n=a+2:i=a}return i}function gv(l,s,n,i){let a;const e=s.indexOf(":",n),d=s.substring(n,e).trim(),_=s.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=du.parse(_,"Record_Route"),a===-1)a=void 0;else for(const u of a)l.addHeader("record-route",_.substring(u.possition,u.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=u.parsed;break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=du.parse(_,"Contact"),a===-1)a=void 0;else for(const u of a)l.addHeader("contact",_.substring(u.possition,u.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=u.parsed;break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof Ws.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:`error parsing header "${d}"`}:!0}const Tv={parseMessage:pv},Lr=new fl("Registrator"),Ul=10;class vv{constructor(s,n){this._reg_id=1,this._ua=s,this._transport=n,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=Rn.createRandomToken(22),this._cseq=0,this._to_uri=s.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const i=this._contact.indexOf(">");if(i!==-1){const a=this._contact.slice(0,i)+this._contact.slice(i+1,this._contact.length);this._contact=a}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}setExtraContactParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const n in s)if(Object.prototype.hasOwnProperty.call(s,n)){const i=s[n];this._extraContactParams+=`;${n}`,i&&(this._extraContactParams+=`=${i}`)}}setExtraContactUriParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const n in s)if(Object.prototype.hasOwnProperty.call(s,n)){const i=s[n];this._extraContactParams+=`;${n}`,i&&(this._extraContactParams+=`=${i}`)}}register(){if(this._registering){Lr.debug("Register request in progress...");return}const s=this._extraHeaders.slice();s.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),s.push(`Expires: ${this._expires}`);const n=new St.OutgoingRequest(U.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),i=new Ir(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,U.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,U.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")){Lr.debug("no Contact header in response to REGISTER, response ignored");break}const e=a.headers.Contact.reduce((g,p)=>g.concat(p.parsed),[]);let d=e.find(g=>this._sipInstance===g.getParam("+sip.instance")&&this._reg_id===parseInt(g.getParam("reg-id")));if(d||(d=e.find(g=>g.uri.user===this._ua.contact.uri.user)),!d){Lr.debug("no Contact header pointing to us, response ignored");break}this._ua.clearKeepAliveInterval(),this._ua.setLastRegisterTimestamp();let _=d.getParam("expires");!_&&a.hasHeader("expires")&&(_=a.getHeader("expires")),_||(_=this._expires),_=Number(_),_<Ul&&(_=Ul);const u=_>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")},u),d.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=d.getParam("temp-gruu").replace(/"/g,"")),d.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=d.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<Ul&&(this._expires=Ul),this.register()):(Lr.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,U.causes.SIP_FAILURE_CODE));break}default:{const e=Rn.sipErrorCause(a.status_code);this._registrationFailure(a,e)}}}});this._registering=!0,i.send()}unregister(s={}){if(!this._registered){Lr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();s.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const i=new St.OutgoingRequest(U.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new Ir(this._ua,i,{onRequestTimeout:()=>{this._unregistered(null,U.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,U.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._unregistered(a);break;default:{const e=Rn.sipErrorCause(a.status_code);this._unregistered(a,e)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(s,n){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:n}))}_unregistered(s,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:n||null})}}const st=console,es={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},yv=ov;class Ev extends yv{constructor(s){super(s),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 vv(this)}setLastRegisterTimestamp(){this.lastRegisterTimestamp=Date.now()}call(s,n){return super.call(s,n)}joinVideoCall(s,n,i){st.debug("call()");const a=new Dl(this);return a.configureMedia({audio:!0,video:!0}),a.connect(s,n,i),a}startScreenShare(){st.debug("startScreenShare()");for(const s in this._janus_sessions)this._janus_sessions[s].connectScreenShare()}changeMediaConstraints(s){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(s)}startBlur(){for(const s in this._janus_sessions)this._janus_sessions[s].connectBlur()}stopBlur(){for(const s in this._janus_sessions)this._janus_sessions[s].stopBlur()}_loadConfig(s){try{Pr.load(this._configuration,s)}catch(e){throw e}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Rn.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+=" "+Ne.USER_AGENT,this._configuration.user_agent=s.overrideUserAgent&&typeof s.overrideUserAgent=="function"?s.overrideUserAgent(n):n,s.onTransportCallback&&typeof s.onTransportCallback=="function"&&(this.onTransportCallback=s.onTransportCallback),this._configuration.jssip_id=Rn.createRandomToken(5);const i=this._configuration.uri.clone();i.user=null,this._configuration.hostport_params=i.toString().replace(/^sip:/i,"");try{this._transport=new kT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Sv.bind(this),this._transport.onconnect=Av.bind(this),this._transport.ondisconnect=Cv.bind(this),this._transport.ondata=bv.bind(this)}catch(e){throw st.warn(e),new Xn.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 e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ds("sip",Rn.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(e={}){const d=e.anonymous||null,_=e.outbound||null;let u="<";return d?u+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":u+=this.pub_gruu||this.uri.toString(),_&&(d?!this.temp_gruu:!this.pub_gruu)&&(u+=";ob"),u+=">",u}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const e in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,e)&&(a.indexOf(e)!==-1?Object.defineProperty(this._configuration,e,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,e,{writable:!1,configurable:!1}));st.debug("configuration parameters after validation:");for(const e in this._configuration)if(Object.prototype.hasOwnProperty.call(Pr.settings,e))switch(e){case"uri":case"registrar_server":st.debug(`- ${e}: ${this._configuration[e]}`);break;case"password":case"ha1":case"authorization_jwt":st.debug(`- ${e}: NOT SHOWN`);break;default:st.debug(`- ${e}: ${JSON.stringify(this._configuration[e])}`)}}newMSRPSession(s,n){s.on("msgHistoryUpdate",i=>{console.log(i)}),this._msrp_sessions[s.id]=s,this.emit("newMSRPSession",n)}newJanusSession(s,n){this._janus_sessions[s.id]=s,this.newStreamPlugins.forEach(i=>{i.setSession(s)}),this.processStreamPlugins.forEach(i=>{i.setSession(s)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(s){delete this._msrp_sessions[s.id]}destroyJanusSession(s){delete this._janus_sessions[s.id]}clearKeepAliveInterval(){clearInterval(this.optionsInterval),this.optionsInterval=null}receiveRequest(s){var n,i,a,e;const d=s.method;if(s.ruri.user!==this._configuration.uri.user&&s.ruri.user!==this._contact.uri.user){st.debug("Request-URI does not point to us"),s.method!==Ne.ACK&&s.reply_sl(404);return}if(s.ruri.scheme===Ne.SIPS){s.reply_sl(416);return}if(Wt.checkTransaction(this,s))return;if(d===Ne.INVITE?new Wt.InviteServerTransaction(this,this._transport,s):d!==Ne.ACK&&d!==Ne.CANCEL&&new Wt.NonInviteServerTransaction(this,this._transport,s),d===Ne.OPTIONS){if(this.lastOptionsTimestamp=Date.now(),this.optionsInterval||(this.emit("initKeepAliveInterval"),this.optionsInterval=setInterval(()=>{const g=Date.now(),p=this.lastOptionsTimestamp>g-35e3,T=this.lastRegisterTimestamp+this._configuration.register_expires*1e3>g;p&&T&&this.emit("keepAliveInterval")},35e3)),this.listeners("newOptions").length===0){s.reply(200);return}new Vh.Options(this).init_incoming(s)}else if(d===Ne.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new Vh.Message(this).init_incoming(s)}else if(d===Ne.INVITE&&!s.to_tag&&this.listeners("newRTCSession").length===0){s.reply(405);return}let _,u;if(s.to_tag)if(_=this._findDialog(s.call_id,s.from_tag,s.to_tag),_)_.receiveRequest(s);else if(d===Ne.NOTIFY)if(u=this._findSession(s),u)u.receiveRequest(s);else{if(s.body)try{const g=JSON.parse(s.body)||{};(i=(n=g.plugindata)==null?void 0:n.data)!=null&&i.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(g),(e=(a=g.plugindata)==null?void 0:a.data)!=null&&e.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(g.plugindata.data.unpublished)}catch(g){console.error(g)}s.reply(200)}else d!==Ne.ACK&&s.reply(481);else switch(d){case Ne.INVITE:if(window.RTCPeerConnection)if(s.hasHeader("replaces")){const g=s.replaces;_=this._findDialog(g.call_id,g.from_tag,g.to_tag),_?(u=_.owner,u.isEnded()?s.reply(603):u.receiveRequest(s)):s.reply(481)}else s.body.search(/MSRP/ig)>-1?(u=new hu(this),u.init_incoming(s)):s.body.search(/JANUS/ig)>-1||(u=new mT(this),u.init_incoming(s));else st.warn("INVITE received but WebRTC is not supported"),s.reply(488);break;case Ne.BYE:s.reply(481);break;case Ne.CANCEL:u=this._findSession(s),u?u.receiveRequest(s):st.debug("received CANCEL request for a non existent session");break;case Ne.ACK:break;case Ne.NOTIFY:this.emit("sipEvent",{event:s.event,request:s}),s.reply(200);break;default:s.reply(405);break}}startMSRP(s,n){st.debug("startMSRP()",n);const i=new hu(this);return i.connect(s),i}startJanus(s,n){st.debug("startJanus()",n);const i=new hu(this);return i.connect(s),i}terminateMSRPSessions(s){st.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(s)}terminateJanusSessions(s){st.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(s)}enableJanusAudio(s){st.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(s?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(s){st.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(s?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}terminateAllSessions(){for(const s in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,s)){st.debug(`closing session ${s}`);try{this._sessions[s].terminate()}catch(n){console.error(n)}}}stop(s=!0){if(st.debug("stop()"),this._dynConfiguration={},this._status===es.STATUS_USER_CLOSED){st.debug("UA already closed");return}this._registrator.close();const n=Object.keys(this._sessions).length;s&&this.terminateAllSessions();for(const i in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,i)){st.debug(`closing session ${i}`);try{this._msrp_sessions[i].terminate()}catch(a){console.error(a)}}for(const i in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,i)){st.debug(`closing session ${i}`);try{this._janus_sessions[i].terminate()}catch(a){console.error(a)}}for(const i in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,i))try{this._applicants[i].close()}catch(a){console.error(a)}this._status=es.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 Sv(l){this.emit("connecting",l)}function Av(l){this._status!==es.STATUS_USER_CLOSED&&(this._status=es.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function Cv(l){const s=["nict","ict","nist","ist"];for(const n of s)for(const i in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],i)&&this._transactions[n][i].onTransportError();this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==es.STATUS_USER_CLOSED&&(this._status=es.STATUS_NOT_READY,this._error=es.NETWORK_ERROR)}function bv(l){const s=l.transport;let n=l.message;const i=n;if(n=Tv.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,i),!!n&&!(this._status===es.STATUS_USER_CLOSED&&n instanceof Ws.IncomingRequest)&&WT(n,this,s)){if(n instanceof Ws.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof Ws.IncomingResponse){let a;switch(n.method){case Ne.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case Ne.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const Rv=["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"],Iv=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function qd(l){const s={};return Rv.forEach(n=>{l[n]!==void 0&&(s[n]=l[n])}),s.localHold=l._localHold,s}function Fd(l){const s={};return Iv.forEach(n=>{l[n]!==void 0&&(s[n]=l[n])}),s}function jd(l,s,n){return re(this,null,function*(){console.log("LLL processAudioVolume",s);const i=l.createMediaStreamSource(s),a=l.createMediaStreamDestination(),e=l.createGain();return i.connect(e),e.connect(a),e.gain.value=n,a.stream})}function wv(l,s,n,i){if($d())return;const a=document.createElement("audio");a.id=s._id,a.className="audioTag",a.srcObject=l,a.setSinkId(n),a.volume=i,a.play(),s.audioTag=a}function Ov(l){if(l&&typeof l.log=="function"&&typeof l.warn=="function"&&typeof l.error=="function")return!0}function $d(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const Nv=ht,Dv=Xt(),kt=new Nv("WebSocketInterface");var kv=class{constructor(l){kt.debug('new() [url:"%s"]',l),this._url=l,this._sip_uri=null,this._via_transport=null,this._ws=null;const s=Dv.parse(l,"absoluteURI");if(s===-1)throw kt.warn(`invalid WebSocket URI: ${l}`),new TypeError(`Invalid argument: ${l}`);if(s.scheme!=="wss"&&s.scheme!=="ws")throw kt.warn(`invalid WebSocket URI scheme: ${s.scheme}`),new TypeError(`Invalid argument: ${l}`);this._sip_uri=`sip:${s.host}${s.port?`:${s.port}`:""};transport=ws`,this._via_transport=s.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(l){this._via_transport=l.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(kt.debug("connect()"),this.isConnected()){kt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){kt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),kt.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(l){this._onError(l)}}disconnect(){kt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(l){return kt.debug("send()"),this.isConnected()?(this._ws.send(l),!0):(kt.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(){kt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:l,code:s,reason:n}){kt.debug(`WebSocket ${this._url} closed`),l===!1&&kt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!l,s,n)}_onMessage({data:l}){kt.debug("received WebSocket message"),this.ondata(l)}_onError(l){kt.warn(`WebSocket ${this._url} error: `,l)}};const _u=Oo,Uv=Ne,Mv=bn,xv=yt(),Pv=Pd,Lv=Sn(),Hv=Ma(),qv=Xt(),Fv=kv;js("JsSIP")("version %s",_u.version);var jv={C:Uv,Exceptions:Mv,Utils:xv,UA:Pv,URI:Lv,NameAddrHeader:Hv,WebSocketInterface:Fv,Grammar:qv,debug:js,get name(){return _u.title},get version(){return _u.version}};const $v=$e(jv);function fu(l){return l<10?`0${l}`:`${l}`}function Vv(l){let s=l.hours||0,n=l.minutes||0,i=l.seconds||0;i++,i===60&&(i=0,n++,n===60&&(n=0,s++));const a=`${fu(s)}:${fu(n)}:${fu(i)}`;return{seconds:i,minutes:n,hours:s,formatted:a}}var Rt={};Rt.forEach=(l,s,n)=>re(this,null,function*(){const i=[];for(let a=0;a<l.length;a++)if(a in l){const e=Promise.resolve(l[a]).then(d=>s.call(n||globalThis,d,a,l));i.push(e)}yield Promise.all(i)}),Rt.forEachSeries=(l,s,n)=>re(this,null,function*(){for(let i=0;i<l.length;i++)i in l&&(yield s.call(n||globalThis,yield l[i],i,l))}),Rt.map=(l,s,n)=>re(this,null,function*(){const i=[];for(let a=0;a<l.length;a++)a in l&&(i[a]=Promise.resolve(l[a]).then(e=>s.call(n||globalThis,e,a,l)));return Promise.all(i)}),Rt.mapSeries=(l,s,n)=>re(this,null,function*(){const i=[];for(let a=0;a<l.length;a++)a in l&&(i[a]=yield s.call(n||globalThis,yield l[a],a,l));return i}),Rt.find=(l,s,n)=>new Promise((i,a)=>{if(l.length===0)return i();let e=1;for(let d=0;d<l.length;d++){const _=u=>{u?i(l[d]):e===l.length&&i(),e++};Promise.resolve(l[d]).then(u=>s.call(n||globalThis,u,d,l)).then(_).catch(a)}}),Rt.findSeries=(l,s,n)=>re(this,null,function*(){for(let i=0;i<l.length;i++)if(yield s.call(n||globalThis,yield l[i],i,l))return l[i]}),Rt.findIndex=(l,s,n)=>new Promise((i,a)=>{if(l.length===0)return i(-1);let e=1;for(let d=0;d<l.length;d++){const _=u=>{u?i(d):e===l.length&&i(-1),e++};Promise.resolve(l[d]).then(u=>s.call(n||globalThis,u,d,l)).then(_).catch(a)}}),Rt.findIndexSeries=(l,s,n)=>re(this,null,function*(){for(let i=0;i<l.length;i++)if(yield s.call(n||globalThis,yield l[i],i,l))return i}),Rt.some=(l,s,n)=>new Promise((i,a)=>{if(l.length===0)return i(!1);let e=1;for(let d=0;d<l.length;d++){if(!(d in l)){e++;continue}const _=u=>{u?i(!0):e===l.length&&i(!1),e++};Promise.resolve(l[d]).then(u=>s.call(n||globalThis,u,d,l)).then(_).catch(a)}}),Rt.someSeries=(l,s,n)=>re(this,null,function*(){for(let i=0;i<l.length;i++)if(i in l&&(yield s.call(n||globalThis,yield l[i],i,l)))return!0;return!1}),Rt.every=(l,s,n)=>new Promise((i,a)=>{if(l.length===0)return i(!0);let e=1;for(let d=0;d<l.length;d++){if(!(d in l)){e++;continue}const _=u=>{u?e===l.length&&i(!0):i(!1),e++};Promise.resolve(l[d]).then(u=>s.call(n||globalThis,u,d,l)).then(_).catch(a)}}),Rt.everySeries=(l,s,n)=>re(this,null,function*(){for(let i=0;i<l.length;i++)if(i in l&&!(yield s.call(n||globalThis,yield l[i],i,l)))return!1;return!0}),Rt.filter=(l,s,n)=>new Promise((i,a)=>re(this,null,function*(){const e=[];for(let _=0;_<l.length;_++)_ in l&&(e[_]=Promise.resolve(l[_]).then(u=>s.call(n||globalThis,u,_,l)).catch(a));const d=[];for(let _=0;_<e.length;_++)(yield e[_])&&d.push(yield l[_]);i(d)})),Rt.filterSeries=(l,s,n)=>re(this,null,function*(){const i=[];for(let a=0;a<l.length;a++)a in l&&(yield s.call(n||globalThis,yield l[a],a,l))&&i.push(yield l[a]);return i}),Rt.reduce=(l,s,n)=>re(this,null,function*(){if(l.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let i,a;for(n!==void 0?(a=n,i=0):(a=l[0],i=1),i;i<l.length;i++)i in l&&(a=yield s(yield a,yield l[i],i,l));return a});var Vd={};(function(l){const s=Rt;Object.keys(s).forEach(n=>{const i=n.charAt(0).toUpperCase()+n.slice(1);l[`async${i}`]=function(...a){return re(this,null,function*(){return s[n](this,...a)})}})})(Vd);var Bv=Object.assign(Rt,{instanceMethods:Vd});const Zt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var Kv={exports:{}};(function(l){var s=function(n){var i=Object.prototype,a=i.hasOwnProperty,e=Object.defineProperty||function(ee,V,k){ee[V]=k.value},d,_=typeof Symbol=="function"?Symbol:{},u=_.iterator||"@@iterator",g=_.asyncIterator||"@@asyncIterator",p=_.toStringTag||"@@toStringTag";function T(ee,V,k){return Object.defineProperty(ee,V,{value:k,enumerable:!0,configurable:!0,writable:!0}),ee[V]}try{T({},"")}catch(ee){T=function(V,k,Ae){return V[k]=Ae}}function y(ee,V,k,Ae){var me=V&&V.prototype instanceof ye?V:ye,Ie=Object.create(me.prototype),xe=new J(Ae||[]);return e(Ie,"_invoke",{value:M(ee,k,xe)}),Ie}n.wrap=y;function A(ee,V,k){try{return{type:"normal",arg:ee.call(V,k)}}catch(Ae){return{type:"throw",arg:Ae}}}var w="suspendedStart",R="suspendedYield",b="executing",G="completed",P={};function ye(){}function O(){}function j(){}var pe={};T(pe,u,function(){return this});var Te=Object.getPrototypeOf,N=Te&&Te(Te(ne([])));N&&N!==i&&a.call(N,u)&&(pe=N);var H=j.prototype=ye.prototype=Object.create(pe);O.prototype=j,e(H,"constructor",{value:j,configurable:!0}),e(j,"constructor",{value:O,configurable:!0}),O.displayName=T(j,p,"GeneratorFunction");function $(ee){["next","throw","return"].forEach(function(V){T(ee,V,function(k){return this._invoke(V,k)})})}n.isGeneratorFunction=function(ee){var V=typeof ee=="function"&&ee.constructor;return V?V===O||(V.displayName||V.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,p,"GeneratorFunction")),ee.prototype=Object.create(H),ee},n.awrap=function(ee){return{__await:ee}};function q(ee,V){function k(Ie,xe,_e,le){var ze=A(ee[Ie],ee,xe);if(ze.type==="throw")le(ze.arg);else{var rt=ze.arg,Ee=rt.value;return Ee&&typeof Ee=="object"&&a.call(Ee,"__await")?V.resolve(Ee.__await).then(function(ge){k("next",ge,_e,le)},function(ge){k("throw",ge,_e,le)}):V.resolve(Ee).then(function(ge){rt.value=ge,_e(rt)},function(ge){return k("throw",ge,_e,le)})}}var Ae;function me(Ie,xe){function _e(){return new V(function(le,ze){k(Ie,xe,le,ze)})}return Ae=Ae?Ae.then(_e,_e):_e()}e(this,"_invoke",{value:me})}$(q.prototype),T(q.prototype,g,function(){return this}),n.AsyncIterator=q,n.async=function(ee,V,k,Ae,me){me===void 0&&(me=Promise);var Ie=new q(y(ee,V,k,Ae),me);return n.isGeneratorFunction(V)?Ie:Ie.next().then(function(xe){return xe.done?xe.value:Ie.next()})};function M(ee,V,k){var Ae=w;return function(me,Ie){if(Ae===b)throw new Error("Generator is already running");if(Ae===G){if(me==="throw")throw Ie;return Ye()}for(k.method=me,k.arg=Ie;;){var xe=k.delegate;if(xe){var _e=W(xe,k);if(_e){if(_e===P)continue;return _e}}if(k.method==="next")k.sent=k._sent=k.arg;else if(k.method==="throw"){if(Ae===w)throw Ae=G,k.arg;k.dispatchException(k.arg)}else k.method==="return"&&k.abrupt("return",k.arg);Ae=b;var le=A(ee,V,k);if(le.type==="normal"){if(Ae=k.done?G:R,le.arg===P)continue;return{value:le.arg,done:k.done}}else le.type==="throw"&&(Ae=G,k.method="throw",k.arg=le.arg)}}}function W(ee,V){var k=V.method,Ae=ee.iterator[k];if(Ae===d)return V.delegate=null,k==="throw"&&ee.iterator.return&&(V.method="return",V.arg=d,W(ee,V),V.method==="throw")||k!=="return"&&(V.method="throw",V.arg=new TypeError("The iterator does not provide a '"+k+"' method")),P;var me=A(Ae,ee.iterator,V.arg);if(me.type==="throw")return V.method="throw",V.arg=me.arg,V.delegate=null,P;var Ie=me.arg;if(!Ie)return V.method="throw",V.arg=new TypeError("iterator result is not an object"),V.delegate=null,P;if(Ie.done)V[ee.resultName]=Ie.value,V.next=ee.nextLoc,V.method!=="return"&&(V.method="next",V.arg=d);else return Ie;return V.delegate=null,P}$(H),T(H,p,"Generator"),T(H,u,function(){return this}),T(H,"toString",function(){return"[object Generator]"});function te(ee){var V={tryLoc:ee[0]};1 in ee&&(V.catchLoc=ee[1]),2 in ee&&(V.finallyLoc=ee[2],V.afterLoc=ee[3]),this.tryEntries.push(V)}function I(ee){var V=ee.completion||{};V.type="normal",delete V.arg,ee.completion=V}function J(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(te,this),this.reset(!0)}n.keys=function(ee){var V=Object(ee),k=[];for(var Ae in V)k.push(Ae);return k.reverse(),function me(){for(;k.length;){var Ie=k.pop();if(Ie in V)return me.value=Ie,me.done=!1,me}return me.done=!0,me}};function ne(ee){if(ee){var V=ee[u];if(V)return V.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var k=-1,Ae=function me(){for(;++k<ee.length;)if(a.call(ee,k))return me.value=ee[k],me.done=!1,me;return me.value=d,me.done=!0,me};return Ae.next=Ae}}return{next:Ye}}n.values=ne;function Ye(){return{value:d,done:!0}}return J.prototype={constructor:J,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(I),!ee)for(var V in this)V.charAt(0)==="t"&&a.call(this,V)&&!isNaN(+V.slice(1))&&(this[V]=d)},stop:function(){this.done=!0;var ee=this.tryEntries[0],V=ee.completion;if(V.type==="throw")throw V.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var V=this;function k(le,ze){return Ie.type="throw",Ie.arg=ee,V.next=le,ze&&(V.method="next",V.arg=d),!!ze}for(var Ae=this.tryEntries.length-1;Ae>=0;--Ae){var me=this.tryEntries[Ae],Ie=me.completion;if(me.tryLoc==="root")return k("end");if(me.tryLoc<=this.prev){var xe=a.call(me,"catchLoc"),_e=a.call(me,"finallyLoc");if(xe&&_e){if(this.prev<me.catchLoc)return k(me.catchLoc,!0);if(this.prev<me.finallyLoc)return k(me.finallyLoc)}else if(xe){if(this.prev<me.catchLoc)return k(me.catchLoc,!0)}else if(_e){if(this.prev<me.finallyLoc)return k(me.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,V){for(var k=this.tryEntries.length-1;k>=0;--k){var Ae=this.tryEntries[k];if(Ae.tryLoc<=this.prev&&a.call(Ae,"finallyLoc")&&this.prev<Ae.finallyLoc){var me=Ae;break}}me&&(ee==="break"||ee==="continue")&&me.tryLoc<=V&&V<=me.finallyLoc&&(me=null);var Ie=me?me.completion:{};return Ie.type=ee,Ie.arg=V,me?(this.method="next",this.next=me.finallyLoc,P):this.complete(Ie)},complete:function(ee,V){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"&&V&&(this.next=V),P},finish:function(ee){for(var V=this.tryEntries.length-1;V>=0;--V){var k=this.tryEntries[V];if(k.finallyLoc===ee)return this.complete(k.completion,k.afterLoc),I(k),P}},catch:function(ee){for(var V=this.tryEntries.length-1;V>=0;--V){var k=this.tryEntries[V];if(k.tryLoc===ee){var Ae=k.completion;if(Ae.type==="throw"){var me=Ae.arg;I(k)}return me}}throw new Error("illegal catch attempt")},delegateYield:function(ee,V,k){return this.delegate={iterator:ne(ee),resultName:V,nextLoc:k},this.method==="next"&&(this.arg=d),P}},n}(l.exports);try{regeneratorRuntime=s}catch(n){typeof globalThis=="object"?globalThis.regeneratorRuntime=s:Function("r","regeneratorRuntime = r")(s)}})(Kv);var Bd={exports:{}};(function(l){(function(s,n){l.exports?l.exports=n():s.log=n()})($l,function(){var s=function(){},n="undefined",i=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),a=["trace","debug","info","warn","error"];function e(R,b){var G=R[b];if(typeof G.bind=="function")return G.bind(R);try{return Function.prototype.bind.call(G,R)}catch(P){return function(){return Function.prototype.apply.apply(G,[R,arguments])}}}function d(){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"&&i?d:console[R]!==void 0?e(console,R):console.log!==void 0?e(console,"log"):s}function u(R,b){for(var G=0;G<a.length;G++){var P=a[G];this[P]=G<R?s:this.methodFactory(P,R,b)}this.log=this.debug}function g(R,b,G){return function(){typeof console!==n&&(u.call(this,b,G),this[R].apply(this,arguments))}}function p(R,b,G){return _(R)||g.apply(this,arguments)}function T(R,b,G){var P=this,ye;b=b!=null?b:"WARN";var O="loglevel";typeof R=="string"?O+=":"+R:typeof R=="symbol"&&(O=void 0);function j(H){var $=(a[H]||"silent").toUpperCase();if(!(typeof window===n||!O)){try{window.localStorage[O]=$;return}catch(q){}try{window.document.cookie=encodeURIComponent(O)+"="+$+";"}catch(q){}}}function pe(){var H;if(!(typeof window===n||!O)){try{H=window.localStorage[O]}catch(M){}if(typeof H===n)try{var $=window.document.cookie,q=$.indexOf(encodeURIComponent(O)+"=");q!==-1&&(H=/^([^;]+)/.exec($.slice(q))[1])}catch(M){}return P.levels[H]===void 0&&(H=void 0),H}}function Te(){if(!(typeof window===n||!O)){try{window.localStorage.removeItem(O);return}catch(H){}try{window.document.cookie=encodeURIComponent(O)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(H){}}}P.name=R,P.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},P.methodFactory=G||p,P.getLevel=function(){return ye},P.setLevel=function(H,$){if(typeof H=="string"&&P.levels[H.toUpperCase()]!==void 0&&(H=P.levels[H.toUpperCase()]),typeof H=="number"&&H>=0&&H<=P.levels.SILENT){if(ye=H,$!==!1&&j(H),u.call(P,H,R),typeof console===n&&H<P.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+H},P.setDefaultLevel=function(H){b=H,pe()||P.setLevel(H,!1)},P.resetLevel=function(){P.setLevel(b,!1),Te()},P.enableAll=function(H){P.setLevel(P.levels.TRACE,H)},P.disableAll=function(H){P.setLevel(P.levels.SILENT,H)};var N=pe();N==null&&(N=b),P.setLevel(N,!1)}var y=new T,A={};y.getLogger=function(R){if(typeof R!="symbol"&&typeof R!="string"||R==="")throw new TypeError("You must supply a name when creating a logger.");var b=A[R];return b||(b=A[R]=new T(R,y.getLevel(),y.methodFactory)),b};var w=typeof window!==n?window.log:void 0;return y.noConflict=function(){return typeof window!==n&&window.log===y&&(window.log=w),y},y.getLoggers=function(){return A},y.default=y,y})})(Bd);var Ot=Bd.exports;const In=()=>`${new Date().toISOString()} | metrics`,wn=(l,s,n)=>`${l} | ${s} | ${n}`;Ot.setDefaultLevel(Ot.levels.TRACE);const Gv=l=>{Ot.info(wn(In(),"log ",`set log level to ${l?"verbose":"info"}`)),Ot.setLevel(l?Ot.levels.TRACE:Ot.levels.INFO)},Wv=l=>{const s=[...Object.keys(Ot.levels)];s.includes(l)?(Ot.info(wn(In(),"log ",`update log level to ${l.toLowerCase()}`)),Ot.setLevel(l)):Ot.warn(wn(In(),"log ","Incorrect log level please choose one of "),s)},ke=(l,s,n)=>{n?Ot.debug(wn(In(),l,s),n):Ot.debug(wn(In(),l,s))},pu=(l,s)=>{Ot.info(wn(In(),l,s))},_s=(l,s)=>{Ot.info(wn(In(),l,s))},Ml=(l,s)=>{Ot.warn(wn(In(),l,s))},Js=(l,s)=>{Ot.error(wn(In(),l,s))};function Yv(l){return Math.floor(Math.random()*l).toString()}function Kd(l,s){let n=s;return l.forEach(i=>{n=n.replace(i,"")}),n}function zv(l,s){let n="";for(let i=0;i<s;i+=1)n+=l[Yv(l.length)];return n}function Xv({length:l=20,useLetters:s=!0,useNumbers:n=!0,includeSymbols:i=[],excludeSymbols:a=[]}={}){let e="abcdefghijklmnopqrstuvwxyz",d="0123456789",_=[],u=[],g=[];return s&&(a.length&&(e=Kd(a,e)),u=e.split("")),n&&(a.length&&(d=Kd(a,d)),g=d.split("")),_=[...u,...g,...i],zv(_,l)}var Qv=Xv;const Hr=$e(Qv),Jv=()=>"WebRTCMetrics",Zv=()=>"5.0.3",Le={INBOUND:"inbound",OUTBOUND:"outbound"},On={IDLE:"idle",RUNNING:"running",MUTED:"muted"},qr={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},ey=()=>({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:[]}),Gd={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:Le.INBOUND},Wd={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:Le.OUTBOUND},Yd={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:Le.INBOUND},zd={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:Le.OUTBOUND},ty=l=>{const s={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(l){const n=ot(oe({},l),{audio:{},video:{},data:oe({},l.data),network:oe({},l.network),experimental:oe({},l.experimental)});return Object.keys(l.audio).forEach(i=>{n.audio[i]=oe({},l.audio[i])}),Object.keys(l.video).forEach(i=>{n.video[i]=oe({},l.video[i])}),n}return ot(oe({},s),{audio:{},video:{},data:oe({},s.data),network:oe({},s.network),experimental:oe({},s.experimental)})},ny={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Hr()}`,cid:`c-${Hr()}`,uid:`u-${Hr()}`,record:!1,ticket:!0},en={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"},F={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"},D={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Fr={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},mu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ie={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},gu="config ",sy=(l,s={},n)=>{const i=oe(oe({},n),s);return s.pname||Ml(gu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),s.cid||Ml(gu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),s.uid||Ml(gu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),i.pc=l,i},ry=(l={})=>{const s=oe(oe({},ny),l);return s.name=Jv(),s.version=Zv(),s},jr=(l,s,n,i=!1,a)=>{let e=l.map(d=>{if(!n)return d[s];if(!a)return d[s][n];const _=d[s][a];return _?_[n]:null});return e=e.filter(d=>i?Number.isFinite(d)&&d>0:Number.isFinite(d)),e.length===0?[]:e},ts=l=>l.reduce((s,n)=>s+n,0)/l.length,iy=()=>`probe-${Hr()}`,oy=()=>`coltr-${Hr()}`,Xd=l=>new Promise(s=>setTimeout(s,l)),Tu=(l,s,n)=>{s?l.call(s,n):l(n)},Xe=(l,s,n,i)=>{const a=jr(l,s,n,!0,i);if(a.length===0)return null;const e=a.reduce((d,_)=>d+_,0)/a.length;return e===0?null:a.map(d=>Math.abs(e-d)).reduce((d,_)=>d+_,0)/a.length*100/e},Ze=(l,s,n,i=!1,a)=>{const e=jr(l,s,n,i,a);return e.length===0?null:e.reduce((d,_)=>d+_,0)/e.length},fs=(l,s,n)=>jr(l,s,n).reduce((i,a)=>i+a,0),Qe=(l,s,n,i)=>{const a=jr(l,s,n,!0,i);return a.length===0?null:Math.min(...a)},Je=(l,s,n,i)=>{const a=jr(l,s,n,!1,i);return a.length===0?null:Math.max(...a)},It=(l,s,n,i)=>{const a=l.slice().pop();if(!a)return null;if(!n)return a[s];if(!i)return a[s][n];const e=a[s][i];return e?e[n]:null},ly=l=>l.slice().pop(),pt=(l,s,n)=>{if(!s)return null;const i={};let a=s[D.AUDIO][l];a||(a=n===Le.INBOUND?oe({},Gd):oe({},Wd)),i[D.AUDIO]=a;let e=s[D.VIDEO][l];return e||(e=n===Le.INBOUND?oe({},Yd):oe({},zd)),i[D.VIDEO]=e,i},$r="exporter ",ay="2.0",Qd=(l,s,n)=>{if(!l||l.length===0)return 0;const i=l[l.length-1];if(!i)return 0;const a=i[s][n];if(a){const e=a.total_rtt_ms_out,d=a.total_rtt_measure_out;return!d||!e?Ze(l,s,"delta_rtt_ms_out",!1,n):Number(e/d)}return null},uy=(l,s)=>{if(!l||l.length===0)return 0;const n=l[l.length-1];if(!n)return 0;const i=n[s].total_rtt_connectivity_ms,a=n[s].total_rtt_connectivity_measure;return!a||!i?Ze(l,s,"delta_rtt_connectivity_ms"):Number(i/a)},cy=l=>It(l,"network","local_candidate_type")!=="relay"?`direct/${It(l,"network","local_candidate_protocol")}`:`turn/${It(l,"network","local_candidate_relay_protocol")}`,hy=l=>{const s=It(l,"network","remote_candidate_type"),n=It(l,"network","remote_candidate_protocol");return s!=="relay"?`direct/${n}`:`turn/${n}`};class dy{constructor(s){this._start=null,this._end=null,this._cfg=s,this._referenceReport=null,this._reports=[],this._events=[]}start(){pu($r,"start() - start exporter...");const s=new Date;return this._start=s.toJSON(),s}stop(){pu($r,"stop() - stop exporter...");const s=new Date;return this._end=s.toJSON(),s}saveReferenceReport(s){this._referenceReport=s}getReferenceReport(){return this._referenceReport}addReport(s){this._cfg.ticket&&(ke($r,`addReport() - add report to exporter at ${s.timestamp}`),this._reports.push(s))}addCustomEvent(s){this._events.push(s)}reset(){pu($r,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){ke($r,"ticket() - generate ticket");const s=It(this._reports,"audio","total_packets_lost_in"),n=It(this._reports,"audio","total_packets_in"),i=It(this._reports,"video","total_packets_lost_in"),a=It(this._reports,"video","total_packets_in"),e={},d=ly(this._reports);return d&&(Object.keys(d[D.AUDIO]).forEach(_=>{const u=d[D.AUDIO][_];if(e[u.ssrc]={type:D.AUDIO,direction:u.direction},u.direction===Le.INBOUND){const g={avg:Ze(this._reports,D.AUDIO,"delta_jitter_ms_in",!1,_),min:Qe(this._reports,D.AUDIO,"delta_jitter_ms_in",_),max:Je(this._reports,D.AUDIO,"delta_jitter_ms_in",_),volatility:Xe(this._reports,D.AUDIO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:Ze(this._reports,D.AUDIO,"delta_kbs_in",!1,_),min:Qe(this._reports,D.AUDIO,"delta_kbs_in",_),max:Je(this._reports,D.AUDIO,"delta_kbs_in",_),volatility:Xe(this._reports,D.AUDIO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Ze(this._reports,D.AUDIO,"delta_KBytes_in",!1,_),min:Qe(this._reports,D.AUDIO,"delta_KBytes_in",_),max:Je(this._reports,D.AUDIO,"delta_KBytes_in",_),volatility:Xe(this._reports,D.AUDIO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y={emodel:{avg:Ze(this._reports,D.AUDIO,"mos_emodel_in",!1,_),min:Qe(this._reports,D.AUDIO,"mos_emodel_in",_),max:Je(this._reports,D.AUDIO,"mos_emodel_in",_),volatility:Xe(this._reports,D.AUDIO,"mos_emodel_in",_)},effective:{avg:Ze(this._reports,D.AUDIO,"mos_in",!1,_),min:Qe(this._reports,D.AUDIO,"mos_in",_),max:Je(this._reports,D.AUDIO,"mos_in",_),volatility:Xe(this._reports,D.AUDIO,"mos_in",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},A=It(this._reports,D.AUDIO,"total_packets_lost_in",_),w=It(this._reports,D.AUDIO,"total_packets_in",_),R={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].mos=y,e[_].traffic=T,e[_].bitrate=p,e[_].loss=R}else{const g={avg:Ze(this._reports,D.AUDIO,"delta_jitter_ms_out",!1,_),min:Qe(this._reports,D.AUDIO,"delta_jitter_ms_out",_),max:Je(this._reports,D.AUDIO,"delta_jitter_ms_out",_),volatility:Xe(this._reports,D.AUDIO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:Ze(this._reports,D.AUDIO,"delta_kbs_out",!1,_),min:Qe(this._reports,D.AUDIO,"delta_kbs_out",_),max:Je(this._reports,D.AUDIO,"delta_kbs_out",_),volatility:Xe(this._reports,D.AUDIO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Ze(this._reports,D.AUDIO,"delta_KBytes_out",!1,_),min:Qe(this._reports,D.AUDIO,"delta_KBytes_out",_),max:Je(this._reports,D.AUDIO,"delta_KBytes_out",_),volatility:Xe(this._reports,D.AUDIO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},y={avg:Qd(this._reports,D.AUDIO,_),min:Qe(this._reports,D.AUDIO,"delta_rtt_ms_out",_),max:Je(this._reports,D.AUDIO,"delta_rtt_ms_out",_),volatility:Xe(this._reports,D.AUDIO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},A=It(this._reports,D.AUDIO,"total_packets_lost_out",_),w=It(this._reports,D.AUDIO,"total_packets_out",_),R={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},b={emodel:{avg:Ze(this._reports,D.AUDIO,"mos_emodel_out",!1,_),min:Qe(this._reports,D.AUDIO,"mos_emodel_out",_),max:Je(this._reports,D.AUDIO,"mos_emodel_out",_),volatility:Xe(this._reports,D.AUDIO,"mos_emodel_out",_)},effective:{avg:Ze(this._reports,D.AUDIO,"mos_out",!1,_),min:Qe(this._reports,D.AUDIO,"mos_out",_),max:Je(this._reports,D.AUDIO,"mos_out",_),volatility:Xe(this._reports,D.AUDIO,"mos_out",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};e[_].jitter=g,e[_].rtt=y,e[_].traffic=T,e[_].bitrate=p,e[_].loss=R,e[_].mos=b}}),Object.keys(d[D.VIDEO]).forEach(_=>{const u=d[D.VIDEO][_];if(e[_]={type:D.VIDEO,direction:u.direction},u.direction===Le.INBOUND){const g={avg:Ze(this._reports,D.VIDEO,"delta_jitter_ms_in",!1,_),min:Qe(this._reports,D.VIDEO,"delta_jitter_ms_in",_),max:Je(this._reports,D.VIDEO,"delta_jitter_ms_in",_),volatility:Xe(this._reports,D.VIDEO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:Ze(this._reports,D.VIDEO,"delta_kbs_in",!1,_),min:Qe(this._reports,D.VIDEO,"delta_kbs_in",_),max:Je(this._reports,D.VIDEO,"delta_kbs_in",_),volatility:Xe(this._reports,D.VIDEO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Ze(this._reports,D.VIDEO,"delta_KBytes_in",!1,_),min:Qe(this._reports,D.VIDEO,"delta_KBytes_in",_),max:Je(this._reports,D.VIDEO,"delta_KBytes_in",_),volatility:Xe(this._reports,D.VIDEO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y=It(this._reports,D.VIDEO,"total_packets_lost_in",_),A=It(this._reports,D.VIDEO,"total_packets_in",_),w={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].traffic=T,e[_].bitrate=p,e[_].loss=w}else{const g={avg:Ze(this._reports,D.VIDEO,"delta_jitter_ms_out",!1,_),min:Qe(this._reports,D.VIDEO,"delta_jitter_ms_out",_),max:Je(this._reports,D.VIDEO,"delta_jitter_ms_out",_),volatility:Xe(this._reports,D.VIDEO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:Ze(this._reports,D.VIDEO,"delta_kbs_out",!1,_),min:Qe(this._reports,D.VIDEO,"delta_kbs_out",_),max:Je(this._reports,D.VIDEO,"delta_kbs_out",_),volatility:Xe(this._reports,D.VIDEO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Ze(this._reports,D.VIDEO,"delta_KBytes_out",!1,_),min:Qe(this._reports,D.VIDEO,"delta_KBytes_out",_),max:Je(this._reports,D.VIDEO,"delta_KBytes_out",_),volatility:Xe(this._reports,D.VIDEO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y={avg:Qd(this._reports,D.VIDEO,_),min:Qe(this._reports,D.VIDEO,"delta_rtt_ms_out",_),max:Je(this._reports,D.VIDEO,"delta_rtt_ms_out",_),volatility:Xe(this._reports,D.VIDEO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},A=It(this._reports,D.VIDEO,"total_packets_lost_out",_),w=It(this._reports,D.VIDEO,"total_packets_out",_),R={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].rtt=y,e[_].traffic=T,e[_].bitrate=p,e[_].loss=R}})),{version:ay,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:e,data:{rtt:{avg:uy(this._reports,"data"),min:Qe(this._reports,"data","delta_rtt_connectivity_ms"),max:Je(this._reports,"data","delta_rtt_connectivity_ms"),volatility:Xe(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((s/(s+n)*100||0)*100)/100}},video:{in:{avg:Math.round((i/(i+a)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Ze(this._reports,"data","delta_kbs_in"),min:Qe(this._reports,"data","delta_kbs_in"),max:Je(this._reports,"data","delta_kbs_in"),volatility:Xe(this._reports,"data","delta_kbs_in")},out:{avg:Ze(this._reports,"data","delta_kbs_out"),min:Qe(this._reports,"data","delta_kbs_out"),max:Je(this._reports,"data","delta_kbs_out"),volatility:Xe(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:Ze(this._reports,"data","delta_KBytes_in"),min:Qe(this._reports,"data","delta_KBytes_in"),max:Je(this._reports,"data","delta_KBytes_in"),volatility:Xe(this._reports,"data","delta_KBytes_in")},out:{avg:Ze(this._reports,"data","delta_KBytes_out"),min:Qe(this._reports,"data","delta_KBytes_out"),max:Je(this._reports,"data","delta_KBytes_out"),volatility:Xe(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:cy(this._reports),remoteConnection:hy(this._reports)}}}}updateConfig(s){this._cfg=s}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const s=this._reports.slice();return s.pop(),s.pop()||null}getReportsNumber(){return this._reports.length}}const ns="extractor ",Jd=(l,s,n,i)=>{let a=!1;const e=i[s].total_rtt_ms_out,d=i[s].total_rtt_measure_out,_=n?n[s].total_rtt_ms_out:0,u=n?n[s].total_rtt_measure_out:0,g={rtt:null,totalRTT:e,totalRTTMeasurements:d};if(l[F.TIMESTAMP]===i[s].timestamp_out||!Object.prototype.hasOwnProperty.call(l,F.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(l,F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(l[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(l[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u===d))return g;const p=1e3*Number(l[F.ROUND_TRIP_TIME]);let T=e+p,y=d+1;return a&&(T=1e3*Number(l[F.TOTAL_ROUND_TRIP_TIME])-_,y=Number(l[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u),{rtt:p,totalRTT:T,totalRTTMeasurements:y}},_y=(l,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(l,F.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:i[s].total_rtt_connectivity_ms,totalRTTMeasurements:i[s].total_rtt_connectivity_measure};const a=1e3*Number(l[F.CURRENT_ROUND_TRIP_TIME]);let e=i[s].total_rtt_connectivity_ms+a,d=i[s].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(l,F.TOTAL_ROUND_TRIP_TIME)&&(e=1e3*Number(l[F.TOTAL_ROUND_TRIP_TIME])-(n?n[s].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(l,F.RESPONSES_RECEIVED)&&(d=Number(l[F.RESPONSES_RECEIVED])-(n?n[s].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:e,totalRTTMeasurements:d}},xl=(l,s,n)=>l[F.TIMESTAMP]===n[s].timestamp_out||!Object.prototype.hasOwnProperty.call(l,F.JITTER)?null:1e3*(Number(l[F.JITTER])||0),fy=(l,s)=>{if(!Object.prototype.hasOwnProperty.call(l,F.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(l,F.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:s[D.VIDEO].delta_ms_decode_frame_in,frames_decoded:s[D.VIDEO].total_frames_decoded_in,total_decode_time:s[D.VIDEO].total_time_decoded_in};const n=l[F.FRAMES_DECODED],i=l[F.TOTAL_DECODE_TIME],a=i-s[D.VIDEO].total_time_decoded_in,e=n-s[D.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:e>0?a*1e3/e:0,frames_decoded:n,total_decode_time:i}},py=(l,s)=>{if(!Object.prototype.hasOwnProperty.call(l,F.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(l,F.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:s[D.VIDEO].delta_ms_encode_frame_out,frames_encoded:s[D.VIDEO].total_frames_encoded_out,total_encode_time:s[D.VIDEO].total_time_encoded_out};const n=l[F.FRAMES_ENCODED],i=l[F.TOTAL_ENCODE_TIME],a=i-s[D.VIDEO].total_time_encoded_out,e=n-s[D.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:e>0&&a?a*1e3/e:0,frames_encoded:n,total_encode_time:i}},Zd=(l,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(l,F.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(l,F.BYTES_SENT))return{packetsSent:n[s].total_packets_out,packetsLost:n[s].total_packets_lost_out,bytesSent:n[s].total_KBytes_out};const a=Number(l[F.PACKETS_SENT])||0-(i?i[s].total_packets_out:0),e=a-n[s].total_packets_out,d=Number(l[F.BYTES_SENT])/1024-(i?i[s].total_KBytes_out:0),_=d-n[s].total_KBytes_out,u=l[F.TIMESTAMP]||Date.now(),g=i?i.timestamp:null;let p=n.timestamp;!p&&g&&(p=g);const T=p?u-p:0,y=T>0?_*.008*1024/T*1e3:0;return{packetsSent:a,deltaPacketsSent:e,KBytesSent:d,deltaKBytesSent:_,kbsSent:y}},e_=(l,s,n,i)=>{let a=n[s].total_packets_lost_out,e=0,d=0;return Object.prototype.hasOwnProperty.call(l,F.PACKETS_LOST)&&(a=Number(l[F.PACKETS_LOST])||0-(i?i[s].total_packets_lost_out:0),e=a-n[s].total_packets_lost_out),Object.prototype.hasOwnProperty.call(l,F.FRACTION_LOST)&&(d=Number(100*l[F.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:e,fractionLost:d}},t_=(l,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(l,F.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(l,F.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(l,F.BYTES_RECEIVED))return{percent_packets_lost:n[s].percent_packets_lost_in,packetsReceived:n[s].total_packets_in,packetsLost:n[s].total_packets_lost_in,bytesReceived:n[s].total_KBytes_in};const a=Number(l[F.PACKETS_RECEIVED])||0-(i?i[s].total_packets_in:0),e=Number(l[F.PACKETS_LOST])||0-(i?i[s].total_packets_lost_in:0),d=e-n[s].total_packets_lost_in,_=a-n[s].total_packets_in,u=a!==n[s].total_packets_in?d*100/(d+_):0,g=Number(l[F.BYTES_RECEIVED])/1024-(i?i[s].total_KBytes_in:0),p=g-n[s].total_KBytes_in,T=l[F.TIMESTAMP]||Date.now(),y=i?i.timestamp:null;let A=n.timestamp;!A&&y&&(A=y);const w=A?T-A:0,R=w>0?p*.008*1024/w*1e3:0;return{percentPacketsLost:u,packetsReceived:a,deltaPacketsReceived:_,packetsLost:e,deltaPacketsLost:d,KBytesReceived:g,deltaKBytesReceived:p,kbsReceived:R}},my=l=>l[F.CANDIDATE_TYPE]!=="relay"?"":l[F.RELAY_PROTOCOL]||"",gy=l=>{if(!Object.prototype.hasOwnProperty.call(l,F.NETWORK_TYPE))return Fr.WIFI;switch(l[F.NETWORK_TYPE]){case mu.ETHERNET:return Fr.ETHERNET;case mu.CELLULAR_4G:return Fr.CELLULAR_4G;case mu.WIFI:return Fr.WIFI;default:return Fr.CELLULAR}},n_=l=>!Object.prototype.hasOwnProperty.call(l,F.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(l,F.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:l[F.FRAME_WIDTH]||null,height:l[F.FRAME_HEIGHT]||null,framerate:l[F.FRAMES_PER_SECOND]},Ty=l=>{const s=Object.prototype.hasOwnProperty.call(l,F.QUALITY_LIMITATION_REASON)?l[F.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(l,F.QUALITY_LIMITATION_RESOLUTION_CHANGES)?l[F.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,i=Object.prototype.hasOwnProperty.call(l,F.QUALITY_LIMITATION_DURATIONS)?l[F.QUALITY_LIMITATION_DURATIONS]:null;return i&&Object.keys(i).forEach(a=>{i[a]>1e3&&(i[a]=Number(i[a]/1e3))}),{reason:s,durations:i,resolutionChanges:n}},vy=(l,s,n)=>{if(!Object.prototype.hasOwnProperty.call(l,F.PLI)||!Object.prototype.hasOwnProperty.call(l,F.NACK))return{pliCount:s.total_pli_sent_in,nackCount:s.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const i=(l[F.PLI]||0)-(n?n[D.VIDEO].total_pli_sent_in:0),a=(l[F.NACK]||0)-(n?n[D.VIDEO].total_nack_sent_in:0);return{pliCount:i,nackCount:a,deltaPliCount:i-s[D.VIDEO].total_pli_sent_in,deltaNackCount:a-s[D.VIDEO].total_nack_sent_in}},yy=(l,s,n)=>{if(!Object.prototype.hasOwnProperty.call(l,F.PLI)||!Object.prototype.hasOwnProperty.call(l,F.NACK))return{pliCount:s.total_pli_received_out,nackCount:s.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const i=(l[F.PLI]||0)-(n?n[D.VIDEO].total_pli_received_out:0),a=(l[F.NACK]||0)-(n?n[D.VIDEO].total_nack_received_out:0);return{pliCount:i,nackCount:a,deltaPliCount:i-s[D.VIDEO].total_pli_received_out,deltaNackCount:a-s[D.VIDEO].total_nack_received_out}},Ey=l=>({channels:l[F.CHANNELS]||null,clock_rate:l[F.CLOCK_RATE]||null,mime_type:l[F.MIME_TYPE]||null,sdp_fmtp_line:l[F.SDP_FMTP_LINE]||null}),Sy=l=>({clock_rate:l[F.CLOCK_RATE]||null,mime_type:l[F.MIME_TYPE]||null}),Ay=(l,s,n)=>{const i=(l[F.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),a=(l[F.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),e=l[F.TIMESTAMP]||Date.now(),d=i-s.data.total_KBytes_in,_=a-s.data.total_KBytes_out,u=n?n.timestamp:null;let g=s.timestamp;!g&&u&&(g=u);const p=g?e-g:0,T=p>0?d*.008*1024/p*1e3:0,y=p>0?_*.008*1024/p*1e3:0;return{total_KBytes_received:i,total_KBytes_sent:a,delta_KBytes_received:d,delta_KBytes_sent:_,kbs_speed_received:T,kbs_speed_sent:y}},Cy=l=>{const s=l[F.AVAILABLE_INCOMING_BITRATE]/1024||0,n=l[F.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:s,kbs_outgoing_bandwidth:n}},by=(l,s,n,i)=>{if(!l)return[];switch(l[F.TYPE]){case en.CANDIDATE_PAIR:let a=!1;if(l[F.NOMINATED]&&l[F.STATE]===D.SUCCEEDED&&(a=!0,ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l),F.SELECTED in l&&!l[F.SELECTED]&&(a=!1)),a){const d=l[F.LOCAL_CANDIDATE_ID],_=l[F.REMOTE_CANDIDATE_ID],u=Ay(l,s,i),g=Cy(l),p=_y(l,"data",i,s);return[{type:ie.NETWORK,value:{local_candidate_id:d}},{type:ie.NETWORK,value:{remote_candidate_id:_}},{type:ie.DATA,value:{total_KBytes_in:u.total_KBytes_received}},{type:ie.DATA,value:{total_KBytes_out:u.total_KBytes_sent}},{type:ie.DATA,value:{delta_KBytes_in:u.delta_KBytes_received}},{type:ie.DATA,value:{delta_KBytes_out:u.delta_KBytes_sent}},{type:ie.DATA,value:{delta_kbs_in:u.kbs_speed_received}},{type:ie.DATA,value:{delta_kbs_out:u.kbs_speed_sent}},{type:ie.DATA,value:{delta_kbs_bandwidth_in:g.kbs_incoming_bandwidth}},{type:ie.DATA,value:{delta_kbs_bandwidth_out:g.kbs_outgoing_bandwidth}},{type:ie.DATA,value:{delta_rtt_connectivity_ms:p.rtt}},{type:ie.DATA,value:{total_rtt_connectivity_ms:p.totalRTT}},{type:ie.DATA,value:{total_rtt_connectivity_measure:p.totalRTTMeasurements}}]}break;case en.LOCAL_CANDIDATE:if(l[F.ID]===s.network.local_candidate_id)return[{type:ie.NETWORK,value:{infrastructure:gy(l)}},{type:ie.NETWORK,value:{local_candidate_type:l[F.CANDIDATE_TYPE]||""}},{type:ie.NETWORK,value:{local_candidate_protocol:l[F.PROTOCOL]||""}},{type:ie.NETWORK,value:{local_candidate_relay_protocol:my(l)}}];break;case en.REMOTE_CANDIDATE:if(l[F.ID]===s.network.remote_candidate_id)return[{type:ie.NETWORK,value:{remote_candidate_type:l[F.CANDIDATE_TYPE]||""}},{type:ie.NETWORK,value:{remote_candidate_protocol:l[F.PROTOCOL]||""}}];break;case en.INBOUND_RTP:{ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);const d=l[F.SSRC],_=pt(d,s,Le.INBOUND);_&&(_.timestamp=s.timestamp);const u=pt(d,i,Le.INBOUND);if(u&&(u.timestamp=i.timestamp),l[F.MEDIA_TYPE]===D.AUDIO){const g=t_(l,D.AUDIO,_,u),p=xl(l,D.AUDIO,_),T=l[F.CODEC_ID]||"";return[{ssrc:d,type:ie.AUDIO,value:{codec_id_in:T}},{ssrc:d,type:ie.AUDIO,value:{total_packets_in:g.packetsReceived}},{ssrc:d,type:ie.AUDIO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:d,type:ie.AUDIO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:d,type:ie.AUDIO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:d,type:ie.AUDIO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:d,type:ie.AUDIO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:d,type:ie.AUDIO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:d,type:ie.AUDIO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:d,type:ie.AUDIO,value:{delta_jitter_ms_in:p}}]}if(l[F.MEDIA_TYPE]===D.VIDEO){const g=fy(l,_),p=t_(l,D.VIDEO,_,u),T=xl(l,D.VIDEO,_),y=l[F.DECODER_IMPLEMENTATION]||null,A=l[F.CODEC_ID]||null,w=n_(l),R=vy(l,_,u);return[{ssrc:d,type:ie.VIDEO,value:{codec_id_in:A}},{ssrc:d,type:ie.VIDEO,value:{total_packets_in:p.packetsReceived}},{ssrc:d,type:ie.VIDEO,value:{delta_packets_in:p.deltaPacketsReceived}},{ssrc:d,type:ie.VIDEO,value:{total_packets_lost_in:p.packetsLost}},{ssrc:d,type:ie.VIDEO,value:{delta_packets_lost_in:p.deltaPacketsLost}},{ssrc:d,type:ie.VIDEO,value:{percent_packets_lost_in:p.percentPacketsLost}},{ssrc:d,type:ie.VIDEO,value:{total_KBytes_in:p.KBytesReceived}},{ssrc:d,type:ie.VIDEO,value:{delta_KBytes_in:p.deltaKBytesReceived}},{ssrc:d,type:ie.VIDEO,value:{delta_kbs_in:p.kbsReceived}},{ssrc:d,type:ie.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:d,type:ie.VIDEO,value:{decoder_in:y}},{ssrc:d,type:ie.VIDEO,value:{delta_ms_decode_frame_in:g.delta_ms_decode_frame}},{ssrc:d,type:ie.VIDEO,value:{total_frames_decoded_in:g.frames_decoded}},{ssrc:d,type:ie.VIDEO,value:{total_time_decoded_in:g.total_decode_time}},{ssrc:d,type:ie.VIDEO,value:{total_nack_sent_in:R.nackCount}},{ssrc:d,type:ie.VIDEO,value:{delta_nack_sent_in:R.deltaNackCount}},{ssrc:d,type:ie.VIDEO,value:{total_pli_sent_in:R.pliCount}},{ssrc:d,type:ie.VIDEO,value:{delta_pli_sent_in:R.deltaPliCount}},{ssrc:d,type:ie.VIDEO,value:{size_in:w}}]}break}case en.OUTBOUND_RTP:{ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);const d=l[F.SSRC],_=pt(d,s,Le.OUTBOUND);_&&(_.timestamp=s.timestamp);const u=pt(d,i,Le.OUTBOUND);if(u&&(u.timestamp=i.timestamp),l[F.MEDIA_TYPE]===D.AUDIO){const g=l[F.CODEC_ID]||null,p=Zd(l,D.AUDIO,_,u);return[{ssrc:d,type:ie.AUDIO,value:{codec_id_out:g}},{ssrc:d,type:ie.AUDIO,value:{total_packets_out:p.packetsSent}},{ssrc:d,type:ie.AUDIO,value:{delta_packets_out:p.deltaPacketsSent}},{ssrc:d,type:ie.AUDIO,value:{total_KBytes_out:p.KBytesSent}},{ssrc:d,type:ie.AUDIO,value:{delta_KBytes_out:p.deltaKBytesSent}},{ssrc:d,type:ie.AUDIO,value:{delta_kbs_out:p.kbsSent}}]}if(l[F.MEDIA_TYPE]===D.VIDEO){const g=l[F.ENCODER_IMPLEMENTATION]||null,p=l[F.CODEC_ID]||null,T=py(l,_),y=n_(l),A=Ty(l),w=yy(l,_,u),R=Zd(l,D.VIDEO,_,u);return[{ssrc:d,type:ie.VIDEO,value:{codec_id_out:p}},{ssrc:d,type:ie.VIDEO,value:{total_packets_out:R.packetsSent}},{ssrc:d,type:ie.VIDEO,value:{delta_packets_out:R.deltaPacketsSent}},{ssrc:d,type:ie.VIDEO,value:{total_KBytes_out:R.KBytesSent}},{ssrc:d,type:ie.VIDEO,value:{delta_KBytes_out:R.deltaKBytesSent}},{ssrc:d,type:ie.VIDEO,value:{delta_kbs_out:R.kbsSent}},{ssrc:d,type:ie.VIDEO,value:{encoder_out:g}},{ssrc:d,type:ie.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:d,type:ie.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:d,type:ie.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:d,type:ie.VIDEO,value:{total_nack_received_out:w.nackCount}},{ssrc:d,type:ie.VIDEO,value:{delta_nack_received_out:w.deltaNackCount}},{ssrc:d,type:ie.VIDEO,value:{total_pli_received_out:w.pliCount}},{ssrc:d,type:ie.VIDEO,value:{delta_pli_received_out:w.deltaPliCount}},{ssrc:d,type:ie.VIDEO,value:{size_out:y}},{ssrc:d,type:ie.VIDEO,value:{limitation_out:A}}]}break}case en.MEDIA_SOURCE:{ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);break}case en.TRACK:{ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);break}case en.CODEC:const e=[];return Object.keys(s[D.AUDIO]).forEach(d=>{const _=s[D.AUDIO][d];if(_.codec_id_in===l[F.ID]||_.codec_id_out===l[F.ID]){ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);const u=Ey(l);l[F.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:ie.AUDIO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:ie.AUDIO,value:{codec_out:u}})}}),Object.keys(s[D.VIDEO]).forEach(d=>{const _=s[D.VIDEO][d];if(_.codec_id_in===l[F.ID]||_.codec_id_out===l[F.ID]){ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);const u=Sy(l);l[F.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:ie.VIDEO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:ie.VIDEO,value:{codec_out:u}})}}),e;case en.REMOTE_INBOUND_RTP:{ke(ns,`analyze() - got stats ${l[F.TYPE]} for ${n}`,l);const d=l[F.SSRC],_=pt(d,s,Le.OUTBOUND),u=pt(d,i,Le.OUTBOUND);if(l[F.KIND]===D.AUDIO){const g=Jd(l,D.AUDIO,u,_),p=xl(l,D.AUDIO,_),T=e_(l,D.AUDIO,_,u);return[{ssrc:d,type:ie.AUDIO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:ie.AUDIO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:ie.AUDIO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:ie.AUDIO,value:{delta_jitter_ms_out:p}},{ssrc:d,type:ie.AUDIO,value:{timestamp_out:l[F.TIMESTAMP]}},{ssrc:d,type:ie.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:ie.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:ie.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(l[F.KIND]===D.VIDEO){const g=Jd(l,D.VIDEO,u,_),p=xl(l,D.VIDEO,_),T=e_(l,D.VIDEO,_,u);return[{ssrc:d,type:ie.VIDEO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:ie.VIDEO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:ie.VIDEO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:ie.VIDEO,value:{delta_jitter_ms_out:p}},{ssrc:d,type:ie.VIDEO,value:{timestamp_out:l[F.TIMESTAMP]}},{ssrc:d,type:ie.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:ie.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:ie.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Pl=l=>l<0?1:l>100?4.5:1+.035*l+7/1e6*l*(l-60)*(100-l),Ry=(l,s=D.AUDIO,n,i,a)=>{const e=pt(a,l,Le.INBOUND),d=pt(a,n,Le.INBOUND),_=pt(a,i,Le.INBOUND),u=[],g=[],p=e[s].percent_packets_lost_in,T=e[s].delta_jitter_ms_in,y=d&&d[s].delta_jitter_ms_in||null,A=_&&_[s].delta_jitter_ms_in||null,w=l.data.delta_rtt_connectivity_ms,R=n&&n.data.delta_rtt_connectivity_ms||null,b=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),R&&u.push(R),b&&u.push(b),T&&g.push(T),n&&y&&g.push(y),i&&A&&g.push(A);const G=u.length>0?ts(u):100,P=g.length>0?ts(g):10,ye=93.2-p,O=.18*ye*ye-27.9*ye+1126.62,j=(G+P)/2,pe=j-177.3<0?0:1,Te=.024*j+.11*(j-177.3)*pe,N=O-Te;return Pl(N)},Iy=(l,s=D.AUDIO,n,i,a)=>{const e=pt(a,l,Le.OUTBOUND),d=pt(a,n,Le.OUTBOUND),_=pt(a,i,Le.OUTBOUND),u=[],g=[],p=e[s].percent_packets_lost_out,T=e[s].delta_rtt_ms_out,y=d&&d[s].delta_rtt_ms_out||null,A=_&&_[s].delta_rtt_ms_out||null,w=e[s].delta_jitter_ms_out,R=d&&d[s].delta_jitter_ms_out||null,b=_&&_[s].delta_jitter_ms_out||null,G=l.data.delta_rtt_connectivity_ms,P=n&&n.data.delta_rtt_connectivity_ms||null,ye=i&&i.data.delta_rtt_connectivity_ms||null;T?u.push(T):G&&u.push(G),y?u.push(y):P&&u.push(P),A?u.push(A):ye&&u.push(ye),w&&g.push(w),n&&R&&g.push(R),i&&b&&g.push(b);const O=u.length>0?ts(u):100,j=g.length>0?ts(g):10,pe=93.2-p,Te=.18*pe*pe-27.9*pe+1126.62,N=(O+j)/2,H=N-177.3<0?0:1,$=.024*N+.11*(N-177.3)*H,q=Te-$;return Pl(q)},wy=(l,s=D.AUDIO,n,i,a)=>{const e=pt(a,l,Le.INBOUND),d=pt(a,n,Le.INBOUND),_=pt(a,i,Le.INBOUND),u=[],g=[],p=e[s].percent_packets_lost_in/100,T=e[s].delta_jitter_ms_in,y=d&&d[s].delta_jitter_ms_in||null,A=_&&_[s].delta_jitter_ms_in||null,w=l.data.delta_rtt_connectivity_ms,R=n&&n.data.delta_rtt_connectivity_ms||null,b=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),R&&u.push(R),b&&u.push(b),T&&g.push(T),d&&y&&g.push(y),_&&A&&g.push(A);const G=u.length>0?ts(u):100,P=g.length>0?ts(g):10,ye=0,O=19.8,j=29.7,pe=30,Te=(G+P)/2+pe,N=Te-177.3<0?0:1,H=.024*Te+.11*(Te-177.3)*N,$=93.2-(ye+O*Math.log(1+j*p)+H);return Pl($)},Oy=(l,s=D.AUDIO,n,i,a)=>{const e=pt(a,l,Le.OUTBOUND),d=pt(a,n,Le.OUTBOUND),_=pt(a,i,Le.OUTBOUND),u=[],g=[],p=e[s].percent_packets_lost_out/100,T=e[s].delta_rtt_ms_out,y=d&&d[s].delta_rtt_ms_out||null,A=_&&_[s].delta_rtt_ms_out||null,w=e[s].delta_jitter_ms_out,R=d&&d[s].delta_jitter_ms_out||null,b=_&&_[s].delta_jitter_ms_out||null,G=l.data.delta_rtt_connectivity_ms,P=n&&n.data.delta_rtt_connectivity_ms||null,ye=i&&i.data.delta_rtt_connectivity_ms||null;T?u.push(T):G&&u.push(G),y?u.push(y):P&&u.push(P),A?u.push(A):ye&&u.push(ye),w&&g.push(w),d&&R&&g.push(R),_&&b&&g.push(b);const O=u.length>0?ts(u):100,j=g.length>0?ts(g):10,pe=0,Te=19.8,N=29.7,H=30,$=(O+j)/2+H,q=$-177.3<0?0:1,M=.024*$+.11*($-177.3)*q,W=93.2-(pe+Te*Math.log(1+N*p)+M);return Pl(W)};class Ny{constructor(s,n){this._callbacks={onreport:null,onticket:null},this._id=oy(),this._moduleName=this._id,this._probeId=n,this._config=s,this._exporter=new dy(s),this._state=On.IDLE,this.registerToPCEvents(),_s(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(s,n,i,a){const e=(u,g)=>u===D.AUDIO?g===en.INBOUND_RTP?oe({},Gd):oe({},Wd):g===en.INBOUND_RTP?oe({},Yd):oe({},zd),d=ty(n);d.pname=this._config.pname,d.call_id=this._config.cid,d.user_id=this._config.uid,d.count=n?n.count+1:1;let _=null;return s.forEach(u=>{!_&&u.timestamp&&(_=u.timestamp),by(u,d,d.pname,a).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let p=d[g.type][g.ssrc];p||(p=e(g.type,u.type),p.ssrc=g.ssrc,d[g.type][g.ssrc]=p),Object.keys(g.value).forEach(T=>{p[T]=g.value[T]})}else Object.keys(g.value).forEach(p=>{d[g.type][p]=g.value[p]})})}),d.timestamp=_,Object.keys(d[D.AUDIO]).forEach(u=>{const g=d[D.AUDIO][u];g.direction===Le.INBOUND?(g.mos_emodel_in=Ry(d,D.AUDIO,n,i,g.ssrc),g.mos_in=wy(d,D.AUDIO,n,i,g.ssrc)):(g.mos_emodel_out=Iy(d,D.AUDIO,n,i,g.ssrc),g.mos_out=Oy(d,D.AUDIO,n,i,g.ssrc))}),d}takeReferenceStats(){return re(this,null,function*(){return new Promise((s,n)=>{const i=Date.now();setTimeout(()=>re(this,null,function*(){try{const a=Date.now()-i,e=Date.now(),d=yield this._config.pc.getStats(),_=this.analyze(d,null,null,null),u=Date.now();_.experimental.time_to_measure_ms=u-e,_.experimental.time_to_wait_ms=a,this._exporter.saveReferenceReport(_),ke(this._moduleName,`got reference report for probe ${this._probeId}`),s()}catch(a){n(a)}}),this._config.startAfter)})})}collectStats(){return re(this,null,function*(){try{if(this._state!==On.RUNNING||!this._config.pc)return ke(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const s=Date.now(),n=yield this._config.pc.getStats(),i=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),a=Date.now();return i.experimental.time_to_measure_ms=a-s,this._exporter.addReport(i),ke(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(i),i}catch(s){return Js(this._moduleName,`got error ${s}`),null}})}start(){return re(this,null,function*(){ke(this._moduleName,"starting"),this.state=On.RUNNING,this._startedTime=this._exporter.start(),ke(this._moduleName,"started")})}mute(){return re(this,null,function*(){this.state=On.MUTED,ke(this._moduleName,"muted")})}unmute(){return re(this,null,function*(){this.state=On.RUNNING,ke(this._moduleName,"unmuted")})}stop(s){return re(this,null,function*(){if(ke(this._moduleName,`stopping${s?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=On.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),ke(this._moduleName,"stopped")})}registerCallback(s,n,i){s in this._callbacks?(this._callbacks[s]={callback:n,context:i},ke(this._moduleName,`registered callback '${s}'`)):Js(this._moduleName,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],ke(this._moduleName,`unregistered callback '${s}'`)):Js(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReport(s){this._callbacks.onreport&&Tu(this._callbacks.onreport.callback,this._callbacks.onreport.context,s)}fireOnTicket(s){this._callbacks.onticket&&Tu(this._callbacks.onticket.callback,this._callbacks.onticket.context,s)}updateConfig(s){this._config=s,this._exporter.updateConfig(s)}get state(){return this._state}set state(s){this._state=s,ke(this._moduleName,`state changed to ${s}`)}addCustomEvent(s,n,i,a){this._exporter.addCustomEvent({at:typeof s=="object"?s.toJSON():s,category:n,name:i,description:a})}registerToPCEvents(){return re(this,null,function*(){const{pc:s}=this._config;if(navigator.mediaDevices.ondevicechange=()=>re(this,null,function*(){try{const n=yield navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch(n){Js(this._moduleName,"can't get devices")}}),s){s.oniceconnectionstatechange=()=>{const i=s.iceConnectionState;i===qr.CONNECTED||i===qr.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===qr.DISCONNECTED||i===qr.FAILED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===qr.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},s.onicegatheringstatechange=()=>{const i=s.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",i,"ICE gathering state")},s.ontrack=i=>{this.addCustomEvent(new Date().toJSON(),"call",`${i.track.kind}track`,"MediaStreamTrack received")},s.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=s.getReceivers();if(n&&n.length>0){const i=n[0],{transport:a}=i;if(a){const{iceTransport:e}=a;e&&(e.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}})}}class Dy{constructor(s){this._id=s.pname&&s.pname.substr(0,12).padEnd(12," ")||iy(),this._moduleName=this._id,_s(this._moduleName,"probe created"),this._config=s,this._collector=new Ny(this._config,this._id)}set onreport(s){s?this._collector.registerCallback("onreport",s):this._collector.unregisterCallback("onreport")}set onticket(s){s?this._collector.registerCallback("onticket",s):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(s){this._collector.state=s}addCustomEvent(s,n,i,a=new Date().toJSON()){this._collector.addCustomEvent(a,n,s,i)}get isRunning(){return this._collector.state===On.RUNNING}get isIdle(){return this._collector.state===On.IDLE}updateUserId(s){this._config.uid=s,this._collector.updateConfig(this._config)}updateCallId(s){this._config.cid=s,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Ml(this._moduleName,"probe is already running");return}this._collector.start()}stop(s=!1){this.isRunning&&this._collector.stop(s)}takeReferenceStats(){return re(this,null,function*(){return this._collector.takeReferenceStats()})}collectStats(){return re(this,null,function*(){return this._collector.collectStats()})}}const Nt="engine ";class ky{constructor(s){this._config=s,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},_s(Nt,`configured for probing every ${this._config.refreshEvery}ms`),_s(Nt,`configured for starting after ${this._config.startAfter}ms`),_s(Nt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),ke(Nt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(s=>s.isRunning)}get isIdle(){return this._probes.every(s=>s.isIdle)}addNewProbe(s,n){if(!s)throw new Error("undefined peer connection");const i=sy(s,n,this._config),a=new Dy(i);return this._probes.push(a),ke(Nt,`${this._probes.length} probes registered`),a}removeExistingProbe(s){if(!s)throw new Error("undefined probe");s.state===On.RUNNING&&s.stop(),this._probes=this._probes.filter(n=>s.id!==n.id)}start(){return re(this,null,function*(){const s=()=>{this._probes.forEach(e=>e.start())},n=()=>re(this,null,function*(){return Promise.all(this._probes.map(e=>e.takeReferenceStats()))}),i=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,a=()=>re(this,null,function*(){const e=ey(),d=this._probes.filter(_=>_.isRunning);for(const _ of d){const u=yield _.collectStats();u&&e.probes.push(u),ke(Nt,`got probe ${_.id}`),yield Xd(0)}return e.delta_time_to_measure_probes_ms=fs(e.probes,"experimental","time_to_measure_ms"),e.delta_KBytes_in=fs(e.probes,"data","delta_KBytes_in"),e.delta_KBytes_out=fs(e.probes,"data","delta_KBytes_out"),e.delta_kbs_in=fs(e.probes,"data","delta_kbs_in"),e.delta_kbs_out=fs(e.probes,"data","delta_kbs_out"),e.total_time_decoded_in=fs(e.probes,"video","total_time_decoded_in"),e.total_time_encoded_out=fs(e.probes,"video","total_time_encoded_out"),e});for(ke(Nt,"starting to collect"),s(),ke(Nt,"generating reference reports..."),yield n(),ke(Nt,"reference reports generated"),this._startedTime=Date.now();i();)if(ke(Nt,`wait ${this._config.refreshEvery}ms before collecting`),yield Xd(this._config.refreshEvery),i()){ke(Nt,"collecting...");const e=Date.now(),d=yield a(),_=Date.now();d.delta_time_consumed_to_measure_ms=_-e,this.fireOnReports(d),ke(Nt,"collected")}ke(Nt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)})}stop(s){const n=i=>{this._probes.forEach(a=>{a.stop(i)})};_s(Nt,"stop collecting"),n(s)}registerCallback(s,n,i){s in this._callbacks?(this._callbacks[s]={callback:n,context:i},ke(Nt,`registered callback '${s}'`)):Js(Nt,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],ke(this._moduleName,`unregistered callback '${s}'`)):Js(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReports(s){this._callbacks.onresult&&s.probes.length>0&&Tu(this._callbacks.onresult.callback,this._callbacks.onresult.context,s)}}const Uy="interface ";class My{constructor(s){this._config=ry(s),_s(Uy,`welcome to ${this._config.name} version ${this._config.version}`),Gv(this._config.verbose||!1),this._engine=new ky(this._config)}setupLogLevel(s){Wv(s)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(s,n){return this._engine.addNewProbe(s,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(s){this._engine.removeExistingProbe(s)}set onresult(s){s?this._engine.registerCallback("onresult",s):this._engine.unregisterCallback("onresult")}}function xy(l,s){return Object.keys(l).filter(n=>s.includes(n)).reduce((n,i)=>{const a=i;return ot(oe({},n),{[a]:l[a]})},{})}const Py=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class Ly{constructor(s){this.intervals={},this.analysers={},this.emitInterval=s.emitInterval||200,this.onChangeFunction=s.onChangeFunction}start(s,n,i){return re(this,null,function*(){n&&n.getTracks().length&&(yield this.beginCalculation(s,n,i))})}stop(s){this.clearVolumeInterval(s),this.analysers[s]&&(this.analysers[s].disconnect(),delete this.analysers[s])}clearVolumeInterval(s){this.intervals[s]&&(clearInterval(this.intervals[s]),delete this.intervals[s])}clearAllIntervals(){Object.keys(this.intervals).forEach(s=>{this.stop(s)}),this.intervals={},this.analysers={}}beginCalculation(s,n,i){return re(this,null,function*(){this.clearVolumeInterval(i);const a=s.createAnalyser(),e=s.createMediaStreamSource(n);a.smoothingTimeConstant=.8,a.fftSize=1024,e.connect(a),this.analysers[i]=a,this.intervals[i]=setInterval(()=>{const d=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(d);let _=0;const u=d.length;for(let p=0;p<u;p++)_+=d[p];const g=_/u;this.onChangeFunction(i,g)},this.emitInterval)})}}class Hy{constructor(){this.resumePromise=null,this.context=new AudioContext}getContext(){return re(this,null,function*(){return this.context.state==="suspended"&&(this.resumePromise||(this.resumePromise=this.context.resume().then(()=>{this.resumePromise=null}).catch(s=>{throw this.resumePromise=null,s})),yield this.resumePromise),this.context})}}const Ll={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},qy=0;class Fy{constructor(s){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.managedAudioContext=new Hy,this.context=s,console.log("LLL audio onstructor"),this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new Ly({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return ot(oe({},this.context.options.sipOptions),{mediaConstraints:this.getUserMediaConstraints})}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(s){this.currentActiveRoomIdValue=s,this.context.emit("currentActiveRoomChanged",s)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(s){this.isCallAddingInProgress=s,this.context.emit("callAddingInProgressChanged",s)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get 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(s=>!s.incomingInProgress).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(s=>s.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(s=>s.kind==="audiooutput")}get getUserMediaConstraints(){return $d()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(s){this.availableMediaDevices=s,this.context.emit("changeAvailableDeviceList",s)}updateDeviceList(){return re(this,null,function*(){yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const s=yield navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)})}initializeMediaDevices(){return re(this,null,function*(){const s=localStorage.getItem(Ll.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(Ll.SELECTED_OUTPUT_DEVICE)||"default";try{const i=yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),a=yield navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(a),yield this.setMicrophone(s),yield this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",()=>re(this,null,function*(){const e=yield navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(e)})),i.getTracks().forEach(e=>e.stop())}catch(i){console.error(i)}})}cleanupConferenceNodes(s){return re(this,null,function*(){const n=this.conferenceNodes[s];if(!n)return;let i=0;n.sources.forEach((d,_)=>{try{d.disconnect(),i++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting source ${_}:`,u)}});let a=0;n.destinations.forEach((d,_)=>{try{d.disconnect(),a++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting destination ${_}:`,u)}});let e=0;n.gains.forEach((d,_)=>{try{d.disconnect(),e++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting gain ${_}:`,u)}}),delete this.conferenceNodes[s]})}setCallTime(s){const n=oe({},s);delete n.callId,this.callTime=ot(oe({},this.callTime),{[s.callId]:n}),this.context.emit("changeCallTime",this.callTime)}removeCallTime(s){const n=oe({},this.callTime);delete n[s],this.callTime=oe({},n),this.context.emit("changeCallTime",this.callTime)}setTimeInterval(s,n){this.timeIntervals=ot(oe({},this.timeIntervals),{[s]:n})}removeTimeInterval(s){const n=oe({},this.timeIntervals);n[s]&&(clearInterval(n[s]),delete n[s],this.timeIntervals=oe({},n))}stopCallTimer(s){this.removeTimeInterval(s),this.removeCallTime(s)}emitVolumeChange(s,n){this.context.emit("changeCallVolume",{callId:s,volume:n})}setMetricsConfig(s){this.metricConfig=oe(oe({},this.metricConfig),s)}sendDTMF(s,n){if(!/^[A-D0-9*#]+$/g.test(n))throw new Error("Not allowed character used in the DTMF input");this.extendedCalls[s].sendDTMF(n)}setIsMuted(s){this.muted=s,this.context.emit("changeIsMuted",s)}processMute(s){const n=this.currentActiveRoomId;this.setIsMuted(s),this.initialStreamValue.getTracks().forEach(i=>i.enabled=!s),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}processHold(a){return re(this,arguments,function*({callId:s,toHold:n,automatic:i}){const e=this.extendedCalls[s];if(!e)return;e._automaticHold=i!=null?i:!1;const d=new Promise((_,u)=>{const g=setTimeout(()=>{u(new Error("Hold operation timeout"))},5e3),p=()=>{clearTimeout(g),e.putOnHoldTimestamp=n?Date.now():void 0,_()},T=y=>{clearTimeout(g),u(y)};try{n?e.hold({},p):e.unhold({},p)}catch(y){T(y)}});try{yield d,this.updateCall(e);const _=Object.values(this.extendedCalls).filter(u=>u.roomId===e.roomId&&(n?s!==u._id:!0));_.length>1&&(yield this.doConference(_))}catch(_){throw console.error("Hold operation failed:",_),_}})}holdCall(s,n=!1){return this.processHold({callId:s,automatic:n,toHold:!0})}unholdCall(s){return this.processHold({callId:s,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(s=>s.direction==="outgoing"&&s.status===qy).forEach(s=>this.terminateCall(s._id))}answerCall(s){const n=this.extendedCalls[s];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",i=>{this.triggerAddStream(i,n)})}moveCall(s,n){return re(this,null,function*(){this.updateCallStatus({callId:s,isMoving:!0}),yield this.processRoomChange({callId:s,roomId:n}),this.updateCallStatus({callId:s,isMoving:!1})})}updateCall(s){this.activeCalls[s._id]=qd(s),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(s){const n=oe(oe({},this.activeRooms[s.roomId]),s);this.activeRooms=ot(oe({},this.activeRooms),{[s.roomId]:oe({},n)}),this.context.emit("updateRoom",{room:n,roomList:this.activeRooms})}hasAutoAnswerHeaders(s){const n=/answer-after=0/,i=s.request.getHeader("Call-Info");return i&&n.test(i)}addCall(s,n=!0){this.activeCalls=ot(oe({},this.activeCalls),{[s._id]:qd(s)}),this.extendedCalls[s._id]=s,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(s){this.callStatus=ot(oe({},this.callStatus),{[s]:{isMoving:!1,isTransferring:!1,isMerging:!1,isTransferred:!1}}),this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(s){const n=oe({},oe({},this.callStatus[s.callId]));s.isMoving!==void 0&&(n.isMoving=s.isMoving),s.isTransferring!==void 0&&(n.isTransferring=s.isTransferring),s.isMerging!==void 0&&(n.isMerging=s.isMerging),s.isTransferred!==void 0&&(n.isTransferred=s.isTransferred),this.callStatus=ot(oe({},this.callStatus),{[s.callId]:oe({},n)}),this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(s){const n=oe({},this.callStatus);delete n[s],this.callStatus=oe({},n),this.context.emit("changeCallStatus",this.callStatus)}addRoom(s){this.activeRooms=ot(oe({},this.activeRooms),{[s.roomId]:s}),this.context.emit("addRoom",{room:s,roomList:this.activeRooms})}getActiveStream(){return re(this,null,function*(){console.log("getActiveStream",this.initialStreamValue);const s=yield jd(yield this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);return s.getTracks().forEach(n=>n.enabled=!this.isMuted),yield this.setActiveStream(s),s})}setMicrophone(s){return re(this,null,function*(){if(!this.getInputDeviceList.find(({deviceId:i})=>i===s)||(this.setSelectedInputDevice(s),Object.keys(this.getActiveCalls).length===0))return;yield this.setupStream();const n=Object.values(this.extendedCalls).filter(i=>i.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(i=>re(this,null,function*(){const a=yield this.getActiveStream();i.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(i)})):yield this.doConference(n)})}setActiveStream(s){return re(this,null,function*(){this.activeStream&&this.stopVUMeter("origin"),yield this.setupVUMeter(s,"origin"),this.activeStreamValue=s,this.context.emit("changeActiveStream",s)})}setSpeaker(s){return re(this,null,function*(){if(!this.getOutputDeviceList.find(({deviceId:a})=>a===s))return;this.setSelectedOutputDevice(s);const n=Object.values(this.extendedCalls);if(n.length===0)return;const i=n.filter(a=>a.roomId===this.currentActiveRoomId);i.length===1?n.forEach(a=>{var e;(e=a.audioTag)==null||e.setSinkId(s),this.updateCall(a)}):yield this.doConference(i)})}removeRoom(s){const n=oe({},this.activeRooms),i=oe({},n[s]);delete n[s],this.activeRooms=oe({},n),this.context.emit("removeRoom",{room:i,roomList:this.activeRooms})}deleteRoomIfEmpty(s){s!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===s).length===0&&(this.removeRoom(s),this.currentActiveRoomId===s&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(s){this.muted?s.mute({audio:!0}):s.unmute({audio:!0})}roomReconfigure(s){return re(this,null,function*(){var n;if(s===void 0)return;const i=Object.values(this.extendedCalls).filter(e=>e.roomId===s),a=this.currentActiveRoomId===s;if(i.forEach((e,d)=>{if(e.audioTag){e.connection.getReceivers().forEach(u=>{u.track.enabled=!e.localMuted}),a&&this.muteReconfigure(e);const _=!a;e.audioTag.muted=_,this.updateCall(e)}}),i.length===0){this.conferenceNodes[s]&&(yield this.cleanupConferenceNodes(s)),this.deleteRoomIfEmpty(s);return}if(i.length===1&&!a){const e=i[0];e.isOnHold().local||(yield this.holdCall(e._id,!0)),this.conferenceNodes[s]&&(yield this.cleanupConferenceNodes(s));return}if(i.length===1&&a){const e=i[0];e.isOnHold().local&&e._automaticHold&&(yield this.unholdCall(e._id));const d=(((n=e.connection)==null?void 0:n.getSenders())||[])[0];if(e.connection&&d)try{console.log("LLL in roomReconfigure");const _=yield this.getActiveStream();console.log("LLL in roomReconfigure processedStream",_);const u=_.getTracks();yield d.replaceTrack(u[0]),this.muteReconfigure(e)}catch(_){console.error(_)}this.conferenceNodes[s]&&(yield this.cleanupConferenceNodes(s));return}i.length>1&&(yield this.doConference(i))})}doConference(s){return re(this,null,function*(){if(s.length===0)return;const n=s[0].roomId,i=this.currentActiveRoomId===n;if(s.find(_=>_.roomId!==n))return;const a=yield this.managedAudioContext.getContext();if(a.state!=="running"){console.error(`[doConference] ERROR: AudioContext is not running! State: ${a.state}`);return}yield this.cleanupConferenceNodes(n),this.conferenceNodes[n]={sources:new Map,destinations:new Map,gains:new Map};const e=this.conferenceNodes[n],d=new Map;s.forEach((_,u)=>{_&&_.connection&&_.connection.getReceivers().forEach((g,p)=>{var T,y,A;g.track.enabled=!_.localMuted;const w=(T=g.track)==null?void 0:T.id;(y=g.track)==null||y.readyState,(A=g.track)==null||A.kind;const R=`${_._id}-${w}`;g.track&&g.track.readyState==="live"&&d.set(R,g.track)})}),yield Bv.forEach(s,(_,u)=>re(this,null,function*(){if(!_||!_.connection)return;const g=a.createMediaStreamDestination();e.destinations.set(_._id,g);let p=0;if(d.forEach((A,w)=>{if(!w.startsWith(_._id))try{const R=a.createMediaStreamSource(new MediaStream([A])),b=a.createGain(),G=`${_._id}-${w}`;R.connect(b),b.connect(g),e.sources.set(G,R),e.gains.set(G,b),p++}catch(R){console.error(R)}}),i&&this.activeStreamValue)try{const A=yield this.getActiveStream(),w=a.createMediaStreamSource(A),R=a.createGain(),b=`${_._id}-local`;w.connect(R),R.connect(g),e.sources.set(b,w),e.gains.set(b,R)}catch(A){console.error(A)}else i&&console.error(`Host room but no activeStreamValue - skipping host microphone for session ${_._id}`);const T=_.connection.getSenders()[0],y=g.stream.getTracks();if(T&&y[0])try{yield T.replaceTrack(y[0]),this.muteReconfigure(_)}catch(A){console.error(A)}}))})}processCallerMute(s,n){const i=this.extendedCalls[s];i&&i.connection.getReceivers().length&&(i.localMuted=n,i.connection.getReceivers().forEach(a=>{a.track.enabled=!n}),this.updateCall(i))}muteCaller(s){this.processCallerMute(s,!0)}unmuteCaller(s){this.processCallerMute(s,!1)}terminateCall(s){const n=this.extendedCalls[s];n._status===4?n.terminate({status_code:603,reason_phrase:"Decline"}):n._status!==8&&n.terminate()}transferCall(s,n){if(n.toString().length===0)return new Error("Target must be passed");const i=this.extendedCalls[s];if(!i._is_confirmed&&!i._is_canceled){const a=`sip:${n}@${this.context.sipDomain}`;i.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${a}`]});return}this.updateCallStatus({callId:s,isTransferring:!0,isTransferred:!1}),i.refer(`sip:${n}@${this.context.sipDomain}`,{eventHandlers:{requestSucceeded:()=>{this.updateCallStatus({callId:s,isTransferring:!1,isTransferred:!0})},requestFailed:()=>{this.updateCallStatus({callId:s,isTransferring:!1,isTransferred:!1})}}}),this.updateCall(i)}mergeCall(s){const n=Object.values(this.extendedCalls).filter(e=>e.roomId===s);if(n.length!==2)return;const i=n[0],a=n[1];!i||!a||(this.updateCallStatus({callId:i._id,isMerging:!0}),this.updateCallStatus({callId:a._id,isMerging:!0}),i.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(i))}mergeCallByIds(s,n){const i=Object.values(this.extendedCalls).find(e=>e._id===s),a=Object.values(this.extendedCalls).find(e=>e._id===n);if(!i||!a)throw new Error("Call ID is not provided");this.updateCallStatus({callId:s,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),i.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(i)}setDND(s){this.isDNDEnabled=s,this.context.emit("changeIsDND",s)}setCallWaiting(s){this.isCallWaitingEnabled=s,this.context.emit("changeIsCallWaiting",s)}startCallTimer(s){this.removeTimeInterval(s);const n={callId:s,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const i=setInterval(()=>{const a=oe({},this.callTime[s]),e=Vv(a);this.setCallTime(oe({callId:s},e))},1e3);this.setTimeInterval(s,i)}setActiveRoom(s){return re(this,null,function*(){const n=this.currentActiveRoomId;s!==n&&(this.currentActiveRoomId=s,yield this.roomReconfigure(n),yield this.roomReconfigure(s))})}getNewRoomId(){const s=Object.keys(this.activeRooms);return s.length===0?1:parseInt(s.sort()[s.length-1])+1}setupCall(s){return re(this,null,function*(){var n,i;const a=s.session;if(this.getActiveCalls[a.id]!==void 0)return;const e=this.getNewRoomId(),d={started:new Date,incomingInProgress:!1,roomId:e};a.direction==="incoming"?(this.context.logger.log("New incoming call from",(i=(n=a._remote_identity)==null?void 0:n._uri)==null?void 0:i._user),d.incomingInProgress=!0,this.context.subscribe(Zt.CALL_CONFIRMED,p=>{a.id===p.id&&(this.updateRoom({incomingInProgress:!1,roomId:e}),this.startCallTimer(a.id))}),this.context.subscribe(Zt.CALL_FAILED,p=>{a.id===p.id&&(this.updateRoom({incomingInProgress:!1,roomId:e}),this.deleteRoomIfEmpty(e))})):a.direction==="outgoing"&&(a.once("confirmed",()=>{this.startCallTimer(a.id)}),this.startCallTimer(a.id));const _=a,u=this.hasAutoAnswerHeaders(s),g=_.direction==="incoming"&&!this.hasActiveCalls&&(u||this.autoAnswer);_.roomId=e,_.localMuted=!1,_.autoAnswer=g,g?this.addCall(_,!1):this.addCall(_),this.addCallStatus(a.id),this.addRoom(d),g&&this.answerCall(_._id)})}removeCall(s){const n=oe({},this.activeCalls);delete n[s],this.activeCalls=oe({},n);const i=oe({},this.extendedCalls);delete i[s],this.extendedCalls=oe({},i),this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(s){const n=this.extendedCalls[s._id];if(!n)return;this.stopVUMeter("origin"),this.stopVUMeter(s._id);const i=n.roomId;this.removeCall(s._id),this.roomReconfigure(i).then(()=>{}).catch(a=>{console.error("Error reconfiguring room after call removal:",a)})}shouldTerminateNewSession(s){if(s.session.direction==="outgoing")return!1;const n=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||n}newRTCSessionCallback(s){return re(this,null,function*(){const n=s.session;if(this.shouldTerminateNewSession(s)){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Zt.NEW_CALL,session:n,event:s}),n.on("ended",i=>{var a,e,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(e=(a=n._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Zt.CALL_ENDED,session:n,event:i});const _=this.getActiveCalls[n.id];_&&this.activeCallListRemove(_),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(u=>u.stop()),console.log("LLL this.initialStreamValue = null 1"),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("progress",i=>{var a,e;this.context.logger.log("Session in progress for",(e=(a=n._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Zt.CALL_PROGRESS,session:n,event:i})}),n.on("failed",i=>{var a,e,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(e=(a=n._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Zt.CALL_FAILED,session:n,event:i}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const _=this.getActiveCalls[n.id];_&&this.activeCallListRemove(_),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(u=>u.stop()),console.log("LLL this.initialStreamValue = null 2"),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("confirmed",i=>{var a,e;this.context.logger.log("Session confirmed for",(e=(a=n._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Zt.CALL_CONFIRMED,session:n,event:i}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),yield this.setupCall(s),n.direction==="outgoing"){const i=this.getActiveCalls[n.id].roomId;yield this.setActiveRoom(i)}})}setMuteWhenJoin(s){this.muteWhenJoinEnabled=s,this.context.emit("changeMuteWhenJoin",s)}setMicrophoneSensitivity(s){if(s<0||s>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=s,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(s){this.speakerVolumeValue=s,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=s,this.updateCall(n))})}setAutoAnswer(s){this.isAutoAnswer=s}setSelectedInputDevice(s){localStorage.setItem(Ll.SELECTED_INPUT_DEVICE,s),this.selectedMediaDevices.input=s,this.context.emit("changeActiveInputMediaDevice",s)}setSelectedOutputDevice(s){localStorage.setItem(Ll.SELECTED_OUTPUT_DEVICE,s),this.selectedMediaDevices.output=s,this.context.emit("changeActiveOutputMediaDevice",s)}setCallMetrics(s){const n=oe({},s);delete n.callId,this.callMetrics=ot(oe({},this.callMetrics),{[s.callId]:n}),this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(s){const n=oe({},this.callMetrics);delete n[s],this.callMetrics=oe({},n),this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(s){const n=new My(this.metricConfig),i=n.createProbe(s.connection,{cid:s._id}),a=[];let e;i.onreport=d=>{Object.entries(d.audio).forEach(([g,p])=>{p.direction==="inbound"&&!a.includes(g)&&(a.push(g),e=g)});const _=d.audio[e];if(!_)return;const u=xy(_,Py);u.callId=s._id,this.setCallMetrics(u)},this.context.subscribe(Zt.CALL_ENDED,d=>{d._id===s._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(s,n){return re(this,null,function*(){yield this.VUMeter.start(yield this.managedAudioContext.getContext(),s,n)})}stopVUMeter(s){this.VUMeter.stop(s)}setupStream(){return re(this,null,function*(){try{const s=Date.now(),n=yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);console.log("LLL this.getUserMediaConstraints",this.getUserMediaConstraints),this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach((i,a)=>{i.stop()}),console.log("LLL this.initialStreamValue = null 3"),this.initialStreamValue=null),console.log("LLL this.initialStreamValue = stream",n),this.initialStreamValue=n}catch(s){throw s}})}triggerAddStream(s,n){return re(this,null,function*(){const i=this.muteWhenJoin||this.isMuted;this.setIsMuted(i),console.log("LLL triggerAddStream this.initialStreamValue",this.initialStreamValue),this.initialStreamValue||(yield this.setupStream());const a=yield this.managedAudioContext.getContext();console.log("LLL triggerAddStream",this.initialStreamValue);const e=yield jd(a,this.initialStreamValue,this.microphoneInputLevel*2),d=this.isMuted||this.muteWhenJoin;e.getTracks().forEach(g=>{g.enabled=!d}),yield this.setActiveStream(e),yield n.connection.getSenders()[0].replaceTrack(e.getTracks()[0]);const _=new MediaStream([s.track]);!Object.values(this.extendedCalls).find(g=>g.audioTag&&g.audioTag.id===n._id)&&wv(_,n,this.selectedOutputDevice,this.speakerVolume);const u=n.roomId===this.currentActiveRoomId;n.audioTag&&(n.audioTag.muted=!u),yield this.setupVUMeter(_,n._id),this.getCallQuality(n),this.updateCall(n)})}initCall(s,n,i=!1){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`);const a=this.context.call(`sip:${s}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=a.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:a.id,roomId:this.currentActiveRoomId}),i)){const e=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&d._id!==a.id);for(const d of e)this.holdCall(d._id,!0)}a.connection.addEventListener("track",e=>{console.log("LLL initCall triggerAddStream"),this.triggerAddStream(e,a)})}processRoomChange(i){return re(this,arguments,function*({callId:s,roomId:n}){const a=this.extendedCalls[s];if(!a)return;const e=a.roomId;a.roomId=n,this.updateCall(a),yield this.roomReconfigure(e),yield this.roomReconfigure(n)})}}class jy{constructor(s){this.context=s}get sipOptions(){return oe({},this.context.options.sipOptions)}initCall(s,n){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${s}@${this.context.sipDomain}`,n,this.sipOptions)}stop(s={}){this.context.terminateJanusSessions(s)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(s){this.context.changeMediaConstraints(s)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class $y{constructor(s){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=s,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(s){const n=this.extendedMessages[s];this.updateMSRPSession(n)}updateMSRPSession(s){this.activeMessages[s._id]=Fd(s),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(s){this.activeMessages=ot(oe({},this.activeMessages),{[s._id]:Fd(s)}),this.extendedMessages[s._id]=s,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(s,n){const i=this.msrpHistory[n.id]||[];i.push(s),this.msrpHistory=ot(oe({},this.msrpHistory),{[n.id]:[...i]}),this.context.emit("newMSRPMessage",{message:s,session:n})}messageTerminate(s){const n=this.extendedMessages[s];n._status!==8&&n.terminate()}addMessageSession(s){if(!s._id||this.getActiveMessages[s._id]!==void 0)return;const n=s;this.addMMSRPSession(n)}triggerMSRPListener({listenerType:s,session:n,event:i}){const a=this.context.listenersList[s];!a||!a.length||a.forEach(e=>{e(n,i)})}removeMMSRPSession(s){const n=oe({},this.activeMessages);delete n[s],this.activeMessages=oe({},n);const i=oe({},this.extendedMessages);delete i[s],this.extendedMessages=oe({},i),this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(s){this.removeMMSRPSession(s._id)}newMSRPSessionCallback(s){const n=s.session;n.on("ended",i=>{this.triggerMSRPListener({listenerType:Zt.CALL_ENDED,session:n,event:i});const a=this.getActiveMessages[n.id];this.activeMessageListRemove(a)}),n.on("failed",i=>{this.triggerMSRPListener({listenerType:Zt.CALL_FAILED,session:n,event:i});const a=this.getActiveMessages[n.id];this.activeMessageListRemove(a)}),n.on("confirmed",i=>{this.triggerMSRPListener({listenerType:Zt.CALL_CONFIRMED,session:n,event:i}),this.updateMSRPSession(n)}),n.on("newMessage",i=>{this.addMSRPMessage(i,n)}),this.addMessageSession(n)}setIsMSRPInitializing(s){this.isMSRPInitializingValue=s,this.context.emit("isMSRPInitializingChanged",s)}initMSRP(s,n,i){if(s.length===0)return console.error("Target must be a valid string");const a=this.context.startMSRP(s,i);a.on("active",()=>{this.addMessageSession(a),a.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(s,n){const i=this.extendedMessages[s];if(!i)throw new Error(`MSRP session with id ${s} doesn't exist!`);i.sendMSRP(n)}}const Hl={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class s_{constructor(s){this.opensips=null,this.session=null,this.name=null,this.name=s}setOpensips(s){this.opensips=s}setSession(s){this.session=s}kill(){this.opensips.kill(this.name)}}class Vy extends s_{constructor(s,n){super(s),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(s={}){this.opaqueId=this.session.generateOpaqueId();const n=Me.cloneArray(s.extraHeaders),i={from_tag:this.session._from_tag};s.fromUserName&&(i.from_uri=new ds("sip",s.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),s.fromDisplayName&&(i.from_display_name=s.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 St.InitialOutgoingInviteRequest(this.session.target,this.session._ua,i,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 s;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(s),s=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(s){s.forEach(n=>{this._connection.addTrack(n)})}_sendInitialRequest(){return re(this,null,function*(){const s=new Ir(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});if(yield this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=yield this._connection.createOffer(n),yield this._connection.setLocalDescription(this.jsep_offer);const i={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},a=JSON.stringify(i);this._request.body=a,s.send()})}_receiveInviteResponse(s){if(this._publisherSubscribeSent||!s.body)return;const n=JSON.parse(s.body);this.handleId=n.data.id;const i={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(qt.PUBLISHER)];this.session.sendRequest(U.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:e=>re(this,null,function*(){var d,_,u,g;if(e.status_code===200){if(this._subscribeSent=!0,e.body)try{const p=JSON.parse(e.body)||{};((_=(d=p.plugindata)==null?void 0:d.data)==null?void 0:_.videoroom)==="joined"&&this.session.myFeedList.push(p.plugindata.data.id),(g=(u=p.plugindata)==null?void 0:u.data)!=null&&g.publishers&&this.session.receivePublishers(p)}catch(p){console.error(p)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}})}}),this._publisherSubscribeSent=!0}_sendConfigureMessage(s){return re(this,null,function*(){const n=this._candidates.map(e=>({janus:"trickle",candidate:e,handle_id:this.handleId,session_id:this.session.session_id})),i={configure:{janus:"message",body:oe({request:"configure",record:!0,filename:this.session.getRecordFileName()},s),jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},a=["Content-Type: application/json",this.session.getPTypeHeader(qt.ICE)];this.session.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:e=>re(this,null,function*(){this._configureSent=!0;const d=e.data.split(`\r
159
- `),_=d[d.length-1],u=JSON.parse(_);yield this._connection.setRemoteDescription(u.jsep),this._candidates=[]})}})})}_sendDetach(){const s={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},n=[this.session.getPTypeHeader(qt.DETACH)];this.session.sendRequest(U.INFO,{extraHeaders:n,body:JSON.stringify(s)}),this.session._ua.emit("pluginDetach",this.name)}stopMedia(){return re(this,null,function*(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)})}stop(){return re(this,null,function*(){yield this.session.stopProcessPlugins(this.type);const s=this._connection.getSenders();s.forEach(n=>{const i=n.track;i&&i.stop()}),s.forEach(n=>{this._connection.removeTrack(n)}),yield this.stopMedia(),this._sendDetach()})}generateStream(){return re(this,null,function*(){throw new Error("generateStream method is not implemented")})}}class By extends s_{constructor(s,n,i={}){super(s),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=i.immediate||!1,this.type=n}start(s){return s}stop(){throw new Error("stop method is not implemented")}process(s){return re(this,null,function*(){if(this.immediate){const n=yield this.start(s);return this.running=!0,n}return s})}connect(){return re(this,null,function*(){this.running=!0,yield this.session.resyncPlugins(this.type)})}terminate(){this.stop()}kill(){return re(this,null,function*(){this.stop(),this.running=!1,yield this.session.resyncPlugins(this.type)})}}class Ky extends Ev{constructor(s,n){if(console.log("LLL opensips constructor"),!s.modules.length)throw new Error("options.modules should include at least 1 module");const i=ot(oe({},s.configuration),{sockets:s.socketInterfaces.map(a=>new $v.WebSocketInterface(a))});super(i),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=[],s.pnExtraHeaders&&Object.keys(s.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(s.pnExtraHeaders),this.options=s,this.modules=s.modules,s.configuration.reconnectionAttemptsLimit&&(this.reconnectionAttemptsLimit=s.configuration.reconnectionAttemptsLimit),n&&Ov(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(Hl.AUDIO)?this.audio.hasActiveAnsweredCalls:!1}on(s,n){return super.on(s,n)}off(s,n){return super.off(s,n)}emit(s,n){return super.emit(s,n)}get sipDomain(){return this.options.sipDomain}use(s){if(this.newStreamPlugins.find(n=>n.name===s.name)||this.processStreamPlugins.find(n=>n.name===s.name))throw new Error(`Plugin with name ${s.name} already exists`);if(s instanceof Vy)s.setOpensips(this),this.newStreamPlugins.push(s);else if(s instanceof By)s.setOpensips(this),this.processStreamPlugins.push(s);else throw new Error("Wrong plugin instance")}getPlugin(s){return this.newStreamPlugins.find(n=>n.name===s)||this.processStreamPlugins.find(n=>n.name===s)}reconnect(){if(this.reconnectionAttemptsCounter<this.reconnectionAttemptsLimit){const s=5e3*Math.pow(2,this.reconnectionAttemptsCounter);this.reconnectionAttemptsCounter++,setTimeout(this.start.bind(this),s)}else this.emit("reconnectionAttemptsLimitReached",void 0)}begin(){if(console.log("LLL begin"),this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(Hl.AUDIO)&&(console.log("LLL new AudioModule"),this.audio=new Fy(this)),this.modules.includes(Hl.MSRP)&&(this.msrp=new $y(this)),this.modules.includes(Hl.VIDEO)&&(this.video=new jy(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(s,n){const i=!this.listenersList[s]||!this.listenersList[s].length?[n]:[...this.listenersList[s],n];this.listenersList=ot(oe({},this.listenersList),{[s]:i})}removeIListener(s){const n=oe({},this.listenersList);delete n[s],this.listenersList=oe({},n)}triggerListener({listenerType:s,session:n,event:i}){const a=this.listenersList[s];!a||!a.length||a.forEach(e=>{e(n,i)})}setInitialized(s){this.initialized=s,this.emit("ready",s)}setConnected(s){this.connected=s,this.emit("connection",s)}setReconnecting(s){this.isReconnecting=s,this.emit("reconnecting",s)}}let se;const r_=ve.ref(!1),i_=ve.ref(!1),o_=ve.ref(!1),l_=ve.ref({}),a_=ve.ref({}),u_=ve.ref(!1),c_=ve.ref(void 0),ql=ve.ref({}),vu=ve.ref({}),Fl=ve.ref([]),yu=ve.ref("default"),Eu=ve.ref("default"),Su=ve.ref(!1),Au=ve.ref(!1),Cu=ve.ref(!0),h_=ve.ref(!1),d_=ve.ref(null),Zs=ve.ref(void 0),__=ve.ref(!1),bu=ve.ref(2),Ru=ve.ref(1),Iu=ve.ref({}),f_=ve.ref({}),p_=ve.ref({}),wu=ve.computed(()=>{const l={};return Object.entries(l_.value).forEach(([s,n])=>{var i;(i=Iu.value[s])!=null&&i.isTransferred||(l[s]=n)}),l}),Gy=ve.computed(()=>{const l={},s=Object.values(wu.value).map(n=>n.roomId);return Object.entries(ql.value).forEach(([n,i])=>{s.includes(i.roomId)&&(l[n]=i)}),l}),Wy=ve.computed(()=>Fl.value.filter(l=>l.kind==="audioinput").map(l=>({deviceId:l.deviceId,kind:l.kind,groupId:l.groupId,label:l.label}))),Yy=ve.computed(()=>Fl.value.filter(l=>l.kind==="audiooutput").map(l=>({deviceId:l.deviceId,kind:l.kind,groupId:l.groupId,label:l.label}))),m_=ve.computed(()=>Object.values(wu.value).filter(l=>l.roomId===Zs.value));ve.watch(m_,l=>{!l.length&&Zs.value&&(Zs.value=void 0)}),ve.watch(Eu,l=>re(this,null,function*(){yield tn.actions.setMicrophone(l)})),ve.watch(yu,l=>re(this,null,function*(){yield tn.actions.setSpeaker(l)})),ve.watch(Su,l=>{tn.actions.setMuteWhenJoin(l)}),ve.watch(Au,l=>{tn.actions.setDND(l)}),ve.watch(Cu,l=>{tn.actions.setCallWaiting(l)}),ve.watch(bu,l=>{tn.actions.setMicrophoneSensitivity(l)}),ve.watch(Ru,l=>{tn.actions.setSpeakerVolume(l)}),ve.watch(Zs,l=>re(this,null,function*(){yield tn.actions.setActiveRoom(l)}));const tn={state:{isInitialized:r_,isOpenSIPSReady:i_,isOpenSIPSReconnecting:o_,activeCalls:wu,callsInActiveRoom:m_,activeMessages:a_,addCallToCurrentRoom:u_,callAddingInProgress:c_,activeRooms:Gy,msrpHistory:vu,availableMediaDevices:Fl,inputMediaDeviceList:Wy,outputMediaDeviceList:Yy,selectedOutputDevice:yu,selectedInputDevice:Eu,muteWhenJoin:Su,isDND:Au,isCallWaitingEnabled:Cu,isMuted:h_,originalStream:d_,currentActiveRoomId:Zs,callStatus:Iu,callTime:f_,callMetrics:p_,autoAnswer:__,microphoneInputLevel:bu,speakerVolume:Ru},actions:{init(l,s,n={}){return new Promise((i,a)=>{try{const e=ot(oe({},n),{session_timers:!1,uri:`sip:${l.username}@${l.domain}`,password:l.password});l.authorization_jwt&&(e.authorization_jwt=l.authorization_jwt),se=new Ky({configuration:e,socketInterfaces:[`wss://${l.domain}`],sipDomain:`${l.domain}`,sipOptions:{session_timers:!1,extraHeaders:["X-Bar: bar"],pcConfig:{}},modules:l.modules,pnExtraHeaders:s}),se.on("connection",d=>{u_.value=!1,r_.value=!0,i_.value=d,i(se)}).on("reconnecting",d=>{o_.value=d}).on("changeActiveCalls",d=>{l_.value=oe({},d)}).on("changeActiveMessages",d=>{a_.value=oe({},d)}).on("newMSRPMessage",d=>{const _=d.session._id,u=vu.value[_]||[];u.push(d.message),vu.value[_]=[...u]}).on("callAddingInProgressChanged",d=>{c_.value=d}).on("changeAvailableDeviceList",d=>{Fl.value=[...d]}).on("changeActiveInputMediaDevice",d=>{Eu.value=d}).on("changeActiveOutputMediaDevice",d=>{yu.value=d}).on("changeMuteWhenJoin",d=>{Su.value=d}).on("changeIsCallWaiting",d=>{Cu.value=d}).on("changeIsDND",d=>{Au.value=d}).on("changeIsMuted",d=>{h_.value=d}).on("changeActiveStream",d=>{d_.value=d}).on("currentActiveRoomChanged",d=>{Zs.value=d}).on("addRoom",({roomList:d})=>{ql.value=oe({},d)}).on("updateRoom",({roomList:d})=>{ql.value=oe({},d)}).on("removeRoom",({roomList:d})=>{ql.value=oe({},d)}).on("changeCallStatus",d=>{Iu.value=oe({},d)}).on("changeCallTime",d=>{f_.value=oe({},d)}).on("changeCallMetrics",d=>{p_.value=oe({},d)}).begin(),i(se)}catch(e){console.error(e),a()}})},unregister(){se==null||se.unregister()},register(){se==null||se.register()},disconnect(){se==null||se.disconnect()},initCall(l,s=!1,n=!1){se==null||se.audio.initCall(l,s,n)},answerCall(l){se==null||se.audio.answerCall(l)},terminateCall(l){se==null||se.audio.terminateCall(l)},mute(){se==null||se.audio.mute()},unmute(){se==null||se.audio.unmute()},transferCall(l,s){se==null||se.audio.transferCall(l,s)},mergeCall(l){se==null||se.audio.mergeCall(l)},mergeCallByIds(l,s){se==null||se.audio.mergeCallByIds(l,s)},holdCall(l,s){se==null||se.audio.holdCall(l,s)},unholdCall(l){se==null||se.audio.unholdCall(l)},moveCall(l,s){return re(this,null,function*(){yield se==null?void 0:se.audio.moveCall(l,s)})},muteCaller(l){se==null||se.audio.muteCaller(l)},unmuteCaller(l){se==null||se.audio.unmuteCaller(l)},setMuteWhenJoin(l){se==null||se.audio.setMuteWhenJoin(l)},setDND(l){se==null||se.audio.setDND(l)},setCallWaiting(l){se==null||se.audio.setCallWaiting(l)},setMicrophone(l){return re(this,null,function*(){yield se==null?void 0:se.audio.setMicrophone(l)})},setSpeaker(l){return re(this,null,function*(){yield se==null?void 0:se.audio.setSpeaker(l)})},sendDTMF(l,s){se==null||se.audio.sendDTMF(l,s)},setActiveRoom(l){return re(this,null,function*(){yield se==null?void 0:se.audio.setActiveRoom(l)})},setMicrophoneSensitivity(l){bu.value=l,se==null||se.audio.setMicrophoneSensitivity(l)},setSpeakerVolume(l){Ru.value=l,se==null||se.audio.setSpeakerVolume(l)},setAutoAnswer(l){__.value=l,se==null||se.audio.setAutoAnswer(l)},setMetricsConfig(l){se==null||se.audio.setMetricsConfig(l)},msrpAnswer(l){se==null||se.msrp.msrpAnswer(l)},messageTerminate(l){se==null||se.msrp.messageTerminate(l)},sendMSRP(l,s){se==null||se.msrp.sendMSRP(l,s)},initMSRP(l,s,n){se==null||se.msrp.initMSRP(l,s,n)}}},g_=Symbol();function zy(){return ve.provide(g_,tn),tn}function Xy(){const l=ve.inject(g_);if(!l)throw new Error("useVsipInject() is called without provider, please call useVsipProvide() first");return l}et.useVsipInject=Xy,et.useVsipProvide=zy,et.vsipAPI=tn,Object.defineProperty(et,Symbol.toStringTag,{value:"Module"})});
155
+ a=path:${n.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
156
+ `),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new yr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:a=>{this.onTransportError(),console.log(a)},onAuthenticated:a=>{this._request=a},onReceiveResponse:a=>{this._receiveInviteResponse(a),a.status_code===200&&(a.parseSDP(!0),this._status=ye.STATUS_CONFIRMED,this.target_addr=a.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=ye.STATUS_INVITE_SENT}terminate(n={}){const s=n.cause||U.causes.BYE,i=ke.cloneArray(n.extraHeaders),a=n.body;let e,d=n.status_code,_=n.reason_phrase;if(this._status===ye.STATUS_TERMINATED)throw new Kn.InvalidStateError(this._status);switch(this.status="terminated",this._status){case ye.STATUS_NULL:case ye.STATUS_INVITE_SENT:case ye.STATUS_1XX_RECEIVED:if(d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);d&&(_=_||U.REASON_PHRASE[d]||"",e=`SIP ;cause=${d} ;text="${_}"`),this._status===ye.STATUS_NULL||this._status===ye.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===ye.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=ye.STATUS_CANCELED,this._failed("local",null,U.causes.CANCELED);break;case ye.STATUS_WAITING_FOR_ANSWER:case ye.STATUS_ANSWERED:if(d=d||480,d<300||d>=700)throw new TypeError(`Invalid status_code: ${d}`);this._request.reply(d,_,i,a),this._failed("local",null,U.causes.REJECTED);break;case ye.STATUS_WAITING_FOR_ACK:case ye.STATUS_CONFIRMED:if(_=n.reason_phrase||U.REASON_PHRASE[d]||"",d&&(d<200||d>=700))throw new TypeError(`Invalid status_code: ${d}`);if(d&&i.push(`Reason: SIP ;cause=${d}; text="${_}"`),this._status===ye.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const u=this._dialog;this.receiveRequest=({method:g})=>{g===U.ACK&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(U.BYE,{extraHeaders:i,body:a}),u.terminate())}),this._ended("local",null,s),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(U.BYE,{extraHeaders:i,body:a}),this._ended("local",null,s)}}sendRequest(n,s){return this._dialog.sendRequest(n,s)}authenticate(n){this.status="auth";let s=new Gs("");s.method="AUTH",s.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),s.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),n&&s.addHeader("Authorization",n.toString());let i=s.toString(),a=[];for(var e=0;e<i.length;e++)a.push(i.charCodeAt(e).toString(16));this._connection.send(s.toString())}onmessage(n){const s=new Gs(n.data);if(this.status==="auth"&&s.code===401){const i=this.parseAuth(s.getHeader("WWW-Authenticate")),a=new yg(this.credentials);a.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},i,ke.createRandomToken(12)),this.authenticate(a)}this.status==="auth"&&s.code===200&&this._direction==="outgoing"?(this.my_addr.push(s.getHeader("To-Path")),this.my_addr.push(s.getHeader("Use-Path")),this.status="active",this.inviteParty(s)):this.status==="auth"&&s.code===200&&this._direction==="incoming"?(this.my_addr.push(s.getHeader("To-Path")),this.my_addr.push(s.getHeader("Use-Path")),this.status="active",this.acceptParty(s),this.emit("confirmed")):s.method==="SEND"&&(this._sendOk(s),this._sendReport(s),s.direction="incoming",this.emit("newMessage",s),this._msgHistory.push(s),this.emit("msgHistoryUpdate",this._msgHistory)),s.code===480&&this._close()}onclose(){console.log("close")}onopen(){const n=new RTCPeerConnection({iceServers:[]});n.createDataChannel(""),n.createOffer().then(n.setLocalDescription.bind(n)),n.onicecandidate=s=>{if(!s||!s.candidate||!s.candidate.candidate)return;const i=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,a=s.candidate.candidate.match(i);this.my_ip=a&&a[1],n.onicecandidate=()=>{},this.authenticate(null)}}onerror(n){console.log(n)}_receiveInviteResponse(n){if(console.log("resp0000000000000",n),this._dialog&&n.status_code>=200&&n.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===n.call_id&&this._dialog.id.local_tag===n.from_tag&&this._dialog.id.remote_tag===n.to_tag){this.sendRequest(U.ACK);return}else{const s=new _l(this,n,"UAC");if(s.error!==void 0){console.log(s.error);return}this.sendRequest(U.ACK),this.sendRequest(U.BYE);return}if(this._is_canceled){n.status_code>=100&&n.status_code<200?this._request.cancel(this._cancel_reason):n.status_code>=200&&n.status_code<299&&this._acceptAndTerminate(n);return}if(!(this._status!==ye.STATUS_INVITE_SENT&&this._status!==ye.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(n.status_code):this._status=ye.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(n.status_code):{if(!n.to_tag){console.log("1xx response received without to tag");break}if(n.hasHeader("contact")&&!this._createDialog(n,"UAC",!0))break;if(this._status=ye.STATUS_1XX_RECEIVED,!n.body){this._progress("remote",n);break}const s={originator:"remote",type:"answer",sdp:n.body};console.log('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>this._progress("remote",n)).catch(a=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(n.status_code):{if(console.log("maybe here???"),this._status=ye.STATUS_CONFIRMED,!n.body){this._acceptAndTerminate(n,400,U.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",n,U.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(n,"UAC"))break;const s={originator:"remote",type:"answer",sdp:n.body};console.log('emit "sdp"'),this.emit("sdp",s),new RTCSessionDescription({type:"answer",sdp:s.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(i=>this._connection.setLocalDescription(i)).catch(i=>{this._acceptAndTerminate(n,500,i.toString()),console.log("failed 4"),this._failed("local",n,U.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(n),this._accepted("remote",n),this.sendRequest(U.ACK),this._confirmed("local",null)});break}default:{const s=ke.sipErrorCause(n.status_code);console.log("failed 5"),this._failed("remote",n,s)}}}sendMSRP(n){const s=new Gs("");s.method="SEND",s.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),s.addHeader("From-Path",`${this.my_addr[0]}`),s.addHeader("Message-ID",ke.createRandomToken(10)),s.addHeader("Byte-Range","1-25/25"),s.addHeader("Content-Type","text/plain"),s.addHeader("Success-Report","yes"),s.addHeader("Failure-Report","yes"),s.body=n;let i=s.toString();console.log(i);let a=[];for(var e=0;e<i.length;e++)a.push(i.charCodeAt(e).toString(16));console.log(a),this._connection.send(s.toString()),s.direction="outgoing",this.emit("newMessage",s),this._msgHistory.push(s),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(n){let s=n.ident,i=n.getHeader("Message-ID"),a=new Gs("");a.method="200 OK",a.addHeader("To-Path",`${this.my_addr[1]}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",i),a.ident=s;let e=a.toString();console.log(e);let d=[];for(var _=0;_<e.length;_++)d.push(e.charCodeAt(_).toString(16));console.log(d),this._connection.send(a.toString())}_sendReport(n){let s=n.ident,i=n.getHeader("Message-ID"),a=new Gs("");a.method="REPORT",a.addHeader("To-Path",`${n.getHeader("From-Path")}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",i),a.addHeader("Byte-Range","1-25/25"),a.addHeader("Status","000 200 OK"),a.ident=s;let e=a.toString();console.log(e);let d=[];for(var _=0;_<e.length;_++)d.push(e.charCodeAt(_).toString(16));console.log(d),this._connection.send(a.toString())}parseAuth(n){const s={},i=n.replace("Digest","").split(",");for(const a of i){const e=a.trim().split("=");s[e[0]]=e[1].match('^"(.+)"$')[1]}return s}init_incoming(n,s){let i;const a=n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0;if(n.body&&a!=="application/sdp"){n.reply(415);return}if(this._status=ye.STATUS_INVITE_RECEIVED,this._from_tag=n.from_tag,this._id=n.call_id+this._from_tag,this._request=n,this._contact=this._ua.contact.toString(),n.hasHeader("expires")&&(i=n.getHeader("expires")*1e3),n.to_tag=ke.newTag(),!this._createDialog(n,"UAS",!0)){n.reply(500,"Missing Contact header field");return}n.body?this._late_sdp=!1:this._late_sdp=!0,this._status=ye.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{n.reply(408),console.log("failed 6"),this._failed("local",null,U.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),i&&(this._timers.expiresTimer=setTimeout(()=>{this._status===ye.STATUS_WAITING_FOR_ANSWER&&(n.reply(487),console.log("failed 7"),this._failed("system",null,U.causes.EXPIRES))},i)),this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from,s&&s(this),n.parseSDP(!0),this.target_addr=n.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",n),this._status!==ye.STATUS_TERMINATED&&(n.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(n,s,i){this.emit("_failed",{originator:n,message:s||null,cause:i}),this._close(),this.emit("failed",{originator:n,message:s||null,cause:i})}_close(){if(console.log("CLOSE SESSION"),this._status!==ye.STATUS_TERMINATED){if(this._status=ye.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(n){console.log("close() | error closing the RTCPeerConnection: %o",n)}for(const n in this._timers)Object.prototype.hasOwnProperty.call(this._timers,n)&&clearTimeout(this._timers[n]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const n in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,n)&&(this._earlyDialogs[n].terminate(),delete this._earlyDialogs[n]);for(const n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyMSRPSession(this)}}_createDialog(n,s,i){const a=s==="UAS"?n.to_tag:n.from_tag,e=s==="UAS"?n.from_tag:n.to_tag,d=n.call_id+a+e;let _=this._earlyDialogs[d];if(i)return _?!0:(_=new _l(this,n,s,_l.C.STATUS_EARLY),_.error?(console.log("failed 8"),this._failed("remote",n,U.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=_,!0));{if(this._from_tag=n.from_tag,this._to_tag=n.to_tag,_)return _.update(n,s),this._dialog=_,delete this._earlyDialogs[d],!0;const u=new _l(this,n,s);return u.error?(console.log("failed 9"),this._failed("remote",n,U.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_newMSRPSession(n,s){this._ua.newMSRPSession(this,{originator:n,session:this,request:s})}_progress(n,s){this.emit("progress",{originator:n,response:s||null})}isEnded(){switch(this._status){case ye.STATUS_CANCELED:case ye.STATUS_TERMINATED:return!0;default:return!1}}_accepted(n,s){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:n,response:s||null})}_confirmed(n,s){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:n,ack:s||null})}_ended(n,s,i){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:n,message:s||null,cause:i})}_handleSessionTimersInIncomingResponse(n){if(!this._sessionTimers.enabled)return;let s;n.session_expires&&n.session_expires>=U.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=n.session_expires,s=n.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}receiveRequest(n){if(console.log("receiveRequest()"),n.method===U.CANCEL)(this._status===ye.STATUS_WAITING_FOR_ANSWER||this._status===ye.STATUS_ANSWERED)&&(this._status=ye.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",n,U.causes.CANCELED));else switch(n.method){case U.ACK:if(this._status!==ye.STATUS_WAITING_FOR_ACK)return;if(this._status=ye.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!n.body){this.terminate({cause:U.causes.MISSING_SDP,status_code:400});break}const s={originator:"remote",type:"answer",sdp:n.body};console.log('emit "sdp"'),this.emit("sdp",s);const i=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(i)).then(()=>{this._is_confirmed||this._confirmed("remote",n)}).catch(a=>{this.terminate({cause:U.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",n);break;case U.BYE:this._status===ye.STATUS_CONFIRMED||this._status===ye.STATUS_WAITING_FOR_ACK?(n.reply(200),this._ended("remote",n,U.causes.BYE)):this._status===ye.STATUS_INVITE_RECEIVED||this._status===ye.STATUS_WAITING_FOR_ANSWER?(n.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",n,U.causes.BYE)):n.reply(403,"Wrong Status");break;case U.INVITE:this._status===ye.STATUS_CONFIRMED?n.hasHeader("replaces")?this._receiveReplaces(n):this._receiveReinvite(n):n.reply(403,"Wrong Status");break;case U.INFO:this._status===ye.STATUS_1XX_RECEIVED||this._status===ye.STATUS_WAITING_FOR_ANSWER||this._status===ye.STATUS_ANSWERED||this._status===ye.STATUS_WAITING_FOR_ACK||this._status===ye.STATUS_CONFIRMED?(n.hasHeader("Content-Type")?n.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new Ha(this).init_incoming(n):n.reply(415):n.reply(403,"Wrong Status");break;case U.UPDATE:this._status===ye.STATUS_CONFIRMED?this._receiveUpdate(n):n.reply(403,"Wrong Status");break;case U.REFER:this._status===ye.STATUS_CONFIRMED?this._receiveRefer(n):n.reply(403,"Wrong Status");break;case U.NOTIFY:this._status===ye.STATUS_CONFIRMED?this._receiveNotify(n):n.reply(403,"Wrong Status");break;default:n.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==ye.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==ye.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==ye.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.DIALOG_ERROR,cause:U.causes.DIALOG_ERROR})}}var uv=Bt();const su=We(uv),bl=new ll("Parser"),cv=(l,n)=>{let s,i,a=l.indexOf(`\r
157
+ `);if(a===-1){bl.warn("parseMessage() | no CRLF found, not a SIP message");return}const e=l.substring(0,a);let d=su.parse(e,"Request_Response");if(d===-1){bl.warn(`parseMessage() | error parsing first line of SIP message: "${e}"`);return}else d.status_code?(s=new $s.IncomingResponse,s.status_code=d.status_code,s.reason_phrase=d.reason_phrase):(s=new $s.IncomingRequest(n),s.method=d.method,s.ruri=d.uri);s.data=l;let _=a+2;for(;;){if(a=hv(l,_),a===-2){i=_+2;break}else if(a===-1){bl.warn("parseMessage() | malformed message");return}if(d=dv(s,l,_,a),d!==!0){bl.warn("parseMessage() |",d.error);return}_=a+2}if(s.hasHeader("content-length")){const u=s.getHeader("content-length");s.body=l.substr(i,u)}else s.body=l.substring(i);return s};function hv(l,n){let s=n,i=0,a=0;if(l.substring(s,s+2).match(/(^\r\n)/))return-2;for(;i===0;){if(a=l.indexOf(`\r
158
+ `,s),a===-1)return a;!l.substring(a+2,a+4).match(/(^\r\n)/)&&l.charAt(a+2).match(/(^\s+)/)?s=a+2:i=a}return i}function dv(l,n,s,i){let a;const e=n.indexOf(":",s),d=n.substring(s,e).trim(),_=n.substring(e+1,i).trim();switch(d.toLowerCase()){case"via":case"v":l.addHeader("via",_),l.getHeaders("via").length===1?(a=l.parseHeader("Via"),a&&(l.via=a,l.via_branch=a.branch)):a=0;break;case"from":case"f":l.setHeader("from",_),a=l.parseHeader("from"),a&&(l.from=a,l.from_tag=a.getParam("tag"));break;case"to":case"t":l.setHeader("to",_),a=l.parseHeader("to"),a&&(l.to=a,l.to_tag=a.getParam("tag"));break;case"record-route":if(a=su.parse(_,"Record_Route"),a===-1)a=void 0;else for(const u of a)l.addHeader("record-route",_.substring(u.possition,u.offset)),l.headers["Record-Route"][l.getHeaders("record-route").length-1].parsed=u.parsed;break;case"call-id":case"i":l.setHeader("call-id",_),a=l.parseHeader("call-id"),a&&(l.call_id=_);break;case"contact":case"m":if(a=su.parse(_,"Contact"),a===-1)a=void 0;else for(const u of a)l.addHeader("contact",_.substring(u.possition,u.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=u.parsed;break;case"content-length":case"l":l.setHeader("content-length",_),a=l.parseHeader("content-length");break;case"content-type":case"c":l.setHeader("content-type",_),a=l.parseHeader("content-type");break;case"cseq":l.setHeader("cseq",_),a=l.parseHeader("cseq"),a&&(l.cseq=a.value),l instanceof $s.IncomingResponse&&(l.method=a.method);break;case"max-forwards":l.setHeader("max-forwards",_),a=l.parseHeader("max-forwards");break;case"www-authenticate":l.setHeader("www-authenticate",_),a=l.parseHeader("www-authenticate");break;case"proxy-authenticate":l.setHeader("proxy-authenticate",_),a=l.parseHeader("proxy-authenticate");break;case"session-expires":case"x":l.setHeader("session-expires",_),a=l.parseHeader("session-expires"),a&&(l.session_expires=a.expires,l.session_expires_refresher=a.refresher);break;case"refer-to":case"r":l.setHeader("refer-to",_),a=l.parseHeader("refer-to"),a&&(l.refer_to=a);break;case"replaces":l.setHeader("replaces",_),a=l.parseHeader("replaces"),a&&(l.replaces=a);break;case"event":case"o":l.setHeader("event",_),a=l.parseHeader("event"),a&&(l.event=a);break;default:l.addHeader(d,_),a=0}return a===void 0?{error:`error parsing header "${d}"`}:!0}const _v={parseMessage:cv},Nr=new ll("Registrator"),Rl=10;class pv{constructor(n,s){this._reg_id=1,this._ua=n,this._transport=s,this._registrar=n.configuration.registrar_server,this._expires=n.configuration.register_expires,this._call_id=En.createRandomToken(22),this._cseq=0,this._to_uri=n.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const i=this._contact.indexOf(">");if(i!==-1){const a=this._contact.slice(0,i)+this._contact.slice(i+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(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}setExtraContactParams(n){n instanceof Object||(n={}),this._extraContactParams="";for(const s in n)if(Object.prototype.hasOwnProperty.call(n,s)){const i=n[s];this._extraContactParams+=`;${s}`,i&&(this._extraContactParams+=`=${i}`)}}setExtraContactUriParams(n){n instanceof Object||(n={}),this._extraContactParams="";for(const s in n)if(Object.prototype.hasOwnProperty.call(n,s)){const i=n[s];this._extraContactParams+=`;${s}`,i&&(this._extraContactParams+=`=${i}`)}}register(){if(this._registering){Nr.debug("Register request in progress...");return}const n=this._extraHeaders.slice();n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),n.push(`Expires: ${this._expires}`);const s=new gt.OutgoingRequest(U.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n),i=new yr(this._ua,s,{onRequestTimeout:()=>{this._registrationFailure(null,U.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,U.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")){Nr.debug("no Contact header in response to REGISTER, response ignored");break}const e=a.headers.Contact.reduce((g,f)=>g.concat(f.parsed),[]);let d=e.find(g=>this._sipInstance===g.getParam("+sip.instance")&&this._reg_id===parseInt(g.getParam("reg-id")));if(d||(d=e.find(g=>g.uri.user===this._ua.contact.uri.user)),!d){Nr.debug("no Contact header pointing to us, response ignored");break}this._ua.clearKeepAliveInterval(),this._ua.setLastRegisterTimestamp();let _=d.getParam("expires");!_&&a.hasHeader("expires")&&(_=a.getHeader("expires")),_||(_=this._expires),_=Number(_),_<Rl&&(_=Rl);const u=_>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")},u),d.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=d.getParam("temp-gruu").replace(/"/g,"")),d.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=d.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<Rl&&(this._expires=Rl),this.register()):(Nr.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,U.causes.SIP_FAILURE_CODE));break}default:{const e=En.sipErrorCause(a.status_code);this._registrationFailure(a,e)}}}});this._registering=!0,i.send()}unregister(n={}){if(!this._registered){Nr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const s=this._extraHeaders.slice();n.all?s.push(`Contact: *${this._extraContactParams}`):s.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),s.push("Expires: 0");const i=new gt.OutgoingRequest(U.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s);new yr(this._ua,i,{onRequestTimeout:()=>{this._unregistered(null,U.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,U.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._unregistered(a);break;default:{const e=En.sipErrorCause(a.status_code);this._unregistered(a,e)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(n,s){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:s}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:s}))}_unregistered(n,s){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:s||null})}}const et=console,zn={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},fv=tv;class mv extends fv{constructor(n){super(n),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 pv(this)}setLastRegisterTimestamp(){this.lastRegisterTimestamp=Date.now()}call(n,s){return super.call(n,s)}joinVideoCall(n,s,i){et.debug("call()");const a=new Cl(this);return a.configureMedia({audio:!0,video:!0}),a.connect(n,s,i),a}startScreenShare(){et.debug("startScreenShare()");for(const n in this._janus_sessions)this._janus_sessions[n].connectScreenShare()}changeMediaConstraints(n){for(const s in this._janus_sessions)this._janus_sessions[s].changeMediaConstraints(n)}startBlur(){for(const n in this._janus_sessions)this._janus_sessions[n].connectBlur()}stopBlur(){for(const n in this._janus_sessions)this._janus_sessions[n].stopBlur()}_loadConfig(n){try{Or.load(this._configuration,n)}catch(e){throw e}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=En.newUUID());let s;typeof window<"u"&&typeof window.document<"u"?s=window?.navigator.userAgent:typeof self<"u"&&self.navigator&&(s=self.navigator.userAgent),s+=" "+Ie.USER_AGENT,this._configuration.user_agent=n.overrideUserAgent&&typeof n.overrideUserAgent=="function"?n.overrideUserAgent(s):s,n.onTransportCallback&&typeof n.onTransportCallback=="function"&&(this.onTransportCallback=n.onTransportCallback),this._configuration.jssip_id=En.createRandomToken(5);const i=this._configuration.uri.clone();i.user=null,this._configuration.hostport_params=i.toString().replace(/^sip:/i,"");try{this._transport=new IT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=gv.bind(this),this._transport.onconnect=Tv.bind(this),this._transport.ondisconnect=vv.bind(this),this._transport.ondata=yv.bind(this)}catch(e){throw et.warn(e),new Kn.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 e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ls("sip",En.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(e={}){const d=e.anonymous||null,_=e.outbound||null;let u="<";return d?u+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":u+=this.pub_gruu||this.uri.toString(),_&&(d?!this.temp_gruu:!this.pub_gruu)&&(u+=";ob"),u+=">",u}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const e in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,e)&&(a.indexOf(e)!==-1?Object.defineProperty(this._configuration,e,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,e,{writable:!1,configurable:!1}));et.debug("configuration parameters after validation:");for(const e in this._configuration)if(Object.prototype.hasOwnProperty.call(Or.settings,e))switch(e){case"uri":case"registrar_server":et.debug(`- ${e}: ${this._configuration[e]}`);break;case"password":case"ha1":case"authorization_jwt":et.debug(`- ${e}: NOT SHOWN`);break;default:et.debug(`- ${e}: ${JSON.stringify(this._configuration[e])}`)}}newMSRPSession(n,s){n.on("msgHistoryUpdate",i=>{console.log(i)}),this._msrp_sessions[n.id]=n,this.emit("newMSRPSession",s)}newJanusSession(n,s){this._janus_sessions[n.id]=n,this.newStreamPlugins.forEach(i=>{i.setSession(n)}),this.processStreamPlugins.forEach(i=>{i.setSession(n)}),this.emit("newJanusSession",s)}kill(){}destroyMSRPSession(n){delete this._msrp_sessions[n.id]}destroyJanusSession(n){delete this._janus_sessions[n.id]}clearKeepAliveInterval(){clearInterval(this.optionsInterval),this.optionsInterval=null}receiveRequest(n){var s,i,a,e;const d=n.method;if(n.ruri.user!==this._configuration.uri.user&&n.ruri.user!==this._contact.uri.user){et.debug("Request-URI does not point to us"),n.method!==Ie.ACK&&n.reply_sl(404);return}if(n.ruri.scheme===Ie.SIPS){n.reply_sl(416);return}if(jt.checkTransaction(this,n))return;if(d===Ie.INVITE?new jt.InviteServerTransaction(this,this._transport,n):d!==Ie.ACK&&d!==Ie.CANCEL&&new jt.NonInviteServerTransaction(this,this._transport,n),d===Ie.OPTIONS){if(this.lastOptionsTimestamp=Date.now(),this.optionsInterval||(this.emit("initKeepAliveInterval"),this.optionsInterval=setInterval(()=>{const g=Date.now(),f=this.lastOptionsTimestamp>g-35e3,T=this.lastRegisterTimestamp+this._configuration.register_expires*1e3>g;f&&T&&this.emit("keepAliveInterval")},35e3)),this.listeners("newOptions").length===0){n.reply(200);return}new Ph.Options(this).init_incoming(n)}else if(d===Ie.MESSAGE){if(this.listeners("newMessage").length===0){n.reply(405);return}new Ph.Message(this).init_incoming(n)}else if(d===Ie.INVITE&&!n.to_tag&&this.listeners("newRTCSession").length===0){n.reply(405);return}let _,u;if(n.to_tag)if(_=this._findDialog(n.call_id,n.from_tag,n.to_tag),_)_.receiveRequest(n);else if(d===Ie.NOTIFY)if(u=this._findSession(n),u)u.receiveRequest(n);else{if(n.body)try{const g=JSON.parse(n.body)||{};(i=(s=g.plugindata)==null?void 0:s.data)!=null&&i.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(g),(e=(a=g.plugindata)==null?void 0:a.data)!=null&&e.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(g.plugindata.data.unpublished)}catch(g){console.error(g)}n.reply(200)}else d!==Ie.ACK&&n.reply(481);else switch(d){case Ie.INVITE:if(window.RTCPeerConnection)if(n.hasHeader("replaces")){const g=n.replaces;_=this._findDialog(g.call_id,g.from_tag,g.to_tag),_?(u=_.owner,u.isEnded()?n.reply(603):u.receiveRequest(n)):n.reply(481)}else n.body.search(/MSRP/ig)>-1?(u=new nu(this),u.init_incoming(n)):n.body.search(/JANUS/ig)>-1||(u=new hT(this),u.init_incoming(n));else et.warn("INVITE received but WebRTC is not supported"),n.reply(488);break;case Ie.BYE:n.reply(481);break;case Ie.CANCEL:u=this._findSession(n),u?u.receiveRequest(n):et.debug("received CANCEL request for a non existent session");break;case Ie.ACK:break;case Ie.NOTIFY:this.emit("sipEvent",{event:n.event,request:n}),n.reply(200);break;default:n.reply(405);break}}startMSRP(n,s){et.debug("startMSRP()",s);const i=new nu(this);return i.connect(n),i}startJanus(n,s){et.debug("startJanus()",s);const i=new nu(this);return i.connect(n),i}terminateMSRPSessions(n){et.debug("terminateSessions()");for(const s in this._msrp_sessions)this._msrp_sessions[s].isEnded()||this._msrp_sessions[s].terminate(n)}terminateJanusSessions(n){et.debug("terminateSessions()");for(const s in this._janus_sessions)this._janus_sessions[s].isEnded()||this._janus_sessions[s].terminate(n)}enableJanusAudio(n){et.debug("enableJanusAudio()");for(const s in this._janus_sessions)this._janus_sessions[s].isEnded()||(n?this._janus_sessions[s].startAudio():this._janus_sessions[s].stopAudio())}enableJanusVideo(n){et.debug("enableJanusVideo()");for(const s in this._janus_sessions)this._janus_sessions[s].isEnded()||(n?this._janus_sessions[s].startVideo():this._janus_sessions[s].stopVideo())}terminateAllSessions(){for(const n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){et.debug(`closing session ${n}`);try{this._sessions[n].terminate()}catch(s){console.error(s)}}}stop(n=!0){if(et.debug("stop()"),this._dynConfiguration={},this._status===zn.STATUS_USER_CLOSED){et.debug("UA already closed");return}this._registrator.close();const s=Object.keys(this._sessions).length;n&&this.terminateAllSessions();for(const i in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,i)){et.debug(`closing session ${i}`);try{this._msrp_sessions[i].terminate()}catch(a){console.error(a)}}for(const i in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,i)){et.debug(`closing session ${i}`);try{this._janus_sessions[i].terminate()}catch(a){console.error(a)}}for(const i in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,i))try{this._applicants[i].close()}catch(a){console.error(a)}this._status=zn.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function gv(l){this.emit("connecting",l)}function Tv(l){this._status!==zn.STATUS_USER_CLOSED&&(this._status=zn.STATUS_READY,this._error=null,this.emit("connected",l),this._dynConfiguration.register&&this._registrator.register())}function vv(l){const n=["nict","ict","nist","ist"];for(const s of n)for(const i in this._transactions[s])Object.prototype.hasOwnProperty.call(this._transactions[s],i)&&this._transactions[s][i].onTransportError();this.emit("disconnected",l),this._registrator.onTransportClosed(),this._status!==zn.STATUS_USER_CLOSED&&(this._status=zn.STATUS_NOT_READY,this._error=zn.NETWORK_ERROR)}function yv(l){const n=l.transport;let s=l.message;const i=s;if(s=_v.parseMessage(s,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(s,i),!!s&&!(this._status===zn.STATUS_USER_CLOSED&&s instanceof $s.IncomingRequest)&&$T(s,this,n)){if(s instanceof $s.IncomingRequest)s.transport=n,this.receiveRequest(s);else if(s instanceof $s.IncomingResponse){let a;switch(s.method){case Ie.INVITE:a=this._transactions.ict[s.via_branch],a&&a.receiveResponse(s);break;case Ie.ACK:break;default:a=this._transactions.nict[s.via_branch],a&&a.receiveResponse(s);break}}}}const Ev=["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"],Sv=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Dd(l){const n={};return Ev.forEach(s=>{l[s]!==void 0&&(n[s]=l[s])}),n.localHold=l._localHold,n}function kd(l){const n={};return Sv.forEach(s=>{l[s]!==void 0&&(n[s]=l[s])}),n}async function ru(l,n,s){const i=l.createMediaStreamSource(n),a=l.createMediaStreamDestination(),e=l.createGain();return i.connect(e),e.connect(a),e.gain.value=s,a.stream}function Av(l,n,s,i){if(Ud())return;const a=document.createElement("audio");a.id=n._id,a.className="audioTag",a.srcObject=l,a.setSinkId(s),a.volume=i,a.play(),n.audioTag=a}function Cv(l){if(l&&typeof l.log=="function"&&typeof l.warn=="function"&&typeof l.error=="function")return!0}function Ud(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const bv=ot,Rv=Bt(),It=new bv("WebSocketInterface");var Iv=class{constructor(l){It.debug('new() [url:"%s"]',l),this._url=l,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=Rv.parse(l,"absoluteURI");if(n===-1)throw It.warn(`invalid WebSocket URI: ${l}`),new TypeError(`Invalid argument: ${l}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw It.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${l}`);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(l){this._via_transport=l.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(It.debug("connect()"),this.isConnected()){It.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){It.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),It.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(l){this._onError(l)}}disconnect(){It.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(l){return It.debug("send()"),this.isConnected()?(this._ws.send(l),!0):(It.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(){It.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:l,code:n,reason:s}){It.debug(`WebSocket ${this._url} closed`),l===!1&&It.debug("WebSocket abrupt disconnection"),this.ondisconnect(!l,n,s)}_onMessage({data:l}){It.debug("received WebSocket message"),this.ondata(l)}_onError(l){It.warn(`WebSocket ${this._url} error: `,l)}};const iu=So,wv=Ie,Ov=yn,Nv=ft(),Dv=wd,kv=gn(),Uv=ba(),Mv=Bt(),Pv=Iv;xs("JsSIP")("version %s",iu.version);var xv={C:wv,Exceptions:Ov,Utils:Nv,UA:Dv,URI:kv,NameAddrHeader:Uv,WebSocketInterface:Pv,Grammar:Mv,debug:xs,get name(){return iu.title},get version(){return iu.version}};const Lv=We(xv);function ou(l){return l<10?`0${l}`:`${l}`}function Hv(l){let n=l.hours||0,s=l.minutes||0,i=l.seconds||0;i++,i===60&&(i=0,s++,s===60&&(s=0,n++));const a=`${ou(n)}:${ou(s)}:${ou(i)}`;return{seconds:i,minutes:s,hours:n,formatted:a}}function qv(l){let n=0;for(let s=0;s<l.length;s++)n+=l[s]*l[s];return Math.sqrt(n/l.length)}async function Fv(l,n,s=150){const i=n.createMediaStreamSource(l),a=n.createDelay();a.delayTime.value=s/1e3;const e=n.createGain();e.gain.value=0;const d=n.createMediaStreamDestination();return i.connect(a).connect(e).connect(d),{stream:d.stream,setSpeaking:_=>{e.gain.value=_?1:0}}}var Et={};Et.forEach=async(l,n,s)=>{const i=[];for(let a=0;a<l.length;a++)if(a in l){const e=Promise.resolve(l[a]).then(d=>n.call(s||globalThis,d,a,l));i.push(e)}await Promise.all(i)},Et.forEachSeries=async(l,n,s)=>{for(let i=0;i<l.length;i++)i in l&&await n.call(s||globalThis,await l[i],i,l)},Et.map=async(l,n,s)=>{const i=[];for(let a=0;a<l.length;a++)a in l&&(i[a]=Promise.resolve(l[a]).then(e=>n.call(s||globalThis,e,a,l)));return Promise.all(i)},Et.mapSeries=async(l,n,s)=>{const i=[];for(let a=0;a<l.length;a++)a in l&&(i[a]=await n.call(s||globalThis,await l[a],a,l));return i},Et.find=(l,n,s)=>new Promise((i,a)=>{if(l.length===0)return i();let e=1;for(let d=0;d<l.length;d++){const _=u=>{u?i(l[d]):e===l.length&&i(),e++};Promise.resolve(l[d]).then(u=>n.call(s||globalThis,u,d,l)).then(_).catch(a)}}),Et.findSeries=async(l,n,s)=>{for(let i=0;i<l.length;i++)if(await n.call(s||globalThis,await l[i],i,l))return l[i]},Et.findIndex=(l,n,s)=>new Promise((i,a)=>{if(l.length===0)return i(-1);let e=1;for(let d=0;d<l.length;d++){const _=u=>{u?i(d):e===l.length&&i(-1),e++};Promise.resolve(l[d]).then(u=>n.call(s||globalThis,u,d,l)).then(_).catch(a)}}),Et.findIndexSeries=async(l,n,s)=>{for(let i=0;i<l.length;i++)if(await n.call(s||globalThis,await l[i],i,l))return i},Et.some=(l,n,s)=>new Promise((i,a)=>{if(l.length===0)return i(!1);let e=1;for(let d=0;d<l.length;d++){if(!(d in l)){e++;continue}const _=u=>{u?i(!0):e===l.length&&i(!1),e++};Promise.resolve(l[d]).then(u=>n.call(s||globalThis,u,d,l)).then(_).catch(a)}}),Et.someSeries=async(l,n,s)=>{for(let i=0;i<l.length;i++)if(i in l&&await n.call(s||globalThis,await l[i],i,l))return!0;return!1},Et.every=(l,n,s)=>new Promise((i,a)=>{if(l.length===0)return i(!0);let e=1;for(let d=0;d<l.length;d++){if(!(d in l)){e++;continue}const _=u=>{u?e===l.length&&i(!0):i(!1),e++};Promise.resolve(l[d]).then(u=>n.call(s||globalThis,u,d,l)).then(_).catch(a)}}),Et.everySeries=async(l,n,s)=>{for(let i=0;i<l.length;i++)if(i in l&&!await n.call(s||globalThis,await l[i],i,l))return!1;return!0},Et.filter=(l,n,s)=>new Promise(async(i,a)=>{const e=[];for(let _=0;_<l.length;_++)_ in l&&(e[_]=Promise.resolve(l[_]).then(u=>n.call(s||globalThis,u,_,l)).catch(a));const d=[];for(let _=0;_<e.length;_++)await e[_]&&d.push(await l[_]);i(d)}),Et.filterSeries=async(l,n,s)=>{const i=[];for(let a=0;a<l.length;a++)a in l&&await n.call(s||globalThis,await l[a],a,l)&&i.push(await l[a]);return i},Et.reduce=async(l,n,s)=>{if(l.length===0&&s===void 0)throw TypeError("Reduce of empty array with no initial value");let i,a;for(s!==void 0?(a=s,i=0):(a=l[0],i=1),i;i<l.length;i++)i in l&&(a=await n(await a,await l[i],i,l));return a};var Md={};(function(l){const n=Et;Object.keys(n).forEach(s=>{const i=s.charAt(0).toUpperCase()+s.slice(1);l[`async${i}`]=async function(...a){return n[s](this,...a)}})})(Md);var jv=Object.assign(Et,{instanceMethods:Md});const Wt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var $v={exports:{}};(function(l){var n=function(s){var i=Object.prototype,a=i.hasOwnProperty,e=Object.defineProperty||function(Q,V,k){Q[V]=k.value},d,_=typeof Symbol=="function"?Symbol:{},u=_.iterator||"@@iterator",g=_.asyncIterator||"@@asyncIterator",f=_.toStringTag||"@@toStringTag";function T(Q,V,k){return Object.defineProperty(Q,V,{value:k,enumerable:!0,configurable:!0,writable:!0}),Q[V]}try{T({},"")}catch{T=function(Q,V,k){return Q[V]=k}}function y(Q,V,k,ve){var _e=V&&V.prototype instanceof me?V:me,Ae=Object.create(_e.prototype),Ue=new X(ve||[]);return e(Ae,"_invoke",{value:P(Q,k,Ue)}),Ae}s.wrap=y;function A(Q,V,k){try{return{type:"normal",arg:Q.call(V,k)}}catch(ve){return{type:"throw",arg:ve}}}var w="suspendedStart",b="suspendedYield",R="executing",G="completed",x={};function me(){}function O(){}function $(){}var de={};T(de,u,function(){return this});var fe=Object.getPrototypeOf,N=fe&&fe(fe(te([])));N&&N!==i&&a.call(N,u)&&(de=N);var H=$.prototype=me.prototype=Object.create(de);O.prototype=$,e(H,"constructor",{value:$,configurable:!0}),e($,"constructor",{value:O,configurable:!0}),O.displayName=T($,f,"GeneratorFunction");function j(Q){["next","throw","return"].forEach(function(V){T(Q,V,function(k){return this._invoke(V,k)})})}s.isGeneratorFunction=function(Q){var V=typeof Q=="function"&&Q.constructor;return V?V===O||(V.displayName||V.name)==="GeneratorFunction":!1},s.mark=function(Q){return Object.setPrototypeOf?Object.setPrototypeOf(Q,$):(Q.__proto__=$,T(Q,f,"GeneratorFunction")),Q.prototype=Object.create(H),Q},s.awrap=function(Q){return{__await:Q}};function F(Q,V){function k(Ae,Ue,ce,re){var Ge=A(Q[Ae],Q,Ue);if(Ge.type==="throw")re(Ge.arg);else{var tt=Ge.arg,ge=tt.value;return ge&&typeof ge=="object"&&a.call(ge,"__await")?V.resolve(ge.__await).then(function(pe){k("next",pe,ce,re)},function(pe){k("throw",pe,ce,re)}):V.resolve(ge).then(function(pe){tt.value=pe,ce(tt)},function(pe){return k("throw",pe,ce,re)})}}var ve;function _e(Ae,Ue){function ce(){return new V(function(re,Ge){k(Ae,Ue,re,Ge)})}return ve=ve?ve.then(ce,ce):ce()}e(this,"_invoke",{value:_e})}j(F.prototype),T(F.prototype,g,function(){return this}),s.AsyncIterator=F,s.async=function(Q,V,k,ve,_e){_e===void 0&&(_e=Promise);var Ae=new F(y(Q,V,k,ve),_e);return s.isGeneratorFunction(V)?Ae:Ae.next().then(function(Ue){return Ue.done?Ue.value:Ae.next()})};function P(Q,V,k){var ve=w;return function(_e,Ae){if(ve===R)throw new Error("Generator is already running");if(ve===G){if(_e==="throw")throw Ae;return Ke()}for(k.method=_e,k.arg=Ae;;){var Ue=k.delegate;if(Ue){var ce=W(Ue,k);if(ce){if(ce===x)continue;return ce}}if(k.method==="next")k.sent=k._sent=k.arg;else if(k.method==="throw"){if(ve===w)throw ve=G,k.arg;k.dispatchException(k.arg)}else k.method==="return"&&k.abrupt("return",k.arg);ve=R;var re=A(Q,V,k);if(re.type==="normal"){if(ve=k.done?G:b,re.arg===x)continue;return{value:re.arg,done:k.done}}else re.type==="throw"&&(ve=G,k.method="throw",k.arg=re.arg)}}}function W(Q,V){var k=V.method,ve=Q.iterator[k];if(ve===d)return V.delegate=null,k==="throw"&&Q.iterator.return&&(V.method="return",V.arg=d,W(Q,V),V.method==="throw")||k!=="return"&&(V.method="throw",V.arg=new TypeError("The iterator does not provide a '"+k+"' method")),x;var _e=A(ve,Q.iterator,V.arg);if(_e.type==="throw")return V.method="throw",V.arg=_e.arg,V.delegate=null,x;var Ae=_e.arg;if(!Ae)return V.method="throw",V.arg=new TypeError("iterator result is not an object"),V.delegate=null,x;if(Ae.done)V[Q.resultName]=Ae.value,V.next=Q.nextLoc,V.method!=="return"&&(V.method="next",V.arg=d);else return Ae;return V.delegate=null,x}j(H),T(H,f,"Generator"),T(H,u,function(){return this}),T(H,"toString",function(){return"[object Generator]"});function ee(Q){var V={tryLoc:Q[0]};1 in Q&&(V.catchLoc=Q[1]),2 in Q&&(V.finallyLoc=Q[2],V.afterLoc=Q[3]),this.tryEntries.push(V)}function I(Q){var V=Q.completion||{};V.type="normal",delete V.arg,Q.completion=V}function X(Q){this.tryEntries=[{tryLoc:"root"}],Q.forEach(ee,this),this.reset(!0)}s.keys=function(Q){var V=Object(Q),k=[];for(var ve in V)k.push(ve);return k.reverse(),function _e(){for(;k.length;){var Ae=k.pop();if(Ae in V)return _e.value=Ae,_e.done=!1,_e}return _e.done=!0,_e}};function te(Q){if(Q){var V=Q[u];if(V)return V.call(Q);if(typeof Q.next=="function")return Q;if(!isNaN(Q.length)){var k=-1,ve=function _e(){for(;++k<Q.length;)if(a.call(Q,k))return _e.value=Q[k],_e.done=!1,_e;return _e.value=d,_e.done=!0,_e};return ve.next=ve}}return{next:Ke}}s.values=te;function Ke(){return{value:d,done:!0}}return X.prototype={constructor:X,reset:function(Q){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(I),!Q)for(var V in this)V.charAt(0)==="t"&&a.call(this,V)&&!isNaN(+V.slice(1))&&(this[V]=d)},stop:function(){this.done=!0;var Q=this.tryEntries[0],V=Q.completion;if(V.type==="throw")throw V.arg;return this.rval},dispatchException:function(Q){if(this.done)throw Q;var V=this;function k(re,Ge){return Ae.type="throw",Ae.arg=Q,V.next=re,Ge&&(V.method="next",V.arg=d),!!Ge}for(var ve=this.tryEntries.length-1;ve>=0;--ve){var _e=this.tryEntries[ve],Ae=_e.completion;if(_e.tryLoc==="root")return k("end");if(_e.tryLoc<=this.prev){var Ue=a.call(_e,"catchLoc"),ce=a.call(_e,"finallyLoc");if(Ue&&ce){if(this.prev<_e.catchLoc)return k(_e.catchLoc,!0);if(this.prev<_e.finallyLoc)return k(_e.finallyLoc)}else if(Ue){if(this.prev<_e.catchLoc)return k(_e.catchLoc,!0)}else if(ce){if(this.prev<_e.finallyLoc)return k(_e.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(Q,V){for(var k=this.tryEntries.length-1;k>=0;--k){var ve=this.tryEntries[k];if(ve.tryLoc<=this.prev&&a.call(ve,"finallyLoc")&&this.prev<ve.finallyLoc){var _e=ve;break}}_e&&(Q==="break"||Q==="continue")&&_e.tryLoc<=V&&V<=_e.finallyLoc&&(_e=null);var Ae=_e?_e.completion:{};return Ae.type=Q,Ae.arg=V,_e?(this.method="next",this.next=_e.finallyLoc,x):this.complete(Ae)},complete:function(Q,V){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"&&V&&(this.next=V),x},finish:function(Q){for(var V=this.tryEntries.length-1;V>=0;--V){var k=this.tryEntries[V];if(k.finallyLoc===Q)return this.complete(k.completion,k.afterLoc),I(k),x}},catch:function(Q){for(var V=this.tryEntries.length-1;V>=0;--V){var k=this.tryEntries[V];if(k.tryLoc===Q){var ve=k.completion;if(ve.type==="throw"){var _e=ve.arg;I(k)}return _e}}throw new Error("illegal catch attempt")},delegateYield:function(Q,V,k){return this.delegate={iterator:te(Q),resultName:V,nextLoc:k},this.method==="next"&&(this.arg=d),x}},s}(l.exports);try{regeneratorRuntime=n}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}})($v);var Pd={exports:{}};(function(l){(function(n,s){l.exports?l.exports=s():n.log=s()})(__,function(){var n=function(){},s="undefined",i=typeof window!==s&&typeof window.navigator!==s&&/Trident\/|MSIE /.test(window.navigator.userAgent),a=["trace","debug","info","warn","error"];function e(b,R){var G=b[R];if(typeof G.bind=="function")return G.bind(b);try{return Function.prototype.bind.call(G,b)}catch{return function(){return Function.prototype.apply.apply(G,[b,arguments])}}}function d(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function _(b){return b==="debug"&&(b="log"),typeof console===s?!1:b==="trace"&&i?d:console[b]!==void 0?e(console,b):console.log!==void 0?e(console,"log"):n}function u(b,R){for(var G=0;G<a.length;G++){var x=a[G];this[x]=G<b?n:this.methodFactory(x,b,R)}this.log=this.debug}function g(b,R,G){return function(){typeof console!==s&&(u.call(this,R,G),this[b].apply(this,arguments))}}function f(b,R,G){return _(b)||g.apply(this,arguments)}function T(b,R,G){var x=this,me;R=R??"WARN";var O="loglevel";typeof b=="string"?O+=":"+b:typeof b=="symbol"&&(O=void 0);function $(H){var j=(a[H]||"silent").toUpperCase();if(!(typeof window===s||!O)){try{window.localStorage[O]=j;return}catch{}try{window.document.cookie=encodeURIComponent(O)+"="+j+";"}catch{}}}function de(){var H;if(!(typeof window===s||!O)){try{H=window.localStorage[O]}catch{}if(typeof H===s)try{var j=window.document.cookie,F=j.indexOf(encodeURIComponent(O)+"=");F!==-1&&(H=/^([^;]+)/.exec(j.slice(F))[1])}catch{}return x.levels[H]===void 0&&(H=void 0),H}}function fe(){if(!(typeof window===s||!O)){try{window.localStorage.removeItem(O);return}catch{}try{window.document.cookie=encodeURIComponent(O)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}x.name=b,x.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},x.methodFactory=G||f,x.getLevel=function(){return me},x.setLevel=function(H,j){if(typeof H=="string"&&x.levels[H.toUpperCase()]!==void 0&&(H=x.levels[H.toUpperCase()]),typeof H=="number"&&H>=0&&H<=x.levels.SILENT){if(me=H,j!==!1&&$(H),u.call(x,H,b),typeof console===s&&H<x.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+H},x.setDefaultLevel=function(H){R=H,de()||x.setLevel(H,!1)},x.resetLevel=function(){x.setLevel(R,!1),fe()},x.enableAll=function(H){x.setLevel(x.levels.TRACE,H)},x.disableAll=function(H){x.setLevel(x.levels.SILENT,H)};var N=de();N==null&&(N=R),x.setLevel(N,!1)}var y=new T,A={};y.getLogger=function(b){if(typeof b!="symbol"&&typeof b!="string"||b==="")throw new TypeError("You must supply a name when creating a logger.");var R=A[b];return R||(R=A[b]=new T(b,y.getLevel(),y.methodFactory)),R};var w=typeof window!==s?window.log:void 0;return y.noConflict=function(){return typeof window!==s&&window.log===y&&(window.log=w),y},y.getLoggers=function(){return A},y.default=y,y})})(Pd);var Ct=Pd.exports;const Sn=()=>`${new Date().toISOString()} | metrics`,An=(l,n,s)=>`${l} | ${n} | ${s}`;Ct.setDefaultLevel(Ct.levels.TRACE);const Vv=l=>{Ct.info(An(Sn(),"log ",`set log level to ${l?"verbose":"info"}`)),Ct.setLevel(l?Ct.levels.TRACE:Ct.levels.INFO)},Bv=l=>{const n=[...Object.keys(Ct.levels)];n.includes(l)?(Ct.info(An(Sn(),"log ",`update log level to ${l.toLowerCase()}`)),Ct.setLevel(l)):Ct.warn(An(Sn(),"log ","Incorrect log level please choose one of "),n)},Ne=(l,n,s)=>{s?Ct.debug(An(Sn(),l,n),s):Ct.debug(An(Sn(),l,n))},lu=(l,n)=>{Ct.info(An(Sn(),l,n))},as=(l,n)=>{Ct.info(An(Sn(),l,n))},Il=(l,n)=>{Ct.warn(An(Sn(),l,n))},Ws=(l,n)=>{Ct.error(An(Sn(),l,n))};function Kv(l){return Math.floor(Math.random()*l).toString()}function xd(l,n){let s=n;return l.forEach(i=>{s=s.replace(i,"")}),s}function Gv(l,n){let s="";for(let i=0;i<n;i+=1)s+=l[Kv(l.length)];return s}function Wv({length:l=20,useLetters:n=!0,useNumbers:s=!0,includeSymbols:i=[],excludeSymbols:a=[]}={}){let e="abcdefghijklmnopqrstuvwxyz",d="0123456789",_=[],u=[],g=[];return n&&(a.length&&(e=xd(a,e)),u=e.split("")),s&&(a.length&&(d=xd(a,d)),g=d.split("")),_=[...u,...g,...i],Gv(_,l)}var Yv=Wv;const Dr=We(Yv),zv=()=>"WebRTCMetrics",Jv=()=>"5.0.3",Pe={INBOUND:"inbound",OUTBOUND:"outbound"},Cn={IDLE:"idle",RUNNING:"running",MUTED:"muted"},kr={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Xv=()=>({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:[]}),Ld={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:Pe.INBOUND},Hd={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:Pe.OUTBOUND},qd={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:Pe.INBOUND},Fd={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:Pe.OUTBOUND},Qv=l=>{const n={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(l){const s={...l,audio:{},video:{},data:{...l.data},network:{...l.network},experimental:{...l.experimental}};return Object.keys(l.audio).forEach(i=>{s.audio[i]={...l.audio[i]}}),Object.keys(l.video).forEach(i=>{s.video[i]={...l.video[i]}}),s}return{...n,audio:{},video:{},data:{...n.data},network:{...n.network},experimental:{...n.experimental}}},Zv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Dr()}`,cid:`c-${Dr()}`,uid:`u-${Dr()}`,record:!1,ticket:!0},Yt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},D={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Ur={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},au={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},se={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},uu="config ",ey=(l,n={},s)=>{const i={...s,...n};return n.pname||Il(uu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${s.pname}'`),n.cid||Il(uu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${s.cid}'`),n.uid||Il(uu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${s.uid}'`),i.pc=l,i},ty=(l={})=>{const n={...Zv,...l};return n.name=zv(),n.version=Jv(),n},Mr=(l,n,s,i=!1,a)=>{let e=l.map(d=>{if(!s)return d[n];if(!a)return d[n][s];const _=d[n][a];return _?_[s]:null});return e=e.filter(d=>i?Number.isFinite(d)&&d>0:Number.isFinite(d)),e.length===0?[]:e},Jn=l=>l.reduce((n,s)=>n+s,0)/l.length,ny=()=>`probe-${Dr()}`,sy=()=>`coltr-${Dr()}`,jd=l=>new Promise(n=>setTimeout(n,l)),cu=(l,n,s)=>{n?l.call(n,s):l(s)},Ye=(l,n,s,i)=>{const a=Mr(l,n,s,!0,i);if(a.length===0)return null;const e=a.reduce((d,_)=>d+_,0)/a.length;return e===0?null:a.map(d=>Math.abs(e-d)).reduce((d,_)=>d+_,0)/a.length*100/e},Xe=(l,n,s,i=!1,a)=>{const e=Mr(l,n,s,i,a);return e.length===0?null:e.reduce((d,_)=>d+_,0)/e.length},us=(l,n,s)=>Mr(l,n,s).reduce((i,a)=>i+a,0),ze=(l,n,s,i)=>{const a=Mr(l,n,s,!0,i);return a.length===0?null:Math.min(...a)},Je=(l,n,s,i)=>{const a=Mr(l,n,s,!1,i);return a.length===0?null:Math.max(...a)},St=(l,n,s,i)=>{const a=l.slice().pop();if(!a)return null;if(!s)return a[n];if(!i)return a[n][s];const e=a[n][i];return e?e[s]:null},ry=l=>l.slice().pop(),ht=(l,n,s)=>{if(!n)return null;const i={};let a=n[D.AUDIO][l];a||(a=s===Pe.INBOUND?{...Ld}:{...Hd}),i[D.AUDIO]=a;let e=n[D.VIDEO][l];return e||(e=s===Pe.INBOUND?{...qd}:{...Fd}),i[D.VIDEO]=e,i},Pr="exporter ",iy="2.0",$d=(l,n,s)=>{if(!l||l.length===0)return 0;const i=l[l.length-1];if(!i)return 0;const a=i[n][s];if(a){const e=a.total_rtt_ms_out,d=a.total_rtt_measure_out;return!d||!e?Xe(l,n,"delta_rtt_ms_out",!1,s):Number(e/d)}return null},oy=(l,n)=>{if(!l||l.length===0)return 0;const s=l[l.length-1];if(!s)return 0;const i=s[n].total_rtt_connectivity_ms,a=s[n].total_rtt_connectivity_measure;return!a||!i?Xe(l,n,"delta_rtt_connectivity_ms"):Number(i/a)},ly=l=>St(l,"network","local_candidate_type")!=="relay"?`direct/${St(l,"network","local_candidate_protocol")}`:`turn/${St(l,"network","local_candidate_relay_protocol")}`,ay=l=>{const n=St(l,"network","remote_candidate_type"),s=St(l,"network","remote_candidate_protocol");return n!=="relay"?`direct/${s}`:`turn/${s}`};class uy{constructor(n){this._start=null,this._end=null,this._cfg=n,this._referenceReport=null,this._reports=[],this._events=[]}start(){lu(Pr,"start() - start exporter...");const n=new Date;return this._start=n.toJSON(),n}stop(){lu(Pr,"stop() - stop exporter...");const n=new Date;return this._end=n.toJSON(),n}saveReferenceReport(n){this._referenceReport=n}getReferenceReport(){return this._referenceReport}addReport(n){this._cfg.ticket&&(Ne(Pr,`addReport() - add report to exporter at ${n.timestamp}`),this._reports.push(n))}addCustomEvent(n){this._events.push(n)}reset(){lu(Pr,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Ne(Pr,"ticket() - generate ticket");const n=St(this._reports,"audio","total_packets_lost_in"),s=St(this._reports,"audio","total_packets_in"),i=St(this._reports,"video","total_packets_lost_in"),a=St(this._reports,"video","total_packets_in"),e={},d=ry(this._reports);return d&&(Object.keys(d[D.AUDIO]).forEach(_=>{const u=d[D.AUDIO][_];if(e[u.ssrc]={type:D.AUDIO,direction:u.direction},u.direction===Pe.INBOUND){const g={avg:Xe(this._reports,D.AUDIO,"delta_jitter_ms_in",!1,_),min:ze(this._reports,D.AUDIO,"delta_jitter_ms_in",_),max:Je(this._reports,D.AUDIO,"delta_jitter_ms_in",_),volatility:Ye(this._reports,D.AUDIO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},f={avg:Xe(this._reports,D.AUDIO,"delta_kbs_in",!1,_),min:ze(this._reports,D.AUDIO,"delta_kbs_in",_),max:Je(this._reports,D.AUDIO,"delta_kbs_in",_),volatility:Ye(this._reports,D.AUDIO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,D.AUDIO,"delta_KBytes_in",!1,_),min:ze(this._reports,D.AUDIO,"delta_KBytes_in",_),max:Je(this._reports,D.AUDIO,"delta_KBytes_in",_),volatility:Ye(this._reports,D.AUDIO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y={emodel:{avg:Xe(this._reports,D.AUDIO,"mos_emodel_in",!1,_),min:ze(this._reports,D.AUDIO,"mos_emodel_in",_),max:Je(this._reports,D.AUDIO,"mos_emodel_in",_),volatility:Ye(this._reports,D.AUDIO,"mos_emodel_in",_)},effective:{avg:Xe(this._reports,D.AUDIO,"mos_in",!1,_),min:ze(this._reports,D.AUDIO,"mos_in",_),max:Je(this._reports,D.AUDIO,"mos_in",_),volatility:Ye(this._reports,D.AUDIO,"mos_in",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},A=St(this._reports,D.AUDIO,"total_packets_lost_in",_),w=St(this._reports,D.AUDIO,"total_packets_in",_),b={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].mos=y,e[_].traffic=T,e[_].bitrate=f,e[_].loss=b}else{const g={avg:Xe(this._reports,D.AUDIO,"delta_jitter_ms_out",!1,_),min:ze(this._reports,D.AUDIO,"delta_jitter_ms_out",_),max:Je(this._reports,D.AUDIO,"delta_jitter_ms_out",_),volatility:Ye(this._reports,D.AUDIO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},f={avg:Xe(this._reports,D.AUDIO,"delta_kbs_out",!1,_),min:ze(this._reports,D.AUDIO,"delta_kbs_out",_),max:Je(this._reports,D.AUDIO,"delta_kbs_out",_),volatility:Ye(this._reports,D.AUDIO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,D.AUDIO,"delta_KBytes_out",!1,_),min:ze(this._reports,D.AUDIO,"delta_KBytes_out",_),max:Je(this._reports,D.AUDIO,"delta_KBytes_out",_),volatility:Ye(this._reports,D.AUDIO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},y={avg:$d(this._reports,D.AUDIO,_),min:ze(this._reports,D.AUDIO,"delta_rtt_ms_out",_),max:Je(this._reports,D.AUDIO,"delta_rtt_ms_out",_),volatility:Ye(this._reports,D.AUDIO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},A=St(this._reports,D.AUDIO,"total_packets_lost_out",_),w=St(this._reports,D.AUDIO,"total_packets_out",_),b={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},R={emodel:{avg:Xe(this._reports,D.AUDIO,"mos_emodel_out",!1,_),min:ze(this._reports,D.AUDIO,"mos_emodel_out",_),max:Je(this._reports,D.AUDIO,"mos_emodel_out",_),volatility:Ye(this._reports,D.AUDIO,"mos_emodel_out",_)},effective:{avg:Xe(this._reports,D.AUDIO,"mos_out",!1,_),min:ze(this._reports,D.AUDIO,"mos_out",_),max:Je(this._reports,D.AUDIO,"mos_out",_),volatility:Ye(this._reports,D.AUDIO,"mos_out",_)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};e[_].jitter=g,e[_].rtt=y,e[_].traffic=T,e[_].bitrate=f,e[_].loss=b,e[_].mos=R}}),Object.keys(d[D.VIDEO]).forEach(_=>{const u=d[D.VIDEO][_];if(e[_]={type:D.VIDEO,direction:u.direction},u.direction===Pe.INBOUND){const g={avg:Xe(this._reports,D.VIDEO,"delta_jitter_ms_in",!1,_),min:ze(this._reports,D.VIDEO,"delta_jitter_ms_in",_),max:Je(this._reports,D.VIDEO,"delta_jitter_ms_in",_),volatility:Ye(this._reports,D.VIDEO,"delta_jitter_ms_in",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},f={avg:Xe(this._reports,D.VIDEO,"delta_kbs_in",!1,_),min:ze(this._reports,D.VIDEO,"delta_kbs_in",_),max:Je(this._reports,D.VIDEO,"delta_kbs_in",_),volatility:Ye(this._reports,D.VIDEO,"delta_kbs_in",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,D.VIDEO,"delta_KBytes_in",!1,_),min:ze(this._reports,D.VIDEO,"delta_KBytes_in",_),max:Je(this._reports,D.VIDEO,"delta_KBytes_in",_),volatility:Ye(this._reports,D.VIDEO,"delta_KBytes_in",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y=St(this._reports,D.VIDEO,"total_packets_lost_in",_),A=St(this._reports,D.VIDEO,"total_packets_in",_),w={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].traffic=T,e[_].bitrate=f,e[_].loss=w}else{const g={avg:Xe(this._reports,D.VIDEO,"delta_jitter_ms_out",!1,_),min:ze(this._reports,D.VIDEO,"delta_jitter_ms_out",_),max:Je(this._reports,D.VIDEO,"delta_jitter_ms_out",_),volatility:Ye(this._reports,D.VIDEO,"delta_jitter_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},f={avg:Xe(this._reports,D.VIDEO,"delta_kbs_out",!1,_),min:ze(this._reports,D.VIDEO,"delta_kbs_out",_),max:Je(this._reports,D.VIDEO,"delta_kbs_out",_),volatility:Ye(this._reports,D.VIDEO,"delta_kbs_out",_),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,D.VIDEO,"delta_KBytes_out",!1,_),min:ze(this._reports,D.VIDEO,"delta_KBytes_out",_),max:Je(this._reports,D.VIDEO,"delta_KBytes_out",_),volatility:Ye(this._reports,D.VIDEO,"delta_KBytes_out",_),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},y={avg:$d(this._reports,D.VIDEO,_),min:ze(this._reports,D.VIDEO,"delta_rtt_ms_out",_),max:Je(this._reports,D.VIDEO,"delta_rtt_ms_out",_),volatility:Ye(this._reports,D.VIDEO,"delta_rtt_ms_out",_),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},A=St(this._reports,D.VIDEO,"total_packets_lost_out",_),w=St(this._reports,D.VIDEO,"total_packets_out",_),b={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};e[_].jitter=g,e[_].rtt=y,e[_].traffic=T,e[_].bitrate=f,e[_].loss=b}})),{version:iy,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:e,data:{rtt:{avg:oy(this._reports,"data"),min:ze(this._reports,"data","delta_rtt_connectivity_ms"),max:Je(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((n/(n+s)*100||0)*100)/100}},video:{in:{avg:Math.round((i/(i+a)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min:ze(this._reports,"data","delta_kbs_in"),max:Je(this._reports,"data","delta_kbs_in"),volatility:Ye(this._reports,"data","delta_kbs_in")},out:{avg:Xe(this._reports,"data","delta_kbs_out"),min:ze(this._reports,"data","delta_kbs_out"),max:Je(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:Xe(this._reports,"data","delta_KBytes_in"),min:ze(this._reports,"data","delta_KBytes_in"),max:Je(this._reports,"data","delta_KBytes_in"),volatility:Ye(this._reports,"data","delta_KBytes_in")},out:{avg:Xe(this._reports,"data","delta_KBytes_out"),min:ze(this._reports,"data","delta_KBytes_out"),max:Je(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:ly(this._reports),remoteConnection:ay(this._reports)}}}}updateConfig(n){this._cfg=n}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const n=this._reports.slice();return n.pop(),n.pop()||null}getReportsNumber(){return this._reports.length}}const Xn="extractor ",Vd=(l,n,s,i)=>{let a=!1;const e=i[n].total_rtt_ms_out,d=i[n].total_rtt_measure_out,_=s?s[n].total_rtt_ms_out:0,u=s?s[n].total_rtt_measure_out:0,g={rtt:null,totalRTT:e,totalRTTMeasurements:d};if(l[q.TIMESTAMP]===i[n].timestamp_out||!Object.prototype.hasOwnProperty.call(l,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(l,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(l[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(l[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u===d))return g;const f=1e3*Number(l[q.ROUND_TRIP_TIME]);let T=e+f,y=d+1;return a&&(T=1e3*Number(l[q.TOTAL_ROUND_TRIP_TIME])-_,y=Number(l[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u),{rtt:f,totalRTT:T,totalRTTMeasurements:y}},cy=(l,n,s,i)=>{if(!Object.prototype.hasOwnProperty.call(l,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:i[n].total_rtt_connectivity_ms,totalRTTMeasurements:i[n].total_rtt_connectivity_measure};const a=1e3*Number(l[q.CURRENT_ROUND_TRIP_TIME]);let e=i[n].total_rtt_connectivity_ms+a,d=i[n].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(l,q.TOTAL_ROUND_TRIP_TIME)&&(e=1e3*Number(l[q.TOTAL_ROUND_TRIP_TIME])-(s?s[n].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(l,q.RESPONSES_RECEIVED)&&(d=Number(l[q.RESPONSES_RECEIVED])-(s?s[n].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:e,totalRTTMeasurements:d}},wl=(l,n,s)=>l[q.TIMESTAMP]===s[n].timestamp_out||!Object.prototype.hasOwnProperty.call(l,q.JITTER)?null:1e3*(Number(l[q.JITTER])||0),hy=(l,n)=>{if(!Object.prototype.hasOwnProperty.call(l,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(l,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:n[D.VIDEO].delta_ms_decode_frame_in,frames_decoded:n[D.VIDEO].total_frames_decoded_in,total_decode_time:n[D.VIDEO].total_time_decoded_in};const s=l[q.FRAMES_DECODED],i=l[q.TOTAL_DECODE_TIME],a=i-n[D.VIDEO].total_time_decoded_in,e=s-n[D.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:e>0?a*1e3/e:0,frames_decoded:s,total_decode_time:i}},dy=(l,n)=>{if(!Object.prototype.hasOwnProperty.call(l,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(l,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:n[D.VIDEO].delta_ms_encode_frame_out,frames_encoded:n[D.VIDEO].total_frames_encoded_out,total_encode_time:n[D.VIDEO].total_time_encoded_out};const s=l[q.FRAMES_ENCODED],i=l[q.TOTAL_ENCODE_TIME],a=i-n[D.VIDEO].total_time_encoded_out,e=s-n[D.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:e>0&&a?a*1e3/e:0,frames_encoded:s,total_encode_time:i}},Bd=(l,n,s,i)=>{if(!Object.prototype.hasOwnProperty.call(l,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(l,q.BYTES_SENT))return{packetsSent:s[n].total_packets_out,packetsLost:s[n].total_packets_lost_out,bytesSent:s[n].total_KBytes_out};const a=Number(l[q.PACKETS_SENT])||0-(i?i[n].total_packets_out:0),e=a-s[n].total_packets_out,d=Number(l[q.BYTES_SENT])/1024-(i?i[n].total_KBytes_out:0),_=d-s[n].total_KBytes_out,u=l[q.TIMESTAMP]||Date.now(),g=i?i.timestamp:null;let f=s.timestamp;!f&&g&&(f=g);const T=f?u-f:0,y=T>0?_*.008*1024/T*1e3:0;return{packetsSent:a,deltaPacketsSent:e,KBytesSent:d,deltaKBytesSent:_,kbsSent:y}},Kd=(l,n,s,i)=>{let a=s[n].total_packets_lost_out,e=0,d=0;return Object.prototype.hasOwnProperty.call(l,q.PACKETS_LOST)&&(a=Number(l[q.PACKETS_LOST])||0-(i?i[n].total_packets_lost_out:0),e=a-s[n].total_packets_lost_out),Object.prototype.hasOwnProperty.call(l,q.FRACTION_LOST)&&(d=Number(100*l[q.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:e,fractionLost:d}},Gd=(l,n,s,i)=>{if(!Object.prototype.hasOwnProperty.call(l,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(l,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(l,q.BYTES_RECEIVED))return{percent_packets_lost:s[n].percent_packets_lost_in,packetsReceived:s[n].total_packets_in,packetsLost:s[n].total_packets_lost_in,bytesReceived:s[n].total_KBytes_in};const a=Number(l[q.PACKETS_RECEIVED])||0-(i?i[n].total_packets_in:0),e=Number(l[q.PACKETS_LOST])||0-(i?i[n].total_packets_lost_in:0),d=e-s[n].total_packets_lost_in,_=a-s[n].total_packets_in,u=a!==s[n].total_packets_in?d*100/(d+_):0,g=Number(l[q.BYTES_RECEIVED])/1024-(i?i[n].total_KBytes_in:0),f=g-s[n].total_KBytes_in,T=l[q.TIMESTAMP]||Date.now(),y=i?i.timestamp:null;let A=s.timestamp;!A&&y&&(A=y);const w=A?T-A:0,b=w>0?f*.008*1024/w*1e3:0;return{percentPacketsLost:u,packetsReceived:a,deltaPacketsReceived:_,packetsLost:e,deltaPacketsLost:d,KBytesReceived:g,deltaKBytesReceived:f,kbsReceived:b}},_y=l=>l[q.CANDIDATE_TYPE]!=="relay"?"":l[q.RELAY_PROTOCOL]||"",py=l=>{if(!Object.prototype.hasOwnProperty.call(l,q.NETWORK_TYPE))return Ur.WIFI;switch(l[q.NETWORK_TYPE]){case au.ETHERNET:return Ur.ETHERNET;case au.CELLULAR_4G:return Ur.CELLULAR_4G;case au.WIFI:return Ur.WIFI;default:return Ur.CELLULAR}},Wd=l=>!Object.prototype.hasOwnProperty.call(l,q.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(l,q.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:l[q.FRAME_WIDTH]||null,height:l[q.FRAME_HEIGHT]||null,framerate:l[q.FRAMES_PER_SECOND]},fy=l=>{const n=Object.prototype.hasOwnProperty.call(l,q.QUALITY_LIMITATION_REASON)?l[q.QUALITY_LIMITATION_REASON]:null,s=Object.prototype.hasOwnProperty.call(l,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?l[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,i=Object.prototype.hasOwnProperty.call(l,q.QUALITY_LIMITATION_DURATIONS)?l[q.QUALITY_LIMITATION_DURATIONS]:null;return i&&Object.keys(i).forEach(a=>{i[a]>1e3&&(i[a]=Number(i[a]/1e3))}),{reason:n,durations:i,resolutionChanges:s}},my=(l,n,s)=>{if(!Object.prototype.hasOwnProperty.call(l,q.PLI)||!Object.prototype.hasOwnProperty.call(l,q.NACK))return{pliCount:n.total_pli_sent_in,nackCount:n.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const i=(l[q.PLI]||0)-(s?s[D.VIDEO].total_pli_sent_in:0),a=(l[q.NACK]||0)-(s?s[D.VIDEO].total_nack_sent_in:0);return{pliCount:i,nackCount:a,deltaPliCount:i-n[D.VIDEO].total_pli_sent_in,deltaNackCount:a-n[D.VIDEO].total_nack_sent_in}},gy=(l,n,s)=>{if(!Object.prototype.hasOwnProperty.call(l,q.PLI)||!Object.prototype.hasOwnProperty.call(l,q.NACK))return{pliCount:n.total_pli_received_out,nackCount:n.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const i=(l[q.PLI]||0)-(s?s[D.VIDEO].total_pli_received_out:0),a=(l[q.NACK]||0)-(s?s[D.VIDEO].total_nack_received_out:0);return{pliCount:i,nackCount:a,deltaPliCount:i-n[D.VIDEO].total_pli_received_out,deltaNackCount:a-n[D.VIDEO].total_nack_received_out}},Ty=l=>({channels:l[q.CHANNELS]||null,clock_rate:l[q.CLOCK_RATE]||null,mime_type:l[q.MIME_TYPE]||null,sdp_fmtp_line:l[q.SDP_FMTP_LINE]||null}),vy=l=>({clock_rate:l[q.CLOCK_RATE]||null,mime_type:l[q.MIME_TYPE]||null}),yy=(l,n,s)=>{const i=(l[q.BYTES_RECEIVED]||0)/1024-(s?s.data.total_KBytes_in:0),a=(l[q.BYTES_SENT]||0)/1024-(s?s.data.total_KBytes_out:0),e=l[q.TIMESTAMP]||Date.now(),d=i-n.data.total_KBytes_in,_=a-n.data.total_KBytes_out,u=s?s.timestamp:null;let g=n.timestamp;!g&&u&&(g=u);const f=g?e-g:0,T=f>0?d*.008*1024/f*1e3:0,y=f>0?_*.008*1024/f*1e3:0;return{total_KBytes_received:i,total_KBytes_sent:a,delta_KBytes_received:d,delta_KBytes_sent:_,kbs_speed_received:T,kbs_speed_sent:y}},Ey=l=>{const n=l[q.AVAILABLE_INCOMING_BITRATE]/1024||0,s=l[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:n,kbs_outgoing_bandwidth:s}},Sy=(l,n,s,i)=>{if(!l)return[];switch(l[q.TYPE]){case Yt.CANDIDATE_PAIR:let a=!1;if(l[q.NOMINATED]&&l[q.STATE]===D.SUCCEEDED&&(a=!0,Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l),q.SELECTED in l&&!l[q.SELECTED]&&(a=!1)),a){const d=l[q.LOCAL_CANDIDATE_ID],_=l[q.REMOTE_CANDIDATE_ID],u=yy(l,n,i),g=Ey(l),f=cy(l,"data",i,n);return[{type:se.NETWORK,value:{local_candidate_id:d}},{type:se.NETWORK,value:{remote_candidate_id:_}},{type:se.DATA,value:{total_KBytes_in:u.total_KBytes_received}},{type:se.DATA,value:{total_KBytes_out:u.total_KBytes_sent}},{type:se.DATA,value:{delta_KBytes_in:u.delta_KBytes_received}},{type:se.DATA,value:{delta_KBytes_out:u.delta_KBytes_sent}},{type:se.DATA,value:{delta_kbs_in:u.kbs_speed_received}},{type:se.DATA,value:{delta_kbs_out:u.kbs_speed_sent}},{type:se.DATA,value:{delta_kbs_bandwidth_in:g.kbs_incoming_bandwidth}},{type:se.DATA,value:{delta_kbs_bandwidth_out:g.kbs_outgoing_bandwidth}},{type:se.DATA,value:{delta_rtt_connectivity_ms:f.rtt}},{type:se.DATA,value:{total_rtt_connectivity_ms:f.totalRTT}},{type:se.DATA,value:{total_rtt_connectivity_measure:f.totalRTTMeasurements}}]}break;case Yt.LOCAL_CANDIDATE:if(l[q.ID]===n.network.local_candidate_id)return[{type:se.NETWORK,value:{infrastructure:py(l)}},{type:se.NETWORK,value:{local_candidate_type:l[q.CANDIDATE_TYPE]||""}},{type:se.NETWORK,value:{local_candidate_protocol:l[q.PROTOCOL]||""}},{type:se.NETWORK,value:{local_candidate_relay_protocol:_y(l)}}];break;case Yt.REMOTE_CANDIDATE:if(l[q.ID]===n.network.remote_candidate_id)return[{type:se.NETWORK,value:{remote_candidate_type:l[q.CANDIDATE_TYPE]||""}},{type:se.NETWORK,value:{remote_candidate_protocol:l[q.PROTOCOL]||""}}];break;case Yt.INBOUND_RTP:{Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);const d=l[q.SSRC],_=ht(d,n,Pe.INBOUND);_&&(_.timestamp=n.timestamp);const u=ht(d,i,Pe.INBOUND);if(u&&(u.timestamp=i.timestamp),l[q.MEDIA_TYPE]===D.AUDIO){const g=Gd(l,D.AUDIO,_,u),f=wl(l,D.AUDIO,_),T=l[q.CODEC_ID]||"";return[{ssrc:d,type:se.AUDIO,value:{codec_id_in:T}},{ssrc:d,type:se.AUDIO,value:{total_packets_in:g.packetsReceived}},{ssrc:d,type:se.AUDIO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:d,type:se.AUDIO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:d,type:se.AUDIO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:d,type:se.AUDIO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:d,type:se.AUDIO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:d,type:se.AUDIO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:d,type:se.AUDIO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:d,type:se.AUDIO,value:{delta_jitter_ms_in:f}}]}if(l[q.MEDIA_TYPE]===D.VIDEO){const g=hy(l,_),f=Gd(l,D.VIDEO,_,u),T=wl(l,D.VIDEO,_),y=l[q.DECODER_IMPLEMENTATION]||null,A=l[q.CODEC_ID]||null,w=Wd(l),b=my(l,_,u);return[{ssrc:d,type:se.VIDEO,value:{codec_id_in:A}},{ssrc:d,type:se.VIDEO,value:{total_packets_in:f.packetsReceived}},{ssrc:d,type:se.VIDEO,value:{delta_packets_in:f.deltaPacketsReceived}},{ssrc:d,type:se.VIDEO,value:{total_packets_lost_in:f.packetsLost}},{ssrc:d,type:se.VIDEO,value:{delta_packets_lost_in:f.deltaPacketsLost}},{ssrc:d,type:se.VIDEO,value:{percent_packets_lost_in:f.percentPacketsLost}},{ssrc:d,type:se.VIDEO,value:{total_KBytes_in:f.KBytesReceived}},{ssrc:d,type:se.VIDEO,value:{delta_KBytes_in:f.deltaKBytesReceived}},{ssrc:d,type:se.VIDEO,value:{delta_kbs_in:f.kbsReceived}},{ssrc:d,type:se.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:d,type:se.VIDEO,value:{decoder_in:y}},{ssrc:d,type:se.VIDEO,value:{delta_ms_decode_frame_in:g.delta_ms_decode_frame}},{ssrc:d,type:se.VIDEO,value:{total_frames_decoded_in:g.frames_decoded}},{ssrc:d,type:se.VIDEO,value:{total_time_decoded_in:g.total_decode_time}},{ssrc:d,type:se.VIDEO,value:{total_nack_sent_in:b.nackCount}},{ssrc:d,type:se.VIDEO,value:{delta_nack_sent_in:b.deltaNackCount}},{ssrc:d,type:se.VIDEO,value:{total_pli_sent_in:b.pliCount}},{ssrc:d,type:se.VIDEO,value:{delta_pli_sent_in:b.deltaPliCount}},{ssrc:d,type:se.VIDEO,value:{size_in:w}}]}break}case Yt.OUTBOUND_RTP:{Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);const d=l[q.SSRC],_=ht(d,n,Pe.OUTBOUND);_&&(_.timestamp=n.timestamp);const u=ht(d,i,Pe.OUTBOUND);if(u&&(u.timestamp=i.timestamp),l[q.MEDIA_TYPE]===D.AUDIO){const g=l[q.CODEC_ID]||null,f=Bd(l,D.AUDIO,_,u);return[{ssrc:d,type:se.AUDIO,value:{codec_id_out:g}},{ssrc:d,type:se.AUDIO,value:{total_packets_out:f.packetsSent}},{ssrc:d,type:se.AUDIO,value:{delta_packets_out:f.deltaPacketsSent}},{ssrc:d,type:se.AUDIO,value:{total_KBytes_out:f.KBytesSent}},{ssrc:d,type:se.AUDIO,value:{delta_KBytes_out:f.deltaKBytesSent}},{ssrc:d,type:se.AUDIO,value:{delta_kbs_out:f.kbsSent}}]}if(l[q.MEDIA_TYPE]===D.VIDEO){const g=l[q.ENCODER_IMPLEMENTATION]||null,f=l[q.CODEC_ID]||null,T=dy(l,_),y=Wd(l),A=fy(l),w=gy(l,_,u),b=Bd(l,D.VIDEO,_,u);return[{ssrc:d,type:se.VIDEO,value:{codec_id_out:f}},{ssrc:d,type:se.VIDEO,value:{total_packets_out:b.packetsSent}},{ssrc:d,type:se.VIDEO,value:{delta_packets_out:b.deltaPacketsSent}},{ssrc:d,type:se.VIDEO,value:{total_KBytes_out:b.KBytesSent}},{ssrc:d,type:se.VIDEO,value:{delta_KBytes_out:b.deltaKBytesSent}},{ssrc:d,type:se.VIDEO,value:{delta_kbs_out:b.kbsSent}},{ssrc:d,type:se.VIDEO,value:{encoder_out:g}},{ssrc:d,type:se.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:d,type:se.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:d,type:se.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:d,type:se.VIDEO,value:{total_nack_received_out:w.nackCount}},{ssrc:d,type:se.VIDEO,value:{delta_nack_received_out:w.deltaNackCount}},{ssrc:d,type:se.VIDEO,value:{total_pli_received_out:w.pliCount}},{ssrc:d,type:se.VIDEO,value:{delta_pli_received_out:w.deltaPliCount}},{ssrc:d,type:se.VIDEO,value:{size_out:y}},{ssrc:d,type:se.VIDEO,value:{limitation_out:A}}]}break}case Yt.MEDIA_SOURCE:{Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);break}case Yt.TRACK:{Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);break}case Yt.CODEC:const e=[];return Object.keys(n[D.AUDIO]).forEach(d=>{const _=n[D.AUDIO][d];if(_.codec_id_in===l[q.ID]||_.codec_id_out===l[q.ID]){Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);const u=Ty(l);l[q.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:se.AUDIO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:se.AUDIO,value:{codec_out:u}})}}),Object.keys(n[D.VIDEO]).forEach(d=>{const _=n[D.VIDEO][d];if(_.codec_id_in===l[q.ID]||_.codec_id_out===l[q.ID]){Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);const u=vy(l);l[q.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:se.VIDEO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:se.VIDEO,value:{codec_out:u}})}}),e;case Yt.REMOTE_INBOUND_RTP:{Ne(Xn,`analyze() - got stats ${l[q.TYPE]} for ${s}`,l);const d=l[q.SSRC],_=ht(d,n,Pe.OUTBOUND),u=ht(d,i,Pe.OUTBOUND);if(l[q.KIND]===D.AUDIO){const g=Vd(l,D.AUDIO,u,_),f=wl(l,D.AUDIO,_),T=Kd(l,D.AUDIO,_,u);return[{ssrc:d,type:se.AUDIO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:se.AUDIO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:se.AUDIO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:se.AUDIO,value:{delta_jitter_ms_out:f}},{ssrc:d,type:se.AUDIO,value:{timestamp_out:l[q.TIMESTAMP]}},{ssrc:d,type:se.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:se.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:se.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(l[q.KIND]===D.VIDEO){const g=Vd(l,D.VIDEO,u,_),f=wl(l,D.VIDEO,_),T=Kd(l,D.VIDEO,_,u);return[{ssrc:d,type:se.VIDEO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:se.VIDEO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:se.VIDEO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:se.VIDEO,value:{delta_jitter_ms_out:f}},{ssrc:d,type:se.VIDEO,value:{timestamp_out:l[q.TIMESTAMP]}},{ssrc:d,type:se.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:se.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:se.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ol=l=>l<0?1:l>100?4.5:1+.035*l+7/1e6*l*(l-60)*(100-l),Ay=(l,n=D.AUDIO,s,i,a)=>{const e=ht(a,l,Pe.INBOUND),d=ht(a,s,Pe.INBOUND),_=ht(a,i,Pe.INBOUND),u=[],g=[],f=e[n].percent_packets_lost_in,T=e[n].delta_jitter_ms_in,y=d&&d[n].delta_jitter_ms_in||null,A=_&&_[n].delta_jitter_ms_in||null,w=l.data.delta_rtt_connectivity_ms,b=s&&s.data.delta_rtt_connectivity_ms||null,R=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),b&&u.push(b),R&&u.push(R),T&&g.push(T),s&&y&&g.push(y),i&&A&&g.push(A);const G=u.length>0?Jn(u):100,x=g.length>0?Jn(g):10,me=93.2-f,O=.18*me*me-27.9*me+1126.62,$=(G+x)/2,de=$-177.3<0?0:1,fe=.024*$+.11*($-177.3)*de,N=O-fe;return Ol(N)},Cy=(l,n=D.AUDIO,s,i,a)=>{const e=ht(a,l,Pe.OUTBOUND),d=ht(a,s,Pe.OUTBOUND),_=ht(a,i,Pe.OUTBOUND),u=[],g=[],f=e[n].percent_packets_lost_out,T=e[n].delta_rtt_ms_out,y=d&&d[n].delta_rtt_ms_out||null,A=_&&_[n].delta_rtt_ms_out||null,w=e[n].delta_jitter_ms_out,b=d&&d[n].delta_jitter_ms_out||null,R=_&&_[n].delta_jitter_ms_out||null,G=l.data.delta_rtt_connectivity_ms,x=s&&s.data.delta_rtt_connectivity_ms||null,me=i&&i.data.delta_rtt_connectivity_ms||null;T?u.push(T):G&&u.push(G),y?u.push(y):x&&u.push(x),A?u.push(A):me&&u.push(me),w&&g.push(w),s&&b&&g.push(b),i&&R&&g.push(R);const O=u.length>0?Jn(u):100,$=g.length>0?Jn(g):10,de=93.2-f,fe=.18*de*de-27.9*de+1126.62,N=(O+$)/2,H=N-177.3<0?0:1,j=.024*N+.11*(N-177.3)*H,F=fe-j;return Ol(F)},by=(l,n=D.AUDIO,s,i,a)=>{const e=ht(a,l,Pe.INBOUND),d=ht(a,s,Pe.INBOUND),_=ht(a,i,Pe.INBOUND),u=[],g=[],f=e[n].percent_packets_lost_in/100,T=e[n].delta_jitter_ms_in,y=d&&d[n].delta_jitter_ms_in||null,A=_&&_[n].delta_jitter_ms_in||null,w=l.data.delta_rtt_connectivity_ms,b=s&&s.data.delta_rtt_connectivity_ms||null,R=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),b&&u.push(b),R&&u.push(R),T&&g.push(T),d&&y&&g.push(y),_&&A&&g.push(A);const G=u.length>0?Jn(u):100,x=g.length>0?Jn(g):10,me=0,O=19.8,$=29.7,de=30,fe=(G+x)/2+de,N=fe-177.3<0?0:1,H=.024*fe+.11*(fe-177.3)*N,j=93.2-(me+O*Math.log(1+$*f)+H);return Ol(j)},Ry=(l,n=D.AUDIO,s,i,a)=>{const e=ht(a,l,Pe.OUTBOUND),d=ht(a,s,Pe.OUTBOUND),_=ht(a,i,Pe.OUTBOUND),u=[],g=[],f=e[n].percent_packets_lost_out/100,T=e[n].delta_rtt_ms_out,y=d&&d[n].delta_rtt_ms_out||null,A=_&&_[n].delta_rtt_ms_out||null,w=e[n].delta_jitter_ms_out,b=d&&d[n].delta_jitter_ms_out||null,R=_&&_[n].delta_jitter_ms_out||null,G=l.data.delta_rtt_connectivity_ms,x=s&&s.data.delta_rtt_connectivity_ms||null,me=i&&i.data.delta_rtt_connectivity_ms||null;T?u.push(T):G&&u.push(G),y?u.push(y):x&&u.push(x),A?u.push(A):me&&u.push(me),w&&g.push(w),d&&b&&g.push(b),_&&R&&g.push(R);const O=u.length>0?Jn(u):100,$=g.length>0?Jn(g):10,de=0,fe=19.8,N=29.7,H=30,j=(O+$)/2+H,F=j-177.3<0?0:1,P=.024*j+.11*(j-177.3)*F,W=93.2-(de+fe*Math.log(1+N*f)+P);return Ol(W)};class Iy{constructor(n,s){this._callbacks={onreport:null,onticket:null},this._id=sy(),this._moduleName=this._id,this._probeId=s,this._config=n,this._exporter=new uy(n),this._state=Cn.IDLE,this.registerToPCEvents(),as(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(n,s,i,a){const e=(u,g)=>u===D.AUDIO?g===Yt.INBOUND_RTP?{...Ld}:{...Hd}:g===Yt.INBOUND_RTP?{...qd}:{...Fd},d=Qv(s);d.pname=this._config.pname,d.call_id=this._config.cid,d.user_id=this._config.uid,d.count=s?s.count+1:1;let _=null;return n.forEach(u=>{!_&&u.timestamp&&(_=u.timestamp),Sy(u,d,d.pname,a).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let f=d[g.type][g.ssrc];f||(f=e(g.type,u.type),f.ssrc=g.ssrc,d[g.type][g.ssrc]=f),Object.keys(g.value).forEach(T=>{f[T]=g.value[T]})}else Object.keys(g.value).forEach(f=>{d[g.type][f]=g.value[f]})})}),d.timestamp=_,Object.keys(d[D.AUDIO]).forEach(u=>{const g=d[D.AUDIO][u];g.direction===Pe.INBOUND?(g.mos_emodel_in=Ay(d,D.AUDIO,s,i,g.ssrc),g.mos_in=by(d,D.AUDIO,s,i,g.ssrc)):(g.mos_emodel_out=Cy(d,D.AUDIO,s,i,g.ssrc),g.mos_out=Ry(d,D.AUDIO,s,i,g.ssrc))}),d}async takeReferenceStats(){return new Promise((n,s)=>{const i=Date.now();setTimeout(async()=>{try{const a=Date.now()-i,e=Date.now(),d=await this._config.pc.getStats(),_=this.analyze(d,null,null,null),u=Date.now();_.experimental.time_to_measure_ms=u-e,_.experimental.time_to_wait_ms=a,this._exporter.saveReferenceReport(_),Ne(this._moduleName,`got reference report for probe ${this._probeId}`),n()}catch(a){s(a)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==Cn.RUNNING||!this._config.pc)return Ne(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const n=Date.now(),s=await this._config.pc.getStats(),i=this.analyze(s,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),a=Date.now();return i.experimental.time_to_measure_ms=a-n,this._exporter.addReport(i),Ne(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(i),i}catch(n){return Ws(this._moduleName,`got error ${n}`),null}}async start(){Ne(this._moduleName,"starting"),this.state=Cn.RUNNING,this._startedTime=this._exporter.start(),Ne(this._moduleName,"started")}async mute(){this.state=Cn.MUTED,Ne(this._moduleName,"muted")}async unmute(){this.state=Cn.RUNNING,Ne(this._moduleName,"unmuted")}async stop(n){if(Ne(this._moduleName,`stopping${n?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=Cn.IDLE,this._config.ticket){const{ticket:s}=this._exporter;this.fireOnTicket(s)}this._exporter.reset(),Ne(this._moduleName,"stopped")}registerCallback(n,s,i){n in this._callbacks?(this._callbacks[n]={callback:s,context:i},Ne(this._moduleName,`registered callback '${n}'`)):Ws(this._moduleName,`can't register callback for '${n}' - not found`)}unregisterCallback(n){n in this._callbacks?(this._callbacks[n]=null,delete this._callbacks[n],Ne(this._moduleName,`unregistered callback '${n}'`)):Ws(this._moduleName,`can't unregister callback for '${n}' - not found`)}fireOnReport(n){this._callbacks.onreport&&cu(this._callbacks.onreport.callback,this._callbacks.onreport.context,n)}fireOnTicket(n){this._callbacks.onticket&&cu(this._callbacks.onticket.callback,this._callbacks.onticket.context,n)}updateConfig(n){this._config=n,this._exporter.updateConfig(n)}get state(){return this._state}set state(n){this._state=n,Ne(this._moduleName,`state changed to ${n}`)}addCustomEvent(n,s,i,a){this._exporter.addCustomEvent({at:typeof n=="object"?n.toJSON():n,category:s,name:i,description:a})}async registerToPCEvents(){const{pc:n}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const s=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${s.length} devices found`,"Media Devices state")}catch{Ws(this._moduleName,"can't get devices")}},n){n.oniceconnectionstatechange=()=>{const i=n.iceConnectionState;i===kr.CONNECTED||i===kr.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===kr.DISCONNECTED||i===kr.FAILED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===kr.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},n.onicegatheringstatechange=()=>{const i=n.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",i,"ICE gathering state")},n.ontrack=i=>{this.addCustomEvent(new Date().toJSON(),"call",`${i.track.kind}track`,"MediaStreamTrack received")},n.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const s=n.getReceivers();if(s&&s.length>0){const i=s[0],{transport:a}=i;if(a){const{iceTransport:e}=a;e&&(e.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class wy{constructor(n){this._id=n.pname&&n.pname.substr(0,12).padEnd(12," ")||ny(),this._moduleName=this._id,as(this._moduleName,"probe created"),this._config=n,this._collector=new Iy(this._config,this._id)}set onreport(n){n?this._collector.registerCallback("onreport",n):this._collector.unregisterCallback("onreport")}set onticket(n){n?this._collector.registerCallback("onticket",n):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(n){this._collector.state=n}addCustomEvent(n,s,i,a=new Date().toJSON()){this._collector.addCustomEvent(a,s,n,i)}get isRunning(){return this._collector.state===Cn.RUNNING}get isIdle(){return this._collector.state===Cn.IDLE}updateUserId(n){this._config.uid=n,this._collector.updateConfig(this._config)}updateCallId(n){this._config.cid=n,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Il(this._moduleName,"probe is already running");return}this._collector.start()}stop(n=!1){this.isRunning&&this._collector.stop(n)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const bt="engine ";class Oy{constructor(n){this._config=n,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},as(bt,`configured for probing every ${this._config.refreshEvery}ms`),as(bt,`configured for starting after ${this._config.startAfter}ms`),as(bt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Ne(bt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(n=>n.isRunning)}get isIdle(){return this._probes.every(n=>n.isIdle)}addNewProbe(n,s){if(!n)throw new Error("undefined peer connection");const i=ey(n,s,this._config),a=new wy(i);return this._probes.push(a),Ne(bt,`${this._probes.length} probes registered`),a}removeExistingProbe(n){if(!n)throw new Error("undefined probe");n.state===Cn.RUNNING&&n.stop(),this._probes=this._probes.filter(s=>n.id!==s.id)}async start(){const n=()=>{this._probes.forEach(e=>e.start())},s=async()=>Promise.all(this._probes.map(e=>e.takeReferenceStats())),i=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,a=async()=>{const e=Xv(),d=this._probes.filter(_=>_.isRunning);for(const _ of d){const u=await _.collectStats();u&&e.probes.push(u),Ne(bt,`got probe ${_.id}`),await jd(0)}return e.delta_time_to_measure_probes_ms=us(e.probes,"experimental","time_to_measure_ms"),e.delta_KBytes_in=us(e.probes,"data","delta_KBytes_in"),e.delta_KBytes_out=us(e.probes,"data","delta_KBytes_out"),e.delta_kbs_in=us(e.probes,"data","delta_kbs_in"),e.delta_kbs_out=us(e.probes,"data","delta_kbs_out"),e.total_time_decoded_in=us(e.probes,"video","total_time_decoded_in"),e.total_time_encoded_out=us(e.probes,"video","total_time_encoded_out"),e};for(Ne(bt,"starting to collect"),n(),Ne(bt,"generating reference reports..."),await s(),Ne(bt,"reference reports generated"),this._startedTime=Date.now();i();)if(Ne(bt,`wait ${this._config.refreshEvery}ms before collecting`),await jd(this._config.refreshEvery),i()){Ne(bt,"collecting...");const e=Date.now(),d=await a(),_=Date.now();d.delta_time_consumed_to_measure_ms=_-e,this.fireOnReports(d),Ne(bt,"collected")}Ne(bt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(n){const s=i=>{this._probes.forEach(a=>{a.stop(i)})};as(bt,"stop collecting"),s(n)}registerCallback(n,s,i){n in this._callbacks?(this._callbacks[n]={callback:s,context:i},Ne(bt,`registered callback '${n}'`)):Ws(bt,`can't register callback for '${n}' - not found`)}unregisterCallback(n){n in this._callbacks?(this._callbacks[n]=null,delete this._callbacks[n],Ne(this._moduleName,`unregistered callback '${n}'`)):Ws(this._moduleName,`can't unregister callback for '${n}' - not found`)}fireOnReports(n){this._callbacks.onresult&&n.probes.length>0&&cu(this._callbacks.onresult.callback,this._callbacks.onresult.context,n)}}const Ny="interface ";class Dy{constructor(n){this._config=ty(n),as(Ny,`welcome to ${this._config.name} version ${this._config.version}`),Vv(this._config.verbose||!1),this._engine=new Oy(this._config)}setupLogLevel(n){Bv(n)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(n,s){return this._engine.addNewProbe(n,s)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(n){this._engine.removeExistingProbe(n)}set onresult(n){n?this._engine.registerCallback("onresult",n):this._engine.unregisterCallback("onresult")}}function ky(l,n){return Object.keys(l).filter(s=>n.includes(s)).reduce((s,i)=>{const a=i;return{...s,[a]:l[a]}},{})}const Uy=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"],My={positiveSpeechThreshold:.6,negativeSpeechThreshold:.3,preSpeechPadMs:150,redemptionMs:1500,minSpeechMs:50};class Py{constructor(n){this.intervals={},this.analysers={},this.emitInterval=n.emitInterval||200,this.onChangeFunction=n.onChangeFunction}async start(n,s,i){s&&s.getTracks().length&&await this.beginCalculation(n,s,i)}stop(n){this.clearVolumeInterval(n),this.analysers[n]&&typeof this.analysers[n].disconnect=="function"&&(this.analysers[n].disconnect(),delete this.analysers[n])}clearVolumeInterval(n){this.intervals[n]&&(clearInterval(this.intervals[n]),delete this.intervals[n])}clearAllIntervals(){Object.keys(this.intervals).forEach(n=>{this.stop(n)}),this.intervals={},this.analysers={}}async beginCalculation(n,s,i){this.clearVolumeInterval(i);const a=n.createAnalyser(),e=n.createMediaStreamSource(s);a.smoothingTimeConstant=.8,a.fftSize=1024,e.connect(a),this.analysers[i]=a,this.intervals[i]=setInterval(()=>{const d=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(d);let _=0;const u=d.length;for(let f=0;f<u;f++)_+=d[f];const g=_/u;this.onChangeFunction(i,g)},this.emitInterval)}}class xy{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(n=>{throw this.resumePromise=null,n})),await this.resumePromise),this.context}}const Nl={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Ly=0;class Hy{constructor(n){var s;if(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 xy,this.context=n,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new Py({onChangeFunction:this.emitVolumeChange.bind(this)}),this.processVADConfiguration(),this.initializeMediaDevices(),["enabled","dynamic"].includes(this.noiseReduction.mode)){const i=(s=this.context.options.configuration)==null?void 0:s.vadModule;i&&i.MicVAD?(this.MicVAD=i.MicVAD,console.log("✅ VAD module loaded successfully")):(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.vadModule option."),this.noiseReduction.mode="disabled")}}processVADConfiguration(){var n;const s=((n=this.context.options.configuration)==null?void 0:n.noiseReductionOptions)||{};this.noiseReduction={mode:s.mode||"disabled",checkEveryMs:s.checkEveryMs||500,noiseCheckInterval:s.noiseCheckInterval||2e3,noiseThreshold:s.noiseThreshold||.004,vadConfig:s.vadConfig||{}}}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(n){this.currentActiveRoomIdValue=n,this.context.emit("currentActiveRoomChanged",n)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(n){this.isCallAddingInProgress=n,this.context.emit("callAddingInProgressChanged",n)}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(n=>!n.incomingInProgress).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(n=>n.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(n=>n.kind==="audiooutput")}get getUserMediaConstraints(){return Ud()?{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(n){this.availableMediaDevices=n,this.context.emit("changeAvailableDeviceList",n)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const n=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(n)}async initializeMediaDevices(){const n=localStorage.getItem(Nl.SELECTED_INPUT_DEVICE)||"default",s=localStorage.getItem(Nl.SELECTED_OUTPUT_DEVICE)||"default";try{const i=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),a=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(a),await this.setMicrophone(n),await this.setSpeaker(s),navigator.mediaDevices.addEventListener("devicechange",async()=>{const e=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(e)}),i.getTracks().forEach(e=>e.stop())}catch(i){console.error(i)}}async cleanupConferenceNodes(n){const s=this.conferenceNodes[n];if(!s)return;let i=0;s.sources.forEach((d,_)=>{try{d.disconnect(),i++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting source ${_}:`,u)}});let a=0;s.destinations.forEach((d,_)=>{try{d.disconnect(),a++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting destination ${_}:`,u)}});let e=0;s.gains.forEach((d,_)=>{try{d.disconnect(),e++}catch(u){console.error(`[cleanupConferenceNodes] Error disconnecting gain ${_}:`,u)}}),delete this.conferenceNodes[n]}setCallTime(n){const s={...n};delete s.callId,this.callTime={...this.callTime,[n.callId]:s},this.context.emit("changeCallTime",this.callTime)}removeCallTime(n){const s={...this.callTime};delete s[n],this.callTime={...s},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(n,s){this.timeIntervals={...this.timeIntervals,[n]:s}}removeTimeInterval(n){const s={...this.timeIntervals};s[n]&&(clearInterval(s[n]),delete s[n],this.timeIntervals={...s})}stopCallTimer(n){this.removeTimeInterval(n),this.removeCallTime(n)}emitVolumeChange(n,s){this.context.emit("changeCallVolume",{callId:n,volume:s})}setMetricsConfig(n){this.metricConfig={...this.metricConfig,...n}}sendDTMF(n,s){if(!/^[A-D0-9*#]+$/g.test(s))throw new Error("Not allowed character used in the DTMF input");this.extendedCalls[n].sendDTMF(s)}setIsMuted(n){this.muted=n,this.context.emit("changeIsMuted",n)}processMute(n){const s=this.currentActiveRoomId;this.setIsMuted(n),this.initialStreamValue.getTracks().forEach(i=>i.enabled=!n),this.roomReconfigure(s)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:n,toHold:s,automatic:i}){const a=this.extendedCalls[n];if(!a)return;a._automaticHold=i??!1;const e=new Promise((d,_)=>{const u=setTimeout(()=>{_(new Error("Hold operation timeout"))},5e3),g=()=>{clearTimeout(u),a.putOnHoldTimestamp=s?Date.now():void 0,d()},f=T=>{clearTimeout(u),_(T)};try{s?(this.stopSessionVad(a._id),a.hold({},g)):a.unhold({},g)}catch(T){f(T)}});try{await e,this.updateCall(a);const d=Object.values(this.extendedCalls).filter(_=>_.roomId===a.roomId&&(s?n!==_._id:!0));d.length>1&&await this.doConference(d)}catch(d){throw console.error("Hold operation failed:",d),d}}holdCall(n,s=!1){return this.processHold({callId:n,automatic:s,toHold:!0})}unholdCall(n){return this.processHold({callId:n,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(n=>n.direction==="outgoing"&&n.status===Ly).forEach(n=>this.terminateCall(n._id))}answerCall(n){const s=this.extendedCalls[n];this.cancelAllOutgoingUnanswered(),s.answer(this.sipOptions),this.updateCall(s),this.setActiveRoom(s.roomId),s.connection.addEventListener("track",i=>{this.triggerAddStream(i,s)})}async moveCall(n,s){this.updateCallStatus({callId:n,isMoving:!0}),await this.processRoomChange({callId:n,roomId:s}),this.updateCallStatus({callId:n,isMoving:!1})}updateCall(n){this.activeCalls[n._id]=Dd(n),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(n){const s={...this.activeRooms[n.roomId],...n};this.activeRooms={...this.activeRooms,[n.roomId]:{...s}},this.context.emit("updateRoom",{room:s,roomList:this.activeRooms})}hasAutoAnswerHeaders(n){const s=/answer-after=0/,i=n.request.getHeader("Call-Info");return i&&s.test(i)}addCall(n,s=!0){this.activeCalls={...this.activeCalls,[n._id]:Dd(n)},this.extendedCalls[n._id]=n,s&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(n){this.callStatus={...this.callStatus,[n]:{isMoving:!1,isTransferring:!1,isMerging:!1,isTransferred:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(n){const s={...this.callStatus[n.callId]};n.isMoving!==void 0&&(s.isMoving=n.isMoving),n.isTransferring!==void 0&&(s.isTransferring=n.isTransferring),n.isMerging!==void 0&&(s.isMerging=n.isMerging),n.isTransferred!==void 0&&(s.isTransferred=n.isTransferred),this.callStatus={...this.callStatus,[n.callId]:{...s}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(n){const s={...this.callStatus};delete s[n],this.callStatus={...s},this.context.emit("changeCallStatus",this.callStatus)}addRoom(n){this.activeRooms={...this.activeRooms,[n.roomId]:n},this.context.emit("addRoom",{room:n,roomList:this.activeRooms})}async setupActiveStream(){const n=await ru(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);n.getTracks().forEach(s=>s.enabled=!this.isMuted),await this.setActiveStream(n)}async getActiveStream(){const n=await ru(await this.managedAudioContext.getContext(),this.initialStreamValue,this.microphoneInputLevel*2);return n.getTracks().forEach(s=>s.enabled=!this.isMuted),await this.setActiveStream(n),n}async setMicrophone(n){if(!this.getInputDeviceList.find(({deviceId:i})=>i===n)||(this.setSelectedInputDevice(n),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const s=Object.values(this.extendedCalls).filter(i=>i.roomId===this.currentActiveRoomId);s.length===1?Object.values(s).forEach(async i=>{await this.setupActiveStream();const a=this.activeStream;i.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(i)}):await this.doConference(s)}async setActiveStream(n){this.activeStream&&this.stopVUMeter("origin"),await this.setupVUMeter(n,"origin"),this.activeStreamValue=n,this.context.emit("changeActiveStream",n)}async setSpeaker(n){if(!this.getOutputDeviceList.find(({deviceId:a})=>a===n))return;this.setSelectedOutputDevice(n);const s=Object.values(this.extendedCalls);if(s.length===0)return;const i=s.filter(a=>a.roomId===this.currentActiveRoomId);i.length===1?s.forEach(a=>{var e;(e=a.audioTag)==null||e.setSinkId(n),this.updateCall(a)}):await this.doConference(i)}removeRoom(n){const s={...this.activeRooms},i={...s[n]};delete s[n],this.activeRooms={...s},this.context.emit("removeRoom",{room:i,roomList:this.activeRooms})}deleteRoomIfEmpty(n){n!==void 0&&Object.values(this.extendedCalls).filter(s=>s.roomId===n).length===0&&(this.removeRoom(n),this.currentActiveRoomId===n&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(n){this.muted?n.mute({audio:!0}):n.unmute({audio:!0})}startNoiseMonitor({sessionId:n,stream:s,onNoiseDetected:i,onNoiseStop:a}){const e=new AudioContext,d=e.createMediaStreamSource(s.clone()),_=e.createAnalyser();_.fftSize=1024;const u=new Float32Array(_.fftSize);d.connect(_);const g=[];this.vadIntervals[n]&&(clearInterval(this.vadIntervals[n]),this.vadIntervals[n]=null),this.vadMrsIntervals[n]&&(clearInterval(this.vadMrsIntervals[n]),this.vadMrsIntervals[n]=null),this.vadMrsIntervals[n]=setInterval(()=>{_.getFloatTimeDomainData(u);const f=qv(u);g.push(f);const T=Math.ceil(this.noiseReduction.noiseCheckInterval/this.noiseReduction.checkEveryMs);g.length>T&&g.shift()},this.noiseReduction.checkEveryMs),this.vadIntervals[n]=setInterval(()=>{if(g.length===0)return;const f=g.reduce((A,w)=>A+w,0)/g.length,T=this.vadSessionsState[n],y=f>this.noiseReduction.noiseThreshold;T.isSpeaking||(y&&T.currentMode==="clean"?(T.currentMode="noisy",console.log("Average noise high → enable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:n,enabled:!0}),i()):!y&&T.currentMode==="noisy"&&(T.currentMode="clean",console.log("Average noise low → disable VAD"),this.context.emit("changeNoiseReductionState",{sessionId:n,enabled:!1}),a()))},this.noiseReduction.noiseCheckInterval)}async processVAD(n,s){const i=s.clone();this.stopSessionVad(n._id),this.vadSessionsState[n._id]={currentMode:"clean",isSpeaking:!1};const a=await this.managedAudioContext.getContext(),e=await Fv(i,a,150);let d=!1;const _=await this.MicVAD.new({getStream:()=>new Promise(u=>u(i)),...My,...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(!d){if(d=!0,console.log("✅ VAD initialized, starting background noise monitoring"),this.noiseReduction.mode==="enabled"){n.connection.getSenders()[0]&&n.connection.getSenders()[0].replaceTrack(e.stream.getAudioTracks()[0]);return}this.startNoiseMonitor({sessionId:n._id,stream:i,onNoiseDetected:async()=>{var u;console.log("Replace track with Vad Controlled"),await((u=n.connection.getSenders()[0])==null?void 0:u.replaceTrack(e.stream.getAudioTracks()[0]))},onNoiseStop:async()=>{const u=n.connection.getSenders()[0];u&&u.track&&u.transport&&u.transport.state!=="closed"&&u.transport.state!=="failed"&&(console.log("Replace track with Original"),await u.replaceTrack(i.getAudioTracks()[0]))}})}},onSpeechStart:()=>{var u;console.log("🎤 Speech started"),e.setSpeaking(!0),this.noiseReduction.mode==="enabled"&&((u=n.connection.getSenders()[0])==null||u.replaceTrack(e.stream.getAudioTracks()[0])),this.vadSessionsState[n._id].isSpeaking=!0},onSpeechEnd:()=>{var u;console.log("🛑 Speech end"),e.setSpeaking(!1),this.noiseReduction.mode==="enabled"&&((u=n.connection.getSenders()[0])==null||u.replaceTrack(e.stream.getAudioTracks()[0])),this.vadSessionsState[n._id].isSpeaking=!1}});this.vadSessions[n._id]&&(this.vadSessions[n._id].pause(),delete this.vadSessions[n._id]),this.vadSessions[n._id]=_,_.start()}stopSessionVad(n){this.vadSessions[n]&&(this.vadSessions[n].pause(),delete this.vadSessions[n]),this.vadIntervals[n]&&(clearInterval(this.vadIntervals[n]),delete this.vadIntervals[n]),this.vadMrsIntervals[n]&&(clearInterval(this.vadMrsIntervals[n]),delete this.vadMrsIntervals[n]),this.vadSessionsState[n]&&delete this.vadSessionsState[n]}async roomReconfigure(n){var s;if(n===void 0)return;const i=Object.values(this.extendedCalls).filter(e=>e.roomId===n),a=this.currentActiveRoomId===n;if(i.forEach((e,d)=>{if(e.audioTag){e.connection.getReceivers().forEach(u=>{u.track.enabled=!e.localMuted}),a&&this.muteReconfigure(e);const _=!a;e.audioTag.muted=_,this.updateCall(e)}}),i.length===0){this.conferenceNodes[n]&&await this.cleanupConferenceNodes(n),this.deleteRoomIfEmpty(n);return}if(i.length===1&&!a){const e=i[0];e.isOnHold().local||await this.holdCall(e._id,!0),this.conferenceNodes[n]&&await this.cleanupConferenceNodes(n);return}if(i.length===1&&a){const e=i[0];e.isOnHold().local&&e._automaticHold&&await this.unholdCall(e._id);const d=(((s=e.connection)==null?void 0:s.getSenders())||[])[0];if(e.connection&&d)try{await this.setupActiveStream();const _=this.activeStream;["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(i[0],_);const u=_.getTracks();await d.replaceTrack(u[0]),this.muteReconfigure(e)}catch(_){console.error(_)}this.conferenceNodes[n]&&await this.cleanupConferenceNodes(n);return}i.length>1&&await this.doConference(i)}async doConference(n){if(n.length===0)return;const s=n[0].roomId,i=this.currentActiveRoomId===s;if(n.find(_=>_.roomId!==s))return;const a=await this.managedAudioContext.getContext();if(a.state!=="running"){console.error(`[doConference] ERROR: AudioContext is not running! State: ${a.state}`);return}await this.cleanupConferenceNodes(s),this.conferenceNodes[s]={sources:new Map,destinations:new Map,gains:new Map};const e=this.conferenceNodes[s],d=new Map;n.forEach((_,u)=>{_&&_.connection&&_.connection.getReceivers().forEach((g,f)=>{var T,y,A;g.track.enabled=!_.localMuted;const w=(T=g.track)==null?void 0:T.id;(y=g.track)==null||y.readyState,(A=g.track)==null||A.kind;const b=`${_._id}-${w}`;g.track&&g.track.readyState==="live"&&d.set(b,g.track)})}),await this.setupActiveStream(),await jv.forEach(n,async(_,u)=>{if(!_||!_.connection)return;const g=a.createMediaStreamDestination();e.destinations.set(_._id,g);let f=0;if(d.forEach((A,w)=>{if(!w.startsWith(_._id))try{const b=a.createMediaStreamSource(new MediaStream([A])),R=a.createGain(),G=`${_._id}-${w}`;b.connect(R),R.connect(g),e.sources.set(G,b),e.gains.set(G,R),f++}catch(b){console.error(b)}}),i&&this.activeStreamValue)try{const A=this.activeStream,w=a.createMediaStreamSource(A),b=a.createGain(),R=`${_._id}-local`;w.connect(b),b.connect(g),e.sources.set(R,w),e.gains.set(R,b)}catch(A){console.error(A)}else i&&console.error(`Host room but no activeStreamValue - skipping host microphone for session ${_._id}`);const T=_.connection.getSenders()[0],y=g.stream.getTracks();if(["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(_,g.stream),T&&y[0])try{await T.replaceTrack(y[0]),this.muteReconfigure(_)}catch(A){console.error(A)}})}processCallerMute(n,s){const i=this.extendedCalls[n];i&&i.connection.getReceivers().length&&(i.localMuted=s,i.connection.getReceivers().forEach(a=>{a.track.enabled=!s}),this.updateCall(i))}muteCaller(n){this.processCallerMute(n,!0)}unmuteCaller(n){this.processCallerMute(n,!1)}terminateCall(n){const s=this.extendedCalls[n];s._status===4?s.terminate({status_code:603,reason_phrase:"Decline"}):s._status!==8&&s.terminate()}transferCall(n,s){if(s.toString().length===0)return new Error("Target must be passed");const i=this.extendedCalls[n];if(!i._is_confirmed&&!i._is_canceled){const a=`sip:${s}@${this.context.sipDomain}`;i.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${a}`]});return}this.updateCallStatus({callId:n,isTransferring:!0,isTransferred:!1}),i.refer(`sip:${s}@${this.context.sipDomain}`,{eventHandlers:{requestSucceeded:()=>{this.updateCallStatus({callId:n,isTransferring:!1,isTransferred:!0})},requestFailed:()=>{this.updateCallStatus({callId:n,isTransferring:!1,isTransferred:!1})}}}),this.updateCall(i)}mergeCall(n){const s=Object.values(this.extendedCalls).filter(e=>e.roomId===n);if(s.length!==2)return;const i=s[0],a=s[1];!i||!a||(this.updateCallStatus({callId:i._id,isMerging:!0}),this.updateCallStatus({callId:a._id,isMerging:!0}),i.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(i))}mergeCallByIds(n,s){const i=Object.values(this.extendedCalls).find(e=>e._id===n),a=Object.values(this.extendedCalls).find(e=>e._id===s);if(!i||!a)throw new Error("Call ID is not provided");this.updateCallStatus({callId:n,isMerging:!0}),this.updateCallStatus({callId:s,isMerging:!0}),i.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(i)}setDND(n){this.isDNDEnabled=n,this.context.emit("changeIsDND",n)}setCallWaiting(n){this.isCallWaitingEnabled=n,this.context.emit("changeIsCallWaiting",n)}startCallTimer(n){this.removeTimeInterval(n);const s={callId:n,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(s);const i=setInterval(()=>{const a={...this.callTime[n]},e=Hv(a);this.setCallTime({callId:n,...e})},1e3);this.setTimeInterval(n,i)}async setActiveRoom(n){const s=this.currentActiveRoomId;n!==s&&(this.currentActiveRoomId=n,await this.roomReconfigure(s),await this.roomReconfigure(n))}getNewRoomId(){const n=Object.keys(this.activeRooms);return n.length===0?1:parseInt(n.sort()[n.length-1])+1}async setupCall(n){var s,i;const a=n.session;if(this.getActiveCalls[a.id]!==void 0)return;const e=this.getNewRoomId(),d={started:new Date,incomingInProgress:!1,roomId:e};a.direction==="incoming"?(this.context.logger.log("New incoming call from",(i=(s=a._remote_identity)==null?void 0:s._uri)==null?void 0:i._user),d.incomingInProgress=!0,this.context.subscribe(Wt.CALL_CONFIRMED,f=>{a.id===f.id&&(this.updateRoom({incomingInProgress:!1,roomId:e}),this.startCallTimer(a.id))}),this.context.subscribe(Wt.CALL_FAILED,f=>{a.id===f.id&&(this.updateRoom({incomingInProgress:!1,roomId:e}),this.deleteRoomIfEmpty(e))})):a.direction==="outgoing"&&(a.once("confirmed",()=>{this.startCallTimer(a.id)}),this.startCallTimer(a.id));const _=a,u=this.hasAutoAnswerHeaders(n),g=_.direction==="incoming"&&!this.hasActiveCalls&&(u||this.autoAnswer);_.roomId=e,_.localMuted=!1,_.autoAnswer=g,g?this.addCall(_,!1):this.addCall(_),this.addCallStatus(a.id),this.addRoom(d),g&&this.answerCall(_._id)}removeCall(n){const s={...this.activeCalls};delete s[n],this.activeCalls={...s};const i={...this.extendedCalls};delete i[n],this.extendedCalls={...i},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(n){const s=this.extendedCalls[n._id];if(!s)return;this.stopVUMeter("origin"),this.stopVUMeter(n._id);const i=s.roomId;this.removeCall(n._id),this.roomReconfigure(i).then(()=>{}).catch(a=>{console.error("Error reconfiguring room after call removal:",a)})}shouldTerminateNewSession(n){if(n.session.direction==="outgoing")return!1;const s=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||s}async newRTCSessionCallback(n){const s=n.session;if(this.shouldTerminateNewSession(n)){s.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Wt.NEW_CALL,session:s,event:n}),s.on("ended",i=>{var a,e,d;this.stopVUMeter(s.id),this.context.logger.log("Session ended for",(e=(a=s._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Wt.CALL_ENDED,session:s,event:i}),["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(s._id);const _=this.getActiveCalls[s.id];_&&this.activeCallListRemove(_),this.stopCallTimer(s.id),this.removeCallStatus(s.id),this.removeCallMetrics(s.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(u=>u.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),s.on("progress",i=>{var a,e;this.context.logger.log("Session in progress for",(e=(a=s._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Wt.CALL_PROGRESS,session:s,event:i})}),s.on("failed",i=>{var a,e,d;this.stopVUMeter(s.id),this.context.logger.log("Session failed for",(e=(a=s._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Wt.CALL_FAILED,session:s,event:i}),["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.stopSessionVad(s._id),s.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const _=this.getActiveCalls[s.id];_&&this.activeCallListRemove(_),this.stopCallTimer(s.id),this.removeCallStatus(s.id),this.removeCallMetrics(s.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(u=>u.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),s.on("confirmed",i=>{var a,e;this.context.logger.log("Session confirmed for",(e=(a=s._remote_identity)==null?void 0:a._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Wt.CALL_CONFIRMED,session:s,event:i}),this.updateCall(s),s.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(n),s.direction==="outgoing"){const i=this.getActiveCalls[s.id].roomId;await this.setActiveRoom(i)}}setMuteWhenJoin(n){this.muteWhenJoinEnabled=n,this.context.emit("changeMuteWhenJoin",n)}setMicrophoneSensitivity(n){if(n<0||n>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=n,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(n){this.speakerVolumeValue=n,Object.values(this.extendedCalls).forEach(s=>{s.audioTag&&(s.audioTag.volume=n,this.updateCall(s))})}setAutoAnswer(n){this.isAutoAnswer=n}setSelectedInputDevice(n){localStorage.setItem(Nl.SELECTED_INPUT_DEVICE,n),this.selectedMediaDevices.input=n,this.context.emit("changeActiveInputMediaDevice",n)}setSelectedOutputDevice(n){localStorage.setItem(Nl.SELECTED_OUTPUT_DEVICE,n),this.selectedMediaDevices.output=n,this.context.emit("changeActiveOutputMediaDevice",n)}setCallMetrics(n){const s={...n};delete s.callId,this.callMetrics={...this.callMetrics,[n.callId]:s},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(n){const s={...this.callMetrics};delete s[n],this.callMetrics={...s},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(n){const s=new Dy(this.metricConfig),i=s.createProbe(n.connection,{cid:n._id}),a=[];let e;i.onreport=d=>{Object.entries(d.audio).forEach(([g,f])=>{f.direction==="inbound"&&!a.includes(g)&&(a.push(g),e=g)});const _=d.audio[e];if(!_)return;const u=ky(_,Uy);u.callId=n._id,this.setCallMetrics(u)},this.context.subscribe(Wt.CALL_ENDED,d=>{d._id===n._id&&s.stopAllProbes()}),s.startAllProbes()}async setupVUMeter(n,s){await this.VUMeter.start(await this.managedAudioContext.getContext(),n,s)}stopVUMeter(n){this.VUMeter.stop(n)}async setupStream(){try{const n=Date.now(),s=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach((i,a)=>{i.stop()}),this.initialStreamValue=null),this.initialStreamValue=s}catch(n){throw n}}async triggerAddStream(n,s){const i=this.muteWhenJoin||this.isMuted;this.setIsMuted(i),this.initialStreamValue||await this.setupStream();const a=await this.managedAudioContext.getContext(),e=await ru(a,this.initialStreamValue,this.microphoneInputLevel*2),d=this.isMuted||this.muteWhenJoin;e.getTracks().forEach(g=>{g.enabled=!d}),await this.setActiveStream(e),await s.connection.getSenders()[0].replaceTrack(e.getTracks()[0]);const _=new MediaStream([n.track]);!Object.values(this.extendedCalls).find(g=>g.audioTag&&g.audioTag.id===s._id)&&Av(_,s,this.selectedOutputDevice,this.speakerVolume);const u=s.roomId===this.currentActiveRoomId;s.audioTag&&(s.audioTag.muted=!u),await this.setupVUMeter(_,s._id),this.getCallQuality(s),this.updateCall(s),["enabled","dynamic"].includes(this.noiseReduction.mode)&&this.processVAD(s,e)}initCall(n,s,i=!1){if(n.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${n}@${this.context.sipDomain}...`);const a=this.context.call(`sip:${n}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=a.id,s&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:a.id,roomId:this.currentActiveRoomId}),i)){const e=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&d._id!==a.id);for(const d of e)this.holdCall(d._id,!0)}a.connection.addEventListener("track",e=>{this.triggerAddStream(e,a)})}async processRoomChange({callId:n,roomId:s}){const i=this.extendedCalls[n];if(!i)return;const a=i.roomId;i.roomId=s,this.updateCall(i),await this.roomReconfigure(a),await this.roomReconfigure(s)}}class qy{constructor(n){this.context=n}get sipOptions(){return{...this.context.options.sipOptions}}initCall(n,s){if(n.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${n}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${n}@${this.context.sipDomain}`,s,this.sipOptions)}stop(n={}){this.context.terminateJanusSessions(n)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(n){this.context.changeMediaConstraints(n)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class Fy{constructor(n){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=n,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(n){const s=this.extendedMessages[n];this.updateMSRPSession(s)}updateMSRPSession(n){this.activeMessages[n._id]=kd(n),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(n){this.activeMessages={...this.activeMessages,[n._id]:kd(n)},this.extendedMessages[n._id]=n,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(n,s){const i=this.msrpHistory[s.id]||[];i.push(n),this.msrpHistory={...this.msrpHistory,[s.id]:[...i]},this.context.emit("newMSRPMessage",{message:n,session:s})}messageTerminate(n){const s=this.extendedMessages[n];s._status!==8&&s.terminate()}addMessageSession(n){if(!n._id||this.getActiveMessages[n._id]!==void 0)return;const s=n;this.addMMSRPSession(s)}triggerMSRPListener({listenerType:n,session:s,event:i}){const a=this.context.listenersList[n];!a||!a.length||a.forEach(e=>{e(s,i)})}removeMMSRPSession(n){const s={...this.activeMessages};delete s[n],this.activeMessages={...s};const i={...this.extendedMessages};delete i[n],this.extendedMessages={...i},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(n){this.removeMMSRPSession(n._id)}newMSRPSessionCallback(n){const s=n.session;s.on("ended",i=>{this.triggerMSRPListener({listenerType:Wt.CALL_ENDED,session:s,event:i});const a=this.getActiveMessages[s.id];this.activeMessageListRemove(a)}),s.on("failed",i=>{this.triggerMSRPListener({listenerType:Wt.CALL_FAILED,session:s,event:i});const a=this.getActiveMessages[s.id];this.activeMessageListRemove(a)}),s.on("confirmed",i=>{this.triggerMSRPListener({listenerType:Wt.CALL_CONFIRMED,session:s,event:i}),this.updateMSRPSession(s)}),s.on("newMessage",i=>{this.addMSRPMessage(i,s)}),this.addMessageSession(s)}setIsMSRPInitializing(n){this.isMSRPInitializingValue=n,this.context.emit("isMSRPInitializingChanged",n)}initMSRP(n,s,i){if(n.length===0)return console.error("Target must be a valid string");const a=this.context.startMSRP(n,i);a.on("active",()=>{this.addMessageSession(a),a.sendMSRP(s),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(n,s){const i=this.extendedMessages[n];if(!i)throw new Error(`MSRP session with id ${n} doesn't exist!`);i.sendMSRP(s)}}const Dl={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class Yd{constructor(n){this.opensips=null,this.session=null,this.name=null,this.name=n}setOpensips(n){this.opensips=n}setSession(n){this.session=n}kill(){this.opensips.kill(this.name)}}class jy extends Yd{constructor(n,s){super(n),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=s}connect(n={}){this.opaqueId=this.session.generateOpaqueId();const s=ke.cloneArray(n.extraHeaders),i={from_tag:this.session._from_tag};n.fromUserName&&(i.from_uri=new ls("sip",n.fromUserName,this.session._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(i.from_display_name=n.fromDisplayName),s.push(`Contact: ${this.session._contact}`),s.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&s.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new gt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,i,s),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 n;this._connection.onicecandidate=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(n),n=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(n){n.forEach(s=>{this._connection.addTrack(s)})}async _sendInitialRequest(){const n=new yr(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const s={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(s),await this._connection.setLocalDescription(this.jsep_offer);const i={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},a=JSON.stringify(i);this._request.body=a,n.send()}_receiveInviteResponse(n){if(this._publisherSubscribeSent||!n.body)return;const s=JSON.parse(n.body);this.handleId=s.data.id;const i={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(Mt.PUBLISHER)];this.session.sendRequest(U.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async e=>{var d,_,u,g;if(e.status_code===200){if(this._subscribeSent=!0,e.body)try{const f=JSON.parse(e.body)||{};((_=(d=f.plugindata)==null?void 0:d.data)==null?void 0:_.videoroom)==="joined"&&this.session.myFeedList.push(f.plugindata.data.id),(g=(u=f.plugindata)==null?void 0:u.data)!=null&&g.publishers&&this.session.receivePublishers(f)}catch(f){console.error(f)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(n){const s=this._candidates.map(e=>({janus:"trickle",candidate:e,handle_id:this.handleId,session_id:this.session.session_id})),i={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...n},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...s]},a=["Content-Type: application/json",this.session.getPTypeHeader(Mt.ICE)];this.session.sendRequest(U.INFO,{extraHeaders:a,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async e=>{this._configureSent=!0;const d=e.data.split(`\r
159
+ `),_=d[d.length-1],u=JSON.parse(_);await this._connection.setRemoteDescription(u.jsep),this._candidates=[]}}})}_sendDetach(){const n={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},s=[this.session.getPTypeHeader(Mt.DETACH)];this.session.sendRequest(U.INFO,{extraHeaders:s,body:JSON.stringify(n)}),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 n=this._connection.getSenders();n.forEach(s=>{const i=s.track;i&&i.stop()}),n.forEach(s=>{this._connection.removeTrack(s)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class $y extends Yd{constructor(n,s,i={}){super(n),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=i.immediate||!1,this.type=s}start(n){return n}stop(){throw new Error("stop method is not implemented")}async process(n){if(this.immediate){const s=await this.start(n);return this.running=!0,s}return n}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 Vy extends mv{constructor(n,s){if(!n.modules.length)throw new Error("options.modules should include at least 1 module");const i={...n.configuration,sockets:n.socketInterfaces.map(a=>new Lv.WebSocketInterface(a))};super(i),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=[],n.pnExtraHeaders&&Object.keys(n.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(n.pnExtraHeaders),this.options=n,this.modules=n.modules,n.configuration.reconnectionAttemptsLimit&&(this.reconnectionAttemptsLimit=n.configuration.reconnectionAttemptsLimit),s&&Cv(s)&&(this.logger=s)}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(Dl.AUDIO)?this.audio.hasActiveAnsweredCalls:!1}on(n,s){return super.on(n,s)}off(n,s){return super.off(n,s)}emit(n,s){return super.emit(n,s)}get sipDomain(){return this.options.sipDomain}use(n){if(this.newStreamPlugins.find(s=>s.name===n.name)||this.processStreamPlugins.find(s=>s.name===n.name))throw new Error(`Plugin with name ${n.name} already exists`);if(n instanceof jy)n.setOpensips(this),this.newStreamPlugins.push(n);else if(n instanceof $y)n.setOpensips(this),this.processStreamPlugins.push(n);else throw new Error("Wrong plugin instance")}getPlugin(n){return this.newStreamPlugins.find(s=>s.name===n)||this.processStreamPlugins.find(s=>s.name===n)}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(Dl.AUDIO)&&(this.audio=new Hy(this)),this.modules.includes(Dl.MSRP)&&(this.msrp=new Fy(this)),this.modules.includes(Dl.VIDEO)&&(this.video=new qy(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(n,s){const i=!this.listenersList[n]||!this.listenersList[n].length?[s]:[...this.listenersList[n],s];this.listenersList={...this.listenersList,[n]:i}}removeIListener(n){const s={...this.listenersList};delete s[n],this.listenersList={...s}}triggerListener({listenerType:n,session:s,event:i}){const a=this.listenersList[n];!a||!a.length||a.forEach(e=>{e(s,i)})}setInitialized(n){this.initialized=n,this.emit("ready",n)}setConnected(n){this.connected=n,this.emit("connection",n)}setReconnecting(n){this.isReconnecting=n,this.emit("reconnecting",n)}}let Oe;const zd=Ce.ref(!1),Jd=Ce.ref(!1),Xd=Ce.ref(!1),Qd=Ce.ref({}),Zd=Ce.ref({}),e_=Ce.ref(!1),t_=Ce.ref(void 0),kl=Ce.ref({}),hu=Ce.ref({}),Ul=Ce.ref([]),du=Ce.ref("default"),_u=Ce.ref("default"),pu=Ce.ref(!1),fu=Ce.ref(!1),mu=Ce.ref(!0),n_=Ce.ref(!1),s_=Ce.ref(null),Ys=Ce.ref(void 0),r_=Ce.ref(!1),gu=Ce.ref(2),Tu=Ce.ref(1),vu=Ce.ref({}),i_=Ce.ref({}),o_=Ce.ref({}),yu=Ce.computed(()=>{const l={};return Object.entries(Qd.value).forEach(([n,s])=>{vu.value[n]?.isTransferred||(l[n]=s)}),l}),By=Ce.computed(()=>{const l={},n=Object.values(yu.value).map(s=>s.roomId);return Object.entries(kl.value).forEach(([s,i])=>{n.includes(i.roomId)&&(l[s]=i)}),l}),Ky=Ce.computed(()=>Ul.value.filter(l=>l.kind==="audioinput").map(l=>({deviceId:l.deviceId,kind:l.kind,groupId:l.groupId,label:l.label}))),Gy=Ce.computed(()=>Ul.value.filter(l=>l.kind==="audiooutput").map(l=>({deviceId:l.deviceId,kind:l.kind,groupId:l.groupId,label:l.label}))),l_=Ce.computed(()=>Object.values(yu.value).filter(l=>l.roomId===Ys.value));Ce.watch(l_,l=>{!l.length&&Ys.value&&(Ys.value=void 0)}),Ce.watch(_u,async l=>{await zt.actions.setMicrophone(l)}),Ce.watch(du,async l=>{await zt.actions.setSpeaker(l)}),Ce.watch(pu,l=>{zt.actions.setMuteWhenJoin(l)}),Ce.watch(fu,l=>{zt.actions.setDND(l)}),Ce.watch(mu,l=>{zt.actions.setCallWaiting(l)}),Ce.watch(gu,l=>{zt.actions.setMicrophoneSensitivity(l)}),Ce.watch(Tu,l=>{zt.actions.setSpeakerVolume(l)}),Ce.watch(Ys,async l=>{await zt.actions.setActiveRoom(l)});const zt={state:{isInitialized:zd,isOpenSIPSReady:Jd,isOpenSIPSReconnecting:Xd,activeCalls:yu,callsInActiveRoom:l_,activeMessages:Zd,addCallToCurrentRoom:e_,callAddingInProgress:t_,activeRooms:By,msrpHistory:hu,availableMediaDevices:Ul,inputMediaDeviceList:Ky,outputMediaDeviceList:Gy,selectedOutputDevice:du,selectedInputDevice:_u,muteWhenJoin:pu,isDND:fu,isCallWaitingEnabled:mu,isMuted:n_,originalStream:s_,currentActiveRoomId:Ys,callStatus:vu,callTime:i_,callMetrics:o_,autoAnswer:r_,microphoneInputLevel:gu,speakerVolume:Tu},actions:{init(l,n,s={}){return new Promise((i,a)=>{try{const e={...s,session_timers:!1,uri:`sip:${l.username}@${l.domain}`,password:l.password};l.authorization_jwt&&(e.authorization_jwt=l.authorization_jwt),Oe=new Vy({configuration:e,socketInterfaces:[`wss://${l.domain}`],sipDomain:`${l.domain}`,sipOptions:{session_timers:!1,extraHeaders:["X-Bar: bar"],pcConfig:{}},modules:l.modules,pnExtraHeaders:n}),Oe.on("connection",d=>{e_.value=!1,zd.value=!0,Jd.value=d,i(Oe)}).on("reconnecting",d=>{Xd.value=d}).on("changeActiveCalls",d=>{Qd.value={...d}}).on("changeActiveMessages",d=>{Zd.value={...d}}).on("newMSRPMessage",d=>{const _=d.session._id,u=hu.value[_]||[];u.push(d.message),hu.value[_]=[...u]}).on("callAddingInProgressChanged",d=>{t_.value=d}).on("changeAvailableDeviceList",d=>{Ul.value=[...d]}).on("changeActiveInputMediaDevice",d=>{_u.value=d}).on("changeActiveOutputMediaDevice",d=>{du.value=d}).on("changeMuteWhenJoin",d=>{pu.value=d}).on("changeIsCallWaiting",d=>{mu.value=d}).on("changeIsDND",d=>{fu.value=d}).on("changeIsMuted",d=>{n_.value=d}).on("changeActiveStream",d=>{s_.value=d}).on("currentActiveRoomChanged",d=>{Ys.value=d}).on("addRoom",({roomList:d})=>{kl.value={...d}}).on("updateRoom",({roomList:d})=>{kl.value={...d}}).on("removeRoom",({roomList:d})=>{kl.value={...d}}).on("changeCallStatus",d=>{vu.value={...d}}).on("changeCallTime",d=>{i_.value={...d}}).on("changeCallMetrics",d=>{o_.value={...d}}).begin(),i(Oe)}catch(e){console.error(e),a()}})},unregister(){Oe?.unregister()},register(){Oe?.register()},disconnect(){Oe?.disconnect()},initCall(l,n=!1,s=!1){Oe?.audio.initCall(l,n,s)},answerCall(l){Oe?.audio.answerCall(l)},terminateCall(l){Oe?.audio.terminateCall(l)},mute(){Oe?.audio.mute()},unmute(){Oe?.audio.unmute()},transferCall(l,n){Oe?.audio.transferCall(l,n)},mergeCall(l){Oe?.audio.mergeCall(l)},mergeCallByIds(l,n){Oe?.audio.mergeCallByIds(l,n)},holdCall(l,n){Oe?.audio.holdCall(l,n)},unholdCall(l){Oe?.audio.unholdCall(l)},async moveCall(l,n){await Oe?.audio.moveCall(l,n)},muteCaller(l){Oe?.audio.muteCaller(l)},unmuteCaller(l){Oe?.audio.unmuteCaller(l)},setMuteWhenJoin(l){Oe?.audio.setMuteWhenJoin(l)},setDND(l){Oe?.audio.setDND(l)},setCallWaiting(l){Oe?.audio.setCallWaiting(l)},async setMicrophone(l){await Oe?.audio.setMicrophone(l)},async setSpeaker(l){await Oe?.audio.setSpeaker(l)},sendDTMF(l,n){Oe?.audio.sendDTMF(l,n)},async setActiveRoom(l){await Oe?.audio.setActiveRoom(l)},setMicrophoneSensitivity(l){gu.value=l,Oe?.audio.setMicrophoneSensitivity(l)},setSpeakerVolume(l){Tu.value=l,Oe?.audio.setSpeakerVolume(l)},setAutoAnswer(l){r_.value=l,Oe?.audio.setAutoAnswer(l)},setMetricsConfig(l){Oe?.audio.setMetricsConfig(l)},msrpAnswer(l){Oe?.msrp.msrpAnswer(l)},messageTerminate(l){Oe?.msrp.messageTerminate(l)},sendMSRP(l,n){Oe?.msrp.sendMSRP(l,n)},initMSRP(l,n,s){Oe?.msrp.initMSRP(l,n,s)}}},a_=Symbol();function Wy(){return Ce.provide(a_,zt),zt}function Yy(){const l=Ce.inject(a_);if(!l)throw new Error("useVsipInject() is called without provider, please call useVsipProvide() first");return l}dn.useVsipInject=Yy,dn.useVsipProvide=Wy,dn.vsipAPI=zt,Object.defineProperty(dn,Symbol.toStringTag,{value:"Module"})});
160
160
  //# sourceMappingURL=super.umd.js.map