opensips-js-vue 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library/index.d.ts +9 -1
- package/library/super.mjs +5233 -5078
- package/library/super.mjs.map +1 -1
- package/library/super.umd.js +48 -48
- package/library/super.umd.js.map +1 -1
- package/package.json +2 -2
package/library/super.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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 v_=Object.getOwnPropertySymbols;var eE=Object.prototype.hasOwnProperty,tE=Object.prototype.propertyIsEnumerable;var y_=(et,ve,mt)=>ve in et?Qy(et,ve,{enumerable:!0,configurable:!0,writable:!0,value:mt}):et[ve]=mt,ie=(et,ve)=>{for(var mt in ve||(ve={}))eE.call(ve,mt)&&y_(et,mt,ve[mt]);if(v_)for(var mt of v_(ve))tE.call(ve,mt)&&y_(et,mt,ve[mt]);return et},lt=(et,ve)=>Jy(et,Zy(ve));var oe=(et,ve,mt)=>new Promise(($o,jt)=>{var Vo=gn=>{try{tr(mt.next(gn))}catch(nr){jt(nr)}},$e=gn=>{try{tr(mt.throw(gn))}catch(nr){jt(nr)}},tr=gn=>gn.done?$o(gn.value):Promise.resolve(gn.value).then(Vo,$e);tr((mt=mt.apply(et,ve)).next())});var mt=Object.defineProperty,$o=(o,s,n)=>s in o?mt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[s]=n,jt=(o,s,n)=>($o(o,typeof s!="symbol"?s+"":s,n),n),Vo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $e(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}const tr="jssip",gn="JsSIP",nr="the Javascript SIP library",A_="3.10.0",C_="https://jssip.net",b_=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],R_="lib/JsSIP.d.ts",I_="lib-es5/JsSIP.js",w_=["sip","websocket","webrtc","node","browser","library"],O_="MIT",N_={type:"git",url:"https://github.com/versatica/JsSIP.git"},D_={url:"https://github.com/versatica/JsSIP/issues"},k_={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},U_={"@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"},M_={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Ol={name:tr,title:gn,description:nr,version:A_,homepage:C_,contributors:b_,types:R_,main:I_,keywords:w_,license:O_,repository:N_,bugs:D_,dependencies:k_,devDependencies:U_,scripts:M_};var pc=Ol,ot={USER_AGENT:"".concat(pc.title," ").concat(pc.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 Nl(o){"@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(o)}function Dl(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function kl(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&sr(o,s)}function Ul(o){var s=mc();return function(){var n=rr(o),i;if(s){var a=rr(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return x_(this,i)}}function x_(o,s){return s&&(Nl(s)==="object"||typeof s=="function")?s:P_(o)}function P_(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function Fs(o){var s=typeof Map=="function"?new Map:void 0;return Fs=function(n){if(n===null||!L_(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 Ml(n,arguments,rr(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),sr(i,n)},Fs(o)}function Ml(o,s,n){return mc()?Ml=Reflect.construct:Ml=function(i,a,e){var d=[null];d.push.apply(d,a);var _=Function.bind.apply(i,d),u=new _;return e&&sr(u,e.prototype),u},Ml.apply(null,arguments)}function mc(){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(o){return!1}}function L_(o){return Function.toString.call(o).indexOf("[native code]")!==-1}function sr(o,s){return sr=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},sr(o,s)}function rr(o){return rr=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},rr(o)}var H_=function(o){kl(n,o);var s=Ul(n);function n(i,a){var e;return Dl(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}(Fs(Error)),q_=function(o){kl(n,o);var s=Ul(n);function n(i){var a;return Dl(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}(Fs(Error)),F_=function(o){kl(n,o);var s=Ul(n);function n(i){var a;return Dl(this,n),a=s.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=i,a}return n}(Fs(Error)),j_=function(o){kl(n,o);var s=Ul(n);function n(i){var a;return Dl(this,n),a=s.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=i,a}return n}(Fs(Error)),Kn={ConfigurationError:H_,InvalidStateError:q_,NotSupportedError:F_,NotReadyError:j_},tt={},Bo,gc;function Ko(){if(gc)return Bo;gc=1;function o(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 Bo=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(o(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}(),Bo}var Tc,vc;function dn(){return vc||(vc=1,Tc=function(){function o(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:I,SP:R,HTAB:Q,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:G,LHEX:te,token:b,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:ms,password:Br,hostport:Nn,host:nn,hostname:gs,domainlabel:Ts,toplabel:Kr,IPv6reference:vs,IPv6address:ys,h16:x,ls32:qe,IPv4address:sn,dec_octet:rn,port:Gr,uri_parameters:Wr,uri_parameter:Es,transport_param:Yr,user_param:zr,method_param:Xr,ttl_param:Qr,maddr_param:Jr,lr_param:Zr,other_param:ei,pname:ti,pvalue:ni,paramchar:ln,param_unreserved:si,headers:ri,header:Dn,hname:ii,hvalue:li,hnv_unreserved:on,Request_Response:Nu,Request_Line:oi,Request_URI:ai,absoluteURI:Ss,hier_part:ui,net_path:ci,abs_path:kn,opaque_part:hi,uric:an,uric_no_slash:di,path_segments:_i,segment:Un,param:As,pchar:un,scheme:fi,authority:pi,srvr:mi,reg_name:gi,query:Ti,SIP_Version:Cs,INVITEm:vi,ACKm:yi,OPTIONSm:Ei,BYEm:Si,CANCELm:Ai,REGISTERm:Ci,SUBSCRIBEm:bi,NOTIFYm:Ri,REFERm:Ii,Method:Mn,Status_Line:wi,Status_Code:Oi,extension_code:Ni,Reason_Phrase:Di,Allow_Events:Du,Call_ID:ku,Contact:Uu,contact_param:xn,name_addr:Mt,display_name:Pn,contact_params:bs,c_p_q:ki,c_p_expires:Ui,delta_seconds:xt,qvalue:Mi,generic_param:Oe,gen_value:xi,Content_Disposition:Mu,disp_type:Pi,disp_param:Rs,handling_param:Li,Content_Encoding:xu,Content_Length:Pu,Content_Type:Lu,media_type:Hi,m_type:qi,discrete_type:Fi,composite_type:ji,extension_token:Ln,x_token:$i,m_subtype:Vi,m_parameter:Is,m_value:Bi,CSeq:Hu,CSeq_value:Ki,Expires:qu,Event:Fu,event_type:cn,From:ju,from_param:ws,tag_param:Os,Max_Forwards:$u,Min_Expires:Vu,Name_Addr_Header:Bu,Proxy_Authenticate:Ku,challenge:Ns,other_challenge:Gi,auth_param:hn,digest_cln:Hn,realm:Wi,realm_value:Yi,domain:zi,URI:qn,nonce:Xi,nonce_value:Qi,opaque:Ji,stale:Zi,algorithm:el,qop_options:tl,qop_value:Fn,Proxy_Require:Gu,Record_Route:Wu,rec_route:jn,Reason:Yu,reason_param:Ds,reason_cause:nl,Require:zu,Route:Xu,route_param:$n,Subscription_State:Qu,substate_value:sl,subexp_params:ks,event_reason_value:rl,Subject:Ju,Supported:Zu,To:ec,to_param:Us,Via:tc,via_param:Vn,via_params:Ms,via_ttl:il,via_maddr:ll,via_received:ol,via_branch:al,response_port:ul,rport:cl,sent_protocol:hl,protocol_name:dl,transport:_l,sent_by:fl,via_host:pl,via_port:ml,ttl:xs,WWW_Authenticate:nc,Session_Expires:sc,s_e_expires:gl,s_e_params:Ps,s_e_refresher:Tl,extension_header:rc,header_value:vl,message_body:ic,uuid_URI:lc,uuid:yl,hex4:dt,hex8:El,hex12:Sl,Refer_To:oc,Replaces:ac,call_id:Al,replaces_param:Ls,to_tag:Cl,from_tag:bl,early_flag:Rl};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+o(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(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",C_="https://jssip.net",A_=["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:C_,contributors:A_,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:C,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:Ce,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:Cs,INVITEm:Ti,ACKm:vi,OPTIONSm:yi,BYEm:Ei,CANCELm:Si,REGISTERm:Ci,SUBSCRIBEm:Ai,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:As,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:Co,replaces_param:Ps,to_tag:Ao,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
|
|
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=R(),t===null&&(t=Q()),t}function w(){var t;return/^[\0-\xFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function I(){var t;return/^["]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u('["]')),t}function R(){var t;return n.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function Q(){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,l,c,h;return c=e,h=e,n.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(l=y(),l!==null?t=[t,r,l]:(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,l,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(l=A(),l!==null)for(r=[];l!==null;)r.push(l),l=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,l,c,h;for(c=e,h=e,t=[],r=R(),r===null&&(r=Q());r!==null;)t.push(r),r=R(),r===null&&(r=Q());return t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,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,l=[],c=Te();c!==null;)l.push(c),c=Te();for(l!==null?(c=q(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;){for(r.push(l),m=e,l=[],c=Te();c!==null;)l.push(c),c=Te();l!==null?(c=q(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 G(){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 b(){var t,r,l;if(l=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)}(l)),t===null&&(e=l),t}function J(){var t,r,l;if(l=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)}(l)),t===null&&(e=l),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=I(),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=R(),t===null&&(t=Q())))))))))))))))))),t}function Ye(){var t,r,l;if(l=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=I(),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=I(),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)}(l)),t===null&&(e=l),t}function ee(){var t,r,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c;return l=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=l),t}function xe(){var t,r,l,c;return l=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=l),t}function _e(){var t,r,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c;return l=e,c=e,t=N(),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=l),t}function Ee(){var t,r,l,c;return l=e,c=e,t=I(),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=l),t}function ge(){var t,r,l,c;if(c=e,t=Ae(),t!==null){for(r=[],l=Re(),l===null&&(l=ae(),l===null&&(l=ge()));l!==null;)r.push(l),l=Re(),l===null&&(l=ae(),l===null&&(l=ge()));r!==null?(l=me(),l!==null?t=[t,r,l]:(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,l,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=I(),r!==null){for(l=[],c=fe(),c===null&&(c=ae());c!==null;)l.push(c),c=fe(),c===null&&(c=ae());l!==null?(c=I(),c!==null?t=[t,r,l,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,l,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=I(),r!==null){for(l=[],c=fe(),c===null&&(c=ae());c!==null;)l.push(c),c=fe(),c===null&&(c=ae());l!==null?(c=I(),c!==null?t=[t,r,l,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,l;return l=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=l)):(t=null,e=l),t}function Se(){var t,r,l,c,h,f;return h=e,f=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=Ft(),l=l!==null?l:"",l!==null?(c=Nn(),c!==null?t=[t,r,l,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 Il(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,l,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?(l=Ft(),l=l!==null?l:"",l!==null?(c=Nn(),c!==null?(h=Wr(),h!==null?(f=ri(),f=f!==null?f:"",f!==null?t=[t,r,l,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 Il(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(Y){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(l,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(l,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Ft(){var t,r,l,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?(l=Br(),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?(n.charCodeAt(e)===64?(l="@",e++):(l=null,u('"@"')),l!==null?t=[t,r,l]:(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=ms())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(r=ms()));else t=null;return t}function ms(){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 Br(){var t,r,l;for(l=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)}(l)),t===null&&(e=l),t}function Nn(){var t,r,l,c,h;return c=e,t=nn(),t!==null?(h=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=Gr(),l!==null?r=[r,l]:(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=gs(),t===null&&(t=sn(),t===null&&(t=vs())),t!==null&&(t=function(l){return v.host=n.substring(e,l).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function gs(){var t,r,l,c,h,f;for(c=e,h=e,t=[],f=e,r=Ts(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f);r!==null;)t.push(r),f=e,r=Ts(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f);return t!==null?(r=Kr(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l=l!==null?l:"",l!==null?t=[t,r,l]:(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 Ts(){var t,r,l,c;if(c=e,t=P(),t!==null){for(r=[],l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));l!==null;)r.push(l),l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Kr(){var t,r,l,c;if(c=e,t=T(),t!==null){for(r=[],l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));l!==null;)r.push(l),l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function vs(){var t,r,l,c,h;return c=e,h=e,n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=ys(),r!==null?(n.charCodeAt(e)===93?(l="]",e++):(l=null,u('"]"')),l!==null?t=[t,r,l]:(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 ys(){var t,r,l,c,h,f,m,E,C,Y,be,it,Bn,qs,S,L;return qs=e,S=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=x(),l!==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?(Y=":",e++):(Y=null,u('":"')),Y!==null?(be=x(),be!==null?(n.charCodeAt(e)===58?(it=":",e++):(it=null,u('":"')),it!==null?(Bn=qe(),Bn!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=":",e++):(l=null,u('":"')),l!==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?(Y=x(),Y!==null?(n.charCodeAt(e)===58?(be=":",e++):(be=null,u('":"')),be!==null?(it=qe(),it!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=":",e++):(l=null,u('":"')),l!==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?(Y=qe(),Y!==null?t=[t,r,l,c,h,f,m,E,C,Y]:(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?(l=":",e++):(l=null,u('":"')),l!==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,l,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?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=qe(),f!==null?t=[t,r,l,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?(l=":",e++):(l=null,u('":"')),l!==null?(c=qe(),c!==null?t=[t,r,l,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?(l=x(),l!==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?(Y=":",e++):(Y=null,u('":"')),Y!==null?(be=qe(),be!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(n.substr(e,2)==="::"?(l="::",e+=2):(l=null,u('"::"')),l!==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?(Y=qe(),Y!==null?t=[t,r,l,c,h,f,m,E,C,Y]:(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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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(_c){return v.host_type="IPv6",n.substring(e,_c)}(qs)),t===null&&(e=qs),t}function x(){var t,r,l,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(l=y(),l=l!==null?l:"",l!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function qe(){var t,r,l,c;return c=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=x(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=sn()),t}function sn(){var t,r,l,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?(l=rn(),l!==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,l,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(Y){return v.host_type="IPv4",n.substring(e,Y)}(E)),t===null&&(e=E),t}function rn(){var t,r,l,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?(l=p(),l!==null?t=[t,r,l]:(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?(l=p(),l!==null?t=[t,r,l]:(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 Gr(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 Wr(){var t,r,l,c;for(t=[],c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(l=Es(),l!==null?r=[r,l]:(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?(l=Es(),l!==null?r=[r,l]:(r=null,e=c)):(r=null,e=c);return t}function Es(){var t;return t=Yr(),t===null&&(t=zr(),t===null&&(t=Xr(),t===null&&(t=Qr(),t===null&&(t=Jr(),t===null&&(t=Zr(),t===null&&(t=ei())))))),t}function Yr(){var t,r,l,c;return l=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=b())))),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()}(l,t[1])),t===null&&(e=l),t}function zr(){var t,r,l,c;return l=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=b())),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()}(l,t[1])),t===null&&(e=l),t}function Xr(){var t,r,l,c;return l=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}(l,t[1])),t===null&&(e=l),t}function Qr(){var t,r,l,c;return l=e,c=e,n.substr(e,4).toLowerCase()==="ttl="?(t=n.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=xs(),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}(l,t[1])),t===null&&(e=l),t}function Jr(){var t,r,l,c;return l=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}(l,t[1])),t===null&&(e=l),t}function Zr(){var t,r,l,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?(l=b(),l!==null?r=[r,l]:(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 ei(){var t,r,l,c,h,f;return c=e,h=e,t=ti(),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=ni(),l!==null?r=[r,l]:(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 ti(){var t,r,l;if(l=e,r=ln(),r!==null)for(t=[];r!==null;)t.push(r),r=ln();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(l,t)),t===null&&(e=l),t}function ni(){var t,r,l;if(l=e,r=ln(),r!==null)for(t=[];r!==null;)t.push(r),r=ln();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(l,t)),t===null&&(e=l),t}function ln(){var t;return t=si(),t===null&&(t=O(),t===null&&(t=pe())),t}function si(){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 ri(){var t,r,l,c,h,f,m;if(f=e,n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Dn(),r!==null){for(l=[],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;)l.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);l!==null?t=[t,r,l]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t}function Dn(){var t,r,l,c,h;return c=e,h=e,t=ii(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=li(),l!==null?t=[t,r,l]:(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 ii(){var t,r;if(r=on(),r===null&&(r=O(),r===null&&(r=pe())),r!==null)for(t=[];r!==null;)t.push(r),r=on(),r===null&&(r=O(),r===null&&(r=pe()));else t=null;return t}function li(){var t,r;for(t=[],r=on(),r===null&&(r=O(),r===null&&(r=pe()));r!==null;)t.push(r),r=on(),r===null&&(r=O(),r===null&&(r=pe()));return t}function on(){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 Nu(){var t;return t=wi(),t===null&&(t=oi()),t}function oi(){var t,r,l,c,h,f;return f=e,t=Mn(),t!==null?(r=R(),r!==null?(l=ai(),l!==null?(c=R(),c!==null?(h=Cs(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function ai(){var t;return t=De(),t===null&&(t=Ss()),t}function Ss(){var t,r,l,c;return c=e,t=fi(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=ui(),l===null&&(l=hi()),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ui(){var t,r,l,c,h;return c=e,t=ci(),t===null&&(t=kn()),t!==null?(h=e,n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(l=Ti(),l!==null?r=[r,l]:(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 ci(){var t,r,l,c;return c=e,n.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=pi(),r!==null?(l=kn(),l=l!==null?l:"",l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function kn(){var t,r,l;return l=e,n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=_i(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function hi(){var t,r,l,c;if(c=e,t=di(),t!==null){for(r=[],l=an();l!==null;)r.push(l),l=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 di(){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 _i(){var t,r,l,c,h,f;if(h=e,t=Un(),t!==null){for(r=[],f=e,n.charCodeAt(e)===47?(l="/",e++):(l=null,u('"/"')),l!==null?(c=Un(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===47?(l="/",e++):(l=null,u('"/"')),l!==null?(c=Un(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Un(){var t,r,l,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?(l=";",e++):(l=null,u('";"')),l!==null?(c=As(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===59?(l=";",e++):(l=null,u('";"')),l!==null?(c=As(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function As(){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 fi(){var t,r,l,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],l=T(),l===null&&(l=p(),l===null&&(n.charCodeAt(e)===43?(l="+",e++):(l=null,u('"+"')),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."'))))));l!==null;)r.push(l),l=T(),l===null&&(l=p(),l===null&&(n.charCodeAt(e)===43?(l="+",e++):(l=null,u('"+"')),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===46?(l=".",e++):(l=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 pi(){var t;return t=mi(),t===null&&(t=gi()),t}function mi(){var t,r,l,c;return l=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=l)):(t=null,e=l),t=t!==null?t:"",t}function gi(){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 Ti(){var t,r;for(t=[],r=an();r!==null;)t.push(r),r=an();return t}function Cs(){var t,r,l,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(l=[];c!==null;)l.push(c),c=p();else l=null;if(l!==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,l,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 vi(){var t;return n.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function yi(){var t;return n.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function Ei(){var t;return n.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function Si(){var t;return n.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function Ai(){var t;return n.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function Ci(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function bi(){var t;return n.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function Ri(){var t;return n.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function Ii(){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=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=Ii(),t===null&&(t=b()))))))))),t!==null&&(t=function(l){return v.method=n.substring(e,l),v.method}(r)),t===null&&(e=r),t}function wi(){var t,r,l,c,h,f;return f=e,t=Cs(),t!==null?(r=R(),r!==null?(l=Oi(),l!==null?(c=R(),c!==null?(h=Di(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function Oi(){var t,r;return r=e,t=Ni(),t!==null&&(t=function(l,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Ni(){var t,r,l,c;return c=e,t=p(),t!==null?(r=p(),r!==null?(l=p(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Di(){var t,r,l;for(l=e,t=[],r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=G(),r===null&&(r=R(),r===null&&(r=Q()))))));r!==null;)t.push(r),r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=G(),r===null&&(r=R(),r===null&&(r=Q()))))));return t!==null&&(t=function(c){v.reason_phrase=n.substring(e,c)}(l)),t===null&&(e=l),t}function Du(){var t,r,l,c,h,f;if(h=e,t=cn(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=cn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=cn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ku(){var t,r,l,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?(l=Ye(),l!==null?r=[r,l]:(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 Uu(){var t,r,l,c,h,f,m;if(h=e,t=ee(),t===null)if(f=e,t=xn(),t!==null){for(r=[],m=e,l=_e(),l!==null?(c=xn(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=_e(),l!==null?(c=xn(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,Y;for(Y=v.multi_header.length,C=0;C<Y;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,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=bs(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=bs(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Mt(){var t,r,l,c,h;return h=e,t=Pn(),t=t!==null?t:"",t!==null?(r=xe(),r!==null?(l=De(),l!==null?(c=Ie(),c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Pn(){var t,r,l,c,h,f,m;if(h=e,f=e,t=b(),t!==null){for(r=[],m=e,l=Te(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=Te(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y,be){return Y+be[0]+be[1]},C[0])}(h,t)),t===null&&(e=h),t}function bs(){var t;return t=ki(),t===null&&(t=Ui(),t===null&&(t=Oe())),t}function ki(){var t,r,l,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?(l=Mi(),l!==null?t=[t,r,l]:(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 Ui(){var t,r,l,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?(l=xt(),l!==null?t=[t,r,l]:(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,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Mi(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?r=[r,l,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,l,c,h,f;return c=e,h=e,t=b(),t!==null?(f=e,r=k(),r!==null?(l=xi(),l!==null?r=[r,l]:(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 xi(){var t;return t=b(),t===null&&(t=nn(),t===null&&(t=we())),t}function Mu(){var t,r,l,c,h,f;if(h=e,t=Pi(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Rs(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Rs(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Pi(){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=b())))),t}function Rs(){var t;return t=Li(),t===null&&(t=Oe()),t}function Li(){var t,r,l,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"?(l=n.substr(e,8),e+=8):(l=null,u('"optional"')),l===null&&(n.substr(e,8).toLowerCase()==="required"?(l=n.substr(e,8),e+=8):(l=null,u('"required"')),l===null&&(l=b())),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function xu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Pu(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Lu(){var t,r;return r=e,t=Hi(),t!==null&&(t=function(l){v=n.substring(e,l)}(r)),t===null&&(e=r),t}function Hi(){var t,r,l,c,h,f,m,E;if(m=e,t=qi(),t!==null)if(r=V(),r!==null)if(l=Vi(),l!==null){for(c=[],E=e,h=le(),h!==null?(f=Is(),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=Is(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function qi(){var t;return t=Fi(),t===null&&(t=ji()),t}function Fi(){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 ji(){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=b(),t===null&&(t=$i()),t}function $i(){var t,r,l;return l=e,n.substr(e,2).toLowerCase()==="x-"?(t=n.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=b(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function Vi(){var t;return t=Ln(),t===null&&(t=b()),t}function Is(){var t,r,l,c;return c=e,t=b(),t!==null?(r=k(),r!==null?(l=Bi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Bi(){var t;return t=b(),t===null&&(t=we()),t}function Hu(){var t,r,l,c;return c=e,t=Ki(),t!==null?(r=Te(),r!==null?(l=Mn(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ki(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function qu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v=c}(r,t)),t===null&&(e=r),t}function Fu(){var t,r,l,c,h,f,m;if(h=e,f=e,t=cn(),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,l,c,h,f;if(h=e,t=J(),t!==null){for(r=[],f=e,n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?(c=J(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?(c=J(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ju(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=ws(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=ws(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){v=-1}}()),t===null&&(e=h),t}function ws(){var t;return t=Os(),t===null&&(t=Oe()),t}function Os(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 $u(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Vu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v=c}(r,t)),t===null&&(e=r),t}function Bu(){var t,r,l,c,h,f,m,E,C,Y;for(E=e,C=e,t=[],r=Pn();r!==null;)t.push(r),r=Pn();if(t!==null)if(r=xe(),r!==null)if(l=De(),l!==null)if(c=Ie(),c!==null){for(h=[],Y=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);f!==null;)h.push(f),Y=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);h!==null?t=[t,r,l,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 Ku(){var t;return t=Ns(),t}function Ns(){var t,r,l,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(l=Hn(),l!==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,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Gi()),t}function Gi(){var t,r,l,c,h,f,m,E;if(m=e,t=b(),t!==null)if(r=Te(),r!==null)if(l=hn(),l!==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,l,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,l,c;return c=e,t=b(),t!==null?(r=k(),r!==null?(l=b(),l===null&&(l=we()),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Hn(){var t;return t=Wi(),t===null&&(t=zi(),t===null&&(t=Xi(),t===null&&(t=Ji(),t===null&&(t=Zi(),t===null&&(t=el(),t===null&&(t=tl(),t===null&&(t=hn()))))))),t}function Wi(){var t,r,l,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?(l=Yi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Yi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(l,c){v.realm=c}(r,t)),t===null&&(e=r),t}function zi(){var t,r,l,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(l=rt(),l!==null)if(c=qn(),c!==null){if(h=[],C=e,m=R(),m!==null)for(f=[];m!==null;)f.push(m),m=R();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=R(),m!==null)for(f=[];m!==null;)f.push(m),m=R();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,l,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=Ss(),t===null&&(t=kn()),t}function Xi(){var t,r,l,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?(l=Qi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Qi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(l,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Ji(){var t,r,l,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?(l=Ue(),l!==null?t=[t,r,l]:(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 Zi(){var t,r,l,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"?(l=n.substr(e,4),e+=4):(l=null,u('"true"')),l!==null&&(l=function(f){v.stale=!0}()),l===null&&(e=h),l===null&&(h=e,n.substr(e,5).toLowerCase()==="false"?(l=n.substr(e,5),e+=5):(l=null,u('"false"')),l!==null&&(l=function(f){v.stale=!1}()),l===null&&(e=h)),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function el(){var t,r,l,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"?(l=n.substr(e,3),e+=3):(l=null,u('"MD5"')),l===null&&(n.substr(e,8).toLowerCase()==="md5-sess"?(l=n.substr(e,8),e+=8):(l=null,u('"MD5-sess"')),l===null&&(l=b())),l!==null?t=[t,r,l]:(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 tl(){var t,r,l,c,h,f,m,E,C,Y;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(l=rt(),l!==null){if(C=e,c=Fn(),c!==null){for(h=[],Y=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);f!==null;)h.push(f),Y=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=Ee(),h!==null?t=[t,r,l,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=b())),t!==null&&(t=function(l,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Gu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Wu(){var t,r,l,c,h,f,m;if(h=e,f=e,t=jn(),t!==null){for(r=[],m=e,l=_e(),l!==null?(c=jn(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=_e(),l!==null?(c=jn(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,Y;for(Y=v.multi_header.length,C=0;C<Y;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,l,c,h,f,m;if(h=e,f=e,t=Mt(),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Yu(){var t,r,l,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=b()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Ds(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Ds(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 Y=v.params.text;v.text=Y.substring(1,Y.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function Ds(){var t;return t=nl(),t===null&&(t=Oe()),t}function nl(){var t,r,l,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(l=[];c!==null;)l.push(c),c=p();else l=null;l!==null?t=[t,r,l]:(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 zu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Xu(){var t,r,l,c,h,f;if(h=e,t=$n(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=$n(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=$n(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $n(){var t,r,l,c,h,f;if(h=e,t=Mt(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Qu(){var t,r,l,c,h,f;if(h=e,t=sl(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=ks(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=ks(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function sl(){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=b()))),t!==null&&(t=function(l){v.state=n.substring(e,l)}(r)),t===null&&(e=r),t}function ks(){var t,r,l,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?(l=rl(),l!==null?t=[t,r,l]:(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?(l=xt(),l!==null?t=[t,r,l]:(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?(l=xt(),l!==null?t=[t,r,l]:(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 rl(){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=b()))))))),t}function Ju(){var t;return t=$(),t=t!==null?t:"",t}function Zu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function ec(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Us(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Us(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){v=-1}}()),t===null&&(e=h),t}function Us(){var t;return t=Os(),t===null&&(t=Oe()),t}function tc(){var t,r,l,c,h,f;if(h=e,t=Vn(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=Vn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=Vn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Vn(){var t,r,l,c,h,f,m,E;if(m=e,t=hl(),t!==null)if(r=Te(),r!==null)if(l=fl(),l!==null){for(c=[],E=e,h=le(),h!==null?(f=Ms(),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=Ms(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Ms(){var t;return t=il(),t===null&&(t=ll(),t===null&&(t=ol(),t===null&&(t=al(),t===null&&(t=ul(),t===null&&(t=Oe()))))),t}function il(){var t,r,l,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?(l=xs(),l!==null?t=[t,r,l]:(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 ll(){var t,r,l,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?(l=nn(),l!==null?t=[t,r,l]:(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 ol(){var t,r,l,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?(l=sn(),l===null&&(l=ys()),l!==null?t=[t,r,l]:(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 al(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 ul(){var t,r,l,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?(l=cl(),l!==null?r=[r,l]:(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 cl(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 hl(){var t,r,l,c,h,f;return f=e,t=dl(),t!==null?(r=V(),r!==null?(l=b(),l!==null?(c=V(),c!==null?(h=_l(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function dl(){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=b()),t!==null&&(t=function(l,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function _l(){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=b())))),t!==null&&(t=function(l,c){v.transport=c}(r,t)),t===null&&(e=r),t}function fl(){var t,r,l,c,h;return c=e,t=pl(),t!==null?(h=e,r=ze(),r!==null?(l=ml(),l!==null?r=[r,l]:(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 pl(){var t,r;return r=e,t=sn(),t===null&&(t=vs(),t===null&&(t=gs())),t!==null&&(t=function(l){v.host=n.substring(e,l)}(r)),t===null&&(e=r),t}function ml(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 xs(){var t,r,l,c,h;return c=e,h=e,t=p(),t!==null?(r=p(),r=r!==null?r:"",r!==null?(l=p(),l=l!==null?l:"",l!==null?t=[t,r,l]:(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 nc(){var t;return t=Ns(),t}function sc(){var t,r,l,c,h,f;if(h=e,t=gl(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Ps(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Ps(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function gl(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v.expires=c}(r,t)),t===null&&(e=r),t}function Ps(){var t;return t=Tl(),t===null&&(t=Oe()),t}function Tl(){var t,r,l,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"?(l=n.substr(e,3),e+=3):(l=null,u('"uac"')),l===null&&(n.substr(e,3).toLowerCase()==="uas"?(l=n.substr(e,3),e+=3):(l=null,u('"uas"'))),l!==null?t=[t,r,l]:(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 rc(){var t,r,l,c;return c=e,t=b(),t!==null?(r=H(),r!==null?(l=vl(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function vl(){var t,r;for(t=[],r=q(),r===null&&(r=G(),r===null&&(r=Te()));r!==null;)t.push(r),r=q(),r===null&&(r=G(),r===null&&(r=Te()));return t}function ic(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function lc(){var t,r,l;return l=e,n.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=yl(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function yl(){var t,r,l,c,h,f,m,E,C,Y,be;return Y=e,be=e,t=El(),t!==null?(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(l=dt(),l!==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=Sl(),C!==null?t=[t,r,l,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)}(Y,t[0])),t===null&&(e=Y),t}function dt(){var t,r,l,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(l=y(),l!==null?(c=y(),c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function El(){var t,r,l;return l=e,t=dt(),t!==null?(r=dt(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function Sl(){var t,r,l,c;return c=e,t=dt(),t!==null?(r=dt(),r!==null?(l=dt(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function oc(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 ac(){var t,r,l,c,h,f;if(h=e,t=Al(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Ls(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Ls(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Al(){var t,r,l,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?(l=Ye(),l!==null?r=[r,l]:(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 Ls(){var t;return t=Cl(),t===null&&(t=bl(),t===null&&(t=Rl(),t===null&&(t=Oe()))),t}function Cl(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 bl(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 Rl(){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(l){v.early_only=!0}()),t===null&&(e=r),t}function uc(t){t.sort();for(var r=null,l=[],c=0;c<t.length;c++)t[c]!==r&&(l.push(t[c]),r=t[c]);return l}function cc(){for(var t=1,r=1,l=!1,c=0;c<Math.max(e,d);c++){var h=n.charAt(c);h===`
|
|
4
|
-
`?(
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var w=!0,
|
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var I=!0,R=!1,Q;return{s:function(){y=p[Symbol.iterator]()},n:function(){var P=y.next();return I=P.done,P},e:function(P){R=!0,Q=P},f:function(){try{!I&&y.return!=null&&y.return()}finally{if(R)throw Q}}}}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=ot,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,I=y;w<I.length;w++){var R=I[w];if(_(p[R]))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 I;return(I=e.parse(p))?I: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,I;for(I=0;I<w;I++)I!==0&&(A+="-"),A+=y[I].charAt(0).toUpperCase()+y[I].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 I(fe,ae,Se){return fe^ae^Se}function R(fe,ae,Se){return ae^(fe|~Se)}function Q(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(I(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(R(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,G,te,b,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,b=4023233417,J=2562383102,ne=271733878,H=0;H<N.length;H+=16)$=te,q=b,M=J,G=ne,te=Q(te,b,J,ne,N[H+0],Ye,3614090360),ne=Q(ne,te,b,J,N[H+1],ee,3905402710),J=Q(J,ne,te,b,N[H+2],V,606105819),b=Q(b,J,ne,te,N[H+3],k,3250441966),te=Q(te,b,J,ne,N[H+4],Ye,4118548399),ne=Q(ne,te,b,J,N[H+5],ee,1200080426),J=Q(J,ne,te,b,N[H+6],V,2821735955),b=Q(b,J,ne,te,N[H+7],k,4249261313),te=Q(te,b,J,ne,N[H+8],Ye,1770035416),ne=Q(ne,te,b,J,N[H+9],ee,2336552879),J=Q(J,ne,te,b,N[H+10],V,4294925233),b=Q(b,J,ne,te,N[H+11],k,2304563134),te=Q(te,b,J,ne,N[H+12],Ye,1804603682),ne=Q(ne,te,b,J,N[H+13],ee,4254626195),J=Q(J,ne,te,b,N[H+14],V,2792965006),b=Q(b,J,ne,te,N[H+15],k,1236535329),te=P(te,b,J,ne,N[H+1],Ae,4129170786),ne=P(ne,te,b,J,N[H+6],me,3225465664),J=P(J,ne,te,b,N[H+11],Ie,643717713),b=P(b,J,ne,te,N[H+0],xe,3921069994),te=P(te,b,J,ne,N[H+5],Ae,3593408605),ne=P(ne,te,b,J,N[H+10],me,38016083),J=P(J,ne,te,b,N[H+15],Ie,3634488961),b=P(b,J,ne,te,N[H+4],xe,3889429448),te=P(te,b,J,ne,N[H+9],Ae,568446438),ne=P(ne,te,b,J,N[H+14],me,3275163606),J=P(J,ne,te,b,N[H+3],Ie,4107603335),b=P(b,J,ne,te,N[H+8],xe,1163531501),te=P(te,b,J,ne,N[H+13],Ae,2850285829),ne=P(ne,te,b,J,N[H+2],me,4243563512),J=P(J,ne,te,b,N[H+7],Ie,1735328473),b=P(b,J,ne,te,N[H+12],xe,2368359562),te=ye(te,b,J,ne,N[H+5],_e,4294588738),ne=ye(ne,te,b,J,N[H+8],le,2272392833),J=ye(J,ne,te,b,N[H+11],ze,1839030562),b=ye(b,J,ne,te,N[H+14],rt,4259657740),te=ye(te,b,J,ne,N[H+1],_e,2763975236),ne=ye(ne,te,b,J,N[H+4],le,1272893353),J=ye(J,ne,te,b,N[H+7],ze,4139469664),b=ye(b,J,ne,te,N[H+10],rt,3200236656),te=ye(te,b,J,ne,N[H+13],_e,681279174),ne=ye(ne,te,b,J,N[H+0],le,3936430074),J=ye(J,ne,te,b,N[H+3],ze,3572445317),b=ye(b,J,ne,te,N[H+6],rt,76029189),te=ye(te,b,J,ne,N[H+9],_e,3654602809),ne=ye(ne,te,b,J,N[H+12],le,3873151461),J=ye(J,ne,te,b,N[H+15],ze,530742520),b=ye(b,J,ne,te,N[H+2],rt,3299628645),te=O(te,b,J,ne,N[H+0],Ee,4096336452),ne=O(ne,te,b,J,N[H+7],ge,1126891415),J=O(J,ne,te,b,N[H+14],Re,2878612391),b=O(b,J,ne,te,N[H+5],we,4237533241),te=O(te,b,J,ne,N[H+12],Ee,1700485571),ne=O(ne,te,b,J,N[H+3],ge,2399980690),J=O(J,ne,te,b,N[H+10],Re,4293915773),b=O(b,J,ne,te,N[H+1],we,2240044497),te=O(te,b,J,ne,N[H+8],Ee,1873313359),ne=O(ne,te,b,J,N[H+15],ge,4264355552),J=O(J,ne,te,b,N[H+6],Re,2734768916),b=O(b,J,ne,te,N[H+13],we,1309151649),te=O(te,b,J,ne,N[H+4],Ee,4149444226),ne=O(ne,te,b,J,N[H+11],ge,3174756917),J=O(J,ne,te,b,N[H+2],Re,718787259),b=O(b,J,ne,te,N[H+9],we,3951481745),te=y(te,$),b=y(b,q),J=y(J,M),ne=y(ne,G);var Ue=pe(te)+pe(b)+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 I=s(T),R;try{for(I.s();!(R=I.n()).done;){var Q=R.value;Q.stop()}}catch(j){I.e(j)}finally{I.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"||o(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 Wo={exports:{}},js=typeof Reflect=="object"?Reflect:null,Sc=js&&typeof js.apply=="function"?js.apply:function(o,s,n){return Function.prototype.apply.call(o,s,n)},xl;js&&typeof js.ownKeys=="function"?xl=js.ownKeys:Object.getOwnPropertySymbols?xl=function(o){return Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o))}:xl=function(o){return Object.getOwnPropertyNames(o)};function $_(o){console&&console.warn&&console.warn(o)}var Ac=Number.isNaN||function(o){return o!==o};function Pe(){Pe.init.call(this)}Wo.exports=Pe,Wo.exports.once=G_,Pe.EventEmitter=Pe,Pe.prototype._events=void 0,Pe.prototype._eventsCount=0,Pe.prototype._maxListeners=void 0;var Cc=10;function Pl(o){if(typeof o!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof o)}Object.defineProperty(Pe,"defaultMaxListeners",{enumerable:!0,get:function(){return Cc},set:function(o){if(typeof o!="number"||o<0||Ac(o))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+o+".");Cc=o}}),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(o){if(typeof o!="number"||o<0||Ac(o))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+o+".");return this._maxListeners=o,this};function bc(o){return o._maxListeners===void 0?Pe.defaultMaxListeners:o._maxListeners}Pe.prototype.getMaxListeners=function(){return bc(this)},Pe.prototype.emit=function(o){for(var s=[],n=1;n<arguments.length;n++)s.push(arguments[n]);var i=o==="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[o];if(_===void 0)return!1;if(typeof _=="function")Sc(_,this,s);else for(var u=_.length,g=Nc(_,u),n=0;n<u;++n)Sc(g[n],this,s);return!0};function Rc(o,s,n,i){var a,e,d;if(Pl(n),e=o._events,e===void 0?(e=o._events=Object.create(null),o._eventsCount=0):(e.newListener!==void 0&&(o.emit("newListener",s,n.listener?n.listener:n),e=o._events),d=e[s]),d===void 0)d=e[s]=n,++o._eventsCount;else if(typeof d=="function"?d=e[s]=i?[n,d]:[d,n]:i?d.unshift(n):d.push(n),a=bc(o),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=o,_.type=s,_.count=d.length,$_(_)}return o}Pe.prototype.addListener=function(o,s){return Rc(this,o,s,!1)},Pe.prototype.on=Pe.prototype.addListener,Pe.prototype.prependListener=function(o,s){return Rc(this,o,s,!0)};function V_(){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 Ic(o,s,n){var i={fired:!1,wrapFn:void 0,target:o,type:s,listener:n},a=V_.bind(i);return a.listener=n,i.wrapFn=a,a}Pe.prototype.once=function(o,s){return Pl(s),this.on(o,Ic(this,o,s)),this},Pe.prototype.prependOnceListener=function(o,s){return Pl(s),this.prependListener(o,Ic(this,o,s)),this},Pe.prototype.removeListener=function(o,s){var n,i,a,e,d;if(Pl(s),i=this._events,i===void 0)return this;if(n=i[o],n===void 0)return this;if(n===s||n.listener===s)--this._eventsCount===0?this._events=Object.create(null):(delete i[o],i.removeListener&&this.emit("removeListener",o,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():B_(n,a),n.length===1&&(i[o]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",o,d||s)}return this},Pe.prototype.off=Pe.prototype.removeListener,Pe.prototype.removeAllListeners=function(o){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[o]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[o]),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[o],typeof s=="function")this.removeListener(o,s);else if(s!==void 0)for(i=s.length-1;i>=0;i--)this.removeListener(o,s[i]);return this};function wc(o,s,n){var i=o._events;if(i===void 0)return[];var a=i[s];return a===void 0?[]:typeof a=="function"?n?[a.listener||a]:[a]:n?K_(a):Nc(a,a.length)}Pe.prototype.listeners=function(o){return wc(this,o,!0)},Pe.prototype.rawListeners=function(o){return wc(this,o,!1)},Pe.listenerCount=function(o,s){return typeof o.listenerCount=="function"?o.listenerCount(s):Oc.call(o,s)},Pe.prototype.listenerCount=Oc;function Oc(o){var s=this._events;if(s!==void 0){var n=s[o];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Pe.prototype.eventNames=function(){return this._eventsCount>0?xl(this._events):[]};function Nc(o,s){for(var n=new Array(s),i=0;i<s;++i)n[i]=o[i];return n}function B_(o,s){for(;s+1<o.length;s++)o[s]=o[s+1];o.pop()}function K_(o){for(var s=new Array(o.length),n=0;n<s.length;++n)s[n]=o[n].listener||o[n];return s}function G_(o,s){return new Promise(function(n,i){function a(d){o.removeListener(s,e),i(d)}function e(){typeof o.removeListener=="function"&&o.removeListener("error",a),n([].slice.call(arguments))}Dc(o,s,e,{once:!0}),s!=="error"&&W_(o,a,{once:!0})})}function W_(o,s,n){typeof o.on=="function"&&Dc(o,"error",s,n)}function Dc(o,s,n,i){if(typeof o.on=="function")i.once?o.once(s,n):o.on(s,n);else if(typeof o.addEventListener=="function")o.addEventListener(s,function a(e){i.once&&o.removeEventListener(s,a),n(e)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof o)}var _t=Wo.exports,Yo={exports:{}},zo,kc;function Y_(){if(kc)return zo;kc=1;var o=1e3,s=o*60,n=s*60,i=n*24,a=i*7,e=i*365.25;zo=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*o;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>=o?Math.round(p/o)+"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>=o?g(p,T,o,"second"):p+" ms"}function g(p,T,y,A){var w=T>=y*1.5;return Math.round(p/y)+" "+A+(w?"s":"")}return zo}function z_(o){n.debug=n,n.default=n,n.coerce=u,n.disable=e,n.enable=a,n.enabled=d,n.humanize=Y_(),n.destroy=g,Object.keys(o).forEach(p=>{n[p]=o[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 I(...R){if(!I.enabled)return;const Q=I,P=Number(new Date),ye=P-(T||P);Q.diff=ye,Q.prev=T,Q.curr=P,T=P,R[0]=n.coerce(R[0]),typeof R[0]!="string"&&R.unshift("%O");let O=0;R[0]=R[0].replace(/%([a-zA-Z%])/g,(j,pe)=>{if(j==="%%")return"%";O++;const Te=n.formatters[pe];if(typeof Te=="function"){const N=R[O];j=Te.call(Q,N),R.splice(O,1),O--}return j}),n.formatArgs.call(Q,R),(Q.log||n.log).apply(Q,R)}return I.namespace=p,I.useColors=n.useColors(),I.color=n.selectColor(p),I.extend=i,I.destroy=n.destroy,Object.defineProperty(I,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(A!==n.namespaces&&(A=n.namespaces,w=n.enabled(p)),w),set:R=>{y=R}}),typeof n.init=="function"&&n.init(I),I}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 X_=z_;(function(o,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 ":" ")+"+"+o.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){}}o.exports=X_(s);const{formatters:_}=o.exports;_.j=function(u){try{return JSON.stringify(u)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}})(Yo,Yo.exports);var $s=Yo.exports;function Q_(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Uc(o,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(o,i.key,i)}}function J_(o,s,n){return s&&Uc(o.prototype,s),n&&Uc(o,n),o}var Vs=$s,Bs="JsSIP",ft=function(){function o(s){Q_(this,o),s?(this._debug=Vs.default("".concat(Bs,":").concat(s)),this._warn=Vs.default("".concat(Bs,":WARN:").concat(s)),this._error=Vs.default("".concat(Bs,":ERROR:").concat(s))):(this._debug=Vs.default(Bs),this._warn=Vs.default("".concat(Bs,":WARN")),this._error=Vs.default("".concat(Bs,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return J_(o,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),o}(),Pt={},Mc={},xc={exports:{}},Pc=xc.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(o){return o.encoding?"rtpmap:%d %s/%s/%s":o.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(o){return o.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(o){return o.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(o){return"extmap:%d"+(o.direction?"/%s":"%v")+(o["encrypt-uri"]?" %s":"%v")+" %s"+(o.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(o){return o.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(o){var s="candidate:%s %d %s %d %s %d typ %s";return s+=o.raddr!=null?" raddr %s rport %d":"%v%v",s+=o.tcptype!=null?" tcptype %s":"%v",o.generation!=null&&(s+=" generation %d"),s+=o["network-id"]!=null?" network-id %d":"%v",s+=o["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(o){var s="ssrc:%d";return o.attribute!=null&&(s+=" %s",o.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(o){return o.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(o){return o.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(o){return"imageattr:%s %s %s"+(o.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(o){return"simulcast:%s %s"+(o.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(o){return"ts-refclk:%s"+(o.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(o){var s="mediaclk:";return s+=o.id!=null?"id=%s %s":"%v%s",s+=o.mediaClockValue!=null?"=%s":"",s+=o.rateNumerator!=null?" rate=%s":"",s+=o.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(Pc).forEach(function(o){var s=Pc[o];s.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Lc=xc.exports;(function(o){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=Lc,e=RegExp.prototype.test.bind(/^([a-z])=(.*)/);o.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 I=a[y][w];if(I.reg.test(A))return i(I,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),_};o.parseParams=function(_){return _.split(/;\s?/).reduce(d,{})},o.parseFmtpConfig=o.parseParams,o.parsePayloads=function(_){return _.toString().split(" ").map(Number)},o.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},o.parseImageAttributes=function(_){return _.split(" ").map(function(u){return u.substring(1,u.length-1).split(",").reduce(d,{})})},o.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}})})}})(Mc);var Xo=Lc,Z_=/%[sdv%]/g,ef=function(o){var s=1,n=arguments,i=n.length;return o.replace(Z_,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""}})},ir=function(o,s,n){var i=s.format instanceof Function?s.format(s.push?n:n[s.name]):s.format,a=[o+"="+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 ef.apply(null,a)},tf=["v","o","s","i","u","e","p","c","b","t","r","z","a"],nf=["i","c","b","a"],sf=function(o,s){s=s||{},o.version==null&&(o.version=0),o.name==null&&(o.name=" "),o.media.forEach(function(e){e.payloads==null&&(e.payloads="")});var n=s.outerOrder||tf,i=s.innerOrder||nf,a=[];return n.forEach(function(e){Xo[e].forEach(function(d){d.name in o&&o[d.name]!=null?a.push(ir(e,d,o)):d.push in o&&o[d.push]!=null&&o[d.push].forEach(function(_){a.push(ir(e,d,_))})})}),o.media.forEach(function(e){a.push(ir("m",Xo.m[0],e)),i.forEach(function(d){Xo[d].forEach(function(_){_.name in e&&e[_.name]!=null?a.push(ir(d,_,e)):_.push in e&&e[_.push]!=null&&e[_.push].forEach(function(u){a.push(ir(d,_,u))})})})}),a.join(`\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 C(){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=C();r!==null;)t.push(r),r=C();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=C(),o!==null)for(r=[];o!==null;)r.push(o),o=C();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 Ce(){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=Ce(),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(A){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,A,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?(A=x(),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,A,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?(A=x(),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,A,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?(A=qe(),A!==null?t=[t,r,o,c,h,f,m,E,A]:(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,A;return E=e,A=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=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A),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,A){return A=parseInt(A.join("")),v.port=A,A}(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,A){v.uri_params||(v.uri_params={}),typeof A>"u"?A=void 0:A=A[1],v.uri_params[E.toLowerCase()]=A}(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=Cs(),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 Cs(){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(A){v.sip_version=n.substring(e,A)}(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 Ci(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function Ai(){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=Ci(),t===null&&(t=Ai(),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=Cs(),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 A,z;for(z=v.multi_header.length,A=0;A<z;A++)if(v.multi_header[A].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=As(),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=As(),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 A;v.multi_header||(v.multi_header=[]);try{A=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){A=null}v.multi_header.push({possition:e,offset:E,parsed:A})}(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,A){typeof A=="string"?v.display_name=A:v.display_name=A[1].reduce(function(z,be){return z+be[0]+be[1]},A[0])}(h,t)),t===null&&(e=h),t}function As(){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(A){return parseFloat(n.substring(e,A))}(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,A){v.params||(v.params={}),typeof A>"u"?A=void 0:A=A[1],v.params[E.toLowerCase()]=A}(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,A){v.event=A.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 A=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),A&&v.setParam("tag",A)}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,A,z;for(E=e,A=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=A)}else t=null,e=A;else t=null,e=A;else t=null,e=A;else t=null,e=A;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,A;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=[],A=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=A)):(f=null,e=A);f!==null;){if(h.push(f),A=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=A)):(f=null,e=A)}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,A,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(A=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=A)}else c=null,e=A;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 A,z;for(z=v.multi_header.length,A=0;A<z;A++)if(v.multi_header[A].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 A;v.multi_header||(v.multi_header=[]);try{A=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){A=null}v.multi_header.push({possition:e,offset:E,parsed:A})}(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,A){if(v.protocol=A.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 A=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),A&&v.setParam("tag",A)}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,A){v.rport=parseInt(A.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,A){v.port=parseInt(A.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,A,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?(A=So(),A!==null?t=[t,r,o,c,h,f,m,E,A]:(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(A){v=-1}}()),t===null&&(e=h),t}function lc(){var t,r,o,c,h,f;if(h=e,t=Co(),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 Co(){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=Ao(),t===null&&(t=bo(),t===null&&(t=Ro(),t===null&&(t=Oe()))),t}function Ao(){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,C=function(){};return{s:C,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(G){throw G},f:C}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var 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,C){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=C;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 C in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,C)){var w=l(this._headers[C]),R;try{for(w.s();!(R=w.n()).done;){var b=R.value;p.push("".concat(C,"=").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 C=0,w=function(){};return{s:w,n:function(){return C>=p.length?{done:!0}:{done:!1,value:p[C++]}},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,C=new Array(T);y<T;y++)C[y]=p[y];return C}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),C=1;C<T;C++)y[C-1]=arguments[C];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,C,w="";for(y=0;y<p;y++)C=Math.random()*T|0,w+=C.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,C=T==="x"?y:y&3|8;return C.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("@"),C,w;switch(y.length){case 1:if(!T)return;C=p,w=T;break;case 2:C=y[0],w=y[1];break;default:C=y.slice(0,y.length-1).join("@"),w=y[y.length-1]}C=C.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(C)&&(C=C.replace(/[-.()]/g,"")),p="".concat(a.SIP,":").concat(g(C),"@").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("-"),C="",w=y.length,R;for(R=0;R<w;R++)R!==0&&(C+="-"),C+=y[R].charAt(0).toUpperCase()+y[R].substring(1);return T[C]&&(C=T[C]),C},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 C(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(C(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,Ce=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],Ce,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],Ce,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],Ce,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],Ce,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),C;try{for(y.s();!(C=y.n()).done;){var w=C.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 Cc=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 Cc},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+".");Cc=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 Ac(l){return l._maxListeners===void 0?Pe.defaultMaxListeners:l._maxListeners}Pe.prototype.getMaxListeners=function(){return Ac(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=Ac(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]),C=(T[2]||"ms").toLowerCase();switch(C){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,C){var w=T>=y*1.5;return Math.round(p/y)+" "+C+(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,C,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:(C!==n.namespaces&&(C=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,]+/),C=y.length;for(T=0;T<C;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],C=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(C))return i(R,p,C)}}),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
|
|
7
7
|
`)+`\r
|
|
8
|
-
`},ss=
|
|
9
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var e=!0,d=!1,_;return{s:function(){n=
|
|
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 C=a.call_id||i.configuration.jssip_id+at.createRandomToken(15);this.call_id=C,this.setHeader("call-id",C);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
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
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
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
|
|
@@ -16,10 +16,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
16
16
|
\r
|
|
17
17
|
`),s+=this.body}else s+=`Content-Length: 0\r
|
|
18
18
|
\r
|
|
19
|
-
`;return s}},{key:"clone",value:function(){var s=new
|
|
20
|
-
`);if(this.method===gt.INVITE&&i>100&&i<=200){var y=this.getHeaders("record-route"),
|
|
21
|
-
`)}}catch(N){
|
|
22
|
-
`)}}catch(N){
|
|
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"),C=Kt(y),w;try{for(C.s();!(w=C.n()).done;){var R=w.value;T+="Record-Route: ".concat(R,`\r
|
|
21
|
+
`)}}catch(N){C.e(N)}finally{C.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
|
|
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
|
|
@@ -40,14 +40,14 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
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
|
|
43
|
+
`),this.ua.configuration.extra_headers){var T=Kt(this.ua.configuration.extra_headers),y;try{for(T.s();!(y=T.n()).done;){var C=y.value;d+="".concat(C.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}(Vc),ff=function(o){Qo(n,o);var s=Zo(n);function n(){var i;return lr(this,n),i=s.call(this),i.headers={},i.status_code=null,i.reason_phrase=null,i}return n}(Vc),Tn={OutgoingRequest:$c,InitialOutgoingInviteRequest:df,IncomingRequest:_f,IncomingResponse:ff};function pf(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Bc(o,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(o,i.key,i)}}function mf(o,s,n){return s&&Bc(o.prototype,s),n&&Bc(o,n),o}var gf=ft,vn=wt(),zt=new gf("DigestAuthentication"),Tf=function(){function o(s){pf(this,o),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 mf(o,[{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(", "))}}]),o}(),yn=500,vf=4e3,Kc=5e3,Gc={T1:yn,T2:vf,T4:Kc,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*Kc,TIMER_L:64*yn,TIMER_M:64*yn,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Fl(o){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fl=function(s){return typeof s}:Fl=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Fl(o)}function or(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Wc(o,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(o,i.key,i)}}function ar(o,s,n){return s&&Wc(o.prototype,s),n&&Wc(o,n),o}function ur(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&ta(o,s)}function ta(o,s){return ta=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ta(o,s)}function cr(o){var s=Ef();return function(){var n=jl(o),i;if(s){var a=jl(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return yf(this,i)}}function yf(o,s){return s&&(Fl(s)==="object"||typeof s=="function")?s:Wn(o)}function Wn(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function Ef(){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(o){return!1}}function jl(o){return jl=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},jl(o)}var hr=_t.EventEmitter,dr=ft,_r=ot,Yc=Tn,_n=Gc,zc=new dr("NonInviteClientTransaction"),$l=new dr("InviteClientTransaction"),Sf=new dr("AckClientTransaction"),Xc=new dr("NonInviteServerTransaction"),Vl=new dr("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"},Af=function(o){ur(n,o);var s=cr(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 ar(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(){zc.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(){zc.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}(hr),Cf=function(o){ur(n,o);var s=cr(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 ar(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&&($l.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(){$l.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(){$l.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(){$l.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 Yc.OutgoingRequest(_r.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 Yc.OutgoingRequest(_r.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}(hr),bf=function(o){ur(n,o);var s=cr(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 ar(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Sf.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ue}}]),n}(hr),Rf=function(o){ur(n,o);var s=cr(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 ar(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_J",value:function(){Xc.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,Xc.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}(hr),If=function(o){ur(n,o);var s=cr(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 ar(n,[{key:"stateChanged",value:function(i){this.state=i,this.emit("stateChanged")}},{key:"timer_H",value:function(){Vl.debug("Timer H expired for transaction ".concat(this.id)),this.state===ue.STATUS_COMPLETED&&Vl.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(){Vl.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,Vl.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}(hr);function wf(o,s){var n=o._transactions,i;switch(s.method){case _r.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 _r.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 _r.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 fr={C:ue,NonInviteClientTransaction:Af,InviteClientTransaction:Cf,AckClientTransaction:bf,NonInviteServerTransaction:Rf,InviteServerTransaction:If,checkTransaction:wf};function Of(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Qc(o,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(o,i.key,i)}}function Nf(o,s,n){return s&&Qc(o.prototype,s),n&&Qc(o,n),o}var Df=ft,Jc=ot,kf=Tf,na=fr,Uf=new Df("RequestSender"),sa={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},pr=function(){function o(s,n,i){Of(this,o),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 sa)Object.prototype.hasOwnProperty.call(sa,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=sa[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==Jc.BYE||this._method!==Jc.ACK)&&this._eventHandlers.onTransportError()}return Nf(o,[{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 na.InviteClientTransaction(this._ua,this._ua.transport,this._request,n);break;case"ACK":this.clientTransaction=new na.AckClientTransaction(this._ua,this._ua.transport,this._request,n);break;default:this.clientTransaction=new na.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){Uf.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 kf({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)}}]),o}();function Mf(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Zc(o,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(o,i.key,i)}}function xf(o,s,n){return s&&Zc(o.prototype,s),n&&Zc(o,n),o}var Pf=ft,ra=wt(),rs=ot,eh=Tn,th=pr,mr=new Pf("Registrator"),Bl=10,Lf=function(){function o(s,n){Mf(this,o),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=ra.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 xf(o,[{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){mr.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 eh.OutgoingRequest(rs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n),a=new th(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")){mr.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})),!_){mr.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<Bl&&(u=Bl);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<Bl&&(s._expires=Bl),s.register()):(mr.debug("423 response received for REGISTER without Min-Expires"),s._registrationFailure(e,rs.causes.SIP_FAILURE_CODE));break}default:{var p=ra.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){mr.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 eh.OutgoingRequest(rs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},i),e=new th(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 _=ra.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}}]),o}();function Hf(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function nh(o,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(o,i.key,i)}}function qf(o,s,n){return s&&nh(o.prototype,s),n&&nh(o,n),o}var ia=ot,Kl=fr,Ff=pr,la={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},jf=function(){function o(s,n,i){Hf(this,o),this._dialog=s,this._ua=s._ua,this._request=n,this._eventHandlers=i,this._reattempt=!1,this._reattemptTimer=null;for(var a in la)Object.prototype.hasOwnProperty.call(la,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=la[a]))}return qf(o,[{key:"send",value:function(){var s=this,n=new Ff(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===ia.INVITE||this._request.method===ia.UPDATE&&this._request.body)&&n.clientTransaction.state!==Kl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var i=function a(){(n.clientTransaction.state===Kl.C.STATUS_ACCEPTED||n.clientTransaction.state===Kl.C.STATUS_COMPLETED||n.clientTransaction.state===Kl.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===ia.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}}]),o}();function $f(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function sh(o,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(o,i.key,i)}}function rh(o,s,n){return s&&sh(o.prototype,s),n&&sh(o,n),o}var Vf=ft,ih=Tn,Yn=ot,gr=fr,Bf=jf,oa=wt(),aa=new Vf("Dialog"),zn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Kf=function(){rh(o,null,[{key:"C",get:function(){return zn}}]);function o(s,n,i){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:zn.STATUS_CONFIRMED;if($f(this,o),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 ih.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),aa.debug("new ".concat(i," dialog created with status ").concat(this._state===zn.STATUS_EARLY?"EARLY":"CONFIRMED"))}return rh(o,[{key:"isTerminated",value:function(){return this._status===zn.STATUS_TERMINATED}},{key:"update",value:function(s,n){this._state=zn.STATUS_CONFIRMED,aa.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),n==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){aa.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 Bf(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 ih.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===gr.C.STATUS_ACCEPTED||s.server_transaction.state===gr.C.STATUS_COMPLETED||s.server_transaction.state===gr.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===gr.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===gr.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}}]),o}(),ua={exports:{}};function Gl(o){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Gl=function(s){return typeof s}:Gl=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Gl(o)}function Gf(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function lh(o,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(o,i.key,i)}}function Wf(o,s,n){return s&&lh(o.prototype,s),n&&lh(o,n),o}function Yf(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&ca(o,s)}function ca(o,s){return ca=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ca(o,s)}function zf(o){var s=Jf();return function(){var n=Wl(o),i;if(s){var a=Wl(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Xf(this,i)}}function Xf(o,s){return s&&(Gl(s)==="object"||typeof s=="function")?s:Qf(o)}function Qf(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function Jf(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(o){return!1}}function Wl(o){return Wl=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Wl(o)}var Zf=_t.EventEmitter,ep=ft,tp=ot,np=Kn,oh=wt(),sp=new ep("RTCSession:DTMF"),ah={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ua.exports=function(o){Yf(n,o);var s=zf(n);function n(i){var a;return Gf(this,n),a=s.call(this),a._session=i,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return Wf(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 np.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(
|
|
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=
|
|
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}(
|
|
50
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var e=!0,d=!1,_;return{s:function(){n=o[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 Up(o,s){if(o){if(typeof o=="string")return fh(o,s);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor&&(n=o.constructor.name),n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return fh(o,s)}}function fh(o,s){(s==null||s>o.length)&&(s=o.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=o[n];return i}function Mp(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function ph(o,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(o,i.key,i)}}function mh(o,s,n){return s&&ph(o.prototype,s),n&&ph(o,n),o}function xp(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&fa(o,s)}function fa(o,s){return fa=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},fa(o,s)}function Pp(o){var s=qp();return function(){var n=Zl(o),i;if(s){var a=Zl(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Lp(this,i)}}function Lp(o,s){return s&&(Jl(s)==="object"||typeof s=="function")?s:Hp(o)}function Hp(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function qp(){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(o){return!1}}function Zl(o){return Zl=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},Zl(o)}var Fp=_t.EventEmitter,gh=Pt,jp=ft,ce=ot,ls=Kn,Th=fr,Ge=wt(),vr=Gc,$p=Tn,eo=Kf,Vp=pr,$t=rp,vh=mp,Bp=Ep,Kp=kp,yh=Gn(),B=new jp("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},to=["audio","video"],Gp=function(o){xp(n,o);var s=Pp(n);mh(n,null,[{key:"C",get:function(){return z}}]);function n(i){var a;return Mp(this,n),B.debug("new"),a=s.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:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},a._referSubscribers={},a._data={},a}return mh(n,[{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,_=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!==z.STATUS_NULL)throw new ls.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new ls.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 I=a.anonymous||!1,R={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(R.from_display_name="Anonymous",R.from_uri=new yh("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 yh("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 $p.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,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=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=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=z.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===z.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!==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=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,I=!1,R=!1,Q=!1;if(this._rtcAnswerConstraints=T,this._rtcOfferConstraints=a.rtcOfferConstraints||null,this._data=a.data||this._data,this._direction!=="incoming")throw new ls.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==z.STATUS_WAITING_FOR_ANSWER)throw new ls.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=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 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")&&(R=!0)),j.type==="video"&&(I=!0,(!j.direction||j.direction==="sendrecv")&&(Q=!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=R),!u&&_.video===void 0&&(_.video=Q),!u&&!w&&!y.offerToReceiveAudio&&(_.audio=!1),!u&&!I&&!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===z.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===z.STATUS_TERMINATED)throw new Error("terminated");i._localMediaStream=M,M&&M.getTracks().forEach(function(G){i._connection.addTrack(G,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 G=new RTCSessionDescription({type:"offer",sdp:M.sdp});return i._connectionPromiseQueue=i._connectionPromiseQueue.then(function(){return i._connection.setRemoteDescription(G)}).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===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(M){if(i._status===z.STATUS_TERMINATED)throw new Error("terminated");i._handleSessionTimersInIncomingRequest(e,d),e.reply(200,null,d,M,function(){i._status=z.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!==z.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===z.STATUS_TERMINATED)throw new ls.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&&(p=p||ce.REASON_PHRASE[g]||"",u="SIP ;cause=".concat(g,' ;text="').concat(p,'"')),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,ce.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,p,d,_),this._failed("local",null,ce.causes.REJECTED);break;case z.STATUS_WAITING_FOR_ACK:case z.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===z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Th.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===Th.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!==z.STATUS_CONFIRMED&&this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_1XX_RECEIVED)throw new ls.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===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 $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!==z.STATUS_CONFIRMED&&this._status!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.STATUS_1XX_RECEIVED)throw new ls.InvalidStateError(this._status);var d=new vh(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: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!==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: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!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.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!==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 Kp(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===z.STATUS_WAITING_FOR_ANSWER||this._status===z.STATUS_ANSWERED)&&(this._status=z.STATUS_CANCELED,this._request.reply(487),this._failed("remote",i,ce.causes.CANCELED));else switch(i.method){case ce.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: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===z.STATUS_CONFIRMED||this._status===z.STATUS_WAITING_FOR_ACK?(i.reply(200),this._ended("remote",i,ce.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,ce.causes.BYE)):i.reply(403,"Wrong Status");break;case ce.INVITE:this._status===z.STATUS_CONFIRMED?i.hasHeader("replaces")?this._receiveReplaces(i):this._receiveReinvite(i):i.reply(403,"Wrong Status");break;case ce.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 $t(this).init_incoming(i):_!==void 0?new vh(this).init_incoming(i):i.reply(415)}else i.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===z.STATUS_CONFIRMED?this._receiveUpdate(i):i.reply(403,"Wrong Status");break;case ce.REFER:this._status===z.STATUS_CONFIRMED?this._receiveRefer(i):i.reply(403,"Wrong Status");break;case ce.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:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){B.warn("onRequestTimeout()"),this._status!==z.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!==z.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!==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=vr.T1;function d(){this._status===z.STATUS_WAITING_FOR_ACK&&(i.reply(200,null,["Contact: ".concat(this._contact)],a),e<vr.T2&&(e=e*2,e>vr.T2&&(e=vr.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(ce.BYE),i._ended("remote",null,ce.causes.NO_ACK))},vr.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 I=w.candidate;I?e.emit("icecandidate",{candidate:I,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 eo(this,i,a,eo.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 eo(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!==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(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!==z.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=z.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!==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(p){a._status!==z.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(to.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===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!==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 Bp(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 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!==z.STATUS_WAITING_FOR_ACK&&this._status!==z.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 Vp(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,ce.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,ce.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(ce.ACK);return}else{var e=new eo(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!==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,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!==z.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(I){p.call(y),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',I),y.emit("peerconnection:setremotedescriptionfailed",I)})}}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!==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 I=new RTCSessionDescription({type:"answer",sdp:w.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(I)}).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||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=z.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(i){if(!this._localHold&&!this._remoteHold)return i;if(i=gh.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;to.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;to.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;to.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 gh.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!==z.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!==z.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 z}},{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}(Fp);function no(o){"@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(o)}function Wp(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Eh(o,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(o,i.key,i)}}function Yp(o,s,n){return s&&Eh(o.prototype,s),n&&Eh(o,n),o}function zp(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&pa(o,s)}function pa(o,s){return pa=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},pa(o,s)}function Xp(o){var s=Zp();return function(){var n=so(o),i;if(s){var a=so(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Qp(this,i)}}function Qp(o,s){return s&&(no(s)==="object"||typeof s=="function")?s:Jp(o)}function Jp(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function Zp(){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(o){return!1}}function so(o){return so=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},so(o)}var em=_t.EventEmitter,tm=ft,ma=ot,nm=Tn,yr=wt(),sm=pr,Sh=Kn,rm=Gn(),ro=new tm("Message"),im=function(o){zp(n,o);var s=Xp(n);function n(i){var a;return Wp(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 Yp(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=yr.cloneArray(d.extraHeaders),g=yr.cloneObject(d.eventHandlers),p=d.contentType||"text/plain",T={};d.fromUserName&&(T.from_uri=new rm("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 nm.OutgoingRequest(ma.MESSAGE,i,this._ua,T,u),a&&(this._request.body=a);var A=new sm(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=yr.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new Sh.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=yr.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new Sh.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=yr.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,ma.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,ma.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){ro.debug("MESSAGE failed"),this._close(),ro.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){ro.debug("MESSAGE succeeded"),this._close(),ro.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}(em);function io(o){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?io=function(s){return typeof s}:io=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},io(o)}function lm(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Ah(o,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(o,i.key,i)}}function om(o,s,n){return s&&Ah(o.prototype,s),n&&Ah(o,n),o}function am(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&ga(o,s)}function ga(o,s){return ga=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},ga(o,s)}function um(o){var s=dm();return function(){var n=lo(o),i;if(s){var a=lo(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return cm(this,i)}}function cm(o,s){return s&&(io(s)==="object"||typeof s=="function")?s:hm(o)}function hm(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function dm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(o){return!1}}function lo(o){return lo=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},lo(o)}var _m=_t.EventEmitter,fm=ft,Ta=ot,pm=Tn,Er=wt(),mm=pr,Ch=Kn,oo=new fm("Options"),gm=function(o){am(n,o);var s=um(n);function n(i){var a;return lm(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=Er.cloneArray(d.extraHeaders),g=Er.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 pm.OutgoingRequest(Ta.OPTIONS,i,this._ua,null,u),a&&(this._request.body=a);var y=new mm(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=Er.cloneArray(i.extraHeaders),e=i.body;if(this._direction!=="incoming")throw new Ch.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=Er.cloneArray(i.extraHeaders),_=i.body;if(this._direction!=="incoming")throw new Ch.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=Er.sipErrorCause(i.status_code);this._failed("remote",i,a);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Ta.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Ta.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){oo.debug("OPTIONS failed"),this._close(),oo.debug('emit "failed"'),this.emit("failed",{originator:i,response:a||null,cause:e})}},{key:"_succeeded",value:function(i,a){oo.debug("OPTIONS succeeded"),this._close(),oo.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}(_m),va={},Tm=ft,ya=wt(),vm=dn(),Sr=new Tm("Socket");va.isSocket=function(o){if(Array.isArray(o))return!1;if(typeof o>"u")return Sr.warn("undefined JsSIP.Socket instance"),!1;try{if(!ya.isString(o.url))throw Sr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!ya.isString(o.via_transport))throw Sr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(vm.parse(o.sip_uri,"SIP_URI")===-1)throw Sr.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(!ya.isFunction(o[s]))throw Sr.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 ym(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function bh(o,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(o,i.key,i)}}function Em(o,s,n){return s&&bh(o.prototype,s),n&&bh(o,n),o}var Sm=ft,Am=va,Rh=ot,Lt=new Sm("Transport"),Gt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Rh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Rh.CONNECTION_RECOVERY_MAX_INTERVAL}},Cm=function(){function o(s){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Gt.recovery_options;ym(this,o),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(!Am.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 Em(o,[{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:
|
|
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),Cf=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),Af=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:Cf,AckClientTransaction:Af,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 Cp(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 Ap(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){Cp(n,l);var s=Ap(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(C){return C.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(C){a._requestSucceeded(C)},onErrorResponse:function(C){a._requestFailed(C,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,C=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=C,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,C,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),C,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){C=u.getAudioTracks();var pe=En(C),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){C=u.getVideoTracks();var H=En(C),$;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 C=y.method;C===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 C=this._tones[e];if(e+=1,C===",")y=2e3;else{var w=new $t(this);a.eventHandlers={onFailed:function(){T._tones=null}},w.send(C,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 C=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:C}):p||C()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!p&&C()})})})}},{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||"",C=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,C)}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||"",C=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,C)}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(C){_.e(C)}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(C){throw i.reply(488),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',C),a.emit("peerconnection:setremotedescriptionfailed",C),C})}).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(C){throw i.reply(500),B.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',C),C})}).catch(function(C){B.warn("_processInDialogSdpOffer() failed [error: %o]",C)}),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 C=y.response;e.notify(C.status_code,C.reason_phrase)}),p.on("accepted",function(y){var C=y.response;e.notify(C.status_code,C.reason_phrase)}),p.on("_failed",function(y){var C=y.message,w=y.cause;C?e.notify(C.status_code,C.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(C){g.call(i,C),u=!0},onErrorResponse:function(C){p.call(i,C)},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 C={originator:"remote",type:"answer",sdp:T.body};B.debug('emit "sdp"'),this.emit("sdp",C);var w=new RTCSessionDescription({type:"answer",sdp:C.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 C={originator:"local",type:"offer",sdp:y};B.debug('emit "sdp"'),i.emit("sdp",C),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 C=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 C._connection.setRemoteDescription(R)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(b){T.call(C),B.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',b),C.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(C){a.e(C)}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(C){_.e(C)}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(C){p.e(C)}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 C=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),C.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,Ch=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(C){e._receiveResponse(C)}});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 Ch.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 Ch.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 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 ym(l,s,n){return s&&Ah(l.prototype,s),n&&Ah(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}},Cm=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
51
|
|
|
52
52
|
`.concat(n,`
|
|
53
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
|
|
@@ -57,22 +57,22 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
57
57
|
`))}else Lt.debug(`received text message:
|
|
58
58
|
|
|
59
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}}]),
|
|
61
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var e=!0,d=!1,_;return{s:function(){n=
|
|
62
|
-
`);if(a===-1){
|
|
63
|
-
`,n),a===-1)return a;!
|
|
64
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var e=!0,d=!1,_;return{s:function(){n=
|
|
65
|
-
`),a=
|
|
66
|
-
`)}}catch(_){a.e(_)}finally{a.f()}n=Fe.getHeader("To"),Fe.to_tag||(n+=";tag=".concat(
|
|
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=Am(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 Am(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 C=y.value;l.addHeader("contact",_.substring(C.possition,C.offset)),l.headers.Contact[l.getHeaders("contact").length-1].parsed=C.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(),Ca=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 Ca.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 Ca.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 Ca.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
67
|
`),i+="From: ".concat(Fe.getHeader("From"),`\r
|
|
68
68
|
`),i+="Call-ID: ".concat(Fe.call_id,`\r
|
|
69
69
|
`),i+="CSeq: ".concat(Fe.cseq," ").concat(Fe.method,`\r
|
|
70
70
|
`),i+=`\r
|
|
71
|
-
`,
|
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var e=!0,d=!1,_;return{s:function(){n=o[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 $m(o,s){if(o){if(typeof o=="string")return xh(o,s);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor&&(n=o.constructor.name),n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return xh(o,s)}}function xh(o,s){(s==null||s>o.length)&&(s=o.length);for(var n=0,i=new Array(s);n<s;n++)i[n]=o[n];return i}var Ks=wt(),os=ot,Ra=dn(),Ph=Gn(),Ia=va,wa=Kn;ba.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:"".concat(Ks.createRandomToken(12),".invalid")};var co={mandatory:{sockets:function(o){var s=[];if(Ia.isSocket(o))s.push({socket:o});else if(Array.isArray(o)&&o.length){var n=Mh(o),i;try{for(n.s();!(i=n.n()).done;){var a=i.value;Object.prototype.hasOwnProperty.call(a,"socket")&&Ia.isSocket(a.socket)?s.push(a):Ia.isSocket(a)&&s.push({socket:a})}}catch(e){n.e(e)}finally{n.f()}}else return;return s},uri:function(o){/^sip:/i.test(o)||(o="".concat(os.SIP,":").concat(o));var s=Ph.parse(o);if(s)return s.user?s:void 0}},optional:{authorization_user:function(o){if(Ra.parse('"'.concat(o,'"'),"quoted_string")!==-1)return o},authorization_jwt:function(o){if(typeof o=="string")return o},user_agent:function(o){if(typeof o=="string")return o},connection_recovery_max_interval:function(o){if(Ks.isDecimal(o)){var s=Number(o);if(s>0)return s}},connection_recovery_min_interval:function(o){if(Ks.isDecimal(o)){var s=Number(o);if(s>0)return s}},contact_uri:function(o){if(typeof o=="string"){var s=Ra.parse(o,"SIP_URI");if(s!==-1)return s}},display_name:function(o){return o},instance_id:function(o){if(/^uuid:/i.test(o)&&(o=o.substr(5)),Ra.parse(o,"uuid")!==-1)return o},no_answer_timeout:function(o){if(Ks.isDecimal(o)){var s=Number(o);if(s>0)return s}},session_timers:function(o){if(typeof o=="boolean")return o},session_timers_refresh_method:function(o){if(typeof o=="string"&&(o=o.toUpperCase(),o===os.INVITE||o===os.UPDATE))return o},session_timers_force_refresher:function(o){if(typeof o=="boolean")return o},password:function(o){return String(o)},realm:function(o){return String(o)},ha1:function(o){return String(o)},register:function(o){if(typeof o=="boolean")return o},register_expires:function(o){if(Ks.isDecimal(o)){var s=Number(o);if(s>0)return s}},registrar_server:function(o){/^sip:/i.test(o)||(o="".concat(os.SIP,":").concat(o));var s=Ph.parse(o);if(s)return s.user?void 0:s},use_preloaded_route:function(o){if(typeof o=="boolean")return o},extra_headers:function(o){var s=[];if(Array.isArray(o)&&o.length){var n=Mh(o),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}}};ba.load=function(o,s){for(var n in co.mandatory)if(s.hasOwnProperty(n)){var i=s[n],a=co.mandatory[n](i);if(a!==void 0)o[n]=a;else throw new wa.ConfigurationError(n,i)}else throw new wa.ConfigurationError(n);for(var e in co.optional)if(s.hasOwnProperty(e)){var d=s[e];if(Ks.isEmpty(d))continue;var _=co.optional[e](d);if(_!==void 0)o[e]=_;else throw new wa.ConfigurationError(e,d)}};function ho(o){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ho=function(s){return typeof s}:ho=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},ho(o)}function Vm(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Lh(o,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(o,i.key,i)}}function Hh(o,s,n){return s&&Lh(o.prototype,s),n&&Lh(o,n),o}function Bm(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(s&&s.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),s&&Oa(o,s)}function Oa(o,s){return Oa=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},Oa(o,s)}function Km(o){var s=Wm();return function(){var n=_o(o),i;if(s){var a=_o(this).constructor;i=Reflect.construct(n,arguments,a)}else i=n.apply(this,arguments);return Gm(this,i)}}function Gm(o,s){return s&&(ho(s)==="object"||typeof s=="function")?s:qh(o)}function qh(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function Wm(){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(o){return!1}}function _o(o){return _o=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},_o(o)}var Ym=_t.EventEmitter,zm=ft,Tt=ot,Xm=Lf,Fh=Gp,jh=im,$h=gm,Na=fr,Qm=Cm,fo=wt(),Jm=Kn,Zm=Gn(),eg=Ih,Da=Tn,tg=Mm,ka=ba,Ve=new zm("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},ng=function(o){Bm(n,o);var s=Km(n);Hh(n,null,[{key:"C",get:function(){return vt}}]);function n(i){var a;if(Vm(this,n),Ve.debug("new() [configuration:%o]",i),a=s.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},ka.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=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 Xm(qh(a)),a}return Hh(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 Fh(this);return e.connect(i,a),e}},{key:"sendMessage",value:function(i,a,e){Ve.debug("sendMessage()");var d=new jh(this);return d.send(i,a,e),d}},{key:"sendOptions",value:function(i,a,e){Ve.debug("sendOptions()");var d=new $h(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 fo.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(!Na.checkTransaction(this,i)){if(a===Tt.INVITE?new Na.InviteServerTransaction(this,this._transport,i):a!==Tt.ACK&&a!==Tt.CANCEL&&new Na.NonInviteServerTransaction(this,this._transport,i),a===Tt.OPTIONS){if(this.listeners("newOptions").length===0){i.reply(200);return}var e=new $h(this);e.init_incoming(i)}else if(a===Tt.MESSAGE){if(this.listeners("newMessage").length===0){i.reply(405);return}var d=new jh(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 Fh(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{ka.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=fo.newUUID()),this._configuration.jssip_id=fo.createRandomToken(5);var a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Qm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=sg.bind(this),this._transport.onconnect=rg.bind(this),this._transport.ondisconnect=ig.bind(this),this._transport.ondata=lg.bind(this)}catch(g){throw Ve.warn(g),new Jm.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 Zm("sip",fo.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(ka.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}(Ym);function sg(o){this.emit("connecting",o)}function rg(o){this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_READY,this._error=null,this.emit("connected",o),this._dynConfiguration.register&&this._registrator.register())}function ig(o){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",o),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function lg(o){var s=o.transport,n=o.message;if(n=eg.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof Da.IncomingRequest)&&tg(n,this,s)){if(n instanceof Da.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof Da.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(o,s){if(!(o instanceof s))throw new TypeError("Cannot call a class as a function")}function Vh(o,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(o,i.key,i)}}function ag(o,s,n){return s&&Vh(o.prototype,s),n&&Vh(o,n),o}var ug=ft,cg=dn(),Dt=new ug("WebSocketInterface"),hg=function(){function o(s){og(this,o),Dt.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=cg.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 ag(o,[{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}}]),o}(),Ua=Ol,dg=ot,_g=Kn,fg=wt(),pg=ng,mg=Gn(),gg=Ko(),Tg=dn(),vg=hg,yg=$s("JsSIP");yg("version %s",Ua.version);var Bh={C:dg,Exceptions:_g,Utils:fg,UA:pg,URI:mg,NameAddrHeader:gg,WebSocketInterface:vg,Grammar:Tg,debug:$s,get name(){return Ua.title},get version(){return Ua.version}};const Gs=$s,Ws="JsSIP";var ht=class{constructor(o){o?(this._debug=Gs.default(`${Ws}:${o}`),this._warn=Gs.default(`${Ws}:WARN:${o}`),this._error=Gs.default(`${Ws}:ERROR:${o}`)):(this._debug=Gs.default(Ws),this._warn=Gs.default(`${Ws}:WARN`),this._error=Gs.default(`${Ws}: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 po=$e(ht),Kh=Ol;var Ne={USER_AGENT:`${Kh.title} ${Kh.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={},Ma,Gh;function xa(){if(Gh)return Ma;Gh=1;const o=Sn(),s=Xt();return Ma=class E_{static parse(i){if(i=s.parse(i,"Name_Addr_Header"),i!==-1)return i}constructor(i,a,e){if(!i||!(i instanceof o))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 E_(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}},Ma}var Wh,Yh;function Xt(){return Yh||(Yh=1,Wh=function(){function o(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:I,SP:R,HTAB:Q,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:G,LHEX:te,token:b,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:ms,password:Br,hostport:Nn,host:nn,hostname:gs,domainlabel:Ts,toplabel:Kr,IPv6reference:vs,IPv6address:ys,h16:x,ls32:qe,IPv4address:sn,dec_octet:rn,port:Gr,uri_parameters:Wr,uri_parameter:Es,transport_param:Yr,user_param:zr,method_param:Xr,ttl_param:Qr,maddr_param:Jr,lr_param:Zr,other_param:ei,pname:ti,pvalue:ni,paramchar:ln,param_unreserved:si,headers:ri,header:Dn,hname:ii,hvalue:li,hnv_unreserved:on,Request_Response:Nu,Request_Line:oi,Request_URI:ai,absoluteURI:Ss,hier_part:ui,net_path:ci,abs_path:kn,opaque_part:hi,uric:an,uric_no_slash:di,path_segments:_i,segment:Un,param:As,pchar:un,scheme:fi,authority:pi,srvr:mi,reg_name:gi,query:Ti,SIP_Version:Cs,INVITEm:vi,ACKm:yi,OPTIONSm:Ei,BYEm:Si,CANCELm:Ai,REGISTERm:Ci,SUBSCRIBEm:bi,NOTIFYm:Ri,REFERm:Ii,Method:Mn,Status_Line:wi,Status_Code:Oi,extension_code:Ni,Reason_Phrase:Di,Allow_Events:Du,Call_ID:ku,Contact:Uu,contact_param:xn,name_addr:Mt,display_name:Pn,contact_params:bs,c_p_q:ki,c_p_expires:Ui,delta_seconds:xt,qvalue:Mi,generic_param:Oe,gen_value:xi,Content_Disposition:Mu,disp_type:Pi,disp_param:Rs,handling_param:Li,Content_Encoding:xu,Content_Length:Pu,Content_Type:Lu,media_type:Hi,m_type:qi,discrete_type:Fi,composite_type:ji,extension_token:Ln,x_token:$i,m_subtype:Vi,m_parameter:Is,m_value:Bi,CSeq:Hu,CSeq_value:Ki,Expires:qu,Event:Fu,event_type:cn,From:ju,from_param:ws,tag_param:Os,Max_Forwards:$u,Min_Expires:Vu,Name_Addr_Header:Bu,Proxy_Authenticate:Ku,challenge:Ns,other_challenge:Gi,auth_param:hn,digest_cln:Hn,realm:Wi,realm_value:Yi,domain:zi,URI:qn,nonce:Xi,nonce_value:Qi,opaque:Ji,stale:Zi,algorithm:el,qop_options:tl,qop_value:Fn,Proxy_Require:Gu,Record_Route:Wu,rec_route:jn,Reason:Yu,reason_param:Ds,reason_cause:nl,Require:zu,Route:Xu,route_param:$n,Subscription_State:Qu,substate_value:sl,subexp_params:ks,event_reason_value:rl,Subject:Ju,Supported:Zu,To:ec,to_param:Us,Via:tc,via_param:Vn,via_params:Ms,via_ttl:il,via_maddr:ll,via_received:ol,via_branch:al,response_port:ul,rport:cl,sent_protocol:hl,protocol_name:dl,transport:_l,sent_by:fl,via_host:pl,via_port:ml,ttl:xs,WWW_Authenticate:nc,Session_Expires:sc,s_e_expires:gl,s_e_params:Ps,s_e_refresher:Tl,extension_header:rc,header_value:vl,message_body:ic,uuid_URI:lc,uuid:yl,hex4:dt,hex8:El,hex12:Sl,Refer_To:oc,Replaces:ac,call_id:Al,replaces_param:Ls,to_tag:Cl,from_tag:bl,early_flag:Rl};if(i!==void 0){if(a[i]===void 0)throw new Error("Invalid rule name: "+o(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
|
+
`,kh.send(i)}var Aa={};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;Aa.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}}};Aa.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=Cm,_l=wt(),Qm=Kn,Jm=Gn(),Zm=Rh,Na=Tn,eg=Um,Da=Aa,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:C,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:Ce,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:Cs,INVITEm:Ti,ACKm:vi,OPTIONSm:yi,BYEm:Ei,CANCELm:Si,REGISTERm:Ci,SUBSCRIBEm:Ai,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:As,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:Co,replaces_param:Ps,to_tag:Ao,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
|
|
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=R(),t===null&&(t=Q()),t}function w(){var t;return/^[\0-\xFF]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u("[\\0-\\xFF]")),t}function I(){var t;return/^["]/.test(n.charAt(e))?(t=n.charAt(e),e++):(t=null,u('["]')),t}function R(){var t;return n.charCodeAt(e)===32?(t=" ",e++):(t=null,u('" "')),t}function Q(){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,l,c,h;return c=e,h=e,n.charCodeAt(e)===37?(t="%",e++):(t=null,u('"%"')),t!==null?(r=y(),r!==null?(l=y(),l!==null?t=[t,r,l]:(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,l,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(l=A(),l!==null)for(r=[];l!==null;)r.push(l),l=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,l,c,h;for(c=e,h=e,t=[],r=R(),r===null&&(r=Q());r!==null;)t.push(r),r=R(),r===null&&(r=Q());return t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,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,l=[],c=Te();c!==null;)l.push(c),c=Te();for(l!==null?(c=q(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;){for(r.push(l),m=e,l=[],c=Te();c!==null;)l.push(c),c=Te();l!==null?(c=q(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 G(){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 b(){var t,r,l;if(l=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)}(l)),t===null&&(e=l),t}function J(){var t,r,l;if(l=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)}(l)),t===null&&(e=l),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=I(),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=R(),t===null&&(t=Q())))))))))))))))))),t}function Ye(){var t,r,l;if(l=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=I(),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=I(),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)}(l)),t===null&&(e=l),t}function ee(){var t,r,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===42?(r="*",e++):(r=null,u('"*"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===47?(r="/",e++):(r=null,u('"/"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===40?(r="(",e++):(r=null,u('"("')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===41?(r=")",e++):(r=null,u('")"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c;return l=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=l),t}function xe(){var t,r,l,c;return l=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=l),t}function _e(){var t,r,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===44?(r=",",e++):(r=null,u('","')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c,h;return c=e,h=e,t=N(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=N(),l!==null?t=[t,r,l]:(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,l,c;return l=e,c=e,t=N(),t!==null?(r=I(),r!==null?t=[t,r]:(t=null,e=c)):(t=null,e=c),t!==null&&(t=function(h){return'"'}()),t===null&&(e=l),t}function Ee(){var t,r,l,c;return l=e,c=e,t=I(),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=l),t}function ge(){var t,r,l,c;if(c=e,t=Ae(),t!==null){for(r=[],l=Re(),l===null&&(l=ae(),l===null&&(l=ge()));l!==null;)r.push(l),l=Re(),l===null&&(l=ae(),l===null&&(l=ge()));r!==null?(l=me(),l!==null?t=[t,r,l]:(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,l,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=I(),r!==null){for(l=[],c=fe(),c===null&&(c=ae());c!==null;)l.push(c),c=fe(),c===null&&(c=ae());l!==null?(c=I(),c!==null?t=[t,r,l,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,l,c,h,f;if(h=e,f=e,t=N(),t!==null)if(r=I(),r!==null){for(l=[],c=fe(),c===null&&(c=ae());c!==null;)l.push(c),c=fe(),c===null&&(c=ae());l!==null?(c=I(),c!==null?t=[t,r,l,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,l;return l=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=l)):(t=null,e=l),t}function Se(){var t,r,l,c,h,f;return h=e,f=e,t=Ke(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=Ft(),l=l!==null?l:"",l!==null?(c=Nn(),c!==null?t=[t,r,l,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 Il(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,l,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?(l=Ft(),l=l!==null?l:"",l!==null?(c=Nn(),c!==null?(h=Wr(),h!==null?(f=ri(),f=f!==null?f:"",f!==null?t=[t,r,l,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 Il(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(Y){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(l,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(l,c){v.scheme=c.toLowerCase()}(r,t)),t===null&&(e=r),t}function Ft(){var t,r,l,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?(l=Br(),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f),r=r!==null?r:"",r!==null?(n.charCodeAt(e)===64?(l="@",e++):(l=null,u('"@"')),l!==null?t=[t,r,l]:(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=ms())),r!==null)for(t=[];r!==null;)t.push(r),r=O(),r===null&&(r=pe(),r===null&&(r=ms()));else t=null;return t}function ms(){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 Br(){var t,r,l;for(l=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)}(l)),t===null&&(e=l),t}function Nn(){var t,r,l,c,h;return c=e,t=nn(),t!==null?(h=e,n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=Gr(),l!==null?r=[r,l]:(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=gs(),t===null&&(t=sn(),t===null&&(t=vs())),t!==null&&(t=function(l){return v.host=n.substring(e,l).toLowerCase(),v.host}(r)),t===null&&(e=r),t}function gs(){var t,r,l,c,h,f;for(c=e,h=e,t=[],f=e,r=Ts(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f);r!==null;)t.push(r),f=e,r=Ts(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?r=[r,l]:(r=null,e=f)):(r=null,e=f);return t!==null?(r=Kr(),r!==null?(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l=l!==null?l:"",l!==null?t=[t,r,l]:(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 Ts(){var t,r,l,c;if(c=e,t=P(),t!==null){for(r=[],l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));l!==null;)r.push(l),l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function Kr(){var t,r,l,c;if(c=e,t=T(),t!==null){for(r=[],l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));l!==null;)r.push(l),l=P(),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===95?(l="_",e++):(l=null,u('"_"'))));r!==null?t=[t,r]:(t=null,e=c)}else t=null,e=c;return t}function vs(){var t,r,l,c,h;return c=e,h=e,n.charCodeAt(e)===91?(t="[",e++):(t=null,u('"["')),t!==null?(r=ys(),r!==null?(n.charCodeAt(e)===93?(l="]",e++):(l=null,u('"]"')),l!==null?t=[t,r,l]:(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 ys(){var t,r,l,c,h,f,m,E,C,Y,be,it,Bn,qs,S,L;return qs=e,S=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=x(),l!==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?(Y=":",e++):(Y=null,u('":"')),Y!==null?(be=x(),be!==null?(n.charCodeAt(e)===58?(it=":",e++):(it=null,u('":"')),it!==null?(Bn=qe(),Bn!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=":",e++):(l=null,u('":"')),l!==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?(Y=x(),Y!==null?(n.charCodeAt(e)===58?(be=":",e++):(be=null,u('":"')),be!==null?(it=qe(),it!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=":",e++):(l=null,u('":"')),l!==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?(Y=qe(),Y!==null?t=[t,r,l,c,h,f,m,E,C,Y]:(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?(l=":",e++):(l=null,u('":"')),l!==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,l,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?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?(n.charCodeAt(e)===58?(h=":",e++):(h=null,u('":"')),h!==null?(f=qe(),f!==null?t=[t,r,l,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?(l=":",e++):(l=null,u('":"')),l!==null?(c=qe(),c!==null?t=[t,r,l,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?(l=x(),l!==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?(Y=":",e++):(Y=null,u('":"')),Y!==null?(be=qe(),be!==null?t=[t,r,l,c,h,f,m,E,C,Y,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(n.substr(e,2)==="::"?(l="::",e+=2):(l=null,u('"::"')),l!==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?(Y=qe(),Y!==null?t=[t,r,l,c,h,f,m,E,C,Y]:(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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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?(l=x(),l!==null?r=[r,l]:(r=null,e=L)):(r=null,e=L),r=r!==null?r:"",r!==null?(L=e,n.charCodeAt(e)===58?(l=":",e++):(l=null,u('":"')),l!==null?(c=x(),c!==null?l=[l,c]:(l=null,e=L)):(l=null,e=L),l=l!==null?l:"",l!==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,l,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(_c){return v.host_type="IPv6",n.substring(e,_c)}(qs)),t===null&&(e=qs),t}function x(){var t,r,l,c,h;return h=e,t=y(),t!==null?(r=y(),r=r!==null?r:"",r!==null?(l=y(),l=l!==null?l:"",l!==null?(c=y(),c=c!==null?c:"",c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function qe(){var t,r,l,c;return c=e,t=x(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=x(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t===null&&(t=sn()),t}function sn(){var t,r,l,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?(l=rn(),l!==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,l,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(Y){return v.host_type="IPv4",n.substring(e,Y)}(E)),t===null&&(e=E),t}function rn(){var t,r,l,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?(l=p(),l!==null?t=[t,r,l]:(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?(l=p(),l!==null?t=[t,r,l]:(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 Gr(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 Wr(){var t,r,l,c;for(t=[],c=e,n.charCodeAt(e)===59?(r=";",e++):(r=null,u('";"')),r!==null?(l=Es(),l!==null?r=[r,l]:(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?(l=Es(),l!==null?r=[r,l]:(r=null,e=c)):(r=null,e=c);return t}function Es(){var t;return t=Yr(),t===null&&(t=zr(),t===null&&(t=Xr(),t===null&&(t=Qr(),t===null&&(t=Jr(),t===null&&(t=Zr(),t===null&&(t=ei())))))),t}function Yr(){var t,r,l,c;return l=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=b())))),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()}(l,t[1])),t===null&&(e=l),t}function zr(){var t,r,l,c;return l=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=b())),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()}(l,t[1])),t===null&&(e=l),t}function Xr(){var t,r,l,c;return l=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}(l,t[1])),t===null&&(e=l),t}function Qr(){var t,r,l,c;return l=e,c=e,n.substr(e,4).toLowerCase()==="ttl="?(t=n.substr(e,4),e+=4):(t=null,u('"ttl="')),t!==null?(r=xs(),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}(l,t[1])),t===null&&(e=l),t}function Jr(){var t,r,l,c;return l=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}(l,t[1])),t===null&&(e=l),t}function Zr(){var t,r,l,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?(l=b(),l!==null?r=[r,l]:(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 ei(){var t,r,l,c,h,f;return c=e,h=e,t=ti(),t!==null?(f=e,n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=ni(),l!==null?r=[r,l]:(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 ti(){var t,r,l;if(l=e,r=ln(),r!==null)for(t=[];r!==null;)t.push(r),r=ln();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(l,t)),t===null&&(e=l),t}function ni(){var t,r,l;if(l=e,r=ln(),r!==null)for(t=[];r!==null;)t.push(r),r=ln();else t=null;return t!==null&&(t=function(c,h){return h.join("")}(l,t)),t===null&&(e=l),t}function ln(){var t;return t=si(),t===null&&(t=O(),t===null&&(t=pe())),t}function si(){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 ri(){var t,r,l,c,h,f,m;if(f=e,n.charCodeAt(e)===63?(t="?",e++):(t=null,u('"?"')),t!==null)if(r=Dn(),r!==null){for(l=[],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;)l.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);l!==null?t=[t,r,l]:(t=null,e=f)}else t=null,e=f;else t=null,e=f;return t}function Dn(){var t,r,l,c,h;return c=e,h=e,t=ii(),t!==null?(n.charCodeAt(e)===61?(r="=",e++):(r=null,u('"="')),r!==null?(l=li(),l!==null?t=[t,r,l]:(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 ii(){var t,r;if(r=on(),r===null&&(r=O(),r===null&&(r=pe())),r!==null)for(t=[];r!==null;)t.push(r),r=on(),r===null&&(r=O(),r===null&&(r=pe()));else t=null;return t}function li(){var t,r;for(t=[],r=on(),r===null&&(r=O(),r===null&&(r=pe()));r!==null;)t.push(r),r=on(),r===null&&(r=O(),r===null&&(r=pe()));return t}function on(){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 Nu(){var t;return t=wi(),t===null&&(t=oi()),t}function oi(){var t,r,l,c,h,f;return f=e,t=Mn(),t!==null?(r=R(),r!==null?(l=ai(),l!==null?(c=R(),c!==null?(h=Cs(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function ai(){var t;return t=De(),t===null&&(t=Ss()),t}function Ss(){var t,r,l,c;return c=e,t=fi(),t!==null?(n.charCodeAt(e)===58?(r=":",e++):(r=null,u('":"')),r!==null?(l=ui(),l===null&&(l=hi()),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function ui(){var t,r,l,c,h;return c=e,t=ci(),t===null&&(t=kn()),t!==null?(h=e,n.charCodeAt(e)===63?(r="?",e++):(r=null,u('"?"')),r!==null?(l=Ti(),l!==null?r=[r,l]:(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 ci(){var t,r,l,c;return c=e,n.substr(e,2)==="//"?(t="//",e+=2):(t=null,u('"//"')),t!==null?(r=pi(),r!==null?(l=kn(),l=l!==null?l:"",l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function kn(){var t,r,l;return l=e,n.charCodeAt(e)===47?(t="/",e++):(t=null,u('"/"')),t!==null?(r=_i(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function hi(){var t,r,l,c;if(c=e,t=di(),t!==null){for(r=[],l=an();l!==null;)r.push(l),l=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 di(){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 _i(){var t,r,l,c,h,f;if(h=e,t=Un(),t!==null){for(r=[],f=e,n.charCodeAt(e)===47?(l="/",e++):(l=null,u('"/"')),l!==null?(c=Un(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===47?(l="/",e++):(l=null,u('"/"')),l!==null?(c=Un(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Un(){var t,r,l,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?(l=";",e++):(l=null,u('";"')),l!==null?(c=As(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===59?(l=";",e++):(l=null,u('";"')),l!==null?(c=As(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function As(){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 fi(){var t,r,l,c,h;if(c=e,h=e,t=T(),t!==null){for(r=[],l=T(),l===null&&(l=p(),l===null&&(n.charCodeAt(e)===43?(l="+",e++):(l=null,u('"+"')),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."'))))));l!==null;)r.push(l),l=T(),l===null&&(l=p(),l===null&&(n.charCodeAt(e)===43?(l="+",e++):(l=null,u('"+"')),l===null&&(n.charCodeAt(e)===45?(l="-",e++):(l=null,u('"-"')),l===null&&(n.charCodeAt(e)===46?(l=".",e++):(l=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 pi(){var t;return t=mi(),t===null&&(t=gi()),t}function mi(){var t,r,l,c;return l=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=l)):(t=null,e=l),t=t!==null?t:"",t}function gi(){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 Ti(){var t,r;for(t=[],r=an();r!==null;)t.push(r),r=an();return t}function Cs(){var t,r,l,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(l=[];c!==null;)l.push(c),c=p();else l=null;if(l!==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,l,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 vi(){var t;return n.substr(e,6)==="INVITE"?(t="INVITE",e+=6):(t=null,u('"INVITE"')),t}function yi(){var t;return n.substr(e,3)==="ACK"?(t="ACK",e+=3):(t=null,u('"ACK"')),t}function Ei(){var t;return n.substr(e,7)==="OPTIONS"?(t="OPTIONS",e+=7):(t=null,u('"OPTIONS"')),t}function Si(){var t;return n.substr(e,3)==="BYE"?(t="BYE",e+=3):(t=null,u('"BYE"')),t}function Ai(){var t;return n.substr(e,6)==="CANCEL"?(t="CANCEL",e+=6):(t=null,u('"CANCEL"')),t}function Ci(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function bi(){var t;return n.substr(e,9)==="SUBSCRIBE"?(t="SUBSCRIBE",e+=9):(t=null,u('"SUBSCRIBE"')),t}function Ri(){var t;return n.substr(e,6)==="NOTIFY"?(t="NOTIFY",e+=6):(t=null,u('"NOTIFY"')),t}function Ii(){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=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=Ii(),t===null&&(t=b()))))))))),t!==null&&(t=function(l){return v.method=n.substring(e,l),v.method}(r)),t===null&&(e=r),t}function wi(){var t,r,l,c,h,f;return f=e,t=Cs(),t!==null?(r=R(),r!==null?(l=Oi(),l!==null?(c=R(),c!==null?(h=Di(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function Oi(){var t,r;return r=e,t=Ni(),t!==null&&(t=function(l,c){v.status_code=parseInt(c.join(""))}(r,t)),t===null&&(e=r),t}function Ni(){var t,r,l,c;return c=e,t=p(),t!==null?(r=p(),r!==null?(l=p(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Di(){var t,r,l;for(l=e,t=[],r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=G(),r===null&&(r=R(),r===null&&(r=Q()))))));r!==null;)t.push(r),r=ye(),r===null&&(r=O(),r===null&&(r=pe(),r===null&&(r=M(),r===null&&(r=G(),r===null&&(r=R(),r===null&&(r=Q()))))));return t!==null&&(t=function(c){v.reason_phrase=n.substring(e,c)}(l)),t===null&&(e=l),t}function Du(){var t,r,l,c,h,f;if(h=e,t=cn(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=cn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=cn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ku(){var t,r,l,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?(l=Ye(),l!==null?r=[r,l]:(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 Uu(){var t,r,l,c,h,f,m;if(h=e,t=ee(),t===null)if(f=e,t=xn(),t!==null){for(r=[],m=e,l=_e(),l!==null?(c=xn(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=_e(),l!==null?(c=xn(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,Y;for(Y=v.multi_header.length,C=0;C<Y;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,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=bs(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=bs(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Mt(){var t,r,l,c,h;return h=e,t=Pn(),t=t!==null?t:"",t!==null?(r=xe(),r!==null?(l=De(),l!==null?(c=Ie(),c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function Pn(){var t,r,l,c,h,f,m;if(h=e,f=e,t=b(),t!==null){for(r=[],m=e,l=Te(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=Te(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y,be){return Y+be[0]+be[1]},C[0])}(h,t)),t===null&&(e=h),t}function bs(){var t;return t=ki(),t===null&&(t=Ui(),t===null&&(t=Oe())),t}function ki(){var t,r,l,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?(l=Mi(),l!==null?t=[t,r,l]:(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 Ui(){var t,r,l,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?(l=xt(),l!==null?t=[t,r,l]:(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,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Mi(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?r=[r,l,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,l,c,h,f;return c=e,h=e,t=b(),t!==null?(f=e,r=k(),r!==null?(l=xi(),l!==null?r=[r,l]:(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 xi(){var t;return t=b(),t===null&&(t=nn(),t===null&&(t=we())),t}function Mu(){var t,r,l,c,h,f;if(h=e,t=Pi(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Rs(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Rs(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Pi(){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=b())))),t}function Rs(){var t;return t=Li(),t===null&&(t=Oe()),t}function Li(){var t,r,l,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"?(l=n.substr(e,8),e+=8):(l=null,u('"optional"')),l===null&&(n.substr(e,8).toLowerCase()==="required"?(l=n.substr(e,8),e+=8):(l=null,u('"required"')),l===null&&(l=b())),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function xu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Pu(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Lu(){var t,r;return r=e,t=Hi(),t!==null&&(t=function(l){v=n.substring(e,l)}(r)),t===null&&(e=r),t}function Hi(){var t,r,l,c,h,f,m,E;if(m=e,t=qi(),t!==null)if(r=V(),r!==null)if(l=Vi(),l!==null){for(c=[],E=e,h=le(),h!==null?(f=Is(),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=Is(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function qi(){var t;return t=Fi(),t===null&&(t=ji()),t}function Fi(){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 ji(){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=b(),t===null&&(t=$i()),t}function $i(){var t,r,l;return l=e,n.substr(e,2).toLowerCase()==="x-"?(t=n.substr(e,2),e+=2):(t=null,u('"x-"')),t!==null?(r=b(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function Vi(){var t;return t=Ln(),t===null&&(t=b()),t}function Is(){var t,r,l,c;return c=e,t=b(),t!==null?(r=k(),r!==null?(l=Bi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Bi(){var t;return t=b(),t===null&&(t=we()),t}function Hu(){var t,r,l,c;return c=e,t=Ki(),t!==null?(r=Te(),r!==null?(l=Mn(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Ki(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function qu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v=c}(r,t)),t===null&&(e=r),t}function Fu(){var t,r,l,c,h,f,m;if(h=e,f=e,t=cn(),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,l,c,h,f;if(h=e,t=J(),t!==null){for(r=[],f=e,n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?(c=J(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,n.charCodeAt(e)===46?(l=".",e++):(l=null,u('"."')),l!==null?(c=J(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function ju(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=ws(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=ws(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){v=-1}}()),t===null&&(e=h),t}function ws(){var t;return t=Os(),t===null&&(t=Oe()),t}function Os(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 $u(){var t,r,l;if(l=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(""))}(l,t)),t===null&&(e=l),t}function Vu(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v=c}(r,t)),t===null&&(e=r),t}function Bu(){var t,r,l,c,h,f,m,E,C,Y;for(E=e,C=e,t=[],r=Pn();r!==null;)t.push(r),r=Pn();if(t!==null)if(r=xe(),r!==null)if(l=De(),l!==null)if(c=Ie(),c!==null){for(h=[],Y=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);f!==null;)h.push(f),Y=e,f=le(),f!==null?(m=Oe(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);h!==null?t=[t,r,l,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 Ku(){var t;return t=Ns(),t}function Ns(){var t,r,l,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(l=Hn(),l!==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,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t===null&&(t=Gi()),t}function Gi(){var t,r,l,c,h,f,m,E;if(m=e,t=b(),t!==null)if(r=Te(),r!==null)if(l=hn(),l!==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,l,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,l,c;return c=e,t=b(),t!==null?(r=k(),r!==null?(l=b(),l===null&&(l=we()),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Hn(){var t;return t=Wi(),t===null&&(t=zi(),t===null&&(t=Xi(),t===null&&(t=Ji(),t===null&&(t=Zi(),t===null&&(t=el(),t===null&&(t=tl(),t===null&&(t=hn()))))))),t}function Wi(){var t,r,l,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?(l=Yi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Yi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(l,c){v.realm=c}(r,t)),t===null&&(e=r),t}function zi(){var t,r,l,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(l=rt(),l!==null)if(c=qn(),c!==null){if(h=[],C=e,m=R(),m!==null)for(f=[];m!==null;)f.push(m),m=R();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=R(),m!==null)for(f=[];m!==null;)f.push(m),m=R();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,l,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=Ss(),t===null&&(t=kn()),t}function Xi(){var t,r,l,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?(l=Qi(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function Qi(){var t,r;return r=e,t=Ue(),t!==null&&(t=function(l,c){v.nonce=c}(r,t)),t===null&&(e=r),t}function Ji(){var t,r,l,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?(l=Ue(),l!==null?t=[t,r,l]:(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 Zi(){var t,r,l,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"?(l=n.substr(e,4),e+=4):(l=null,u('"true"')),l!==null&&(l=function(f){v.stale=!0}()),l===null&&(e=h),l===null&&(h=e,n.substr(e,5).toLowerCase()==="false"?(l=n.substr(e,5),e+=5):(l=null,u('"false"')),l!==null&&(l=function(f){v.stale=!1}()),l===null&&(e=h)),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function el(){var t,r,l,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"?(l=n.substr(e,3),e+=3):(l=null,u('"MD5"')),l===null&&(n.substr(e,8).toLowerCase()==="md5-sess"?(l=n.substr(e,8),e+=8):(l=null,u('"MD5-sess"')),l===null&&(l=b())),l!==null?t=[t,r,l]:(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 tl(){var t,r,l,c,h,f,m,E,C,Y;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(l=rt(),l!==null){if(C=e,c=Fn(),c!==null){for(h=[],Y=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);f!==null;)h.push(f),Y=e,n.charCodeAt(e)===44?(f=",",e++):(f=null,u('","')),f!==null?(m=Fn(),m!==null?f=[f,m]:(f=null,e=Y)):(f=null,e=Y);h!==null?c=[c,h]:(c=null,e=C)}else c=null,e=C;c!==null?(h=Ee(),h!==null?t=[t,r,l,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=b())),t!==null&&(t=function(l,c){v.qop||(v.qop=[]),v.qop.push(c.toLowerCase())}(r,t)),t===null&&(e=r),t}function Gu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Wu(){var t,r,l,c,h,f,m;if(h=e,f=e,t=jn(),t!==null){for(r=[],m=e,l=_e(),l!==null?(c=jn(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=_e(),l!==null?(c=jn(),c!==null?l=[l,c]:(l=null,e=m)):(l=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,Y;for(Y=v.multi_header.length,C=0;C<Y;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,l,c,h,f,m;if(h=e,f=e,t=Mt(),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){C=null}v.multi_header.push({possition:e,offset:E,parsed:C})}(h)),t===null&&(e=h),t}function Yu(){var t,r,l,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=b()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Ds(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Ds(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 Y=v.params.text;v.text=Y.substring(1,Y.length-1),delete v.params.text}}(h,t[0])),t===null&&(e=h),t}function Ds(){var t;return t=nl(),t===null&&(t=Oe()),t}function nl(){var t,r,l,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(l=[];c!==null;)l.push(c),c=p();else l=null;l!==null?t=[t,r,l]:(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 zu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Xu(){var t,r,l,c,h,f;if(h=e,t=$n(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=$n(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=$n(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function $n(){var t,r,l,c,h,f;if(h=e,t=Mt(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Qu(){var t,r,l,c,h,f;if(h=e,t=sl(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=ks(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=ks(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function sl(){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=b()))),t!==null&&(t=function(l){v.state=n.substring(e,l)}(r)),t===null&&(e=r),t}function ks(){var t,r,l,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?(l=rl(),l!==null?t=[t,r,l]:(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?(l=xt(),l!==null?t=[t,r,l]:(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?(l=xt(),l!==null?t=[t,r,l]:(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 rl(){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=b()))))))),t}function Ju(){var t;return t=$(),t=t!==null?t:"",t}function Zu(){var t,r,l,c,h,f;if(h=e,t=b(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=b(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t=t!==null?t:"",t}function ec(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Us(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Us(),c!==null?l=[l,c]:(l=null,e=m)):(l=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(Y){v=-1}}()),t===null&&(e=h),t}function Us(){var t;return t=Os(),t===null&&(t=Oe()),t}function tc(){var t,r,l,c,h,f;if(h=e,t=Vn(),t!==null){for(r=[],f=e,l=_e(),l!==null?(c=Vn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=_e(),l!==null?(c=Vn(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Vn(){var t,r,l,c,h,f,m,E;if(m=e,t=hl(),t!==null)if(r=Te(),r!==null)if(l=fl(),l!==null){for(c=[],E=e,h=le(),h!==null?(f=Ms(),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=Ms(),f!==null?h=[h,f]:(h=null,e=E)):(h=null,e=E);c!==null?t=[t,r,l,c]:(t=null,e=m)}else t=null,e=m;else t=null,e=m;else t=null,e=m;return t}function Ms(){var t;return t=il(),t===null&&(t=ll(),t===null&&(t=ol(),t===null&&(t=al(),t===null&&(t=ul(),t===null&&(t=Oe()))))),t}function il(){var t,r,l,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?(l=xs(),l!==null?t=[t,r,l]:(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 ll(){var t,r,l,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?(l=nn(),l!==null?t=[t,r,l]:(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 ol(){var t,r,l,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?(l=sn(),l===null&&(l=ys()),l!==null?t=[t,r,l]:(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 al(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 ul(){var t,r,l,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?(l=cl(),l!==null?r=[r,l]:(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 cl(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 hl(){var t,r,l,c,h,f;return f=e,t=dl(),t!==null?(r=V(),r!==null?(l=b(),l!==null?(c=V(),c!==null?(h=_l(),h!==null?t=[t,r,l,c,h]:(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f)):(t=null,e=f),t}function dl(){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=b()),t!==null&&(t=function(l,c){v.protocol=c}(r,t)),t===null&&(e=r),t}function _l(){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=b())))),t!==null&&(t=function(l,c){v.transport=c}(r,t)),t===null&&(e=r),t}function fl(){var t,r,l,c,h;return c=e,t=pl(),t!==null?(h=e,r=ze(),r!==null?(l=ml(),l!==null?r=[r,l]:(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 pl(){var t,r;return r=e,t=sn(),t===null&&(t=vs(),t===null&&(t=gs())),t!==null&&(t=function(l){v.host=n.substring(e,l)}(r)),t===null&&(e=r),t}function ml(){var t,r,l,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?(l=p(),l=l!==null?l:"",l!==null?(c=p(),c=c!==null?c:"",c!==null?(h=p(),h=h!==null?h:"",h!==null?t=[t,r,l,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 xs(){var t,r,l,c,h;return c=e,h=e,t=p(),t!==null?(r=p(),r=r!==null?r:"",r!==null?(l=p(),l=l!==null?l:"",l!==null?t=[t,r,l]:(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 nc(){var t;return t=Ns(),t}function sc(){var t,r,l,c,h,f;if(h=e,t=gl(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Ps(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Ps(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function gl(){var t,r;return r=e,t=xt(),t!==null&&(t=function(l,c){v.expires=c}(r,t)),t===null&&(e=r),t}function Ps(){var t;return t=Tl(),t===null&&(t=Oe()),t}function Tl(){var t,r,l,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"?(l=n.substr(e,3),e+=3):(l=null,u('"uac"')),l===null&&(n.substr(e,3).toLowerCase()==="uas"?(l=n.substr(e,3),e+=3):(l=null,u('"uas"'))),l!==null?t=[t,r,l]:(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 rc(){var t,r,l,c;return c=e,t=b(),t!==null?(r=H(),r!==null?(l=vl(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function vl(){var t,r;for(t=[],r=q(),r===null&&(r=G(),r===null&&(r=Te()));r!==null;)t.push(r),r=q(),r===null&&(r=G(),r===null&&(r=Te()));return t}function ic(){var t,r;for(t=[],r=w();r!==null;)t.push(r),r=w();return t}function lc(){var t,r,l;return l=e,n.substr(e,5)==="uuid:"?(t="uuid:",e+=5):(t=null,u('"uuid:"')),t!==null?(r=yl(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function yl(){var t,r,l,c,h,f,m,E,C,Y,be;return Y=e,be=e,t=El(),t!==null?(n.charCodeAt(e)===45?(r="-",e++):(r=null,u('"-"')),r!==null?(l=dt(),l!==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=Sl(),C!==null?t=[t,r,l,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)}(Y,t[0])),t===null&&(e=Y),t}function dt(){var t,r,l,c,h;return h=e,t=y(),t!==null?(r=y(),r!==null?(l=y(),l!==null?(c=y(),c!==null?t=[t,r,l,c]:(t=null,e=h)):(t=null,e=h)):(t=null,e=h)):(t=null,e=h),t}function El(){var t,r,l;return l=e,t=dt(),t!==null?(r=dt(),r!==null?t=[t,r]:(t=null,e=l)):(t=null,e=l),t}function Sl(){var t,r,l,c;return c=e,t=dt(),t!==null?(r=dt(),r!==null?(l=dt(),l!==null?t=[t,r,l]:(t=null,e=c)):(t=null,e=c)):(t=null,e=c),t}function oc(){var t,r,l,c,h,f,m;if(h=e,f=e,t=Se(),t===null&&(t=Mt()),t!==null){for(r=[],m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=null,e=m);l!==null;)r.push(l),m=e,l=le(),l!==null?(c=Oe(),c!==null?l=[l,c]:(l=null,e=m)):(l=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 ac(){var t,r,l,c,h,f;if(h=e,t=Al(),t!==null){for(r=[],f=e,l=le(),l!==null?(c=Ls(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);l!==null;)r.push(l),f=e,l=le(),l!==null?(c=Ls(),c!==null?l=[l,c]:(l=null,e=f)):(l=null,e=f);r!==null?t=[t,r]:(t=null,e=h)}else t=null,e=h;return t}function Al(){var t,r,l,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?(l=Ye(),l!==null?r=[r,l]:(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 Ls(){var t;return t=Cl(),t===null&&(t=bl(),t===null&&(t=Rl(),t===null&&(t=Oe()))),t}function Cl(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 bl(){var t,r,l,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?(l=b(),l!==null?t=[t,r,l]:(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 Rl(){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(l){v.early_only=!0}()),t===null&&(e=r),t}function uc(t){t.sort();for(var r=null,l=[],c=0;c<t.length;c++)t[c]!==r&&(l.push(t[c]),r=t[c]);return l}function cc(){for(var t=1,r=1,l=!1,c=0;c<Math.max(e,d);c++){var h=n.charAt(c);h===`
|
|
75
|
-
`?(l||t++,r=1,l=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(t++,r=1,l=!0):(r++,l=!1)}return{line:t,column:r}}var Il=Sn(),Bt=xa(),v={},hc=a[i]();if(hc===null||e!==n.length){var Hs=Math.max(e,d),dc=Hs<n.length?n.charAt(Hs):null,wl=cc();return new this.SyntaxError(uc(_),dc,Hs,wl.line,wl.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?o(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}()),Wh}var Pa,zh;function Sn(){if(zh)return Pa;zh=1;const o=Ne,s=yt(),n=Xt();return Pa=class S_{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||o.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 S_(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}},Pa}var Xh;function yt(){if(Xh)return nt;Xh=1;const o=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=`${o.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 o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[_].indexOf(d)!==-1)return o.causes[_];return o.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 I(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(T(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function R(Ee,ge,Re,we,Ue,fe,ae){return Ee=u(Ee,u(u(y(ge,Re,we),Ue),ae)),u(_(Ee,fe),ge)}function Q(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,G;const te=7,b=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=Q(d),$=1732584193,q=4023233417,M=2562383102,G=271733878,j=0;j<O.length;j+=16)pe=$,Te=q,N=M,H=G,$=A($,q,M,G,O[j+0],te,3614090360),G=A(G,$,q,M,O[j+1],b,3905402710),M=A(M,G,$,q,O[j+2],J,606105819),q=A(q,M,G,$,O[j+3],ne,3250441966),$=A($,q,M,G,O[j+4],te,4118548399),G=A(G,$,q,M,O[j+5],b,1200080426),M=A(M,G,$,q,O[j+6],J,2821735955),q=A(q,M,G,$,O[j+7],ne,4249261313),$=A($,q,M,G,O[j+8],te,1770035416),G=A(G,$,q,M,O[j+9],b,2336552879),M=A(M,G,$,q,O[j+10],J,4294925233),q=A(q,M,G,$,O[j+11],ne,2304563134),$=A($,q,M,G,O[j+12],te,1804603682),G=A(G,$,q,M,O[j+13],b,4254626195),M=A(M,G,$,q,O[j+14],J,2792965006),q=A(q,M,G,$,O[j+15],ne,1236535329),$=w($,q,M,G,O[j+1],Ye,4129170786),G=w(G,$,q,M,O[j+6],ee,3225465664),M=w(M,G,$,q,O[j+11],V,643717713),q=w(q,M,G,$,O[j+0],k,3921069994),$=w($,q,M,G,O[j+5],Ye,3593408605),G=w(G,$,q,M,O[j+10],ee,38016083),M=w(M,G,$,q,O[j+15],V,3634488961),q=w(q,M,G,$,O[j+4],k,3889429448),$=w($,q,M,G,O[j+9],Ye,568446438),G=w(G,$,q,M,O[j+14],ee,3275163606),M=w(M,G,$,q,O[j+3],V,4107603335),q=w(q,M,G,$,O[j+8],k,1163531501),$=w($,q,M,G,O[j+13],Ye,2850285829),G=w(G,$,q,M,O[j+2],ee,4243563512),M=w(M,G,$,q,O[j+7],V,1735328473),q=w(q,M,G,$,O[j+12],k,2368359562),$=I($,q,M,G,O[j+5],Ae,4294588738),G=I(G,$,q,M,O[j+8],me,2272392833),M=I(M,G,$,q,O[j+11],Ie,1839030562),q=I(q,M,G,$,O[j+14],xe,4259657740),$=I($,q,M,G,O[j+1],Ae,2763975236),G=I(G,$,q,M,O[j+4],me,1272893353),M=I(M,G,$,q,O[j+7],Ie,4139469664),q=I(q,M,G,$,O[j+10],xe,3200236656),$=I($,q,M,G,O[j+13],Ae,681279174),G=I(G,$,q,M,O[j+0],me,3936430074),M=I(M,G,$,q,O[j+3],Ie,3572445317),q=I(q,M,G,$,O[j+6],xe,76029189),$=I($,q,M,G,O[j+9],Ae,3654602809),G=I(G,$,q,M,O[j+12],me,3873151461),M=I(M,G,$,q,O[j+15],Ie,530742520),q=I(q,M,G,$,O[j+2],xe,3299628645),$=R($,q,M,G,O[j+0],_e,4096336452),G=R(G,$,q,M,O[j+7],le,1126891415),M=R(M,G,$,q,O[j+14],ze,2878612391),q=R(q,M,G,$,O[j+5],rt,4237533241),$=R($,q,M,G,O[j+12],_e,1700485571),G=R(G,$,q,M,O[j+3],le,2399980690),M=R(M,G,$,q,O[j+10],ze,4293915773),q=R(q,M,G,$,O[j+1],rt,2240044497),$=R($,q,M,G,O[j+8],_e,1873313359),G=R(G,$,q,M,O[j+15],le,4264355552),M=R(M,G,$,q,O[j+6],ze,2734768916),q=R(q,M,G,$,O[j+13],rt,1309151649),$=R($,q,M,G,O[j+4],_e,4149444226),G=R(G,$,q,M,O[j+11],le,3174756917),M=R(M,G,$,q,O[j+2],ze,718787259),q=R(q,M,G,$,O[j+9],rt,3951481745),$=u($,pe),q=u(q,Te),M=u(M,N),G=u(G,H);return(P($)+P(q)+P(M)+P(G)).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 Qh=Pt,Eg=ht,Et=Ne,ut=yt(),Jh=xa(),Sg=Xt(),La=new Eg("SIPMessage");class mo{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 Jh(_,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 Jh(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=Qh.parse(this.body||""),this.sdp)}toString(){let s=`${this.method} ${this.ruri} SIP/2.0\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 C(){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=C();r!==null;)t.push(r),r=C();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=C(),o!==null)for(r=[];o!==null;)r.push(o),o=C();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 Ce(){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=Ce(),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(A){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,A,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?(A=x(),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,A,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?(A=x(),A!==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,A,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?(A=":",e++):(A=null,u('":"')),A!==null?(z=qe(),z!==null?t=[t,r,o,c,h,f,m,E,A,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?(A=qe(),A!==null?t=[t,r,o,c,h,f,m,E,A]:(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,A;return E=e,A=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=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A)):(t=null,e=A),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,A){return A=parseInt(A.join("")),v.port=A,A}(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,A){v.uri_params||(v.uri_params={}),typeof A>"u"?A=void 0:A=A[1],v.uri_params[E.toLowerCase()]=A}(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=Cs(),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 Cs(){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(A){v.sip_version=n.substring(e,A)}(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 Ci(){var t;return n.substr(e,8)==="REGISTER"?(t="REGISTER",e+=8):(t=null,u('"REGISTER"')),t}function Ai(){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=Ci(),t===null&&(t=Ai(),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=Cs(),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 A,z;for(z=v.multi_header.length,A=0;A<z;A++)if(v.multi_header[A].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=As(),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=As(),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 A;v.multi_header||(v.multi_header=[]);try{A=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){A=null}v.multi_header.push({possition:e,offset:E,parsed:A})}(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,A){typeof A=="string"?v.display_name=A:v.display_name=A[1].reduce(function(z,be){return z+be[0]+be[1]},A[0])}(h,t)),t===null&&(e=h),t}function As(){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(A){return parseFloat(n.substring(e,A))}(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,A){v.params||(v.params={}),typeof A>"u"?A=void 0:A=A[1],v.params[E.toLowerCase()]=A}(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,A){v.event=A.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 A=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),A&&v.setParam("tag",A)}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,A,z;for(E=e,A=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=A)}else t=null,e=A;else t=null,e=A;else t=null,e=A;else t=null,e=A;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,A;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=[],A=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=A)):(f=null,e=A);f!==null;){if(h.push(f),A=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=A)):(f=null,e=A)}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,A,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(A=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=A)}else c=null,e=A;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 A,z;for(z=v.multi_header.length,A=0;A<z;A++)if(v.multi_header[A].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 A;v.multi_header||(v.multi_header=[]);try{A=new Bt(v.uri,v.display_name,v.params),delete v.uri,delete v.display_name,delete v.params}catch(z){A=null}v.multi_header.push({possition:e,offset:E,parsed:A})}(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,A){if(v.protocol=A.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 A=v.tag;try{v=new Bt(v.uri,v.display_name,v.params),A&&v.setParam("tag",A)}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,A){v.rport=parseInt(A.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,A){v.port=parseInt(A.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,A,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?(A=So(),A!==null?t=[t,r,o,c,h,f,m,E,A]:(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(A){v=-1}}()),t===null&&(e=h),t}function lc(){var t,r,o,c,h,f;if(h=e,t=Co(),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 Co(){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=Ao(),t===null&&(t=bo(),t===null&&(t=Ro(),t===null&&(t=Oe()))),t}function Ao(){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 C(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,Ce=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,$=C($,q,M,W,O[j+0],te,3614090360),W=C(W,$,q,M,O[j+1],I,3905402710),M=C(M,W,$,q,O[j+2],J,606105819),q=C(q,M,W,$,O[j+3],ne,3250441966),$=C($,q,M,W,O[j+4],te,4118548399),W=C(W,$,q,M,O[j+5],I,1200080426),M=C(M,W,$,q,O[j+6],J,2821735955),q=C(q,M,W,$,O[j+7],ne,4249261313),$=C($,q,M,W,O[j+8],te,1770035416),W=C(W,$,q,M,O[j+9],I,2336552879),M=C(M,W,$,q,O[j+10],J,4294925233),q=C(q,M,W,$,O[j+11],ne,2304563134),$=C($,q,M,W,O[j+12],te,1804603682),W=C(W,$,q,M,O[j+13],I,4254626195),M=C(M,W,$,q,O[j+14],J,2792965006),q=C(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],Ce,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],Ce,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],Ce,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],Ce,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 C=a.call_id||i.configuration.jssip_id+ut.createRandomToken(15);this.call_id=C,this.setHeader("call-id",C);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
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
77
|
`;for(const a of this.extraHeaders)s+=`${a.trim()}\r
|
|
78
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
|
|
@@ -82,7 +82,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
82
82
|
\r
|
|
83
83
|
`,s+=this.body}else s+=`Content-Length: 0\r
|
|
84
84
|
\r
|
|
85
|
-
`;return s}clone(){const s=new
|
|
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
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
87
|
`}const p=this.getHeaders("via");for(const T of p)g+=`Via: ${T}\r
|
|
88
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
|
|
@@ -109,37 +109,37 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
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 Cg extends Zh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var St={OutgoingRequest:mo,InitialOutgoingInviteRequest:Ha,IncomingRequest:Ag,IncomingResponse:Cg};const Ys=$e(St),bg=ht,An=yt(),Qt=new bg("DigestAuthentication");var ed=class{constructor(o){this._credentials=o,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(o){switch(o){case"realm":return this._realm;case"ha1":return this._ha1;default:Qt.warn('get() | cannot get "%s" parameter',o);return}}authenticate({method:o,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=o,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 o=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return o.push(`algorithm=${this._algorithm}`),o.push(`username="${this._credentials.username}"`),o.push(`realm="${this._realm}"`),o.push(`nonce="${this._nonce}"`),o.push(`uri="${this._uri}"`),o.push(`response="${this._response}"`),this._opaque&&o.push(`opaque="${this._opaque}"`),this._qop&&(o.push(`qop=${this._qop}`),o.push(`cnonce="${this._cnonce}"`),o.push(`nc=${this._ncHex}`)),`Digest ${o.join(", ")}`}};const Rg=$e(ed),Cn=500,Ig=4e3,td=5e3;var qa={T1:Cn,T2:Ig,T4:td,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*td,TIMER_L:64*Cn,TIMER_M:64*Cn,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Cr=$e(qa),br=_t.EventEmitter,Rr=ht,Ir=Ne,nd=St,pn=qa,sd=new Rr("NonInviteClientTransaction"),go=new Rr("InviteClientTransaction"),wg=new Rr("AckClientTransaction"),rd=new Rr("NonInviteServerTransaction"),To=new Rr("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 Og extends br{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(){sd.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(){sd.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 Ng extends br{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&&(go.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){go.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(){go.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(){go.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 nd.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});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 nd.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});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 Dg extends br{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(){wg.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class kg extends br{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(){rd.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,rd.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 Ug extends br{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(){To.debug(`Timer H expired for transaction ${this.id}`),this.state===he.STATUS_COMPLETED&&To.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(){To.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,To.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 Mg({_transactions:o},s){let n;switch(s.method){case Ir.INVITE:if(n=o.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 Ir.ACK:if(n=o.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 Ir.CANCEL:return n=o.ist[s.via_branch],n?(s.reply_sl(200),n.state!==he.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(n=o.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 zs={C:he,NonInviteClientTransaction:Og,InviteClientTransaction:Ng,AckClientTransaction:Dg,NonInviteServerTransaction:kg,InviteServerTransaction:Ug,checkTransaction:Mg};const Wt=$e(zs),xg=ht,id=Ne,Pg=ed,Fa=zs,Lg=new xg("RequestSender"),ja={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Xs=class{constructor(o,s,n){this._ua=o,this._eventHandlers=n,this._method=s.method,this._request=s,this._auth=null,this._challenged=!1,this._staled=!1;for(const i in ja)Object.prototype.hasOwnProperty.call(ja,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=ja[i]));o.status===o.C.STATUS_USER_CLOSED&&(this._method!==id.BYE||this._method!==id.ACK)&&this._eventHandlers.onTransportError()}send(){const o={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:s=>{this._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new Fa.InviteClientTransaction(this._ua,this._ua.transport,this._request,o);break;case"ACK":this.clientTransaction=new Fa.AckClientTransaction(this._ua,this._ua.transport,this._request,o);break;default:this.clientTransaction=new Fa.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,o)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(o){let s,n;const i=o.status_code;if((i===401||i===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(o.status_code===401?(s=o.parseHeader("www-authenticate"),n="authorization"):(s=o.parseHeader("proxy-authenticate"),n="proxy-authorization"),!s){Lg.debug(`${o.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(o);return}if(!this._challenged||!this._staled&&s.stale===!0){if(this._auth||(this._auth=new Pg({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(o);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(o)}else this._eventHandlers.onReceiveResponse(o)}};const wr=$e(Xs),Hg=ht,$a=yt(),as=Ne,ld=St,od=Xs,Or=new Hg("Registrator"),vo=10;var qg=class{constructor(o,s){this._reg_id=1,this._ua=o,this._transport=s,this._registrar=o.configuration.registrar_server,this._expires=o.configuration.register_expires,this._call_id=$a.createRandomToken(22),this._cseq=0,this._to_uri=o.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(o){Array.isArray(o)||(o=[]),this._extraHeaders=o.slice()}setExtraContactParams(o){o instanceof Object||(o={}),this._extraContactParams="";for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const n=o[s];this._extraContactParams+=`;${s}`,n&&(this._extraContactParams+=`=${n}`)}}register(){if(this._registering){Or.debug("Register request in progress...");return}const o=this._extraHeaders.slice();o.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),o.push(`Expires: ${this._expires}`);const s=new ld.OutgoingRequest(as.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),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")){Or.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){Or.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<vo&&(d=vo);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<vo&&(this._expires=vo),this.register()):(Or.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(i,as.causes.SIP_FAILURE_CODE));break}default:{const a=$a.sipErrorCause(i.status_code);this._registrationFailure(i,a)}}}});this._registering=!0,n.send()}unregister(o={}){if(!this._registered){Or.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const s=this._extraHeaders.slice();o.all?s.push(`Contact: *${this._extraContactParams}`):s.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),s.push("Expires: 0");const n=new ld.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=$a.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(o,s){this._registering=!1,this._ua.registrationFailed({response:o||null,cause:s}),this._registered&&(this._registered=!1,this._ua.unregistered({response:o||null,cause:s}))}_unregistered(o,s){this._registering=!1,this._registered=!1,this._ua.unregistered({response:o||null,cause:s||null})}};class Fg 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 jg extends Error{constructor(s){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=s,this.message=`Invalid status: ${s}`}}class $g extends Error{constructor(s){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=s}}class Vg extends Error{constructor(s){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=s}}var bn={ConfigurationError:Fg,InvalidStateError:jg,NotSupportedError:$g,NotReadyError:Vg};const Xn=$e(bn),Va=Ne,yo=zs,Bg=Xs,Ba={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var ad=class{constructor(o,s,n){this._dialog=o,this._ua=o._ua,this._request=s,this._eventHandlers=n,this._reattempt=!1,this._reattemptTimer=null;for(const i in Ba)Object.prototype.hasOwnProperty.call(Ba,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=Ba[i]))}get request(){return this._request}send(){const o=new Bg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:s=>{this._eventHandlers.onAuthenticated(s)},onReceiveResponse:s=>{this._receiveResponse(s)}});if(o.send(),(this._request.method===Va.INVITE||this._request.method===Va.UPDATE&&this._request.body)&&o.clientTransaction.state!==yo.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const s=()=>{(o.clientTransaction.state===yo.C.STATUS_ACCEPTED||o.clientTransaction.state===yo.C.STATUS_COMPLETED||o.clientTransaction.state===yo.C.STATUS_TERMINATED)&&(o.clientTransaction.removeListener("stateChanged",s),this._dialog.uac_pending_reply=!1)};o.clientTransaction.on("stateChanged",s)}}_receiveResponse(o){o.status_code===408||o.status_code===481?this._eventHandlers.onDialogError(o):o.method===Va.INVITE&&o.status_code===491?this._reattempt?o.status_code>=200&&o.status_code<300?this._eventHandlers.onSuccessResponse(o):o.status_code>=300&&this._eventHandlers.onErrorResponse(o):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):o.status_code>=200&&o.status_code<300?this._eventHandlers.onSuccessResponse(o):o.status_code>=300&&this._eventHandlers.onErrorResponse(o)}};const Kg=$e(ad),Gg=ht,ud=St,Qn=Ne,Nr=zs,Wg=ad,Ka=yt(),Ga=new Gg("Dialog"),Jn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var cd=class{static get C(){return Jn}constructor(o,s,n,i=Jn.STATUS_CONFIRMED){if(this._owner=o,this._ua=o._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 ud.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),Ga.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(o){this._local_seqnum=o}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(o){this._uac_pending_reply=o}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Jn.STATUS_TERMINATED}update(o,s){this._state=Jn.STATUS_CONFIRMED,Ga.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),s==="UAC"&&(this._route_set=o.getHeaders("record-route").reverse())}terminate(){Ga.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Jn.STATUS_TERMINATED}sendRequest(o,s={}){const n=Ka.cloneArray(s.extraHeaders),i=Ka.cloneObject(s.eventHandlers),a=s.body||null,e=this._createRequest(o,n,a);return i.onAuthenticated=()=>{this._local_seqnum+=1},new Wg(this,e,i).send(),e}receiveRequest(o){this._checkInDialogRequest(o)&&(o.method===Qn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:o.method===Qn.INVITE&&(this._ack_seqnum=o.cseq),this._owner.receiveRequest(o))}_createRequest(o,s,n){s=Ka.cloneArray(s),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const i=o===Qn.CANCEL||o===Qn.ACK?this._local_seqnum:this._local_seqnum+=1;return new ud.OutgoingRequest(o,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(o){if(!this._remote_seqnum)this._remote_seqnum=o.cseq;else if(o.cseq<this._remote_seqnum)if(o.method===Qn.ACK){if(this._ack_seqnum===null||o.cseq!==this._ack_seqnum)return!1}else return o.reply(500),!1;else o.cseq>this._remote_seqnum&&(this._remote_seqnum=o.cseq);if(o.method===Qn.INVITE||o.method===Qn.UPDATE&&o.body){if(this._uac_pending_reply===!0)o.reply(491);else if(this._uas_pending_reply===!0){const s=(Math.random()*10|0)+1;return o.reply(500,null,[`Retry-After:${s}`]),!1}else{this._uas_pending_reply=!0;const s=()=>{(o.server_transaction.state===Nr.C.STATUS_ACCEPTED||o.server_transaction.state===Nr.C.STATUS_COMPLETED||o.server_transaction.state===Nr.C.STATUS_TERMINATED)&&(o.server_transaction.removeListener("stateChanged",s),this._uas_pending_reply=!1)};o.server_transaction.on("stateChanged",s)}o.hasHeader("contact")&&o.server_transaction.on("stateChanged",()=>{o.server_transaction.state===Nr.C.STATUS_ACCEPTED&&(this._remote_target=o.parseHeader("contact").uri)})}else o.method===Qn.NOTIFY&&o.hasHeader("contact")&&o.server_transaction.on("stateChanged",()=>{o.server_transaction.state===Nr.C.STATUS_COMPLETED&&(this._remote_target=o.parseHeader("contact").uri)});return!0}};const Eo=$e(cd);var Wa={exports:{}};const Yg=_t.EventEmitter,zg=ht,Xg=Ne,Qg=bn,hd=yt(),Jg=new zg("RTCSession:DTMF"),dd={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Wa.exports=class extends Yg{constructor(o){super(),this._session=o,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(o,s={}){if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Qg.InvalidStateError(this._session.status);const n=hd.cloneArray(s.extraHeaders);if(this.eventHandlers=hd.cloneObject(s.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError(`Invalid tone: ${o}`);if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError(`Invalid tone: ${o}`);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(
|
|
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=
|
|
115
|
-
`,1)[0],"Status_Line");if(s===-1){us.debug(`receiveNotify() | error parsing NOTIFY body: "${o.body}"`);return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:o,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:o,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:o,status_line:s});break;default:this.emit("failed",{request:o,status_line:s});break}}_requestSucceeded(o){us.debug("REFER succeeded"),us.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}_requestFailed(o,s){us.debug("REFER failed"),us.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}};const cT=$e(Td),hT=_t.EventEmitter,vd=Pt,dT=ht,de=Ne,cs=bn,yd=zs,We=yt(),kr=qa,_T=St,So=cd,fT=Xs,Vt=_d,Ed=fd,pT=md,mT=Td,Sd=Sn(),K=new dT("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},Ao=["audio","video"];var Ad=class fc extends hT{static get C(){return X}constructor(s){K.debug("new"),super(),this._id=null,this._ua=s,this._status=X.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 X}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 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}}isEstablished(){switch(this._status){case X.STATUS_ANSWERED:case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case X.STATUS_CANCELED:case X.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!==X.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 Sd("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):n.fromUserName&&(A.from_uri=new Sd("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 _T.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=X.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=X.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===X.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!==X.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!==X.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=X.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);const I=n.parseSDP();Array.isArray(I.media)||(I.media=[I.media]);for(const R of I.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){p=e.getAudioTracks();for(const R of p)e.removeTrack(R)}if(e&&a.video===!1){p=e.getVideoTracks();for(const R of p)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===X.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,de.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===X.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(Q=>{this._connection.addTrack(Q,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",R);const Q=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(Q)).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===X.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(R=>{if(this._status===X.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,R,()=>{this._status=X.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,de.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==X.STATUS_TERMINATED&&K.warn(R)})}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===X.STATUS_TERMINATED)throw new cs.InvalidStateError(this._status);switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.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===X.STATUS_NULL||this._status===X.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===X.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=X.STATUS_CANCELED,this._failed("local",null,de.causes.CANCELED);break;case X.STATUS_WAITING_FOR_ANSWER:case X.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 X.STATUS_WAITING_FOR_ACK:case X.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===X.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==yd.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===yd.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!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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===X.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!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new cs.InvalidStateError(this._status);new Ed(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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${i}`);const a=new mT(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===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED)&&(this._status=X.STATUS_CANCELED,this._request.reply(487),this._failed("remote",s,de.causes.CANCELED));else switch(s.method){case de.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(!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===X.STATUS_CONFIRMED||this._status===X.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,de.causes.BYE)):this._status===X.STATUS_INVITE_RECEIVED||this._status===X.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===X.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case de.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){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 Ed(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case de.UPDATE:this._status===X.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case de.REFER:this._status===X.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case de.NOTIFY:this._status===X.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:de.causes.CONNECTION_ERROR,cause:de.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:de.causes.REQUEST_TIMEOUT,cause:de.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==X.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!==X.STATUS_TERMINATED){if(this._status=X.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=kr.T1;function a(){this._status===X.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],n),i<kr.T2&&(i=i*2,i>kr.T2&&(i=kr.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),i))}this._timers.invite2xxTimer=setTimeout(a.bind(this),i)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===X.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))},kr.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 So(this,s,n,So.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 So(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!==X.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!==X.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=X.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!==X.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!==X.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(Ao.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===X.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===X.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===X.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 pT(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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;const _=new fc(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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;const e=new fc(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 fT(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===X.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===X.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===X.STATUS_TERMINATED)throw new Error("terminated");this._request.body=e,this._status=X.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==X.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 So(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!==X.STATUS_INVITE_SENT&&this._status!==X.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=X.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=X.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=X.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===X.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!==X.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=X.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=vd.parse(s),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const n of s.media)Ao.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)Ao.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)Ao.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return vd.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!==X.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!==X.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 gT=$e(Ad),TT=_t.EventEmitter,vT=ht,Xa=Ne,yT=St,Ur=yt(),ET=Xs,Cd=bn,ST=Sn(),Co=new vT("Message");var AT=class extends TT{constructor(o){super(),this._ua=o,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(o,s,n={}){const i=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError(`Invalid target: ${i}`);const a=Ur.cloneArray(n.extraHeaders),e=Ur.cloneObject(n.eventHandlers),d=n.contentType||"text/plain",_={};n.fromUserName&&(_.from_uri=new ST("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 yT.OutgoingRequest(Xa.MESSAGE,o,this._ua,_,a),s&&(this._request.body=s);const u=new ET(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),u.send()}init_incoming(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}accept(o={}){const s=Ur.cloneArray(o.extraHeaders),n=o.body;if(this._direction!=="incoming")throw new Cd.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(o={}){const s=o.status_code||480,n=o.reason_phrase,i=Ur.cloneArray(o.extraHeaders),a=o.body;if(this._direction!=="incoming")throw new Cd.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(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{const s=Ur.sipErrorCause(o.status_code);this._failed("remote",o,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)}_newMessage(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}_failed(o,s,n){Co.debug("MESSAGE failed"),this._close(),Co.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:n})}_succeeded(o,s){Co.debug("MESSAGE succeeded"),this._close(),Co.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}};const CT=_t.EventEmitter,bT=ht,Qa=Ne,RT=St,Mr=yt(),IT=Xs,bd=bn,bo=new bT("Options");var wT=class extends CT{constructor(o){super(),this._ua=o,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(o,s,n={}){const i=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError(`Invalid target: ${i}`);const a=Mr.cloneArray(n.extraHeaders),e=Mr.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 RT.OutgoingRequest(Qa.OPTIONS,o,this._ua,null,a),s&&(this._request.body=s);const _=new IT(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:u=>{this._receiveResponse(u)}});this._newOptions("local",this._request),_.send()}init_incoming(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}accept(o={}){const s=Mr.cloneArray(o.extraHeaders),n=o.body;if(this._direction!=="incoming")throw new bd.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(o={}){const s=o.status_code||480,n=o.reason_phrase,i=Mr.cloneArray(o.extraHeaders),a=o.body;if(this._direction!=="incoming")throw new bd.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(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{const s=Mr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Qa.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Qa.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}_failed(o,s,n){bo.debug("OPTIONS failed"),this._close(),bo.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:n})}_succeeded(o,s){bo.debug("OPTIONS succeeded"),this._close(),bo.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},Ja={};const OT=ht,Za=yt(),NT=Xt(),xr=new OT("Socket");Ja.isSocket=o=>{if(Array.isArray(o))return!1;if(typeof o>"u")return xr.warn("undefined JsSIP.Socket instance"),!1;try{if(!Za.isString(o.url))throw xr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Za.isString(o.via_transport))throw xr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(NT.parse(o.sip_uri,"SIP_URI")===-1)throw xr.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(!Za.isFunction(o[s]))throw xr.warn(`missing or invalid JsSIP.Socket method: ${s}`),new Error(`Missing or invalid JsSIP.Socket method: ${s}`)})}catch(s){return!1}return!0};const DT=ht,kT=Ja,Rd=Ne,Ht=new DT("Transport"),Yt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Rd.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Rd.CONNECTION_RECOVERY_MAX_INTERVAL}};var Id=class{constructor(o,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 o>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");o instanceof Array||(o=[o]),o.forEach(function(n){if(!kT.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(o){if(Ht.debug("send()"),!this.isConnected())return Ht.warn("unable to send message, transport is not connected"),!1;const s=o.toString();return Ht.debug(`sending message:
|
|
112
|
+
`,this.transport.send(a)}}class Cg extends Jh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var St={OutgoingRequest:pl,InitialOutgoingInviteRequest:La,IncomingRequest:Sg,IncomingResponse:Cg};const Ws=$e(St),Ag=ht,Cn=yt(),Qt=new Ag("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||Cn.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=Cn.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}`,_=Cn.calculateMD5(d),Qt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=Cn.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${_}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${Cn.calculateMD5(n||"")}`,_=Cn.calculateMD5(d),Qt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=Cn.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${_}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,_=Cn.calculateMD5(d),Qt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=Cn.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),An=500,Rg=4e3,ed=5e3;var Ha={T1:An,T2:Rg,T4:ed,TIMER_B:64*An,TIMER_D:0*An,TIMER_F:64*An,TIMER_H:64*An,TIMER_I:0*An,TIMER_J:0*An,TIMER_K:0*ed,TIMER_L:64*An,TIMER_M:64*An,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Cr=$e(Ha),Ar=_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 Ar{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 Ar{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 Ar{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 Ar{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 Ar{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,C={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(C.from_display_name="Anonymous",C.from_uri=new Ed("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):n.fromUserName&&(C.from_uri=new Ed("sip",n.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(C.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,C,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,C=!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")&&(C=!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=C),!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,Cd=bn,ET=Sn(),Cl=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 Cd.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 Cd.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){Cl.debug("MESSAGE failed"),this._close(),Cl.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:n})}_succeeded(l,s){Cl.debug("MESSAGE succeeded"),this._close(),Cl.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:s})}};const CT=_t.EventEmitter,AT=ht,Xa=Ne,bT=St,Ur=yt(),RT=zs,Ad=bn,Al=new AT("Options");var IT=class extends CT{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 Ad.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 Ad.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){Al.debug("OPTIONS failed"),this._close(),Al.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:n})}_succeeded(l,s){Al.debug("OPTIONS succeeded"),this._close(),Al.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:
|
|
116
116
|
|
|
117
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
|
|
119
|
-
`){Ht.debug("received message with CRLF Keep Alive response");return}else if(typeof
|
|
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:
|
|
120
120
|
|
|
121
|
-
${
|
|
121
|
+
${l}
|
|
122
122
|
`)}else Ht.debug(`received text message:
|
|
123
123
|
|
|
124
|
-
${
|
|
125
|
-
`);this.ondata({transport:this,message:
|
|
126
|
-
`);if(a===-1){
|
|
127
|
-
`,n),a===-1)return a;!
|
|
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
128
|
`;for(const a of s)i+=`Via: ${a}\r
|
|
129
|
-
`;n=je.getHeader("To"),je.to_tag||(n+=`;tag=${
|
|
129
|
+
`;n=je.getHeader("To"),je.to_tag||(n+=`;tag=${tu.newTag()}`),i+=`To: ${n}\r
|
|
130
130
|
`,i+=`From: ${je.getHeader("From")}\r
|
|
131
131
|
`,i+=`Call-ID: ${je.call_id}\r
|
|
132
132
|
`,i+=`CSeq: ${je.cseq} ${je.method}\r
|
|
133
133
|
`,i+=`\r
|
|
134
|
-
`,Dd.send(i)}const YT=$e(kd);var Lr={};const Qs=yt(),hs=Ne,ru=Xt(),Ud=Sn(),iu=Ja,lu=bn;Lr.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:`${Qs.createRandomToken(12)}.invalid`};const Io={mandatory:{sockets(o){const s=[];if(iu.isSocket(o))s.push({socket:o});else if(Array.isArray(o)&&o.length)for(const n of o)Object.prototype.hasOwnProperty.call(n,"socket")&&iu.isSocket(n.socket)?s.push(n):iu.isSocket(n)&&s.push({socket:n});else return;return s},uri(o){/^sip:/i.test(o)||(o=`${hs.SIP}:${o}`);const s=Ud.parse(o);if(s)return s.user?s:void 0}},optional:{authorization_user(o){if(ru.parse(`"${o}"`,"quoted_string")!==-1)return o},authorization_jwt(o){if(typeof o=="string")return o},user_agent(o){if(typeof o=="string")return o},connection_recovery_max_interval(o){if(Qs.isDecimal(o)){const s=Number(o);if(s>0)return s}},connection_recovery_min_interval(o){if(Qs.isDecimal(o)){const s=Number(o);if(s>0)return s}},contact_uri(o){if(typeof o=="string"){const s=ru.parse(o,"SIP_URI");if(s!==-1)return s}},display_name(o){return o},instance_id(o){if(/^uuid:/i.test(o)&&(o=o.substr(5)),ru.parse(o,"uuid")!==-1)return o},no_answer_timeout(o){if(Qs.isDecimal(o)){const s=Number(o);if(s>0)return s}},session_timers(o){if(typeof o=="boolean")return o},session_timers_refresh_method(o){if(typeof o=="string"&&(o=o.toUpperCase(),o===hs.INVITE||o===hs.UPDATE))return o},session_timers_force_refresher(o){if(typeof o=="boolean")return o},password(o){return String(o)},realm(o){return String(o)},ha1(o){return String(o)},register(o){if(typeof o=="boolean")return o},register_expires(o){if(Qs.isDecimal(o)){const s=Number(o);if(s>0)return s}},registrar_server(o){/^sip:/i.test(o)||(o=`${hs.SIP}:${o}`);const s=Ud.parse(o);if(s)return s.user?void 0:s},use_preloaded_route(o){if(typeof o=="boolean")return o},extra_headers(o){const s=[];if(Array.isArray(o)&&o.length)for(const n of o)typeof n=="string"&&s.push(n);else return;return s}}};Lr.load=(o,s)=>{for(const n in Io.mandatory)if(s.hasOwnProperty(n)){const i=s[n],a=Io.mandatory[n](i);if(a!==void 0)o[n]=a;else throw new lu.ConfigurationError(n,i)}else throw new lu.ConfigurationError(n);for(const n in Io.optional)if(s.hasOwnProperty(n)){const i=s[n];if(Qs.isEmpty(i))continue;const a=Io.optional[n](i);if(a!==void 0)o[n]=a;else throw new lu.ConfigurationError(n,i)}};const zT=_t.EventEmitter,XT=ht,At=Ne,QT=qg,Md=Ad,xd=AT,Pd=wT,ou=zs,JT=Id,wo=yt(),ZT=bn,ev=Sn(),tv=wd,au=St,nv=kd,uu=Lr,Be=new XT("UA"),Ct={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var Ld=class extends zT{static get C(){return Ct}constructor(o){if(Be.debug("new() [configuration:%o]",o),super(),this._cache={credentials:{}},this._configuration=Object.assign({},uu.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,o===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(o)}catch(s){throw this._status=Ct.STATUS_NOT_READY,this._error=Ct.CONFIGURATION_ERROR,s}this._registrator=new QT(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(o){Be.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(o,s){Be.debug("call()");const n=new Md(this);return n.connect(o,s),n}sendMessage(o,s,n){Be.debug("sendMessage()");const i=new xd(this);return i.send(o,s,n),i}sendOptions(o,s,n){Be.debug("sendOptions()");const i=new Pd(this);return i.send(o,s,n),i}terminateSessions(o){Be.debug("terminateSessions()");for(const s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}stop(){if(Be.debug("stop()"),this._dynConfiguration={},this._status===Ct.STATUS_USER_CLOSED){Be.debug("UA already closed");return}this._registrator.close();const o=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&&o===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(o){return wo.normalizeTarget(o,this._configuration.hostport_params)}get(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:Be.warn('get() | cannot get "%s" parameter in runtime',o);return}}set(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return Be.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}newTransaction(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}destroyTransaction(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}newDialog(o){this._dialogs[o.id]=o}destroyDialog(o){delete this._dialogs[o.id]}newMessage(o,s){this._applicants[o]=o,this.emit("newMessage",s)}newOptions(o,s){this._applicants[o]=o,this.emit("newOptions",s)}destroyMessage(o){delete this._applicants[o]}newRTCSession(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}destroyRTCSession(o){delete this._sessions[o.id]}registered(o){this.emit("registered",o)}unregistered(o){this.emit("unregistered",o)}registrationFailed(o){this.emit("registrationFailed",o)}receiveRequest(o){const s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){Be.debug("Request-URI does not point to us"),o.method!==At.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===At.SIPS){o.reply_sl(416);return}if(ou.checkTransaction(this,o))return;if(s===At.INVITE?new ou.InviteServerTransaction(this,this._transport,o):s!==At.ACK&&s!==At.CANCEL&&new ou.NonInviteServerTransaction(this,this._transport,o),s===At.OPTIONS){if(this.listeners("newOptions").length===0){o.reply(200);return}new Pd(this).init_incoming(o)}else if(s===At.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}new xd(this).init_incoming(o)}else if(s===At.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}let n,i;if(o.to_tag)n=this._findDialog(o.call_id,o.from_tag,o.to_tag),n?n.receiveRequest(o):s===At.NOTIFY?(i=this._findSession(o),i?i.receiveRequest(o):(Be.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==At.ACK&&o.reply(481);else switch(s){case At.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){const a=o.replaces;n=this._findDialog(a.call_id,a.from_tag,a.to_tag),n?(i=n.owner,i.isEnded()?o.reply(603):i.receiveRequest(o)):o.reply(481)}else i=new Md(this),i.init_incoming(o);else Be.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case At.BYE:o.reply(481);break;case At.CANCEL:i=this._findSession(o),i?i.receiveRequest(o):Be.debug("received CANCEL request for a non existent session");break;case At.ACK:break;case At.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}_findSession({call_id:o,from_tag:s,to_tag:n}){const i=o+s,a=this._sessions[i],e=o+n,d=this._sessions[e];return a||d||null}_findDialog(o,s,n){let i=o+s+n,a=this._dialogs[i];return a||(i=o+n+s,a=this._dialogs[i],a||null)}_loadConfig(o){try{uu.load(this._configuration,o)}catch(i){throw i}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=wo.newUUID()),this._configuration.jssip_id=wo.createRandomToken(5);const s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new JT(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=rv.bind(this),this._transport.ondisconnect=iv.bind(this),this._transport.ondata=lv.bind(this)}catch(i){throw Be.warn(i),new ZT.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 ev("sip",wo.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(uu.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 sv(o){this.emit("connecting",o)}function rv(o){this._status!==Ct.STATUS_USER_CLOSED&&(this._status=Ct.STATUS_READY,this._error=null,this.emit("connected",o),this._dynConfiguration.register&&this._registrator.register())}function iv(o){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",o),this._registrator.onTransportClosed(),this._status!==Ct.STATUS_USER_CLOSED&&(this._status=Ct.STATUS_NOT_READY,this._error=Ct.NETWORK_ERROR)}function lv(o){const s=o.transport;let n=o.message;if(n=tv.parseMessage(n,this),!!n&&!(this._status===Ct.STATUS_USER_CLOSED&&n instanceof au.IncomingRequest)&&nv(n,this,s)){if(n instanceof au.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof au.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(Ld);for(var bt=[],cu=0;cu<256;++cu)bt.push((cu+256).toString(16).slice(1));function av(o,s=0){return(bt[o[s+0]]+bt[o[s+1]]+bt[o[s+2]]+bt[o[s+3]]+"-"+bt[o[s+4]]+bt[o[s+5]]+"-"+bt[o[s+6]]+bt[o[s+7]]+"-"+bt[o[s+8]]+bt[o[s+9]]+"-"+bt[o[s+10]]+bt[o[s+11]]+bt[o[s+12]]+bt[o[s+13]]+bt[o[s+14]]+bt[o[s+15]]).toLowerCase()}var Oo,uv=new Uint8Array(16);function cv(){if(!Oo&&(Oo=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Oo))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Oo(uv)}var hv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Hd={randomUUID:hv};function qd(o,s,n){if(Hd.randomUUID&&!s&&!o)return Hd.randomUUID();o=o||{};var i=o.random||(o.rng||cv)();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 av(i)}var Me=yt();const Rn=$e(Me),hu=new po("Dialog"),Zn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class No{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),hu.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,hu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){hu.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 Kg(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 dv{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=ie(ie({},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 oe(this,null,function*(){return Jt.canGetMediaDevices()?(yield navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind===s):[]})}static getMicrophoneList(){return oe(this,null,function*(){return(yield Jt.getDevices("audioinput")).map((s,n)=>lt(ie({},s),{deviceId:s.deviceId,label:s.label||`microphone ${n+1}`,kind:s.kind,groupId:s.groupId}))})}static getSpeakerList(){return oe(this,null,function*(){return(yield Jt.getDevices("audiooutput")).map((s,n)=>lt(ie({},s),{deviceId:s.deviceId,label:s.label||`speaker ${n+1}`,kind:s.kind,groupId:s.groupId}))})}static getCameraList(){return oe(this,null,function*(){return(yield Jt.getDevices("videoinput")).map((s,n)=>lt(ie({},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 oe(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 oe(this,null,function*(){return yield navigator.mediaDevices.getUserMedia(s)})}static changeAudioOutput(s,n){return oe(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 oe(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 _v=Sn();const ds=$e(_v),qt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},W=new po("JanusSession"),fv="/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},Do=["audio","video"];class ko extends _t.EventEmitter{static get C(){return Z}constructor(s){W.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-${qd().replace(/-/g,"").slice(0,12)}`}connect(s,n,i={},a){W.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=ie({},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 I in d)Object.prototype.hasOwnProperty.call(d,I)&&this.on(I,d[I]);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=>oe(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){W.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={}){W.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 I=n.parseSDP();Array.isArray(I.media)||(I.media=[I.media]);for(const R of I.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){p=e.getAudioTracks();for(const R of p)e.removeTrack(R)}if(e&&a.video===!1){p=e.getVideoTracks();for(const R of p)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"):(n.reply(480),this._failed("local",null,U.causes.USER_DENIED_MEDIA_ACCESS),W.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(Q=>{this._connection.addTrack(Q,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:n.body};W.debug('emit "sdp"'),this.emit("sdp",R);const Q=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(Q)).catch(P=>{throw n.reply(488),this._failed("system",null,U.causes.WEBRTC_ERROR),W.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(R=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,R,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,U.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==Z.STATUS_TERMINATED&&W.warn(R)})}terminate(s={}){W.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(W.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(W.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(W.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=>oe(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=>oe(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(W.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 Ya(this).send(s,n,i)}mute(s={audio:!0,video:!1}){W.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}){W.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(W.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(W.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){W.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){W.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 cT(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 W.debug("sendRequest()"),this._dialog.sendRequest(s,n)}receiveNotify(s){W.debug("receiveRequest()")}receiveRequest(s){if(W.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};W.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}),W.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 Zg(this).init_incoming(s):n!==void 0?new Ya(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(){W.warn("onTransportError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){W.warn("onRequestTimeout()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){W.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){W.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){W.debug("newInfo()"),this.emit("newInfo",s)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(W.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(W.debug("_isReadyToReOffer() | session not established yet"),!1):(W.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(W.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(W.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){W.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=Cr.T1;function a(){this._status===Z.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],n),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===Z.STATUS_WAITING_FOR_ACK&&(W.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(U.BYE),this._ended("remote",null,U.causes.NO_ACK))},Cr.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,W.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,n){if(W.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=>(W.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):i.createAnswer(n).catch(a=>(W.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,W.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 W.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};W.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 No(this,s,n,No.C.STATUS_EARLY),_.error?(W.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 No(this,s,n);return u.error?(W.debug(u.error),this._failed("remote",s,U.causes.INTERNAL_ERROR),!1):(this._dialog=u,!0)}}_receiveReinvite(s){W.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"){W.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{W.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){W.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"){W.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(_=>{this._status!==Z.STATUS_TERMINATED&&d.call(this,_)}).catch(_=>{W.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){W.debug("_processInDialogSdpOffer()");const n=s.parseSDP();let i=!1;for(const d of n.media){if(Do.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};W.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),W.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),W.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',d),d})}).catch(d=>{W.warn("_processInDialogSdpOffer() failed [error: %o]",d)}),this._connectionPromiseQueue}_receiveRefer(s){if(W.debug("receiveRefer()"),!s.refer_to){W.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==U.SIP){W.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const n=new lT(this,s.cseq);W.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 ko(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(W.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){W.debug("receiveReplaces()");function n(a){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const e=new ko(this._ua);e.on("confirmed",()=>{this.terminate()}),e.init_incoming(s,a)}function i(){W.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 wr(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),W.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,W.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(e=>{this._status!==Z.STATUS_TERMINATED&&W.warn(e)})}requestAudioAndVideoPermissions(){return oe(this,null,function*(){this.stream=yield this.loadStream()})}setupMediaStream(){return oe(this,null,function*(){yield this.requestAudioAndVideoPermissions(),yield this.processPlugins()})}changeMediaConstraints(s){return oe(this,null,function*(){this.mediaConstraints=ie({},s),yield this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})})}loadStream(){return oe(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 fv+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}processIceCandidates(){return oe(this,null,function*(){for(let s=0;s<this.iceCandidates.length;s++)yield this._connection.addIceCandidate(this.iceCandidates[s]);this.iceCandidates=[]})}_sendConfigureMessage(s){return oe(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:ie({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=>oe(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=>oe(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=>oe(this,null,function*(){})}})}_answerAttachedStream(s,n){return oe(this,null,function*(){let i=null;const a=u=>oe(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=>oe(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=>oe(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=ie({},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 dv(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 oe(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 oe(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(W.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 No(this,s,"UAC");if(n.error!==void 0){W.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=qd();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=>oe(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){W.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};W.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=>{W.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={}){W.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};W.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};W.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),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function _(u){i.failed&&i.failed(u)}}_sendUpdate(s={}){W.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};W.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};W.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),W.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){W.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){W.debug("mangleOffer() | me on hold, mangling offer");for(const n of s.media)Do.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){W.debug("mangleOffer() | both on hold, mangling offer");for(const n of s.media)Do.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){W.debug("mangleOffer() | remote on hold, mangling offer");for(const n of s.media)Do.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()&&(W.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&&(W.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){W.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:s,session:this,request:n})}_connecting(s){W.debug("session connecting"),W.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,n){W.debug("session progress"),W.debug('emit "progress"'),this.emit("progress",{originator:s,response:n||null})}_accepted(s,n){W.debug("session accepted"),this._start_time=new Date,W.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:n||null})}_confirmed(s,n){W.debug("session confirmed"),this._is_confirmed=!0,W.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:n||null})}_ended(s,n,i){W.debug("session ended"),this._end_time=new Date,this._close(),W.debug('emit "ended"'),this.emit("ended",{originator:s,message:n||null,cause:i})}_failed(s,n,i){W.debug("session failed"),W.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:n||null,cause:i}),this._close(),W.debug('emit "failed"'),this.emit("failed",{originator:s,message:n||null,cause:i})}_onhold(s){W.debug("session onhold"),this._setLocalMediaStatus(),W.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){W.debug("session onunhold"),this._setLocalMediaStatus(),W.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:n}){W.debug("session onmute"),this._setLocalMediaStatus(),W.debug('emit "muted"'),this.emit("muted",{audio:s,video:n})}_onunmute({audio:s,video:n}){W.debug("session onunmute"),this._setLocalMediaStatus(),W.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:n})}}class Js{constructor(s){if(this.headers={},s.length>0){let n=!1;const i=s.split(`\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,Ct=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"),At={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 At}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=At.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=At.STATUS_NOT_READY,this._error=At.CONFIGURATION_ERROR,s}this._registrator=new XT(this)}get C(){return At}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===At.STATUS_INIT?this._transport.connect():this._status===At.STATUS_USER_CLOSED?(Be.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=At.STATUS_INIT,this._transport.connect()):this._status===At.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===At.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=At.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!==Ct.ACK&&l.reply_sl(404);return}if(l.ruri.scheme===Ct.SIPS){l.reply_sl(416);return}if(ou.checkTransaction(this,l))return;if(s===Ct.INVITE?new ou.InviteServerTransaction(this,this._transport,l):s!==Ct.ACK&&s!==Ct.CANCEL&&new ou.NonInviteServerTransaction(this,this._transport,l),s===Ct.OPTIONS){if(this.listeners("newOptions").length===0){l.reply(200);return}new xd(this).init_incoming(l)}else if(s===Ct.MESSAGE){if(this.listeners("newMessage").length===0){l.reply(405);return}new Md(this).init_incoming(l)}else if(s===Ct.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===Ct.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!==Ct.ACK&&l.reply(481);else switch(s){case Ct.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 Ct.BYE:l.reply(481);break;case Ct.CANCEL:i=this._findSession(l),i?i.receiveRequest(l):Be.debug("received CANCEL request for a non existent session");break;case Ct.ACK:break;case Ct.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!==At.STATUS_USER_CLOSED&&(this._status=At.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!==At.STATUS_USER_CLOSED&&(this._status=At.STATUS_NOT_READY,this._error=At.NETWORK_ERROR)}function iv(l){const s=l.transport;let n=l.message;if(n=ev.parseMessage(n,this),!!n&&!(this._status===At.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 Ct.INVITE:i=this._transactions.ict[n.via_branch],i&&i.receiveResponse(n);break;case Ct.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 C=i.anonymous||!1,w={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:C,outbound:!0}),C?(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,C=!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")&&(C=!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=C),!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=Cr.T1;function a(){this._status===Z.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],n),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===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))},Cr.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 C={audio:!0,video:!0};yield new Promise(w=>{setTimeout(w,100)}),i=yield s.rtcpPeer.createAnswer(C),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
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
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
138
|
`;for(const n in this.headers)s+=`${n}: ${this.headers[n]}\r
|
|
139
139
|
`;return this.body&&(s+=`\r
|
|
140
140
|
${this.body}\r
|
|
141
141
|
`),s+=`-------${this.ident}$\r
|
|
142
|
-
`,s}}const
|
|
142
|
+
`,s}}const Ae={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class 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=Ae.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username: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 Ae}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=Ae.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(s){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
|
|
143
143
|
o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
|
|
144
144
|
c=IN IP4 ${this.my_ip}
|
|
145
145
|
t=0 0
|
|
@@ -153,8 +153,8 @@ t=0 0
|
|
|
153
153
|
m=message 2856 TCP/TLS/MSRP *
|
|
154
154
|
a=accept-types:text/plain text/html
|
|
155
155
|
a=path:${s.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
|
|
156
|
-
`),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new wr(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 Js("");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 Js(s.data);if(this.status==="auth"&&n.code===401){const i=this.parseAuth(n.getHeader("WWW-Authenticate")),a=new Rg(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 Eo(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 Js("");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 Js("");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 Js("");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 Eo(this,s,n,Eo.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 Eo(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 Ya(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 pv=Xt();const _u=$e(pv),Uo=new po("Parser"),mv=(o,s)=>{let n,i,a=o.indexOf(`\r
|
|
157
|
-
`);if(a===-1){
|
|
158
|
-
`,n),a===-1)return a;!o.substring(a+2,a+4).match(/(^\r\n)/)&&o.charAt(a+2).match(/(^\s+)/)?n=a+2:i=a}return i}function Tv(o,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":o.addHeader("via",_),o.getHeaders("via").length===1?(a=o.parseHeader("Via"),a&&(o.via=a,o.via_branch=a.branch)):a=0;break;case"from":case"f":o.setHeader("from",_),a=o.parseHeader("from"),a&&(o.from=a,o.from_tag=a.getParam("tag"));break;case"to":case"t":o.setHeader("to",_),a=o.parseHeader("to"),a&&(o.to=a,o.to_tag=a.getParam("tag"));break;case"record-route":if(a=_u.parse(_,"Record_Route"),a===-1)a=void 0;else for(const u of a)o.addHeader("record-route",_.substring(u.possition,u.offset)),o.headers["Record-Route"][o.getHeaders("record-route").length-1].parsed=u.parsed;break;case"call-id":case"i":o.setHeader("call-id",_),a=o.parseHeader("call-id"),a&&(o.call_id=_);break;case"contact":case"m":if(a=_u.parse(_,"Contact"),a===-1)a=void 0;else for(const u of a)o.addHeader("contact",_.substring(u.possition,u.offset)),o.headers.Contact[o.getHeaders("contact").length-1].parsed=u.parsed;break;case"content-length":case"l":o.setHeader("content-length",_),a=o.parseHeader("content-length");break;case"content-type":case"c":o.setHeader("content-type",_),a=o.parseHeader("content-type");break;case"cseq":o.setHeader("cseq",_),a=o.parseHeader("cseq"),a&&(o.cseq=a.value),o instanceof Ys.IncomingResponse&&(o.method=a.method);break;case"max-forwards":o.setHeader("max-forwards",_),a=o.parseHeader("max-forwards");break;case"www-authenticate":o.setHeader("www-authenticate",_),a=o.parseHeader("www-authenticate");break;case"proxy-authenticate":o.setHeader("proxy-authenticate",_),a=o.parseHeader("proxy-authenticate");break;case"session-expires":case"x":o.setHeader("session-expires",_),a=o.parseHeader("session-expires"),a&&(o.session_expires=a.expires,o.session_expires_refresher=a.refresher);break;case"refer-to":case"r":o.setHeader("refer-to",_),a=o.parseHeader("refer-to"),a&&(o.refer_to=a);break;case"replaces":o.setHeader("replaces",_),a=o.parseHeader("replaces"),a&&(o.replaces=a);break;case"event":case"o":o.setHeader("event",_),a=o.parseHeader("event"),a&&(o.event=a);break;default:o.addHeader(d,_),a=0}return a===void 0?{error:`error parsing header "${d}"`}:!0}const vv={parseMessage:mv},Hr=new po("Registrator"),Mo=10;class yv{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){Hr.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 wr(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")){Hr.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){Hr.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(_),_<Mo&&(_=Mo);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<Mo&&(this._expires=Mo),this.register()):(Hr.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){Hr.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 wr(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},Ev=ov;class Sv extends Ev{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 yv(this)}setLastRegisterTimestamp(){this.lastRegisterTimestamp=Date.now()}call(s,n){return super.call(s,n)}joinVideoCall(s,n,i){st.debug("call()");const a=new ko(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{Lr.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 UT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Av.bind(this),this._transport.onconnect=Cv.bind(this),this._transport.ondisconnect=bv.bind(this),this._transport.ondata=Rv.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(Lr.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 Bh.Options(this).init_incoming(s)}else if(d===Ne.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new Bh.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 du(this),u.init_incoming(s)):s.body.search(/JANUS/ig)>-1||(u=new gT(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 du(this);return i.connect(s),i}startJanus(s,n){st.debug("startJanus()",n);const i=new du(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 Av(o){this.emit("connecting",o)}function Cv(o){this._status!==es.STATUS_USER_CLOSED&&(this._status=es.STATUS_READY,this._error=null,this.emit("connected",o),this._dynConfiguration.register&&this._registrator.register())}function bv(o){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",o),this._registrator.onTransportClosed(),this._status!==es.STATUS_USER_CLOSED&&(this._status=es.STATUS_NOT_READY,this._error=es.NETWORK_ERROR)}function Rv(o){const s=o.transport;let n=o.message;const i=n;if(n=vv.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,i),!!n&&!(this._status===es.STATUS_USER_CLOSED&&n instanceof Ys.IncomingRequest)&&YT(n,this,s)){if(n instanceof Ys.IncomingRequest)n.transport=s,this.receiveRequest(n);else if(n instanceof Ys.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 Iv=["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"],wv=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Fd(o){const s={};return Iv.forEach(n=>{o[n]!==void 0&&(s[n]=o[n])}),s.localHold=o._localHold,s}function jd(o){const s={};return wv.forEach(n=>{o[n]!==void 0&&(s[n]=o[n])}),s}function $d(o,s){const n=new AudioContext,i=n.createMediaStreamSource(o),a=n.createMediaStreamDestination(),e=n.createGain();return i.connect(e),e.connect(a),e.gain.value=s,a.stream}function Ov(o,s,n,i){if(Vd())return;const a=document.createElement("audio");a.id=s._id,a.className="audioTag",a.srcObject=o,a.setSinkId(n),a.volume=i,a.play(),s.audioTag=a}function Nv(o){if(o&&typeof o.log=="function"&&typeof o.warn=="function"&&typeof o.error=="function")return!0}function Vd(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const Dv=ht,kv=Xt(),kt=new Dv("WebSocketInterface");var Uv=class{constructor(o){kt.debug('new() [url:"%s"]',o),this._url=o,this._sip_uri=null,this._via_transport=null,this._ws=null;const s=kv.parse(o,"absoluteURI");if(s===-1)throw kt.warn(`invalid WebSocket URI: ${o}`),new TypeError(`Invalid argument: ${o}`);if(s.scheme!=="wss"&&s.scheme!=="ws")throw kt.warn(`invalid WebSocket URI scheme: ${s.scheme}`),new TypeError(`Invalid argument: ${o}`);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(o){this._via_transport=o.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(o){this._onError(o)}}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(o){return kt.debug("send()"),this.isConnected()?(this._ws.send(o),!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:o,code:s,reason:n}){kt.debug(`WebSocket ${this._url} closed`),o===!1&&kt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!o,s,n)}_onMessage({data:o}){kt.debug("received WebSocket message"),this.ondata(o)}_onError(o){kt.warn(`WebSocket ${this._url} error: `,o)}};const fu=Ol,Mv=Ne,xv=bn,Pv=yt(),Lv=Ld,Hv=Sn(),qv=xa(),Fv=Xt(),jv=Uv;$s("JsSIP")("version %s",fu.version);var $v={C:Mv,Exceptions:xv,Utils:Pv,UA:Lv,URI:Hv,NameAddrHeader:qv,WebSocketInterface:jv,Grammar:Fv,debug:$s,get name(){return fu.title},get version(){return fu.version}};const Vv=$e($v);function pu(o){return o<10?`0${o}`:`${o}`}function Bv(o){let s=o.hours||0,n=o.minutes||0,i=o.seconds||0;i++,i===60&&(i=0,n++,n===60&&(n=0,s++));const a=`${pu(s)}:${pu(n)}:${pu(i)}`;return{seconds:i,minutes:n,hours:s,formatted:a}}var Rt={};Rt.forEach=(o,s,n)=>oe(this,null,function*(){const i=[];for(let a=0;a<o.length;a++)if(a in o){const e=Promise.resolve(o[a]).then(d=>s.call(n||globalThis,d,a,o));i.push(e)}yield Promise.all(i)}),Rt.forEachSeries=(o,s,n)=>oe(this,null,function*(){for(let i=0;i<o.length;i++)i in o&&(yield s.call(n||globalThis,yield o[i],i,o))}),Rt.map=(o,s,n)=>oe(this,null,function*(){const i=[];for(let a=0;a<o.length;a++)a in o&&(i[a]=Promise.resolve(o[a]).then(e=>s.call(n||globalThis,e,a,o)));return Promise.all(i)}),Rt.mapSeries=(o,s,n)=>oe(this,null,function*(){const i=[];for(let a=0;a<o.length;a++)a in o&&(i[a]=yield s.call(n||globalThis,yield o[a],a,o));return i}),Rt.find=(o,s,n)=>new Promise((i,a)=>{if(o.length===0)return i();let e=1;for(let d=0;d<o.length;d++){const _=u=>{u?i(o[d]):e===o.length&&i(),e++};Promise.resolve(o[d]).then(u=>s.call(n||globalThis,u,d,o)).then(_).catch(a)}}),Rt.findSeries=(o,s,n)=>oe(this,null,function*(){for(let i=0;i<o.length;i++)if(yield s.call(n||globalThis,yield o[i],i,o))return o[i]}),Rt.findIndex=(o,s,n)=>new Promise((i,a)=>{if(o.length===0)return i(-1);let e=1;for(let d=0;d<o.length;d++){const _=u=>{u?i(d):e===o.length&&i(-1),e++};Promise.resolve(o[d]).then(u=>s.call(n||globalThis,u,d,o)).then(_).catch(a)}}),Rt.findIndexSeries=(o,s,n)=>oe(this,null,function*(){for(let i=0;i<o.length;i++)if(yield s.call(n||globalThis,yield o[i],i,o))return i}),Rt.some=(o,s,n)=>new Promise((i,a)=>{if(o.length===0)return i(!1);let e=1;for(let d=0;d<o.length;d++){if(!(d in o)){e++;continue}const _=u=>{u?i(!0):e===o.length&&i(!1),e++};Promise.resolve(o[d]).then(u=>s.call(n||globalThis,u,d,o)).then(_).catch(a)}}),Rt.someSeries=(o,s,n)=>oe(this,null,function*(){for(let i=0;i<o.length;i++)if(i in o&&(yield s.call(n||globalThis,yield o[i],i,o)))return!0;return!1}),Rt.every=(o,s,n)=>new Promise((i,a)=>{if(o.length===0)return i(!0);let e=1;for(let d=0;d<o.length;d++){if(!(d in o)){e++;continue}const _=u=>{u?e===o.length&&i(!0):i(!1),e++};Promise.resolve(o[d]).then(u=>s.call(n||globalThis,u,d,o)).then(_).catch(a)}}),Rt.everySeries=(o,s,n)=>oe(this,null,function*(){for(let i=0;i<o.length;i++)if(i in o&&!(yield s.call(n||globalThis,yield o[i],i,o)))return!1;return!0}),Rt.filter=(o,s,n)=>new Promise((i,a)=>oe(this,null,function*(){const e=[];for(let _=0;_<o.length;_++)_ in o&&(e[_]=Promise.resolve(o[_]).then(u=>s.call(n||globalThis,u,_,o)).catch(a));const d=[];for(let _=0;_<e.length;_++)(yield e[_])&&d.push(yield o[_]);i(d)})),Rt.filterSeries=(o,s,n)=>oe(this,null,function*(){const i=[];for(let a=0;a<o.length;a++)a in o&&(yield s.call(n||globalThis,yield o[a],a,o))&&i.push(yield o[a]);return i}),Rt.reduce=(o,s,n)=>oe(this,null,function*(){if(o.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=o[0],i=1),i;i<o.length;i++)i in o&&(a=yield s(yield a,yield o[i],i,o));return a});var Bd={};(function(o){const s=Rt;Object.keys(s).forEach(n=>{const i=n.charAt(0).toUpperCase()+n.slice(1);o[`async${i}`]=function(...a){return oe(this,null,function*(){return s[n](this,...a)})}})})(Bd);var Kv=Object.assign(Rt,{instanceMethods:Bd});const _s=new AudioContext,Zt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var Gv={exports:{}};(function(o){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",I="suspendedYield",R="executing",Q="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===R)throw new Error("Generator is already running");if(Ae===Q){if(me==="throw")throw Ie;return Ye()}for(k.method=me,k.arg=Ie;;){var xe=k.delegate;if(xe){var _e=G(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=Q,k.arg;k.dispatchException(k.arg)}else k.method==="return"&&k.abrupt("return",k.arg);Ae=R;var le=A(ee,V,k);if(le.type==="normal"){if(Ae=k.done?Q:I,le.arg===P)continue;return{value:le.arg,done:k.done}}else le.type==="throw"&&(Ae=Q,k.method="throw",k.arg=le.arg)}}}function G(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,G(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 b(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(b),!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),b(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;b(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}(o.exports);try{regeneratorRuntime=s}catch(n){typeof globalThis=="object"?globalThis.regeneratorRuntime=s:Function("r","regeneratorRuntime = r")(s)}})(Gv);var Kd={exports:{}};(function(o){(function(s,n){o.exports?o.exports=n():s.log=n()})(Vo,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(I,R){var Q=I[R];if(typeof Q.bind=="function")return Q.bind(I);try{return Function.prototype.bind.call(Q,I)}catch(P){return function(){return Function.prototype.apply.apply(Q,[I,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 _(I){return I==="debug"&&(I="log"),typeof console===n?!1:I==="trace"&&i?d:console[I]!==void 0?e(console,I):console.log!==void 0?e(console,"log"):s}function u(I,R){for(var Q=0;Q<a.length;Q++){var P=a[Q];this[P]=Q<I?s:this.methodFactory(P,I,R)}this.log=this.debug}function g(I,R,Q){return function(){typeof console!==n&&(u.call(this,R,Q),this[I].apply(this,arguments))}}function p(I,R,Q){return _(I)||g.apply(this,arguments)}function T(I,R,Q){var P=this,ye;R=R!=null?R:"WARN";var O="loglevel";typeof I=="string"?O+=":"+I:typeof I=="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=I,P.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},P.methodFactory=Q||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,I),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){R=H,pe()||P.setLevel(H,!1)},P.resetLevel=function(){P.setLevel(R,!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=R),P.setLevel(N,!1)}var y=new T,A={};y.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var R=A[I];return R||(R=A[I]=new T(I,y.getLevel(),y.methodFactory)),R};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})})(Kd);var Ot=Kd.exports;const In=()=>`${new Date().toISOString()} | metrics`,wn=(o,s,n)=>`${o} | ${s} | ${n}`;Ot.setDefaultLevel(Ot.levels.TRACE);const Wv=o=>{Ot.info(wn(In(),"log ",`set log level to ${o?"verbose":"info"}`)),Ot.setLevel(o?Ot.levels.TRACE:Ot.levels.INFO)},Yv=o=>{const s=[...Object.keys(Ot.levels)];s.includes(o)?(Ot.info(wn(In(),"log ",`update log level to ${o.toLowerCase()}`)),Ot.setLevel(o)):Ot.warn(wn(In(),"log ","Incorrect log level please choose one of "),s)},ke=(o,s,n)=>{n?Ot.debug(wn(In(),o,s),n):Ot.debug(wn(In(),o,s))},mu=(o,s)=>{Ot.info(wn(In(),o,s))},fs=(o,s)=>{Ot.info(wn(In(),o,s))},xo=(o,s)=>{Ot.warn(wn(In(),o,s))},Zs=(o,s)=>{Ot.error(wn(In(),o,s))};function zv(o){return Math.floor(Math.random()*o).toString()}function Gd(o,s){let n=s;return o.forEach(i=>{n=n.replace(i,"")}),n}function Xv(o,s){let n="";for(let i=0;i<s;i+=1)n+=o[zv(o.length)];return n}function Qv({length:o=20,useLetters:s=!0,useNumbers:n=!0,includeSymbols:i=[],excludeSymbols:a=[]}={}){let e="abcdefghijklmnopqrstuvwxyz",d="0123456789",_=[],u=[],g=[];return s&&(a.length&&(e=Gd(a,e)),u=e.split("")),n&&(a.length&&(d=Gd(a,d)),g=d.split("")),_=[...u,...g,...i],Xv(_,o)}var Jv=Qv;const qr=$e(Jv),Zv=()=>"WebRTCMetrics",ey=()=>"5.0.3",Le={INBOUND:"inbound",OUTBOUND:"outbound"},On={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Fr={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},ty=()=>({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:[]}),Wd={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},Yd={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},zd={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},Xd={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},ny=o=>{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(o){const n=lt(ie({},o),{audio:{},video:{},data:ie({},o.data),network:ie({},o.network),experimental:ie({},o.experimental)});return Object.keys(o.audio).forEach(i=>{n.audio[i]=ie({},o.audio[i])}),Object.keys(o.video).forEach(i=>{n.video[i]=ie({},o.video[i])}),n}return lt(ie({},s),{audio:{},video:{},data:ie({},s.data),network:ie({},s.network),experimental:ie({},s.experimental)})},sy={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${qr()}`,cid:`c-${qr()}`,uid:`u-${qr()}`,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"},jr={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},gu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},re={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},Tu="config ",ry=(o,s={},n)=>{const i=ie(ie({},n),s);return s.pname||xo(Tu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),s.cid||xo(Tu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),s.uid||xo(Tu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),i.pc=o,i},iy=(o={})=>{const s=ie(ie({},sy),o);return s.name=Zv(),s.version=ey(),s},$r=(o,s,n,i=!1,a)=>{let e=o.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=o=>o.reduce((s,n)=>s+n,0)/o.length,ly=()=>`probe-${qr()}`,oy=()=>`coltr-${qr()}`,Qd=o=>new Promise(s=>setTimeout(s,o)),vu=(o,s,n)=>{s?o.call(s,n):o(n)},Xe=(o,s,n,i)=>{const a=$r(o,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=(o,s,n,i=!1,a)=>{const e=$r(o,s,n,i,a);return e.length===0?null:e.reduce((d,_)=>d+_,0)/e.length},ps=(o,s,n)=>$r(o,s,n).reduce((i,a)=>i+a,0),Qe=(o,s,n,i)=>{const a=$r(o,s,n,!0,i);return a.length===0?null:Math.min(...a)},Je=(o,s,n,i)=>{const a=$r(o,s,n,!1,i);return a.length===0?null:Math.max(...a)},It=(o,s,n,i)=>{const a=o.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},ay=o=>o.slice().pop(),pt=(o,s,n)=>{if(!s)return null;const i={};let a=s[D.AUDIO][o];a||(a=n===Le.INBOUND?ie({},Wd):ie({},Yd)),i[D.AUDIO]=a;let e=s[D.VIDEO][o];return e||(e=n===Le.INBOUND?ie({},zd):ie({},Xd)),i[D.VIDEO]=e,i},Vr="exporter ",uy="2.0",Jd=(o,s,n)=>{if(!o||o.length===0)return 0;const i=o[o.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(o,s,"delta_rtt_ms_out",!1,n):Number(e/d)}return null},cy=(o,s)=>{if(!o||o.length===0)return 0;const n=o[o.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(o,s,"delta_rtt_connectivity_ms"):Number(i/a)},hy=o=>It(o,"network","local_candidate_type")!=="relay"?`direct/${It(o,"network","local_candidate_protocol")}`:`turn/${It(o,"network","local_candidate_relay_protocol")}`,dy=o=>{const s=It(o,"network","remote_candidate_type"),n=It(o,"network","remote_candidate_protocol");return s!=="relay"?`direct/${n}`:`turn/${n}`};class _y{constructor(s){this._start=null,this._end=null,this._cfg=s,this._referenceReport=null,this._reports=[],this._events=[]}start(){mu(Vr,"start() - start exporter...");const s=new Date;return this._start=s.toJSON(),s}stop(){mu(Vr,"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(Vr,`addReport() - add report to exporter at ${s.timestamp}`),this._reports.push(s))}addCustomEvent(s){this._events.push(s)}reset(){mu(Vr,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){ke(Vr,"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=ay(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",_),I={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=I}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:Jd(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",_),I={lost:A,avg:Math.round((A/(A+w)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},R={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=I,e[_].mos=R}}),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:Jd(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",_),I={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=I}})),{version:uy,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:cy(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:hy(this._reports),remoteConnection:dy(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 ",Zd=(o,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(o[F.TIMESTAMP]===i[s].timestamp_out||!Object.prototype.hasOwnProperty.call(o,F.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(o,F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(o[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(o[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u===d))return g;const p=1e3*Number(o[F.ROUND_TRIP_TIME]);let T=e+p,y=d+1;return a&&(T=1e3*Number(o[F.TOTAL_ROUND_TRIP_TIME])-_,y=Number(o[F.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-u),{rtt:p,totalRTT:T,totalRTTMeasurements:y}},fy=(o,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(o,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(o[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(o,F.TOTAL_ROUND_TRIP_TIME)&&(e=1e3*Number(o[F.TOTAL_ROUND_TRIP_TIME])-(n?n[s].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(o,F.RESPONSES_RECEIVED)&&(d=Number(o[F.RESPONSES_RECEIVED])-(n?n[s].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:e,totalRTTMeasurements:d}},Po=(o,s,n)=>o[F.TIMESTAMP]===n[s].timestamp_out||!Object.prototype.hasOwnProperty.call(o,F.JITTER)?null:1e3*(Number(o[F.JITTER])||0),py=(o,s)=>{if(!Object.prototype.hasOwnProperty.call(o,F.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(o,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=o[F.FRAMES_DECODED],i=o[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}},my=(o,s)=>{if(!Object.prototype.hasOwnProperty.call(o,F.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(o,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=o[F.FRAMES_ENCODED],i=o[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}},e_=(o,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(o,F.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(o,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(o[F.PACKETS_SENT])||0-(i?i[s].total_packets_out:0),e=a-n[s].total_packets_out,d=Number(o[F.BYTES_SENT])/1024-(i?i[s].total_KBytes_out:0),_=d-n[s].total_KBytes_out,u=o[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}},t_=(o,s,n,i)=>{let a=n[s].total_packets_lost_out,e=0,d=0;return Object.prototype.hasOwnProperty.call(o,F.PACKETS_LOST)&&(a=Number(o[F.PACKETS_LOST])||0-(i?i[s].total_packets_lost_out:0),e=a-n[s].total_packets_lost_out),Object.prototype.hasOwnProperty.call(o,F.FRACTION_LOST)&&(d=Number(100*o[F.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:e,fractionLost:d}},n_=(o,s,n,i)=>{if(!Object.prototype.hasOwnProperty.call(o,F.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(o,F.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(o,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(o[F.PACKETS_RECEIVED])||0-(i?i[s].total_packets_in:0),e=Number(o[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(o[F.BYTES_RECEIVED])/1024-(i?i[s].total_KBytes_in:0),p=g-n[s].total_KBytes_in,T=o[F.TIMESTAMP]||Date.now(),y=i?i.timestamp:null;let A=n.timestamp;!A&&y&&(A=y);const w=A?T-A:0,I=w>0?p*.008*1024/w*1e3:0;return{percentPacketsLost:u,packetsReceived:a,deltaPacketsReceived:_,packetsLost:e,deltaPacketsLost:d,KBytesReceived:g,deltaKBytesReceived:p,kbsReceived:I}},gy=o=>o[F.CANDIDATE_TYPE]!=="relay"?"":o[F.RELAY_PROTOCOL]||"",Ty=o=>{if(!Object.prototype.hasOwnProperty.call(o,F.NETWORK_TYPE))return jr.WIFI;switch(o[F.NETWORK_TYPE]){case gu.ETHERNET:return jr.ETHERNET;case gu.CELLULAR_4G:return jr.CELLULAR_4G;case gu.WIFI:return jr.WIFI;default:return jr.CELLULAR}},s_=o=>!Object.prototype.hasOwnProperty.call(o,F.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(o,F.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:o[F.FRAME_WIDTH]||null,height:o[F.FRAME_HEIGHT]||null,framerate:o[F.FRAMES_PER_SECOND]},vy=o=>{const s=Object.prototype.hasOwnProperty.call(o,F.QUALITY_LIMITATION_REASON)?o[F.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(o,F.QUALITY_LIMITATION_RESOLUTION_CHANGES)?o[F.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,i=Object.prototype.hasOwnProperty.call(o,F.QUALITY_LIMITATION_DURATIONS)?o[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}},yy=(o,s,n)=>{if(!Object.prototype.hasOwnProperty.call(o,F.PLI)||!Object.prototype.hasOwnProperty.call(o,F.NACK))return{pliCount:s.total_pli_sent_in,nackCount:s.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const i=(o[F.PLI]||0)-(n?n[D.VIDEO].total_pli_sent_in:0),a=(o[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}},Ey=(o,s,n)=>{if(!Object.prototype.hasOwnProperty.call(o,F.PLI)||!Object.prototype.hasOwnProperty.call(o,F.NACK))return{pliCount:s.total_pli_received_out,nackCount:s.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const i=(o[F.PLI]||0)-(n?n[D.VIDEO].total_pli_received_out:0),a=(o[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}},Sy=o=>({channels:o[F.CHANNELS]||null,clock_rate:o[F.CLOCK_RATE]||null,mime_type:o[F.MIME_TYPE]||null,sdp_fmtp_line:o[F.SDP_FMTP_LINE]||null}),Ay=o=>({clock_rate:o[F.CLOCK_RATE]||null,mime_type:o[F.MIME_TYPE]||null}),Cy=(o,s,n)=>{const i=(o[F.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),a=(o[F.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),e=o[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}},by=o=>{const s=o[F.AVAILABLE_INCOMING_BITRATE]/1024||0,n=o[F.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:s,kbs_outgoing_bandwidth:n}},Ry=(o,s,n,i)=>{if(!o)return[];switch(o[F.TYPE]){case en.CANDIDATE_PAIR:let a=!1;if(o[F.NOMINATED]&&o[F.STATE]===D.SUCCEEDED&&(a=!0,ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o),F.SELECTED in o&&!o[F.SELECTED]&&(a=!1)),a){const d=o[F.LOCAL_CANDIDATE_ID],_=o[F.REMOTE_CANDIDATE_ID],u=Cy(o,s,i),g=by(o),p=fy(o,"data",i,s);return[{type:re.NETWORK,value:{local_candidate_id:d}},{type:re.NETWORK,value:{remote_candidate_id:_}},{type:re.DATA,value:{total_KBytes_in:u.total_KBytes_received}},{type:re.DATA,value:{total_KBytes_out:u.total_KBytes_sent}},{type:re.DATA,value:{delta_KBytes_in:u.delta_KBytes_received}},{type:re.DATA,value:{delta_KBytes_out:u.delta_KBytes_sent}},{type:re.DATA,value:{delta_kbs_in:u.kbs_speed_received}},{type:re.DATA,value:{delta_kbs_out:u.kbs_speed_sent}},{type:re.DATA,value:{delta_kbs_bandwidth_in:g.kbs_incoming_bandwidth}},{type:re.DATA,value:{delta_kbs_bandwidth_out:g.kbs_outgoing_bandwidth}},{type:re.DATA,value:{delta_rtt_connectivity_ms:p.rtt}},{type:re.DATA,value:{total_rtt_connectivity_ms:p.totalRTT}},{type:re.DATA,value:{total_rtt_connectivity_measure:p.totalRTTMeasurements}}]}break;case en.LOCAL_CANDIDATE:if(o[F.ID]===s.network.local_candidate_id)return[{type:re.NETWORK,value:{infrastructure:Ty(o)}},{type:re.NETWORK,value:{local_candidate_type:o[F.CANDIDATE_TYPE]||""}},{type:re.NETWORK,value:{local_candidate_protocol:o[F.PROTOCOL]||""}},{type:re.NETWORK,value:{local_candidate_relay_protocol:gy(o)}}];break;case en.REMOTE_CANDIDATE:if(o[F.ID]===s.network.remote_candidate_id)return[{type:re.NETWORK,value:{remote_candidate_type:o[F.CANDIDATE_TYPE]||""}},{type:re.NETWORK,value:{remote_candidate_protocol:o[F.PROTOCOL]||""}}];break;case en.INBOUND_RTP:{ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);const d=o[F.SSRC],_=pt(d,s,Le.INBOUND);_&&(_.timestamp=s.timestamp);const u=pt(d,i,Le.INBOUND);if(u&&(u.timestamp=i.timestamp),o[F.MEDIA_TYPE]===D.AUDIO){const g=n_(o,D.AUDIO,_,u),p=Po(o,D.AUDIO,_),T=o[F.CODEC_ID]||"";return[{ssrc:d,type:re.AUDIO,value:{codec_id_in:T}},{ssrc:d,type:re.AUDIO,value:{total_packets_in:g.packetsReceived}},{ssrc:d,type:re.AUDIO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:d,type:re.AUDIO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:d,type:re.AUDIO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:d,type:re.AUDIO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:d,type:re.AUDIO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:d,type:re.AUDIO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:d,type:re.AUDIO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:d,type:re.AUDIO,value:{delta_jitter_ms_in:p}}]}if(o[F.MEDIA_TYPE]===D.VIDEO){const g=py(o,_),p=n_(o,D.VIDEO,_,u),T=Po(o,D.VIDEO,_),y=o[F.DECODER_IMPLEMENTATION]||null,A=o[F.CODEC_ID]||null,w=s_(o),I=yy(o,_,u);return[{ssrc:d,type:re.VIDEO,value:{codec_id_in:A}},{ssrc:d,type:re.VIDEO,value:{total_packets_in:p.packetsReceived}},{ssrc:d,type:re.VIDEO,value:{delta_packets_in:p.deltaPacketsReceived}},{ssrc:d,type:re.VIDEO,value:{total_packets_lost_in:p.packetsLost}},{ssrc:d,type:re.VIDEO,value:{delta_packets_lost_in:p.deltaPacketsLost}},{ssrc:d,type:re.VIDEO,value:{percent_packets_lost_in:p.percentPacketsLost}},{ssrc:d,type:re.VIDEO,value:{total_KBytes_in:p.KBytesReceived}},{ssrc:d,type:re.VIDEO,value:{delta_KBytes_in:p.deltaKBytesReceived}},{ssrc:d,type:re.VIDEO,value:{delta_kbs_in:p.kbsReceived}},{ssrc:d,type:re.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:d,type:re.VIDEO,value:{decoder_in:y}},{ssrc:d,type:re.VIDEO,value:{delta_ms_decode_frame_in:g.delta_ms_decode_frame}},{ssrc:d,type:re.VIDEO,value:{total_frames_decoded_in:g.frames_decoded}},{ssrc:d,type:re.VIDEO,value:{total_time_decoded_in:g.total_decode_time}},{ssrc:d,type:re.VIDEO,value:{total_nack_sent_in:I.nackCount}},{ssrc:d,type:re.VIDEO,value:{delta_nack_sent_in:I.deltaNackCount}},{ssrc:d,type:re.VIDEO,value:{total_pli_sent_in:I.pliCount}},{ssrc:d,type:re.VIDEO,value:{delta_pli_sent_in:I.deltaPliCount}},{ssrc:d,type:re.VIDEO,value:{size_in:w}}]}break}case en.OUTBOUND_RTP:{ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);const d=o[F.SSRC],_=pt(d,s,Le.OUTBOUND);_&&(_.timestamp=s.timestamp);const u=pt(d,i,Le.OUTBOUND);if(u&&(u.timestamp=i.timestamp),o[F.MEDIA_TYPE]===D.AUDIO){const g=o[F.CODEC_ID]||null,p=e_(o,D.AUDIO,_,u);return[{ssrc:d,type:re.AUDIO,value:{codec_id_out:g}},{ssrc:d,type:re.AUDIO,value:{total_packets_out:p.packetsSent}},{ssrc:d,type:re.AUDIO,value:{delta_packets_out:p.deltaPacketsSent}},{ssrc:d,type:re.AUDIO,value:{total_KBytes_out:p.KBytesSent}},{ssrc:d,type:re.AUDIO,value:{delta_KBytes_out:p.deltaKBytesSent}},{ssrc:d,type:re.AUDIO,value:{delta_kbs_out:p.kbsSent}}]}if(o[F.MEDIA_TYPE]===D.VIDEO){const g=o[F.ENCODER_IMPLEMENTATION]||null,p=o[F.CODEC_ID]||null,T=my(o,_),y=s_(o),A=vy(o),w=Ey(o,_,u),I=e_(o,D.VIDEO,_,u);return[{ssrc:d,type:re.VIDEO,value:{codec_id_out:p}},{ssrc:d,type:re.VIDEO,value:{total_packets_out:I.packetsSent}},{ssrc:d,type:re.VIDEO,value:{delta_packets_out:I.deltaPacketsSent}},{ssrc:d,type:re.VIDEO,value:{total_KBytes_out:I.KBytesSent}},{ssrc:d,type:re.VIDEO,value:{delta_KBytes_out:I.deltaKBytesSent}},{ssrc:d,type:re.VIDEO,value:{delta_kbs_out:I.kbsSent}},{ssrc:d,type:re.VIDEO,value:{encoder_out:g}},{ssrc:d,type:re.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:d,type:re.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:d,type:re.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:d,type:re.VIDEO,value:{total_nack_received_out:w.nackCount}},{ssrc:d,type:re.VIDEO,value:{delta_nack_received_out:w.deltaNackCount}},{ssrc:d,type:re.VIDEO,value:{total_pli_received_out:w.pliCount}},{ssrc:d,type:re.VIDEO,value:{delta_pli_received_out:w.deltaPliCount}},{ssrc:d,type:re.VIDEO,value:{size_out:y}},{ssrc:d,type:re.VIDEO,value:{limitation_out:A}}]}break}case en.MEDIA_SOURCE:{ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);break}case en.TRACK:{ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);break}case en.CODEC:const e=[];return Object.keys(s[D.AUDIO]).forEach(d=>{const _=s[D.AUDIO][d];if(_.codec_id_in===o[F.ID]||_.codec_id_out===o[F.ID]){ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);const u=Sy(o);o[F.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:re.AUDIO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:re.AUDIO,value:{codec_out:u}})}}),Object.keys(s[D.VIDEO]).forEach(d=>{const _=s[D.VIDEO][d];if(_.codec_id_in===o[F.ID]||_.codec_id_out===o[F.ID]){ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);const u=Ay(o);o[F.ID]===_.codec_id_in?e.push({ssrc:_.ssrc,type:re.VIDEO,value:{codec_in:u}}):e.push({ssrc:_.ssrc,type:re.VIDEO,value:{codec_out:u}})}}),e;case en.REMOTE_INBOUND_RTP:{ke(ns,`analyze() - got stats ${o[F.TYPE]} for ${n}`,o);const d=o[F.SSRC],_=pt(d,s,Le.OUTBOUND),u=pt(d,i,Le.OUTBOUND);if(o[F.KIND]===D.AUDIO){const g=Zd(o,D.AUDIO,u,_),p=Po(o,D.AUDIO,_),T=t_(o,D.AUDIO,_,u);return[{ssrc:d,type:re.AUDIO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:re.AUDIO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:re.AUDIO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:re.AUDIO,value:{delta_jitter_ms_out:p}},{ssrc:d,type:re.AUDIO,value:{timestamp_out:o[F.TIMESTAMP]}},{ssrc:d,type:re.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:re.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:re.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(o[F.KIND]===D.VIDEO){const g=Zd(o,D.VIDEO,u,_),p=Po(o,D.VIDEO,_),T=t_(o,D.VIDEO,_,u);return[{ssrc:d,type:re.VIDEO,value:{delta_rtt_ms_out:g.rtt}},{ssrc:d,type:re.VIDEO,value:{total_rtt_ms_out:g.totalRTT}},{ssrc:d,type:re.VIDEO,value:{total_rtt_measure_out:g.totalRTTMeasurements}},{ssrc:d,type:re.VIDEO,value:{delta_jitter_ms_out:p}},{ssrc:d,type:re.VIDEO,value:{timestamp_out:o[F.TIMESTAMP]}},{ssrc:d,type:re.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:d,type:re.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:d,type:re.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Lo=o=>o<0?1:o>100?4.5:1+.035*o+7/1e6*o*(o-60)*(100-o),Iy=(o,s=D.AUDIO,n,i,a)=>{const e=pt(a,o,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=o.data.delta_rtt_connectivity_ms,I=n&&n.data.delta_rtt_connectivity_ms||null,R=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),I&&u.push(I),R&&u.push(R),T&&g.push(T),n&&y&&g.push(y),i&&A&&g.push(A);const Q=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=(Q+P)/2,pe=j-177.3<0?0:1,Te=.024*j+.11*(j-177.3)*pe,N=O-Te;return Lo(N)},wy=(o,s=D.AUDIO,n,i,a)=>{const e=pt(a,o,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,I=d&&d[s].delta_jitter_ms_out||null,R=_&&_[s].delta_jitter_ms_out||null,Q=o.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):Q&&u.push(Q),y?u.push(y):P&&u.push(P),A?u.push(A):ye&&u.push(ye),w&&g.push(w),n&&I&&g.push(I),i&&R&&g.push(R);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 Lo(q)},Oy=(o,s=D.AUDIO,n,i,a)=>{const e=pt(a,o,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=o.data.delta_rtt_connectivity_ms,I=n&&n.data.delta_rtt_connectivity_ms||null,R=i&&i.data.delta_rtt_connectivity_ms||null;w&&u.push(w),I&&u.push(I),R&&u.push(R),T&&g.push(T),d&&y&&g.push(y),_&&A&&g.push(A);const Q=u.length>0?ts(u):100,P=g.length>0?ts(g):10,ye=0,O=19.8,j=29.7,pe=30,Te=(Q+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 Lo($)},Ny=(o,s=D.AUDIO,n,i,a)=>{const e=pt(a,o,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,I=d&&d[s].delta_jitter_ms_out||null,R=_&&_[s].delta_jitter_ms_out||null,Q=o.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):Q&&u.push(Q),y?u.push(y):P&&u.push(P),A?u.push(A):ye&&u.push(ye),w&&g.push(w),d&&I&&g.push(I),_&&R&&g.push(R);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,G=93.2-(pe+Te*Math.log(1+N*p)+M);return Lo(G)};class Dy{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 _y(s),this._state=On.IDLE,this.registerToPCEvents(),fs(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?ie({},Wd):ie({},Yd):g===en.INBOUND_RTP?ie({},zd):ie({},Xd),d=ny(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),Ry(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=Iy(d,D.AUDIO,n,i,g.ssrc),g.mos_in=Oy(d,D.AUDIO,n,i,g.ssrc)):(g.mos_emodel_out=wy(d,D.AUDIO,n,i,g.ssrc),g.mos_out=Ny(d,D.AUDIO,n,i,g.ssrc))}),d}takeReferenceStats(){return oe(this,null,function*(){return new Promise((s,n)=>{const i=Date.now();setTimeout(()=>oe(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 oe(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 Zs(this._moduleName,`got error ${s}`),null}})}start(){return oe(this,null,function*(){ke(this._moduleName,"starting"),this.state=On.RUNNING,this._startedTime=this._exporter.start(),ke(this._moduleName,"started")})}mute(){return oe(this,null,function*(){this.state=On.MUTED,ke(this._moduleName,"muted")})}unmute(){return oe(this,null,function*(){this.state=On.RUNNING,ke(this._moduleName,"unmuted")})}stop(s){return oe(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}'`)):Zs(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}'`)):Zs(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReport(s){this._callbacks.onreport&&vu(this._callbacks.onreport.callback,this._callbacks.onreport.context,s)}fireOnTicket(s){this._callbacks.onticket&&vu(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 oe(this,null,function*(){const{pc:s}=this._config;if(navigator.mediaDevices.ondevicechange=()=>oe(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){Zs(this._moduleName,"can't get devices")}}),s){s.oniceconnectionstatechange=()=>{const i=s.iceConnectionState;i===Fr.CONNECTED||i===Fr.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===Fr.DISCONNECTED||i===Fr.FAILED?this.addCustomEvent(new Date().toJSON(),"call",i,"ICE connection state"):i===Fr.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 ky{constructor(s){this._id=s.pname&&s.pname.substr(0,12).padEnd(12," ")||ly(),this._moduleName=this._id,fs(this._moduleName,"probe created"),this._config=s,this._collector=new Dy(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){xo(this._moduleName,"probe is already running");return}this._collector.start()}stop(s=!1){this.isRunning&&this._collector.stop(s)}takeReferenceStats(){return oe(this,null,function*(){return this._collector.takeReferenceStats()})}collectStats(){return oe(this,null,function*(){return this._collector.collectStats()})}}const Nt="engine ";class Uy{constructor(s){this._config=s,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},fs(Nt,`configured for probing every ${this._config.refreshEvery}ms`),fs(Nt,`configured for starting after ${this._config.startAfter}ms`),fs(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=ry(s,n,this._config),a=new ky(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 oe(this,null,function*(){const s=()=>{this._probes.forEach(e=>e.start())},n=()=>oe(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=()=>oe(this,null,function*(){const e=ty(),d=this._probes.filter(_=>_.isRunning);for(const _ of d){const u=yield _.collectStats();u&&e.probes.push(u),ke(Nt,`got probe ${_.id}`),yield Qd(0)}return e.delta_time_to_measure_probes_ms=ps(e.probes,"experimental","time_to_measure_ms"),e.delta_KBytes_in=ps(e.probes,"data","delta_KBytes_in"),e.delta_KBytes_out=ps(e.probes,"data","delta_KBytes_out"),e.delta_kbs_in=ps(e.probes,"data","delta_kbs_in"),e.delta_kbs_out=ps(e.probes,"data","delta_kbs_out"),e.total_time_decoded_in=ps(e.probes,"video","total_time_decoded_in"),e.total_time_encoded_out=ps(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 Qd(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)})};fs(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}'`)):Zs(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}'`)):Zs(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReports(s){this._callbacks.onresult&&s.probes.length>0&&vu(this._callbacks.onresult.callback,this._callbacks.onresult.context,s)}}const My="interface ";class xy{constructor(s){this._config=iy(s),fs(My,`welcome to ${this._config.name} version ${this._config.version}`),Wv(this._config.verbose||!1),this._engine=new Uy(this._config)}setupLogLevel(s){Yv(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 Py(o,s){return Object.keys(o).filter(n=>s.includes(n)).reduce((n,i)=>{const a=i;return lt(ie({},n),{[a]:o[a]})},{})}const Ly=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class Hy{constructor(s){this.intervals={},this.emitInterval=s.emitInterval||200,this.onChangeFunction=s.onChangeFunction}start(s,n){s&&s.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(s,n))}stop(s){this.clearVolumeInterval(s)}clearVolumeInterval(s){clearInterval(this.intervals[s]),delete this.intervals[s]}clearAllIntervals(){Object.keys(this.intervals).forEach(s=>{clearInterval(this.intervals[s])}),this.intervals={}}beginCalculation(s,n){this.clearVolumeInterval(n);const i=_s.createAnalyser(),a=_s.createMediaStreamSource(s),e=_s.createScriptProcessor(2048,1,1);i.smoothingTimeConstant=.8,i.fftSize=1024,a.connect(i),i.connect(e),e.connect(_s.destination),this.intervals[n]=setInterval(()=>{const d=new Uint8Array(i.frequencyBinCount);i.getByteFrequencyData(d);let _=0;const u=d.length;for(let p=0;p<u;p++)_+=d[p];const g=_/u;this.onChangeFunction(n,g)},this.emitInterval)}}const Ho={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.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=s,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new Hy({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return lt(ie({},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 Vd()?{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 oe(this,null,function*(){yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const s=yield navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)})}initializeMediaDevices(){return oe(this,null,function*(){const s=localStorage.getItem(Ho.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(Ho.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",()=>oe(this,null,function*(){const e=yield navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(e)})),i.getTracks().forEach(e=>e.stop())}catch(i){console.error(i)}})}setCallTime(s){const n=ie({},s);delete n.callId,this.callTime=lt(ie({},this.callTime),{[s.callId]:n}),this.context.emit("changeCallTime",this.callTime)}removeCallTime(s){const n=ie({},this.callTime);delete n[s],this.callTime=ie({},n),this.context.emit("changeCallTime",this.callTime)}setTimeInterval(s,n){this.timeIntervals=lt(ie({},this.timeIntervals),{[s]:n})}removeTimeInterval(s){const n=ie({},this.timeIntervals);n[s]&&(clearInterval(n[s]),delete n[s],this.timeIntervals=ie({},n))}stopCallTimer(s){this.removeTimeInterval(s),this.removeCallTime(s)}emitVolumeChange(s,n){this.context.emit("changeCallVolume",{callId:s,volume:n})}setMetricsConfig(s){this.metricConfig=ie(ie({},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 oe(this,arguments,function*({callId:s,toHold:n,automatic:i}){const e=this.extendedCalls[s];e._automaticHold=i!=null?i:!1,yield new Promise(_=>{const u=()=>{e.putOnHoldTimestamp=n?Date.now():void 0,_()};n?e.hold({},u):e.unhold({},u)}),this.updateCall(e);const d=Object.values(this.extendedCalls).filter(_=>_.roomId===this.currentActiveRoomId&&(n?s!==_._id:!0));d.length>1&&(yield this.doConference(d))})}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 oe(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]=Fd(s),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(s){const n=ie(ie({},this.activeRooms[s.roomId]),s);this.activeRooms=lt(ie({},this.activeRooms),{[s.roomId]:ie({},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=lt(ie({},this.activeCalls),{[s._id]:Fd(s)}),this.extendedCalls[s._id]=s,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(s){this.callStatus=lt(ie({},this.callStatus),{[s]:{isMoving:!1,isTransferring:!1,isMerging:!1,isTransferred:!1}}),this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(s){const n=ie({},ie({},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=lt(ie({},this.callStatus),{[s.callId]:ie({},n)}),this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(s){const n=ie({},this.callStatus);delete n[s],this.callStatus=ie({},n),this.context.emit("changeCallStatus",this.callStatus)}addRoom(s){this.activeRooms=lt(ie({},this.activeRooms),{[s.roomId]:s}),this.context.emit("addRoom",{room:s,roomList:this.activeRooms})}getActiveStream(){const s=$d(this.initialStreamValue,this.microphoneInputLevel*2);return s.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(s),s}setMicrophone(s){return oe(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=>oe(this,null,function*(){const a=this.getActiveStream();i.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(i)})):yield this.doConference(n)})}setActiveStream(s){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(s,"origin"),this.activeStreamValue=s,this.context.emit("changeActiveStream",s)}setSpeaker(s){return oe(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=ie({},this.activeRooms),i=ie({},n[s]);delete n[s],this.activeRooms=ie({},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 oe(this,null,function*(){var n;if(s===void 0)return;const i=Object.values(this.extendedCalls).filter(a=>a.roomId===s);if(this.currentActiveRoomId===s?i.forEach(a=>{a.audioTag&&(this.muteReconfigure(a),a.audioTag.muted=!1,this.updateCall(a))}):i.forEach(a=>{a.audioTag&&(a.audioTag.muted=!0,this.updateCall(a))}),i.length===0)this.deleteRoomIfEmpty(s);else if(i.length===1&&this.currentActiveRoomId!==s)i[0].isOnHold().local||(yield this.holdCall(i[0].id,!0));else if(i.length===1&&this.currentActiveRoomId===s){if(i[0].isOnHold().local&&i[0]._automaticHold&&(yield this.unholdCall(i[0].id)),i[0].connection&&(n=i[0].connection)!=null&&n.getSenders()[0]){const a=this.getActiveStream();yield i[0].connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.muteReconfigure(i[0])}}else i.length>1&&(yield this.doConference(i))})}doConference(s){return oe(this,null,function*(){const n=[];s.forEach(i=>{i!=null&&i.connection.getReceivers().forEach(a=>{n.push(a.track)})}),yield Kv.forEach(s,i=>oe(this,null,function*(){var a;if(i==null)return;const e=new MediaStream,d=_s.createMediaStreamDestination();if(i.connection.getReceivers().forEach(_=>{n.forEach(u=>{e.addTrack(_.track),_.track.id!==u.id&&_s.createMediaStreamSource(new MediaStream([u])).connect(d)})}),s[0].roomId===this.currentActiveRoomId){const _=this.getActiveStream();_s.createMediaStreamSource(_).connect(d)}(a=i.connection)!=null&&a.getSenders()[0]&&(yield i.connection.getSenders()[0].replaceTrack(d.stream.getTracks()[0]),this.muteReconfigure(i))}))})}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=ie({},this.callTime[s]),e=Bv(a);this.setCallTime(ie({callId:s},e))},1e3);this.setTimeInterval(s,i)}setActiveRoom(s){return oe(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 oe(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=ie({},this.activeCalls);delete n[s],this.activeCalls=ie({},n);const i=ie({},this.extendedCalls);delete i[s],this.extendedCalls=ie({},i),this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(s){var n;const i=this.extendedCalls[s._id];this.stopVUMeter("origin"),(n=i.connection)==null||n.getSenders().forEach(e=>{e.track.stop()});const a=i.roomId;this.removeCall(s._id),this.roomReconfigure(a)}shouldTerminateNewSession(s){if(s.session.direction==="outgoing")return!1;const n=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||n}newRTCSessionCallback(s){return oe(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()),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()),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;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(Ho.SELECTED_INPUT_DEVICE,s),this.selectedMediaDevices.input=s,this.context.emit("changeActiveInputMediaDevice",s)}setSelectedOutputDevice(s){localStorage.setItem(Ho.SELECTED_OUTPUT_DEVICE,s),this.selectedMediaDevices.output=s,this.context.emit("changeActiveOutputMediaDevice",s)}setCallMetrics(s){const n=ie({},s);delete n.callId,this.callMetrics=lt(ie({},this.callMetrics),{[s.callId]:n}),this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(s){const n=ie({},this.callMetrics);delete n[s],this.callMetrics=ie({},n),this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(s){const n=new xy(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=Py(_,Ly);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){this.VUMeter.start(s,n)}stopVUMeter(s){this.VUMeter.stop(s)}setupStream(){return oe(this,null,function*(){const s=yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=s})}triggerAddStream(s,n){return oe(this,null,function*(){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||(yield this.setupStream());const i=$d(this.initialStreamValue,this.microphoneInputLevel*2),a=this.isMuted||this.muteWhenJoin;i.getTracks().forEach(d=>d.enabled=!a),this.setActiveStream(i),yield n.connection.getSenders()[0].replaceTrack(i.getTracks()[0]);const e=new MediaStream([s.track]);Ov(e,n,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(e,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=>{this.triggerAddStream(e,a)})}processRoomChange(i){return oe(this,arguments,function*({callId:s,roomId:n}){const a=this.extendedCalls[s].roomId;this.extendedCalls[s].roomId=n;const e=this.extendedCalls[s];return this.updateCall(e),yield this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})})}}class jy{constructor(s){this.context=s}get sipOptions(){return ie({},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]=jd(s),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(s){this.activeMessages=lt(ie({},this.activeMessages),{[s._id]:jd(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=lt(ie({},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=ie({},this.activeMessages);delete n[s],this.activeMessages=ie({},n);const i=ie({},this.extendedMessages);delete i[s],this.extendedMessages=ie({},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 qo={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class r_{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 r_{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 oe(this,null,function*(){const s=new wr(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=>oe(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 oe(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:ie({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=>oe(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 oe(this,null,function*(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)})}stop(){return oe(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 oe(this,null,function*(){throw new Error("generateStream method is not implemented")})}}class By extends r_{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 oe(this,null,function*(){if(this.immediate){const n=yield this.start(s);return this.running=!0,n}return s})}connect(){return oe(this,null,function*(){this.running=!0,yield this.session.resyncPlugins(this.type)})}terminate(){this.stop()}kill(){return oe(this,null,function*(){this.stop(),this.running=!1,yield this.session.resyncPlugins(this.type)})}}class Ky extends Sv{constructor(s,n){if(!s.modules.length)throw new Error("options.modules should include at least 1 module");const i=lt(ie({},s.configuration),{sockets:s.socketInterfaces.map(a=>new Vv.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.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,n&&Nv(n)&&(this.logger=n)}isWaitingForSessionHangup(){return this.waitingForSessionHangup}stopSessionAfterWaiting(){this.setInitialized(!1),this.waitingForSessionHangup=!1,clearTimeout(this.waitingForSessionTimeout),this.waitingForSessionTimeout=null,this.activeConnection&&setTimeout(this.start.bind(this),5e3)}get hasActiveSessions(){return this.modules.includes(qo.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)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(qo.AUDIO)&&(this.audio=new Fy(this)),this.modules.includes(qo.MSRP)&&(this.msrp=new $y(this)),this.modules.includes(qo.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.on(this.disconnectedEventName,()=>{this.setConnected(!1),!this.isReconnecting&&(this.setReconnecting(!0),this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.hasActiveSessions?(this.waitingForSessionHangup=!0,this.stop(!1),this.waitingForSessionTimeout=setTimeout(()=>{this.terminateAllSessions(),this.setInitialized(!1),this.waitingForSessionHangup=!1,this.activeConnection&&setTimeout(this.start.bind(this),5e3)},12e5)):(this.stop(),this.setInitialized(!1),this.activeConnection&&setTimeout(this.start.bind(this),5e3)))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(s,n){const i=!this.listenersList[s]||!this.listenersList[s].length?[n]:[...this.listenersList[s],n];this.listenersList=lt(ie({},this.listenersList),{[s]:i})}removeIListener(s){const n=ie({},this.listenersList);delete n[s],this.listenersList=ie({},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 i_=ve.ref(!1),l_=ve.ref(!1),o_=ve.ref(!1),a_=ve.ref({}),u_=ve.ref({}),c_=ve.ref(!1),h_=ve.ref(void 0),Fo=ve.ref({}),yu=ve.ref({}),jo=ve.ref([]),Eu=ve.ref("default"),Su=ve.ref("default"),Au=ve.ref(!1),Cu=ve.ref(!1),bu=ve.ref(!0),d_=ve.ref(!1),__=ve.ref(null),er=ve.ref(void 0),f_=ve.ref(!1),Ru=ve.ref(2),Iu=ve.ref(1),wu=ve.ref({}),p_=ve.ref({}),m_=ve.ref({}),Ou=ve.computed(()=>{const o={};return Object.entries(a_.value).forEach(([s,n])=>{var i;(i=wu.value[s])!=null&&i.isTransferred||(o[s]=n)}),o}),Gy=ve.computed(()=>{const o={},s=Object.values(Ou.value).map(n=>n.roomId);return Object.entries(Fo.value).forEach(([n,i])=>{s.includes(i.roomId)&&(o[n]=i)}),o}),Wy=ve.computed(()=>jo.value.filter(o=>o.kind==="audioinput").map(o=>({deviceId:o.deviceId,kind:o.kind,groupId:o.groupId,label:o.label}))),Yy=ve.computed(()=>jo.value.filter(o=>o.kind==="audiooutput").map(o=>({deviceId:o.deviceId,kind:o.kind,groupId:o.groupId,label:o.label}))),g_=ve.computed(()=>Object.values(Ou.value).filter(o=>o.roomId===er.value));ve.watch(g_,o=>{!o.length&&er.value&&(er.value=void 0)}),ve.watch(Su,o=>oe(this,null,function*(){yield tn.actions.setMicrophone(o)})),ve.watch(Eu,o=>oe(this,null,function*(){yield tn.actions.setSpeaker(o)})),ve.watch(Au,o=>{tn.actions.setMuteWhenJoin(o)}),ve.watch(Cu,o=>{tn.actions.setDND(o)}),ve.watch(bu,o=>{tn.actions.setCallWaiting(o)}),ve.watch(Ru,o=>{tn.actions.setMicrophoneSensitivity(o)}),ve.watch(Iu,o=>{tn.actions.setSpeakerVolume(o)}),ve.watch(er,o=>oe(this,null,function*(){yield tn.actions.setActiveRoom(o)}));const tn={state:{isInitialized:i_,isOpenSIPSReady:l_,isOpenSIPSReconnecting:o_,activeCalls:Ou,callsInActiveRoom:g_,activeMessages:u_,addCallToCurrentRoom:c_,callAddingInProgress:h_,activeRooms:Gy,msrpHistory:yu,availableMediaDevices:jo,inputMediaDeviceList:Wy,outputMediaDeviceList:Yy,selectedOutputDevice:Eu,selectedInputDevice:Su,muteWhenJoin:Au,isDND:Cu,isCallWaitingEnabled:bu,isMuted:d_,originalStream:__,currentActiveRoomId:er,callStatus:wu,callTime:p_,callMetrics:m_,autoAnswer:f_,microphoneInputLevel:Ru,speakerVolume:Iu},actions:{init(o,s,n,i,a={}){return new Promise((e,d)=>{try{se=new Ky({configuration:lt(ie({},a),{session_timers:!1,uri:`sip:${s}@${o}`,password:n}),socketInterfaces:[`wss://${o}`],sipDomain:`${o}`,sipOptions:{session_timers:!1,extraHeaders:["X-Bar: bar"],pcConfig:{}},modules:["audio"],pnExtraHeaders:i}),se.on("connection",_=>{c_.value=!1,i_.value=!0,l_.value=_,e(se)}).on("reconnecting",_=>{o_.value=_}).on("changeActiveCalls",_=>{a_.value=ie({},_)}).on("changeActiveMessages",_=>{u_.value=ie({},_)}).on("newMSRPMessage",_=>{const u=_.session._id,g=yu.value[u]||[];g.push(_.message),yu.value[u]=[...g]}).on("callAddingInProgressChanged",_=>{h_.value=_}).on("changeAvailableDeviceList",_=>{jo.value=[..._]}).on("changeActiveInputMediaDevice",_=>{Su.value=_}).on("changeActiveOutputMediaDevice",_=>{Eu.value=_}).on("changeMuteWhenJoin",_=>{Au.value=_}).on("changeIsCallWaiting",_=>{bu.value=_}).on("changeIsDND",_=>{Cu.value=_}).on("changeIsMuted",_=>{d_.value=_}).on("changeActiveStream",_=>{__.value=_}).on("currentActiveRoomChanged",_=>{er.value=_}).on("addRoom",({roomList:_})=>{Fo.value=ie({},_)}).on("updateRoom",({roomList:_})=>{Fo.value=ie({},_)}).on("removeRoom",({roomList:_})=>{Fo.value=ie({},_)}).on("changeCallStatus",_=>{wu.value=ie({},_)}).on("changeCallTime",_=>{p_.value=ie({},_)}).on("changeCallMetrics",_=>{m_.value=ie({},_)}).begin(),e(se)}catch(_){console.error(_),d()}})},unregister(){se==null||se.unregister()},register(){se==null||se.register()},disconnect(){se==null||se.disconnect()},initCall(o,s=!1,n=!1){se==null||se.audio.initCall(o,s,n)},answerCall(o){se==null||se.audio.answerCall(o)},terminateCall(o){se==null||se.audio.terminateCall(o)},mute(){se==null||se.audio.mute()},unmute(){se==null||se.audio.unmute()},transferCall(o,s){se==null||se.audio.transferCall(o,s)},mergeCall(o){se==null||se.audio.mergeCall(o)},mergeCallByIds(o,s){se==null||se.audio.mergeCallByIds(o,s)},holdCall(o,s){se==null||se.audio.holdCall(o,s)},unholdCall(o){se==null||se.audio.unholdCall(o)},moveCall(o,s){return oe(this,null,function*(){yield se==null?void 0:se.audio.moveCall(o,s)})},muteCaller(o){se==null||se.audio.muteCaller(o)},unmuteCaller(o){se==null||se.audio.unmuteCaller(o)},setMuteWhenJoin(o){se==null||se.audio.setMuteWhenJoin(o)},setDND(o){se==null||se.audio.setDND(o)},setCallWaiting(o){se==null||se.audio.setCallWaiting(o)},setMicrophone(o){return oe(this,null,function*(){yield se==null?void 0:se.audio.setMicrophone(o)})},setSpeaker(o){return oe(this,null,function*(){yield se==null?void 0:se.audio.setSpeaker(o)})},sendDTMF(o,s){se==null||se.audio.sendDTMF(o,s)},setActiveRoom(o){return oe(this,null,function*(){yield se==null?void 0:se.audio.setActiveRoom(o)})},setMicrophoneSensitivity(o){Ru.value=o,se==null||se.audio.setMicrophoneSensitivity(o)},setSpeakerVolume(o){Iu.value=o,se==null||se.audio.setSpeakerVolume(o)},setAutoAnswer(o){f_.value=o,se==null||se.audio.setAutoAnswer(o)},setMetricsConfig(o){se==null||se.audio.setMetricsConfig(o)},msrpAnswer(o){se==null||se.msrp.msrpAnswer(o)},messageTerminate(o){se==null||se.msrp.messageTerminate(o)},sendMSRP(o,s){se==null||se.msrp.sendMSRP(o,s)},initMSRP(o,s,n){se==null||se.msrp.initMSRP(o,s,n)}}},T_=Symbol();function zy(){return ve.provide(T_,tn),tn}function Xy(){const o=ve.inject(T_);if(!o)throw new Error("useVsipInject() is called without provider, please call useVsipProvide() first");return o}et.useVsipInject=Xy,et.useVsipProvide=zy,et.vsipAPI=tn,Object.defineProperty(et,Symbol.toStringTag,{value:"Module"})});
|
|
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=Ae.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=Ae.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===Ae.STATUS_TERMINATED)throw new Xn.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ae.STATUS_NULL:case Ae.STATUS_INVITE_SENT:case Ae.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===Ae.STATUS_NULL||this._status===Ae.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=e):this._status===Ae.STATUS_1XX_RECEIVED&&this._request.cancel(e),this._status=Ae.STATUS_CANCELED,this._failed("local",null,U.causes.CANCELED);break;case Ae.STATUS_WAITING_FOR_ANSWER:case Ae.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 Ae.STATUS_WAITING_FOR_ACK:case Ae.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===Ae.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!==Ae.STATUS_INVITE_SENT&&this._status!==Ae.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(s.status_code):this._status=Ae.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=Ae.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=Ae.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=Ae.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=Ae.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===Ae.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!==Ae.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!==Ae.STATUS_TERMINATED){if(this._status=Ae.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 Ae.STATUS_CANCELED:case Ae.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===Ae.STATUS_WAITING_FOR_ANSWER||this._status===Ae.STATUS_ANSWERED)&&(this._status=Ae.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",s,U.causes.CANCELED));else switch(s.method){case U.ACK:if(this._status!==Ae.STATUS_WAITING_FOR_ACK)return;if(this._status=Ae.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!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===Ae.STATUS_CONFIRMED||this._status===Ae.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,U.causes.BYE)):this._status===Ae.STATUS_INVITE_RECEIVED||this._status===Ae.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===Ae.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case U.INFO:this._status===Ae.STATUS_1XX_RECEIVED||this._status===Ae.STATUS_WAITING_FOR_ANSWER||this._status===Ae.STATUS_ANSWERED||this._status===Ae.STATUS_WAITING_FOR_ACK||this._status===Ae.STATUS_CONFIRMED?(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===Ae.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case U.REFER:this._status===Ae.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case U.NOTIFY:this._status===Ae.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:U.causes.CONNECTION_ERROR,cause:U.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ae.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:U.causes.REQUEST_TIMEOUT,cause:U.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ae.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=Cv.bind(this),this._transport.ondisconnect=Av.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 Cv(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 Av(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*(){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,Ce){return V[k]=Ce}}function y(ee,V,k,Ce){var me=V&&V.prototype instanceof ye?V:ye,Ie=Object.create(me.prototype),xe=new J(Ce||[]);return e(Ie,"_invoke",{value:M(ee,k,xe)}),Ie}n.wrap=y;function C(ee,V,k){try{return{type:"normal",arg:ee.call(V,k)}}catch(Ce){return{type:"throw",arg:Ce}}}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=C(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 Ce;function me(Ie,xe){function _e(){return new V(function(le,ze){k(Ie,xe,le,ze)})}return Ce=Ce?Ce.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,Ce,me){me===void 0&&(me=Promise);var Ie=new q(y(ee,V,k,Ce),me);return n.isGeneratorFunction(V)?Ie:Ie.next().then(function(xe){return xe.done?xe.value:Ie.next()})};function M(ee,V,k){var Ce=w;return function(me,Ie){if(Ce===b)throw new Error("Generator is already running");if(Ce===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(Ce===w)throw Ce=G,k.arg;k.dispatchException(k.arg)}else k.method==="return"&&k.abrupt("return",k.arg);Ce=b;var le=C(ee,V,k);if(le.type==="normal"){if(Ce=k.done?G:R,le.arg===P)continue;return{value:le.arg,done:k.done}}else le.type==="throw"&&(Ce=G,k.method="throw",k.arg=le.arg)}}}function W(ee,V){var k=V.method,Ce=ee.iterator[k];if(Ce===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=C(Ce,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 Ce in V)k.push(Ce);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,Ce=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 Ce.next=Ce}}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 Ce=this.tryEntries.length-1;Ce>=0;--Ce){var me=this.tryEntries[Ce],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 Ce=this.tryEntries[k];if(Ce.tryLoc<=this.prev&&a.call(Ce,"finallyLoc")&&this.prev<Ce.finallyLoc){var me=Ce;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 Ce=k.completion;if(Ce.type==="throw"){var me=Ce.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,C={};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=C[R];return b||(b=C[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 C},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"}},C=It(this._reports,D.AUDIO,"total_packets_lost_in",_),w=It(this._reports,D.AUDIO,"total_packets_in",_),R={lost:C,avg:Math.round((C/(C+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"}},C=It(this._reports,D.AUDIO,"total_packets_lost_out",_),w=It(this._reports,D.AUDIO,"total_packets_out",_),R={lost:C,avg:Math.round((C/(C+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",_),C=It(this._reports,D.VIDEO,"total_packets_in",_),w={lost:y,avg:Math.round((y/(y+C)*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"}},C=It(this._reports,D.VIDEO,"total_packets_lost_out",_),w=It(this._reports,D.VIDEO,"total_packets_out",_),R={lost:C,avg:Math.round((C/(C+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 C=n.timestamp;!C&&y&&(C=y);const w=C?T-C: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}),Cy=(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}},Ay=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=Cy(l,s,i),g=Ay(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,C=l[F.CODEC_ID]||null,w=n_(l),R=vy(l,_,u);return[{ssrc:d,type:ie.VIDEO,value:{codec_id_in:C}},{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),C=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:C}}]}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,C=_&&_[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&&C&&g.push(C);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,C=_&&_[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),C?u.push(C):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,C=_&&_[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),_&&C&&g.push(C);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,C=_&&_[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),C?u.push(C):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.stateChangeCount=0,this.lastStateChange=Date.now(),this.resumeAttempts=0,this.context=new AudioContext,this.context.addEventListener("statechange",()=>{this.stateChangeCount++;const s=Date.now();this.lastStateChange=s})}getContext(){return re(this,null,function*(){return this.context.state==="suspended"&&(this.resumeAttempts++,this.resumePromise||(this.resumePromise=this.context.resume().then(()=>{this.resumePromise=null}).catch(s=>{throw this.resumePromise=null,s})),yield this.resumePromise),this.context})}get rawContext(){return this.context}getDebugInfo(){return{state:this.context.state,sampleRate:this.context.sampleRate,currentTime:this.context.currentTime,stateChangeCount:this.stateChangeCount,resumeAttempts:this.resumeAttempts,lastStateChange:new Date(this.lastStateChange).toISOString(),hasResumePromise:!!this.resumePromise,documentHidden:document.hidden,documentVisibility:document.visibilityState}}}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,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*(){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{const _=(yield this.getActiveStream()).getTracks();yield d.replaceTrack(_[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,C;g.track.enabled=!_.localMuted;const w=(T=g.track)==null?void 0:T.id;(y=g.track)==null||y.readyState,(C=g.track)==null||C.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((C,w)=>{if(!w.startsWith(_._id))try{const R=a.createMediaStreamSource(new MediaStream([C])),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 C=yield this.getActiveStream(),w=a.createMediaStreamSource(C),R=a.createGain(),b=`${_._id}-local`;w.connect(R),R.connect(g),e.sources.set(b,w),e.gains.set(b,R)}catch(C){console.error(C)}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(C){console.error(C)}}))})}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()),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()),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);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach((i,a)=>{i.stop()}),this.initialStreamValue=null),this.initialStreamValue=n}catch(s){throw s}})}triggerAddStream(s,n){return re(this,null,function*(){const i=this.muteWhenJoin||this.isMuted;this.setIsMuted(i),this.initialStreamValue||(yield this.setupStream());const a=yield this.managedAudioContext.getContext(),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=>{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(!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.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,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&&setTimeout(this.start.bind(this),5e3)}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)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(Hl.AUDIO)&&(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.on(this.disconnectedEventName,()=>{this.setConnected(!1),!this.isReconnecting&&(this.setReconnecting(!0),this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.hasActiveSessions?(this.waitingForSessionHangup=!0,this.stop(!1),this.waitingForSessionTimeout=setTimeout(()=>{this.terminateAllSessions(),this.setInitialized(!1),this.waitingForSessionHangup=!1,this.activeConnection&&setTimeout(this.start.bind(this),5e3)},12e5)):(this.stop(),this.setInitialized(!1),this.activeConnection&&setTimeout(this.start.bind(this),5e3)))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(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),Cu=ve.ref(!1),Au=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(Cu,l=>{tn.actions.setDND(l)}),ve.watch(Au,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:Cu,isCallWaitingEnabled:Au,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{se=new Ky({configuration:ot(oe({},n),{session_timers:!1,uri:`sip:${l.username}@${l.domain}`,password:l.password}),socketInterfaces:[`wss://${l.domain}`],sipDomain:`${l.domain}`,sipOptions:{session_timers:!1,extraHeaders:["X-Bar: bar"],pcConfig:{}},modules:l.modules,pnExtraHeaders:s}),se.on("connection",e=>{u_.value=!1,r_.value=!0,i_.value=e,i(se)}).on("reconnecting",e=>{o_.value=e}).on("changeActiveCalls",e=>{l_.value=oe({},e)}).on("changeActiveMessages",e=>{a_.value=oe({},e)}).on("newMSRPMessage",e=>{const d=e.session._id,_=vu.value[d]||[];_.push(e.message),vu.value[d]=[..._]}).on("callAddingInProgressChanged",e=>{c_.value=e}).on("changeAvailableDeviceList",e=>{Fl.value=[...e]}).on("changeActiveInputMediaDevice",e=>{Eu.value=e}).on("changeActiveOutputMediaDevice",e=>{yu.value=e}).on("changeMuteWhenJoin",e=>{Su.value=e}).on("changeIsCallWaiting",e=>{Au.value=e}).on("changeIsDND",e=>{Cu.value=e}).on("changeIsMuted",e=>{h_.value=e}).on("changeActiveStream",e=>{d_.value=e}).on("currentActiveRoomChanged",e=>{Zs.value=e}).on("addRoom",({roomList:e})=>{ql.value=oe({},e)}).on("updateRoom",({roomList:e})=>{ql.value=oe({},e)}).on("removeRoom",({roomList:e})=>{ql.value=oe({},e)}).on("changeCallStatus",e=>{Iu.value=oe({},e)}).on("changeCallTime",e=>{f_.value=oe({},e)}).on("changeCallMetrics",e=>{p_.value=oe({},e)}).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"})});
|
|
160
160
|
//# sourceMappingURL=super.umd.js.map
|