@voicenter-team/opensips-js 1.0.129 → 1.0.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,160 +1,159 @@
1
- "use strict";var h0=Object.defineProperty;var f0=(u,e,t)=>e in u?h0(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var fs=(u,e,t)=>(f0(u,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Wh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function nt(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}const d0="jssip",_0="JsSIP",g0="the Javascript SIP library",p0="3.10.0",m0="https://jssip.net",v0=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],T0="lib/JsSIP.d.ts",y0="lib-es5/JsSIP.js",S0=["sip","websocket","webrtc","node","browser","library"],E0="MIT",C0={type:"git",url:"https://github.com/versatica/JsSIP.git"},A0={url:"https://github.com/versatica/JsSIP/issues"},b0={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},R0={"@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"},w0={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},vu={name:d0,title:_0,description:g0,version:p0,homepage:m0,contributors:v0,types:T0,main:y0,keywords:S0,license:E0,repository:C0,bugs:A0,dependencies:b0,devDependencies:R0,scripts:w0};var sd=vu,St={USER_AGENT:"".concat(sd.title," ").concat(sd.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 Vo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Vo=function(t){return typeof t}:Vo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Vo(u)}function Tu(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function yu(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&da(u,e)}function Su(u){var e=kg();return function(){var r=_a(u),l;if(e){var s=_a(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return I0(this,l)}}function I0(u,e){return e&&(Vo(e)==="object"||typeof e=="function")?e:O0(u)}function O0(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function pr(u){var e=typeof Map=="function"?new Map:void 0;return pr=function(r){if(r===null||!D0(r))return r;if(typeof r!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e<"u"){if(e.has(r))return e.get(r);e.set(r,l)}function l(){return Bo(r,arguments,_a(this).constructor)}return l.prototype=Object.create(r.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}}),da(l,r)},pr(u)}function Bo(u,e,t){return kg()?Bo=Reflect.construct:Bo=function(l,s,i){var f=[null];f.push.apply(f,s);var h=Function.bind.apply(l,f),d=new h;return i&&da(d,i.prototype),d},Bo.apply(null,arguments)}function kg(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function D0(u){return Function.toString.call(u).indexOf("[native code]")!==-1}function da(u,e){return da=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},da(u,e)}function _a(u){return _a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},_a(u)}var N0=function(u){yu(t,u);var e=Su(t);function t(r,l){var s;return Tu(this,t),s=e.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=r,s.value=l,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return t}(pr(Error)),P0=function(u){yu(t,u);var e=Su(t);function t(r){var l;return Tu(this,t),l=e.call(this),l.code=2,l.name="INVALID_STATE_ERROR",l.status=r,l.message="Invalid status: ".concat(r),l}return t}(pr(Error)),x0=function(u){yu(t,u);var e=Su(t);function t(r){var l;return Tu(this,t),l=e.call(this),l.code=3,l.name="NOT_SUPPORTED_ERROR",l.message=r,l}return t}(pr(Error)),k0=function(u){yu(t,u);var e=Su(t);function t(r){var l;return Tu(this,t),l=e.call(this),l.code=4,l.name="NOT_READY_ERROR",l.message=r,l}return t}(pr(Error)),In={ConfigurationError:N0,InvalidStateError:P0,NotSupportedError:x0,NotReadyError:k0},gt={},Uc,nd;function Af(){if(nd)return Uc;nd=1;function u(s,i){if(!(s instanceof i))throw new TypeError("Cannot call a class as a function")}function e(s,i){for(var f=0;f<i.length;f++){var h=i[f];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function t(s,i,f){return i&&e(s.prototype,i),f&&e(s,f),s}var r=On(),l=Ns();return Uc=function(){t(s,null,[{key:"parse",value:function(f){if(f=l.parse(f,"Name_Addr_Header"),f!==-1)return f}}]);function s(i,f,h){if(u(this,s),!i||!(i instanceof r))throw new TypeError('missing or invalid "uri" parameter');this._uri=i,this._parameters={},this.display_name=f;for(var d in h)Object.prototype.hasOwnProperty.call(h,d)&&this.setParam(d,h[d])}return t(s,[{key:"setParam",value:function(f,h){f&&(this._parameters[f.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(f){if(f)return this._parameters[f.toLowerCase()]}},{key:"hasParam",value:function(f){if(f)return this._parameters.hasOwnProperty(f.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(f){if(f=f.toLowerCase(),this._parameters.hasOwnProperty(f)){var h=this._parameters[f];return delete this._parameters[f],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(f){return f.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var f=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";f+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(f+=";".concat(h),this._parameters[h]!==null&&(f+="=".concat(this._parameters[h])));return f}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(f){this._display_name=f===0?"0":f}}]),s}(),Uc}var Lc,id;function Ns(){return id||(id=1,Lc=function(){function u(t){return'"'+t.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 e={parse:function(r,l){var s={CRLF:p,DIGIT:v,ALPHA:T,HEXDIG:y,WSP:S,OCTET:A,DQUOTE:R,SP:O,HTAB:N,alphanum:C,reserved:b,unreserved:w,mark:F,escaped:q,LWS:D,SWS:P,HCOLON:I,TEXT_UTF8_TRIM:x,TEXT_UTF8char:U,UTF8_NONASCII:B,UTF8_CONT:z,LHEX:L,token:V,token_nodot:J,separators:Pe,word:ee,STAR:j,SLASH:K,EQUAL:ie,LPAREN:ue,RPAREN:Ce,RAQUOT:ke,LAQUOT:be,COMMA:M,SEMI:Y,COLON:Ee,LDQUOT:Me,RDQUOT:fe,comment:_e,ctext:we,quoted_string:De,quoted_string_clean:ce,qdtext:de,quoted_pair:ge,SIP_URI_noparams:Oe,SIP_URI:$e,uri_scheme:_t,uri_scheme_sips:Ye,uri_scheme_sip:ts,userinfo:Dt,user:Ai,user_unreserved:bi,password:Un,hostport:Es,host:ks,hostname:Ln,domainlabel:Ri,toplabel:wi,IPv6reference:Fn,IPv6address:Ae,h16:me,ls32:Et,IPv4address:hs,dec_octet:sn,port:Dr,uri_parameters:Ii,uri_parameter:Oi,transport_param:Nr,user_param:Pr,method_param:xr,ttl_param:kr,maddr_param:Mr,lr_param:Ur,other_param:Lr,pname:Fr,pvalue:nn,paramchar:rn,param_unreserved:$r,headers:$n,header:Hn,hname:Hr,hvalue:ln,hnv_unreserved:Gn,Request_Response:Fa,Request_Line:Gr,Request_URI:Di,absoluteURI:Ni,hier_part:Vr,net_path:Vn,abs_path:Bn,opaque_part:an,uric:on,uric_no_slash:Br,path_segments:jn,segment:un,param:Ms,pchar:cn,scheme:jr,authority:qr,srvr:Wr,reg_name:Kr,query:Pi,SIP_Version:xi,INVITEm:Yr,ACKm:zr,OPTIONSm:Xr,BYEm:Jr,CANCELm:Qr,REGISTERm:Zr,SUBSCRIBEm:el,NOTIFYm:tl,REFERm:qn,Method:Wn,Status_Line:sl,Status_Code:nl,extension_code:il,Reason_Phrase:$a,Allow_Events:yc,Call_ID:Sc,Contact:ki,contact_param:ss,name_addr:ns,display_name:hn,contact_params:Mi,c_p_q:rl,c_p_expires:Cs,delta_seconds:As,qvalue:rt,generic_param:lt,gen_value:Ha,Content_Disposition:Ga,disp_type:Ui,disp_param:Li,handling_param:Va,Content_Encoding:Ec,Content_Length:Cc,Content_Type:Ba,media_type:ll,m_type:al,discrete_type:ol,composite_type:Kn,extension_token:Yn,x_token:ul,m_subtype:Fi,m_parameter:$i,m_value:ja,CSeq:qa,CSeq_value:Wa,Expires:Ac,Event:zn,event_type:Xn,From:cl,from_param:Jn,tag_param:hl,Max_Forwards:bc,Min_Expires:Rc,Name_Addr_Header:wc,Proxy_Authenticate:fl,challenge:Hi,other_challenge:fn,auth_param:bs,digest_cln:Qn,realm:dl,realm_value:_l,domain:Zn,URI:ei,nonce:gl,nonce_value:pl,opaque:ml,stale:vl,algorithm:Tl,qop_options:ti,qop_value:Gi,Proxy_Require:Ic,Record_Route:Vi,rec_route:Bi,Reason:yl,reason_param:ji,reason_cause:Ka,Require:Oc,Route:qi,route_param:Wi,Subscription_State:Ya,substate_value:Ki,subexp_params:Yi,event_reason_value:za,Subject:Dc,Supported:Nc,To:Sl,to_param:El,Via:zi,via_param:dn,via_params:Xi,via_ttl:Cl,via_maddr:Al,via_received:bl,via_branch:Rl,response_port:wl,rport:Il,sent_protocol:Ol,protocol_name:Dl,transport:Nl,sent_by:Pl,via_host:xl,via_port:Ji,ttl:kl,WWW_Authenticate:Pc,Session_Expires:Xa,s_e_expires:Qi,s_e_params:Zi,s_e_refresher:Ja,extension_header:Qa,header_value:Za,message_body:xc,uuid_URI:eo,uuid:is,hex4:rs,hex8:Ml,hex12:to,Refer_To:kc,Replaces:so,call_id:er,replaces_param:tr,to_tag:Ul,from_tag:Ll,early_flag:no};if(l!==void 0){if(s[l]===void 0)throw new Error("Invalid rule name: "+u(l)+".")}else l="CRLF";var i=0,f=0,h=[];function d(n){i<f||(i>f&&(f=i,h=[]),h.push(n))}function p(){var n;return r.substr(i,2)===`\r
2
- `?(n=`\r
3
- `,i+=2):(n=null,d('"\\r\\n"')),n}function v(){var n;return/^[0-9]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[0-9]")),n}function T(){var n;return/^[a-zA-Z]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[a-zA-Z]")),n}function y(){var n;return/^[0-9a-fA-F]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[0-9a-fA-F]")),n}function S(){var n;return n=O(),n===null&&(n=N()),n}function A(){var n;return/^[\0-\xFF]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[\\0-\\xFF]")),n}function R(){var n;return/^["]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d('["]')),n}function O(){var n;return r.charCodeAt(i)===32?(n=" ",i++):(n=null,d('" "')),n}function N(){var n;return r.charCodeAt(i)===9?(n=" ",i++):(n=null,d('"\\t"')),n}function C(){var n;return/^[a-zA-Z0-9]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[a-zA-Z0-9]")),n}function b(){var n;return r.charCodeAt(i)===59?(n=";",i++):(n=null,d('";"')),n===null&&(r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n===null&&(r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===64?(n="@",i++):(n=null,d('"@"')),n===null&&(r.charCodeAt(i)===38?(n="&",i++):(n=null,d('"&"')),n===null&&(r.charCodeAt(i)===61?(n="=",i++):(n=null,d('"="')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')),n===null&&(r.charCodeAt(i)===44?(n=",",i++):(n=null,d('","'))))))))))),n}function w(){var n;return n=C(),n===null&&(n=F()),n}function F(){var n;return r.charCodeAt(i)===45?(n="-",i++):(n=null,d('"-"')),n===null&&(r.charCodeAt(i)===95?(n="_",i++):(n=null,d('"_"')),n===null&&(r.charCodeAt(i)===46?(n=".",i++):(n=null,d('"."')),n===null&&(r.charCodeAt(i)===33?(n="!",i++):(n=null,d('"!"')),n===null&&(r.charCodeAt(i)===126?(n="~",i++):(n=null,d('"~"')),n===null&&(r.charCodeAt(i)===42?(n="*",i++):(n=null,d('"*"')),n===null&&(r.charCodeAt(i)===39?(n="'",i++):(n=null,d(`"'"`)),n===null&&(r.charCodeAt(i)===40?(n="(",i++):(n=null,d('"("')),n===null&&(r.charCodeAt(i)===41?(n=")",i++):(n=null,d('")"')))))))))),n}function q(){var n,o,c,_,g;return _=i,g=i,r.charCodeAt(i)===37?(n="%",i++):(n=null,d('"%"')),n!==null?(o=y(),o!==null?(c=y(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){return E.join("")}(_,n)),n===null&&(i=_),n}function D(){var n,o,c,_,g,m;for(_=i,g=i,m=i,n=[],o=S();o!==null;)n.push(o),o=S();if(n!==null?(o=p(),o!==null?n=[n,o]:(n=null,i=m)):(n=null,i=m),n=n!==null?n:"",n!==null){if(c=S(),c!==null)for(o=[];c!==null;)o.push(c),c=S();else o=null;o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n!==null&&(n=function(E){return" "}()),n===null&&(i=_),n}function P(){var n;return n=D(),n=n!==null?n:"",n}function I(){var n,o,c,_,g;for(_=i,g=i,n=[],o=O(),o===null&&(o=N());o!==null;)n.push(o),o=O(),o===null&&(o=N());return n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return":"}()),n===null&&(i=_),n}function x(){var n,o,c,_,g,m,E;if(g=i,m=i,o=U(),o!==null)for(n=[];o!==null;)n.push(o),o=U();else n=null;if(n!==null){for(o=[],E=i,c=[],_=D();_!==null;)c.push(_),_=D();for(c!==null?(_=U(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;){for(o.push(c),E=i,c=[],_=D();_!==null;)c.push(_),_=D();c!==null?(_=U(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E)}o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){return r.substring(i,k)}(g)),n===null&&(i=g),n}function U(){var n;return/^[!-~]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[!-~]")),n===null&&(n=B()),n}function B(){var n;return/^[\x80-\uFFFF]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[\\x80-\\uFFFF]")),n}function z(){var n;return/^[\x80-\xBF]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[\\x80-\\xBF]")),n}function L(){var n;return n=v(),n===null&&(/^[a-f]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[a-f]"))),n}function V(){var n,o,c;if(c=i,o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"')))))))))))),o!==null)for(n=[];o!==null;)n.push(o),o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"'))))))))))));else n=null;return n!==null&&(n=function(_){return r.substring(i,_)}(c)),n===null&&(i=c),n}function J(){var n,o,c;if(c=i,o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"'))))))))))),o!==null)for(n=[];o!==null;)n.push(o),o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"')))))))))));else n=null;return n!==null&&(n=function(_){return r.substring(i,_)}(c)),n===null&&(i=c),n}function Pe(){var n;return r.charCodeAt(i)===40?(n="(",i++):(n=null,d('"("')),n===null&&(r.charCodeAt(i)===41?(n=")",i++):(n=null,d('")"')),n===null&&(r.charCodeAt(i)===60?(n="<",i++):(n=null,d('"<"')),n===null&&(r.charCodeAt(i)===62?(n=">",i++):(n=null,d('">"')),n===null&&(r.charCodeAt(i)===64?(n="@",i++):(n=null,d('"@"')),n===null&&(r.charCodeAt(i)===44?(n=",",i++):(n=null,d('","')),n===null&&(r.charCodeAt(i)===59?(n=";",i++):(n=null,d('";"')),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===92?(n="\\",i++):(n=null,d('"\\\\"')),n===null&&(n=R(),n===null&&(r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n===null&&(r.charCodeAt(i)===91?(n="[",i++):(n=null,d('"["')),n===null&&(r.charCodeAt(i)===93?(n="]",i++):(n=null,d('"]"')),n===null&&(r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n===null&&(r.charCodeAt(i)===61?(n="=",i++):(n=null,d('"="')),n===null&&(r.charCodeAt(i)===123?(n="{",i++):(n=null,d('"{"')),n===null&&(r.charCodeAt(i)===125?(n="}",i++):(n=null,d('"}"')),n===null&&(n=O(),n===null&&(n=N())))))))))))))))))),n}function ee(){var n,o,c;if(c=i,o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"')),o===null&&(r.charCodeAt(i)===40?(o="(",i++):(o=null,d('"("')),o===null&&(r.charCodeAt(i)===41?(o=")",i++):(o=null,d('")"')),o===null&&(r.charCodeAt(i)===60?(o="<",i++):(o=null,d('"<"')),o===null&&(r.charCodeAt(i)===62?(o=">",i++):(o=null,d('">"')),o===null&&(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o===null&&(r.charCodeAt(i)===92?(o="\\",i++):(o=null,d('"\\\\"')),o===null&&(o=R(),o===null&&(r.charCodeAt(i)===47?(o="/",i++):(o=null,d('"/"')),o===null&&(r.charCodeAt(i)===91?(o="[",i++):(o=null,d('"["')),o===null&&(r.charCodeAt(i)===93?(o="]",i++):(o=null,d('"]"')),o===null&&(r.charCodeAt(i)===63?(o="?",i++):(o=null,d('"?"')),o===null&&(r.charCodeAt(i)===123?(o="{",i++):(o=null,d('"{"')),o===null&&(r.charCodeAt(i)===125?(o="}",i++):(o=null,d('"}"'))))))))))))))))))))))))),o!==null)for(n=[];o!==null;)n.push(o),o=C(),o===null&&(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o===null&&(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o===null&&(r.charCodeAt(i)===33?(o="!",i++):(o=null,d('"!"')),o===null&&(r.charCodeAt(i)===37?(o="%",i++):(o=null,d('"%"')),o===null&&(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o===null&&(r.charCodeAt(i)===95?(o="_",i++):(o=null,d('"_"')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===96?(o="`",i++):(o=null,d('"`"')),o===null&&(r.charCodeAt(i)===39?(o="'",i++):(o=null,d(`"'"`)),o===null&&(r.charCodeAt(i)===126?(o="~",i++):(o=null,d('"~"')),o===null&&(r.charCodeAt(i)===40?(o="(",i++):(o=null,d('"("')),o===null&&(r.charCodeAt(i)===41?(o=")",i++):(o=null,d('")"')),o===null&&(r.charCodeAt(i)===60?(o="<",i++):(o=null,d('"<"')),o===null&&(r.charCodeAt(i)===62?(o=">",i++):(o=null,d('">"')),o===null&&(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o===null&&(r.charCodeAt(i)===92?(o="\\",i++):(o=null,d('"\\\\"')),o===null&&(o=R(),o===null&&(r.charCodeAt(i)===47?(o="/",i++):(o=null,d('"/"')),o===null&&(r.charCodeAt(i)===91?(o="[",i++):(o=null,d('"["')),o===null&&(r.charCodeAt(i)===93?(o="]",i++):(o=null,d('"]"')),o===null&&(r.charCodeAt(i)===63?(o="?",i++):(o=null,d('"?"')),o===null&&(r.charCodeAt(i)===123?(o="{",i++):(o=null,d('"{"')),o===null&&(r.charCodeAt(i)===125?(o="}",i++):(o=null,d('"}"')))))))))))))))))))))))));else n=null;return n!==null&&(n=function(_){return r.substring(i,_)}(c)),n===null&&(i=c),n}function j(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===42?(o="*",i++):(o=null,d('"*"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return"*"}()),n===null&&(i=_),n}function K(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===47?(o="/",i++):(o=null,d('"/"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return"/"}()),n===null&&(i=_),n}function ie(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return"="}()),n===null&&(i=_),n}function ue(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===40?(o="(",i++):(o=null,d('"("')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return"("}()),n===null&&(i=_),n}function Ce(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===41?(o=")",i++):(o=null,d('")"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return")"}()),n===null&&(i=_),n}function ke(){var n,o,c,_;return c=i,_=i,r.charCodeAt(i)===62?(n=">",i++):(n=null,d('">"')),n!==null?(o=P(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g){return">"}()),n===null&&(i=c),n}function be(){var n,o,c,_;return c=i,_=i,n=P(),n!==null?(r.charCodeAt(i)===60?(o="<",i++):(o=null,d('"<"')),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g){return"<"}()),n===null&&(i=c),n}function M(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===44?(o=",",i++):(o=null,d('","')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return","}()),n===null&&(i=_),n}function Y(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return";"}()),n===null&&(i=_),n}function Ee(){var n,o,c,_,g;return _=i,g=i,n=P(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=P(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return":"}()),n===null&&(i=_),n}function Me(){var n,o,c,_;return c=i,_=i,n=P(),n!==null?(o=R(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g){return'"'}()),n===null&&(i=c),n}function fe(){var n,o,c,_;return c=i,_=i,n=R(),n!==null?(o=P(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g){return'"'}()),n===null&&(i=c),n}function _e(){var n,o,c,_;if(_=i,n=ue(),n!==null){for(o=[],c=we(),c===null&&(c=ge(),c===null&&(c=_e()));c!==null;)o.push(c),c=we(),c===null&&(c=ge(),c===null&&(c=_e()));o!==null?(c=Ce(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)}else n=null,i=_;return n}function we(){var n;return/^[!-']/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[!-']")),n===null&&(/^[*-[]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[*-[]")),n===null&&(/^[\]-~]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[\\]-~]")),n===null&&(n=B(),n===null&&(n=D())))),n}function De(){var n,o,c,_,g,m;if(g=i,m=i,n=P(),n!==null)if(o=R(),o!==null){for(c=[],_=de(),_===null&&(_=ge());_!==null;)c.push(_),_=de(),_===null&&(_=ge());c!==null?(_=R(),_!==null?n=[n,o,c,_]:(n=null,i=m)):(n=null,i=m)}else n=null,i=m;else n=null,i=m;return n!==null&&(n=function(E){return r.substring(i,E)}(g)),n===null&&(i=g),n}function ce(){var n,o,c,_,g,m;if(g=i,m=i,n=P(),n!==null)if(o=R(),o!==null){for(c=[],_=de(),_===null&&(_=ge());_!==null;)c.push(_),_=de(),_===null&&(_=ge());c!==null?(_=R(),_!==null?n=[n,o,c,_]:(n=null,i=m)):(n=null,i=m)}else n=null,i=m;else n=null,i=m;return n!==null&&(n=function(E){var k=r.substring(i,E).trim();return k.substring(1,k.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(g)),n===null&&(i=g),n}function de(){var n;return n=D(),n===null&&(r.charCodeAt(i)===33?(n="!",i++):(n=null,d('"!"')),n===null&&(/^[#-[]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[#-[]")),n===null&&(/^[\]-~]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[\\]-~]")),n===null&&(n=B())))),n}function ge(){var n,o,c;return c=i,r.charCodeAt(i)===92?(n="\\",i++):(n=null,d('"\\\\"')),n!==null?(/^[\0-\t]/.test(r.charAt(i))?(o=r.charAt(i),i++):(o=null,d("[\\0-\\t]")),o===null&&(/^[\x0B-\f]/.test(r.charAt(i))?(o=r.charAt(i),i++):(o=null,d("[\\x0B-\\f]")),o===null&&(/^[\x0E-]/.test(r.charAt(i))?(o=r.charAt(i),i++):(o=null,d("[\\x0E-]")))),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function Oe(){var n,o,c,_,g,m;return g=i,m=i,n=_t(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Dt(),c=c!==null?c:"",c!==null?(_=Es(),_!==null?n=[n,o,c,_]:(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m),n!==null&&(n=function(E){try{G.uri=new Us(G.scheme,G.user,G.host,G.port),delete G.scheme,delete G.user,delete G.host,delete G.host_type,delete G.port}catch{G=-1}}()),n===null&&(i=g),n}function $e(){var n,o,c,_,g,m,E,k;return E=i,k=i,n=_t(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Dt(),c=c!==null?c:"",c!==null?(_=Es(),_!==null?(g=Ii(),g!==null?(m=$n(),m=m!==null?m:"",m!==null?n=[n,o,c,_,g,m]:(n=null,i=k)):(n=null,i=k)):(n=null,i=k)):(n=null,i=k)):(n=null,i=k)):(n=null,i=k),n!==null&&(n=function(W){try{G.uri=new Us(G.scheme,G.user,G.host,G.port,G.uri_params,G.uri_headers),delete G.scheme,delete G.user,delete G.host,delete G.host_type,delete G.port,delete G.uri_params,l==="SIP_URI"&&(G=G.uri)}catch{G=-1}}()),n===null&&(i=E),n}function _t(){var n;return n=Ye(),n===null&&(n=ts()),n}function Ye(){var n,o;return o=i,r.substr(i,4).toLowerCase()==="sips"?(n=r.substr(i,4),i+=4):(n=null,d('"sips"')),n!==null&&(n=function(c,_){G.scheme=_.toLowerCase()}(o,n)),n===null&&(i=o),n}function ts(){var n,o;return o=i,r.substr(i,3).toLowerCase()==="sip"?(n=r.substr(i,3),i+=3):(n=null,d('"sip"')),n!==null&&(n=function(c,_){G.scheme=_.toLowerCase()}(o,n)),n===null&&(i=o),n}function Dt(){var n,o,c,_,g,m;return _=i,g=i,n=Ai(),n!==null?(m=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Un(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?(r.charCodeAt(i)===64?(c="@",i++):(c=null,d('"@"')),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E){G.user=decodeURIComponent(r.substring(i-1,E))}(_)),n===null&&(i=_),n}function Ai(){var n,o;if(o=w(),o===null&&(o=q(),o===null&&(o=bi())),o!==null)for(n=[];o!==null;)n.push(o),o=w(),o===null&&(o=q(),o===null&&(o=bi()));else n=null;return n}function bi(){var n;return r.charCodeAt(i)===38?(n="&",i++):(n=null,d('"&"')),n===null&&(r.charCodeAt(i)===61?(n="=",i++):(n=null,d('"="')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')),n===null&&(r.charCodeAt(i)===44?(n=",",i++):(n=null,d('","')),n===null&&(r.charCodeAt(i)===59?(n=";",i++):(n=null,d('";"')),n===null&&(r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n===null&&(r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"'))))))))),n}function Un(){var n,o,c;for(c=i,n=[],o=w(),o===null&&(o=q(),o===null&&(r.charCodeAt(i)===38?(o="&",i++):(o=null,d('"&"')),o===null&&(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===36?(o="$",i++):(o=null,d('"$"')),o===null&&(r.charCodeAt(i)===44?(o=",",i++):(o=null,d('","'))))))));o!==null;)n.push(o),o=w(),o===null&&(o=q(),o===null&&(r.charCodeAt(i)===38?(o="&",i++):(o=null,d('"&"')),o===null&&(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')),o===null&&(r.charCodeAt(i)===36?(o="$",i++):(o=null,d('"$"')),o===null&&(r.charCodeAt(i)===44?(o=",",i++):(o=null,d('","'))))))));return n!==null&&(n=function(_){G.password=r.substring(i,_)}(c)),n===null&&(i=c),n}function Es(){var n,o,c,_,g;return _=i,n=ks(),n!==null?(g=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Dr(),c!==null?o=[o,c]:(o=null,i=g)):(o=null,i=g),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n}function ks(){var n,o;return o=i,n=Ln(),n===null&&(n=hs(),n===null&&(n=Fn())),n!==null&&(n=function(c){return G.host=r.substring(i,c).toLowerCase(),G.host}(o)),n===null&&(i=o),n}function Ln(){var n,o,c,_,g,m;for(_=i,g=i,n=[],m=i,o=Ri(),o!==null?(r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."')),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m);o!==null;)n.push(o),m=i,o=Ri(),o!==null?(r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."')),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m);return n!==null?(o=wi(),o!==null?(r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."')),c=c!==null?c:"",c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E){return G.host_type="domain",r.substring(i,E)}(_)),n===null&&(i=_),n}function Ri(){var n,o,c,_;if(_=i,n=C(),n!==null){for(o=[],c=C(),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===95?(c="_",i++):(c=null,d('"_"'))));c!==null;)o.push(c),c=C(),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===95?(c="_",i++):(c=null,d('"_"'))));o!==null?n=[n,o]:(n=null,i=_)}else n=null,i=_;return n}function wi(){var n,o,c,_;if(_=i,n=T(),n!==null){for(o=[],c=C(),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===95?(c="_",i++):(c=null,d('"_"'))));c!==null;)o.push(c),c=C(),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===95?(c="_",i++):(c=null,d('"_"'))));o!==null?n=[n,o]:(n=null,i=_)}else n=null,i=_;return n}function Fn(){var n,o,c,_,g;return _=i,g=i,r.charCodeAt(i)===91?(n="[",i++):(n=null,d('"["')),n!==null?(o=Ae(),o!==null?(r.charCodeAt(i)===93?(c="]",i++):(c=null,d('"]"')),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m){return G.host_type="IPv6",r.substring(i,m)}(_)),n===null&&(i=_),n}function Ae(){var n,o,c,_,g,m,E,k,W,pe,He,Wt,_n,Q,$,Re;return Q=i,$=i,n=me(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?(r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?(r.charCodeAt(i)===58?(m=":",i++):(m=null,d('":"')),m!==null?(E=me(),E!==null?(r.charCodeAt(i)===58?(k=":",i++):(k=null,d('":"')),k!==null?(W=me(),W!==null?(r.charCodeAt(i)===58?(pe=":",i++):(pe=null,d('":"')),pe!==null?(He=me(),He!==null?(r.charCodeAt(i)===58?(Wt=":",i++):(Wt=null,d('":"')),Wt!==null?(_n=Et(),_n!==null?n=[n,o,c,_,g,m,E,k,W,pe,He,Wt,_n]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?(r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?(r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?(r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=me(),k!==null?(r.charCodeAt(i)===58?(W=":",i++):(W=null,d('":"')),W!==null?(pe=me(),pe!==null?(r.charCodeAt(i)===58?(He=":",i++):(He=null,d('":"')),He!==null?(Wt=Et(),Wt!==null?n=[n,o,c,_,g,m,E,k,W,pe,He,Wt]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?(r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?(r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?(r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=me(),k!==null?(r.charCodeAt(i)===58?(W=":",i++):(W=null,d('":"')),W!==null?(pe=Et(),pe!==null?n=[n,o,c,_,g,m,E,k,W,pe]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?(r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?(r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?(r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=Et(),k!==null?n=[n,o,c,_,g,m,E,k]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?(r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?(r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=Et(),m!==null?n=[n,o,c,_,g,m]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?(r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=Et(),_!==null?n=[n,o,c,_]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=Et(),o!==null?n=[n,o]:(n=null,i=$)):(n=null,i=$),n===null&&($=i,r.substr(i,2)==="::"?(n="::",i+=2):(n=null,d('"::"')),n!==null?(o=me(),o!==null?n=[n,o]:(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(r.substr(i,2)==="::"?(o="::",i+=2):(o=null,d('"::"')),o!==null?(c=me(),c!==null?(r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?(r.charCodeAt(i)===58?(m=":",i++):(m=null,d('":"')),m!==null?(E=me(),E!==null?(r.charCodeAt(i)===58?(k=":",i++):(k=null,d('":"')),k!==null?(W=me(),W!==null?(r.charCodeAt(i)===58?(pe=":",i++):(pe=null,d('":"')),pe!==null?(He=Et(),He!==null?n=[n,o,c,_,g,m,E,k,W,pe,He]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(r.substr(i,2)==="::"?(c="::",i+=2):(c=null,d('"::"')),c!==null?(_=me(),_!==null?(r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?(r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=me(),k!==null?(r.charCodeAt(i)===58?(W=":",i++):(W=null,d('":"')),W!==null?(pe=Et(),pe!==null?n=[n,o,c,_,g,m,E,k,W,pe]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(Re=i,r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?c=[c,_]:(c=null,i=Re)):(c=null,i=Re),c=c!==null?c:"",c!==null?(r.substr(i,2)==="::"?(_="::",i+=2):(_=null,d('"::"')),_!==null?(g=me(),g!==null?(r.charCodeAt(i)===58?(m=":",i++):(m=null,d('":"')),m!==null?(E=me(),E!==null?(r.charCodeAt(i)===58?(k=":",i++):(k=null,d('":"')),k!==null?(W=Et(),W!==null?n=[n,o,c,_,g,m,E,k,W]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(Re=i,r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?c=[c,_]:(c=null,i=Re)):(c=null,i=Re),c=c!==null?c:"",c!==null?(Re=i,r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?_=[_,g]:(_=null,i=Re)):(_=null,i=Re),_=_!==null?_:"",_!==null?(r.substr(i,2)==="::"?(g="::",i+=2):(g=null,d('"::"')),g!==null?(m=me(),m!==null?(r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=Et(),k!==null?n=[n,o,c,_,g,m,E,k]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(Re=i,r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?c=[c,_]:(c=null,i=Re)):(c=null,i=Re),c=c!==null?c:"",c!==null?(Re=i,r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?_=[_,g]:(_=null,i=Re)):(_=null,i=Re),_=_!==null?_:"",_!==null?(Re=i,r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?g=[g,m]:(g=null,i=Re)):(g=null,i=Re),g=g!==null?g:"",g!==null?(r.substr(i,2)==="::"?(m="::",i+=2):(m=null,d('"::"')),m!==null?(E=Et(),E!==null?n=[n,o,c,_,g,m,E]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(Re=i,r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?c=[c,_]:(c=null,i=Re)):(c=null,i=Re),c=c!==null?c:"",c!==null?(Re=i,r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?_=[_,g]:(_=null,i=Re)):(_=null,i=Re),_=_!==null?_:"",_!==null?(Re=i,r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?g=[g,m]:(g=null,i=Re)):(g=null,i=Re),g=g!==null?g:"",g!==null?(Re=i,r.charCodeAt(i)===58?(m=":",i++):(m=null,d('":"')),m!==null?(E=me(),E!==null?m=[m,E]:(m=null,i=Re)):(m=null,i=Re),m=m!==null?m:"",m!==null?(r.substr(i,2)==="::"?(E="::",i+=2):(E=null,d('"::"')),E!==null?(k=me(),k!==null?n=[n,o,c,_,g,m,E,k]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$),n===null&&($=i,n=me(),n!==null?(Re=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?o=[o,c]:(o=null,i=Re)):(o=null,i=Re),o=o!==null?o:"",o!==null?(Re=i,r.charCodeAt(i)===58?(c=":",i++):(c=null,d('":"')),c!==null?(_=me(),_!==null?c=[c,_]:(c=null,i=Re)):(c=null,i=Re),c=c!==null?c:"",c!==null?(Re=i,r.charCodeAt(i)===58?(_=":",i++):(_=null,d('":"')),_!==null?(g=me(),g!==null?_=[_,g]:(_=null,i=Re)):(_=null,i=Re),_=_!==null?_:"",_!==null?(Re=i,r.charCodeAt(i)===58?(g=":",i++):(g=null,d('":"')),g!==null?(m=me(),m!==null?g=[g,m]:(g=null,i=Re)):(g=null,i=Re),g=g!==null?g:"",g!==null?(Re=i,r.charCodeAt(i)===58?(m=":",i++):(m=null,d('":"')),m!==null?(E=me(),E!==null?m=[m,E]:(m=null,i=Re)):(m=null,i=Re),m=m!==null?m:"",m!==null?(Re=i,r.charCodeAt(i)===58?(E=":",i++):(E=null,d('":"')),E!==null?(k=me(),k!==null?E=[E,k]:(E=null,i=Re)):(E=null,i=Re),E=E!==null?E:"",E!==null?(r.substr(i,2)==="::"?(k="::",i+=2):(k=null,d('"::"')),k!==null?n=[n,o,c,_,g,m,E,k]:(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$)):(n=null,i=$))))))))))))))),n!==null&&(n=function(c0){return G.host_type="IPv6",r.substring(i,c0)}(Q)),n===null&&(i=Q),n}function me(){var n,o,c,_,g;return g=i,n=y(),n!==null?(o=y(),o=o!==null?o:"",o!==null?(c=y(),c=c!==null?c:"",c!==null?(_=y(),_=_!==null?_:"",_!==null?n=[n,o,c,_]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n}function Et(){var n,o,c,_;return _=i,n=me(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=me(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n===null&&(n=hs()),n}function hs(){var n,o,c,_,g,m,E,k,W;return k=i,W=i,n=sn(),n!==null?(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o!==null?(c=sn(),c!==null?(r.charCodeAt(i)===46?(_=".",i++):(_=null,d('"."')),_!==null?(g=sn(),g!==null?(r.charCodeAt(i)===46?(m=".",i++):(m=null,d('"."')),m!==null?(E=sn(),E!==null?n=[n,o,c,_,g,m,E]:(n=null,i=W)):(n=null,i=W)):(n=null,i=W)):(n=null,i=W)):(n=null,i=W)):(n=null,i=W)):(n=null,i=W),n!==null&&(n=function(pe){return G.host_type="IPv4",r.substring(i,pe)}(k)),n===null&&(i=k),n}function sn(){var n,o,c,_;return _=i,r.substr(i,2)==="25"?(n="25",i+=2):(n=null,d('"25"')),n!==null?(/^[0-5]/.test(r.charAt(i))?(o=r.charAt(i),i++):(o=null,d("[0-5]")),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n===null&&(_=i,r.charCodeAt(i)===50?(n="2",i++):(n=null,d('"2"')),n!==null?(/^[0-4]/.test(r.charAt(i))?(o=r.charAt(i),i++):(o=null,d("[0-4]")),o!==null?(c=v(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n===null&&(_=i,r.charCodeAt(i)===49?(n="1",i++):(n=null,d('"1"')),n!==null?(o=v(),o!==null?(c=v(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n===null&&(_=i,/^[1-9]/.test(r.charAt(i))?(n=r.charAt(i),i++):(n=null,d("[1-9]")),n!==null?(o=v(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n===null&&(n=v())))),n}function Dr(){var n,o,c,_,g,m,E;return m=i,E=i,n=v(),n=n!==null?n:"",n!==null?(o=v(),o=o!==null?o:"",o!==null?(c=v(),c=c!==null?c:"",c!==null?(_=v(),_=_!==null?_:"",_!==null?(g=v(),g=g!==null?g:"",g!==null?n=[n,o,c,_,g]:(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E),n!==null&&(n=function(k,W){return W=parseInt(W.join("")),G.port=W,W}(m,n)),n===null&&(i=m),n}function Ii(){var n,o,c,_;for(n=[],_=i,r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o!==null?(c=Oi(),c!==null?o=[o,c]:(o=null,i=_)):(o=null,i=_);o!==null;)n.push(o),_=i,r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o!==null?(c=Oi(),c!==null?o=[o,c]:(o=null,i=_)):(o=null,i=_);return n}function Oi(){var n;return n=Nr(),n===null&&(n=Pr(),n===null&&(n=xr(),n===null&&(n=kr(),n===null&&(n=Mr(),n===null&&(n=Ur(),n===null&&(n=Lr())))))),n}function Nr(){var n,o,c,_;return c=i,_=i,r.substr(i,10).toLowerCase()==="transport="?(n=r.substr(i,10),i+=10):(n=null,d('"transport="')),n!==null?(r.substr(i,3).toLowerCase()==="udp"?(o=r.substr(i,3),i+=3):(o=null,d('"udp"')),o===null&&(r.substr(i,3).toLowerCase()==="tcp"?(o=r.substr(i,3),i+=3):(o=null,d('"tcp"')),o===null&&(r.substr(i,4).toLowerCase()==="sctp"?(o=r.substr(i,4),i+=4):(o=null,d('"sctp"')),o===null&&(r.substr(i,3).toLowerCase()==="tls"?(o=r.substr(i,3),i+=3):(o=null,d('"tls"')),o===null&&(o=V())))),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g,m){G.uri_params||(G.uri_params={}),G.uri_params.transport=m.toLowerCase()}(c,n[1])),n===null&&(i=c),n}function Pr(){var n,o,c,_;return c=i,_=i,r.substr(i,5).toLowerCase()==="user="?(n=r.substr(i,5),i+=5):(n=null,d('"user="')),n!==null?(r.substr(i,5).toLowerCase()==="phone"?(o=r.substr(i,5),i+=5):(o=null,d('"phone"')),o===null&&(r.substr(i,2).toLowerCase()==="ip"?(o=r.substr(i,2),i+=2):(o=null,d('"ip"')),o===null&&(o=V())),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g,m){G.uri_params||(G.uri_params={}),G.uri_params.user=m.toLowerCase()}(c,n[1])),n===null&&(i=c),n}function xr(){var n,o,c,_;return c=i,_=i,r.substr(i,7).toLowerCase()==="method="?(n=r.substr(i,7),i+=7):(n=null,d('"method="')),n!==null?(o=Wn(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g,m){G.uri_params||(G.uri_params={}),G.uri_params.method=m}(c,n[1])),n===null&&(i=c),n}function kr(){var n,o,c,_;return c=i,_=i,r.substr(i,4).toLowerCase()==="ttl="?(n=r.substr(i,4),i+=4):(n=null,d('"ttl="')),n!==null?(o=kl(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g,m){G.params||(G.params={}),G.params.ttl=m}(c,n[1])),n===null&&(i=c),n}function Mr(){var n,o,c,_;return c=i,_=i,r.substr(i,6).toLowerCase()==="maddr="?(n=r.substr(i,6),i+=6):(n=null,d('"maddr="')),n!==null?(o=ks(),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n!==null&&(n=function(g,m){G.uri_params||(G.uri_params={}),G.uri_params.maddr=m}(c,n[1])),n===null&&(i=c),n}function Ur(){var n,o,c,_,g,m;return _=i,g=i,r.substr(i,2).toLowerCase()==="lr"?(n=r.substr(i,2),i+=2):(n=null,d('"lr"')),n!==null?(m=i,r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=V(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E){G.uri_params||(G.uri_params={}),G.uri_params.lr=void 0}()),n===null&&(i=_),n}function Lr(){var n,o,c,_,g,m;return _=i,g=i,n=Fr(),n!==null?(m=i,r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=nn(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E,k,W){G.uri_params||(G.uri_params={}),typeof W>"u"?W=void 0:W=W[1],G.uri_params[k.toLowerCase()]=W}(_,n[0],n[1])),n===null&&(i=_),n}function Fr(){var n,o,c;if(c=i,o=rn(),o!==null)for(n=[];o!==null;)n.push(o),o=rn();else n=null;return n!==null&&(n=function(_,g){return g.join("")}(c,n)),n===null&&(i=c),n}function nn(){var n,o,c;if(c=i,o=rn(),o!==null)for(n=[];o!==null;)n.push(o),o=rn();else n=null;return n!==null&&(n=function(_,g){return g.join("")}(c,n)),n===null&&(i=c),n}function rn(){var n;return n=$r(),n===null&&(n=w(),n===null&&(n=q())),n}function $r(){var n;return r.charCodeAt(i)===91?(n="[",i++):(n=null,d('"["')),n===null&&(r.charCodeAt(i)===93?(n="]",i++):(n=null,d('"]"')),n===null&&(r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===38?(n="&",i++):(n=null,d('"&"')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')))))))),n}function $n(){var n,o,c,_,g,m,E;if(m=i,r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n!==null)if(o=Hn(),o!==null){for(c=[],E=i,r.charCodeAt(i)===38?(_="&",i++):(_=null,d('"&"')),_!==null?(g=Hn(),g!==null?_=[_,g]:(_=null,i=E)):(_=null,i=E);_!==null;)c.push(_),E=i,r.charCodeAt(i)===38?(_="&",i++):(_=null,d('"&"')),_!==null?(g=Hn(),g!==null?_=[_,g]:(_=null,i=E)):(_=null,i=E);c!==null?n=[n,o,c]:(n=null,i=m)}else n=null,i=m;else n=null,i=m;return n}function Hn(){var n,o,c,_,g;return _=i,g=i,n=Hr(),n!==null?(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=ln(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E,k){E=E.join("").toLowerCase(),k=k.join(""),G.uri_headers||(G.uri_headers={}),G.uri_headers[E]?G.uri_headers[E].push(k):G.uri_headers[E]=[k]}(_,n[0],n[2])),n===null&&(i=_),n}function Hr(){var n,o;if(o=Gn(),o===null&&(o=w(),o===null&&(o=q())),o!==null)for(n=[];o!==null;)n.push(o),o=Gn(),o===null&&(o=w(),o===null&&(o=q()));else n=null;return n}function ln(){var n,o;for(n=[],o=Gn(),o===null&&(o=w(),o===null&&(o=q()));o!==null;)n.push(o),o=Gn(),o===null&&(o=w(),o===null&&(o=q()));return n}function Gn(){var n;return r.charCodeAt(i)===91?(n="[",i++):(n=null,d('"["')),n===null&&(r.charCodeAt(i)===93?(n="]",i++):(n=null,d('"]"')),n===null&&(r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n===null&&(r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')))))))),n}function Fa(){var n;return n=sl(),n===null&&(n=Gr()),n}function Gr(){var n,o,c,_,g,m;return m=i,n=Wn(),n!==null?(o=O(),o!==null?(c=Di(),c!==null?(_=O(),_!==null?(g=xi(),g!==null?n=[n,o,c,_,g]:(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m),n}function Di(){var n;return n=$e(),n===null&&(n=Ni()),n}function Ni(){var n,o,c,_;return _=i,n=jr(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Vr(),c===null&&(c=an()),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Vr(){var n,o,c,_,g;return _=i,n=Vn(),n===null&&(n=Bn()),n!==null?(g=i,r.charCodeAt(i)===63?(o="?",i++):(o=null,d('"?"')),o!==null?(c=Pi(),c!==null?o=[o,c]:(o=null,i=g)):(o=null,i=g),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n}function Vn(){var n,o,c,_;return _=i,r.substr(i,2)==="//"?(n="//",i+=2):(n=null,d('"//"')),n!==null?(o=qr(),o!==null?(c=Bn(),c=c!==null?c:"",c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Bn(){var n,o,c;return c=i,r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n!==null?(o=jn(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function an(){var n,o,c,_;if(_=i,n=Br(),n!==null){for(o=[],c=on();c!==null;)o.push(c),c=on();o!==null?n=[n,o]:(n=null,i=_)}else n=null,i=_;return n}function on(){var n;return n=b(),n===null&&(n=w(),n===null&&(n=q())),n}function Br(){var n;return n=w(),n===null&&(n=q(),n===null&&(r.charCodeAt(i)===59?(n=";",i++):(n=null,d('";"')),n===null&&(r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===64?(n="@",i++):(n=null,d('"@"')),n===null&&(r.charCodeAt(i)===38?(n="&",i++):(n=null,d('"&"')),n===null&&(r.charCodeAt(i)===61?(n="=",i++):(n=null,d('"="')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')),n===null&&(r.charCodeAt(i)===44?(n=",",i++):(n=null,d('","')))))))))))),n}function jn(){var n,o,c,_,g,m;if(g=i,n=un(),n!==null){for(o=[],m=i,r.charCodeAt(i)===47?(c="/",i++):(c=null,d('"/"')),c!==null?(_=un(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,r.charCodeAt(i)===47?(c="/",i++):(c=null,d('"/"')),c!==null?(_=un(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function un(){var n,o,c,_,g,m;for(g=i,n=[],o=cn();o!==null;)n.push(o),o=cn();if(n!==null){for(o=[],m=i,r.charCodeAt(i)===59?(c=";",i++):(c=null,d('";"')),c!==null?(_=Ms(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,r.charCodeAt(i)===59?(c=";",i++):(c=null,d('";"')),c!==null?(_=Ms(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Ms(){var n,o;for(n=[],o=cn();o!==null;)n.push(o),o=cn();return n}function cn(){var n;return n=w(),n===null&&(n=q(),n===null&&(r.charCodeAt(i)===58?(n=":",i++):(n=null,d('":"')),n===null&&(r.charCodeAt(i)===64?(n="@",i++):(n=null,d('"@"')),n===null&&(r.charCodeAt(i)===38?(n="&",i++):(n=null,d('"&"')),n===null&&(r.charCodeAt(i)===61?(n="=",i++):(n=null,d('"="')),n===null&&(r.charCodeAt(i)===43?(n="+",i++):(n=null,d('"+"')),n===null&&(r.charCodeAt(i)===36?(n="$",i++):(n=null,d('"$"')),n===null&&(r.charCodeAt(i)===44?(n=",",i++):(n=null,d('","')))))))))),n}function jr(){var n,o,c,_,g;if(_=i,g=i,n=T(),n!==null){for(o=[],c=T(),c===null&&(c=v(),c===null&&(r.charCodeAt(i)===43?(c="+",i++):(c=null,d('"+"')),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."'))))));c!==null;)o.push(c),c=T(),c===null&&(c=v(),c===null&&(r.charCodeAt(i)===43?(c="+",i++):(c=null,d('"+"')),c===null&&(r.charCodeAt(i)===45?(c="-",i++):(c=null,d('"-"')),c===null&&(r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."'))))));o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n!==null&&(n=function(m){G.scheme=r.substring(i,m)}(_)),n===null&&(i=_),n}function qr(){var n;return n=Wr(),n===null&&(n=Kr()),n}function Wr(){var n,o,c,_;return c=i,_=i,n=Dt(),n!==null?(r.charCodeAt(i)===64?(o="@",i++):(o=null,d('"@"')),o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n=n!==null?n:"",n!==null?(o=Es(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n=n!==null?n:"",n}function Kr(){var n,o;if(o=w(),o===null&&(o=q(),o===null&&(r.charCodeAt(i)===36?(o="$",i++):(o=null,d('"$"')),o===null&&(r.charCodeAt(i)===44?(o=",",i++):(o=null,d('","')),o===null&&(r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o===null&&(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o===null&&(r.charCodeAt(i)===64?(o="@",i++):(o=null,d('"@"')),o===null&&(r.charCodeAt(i)===38?(o="&",i++):(o=null,d('"&"')),o===null&&(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"'))))))))))),o!==null)for(n=[];o!==null;)n.push(o),o=w(),o===null&&(o=q(),o===null&&(r.charCodeAt(i)===36?(o="$",i++):(o=null,d('"$"')),o===null&&(r.charCodeAt(i)===44?(o=",",i++):(o=null,d('","')),o===null&&(r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o===null&&(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o===null&&(r.charCodeAt(i)===64?(o="@",i++):(o=null,d('"@"')),o===null&&(r.charCodeAt(i)===38?(o="&",i++):(o=null,d('"&"')),o===null&&(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o===null&&(r.charCodeAt(i)===43?(o="+",i++):(o=null,d('"+"')))))))))));else n=null;return n}function Pi(){var n,o;for(n=[],o=on();o!==null;)n.push(o),o=on();return n}function xi(){var n,o,c,_,g,m,E,k;if(E=i,k=i,r.substr(i,3).toLowerCase()==="sip"?(n=r.substr(i,3),i+=3):(n=null,d('"SIP"')),n!==null)if(r.charCodeAt(i)===47?(o="/",i++):(o=null,d('"/"')),o!==null){if(_=v(),_!==null)for(c=[];_!==null;)c.push(_),_=v();else c=null;if(c!==null)if(r.charCodeAt(i)===46?(_=".",i++):(_=null,d('"."')),_!==null){if(m=v(),m!==null)for(g=[];m!==null;)g.push(m),m=v();else g=null;g!==null?n=[n,o,c,_,g]:(n=null,i=k)}else n=null,i=k;else n=null,i=k}else n=null,i=k;else n=null,i=k;return n!==null&&(n=function(W){G.sip_version=r.substring(i,W)}(E)),n===null&&(i=E),n}function Yr(){var n;return r.substr(i,6)==="INVITE"?(n="INVITE",i+=6):(n=null,d('"INVITE"')),n}function zr(){var n;return r.substr(i,3)==="ACK"?(n="ACK",i+=3):(n=null,d('"ACK"')),n}function Xr(){var n;return r.substr(i,7)==="OPTIONS"?(n="OPTIONS",i+=7):(n=null,d('"OPTIONS"')),n}function Jr(){var n;return r.substr(i,3)==="BYE"?(n="BYE",i+=3):(n=null,d('"BYE"')),n}function Qr(){var n;return r.substr(i,6)==="CANCEL"?(n="CANCEL",i+=6):(n=null,d('"CANCEL"')),n}function Zr(){var n;return r.substr(i,8)==="REGISTER"?(n="REGISTER",i+=8):(n=null,d('"REGISTER"')),n}function el(){var n;return r.substr(i,9)==="SUBSCRIBE"?(n="SUBSCRIBE",i+=9):(n=null,d('"SUBSCRIBE"')),n}function tl(){var n;return r.substr(i,6)==="NOTIFY"?(n="NOTIFY",i+=6):(n=null,d('"NOTIFY"')),n}function qn(){var n;return r.substr(i,5)==="REFER"?(n="REFER",i+=5):(n=null,d('"REFER"')),n}function Wn(){var n,o;return o=i,n=Yr(),n===null&&(n=zr(),n===null&&(n=Xr(),n===null&&(n=Jr(),n===null&&(n=Qr(),n===null&&(n=Zr(),n===null&&(n=el(),n===null&&(n=tl(),n===null&&(n=qn(),n===null&&(n=V()))))))))),n!==null&&(n=function(c){return G.method=r.substring(i,c),G.method}(o)),n===null&&(i=o),n}function sl(){var n,o,c,_,g,m;return m=i,n=xi(),n!==null?(o=O(),o!==null?(c=nl(),c!==null?(_=O(),_!==null?(g=$a(),g!==null?n=[n,o,c,_,g]:(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m),n}function nl(){var n,o;return o=i,n=il(),n!==null&&(n=function(c,_){G.status_code=parseInt(_.join(""))}(o,n)),n===null&&(i=o),n}function il(){var n,o,c,_;return _=i,n=v(),n!==null?(o=v(),o!==null?(c=v(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function $a(){var n,o,c;for(c=i,n=[],o=b(),o===null&&(o=w(),o===null&&(o=q(),o===null&&(o=B(),o===null&&(o=z(),o===null&&(o=O(),o===null&&(o=N()))))));o!==null;)n.push(o),o=b(),o===null&&(o=w(),o===null&&(o=q(),o===null&&(o=B(),o===null&&(o=z(),o===null&&(o=O(),o===null&&(o=N()))))));return n!==null&&(n=function(_){G.reason_phrase=r.substring(i,_)}(c)),n===null&&(i=c),n}function yc(){var n,o,c,_,g,m;if(g=i,n=Xn(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=Xn(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=Xn(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Sc(){var n,o,c,_,g,m;return _=i,g=i,n=ee(),n!==null?(m=i,r.charCodeAt(i)===64?(o="@",i++):(o=null,d('"@"')),o!==null?(c=ee(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E){G=r.substring(i,E)}(_)),n===null&&(i=_),n}function ki(){var n,o,c,_,g,m,E;if(g=i,n=j(),n===null)if(m=i,n=ss(),n!==null){for(o=[],E=i,c=M(),c!==null?(_=ss(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=M(),c!==null?(_=ss(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W,pe;for(pe=G.multi_header.length,W=0;W<pe;W++)if(G.multi_header[W].parsed===null){G=null;break}G!==null?G=G.multi_header:G=-1}()),n===null&&(i=g),n}function ss(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=ns()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=Mi(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=Mi(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W;G.multi_header||(G.multi_header=[]);try{W=new H(G.uri,G.display_name,G.params),delete G.uri,delete G.display_name,delete G.params}catch{W=null}G.multi_header.push({possition:i,offset:k,parsed:W})}(g)),n===null&&(i=g),n}function ns(){var n,o,c,_,g;return g=i,n=hn(),n=n!==null?n:"",n!==null?(o=be(),o!==null?(c=$e(),c!==null?(_=ke(),_!==null?n=[n,o,c,_]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n}function hn(){var n,o,c,_,g,m,E;if(g=i,m=i,n=V(),n!==null){for(o=[],E=i,c=D(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=D(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n===null&&(n=ce()),n!==null&&(n=function(k,W){typeof W=="string"?G.display_name=W:G.display_name=W[1].reduce(function(pe,He){return pe+He[0]+He[1]},W[0])}(g,n)),n===null&&(i=g),n}function Mi(){var n;return n=rl(),n===null&&(n=Cs(),n===null&&(n=lt())),n}function rl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,1).toLowerCase()==="q"?(n=r.substr(i,1),i++):(n=null,d('"q"')),n!==null?(o=ie(),o!==null?(c=rt(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.params||(G.params={}),G.params.q=E}(_,n[2])),n===null&&(i=_),n}function Cs(){var n,o,c,_,g;return _=i,g=i,r.substr(i,7).toLowerCase()==="expires"?(n=r.substr(i,7),i+=7):(n=null,d('"expires"')),n!==null?(o=ie(),o!==null?(c=As(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.params||(G.params={}),G.params.expires=E}(_,n[2])),n===null&&(i=_),n}function As(){var n,o,c;if(c=i,o=v(),o!==null)for(n=[];o!==null;)n.push(o),o=v();else n=null;return n!==null&&(n=function(_,g){return parseInt(g.join(""))}(c,n)),n===null&&(i=c),n}function rt(){var n,o,c,_,g,m,E,k;return m=i,E=i,r.charCodeAt(i)===48?(n="0",i++):(n=null,d('"0"')),n!==null?(k=i,r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o!==null?(c=v(),c=c!==null?c:"",c!==null?(_=v(),_=_!==null?_:"",_!==null?(g=v(),g=g!==null?g:"",g!==null?o=[o,c,_,g]:(o=null,i=k)):(o=null,i=k)):(o=null,i=k)):(o=null,i=k),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=E)):(n=null,i=E),n!==null&&(n=function(W){return parseFloat(r.substring(i,W))}(m)),n===null&&(i=m),n}function lt(){var n,o,c,_,g,m;return _=i,g=i,n=V(),n!==null?(m=i,o=ie(),o!==null?(c=Ha(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E,k,W){G.params||(G.params={}),typeof W>"u"?W=void 0:W=W[1],G.params[k.toLowerCase()]=W}(_,n[0],n[1])),n===null&&(i=_),n}function Ha(){var n;return n=V(),n===null&&(n=ks(),n===null&&(n=De())),n}function Ga(){var n,o,c,_,g,m;if(g=i,n=Ui(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Li(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Li(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Ui(){var n;return r.substr(i,6).toLowerCase()==="render"?(n=r.substr(i,6),i+=6):(n=null,d('"render"')),n===null&&(r.substr(i,7).toLowerCase()==="session"?(n=r.substr(i,7),i+=7):(n=null,d('"session"')),n===null&&(r.substr(i,4).toLowerCase()==="icon"?(n=r.substr(i,4),i+=4):(n=null,d('"icon"')),n===null&&(r.substr(i,5).toLowerCase()==="alert"?(n=r.substr(i,5),i+=5):(n=null,d('"alert"')),n===null&&(n=V())))),n}function Li(){var n;return n=Va(),n===null&&(n=lt()),n}function Va(){var n,o,c,_;return _=i,r.substr(i,8).toLowerCase()==="handling"?(n=r.substr(i,8),i+=8):(n=null,d('"handling"')),n!==null?(o=ie(),o!==null?(r.substr(i,8).toLowerCase()==="optional"?(c=r.substr(i,8),i+=8):(c=null,d('"optional"')),c===null&&(r.substr(i,8).toLowerCase()==="required"?(c=r.substr(i,8),i+=8):(c=null,d('"required"')),c===null&&(c=V())),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Ec(){var n,o,c,_,g,m;if(g=i,n=V(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Cc(){var n,o,c;if(c=i,o=v(),o!==null)for(n=[];o!==null;)n.push(o),o=v();else n=null;return n!==null&&(n=function(_,g){G=parseInt(g.join(""))}(c,n)),n===null&&(i=c),n}function Ba(){var n,o;return o=i,n=ll(),n!==null&&(n=function(c){G=r.substring(i,c)}(o)),n===null&&(i=o),n}function ll(){var n,o,c,_,g,m,E,k;if(E=i,n=al(),n!==null)if(o=K(),o!==null)if(c=Fi(),c!==null){for(_=[],k=i,g=Y(),g!==null?(m=$i(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=Y(),g!==null?(m=$i(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);_!==null?n=[n,o,c,_]:(n=null,i=E)}else n=null,i=E;else n=null,i=E;else n=null,i=E;return n}function al(){var n;return n=ol(),n===null&&(n=Kn()),n}function ol(){var n;return r.substr(i,4).toLowerCase()==="text"?(n=r.substr(i,4),i+=4):(n=null,d('"text"')),n===null&&(r.substr(i,5).toLowerCase()==="image"?(n=r.substr(i,5),i+=5):(n=null,d('"image"')),n===null&&(r.substr(i,5).toLowerCase()==="audio"?(n=r.substr(i,5),i+=5):(n=null,d('"audio"')),n===null&&(r.substr(i,5).toLowerCase()==="video"?(n=r.substr(i,5),i+=5):(n=null,d('"video"')),n===null&&(r.substr(i,11).toLowerCase()==="application"?(n=r.substr(i,11),i+=11):(n=null,d('"application"')),n===null&&(n=Yn()))))),n}function Kn(){var n;return r.substr(i,7).toLowerCase()==="message"?(n=r.substr(i,7),i+=7):(n=null,d('"message"')),n===null&&(r.substr(i,9).toLowerCase()==="multipart"?(n=r.substr(i,9),i+=9):(n=null,d('"multipart"')),n===null&&(n=Yn())),n}function Yn(){var n;return n=V(),n===null&&(n=ul()),n}function ul(){var n,o,c;return c=i,r.substr(i,2).toLowerCase()==="x-"?(n=r.substr(i,2),i+=2):(n=null,d('"x-"')),n!==null?(o=V(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function Fi(){var n;return n=Yn(),n===null&&(n=V()),n}function $i(){var n,o,c,_;return _=i,n=V(),n!==null?(o=ie(),o!==null?(c=ja(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function ja(){var n;return n=V(),n===null&&(n=De()),n}function qa(){var n,o,c,_;return _=i,n=Wa(),n!==null?(o=D(),o!==null?(c=Wn(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Wa(){var n,o,c;if(c=i,o=v(),o!==null)for(n=[];o!==null;)n.push(o),o=v();else n=null;return n!==null&&(n=function(_,g){G.value=parseInt(g.join(""))}(c,n)),n===null&&(i=c),n}function Ac(){var n,o;return o=i,n=As(),n!==null&&(n=function(c,_){G=_}(o,n)),n===null&&(i=o),n}function zn(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Xn(),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k,W){G.event=W.join("").toLowerCase()}(g,n[0])),n===null&&(i=g),n}function Xn(){var n,o,c,_,g,m;if(g=i,n=J(),n!==null){for(o=[],m=i,r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."')),c!==null?(_=J(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,r.charCodeAt(i)===46?(c=".",i++):(c=null,d('"."')),c!==null?(_=J(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function cl(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=ns()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=Jn(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=Jn(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W=G.tag;try{G=new H(G.uri,G.display_name,G.params),W&&G.setParam("tag",W)}catch{G=-1}}()),n===null&&(i=g),n}function Jn(){var n;return n=hl(),n===null&&(n=lt()),n}function hl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,3).toLowerCase()==="tag"?(n=r.substr(i,3),i+=3):(n=null,d('"tag"')),n!==null?(o=ie(),o!==null?(c=V(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.tag=E}(_,n[2])),n===null&&(i=_),n}function bc(){var n,o,c;if(c=i,o=v(),o!==null)for(n=[];o!==null;)n.push(o),o=v();else n=null;return n!==null&&(n=function(_,g){G=parseInt(g.join(""))}(c,n)),n===null&&(i=c),n}function Rc(){var n,o;return o=i,n=As(),n!==null&&(n=function(c,_){G=_}(o,n)),n===null&&(i=o),n}function wc(){var n,o,c,_,g,m,E,k,W,pe;for(k=i,W=i,n=[],o=hn();o!==null;)n.push(o),o=hn();if(n!==null)if(o=be(),o!==null)if(c=$e(),c!==null)if(_=ke(),_!==null){for(g=[],pe=i,m=Y(),m!==null?(E=lt(),E!==null?m=[m,E]:(m=null,i=pe)):(m=null,i=pe);m!==null;)g.push(m),pe=i,m=Y(),m!==null?(E=lt(),E!==null?m=[m,E]:(m=null,i=pe)):(m=null,i=pe);g!==null?n=[n,o,c,_,g]:(n=null,i=W)}else n=null,i=W;else n=null,i=W;else n=null,i=W;else n=null,i=W;return n!==null&&(n=function(He){try{G=new H(G.uri,G.display_name,G.params)}catch{G=-1}}()),n===null&&(i=k),n}function fl(){var n;return n=Hi(),n}function Hi(){var n,o,c,_,g,m,E,k;if(E=i,r.substr(i,6).toLowerCase()==="digest"?(n=r.substr(i,6),i+=6):(n=null,d('"Digest"')),n!==null)if(o=D(),o!==null)if(c=Qn(),c!==null){for(_=[],k=i,g=M(),g!==null?(m=Qn(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=M(),g!==null?(m=Qn(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);_!==null?n=[n,o,c,_]:(n=null,i=E)}else n=null,i=E;else n=null,i=E;else n=null,i=E;return n===null&&(n=fn()),n}function fn(){var n,o,c,_,g,m,E,k;if(E=i,n=V(),n!==null)if(o=D(),o!==null)if(c=bs(),c!==null){for(_=[],k=i,g=M(),g!==null?(m=bs(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=M(),g!==null?(m=bs(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);_!==null?n=[n,o,c,_]:(n=null,i=E)}else n=null,i=E;else n=null,i=E;else n=null,i=E;return n}function bs(){var n,o,c,_;return _=i,n=V(),n!==null?(o=ie(),o!==null?(c=V(),c===null&&(c=De()),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Qn(){var n;return n=dl(),n===null&&(n=Zn(),n===null&&(n=gl(),n===null&&(n=ml(),n===null&&(n=vl(),n===null&&(n=Tl(),n===null&&(n=ti(),n===null&&(n=bs()))))))),n}function dl(){var n,o,c,_;return _=i,r.substr(i,5).toLowerCase()==="realm"?(n=r.substr(i,5),i+=5):(n=null,d('"realm"')),n!==null?(o=ie(),o!==null?(c=_l(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function _l(){var n,o;return o=i,n=ce(),n!==null&&(n=function(c,_){G.realm=_}(o,n)),n===null&&(i=o),n}function Zn(){var n,o,c,_,g,m,E,k,W;if(k=i,r.substr(i,6).toLowerCase()==="domain"?(n=r.substr(i,6),i+=6):(n=null,d('"domain"')),n!==null)if(o=ie(),o!==null)if(c=Me(),c!==null)if(_=ei(),_!==null){if(g=[],W=i,E=O(),E!==null)for(m=[];E!==null;)m.push(E),E=O();else m=null;for(m!==null?(E=ei(),E!==null?m=[m,E]:(m=null,i=W)):(m=null,i=W);m!==null;){if(g.push(m),W=i,E=O(),E!==null)for(m=[];E!==null;)m.push(E),E=O();else m=null;m!==null?(E=ei(),E!==null?m=[m,E]:(m=null,i=W)):(m=null,i=W)}g!==null?(m=fe(),m!==null?n=[n,o,c,_,g,m]:(n=null,i=k)):(n=null,i=k)}else n=null,i=k;else n=null,i=k;else n=null,i=k;else n=null,i=k;return n}function ei(){var n;return n=Ni(),n===null&&(n=Bn()),n}function gl(){var n,o,c,_;return _=i,r.substr(i,5).toLowerCase()==="nonce"?(n=r.substr(i,5),i+=5):(n=null,d('"nonce"')),n!==null?(o=ie(),o!==null?(c=pl(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function pl(){var n,o;return o=i,n=ce(),n!==null&&(n=function(c,_){G.nonce=_}(o,n)),n===null&&(i=o),n}function ml(){var n,o,c,_,g;return _=i,g=i,r.substr(i,6).toLowerCase()==="opaque"?(n=r.substr(i,6),i+=6):(n=null,d('"opaque"')),n!==null?(o=ie(),o!==null?(c=ce(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.opaque=E}(_,n[2])),n===null&&(i=_),n}function vl(){var n,o,c,_,g;return _=i,r.substr(i,5).toLowerCase()==="stale"?(n=r.substr(i,5),i+=5):(n=null,d('"stale"')),n!==null?(o=ie(),o!==null?(g=i,r.substr(i,4).toLowerCase()==="true"?(c=r.substr(i,4),i+=4):(c=null,d('"true"')),c!==null&&(c=function(m){G.stale=!0}()),c===null&&(i=g),c===null&&(g=i,r.substr(i,5).toLowerCase()==="false"?(c=r.substr(i,5),i+=5):(c=null,d('"false"')),c!==null&&(c=function(m){G.stale=!1}()),c===null&&(i=g)),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Tl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,9).toLowerCase()==="algorithm"?(n=r.substr(i,9),i+=9):(n=null,d('"algorithm"')),n!==null?(o=ie(),o!==null?(r.substr(i,3).toLowerCase()==="md5"?(c=r.substr(i,3),i+=3):(c=null,d('"MD5"')),c===null&&(r.substr(i,8).toLowerCase()==="md5-sess"?(c=r.substr(i,8),i+=8):(c=null,d('"MD5-sess"')),c===null&&(c=V())),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.algorithm=E.toUpperCase()}(_,n[2])),n===null&&(i=_),n}function ti(){var n,o,c,_,g,m,E,k,W,pe;if(k=i,r.substr(i,3).toLowerCase()==="qop"?(n=r.substr(i,3),i+=3):(n=null,d('"qop"')),n!==null)if(o=ie(),o!==null)if(c=Me(),c!==null){if(W=i,_=Gi(),_!==null){for(g=[],pe=i,r.charCodeAt(i)===44?(m=",",i++):(m=null,d('","')),m!==null?(E=Gi(),E!==null?m=[m,E]:(m=null,i=pe)):(m=null,i=pe);m!==null;)g.push(m),pe=i,r.charCodeAt(i)===44?(m=",",i++):(m=null,d('","')),m!==null?(E=Gi(),E!==null?m=[m,E]:(m=null,i=pe)):(m=null,i=pe);g!==null?_=[_,g]:(_=null,i=W)}else _=null,i=W;_!==null?(g=fe(),g!==null?n=[n,o,c,_,g]:(n=null,i=k)):(n=null,i=k)}else n=null,i=k;else n=null,i=k;else n=null,i=k;return n}function Gi(){var n,o;return o=i,r.substr(i,8).toLowerCase()==="auth-int"?(n=r.substr(i,8),i+=8):(n=null,d('"auth-int"')),n===null&&(r.substr(i,4).toLowerCase()==="auth"?(n=r.substr(i,4),i+=4):(n=null,d('"auth"')),n===null&&(n=V())),n!==null&&(n=function(c,_){G.qop||(G.qop=[]),G.qop.push(_.toLowerCase())}(o,n)),n===null&&(i=o),n}function Ic(){var n,o,c,_,g,m;if(g=i,n=V(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Vi(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Bi(),n!==null){for(o=[],E=i,c=M(),c!==null?(_=Bi(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=M(),c!==null?(_=Bi(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W,pe;for(pe=G.multi_header.length,W=0;W<pe;W++)if(G.multi_header[W].parsed===null){G=null;break}G!==null?G=G.multi_header:G=-1}()),n===null&&(i=g),n}function Bi(){var n,o,c,_,g,m,E;if(g=i,m=i,n=ns(),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W;G.multi_header||(G.multi_header=[]);try{W=new H(G.uri,G.display_name,G.params),delete G.uri,delete G.display_name,delete G.params}catch{W=null}G.multi_header.push({possition:i,offset:k,parsed:W})}(g)),n===null&&(i=g),n}function yl(){var n,o,c,_,g,m,E;if(g=i,m=i,r.substr(i,3).toLowerCase()==="sip"?(n=r.substr(i,3),i+=3):(n=null,d('"SIP"')),n===null&&(n=V()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=ji(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=ji(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k,W){if(G.protocol=W.toLowerCase(),G.params||(G.params={}),G.params.text&&G.params.text[0]==='"'){var pe=G.params.text;G.text=pe.substring(1,pe.length-1),delete G.params.text}}(g,n[0])),n===null&&(i=g),n}function ji(){var n;return n=Ka(),n===null&&(n=lt()),n}function Ka(){var n,o,c,_,g,m;if(g=i,m=i,r.substr(i,5).toLowerCase()==="cause"?(n=r.substr(i,5),i+=5):(n=null,d('"cause"')),n!==null)if(o=ie(),o!==null){if(_=v(),_!==null)for(c=[];_!==null;)c.push(_),_=v();else c=null;c!==null?n=[n,o,c]:(n=null,i=m)}else n=null,i=m;else n=null,i=m;return n!==null&&(n=function(E,k){G.cause=parseInt(k.join(""))}(g,n[2])),n===null&&(i=g),n}function Oc(){var n,o,c,_,g,m;if(g=i,n=V(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function qi(){var n,o,c,_,g,m;if(g=i,n=Wi(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=Wi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=Wi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Wi(){var n,o,c,_,g,m;if(g=i,n=ns(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Ya(){var n,o,c,_,g,m;if(g=i,n=Ki(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Yi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Yi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Ki(){var n,o;return o=i,r.substr(i,6).toLowerCase()==="active"?(n=r.substr(i,6),i+=6):(n=null,d('"active"')),n===null&&(r.substr(i,7).toLowerCase()==="pending"?(n=r.substr(i,7),i+=7):(n=null,d('"pending"')),n===null&&(r.substr(i,10).toLowerCase()==="terminated"?(n=r.substr(i,10),i+=10):(n=null,d('"terminated"')),n===null&&(n=V()))),n!==null&&(n=function(c){G.state=r.substring(i,c)}(o)),n===null&&(i=o),n}function Yi(){var n,o,c,_,g;return _=i,g=i,r.substr(i,6).toLowerCase()==="reason"?(n=r.substr(i,6),i+=6):(n=null,d('"reason"')),n!==null?(o=ie(),o!==null?(c=za(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){typeof E<"u"&&(G.reason=E)}(_,n[2])),n===null&&(i=_),n===null&&(_=i,g=i,r.substr(i,7).toLowerCase()==="expires"?(n=r.substr(i,7),i+=7):(n=null,d('"expires"')),n!==null?(o=ie(),o!==null?(c=As(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){typeof E<"u"&&(G.expires=E)}(_,n[2])),n===null&&(i=_),n===null&&(_=i,g=i,r.substr(i,11).toLowerCase()==="retry_after"?(n=r.substr(i,11),i+=11):(n=null,d('"retry_after"')),n!==null?(o=ie(),o!==null?(c=As(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){typeof E<"u"&&(G.retry_after=E)}(_,n[2])),n===null&&(i=_),n===null&&(n=lt()))),n}function za(){var n;return r.substr(i,11).toLowerCase()==="deactivated"?(n=r.substr(i,11),i+=11):(n=null,d('"deactivated"')),n===null&&(r.substr(i,9).toLowerCase()==="probation"?(n=r.substr(i,9),i+=9):(n=null,d('"probation"')),n===null&&(r.substr(i,8).toLowerCase()==="rejected"?(n=r.substr(i,8),i+=8):(n=null,d('"rejected"')),n===null&&(r.substr(i,7).toLowerCase()==="timeout"?(n=r.substr(i,7),i+=7):(n=null,d('"timeout"')),n===null&&(r.substr(i,6).toLowerCase()==="giveup"?(n=r.substr(i,6),i+=6):(n=null,d('"giveup"')),n===null&&(r.substr(i,10).toLowerCase()==="noresource"?(n=r.substr(i,10),i+=10):(n=null,d('"noresource"')),n===null&&(r.substr(i,9).toLowerCase()==="invariant"?(n=r.substr(i,9),i+=9):(n=null,d('"invariant"')),n===null&&(n=V()))))))),n}function Dc(){var n;return n=x(),n=n!==null?n:"",n}function Nc(){var n,o,c,_,g,m;if(g=i,n=V(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=V(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n=n!==null?n:"",n}function Sl(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=ns()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=El(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=El(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){var W=G.tag;try{G=new H(G.uri,G.display_name,G.params),W&&G.setParam("tag",W)}catch{G=-1}}()),n===null&&(i=g),n}function El(){var n;return n=hl(),n===null&&(n=lt()),n}function zi(){var n,o,c,_,g,m;if(g=i,n=dn(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=dn(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=dn(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function dn(){var n,o,c,_,g,m,E,k;if(E=i,n=Ol(),n!==null)if(o=D(),o!==null)if(c=Pl(),c!==null){for(_=[],k=i,g=Y(),g!==null?(m=Xi(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=Y(),g!==null?(m=Xi(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);_!==null?n=[n,o,c,_]:(n=null,i=E)}else n=null,i=E;else n=null,i=E;else n=null,i=E;return n}function Xi(){var n;return n=Cl(),n===null&&(n=Al(),n===null&&(n=bl(),n===null&&(n=Rl(),n===null&&(n=wl(),n===null&&(n=lt()))))),n}function Cl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,3).toLowerCase()==="ttl"?(n=r.substr(i,3),i+=3):(n=null,d('"ttl"')),n!==null?(o=ie(),o!==null?(c=kl(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.ttl=E}(_,n[2])),n===null&&(i=_),n}function Al(){var n,o,c,_,g;return _=i,g=i,r.substr(i,5).toLowerCase()==="maddr"?(n=r.substr(i,5),i+=5):(n=null,d('"maddr"')),n!==null?(o=ie(),o!==null?(c=ks(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.maddr=E}(_,n[2])),n===null&&(i=_),n}function bl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,8).toLowerCase()==="received"?(n=r.substr(i,8),i+=8):(n=null,d('"received"')),n!==null?(o=ie(),o!==null?(c=hs(),c===null&&(c=Ae()),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.received=E}(_,n[2])),n===null&&(i=_),n}function Rl(){var n,o,c,_,g;return _=i,g=i,r.substr(i,6).toLowerCase()==="branch"?(n=r.substr(i,6),i+=6):(n=null,d('"branch"')),n!==null?(o=ie(),o!==null?(c=V(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.branch=E}(_,n[2])),n===null&&(i=_),n}function wl(){var n,o,c,_,g;return _=i,r.substr(i,5).toLowerCase()==="rport"?(n=r.substr(i,5),i+=5):(n=null,d('"rport"')),n!==null?(g=i,o=ie(),o!==null?(c=Il(),c!==null?o=[o,c]:(o=null,i=g)):(o=null,i=g),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n}function Il(){var n,o,c,_,g,m,E;return m=i,E=i,n=v(),n=n!==null?n:"",n!==null?(o=v(),o=o!==null?o:"",o!==null?(c=v(),c=c!==null?c:"",c!==null?(_=v(),_=_!==null?_:"",_!==null?(g=v(),g=g!==null?g:"",g!==null?n=[n,o,c,_,g]:(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E),n!==null&&(n=function(k,W){G.rport=parseInt(W.join(""))}(m,n)),n===null&&(i=m),n}function Ol(){var n,o,c,_,g,m;return m=i,n=Dl(),n!==null?(o=K(),o!==null?(c=V(),c!==null?(_=K(),_!==null?(g=Nl(),g!==null?n=[n,o,c,_,g]:(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m)):(n=null,i=m),n}function Dl(){var n,o;return o=i,r.substr(i,3).toLowerCase()==="sip"?(n=r.substr(i,3),i+=3):(n=null,d('"SIP"')),n===null&&(n=V()),n!==null&&(n=function(c,_){G.protocol=_}(o,n)),n===null&&(i=o),n}function Nl(){var n,o;return o=i,r.substr(i,3).toLowerCase()==="udp"?(n=r.substr(i,3),i+=3):(n=null,d('"UDP"')),n===null&&(r.substr(i,3).toLowerCase()==="tcp"?(n=r.substr(i,3),i+=3):(n=null,d('"TCP"')),n===null&&(r.substr(i,3).toLowerCase()==="tls"?(n=r.substr(i,3),i+=3):(n=null,d('"TLS"')),n===null&&(r.substr(i,4).toLowerCase()==="sctp"?(n=r.substr(i,4),i+=4):(n=null,d('"SCTP"')),n===null&&(n=V())))),n!==null&&(n=function(c,_){G.transport=_}(o,n)),n===null&&(i=o),n}function Pl(){var n,o,c,_,g;return _=i,n=xl(),n!==null?(g=i,o=Ee(),o!==null?(c=Ji(),c!==null?o=[o,c]:(o=null,i=g)):(o=null,i=g),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=_)):(n=null,i=_),n}function xl(){var n,o;return o=i,n=hs(),n===null&&(n=Fn(),n===null&&(n=Ln())),n!==null&&(n=function(c){G.host=r.substring(i,c)}(o)),n===null&&(i=o),n}function Ji(){var n,o,c,_,g,m,E;return m=i,E=i,n=v(),n=n!==null?n:"",n!==null?(o=v(),o=o!==null?o:"",o!==null?(c=v(),c=c!==null?c:"",c!==null?(_=v(),_=_!==null?_:"",_!==null?(g=v(),g=g!==null?g:"",g!==null?n=[n,o,c,_,g]:(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E)):(n=null,i=E),n!==null&&(n=function(k,W){G.port=parseInt(W.join(""))}(m,n)),n===null&&(i=m),n}function kl(){var n,o,c,_,g;return _=i,g=i,n=v(),n!==null?(o=v(),o=o!==null?o:"",o!==null?(c=v(),c=c!==null?c:"",c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){return parseInt(E.join(""))}(_,n)),n===null&&(i=_),n}function Pc(){var n;return n=Hi(),n}function Xa(){var n,o,c,_,g,m;if(g=i,n=Qi(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Zi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Zi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function Qi(){var n,o;return o=i,n=As(),n!==null&&(n=function(c,_){G.expires=_}(o,n)),n===null&&(i=o),n}function Zi(){var n;return n=Ja(),n===null&&(n=lt()),n}function Ja(){var n,o,c,_,g;return _=i,g=i,r.substr(i,9).toLowerCase()==="refresher"?(n=r.substr(i,9),i+=9):(n=null,d('"refresher"')),n!==null?(o=ie(),o!==null?(r.substr(i,3).toLowerCase()==="uac"?(c=r.substr(i,3),i+=3):(c=null,d('"uac"')),c===null&&(r.substr(i,3).toLowerCase()==="uas"?(c=r.substr(i,3),i+=3):(c=null,d('"uas"'))),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.refresher=E.toLowerCase()}(_,n[2])),n===null&&(i=_),n}function Qa(){var n,o,c,_;return _=i,n=V(),n!==null?(o=I(),o!==null?(c=Za(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Za(){var n,o;for(n=[],o=U(),o===null&&(o=z(),o===null&&(o=D()));o!==null;)n.push(o),o=U(),o===null&&(o=z(),o===null&&(o=D()));return n}function xc(){var n,o;for(n=[],o=A();o!==null;)n.push(o),o=A();return n}function eo(){var n,o,c;return c=i,r.substr(i,5)==="uuid:"?(n="uuid:",i+=5):(n=null,d('"uuid:"')),n!==null?(o=is(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function is(){var n,o,c,_,g,m,E,k,W,pe,He;return pe=i,He=i,n=Ml(),n!==null?(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o!==null?(c=rs(),c!==null?(r.charCodeAt(i)===45?(_="-",i++):(_=null,d('"-"')),_!==null?(g=rs(),g!==null?(r.charCodeAt(i)===45?(m="-",i++):(m=null,d('"-"')),m!==null?(E=rs(),E!==null?(r.charCodeAt(i)===45?(k="-",i++):(k=null,d('"-"')),k!==null?(W=to(),W!==null?n=[n,o,c,_,g,m,E,k,W]:(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He)):(n=null,i=He),n!==null&&(n=function(Wt,_n){G=r.substring(i+5,Wt)}(pe,n[0])),n===null&&(i=pe),n}function rs(){var n,o,c,_,g;return g=i,n=y(),n!==null?(o=y(),o!==null?(c=y(),c!==null?(_=y(),_!==null?n=[n,o,c,_]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n}function Ml(){var n,o,c;return c=i,n=rs(),n!==null?(o=rs(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function to(){var n,o,c,_;return _=i,n=rs(),n!==null?(o=rs(),o!==null?(c=rs(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function kc(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=ns()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=lt(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);o!==null?n=[n,o]:(n=null,i=m)}else n=null,i=m;return n!==null&&(n=function(k){try{G=new H(G.uri,G.display_name,G.params)}catch{G=-1}}()),n===null&&(i=g),n}function so(){var n,o,c,_,g,m;if(g=i,n=er(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=tr(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=tr(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);o!==null?n=[n,o]:(n=null,i=g)}else n=null,i=g;return n}function er(){var n,o,c,_,g,m;return _=i,g=i,n=ee(),n!==null?(m=i,r.charCodeAt(i)===64?(o="@",i++):(o=null,d('"@"')),o!==null?(c=ee(),c!==null?o=[o,c]:(o=null,i=m)):(o=null,i=m),o=o!==null?o:"",o!==null?n=[n,o]:(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(E){G.call_id=r.substring(i,E)}(_)),n===null&&(i=_),n}function tr(){var n;return n=Ul(),n===null&&(n=Ll(),n===null&&(n=no(),n===null&&(n=lt()))),n}function Ul(){var n,o,c,_,g;return _=i,g=i,r.substr(i,6)==="to-tag"?(n="to-tag",i+=6):(n=null,d('"to-tag"')),n!==null?(o=ie(),o!==null?(c=V(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.to_tag=E}(_,n[2])),n===null&&(i=_),n}function Ll(){var n,o,c,_,g;return _=i,g=i,r.substr(i,8)==="from-tag"?(n="from-tag",i+=8):(n=null,d('"from-tag"')),n!==null?(o=ie(),o!==null?(c=V(),c!==null?n=[n,o,c]:(n=null,i=g)):(n=null,i=g)):(n=null,i=g),n!==null&&(n=function(m,E){G.from_tag=E}(_,n[2])),n===null&&(i=_),n}function no(){var n,o;return o=i,r.substr(i,10)==="early-only"?(n="early-only",i+=10):(n=null,d('"early-only"')),n!==null&&(n=function(c){G.early_only=!0}()),n===null&&(i=o),n}function Mc(n){n.sort();for(var o=null,c=[],_=0;_<n.length;_++)n[_]!==o&&(c.push(n[_]),o=n[_]);return c}function io(){for(var n=1,o=1,c=!1,_=0;_<Math.max(i,f);_++){var g=r.charAt(_);g===`
4
- `?(c||n++,o=1,c=!1):g==="\r"||g==="\u2028"||g==="\u2029"?(n++,o=1,c=!0):(o++,c=!1)}return{line:n,column:o}}var Us=On(),H=Af(),G={},Fl=s[l]();if(Fl===null||i!==r.length){var $l=Math.max(i,f),ro=$l<r.length?r.charAt($l):null,a=io();return new this.SyntaxError(Mc(h),ro,$l,a.line,a.column),-1}return G},toSource:function(){return this._source}};return e.SyntaxError=function(t,r,l,s,i){function f(h,d){var p,v;switch(h.length){case 0:p="end of input";break;case 1:p=h[0];break;default:p=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return v=d?u(d):"end of input","Expected "+p+" but "+v+" found."}this.name="SyntaxError",this.expected=t,this.found=r,this.message=f(t,r),this.offset=l,this.line=s,this.column=i},e.SyntaxError.prototype=Error.prototype,e}()),Lc}var Fc,rd;function On(){if(rd)return Fc;rd=1;function u(d,p){var v;if(typeof Symbol>"u"||d[Symbol.iterator]==null){if(Array.isArray(d)||(v=e(d))||p&&d&&typeof d.length=="number"){v&&(d=v);var T=0,y=function(){};return{s:y,n:function(){return T>=d.length?{done:!0}:{done:!1,value:d[T++]}},e:function(N){throw N},f:y}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var S=!0,A=!1,R;return{s:function(){v=d[Symbol.iterator]()},n:function(){var N=v.next();return S=N.done,N},e:function(N){A=!0,R=N},f:function(){try{!S&&v.return!=null&&v.return()}finally{if(A)throw R}}}}function e(d,p){if(d){if(typeof d=="string")return t(d,p);var v=Object.prototype.toString.call(d).slice(8,-1);if(v==="Object"&&d.constructor&&(v=d.constructor.name),v==="Map"||v==="Set")return Array.from(d);if(v==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(v))return t(d,p)}}function t(d,p){(p==null||p>d.length)&&(p=d.length);for(var v=0,T=new Array(p);v<p;v++)T[v]=d[v];return T}function r(d,p){if(!(d instanceof p))throw new TypeError("Cannot call a class as a function")}function l(d,p){for(var v=0;v<p.length;v++){var T=p[v];T.enumerable=T.enumerable||!1,T.configurable=!0,"value"in T&&(T.writable=!0),Object.defineProperty(d,T.key,T)}}function s(d,p,v){return p&&l(d.prototype,p),v&&l(d,v),d}var i=St,f=jt(),h=Ns();return Fc=function(){s(d,null,[{key:"parse",value:function(v){if(v=h.parse(v,"SIP_URI"),v!==-1)return v}}]);function d(p,v,T,y){var S=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},A=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(r(this,d),!T)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=p||i.SIP,this._user=v,this._host=T,this._port=y;for(var R in S)Object.prototype.hasOwnProperty.call(S,R)&&this.setParam(R,S[R]);for(var O in A)Object.prototype.hasOwnProperty.call(A,O)&&this.setHeader(O,A[O])}return s(d,[{key:"setParam",value:function(v,T){v&&(this._parameters[v.toLowerCase()]=typeof T>"u"||T===null?null:T.toString())}},{key:"getParam",value:function(v){if(v)return this._parameters[v.toLowerCase()]}},{key:"hasParam",value:function(v){if(v)return this._parameters.hasOwnProperty(v.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(v){if(v=v.toLowerCase(),this._parameters.hasOwnProperty(v)){var T=this._parameters[v];return delete this._parameters[v],T}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(v,T){this._headers[f.headerize(v)]=Array.isArray(T)?T:[T]}},{key:"getHeader",value:function(v){if(v)return this._headers[f.headerize(v)]}},{key:"hasHeader",value:function(v){if(v)return this._headers.hasOwnProperty(f.headerize(v))&&!0||!1}},{key:"deleteHeader",value:function(v){if(v=f.headerize(v),this._headers.hasOwnProperty(v)){var T=this._headers[v];return delete this._headers[v],T}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new d(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 v=[],T="".concat(this._scheme,":");this._user&&(T+="".concat(f.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 S in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,S)){var A=u(this._headers[S]),R;try{for(A.s();!(R=A.n()).done;){var O=R.value;v.push("".concat(S,"=").concat(O))}}catch(N){A.e(N)}finally{A.f()}}return v.length>0&&(T+="?".concat(v.join("&"))),T}},{key:"toAor",value:function(v){var T="".concat(this._scheme,":");return this._user&&(T+="".concat(f.escapeUser(this._user),"@")),T+=this._host,v&&(this._port||this._port===0)&&(T+=":".concat(this._port)),T}},{key:"scheme",get:function(){return this._scheme},set:function(v){this._scheme=v.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(v){this._user=v}},{key:"host",get:function(){return this._host},set:function(v){this._host=v.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(v){this._port=v===0?v:parseInt(v,10)||null}}]),d}(),Fc}var ld;function jt(){if(ld)return gt;ld=1;function u(p){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?u=function(T){return typeof T}:u=function(T){return T&&typeof Symbol=="function"&&T.constructor===Symbol&&T!==Symbol.prototype?"symbol":typeof T},u(p)}function e(p,v){var T;if(typeof Symbol>"u"||p[Symbol.iterator]==null){if(Array.isArray(p)||(T=t(p))||v&&p&&typeof p.length=="number"){T&&(p=T);var y=0,S=function(){};return{s:S,n:function(){return y>=p.length?{done:!0}:{done:!1,value:p[y++]}},e:function(C){throw C},f:S}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
6
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,R=!1,O;return{s:function(){T=p[Symbol.iterator]()},n:function(){var C=T.next();return A=C.done,C},e:function(C){R=!0,O=C},f:function(){try{!A&&T.return!=null&&T.return()}finally{if(R)throw O}}}}function t(p,v){if(p){if(typeof p=="string")return r(p,v);var T=Object.prototype.toString.call(p).slice(8,-1);if(T==="Object"&&p.constructor&&(T=p.constructor.name),T==="Map"||T==="Set")return Array.from(p);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return r(p,v)}}function r(p,v){(v==null||v>p.length)&&(v=p.length);for(var T=0,y=new Array(v);T<v;T++)y[T]=p[T];return y}var l=St,s=On(),i=Ns();gt.str_utf8_length=function(p){return unescape(encodeURIComponent(p)).length};var f=gt.isFunction=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object Function]":!1};gt.isString=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object String]":!1},gt.isDecimal=function(p){return!isNaN(p)&&parseFloat(p)===parseInt(p,10)},gt.isEmpty=function(p){return p===null||p===""||p===void 0||Array.isArray(p)&&p.length===0||typeof p=="number"&&isNaN(p)},gt.hasMethods=function(p){for(var v=arguments.length,T=new Array(v>1?v-1:0),y=1;y<v;y++)T[y-1]=arguments[y];for(var S=0,A=T;S<A.length;S++){var R=A[S];if(f(p[R]))return!1}return!0};var h=gt.createRandomToken=function(p){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,T,y,S="";for(T=0;T<p;T++)y=Math.random()*v|0,S+=y.toString(v);return S};gt.newTag=function(){return h(10)},gt.newUUID=function(){var p="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(v){var T=Math.random()*16|0,y=v==="x"?T:T&3|8;return y.toString(16)});return p},gt.hostType=function(p){if(p){if(p=i.parse(p,"host"),p!==-1)return p.host_type}else return};var d=gt.escapeUser=function(p){return encodeURIComponent(decodeURIComponent(p)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return gt.normalizeTarget=function(p,v){if(p){if(p instanceof s)return p;if(typeof p=="string"){var T=p.split("@"),y,S;switch(T.length){case 1:if(!v)return;y=p,S=v;break;case 2:y=T[0],S=T[1];break;default:y=T.slice(0,T.length-1).join("@"),S=T[T.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),p="".concat(l.SIP,":").concat(d(y),"@").concat(S);var A;return(A=s.parse(p))?A:void 0}else return}else return},gt.headerize=function(p){var v={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},T=p.toLowerCase().replace(/_/g,"-").split("-"),y="",S=T.length,A;for(A=0;A<S;A++)A!==0&&(y+="-"),y+=T[A].charAt(0).toUpperCase()+T[A].substring(1);return v[y]&&(y=v[y]),y},gt.sipErrorCause=function(p){for(var v in l.SIP_ERROR_CAUSES)if(l.SIP_ERROR_CAUSES[v].indexOf(p)!==-1)return l.causes[v];return l.causes.SIP_FAILURE_CODE},gt.getRandomTestNetIP=function(){function p(v,T){return Math.floor(Math.random()*(T-v+1)+v)}return"192.0.2.".concat(p(1,254))},gt.calculateMD5=function(p){function v(ce,de){return ce<<de|ce>>>32-de}function T(ce,de){var ge=ce&2147483648,Oe=de&2147483648,$e=ce&1073741824,_t=de&1073741824,Ye=(ce&1073741823)+(de&1073741823);return $e&_t?Ye^2147483648^ge^Oe:$e|_t?Ye&1073741824?Ye^3221225472^ge^Oe:Ye^1073741824^ge^Oe:Ye^ge^Oe}function y(ce,de,ge){return ce&de|~ce&ge}function S(ce,de,ge){return ce&ge|de&~ge}function A(ce,de,ge){return ce^de^ge}function R(ce,de,ge){return de^(ce|~ge)}function O(ce,de,ge,Oe,$e,_t,Ye){return ce=T(ce,T(T(y(de,ge,Oe),$e),Ye)),T(v(ce,_t),de)}function N(ce,de,ge,Oe,$e,_t,Ye){return ce=T(ce,T(T(S(de,ge,Oe),$e),Ye)),T(v(ce,_t),de)}function C(ce,de,ge,Oe,$e,_t,Ye){return ce=T(ce,T(T(A(de,ge,Oe),$e),Ye)),T(v(ce,_t),de)}function b(ce,de,ge,Oe,$e,_t,Ye){return ce=T(ce,T(T(R(de,ge,Oe),$e),Ye)),T(v(ce,_t),de)}function w(ce){for(var de,ge=ce.length,Oe=ge+8,$e=(Oe-Oe%64)/64,_t=($e+1)*16,Ye=new Array(_t-1),ts=0,Dt=0;Dt<ge;)de=(Dt-Dt%4)/4,ts=Dt%4*8,Ye[de]=Ye[de]|ce.charCodeAt(Dt)<<ts,Dt++;return de=(Dt-Dt%4)/4,ts=Dt%4*8,Ye[de]=Ye[de]|128<<ts,Ye[_t-2]=ge<<3,Ye[_t-1]=ge>>>29,Ye}function F(ce){var de="",ge="",Oe,$e;for($e=0;$e<=3;$e++)Oe=ce>>>$e*8&255,ge="0".concat(Oe.toString(16)),de=de+ge.substr(ge.length-2,2);return de}function q(ce){for(var de="",ge=0;ge<ce.length;ge++){var Oe=ce.charCodeAt(ge);Oe<128?de+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(de+=String.fromCharCode(Oe>>6|192),de+=String.fromCharCode(Oe&63|128)):(de+=String.fromCharCode(Oe>>12|224),de+=String.fromCharCode(Oe>>6&63|128),de+=String.fromCharCode(Oe&63|128))}return de}var D=[],P,I,x,U,B,z,L,V,J,Pe=7,ee=12,j=17,K=22,ie=5,ue=9,Ce=14,ke=20,be=4,M=11,Y=16,Ee=23,Me=6,fe=10,_e=15,we=21;for(p=q(p),D=w(p),z=1732584193,L=4023233417,V=2562383102,J=271733878,P=0;P<D.length;P+=16)I=z,x=L,U=V,B=J,z=O(z,L,V,J,D[P+0],Pe,3614090360),J=O(J,z,L,V,D[P+1],ee,3905402710),V=O(V,J,z,L,D[P+2],j,606105819),L=O(L,V,J,z,D[P+3],K,3250441966),z=O(z,L,V,J,D[P+4],Pe,4118548399),J=O(J,z,L,V,D[P+5],ee,1200080426),V=O(V,J,z,L,D[P+6],j,2821735955),L=O(L,V,J,z,D[P+7],K,4249261313),z=O(z,L,V,J,D[P+8],Pe,1770035416),J=O(J,z,L,V,D[P+9],ee,2336552879),V=O(V,J,z,L,D[P+10],j,4294925233),L=O(L,V,J,z,D[P+11],K,2304563134),z=O(z,L,V,J,D[P+12],Pe,1804603682),J=O(J,z,L,V,D[P+13],ee,4254626195),V=O(V,J,z,L,D[P+14],j,2792965006),L=O(L,V,J,z,D[P+15],K,1236535329),z=N(z,L,V,J,D[P+1],ie,4129170786),J=N(J,z,L,V,D[P+6],ue,3225465664),V=N(V,J,z,L,D[P+11],Ce,643717713),L=N(L,V,J,z,D[P+0],ke,3921069994),z=N(z,L,V,J,D[P+5],ie,3593408605),J=N(J,z,L,V,D[P+10],ue,38016083),V=N(V,J,z,L,D[P+15],Ce,3634488961),L=N(L,V,J,z,D[P+4],ke,3889429448),z=N(z,L,V,J,D[P+9],ie,568446438),J=N(J,z,L,V,D[P+14],ue,3275163606),V=N(V,J,z,L,D[P+3],Ce,4107603335),L=N(L,V,J,z,D[P+8],ke,1163531501),z=N(z,L,V,J,D[P+13],ie,2850285829),J=N(J,z,L,V,D[P+2],ue,4243563512),V=N(V,J,z,L,D[P+7],Ce,1735328473),L=N(L,V,J,z,D[P+12],ke,2368359562),z=C(z,L,V,J,D[P+5],be,4294588738),J=C(J,z,L,V,D[P+8],M,2272392833),V=C(V,J,z,L,D[P+11],Y,1839030562),L=C(L,V,J,z,D[P+14],Ee,4259657740),z=C(z,L,V,J,D[P+1],be,2763975236),J=C(J,z,L,V,D[P+4],M,1272893353),V=C(V,J,z,L,D[P+7],Y,4139469664),L=C(L,V,J,z,D[P+10],Ee,3200236656),z=C(z,L,V,J,D[P+13],be,681279174),J=C(J,z,L,V,D[P+0],M,3936430074),V=C(V,J,z,L,D[P+3],Y,3572445317),L=C(L,V,J,z,D[P+6],Ee,76029189),z=C(z,L,V,J,D[P+9],be,3654602809),J=C(J,z,L,V,D[P+12],M,3873151461),V=C(V,J,z,L,D[P+15],Y,530742520),L=C(L,V,J,z,D[P+2],Ee,3299628645),z=b(z,L,V,J,D[P+0],Me,4096336452),J=b(J,z,L,V,D[P+7],fe,1126891415),V=b(V,J,z,L,D[P+14],_e,2878612391),L=b(L,V,J,z,D[P+5],we,4237533241),z=b(z,L,V,J,D[P+12],Me,1700485571),J=b(J,z,L,V,D[P+3],fe,2399980690),V=b(V,J,z,L,D[P+10],_e,4293915773),L=b(L,V,J,z,D[P+1],we,2240044497),z=b(z,L,V,J,D[P+8],Me,1873313359),J=b(J,z,L,V,D[P+15],fe,4264355552),V=b(V,J,z,L,D[P+6],_e,2734768916),L=b(L,V,J,z,D[P+13],we,1309151649),z=b(z,L,V,J,D[P+4],Me,4149444226),J=b(J,z,L,V,D[P+11],fe,3174756917),V=b(V,J,z,L,D[P+2],_e,718787259),L=b(L,V,J,z,D[P+9],we,3951481745),z=T(z,I),L=T(L,x),V=T(V,U),J=T(J,B);var De=F(z)+F(L)+F(V)+F(J);return De.toLowerCase()},gt.closeMediaStream=function(p){if(p)try{var v;if(p.getTracks){v=p.getTracks();var T=e(v),y;try{for(T.s();!(y=T.n()).done;){var S=y.value;S.stop()}}catch(w){T.e(w)}finally{T.f()}}else{v=p.getAudioTracks();var A=e(v),R;try{for(A.s();!(R=A.n()).done;){var O=R.value;O.stop()}}catch(w){A.e(w)}finally{A.f()}v=p.getVideoTracks();var N=e(v),C;try{for(N.s();!(C=N.n()).done;){var b=C.value;b.stop()}}catch(w){N.e(w)}finally{N.f()}}}catch{(typeof p.stop=="function"||u(p.stop)==="object")&&p.stop()}},gt.cloneArray=function(p){return p&&p.slice()||[]},gt.cloneObject=function(p){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return p&&Object.assign({},p)||v},gt}var bf={exports:{}},_r=typeof Reflect=="object"?Reflect:null,ad=_r&&typeof _r.apply=="function"?_r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)},jo;_r&&typeof _r.ownKeys=="function"?jo=_r.ownKeys:Object.getOwnPropertySymbols?jo=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:jo=function(e){return Object.getOwnPropertyNames(e)};function M0(u){console&&console.warn&&console.warn(u)}var Mg=Number.isNaN||function(e){return e!==e};function Ke(){Ke.init.call(this)}bf.exports=Ke;bf.exports.once=$0;Ke.EventEmitter=Ke;Ke.prototype._events=void 0;Ke.prototype._eventsCount=0;Ke.prototype._maxListeners=void 0;var od=10;function Eu(u){if(typeof u!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof u)}Object.defineProperty(Ke,"defaultMaxListeners",{enumerable:!0,get:function(){return od},set:function(u){if(typeof u!="number"||u<0||Mg(u))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+u+".");od=u}});Ke.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};Ke.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Mg(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Ug(u){return u._maxListeners===void 0?Ke.defaultMaxListeners:u._maxListeners}Ke.prototype.getMaxListeners=function(){return Ug(this)};Ke.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var l=e==="error",s=this._events;if(s!==void 0)l=l&&s.error===void 0;else if(!l)return!1;if(l){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var f=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw f.context=i,f}var h=s[e];if(h===void 0)return!1;if(typeof h=="function")ad(h,this,t);else for(var d=h.length,p=Gg(h,d),r=0;r<d;++r)ad(p[r],this,t);return!0};function Lg(u,e,t,r){var l,s,i;if(Eu(t),s=u._events,s===void 0?(s=u._events=Object.create(null),u._eventsCount=0):(s.newListener!==void 0&&(u.emit("newListener",e,t.listener?t.listener:t),s=u._events),i=s[e]),i===void 0)i=s[e]=t,++u._eventsCount;else if(typeof i=="function"?i=s[e]=r?[t,i]:[i,t]:r?i.unshift(t):i.push(t),l=Ug(u),l>0&&i.length>l&&!i.warned){i.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=u,f.type=e,f.count=i.length,M0(f)}return u}Ke.prototype.addListener=function(e,t){return Lg(this,e,t,!1)};Ke.prototype.on=Ke.prototype.addListener;Ke.prototype.prependListener=function(e,t){return Lg(this,e,t,!0)};function U0(){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 Fg(u,e,t){var r={fired:!1,wrapFn:void 0,target:u,type:e,listener:t},l=U0.bind(r);return l.listener=t,r.wrapFn=l,l}Ke.prototype.once=function(e,t){return Eu(t),this.on(e,Fg(this,e,t)),this};Ke.prototype.prependOnceListener=function(e,t){return Eu(t),this.prependListener(e,Fg(this,e,t)),this};Ke.prototype.removeListener=function(e,t){var r,l,s,i,f;if(Eu(t),l=this._events,l===void 0)return this;if(r=l[e],r===void 0)return this;if(r===t||r.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete l[e],l.removeListener&&this.emit("removeListener",e,r.listener||t));else if(typeof r!="function"){for(s=-1,i=r.length-1;i>=0;i--)if(r[i]===t||r[i].listener===t){f=r[i].listener,s=i;break}if(s<0)return this;s===0?r.shift():L0(r,s),r.length===1&&(l[e]=r[0]),l.removeListener!==void 0&&this.emit("removeListener",e,f||t)}return this};Ke.prototype.off=Ke.prototype.removeListener;Ke.prototype.removeAllListeners=function(e){var t,r,l;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var s=Object.keys(r),i;for(l=0;l<s.length;++l)i=s[l],i!=="removeListener"&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=r[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(l=t.length-1;l>=0;l--)this.removeListener(e,t[l]);return this};function $g(u,e,t){var r=u._events;if(r===void 0)return[];var l=r[e];return l===void 0?[]:typeof l=="function"?t?[l.listener||l]:[l]:t?F0(l):Gg(l,l.length)}Ke.prototype.listeners=function(e){return $g(this,e,!0)};Ke.prototype.rawListeners=function(e){return $g(this,e,!1)};Ke.listenerCount=function(u,e){return typeof u.listenerCount=="function"?u.listenerCount(e):Hg.call(u,e)};Ke.prototype.listenerCount=Hg;function Hg(u){var e=this._events;if(e!==void 0){var t=e[u];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}Ke.prototype.eventNames=function(){return this._eventsCount>0?jo(this._events):[]};function Gg(u,e){for(var t=new Array(e),r=0;r<e;++r)t[r]=u[r];return t}function L0(u,e){for(;e+1<u.length;e++)u[e]=u[e+1];u.pop()}function F0(u){for(var e=new Array(u.length),t=0;t<e.length;++t)e[t]=u[t].listener||u[t];return e}function $0(u,e){return new Promise(function(t,r){function l(i){u.removeListener(e,s),r(i)}function s(){typeof u.removeListener=="function"&&u.removeListener("error",l),t([].slice.call(arguments))}Vg(u,e,s,{once:!0}),e!=="error"&&H0(u,l,{once:!0})})}function H0(u,e,t){typeof u.on=="function"&&Vg(u,"error",e,t)}function Vg(u,e,t,r){if(typeof u.on=="function")r.once?u.once(e,t):u.on(e,t);else if(typeof u.addEventListener=="function")u.addEventListener(e,function l(s){r.once&&u.removeEventListener(e,l),t(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof u)}var It=bf.exports,Kh={exports:{}},$c,ud;function G0(){if(ud)return $c;ud=1;var u=1e3,e=u*60,t=e*60,r=t*24,l=r*7,s=r*365.25;$c=function(p,v){v=v||{};var T=typeof p;if(T==="string"&&p.length>0)return i(p);if(T==="number"&&isFinite(p))return v.long?h(p):f(p);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(p))};function i(p){if(p=String(p),!(p.length>100)){var v=/^(-?(?:\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(v){var T=parseFloat(v[1]),y=(v[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return T*s;case"weeks":case"week":case"w":return T*l;case"days":case"day":case"d":return T*r;case"hours":case"hour":case"hrs":case"hr":case"h":return T*t;case"minutes":case"minute":case"mins":case"min":case"m":return T*e;case"seconds":case"second":case"secs":case"sec":case"s":return T*u;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return T;default:return}}}}function f(p){var v=Math.abs(p);return v>=r?Math.round(p/r)+"d":v>=t?Math.round(p/t)+"h":v>=e?Math.round(p/e)+"m":v>=u?Math.round(p/u)+"s":p+"ms"}function h(p){var v=Math.abs(p);return v>=r?d(p,v,r,"day"):v>=t?d(p,v,t,"hour"):v>=e?d(p,v,e,"minute"):v>=u?d(p,v,u,"second"):p+" ms"}function d(p,v,T,y){var S=v>=T*1.5;return Math.round(p/T)+" "+y+(S?"s":"")}return $c}function V0(u){t.debug=t,t.default=t,t.coerce=h,t.disable=s,t.enable=l,t.enabled=i,t.humanize=G0(),t.destroy=d,Object.keys(u).forEach(p=>{t[p]=u[p]}),t.names=[],t.skips=[],t.formatters={};function e(p){let v=0;for(let T=0;T<p.length;T++)v=(v<<5)-v+p.charCodeAt(T),v|=0;return t.colors[Math.abs(v)%t.colors.length]}t.selectColor=e;function t(p){let v,T=null,y,S;function A(...R){if(!A.enabled)return;const O=A,N=Number(new Date),C=N-(v||N);O.diff=C,O.prev=v,O.curr=N,v=N,R[0]=t.coerce(R[0]),typeof R[0]!="string"&&R.unshift("%O");let b=0;R[0]=R[0].replace(/%([a-zA-Z%])/g,(F,q)=>{if(F==="%%")return"%";b++;const D=t.formatters[q];if(typeof D=="function"){const P=R[b];F=D.call(O,P),R.splice(b,1),b--}return F}),t.formatArgs.call(O,R),(O.log||t.log).apply(O,R)}return A.namespace=p,A.useColors=t.useColors(),A.color=t.selectColor(p),A.extend=r,A.destroy=t.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>T!==null?T:(y!==t.namespaces&&(y=t.namespaces,S=t.enabled(p)),S),set:R=>{T=R}}),typeof t.init=="function"&&t.init(A),A}function r(p,v){const T=t(this.namespace+(typeof v>"u"?":":v)+p);return T.log=this.log,T}function l(p){t.save(p),t.namespaces=p,t.names=[],t.skips=[];let v;const T=(typeof p=="string"?p:"").split(/[\s,]+/),y=T.length;for(v=0;v<y;v++)T[v]&&(p=T[v].replace(/\*/g,".*?"),p[0]==="-"?t.skips.push(new RegExp("^"+p.slice(1)+"$")):t.names.push(new RegExp("^"+p+"$")))}function s(){const p=[...t.names.map(f),...t.skips.map(f).map(v=>"-"+v)].join(",");return t.enable(""),p}function i(p){if(p[p.length-1]==="*")return!0;let v,T;for(v=0,T=t.skips.length;v<T;v++)if(t.skips[v].test(p))return!1;for(v=0,T=t.names.length;v<T;v++)if(t.names[v].test(p))return!0;return!1}function f(p){return p.toString().substring(2,p.toString().length-2).replace(/\.\*\?$/,"*")}function h(p){return p instanceof Error?p.stack||p.message:p}function d(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}var B0=V0;(function(u,e){e.formatArgs=r,e.save=l,e.load=s,e.useColors=t,e.storage=i(),e.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.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 t(){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 r(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+u.exports.humanize(this.diff),!this.useColors)return;const d="color: "+this.color;h.splice(1,0,d,"color: inherit");let p=0,v=0;h[0].replace(/%[a-zA-Z%]/g,T=>{T!=="%%"&&(p++,T==="%c"&&(v=p))}),h.splice(v,0,d)}e.log=console.debug||console.log||(()=>{});function l(h){try{h?e.storage.setItem("debug",h):e.storage.removeItem("debug")}catch{}}function s(){let h;try{h=e.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function i(){try{return localStorage}catch{}}u.exports=B0(e);const{formatters:f}=u.exports;f.j=function(h){try{return JSON.stringify(h)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}})(Kh,Kh.exports);var yr=Kh.exports;function j0(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function cd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function q0(u,e,t){return e&&cd(u.prototype,e),t&&cd(u,t),u}var sr=yr,nr="JsSIP",Ot=function(){function u(e){j0(this,u),e?(this._debug=sr.default("".concat(nr,":").concat(e)),this._warn=sr.default("".concat(nr,":WARN:").concat(e)),this._error=sr.default("".concat(nr,":ERROR:").concat(e))):(this._debug=sr.default(nr),this._warn=sr.default("".concat(nr,":WARN")),this._error=sr.default("".concat(nr,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return q0(u,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),u}(),Qt={},Bg={},jg={exports:{}},hd=jg.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(u){return u.encoding?"rtpmap:%d %s/%s/%s":u.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(u){return u.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(u){return u.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(u){return"extmap:%d"+(u.direction?"/%s":"%v")+(u["encrypt-uri"]?" %s":"%v")+" %s"+(u.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(u){return u.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(u){var e="candidate:%s %d %s %d %s %d typ %s";return e+=u.raddr!=null?" raddr %s rport %d":"%v%v",e+=u.tcptype!=null?" tcptype %s":"%v",u.generation!=null&&(e+=" generation %d"),e+=u["network-id"]!=null?" network-id %d":"%v",e+=u["network-cost"]!=null?" network-cost %d":"%v",e}},{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(u){var e="ssrc:%d";return u.attribute!=null&&(e+=" %s",u.value!=null&&(e+=":%s")),e}},{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(u){return u.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(u){return u.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(u){return"imageattr:%s %s %s"+(u.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(u){return"simulcast:%s %s"+(u.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(u){return"ts-refclk:%s"+(u.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(u){var e="mediaclk:";return e+=u.id!=null?"id=%s %s":"%v%s",e+=u.mediaClockValue!=null?"=%s":"",e+=u.rateNumerator!=null?" rate=%s":"",e+=u.rateDenominator!=null?"/%s":"",e}},{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(hd).forEach(function(u){var e=hd[u];e.forEach(function(t){t.reg||(t.reg=/(.*)/),t.format||(t.format="%s")})});var qg=jg.exports;(function(u){var e=function(f){return String(Number(f))===f?Number(f):f},t=function(f,h,d,p){if(p&&!d)h[p]=e(f[1]);else for(var v=0;v<d.length;v+=1)f[v+1]!=null&&(h[d[v]]=e(f[v+1]))},r=function(f,h,d){var p=f.name&&f.names;f.push&&!h[f.push]?h[f.push]=[]:p&&!h[f.name]&&(h[f.name]={});var v=f.push?{}:p?h[f.name]:h;t(d.match(f.reg),v,f.names,f.name),f.push&&h[f.push].push(v)},l=qg,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);u.parse=function(f){var h={},d=[],p=h;return f.split(/(\r\n|\r|\n)/).filter(s).forEach(function(v){var T=v[0],y=v.slice(2);T==="m"&&(d.push({rtp:[],fmtp:[]}),p=d[d.length-1]);for(var S=0;S<(l[T]||[]).length;S+=1){var A=l[T][S];if(A.reg.test(y))return r(A,p,y)}}),h.media=d,h};var i=function(f,h){var d=h.split(/=(.+)/,2);return d.length===2?f[d[0]]=e(d[1]):d.length===1&&h.length>1&&(f[d[0]]=void 0),f};u.parseParams=function(f){return f.split(/;\s?/).reduce(i,{})},u.parseFmtpConfig=u.parseParams,u.parsePayloads=function(f){return f.toString().split(" ").map(Number)},u.parseRemoteCandidates=function(f){for(var h=[],d=f.split(" ").map(e),p=0;p<d.length;p+=3)h.push({component:d[p],ip:d[p+1],port:d[p+2]});return h},u.parseImageAttributes=function(f){return f.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(i,{})})},u.parseSimulcastStreamList=function(f){return f.split(";").map(function(h){return h.split(",").map(function(d){var p,v=!1;return d[0]!=="~"?p=e(d):(p=e(d.substring(1,d.length)),v=!0),{scid:p,paused:v}})})}})(Bg);var Hc=qg,W0=/%[sdv%]/g,K0=function(u){var e=1,t=arguments,r=t.length;return u.replace(W0,function(l){if(e>=r)return l;var s=t[e];switch(e+=1,l){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Hl=function(u,e,t){var r=e.format instanceof Function?e.format(e.push?t:t[e.name]):e.format,l=[u+"="+r];if(e.names)for(var s=0;s<e.names.length;s+=1){var i=e.names[s];e.name?l.push(t[e.name][i]):l.push(t[e.names[s]])}else l.push(t[e.name]);return K0.apply(null,l)},Y0=["v","o","s","i","u","e","p","c","b","t","r","z","a"],z0=["i","c","b","a"],X0=function(u,e){e=e||{},u.version==null&&(u.version=0),u.name==null&&(u.name=" "),u.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var t=e.outerOrder||Y0,r=e.innerOrder||z0,l=[];return t.forEach(function(s){Hc[s].forEach(function(i){i.name in u&&u[i.name]!=null?l.push(Hl(s,i,u)):i.push in u&&u[i.push]!=null&&u[i.push].forEach(function(f){l.push(Hl(s,i,f))})})}),u.media.forEach(function(s){l.push(Hl("m",Hc.m[0],s)),r.forEach(function(i){Hc[i].forEach(function(f){f.name in s&&s[f.name]!=null?l.push(Hl(i,f,s)):f.push in s&&s[f.push]!=null&&s[f.push].forEach(function(h){l.push(Hl(i,f,h))})})})}),l.join(`\r
1
+ "use strict";var Hh=Object.defineProperty;var Fh=(c,t,n)=>t in c?Hh(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var Kt=(c,t,n)=>(Fh(c,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var jh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ze(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const qh="jssip",Vh="JsSIP",Bh="the Javascript SIP library",Gh="3.10.0",Wh="https://jssip.net",Kh=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],Yh="lib/JsSIP.d.ts",Jh="lib-es5/JsSIP.js",zh=["sip","websocket","webrtc","node","browser","library"],Xh="MIT",Qh={type:"git",url:"https://github.com/versatica/JsSIP.git"},Zh={url:"https://github.com/versatica/JsSIP/issues"},ed={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},td={"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},sd={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Ha={name:qh,title:Vh,description:Bh,version:Gh,homepage:Wh,contributors:Kh,types:Yh,main:Jh,keywords:zh,license:Xh,repository:Qh,bugs:Zh,dependencies:ed,devDependencies:td,scripts:sd};var Gu=Ha,lt={USER_AGENT:"".concat(Gu.title," ").concat(Gu.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};function pa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?pa=function(n){return typeof n}:pa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},pa(c)}function Fa(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ja(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Zi(c,t)}function qa(c){var t=qf();return function(){var a=el(c),o;if(t){var s=el(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return nd(this,o)}}function nd(c,t){return t&&(pa(t)==="object"||typeof t=="function")?t:rd(c)}function rd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mr(c){var t=typeof Map=="function"?new Map:void 0;return mr=function(a){if(a===null||!id(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(a))return t.get(a);t.set(a,o)}function o(){return ma(a,arguments,el(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),Zi(o,a)},mr(c)}function ma(c,t,n){return qf()?ma=Reflect.construct:ma=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&Zi(_,r.prototype),_},ma.apply(null,arguments)}function qf(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function id(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function Zi(c,t){return Zi=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Zi(c,t)}function el(c){return el=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},el(c)}var ld=function(c){ja(n,c);var t=qa(n);function n(a,o){var s;return Fa(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=a,s.value=o,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(mr(Error)),ad=function(c){ja(n,c);var t=qa(n);function n(a){var o;return Fa(this,n),o=t.call(this),o.code=2,o.name="INVALID_STATE_ERROR",o.status=a,o.message="Invalid status: ".concat(a),o}return n}(mr(Error)),od=function(c){ja(n,c);var t=qa(n);function n(a){var o;return Fa(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(mr(Error)),ud=function(c){ja(n,c);var t=qa(n);function n(a){var o;return Fa(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(mr(Error)),Ws={ConfigurationError:ld,InvalidStateError:ad,NotSupportedError:od,NotReadyError:ud},Ze={},co,Wu;function Ou(){if(Wu)return co;Wu=1;function c(s,r){if(!(s instanceof r))throw new TypeError("Cannot call a class as a function")}function t(s,r){for(var d=0;d<r.length;d++){var h=r[d];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,d){return r&&t(s.prototype,r),d&&t(s,d),s}var a=Ks(),o=os();return co=function(){n(s,null,[{key:"parse",value:function(d){if(d=o.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function s(r,d,h){if(c(this,s),!r||!(r instanceof a))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=d;for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.setParam(_,h[_])}return n(s,[{key:"setParam",value:function(d,h){d&&(this._parameters[d.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var h=this._parameters[d];return delete this._parameters[d],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(d+=";".concat(h),this._parameters[h]!==null&&(d+="=".concat(this._parameters[h])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),s}(),co}var fo,Ku;function os(){return Ku||(Ku=1,fo=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(a,o){var s={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:A,OCTET:C,DQUOTE:I,SP:H,HTAB:$,alphanum:oe,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:k,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:X,LHEX:U,token:P,token_nodot:se,separators:st,word:ee,STAR:W,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:xe,LAQUOT:Ce,COMMA:le,SEMI:ye,COLON:nt,LDQUOT:at,RDQUOT:Ee,comment:Ae,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:ue,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:Qe,uri_scheme_sips:Le,uri_scheme_sip:Lt,userinfo:dt,user:wn,user_unreserved:On,password:Ys,hostport:es,host:us,hostname:Js,domainlabel:Dn,toplabel:Nn,IPv6reference:zs,IPv6address:me,h16:ae,ls32:ot,IPv4address:Wt,dec_octet:Cs,port:Er,uri_parameters:Un,uri_parameter:Pn,transport_param:Sr,user_param:yr,method_param:Ar,ttl_param:Cr,maddr_param:Rr,lr_param:Ir,other_param:br,pname:wr,pvalue:Rs,paramchar:Is,param_unreserved:Or,headers:Xs,header:Qs,hname:Dr,hvalue:bs,hnv_unreserved:Zs,Request_Response:gl,Request_Line:Nr,Request_URI:xn,absoluteURI:kn,hier_part:Ur,net_path:en,abs_path:tn,opaque_part:ws,uric:Os,uric_no_slash:Pr,path_segments:sn,segment:Ds,param:cs,pchar:Ns,scheme:xr,authority:kr,srvr:Mr,reg_name:Lr,query:Mn,SIP_Version:Ln,INVITEm:$r,ACKm:Hr,OPTIONSm:Fr,BYEm:jr,CANCELm:qr,REGISTERm:Vr,SUBSCRIBEm:Br,NOTIFYm:Gr,REFERm:nn,Method:rn,Status_Line:Wr,Status_Code:Kr,extension_code:Yr,Reason_Phrase:Tl,Allow_Events:Ya,Call_ID:Ja,Contact:$n,contact_param:$t,name_addr:Ht,display_name:Us,contact_params:Hn,c_p_q:Jr,c_p_expires:ts,delta_seconds:ss,qvalue:Ge,generic_param:We,gen_value:vl,Content_Disposition:El,disp_type:Fn,disp_param:jn,handling_param:Sl,Content_Encoding:za,Content_Length:Xa,Content_Type:yl,media_type:zr,m_type:Xr,discrete_type:Qr,composite_type:ln,extension_token:an,x_token:Zr,m_subtype:qn,m_parameter:Vn,m_value:Al,CSeq:Cl,CSeq_value:Rl,Expires:Qa,Event:on,event_type:un,From:ei,from_param:cn,tag_param:ti,Max_Forwards:Za,Min_Expires:eo,Name_Addr_Header:to,Proxy_Authenticate:si,challenge:Bn,other_challenge:Ps,auth_param:ns,digest_cln:fn,realm:ni,realm_value:ri,domain:hn,URI:dn,nonce:ii,nonce_value:li,opaque:ai,stale:oi,algorithm:ui,qop_options:_n,qop_value:Gn,Proxy_Require:so,Record_Route:Wn,rec_route:Kn,Reason:ci,reason_param:Yn,reason_cause:Il,Require:no,Route:Jn,route_param:zn,Subscription_State:bl,substate_value:Xn,subexp_params:Qn,event_reason_value:wl,Subject:ro,Supported:io,To:fi,to_param:hi,Via:Zn,via_param:xs,via_params:er,via_ttl:di,via_maddr:_i,via_received:pi,via_branch:mi,response_port:gi,rport:Ti,sent_protocol:vi,protocol_name:Ei,transport:Si,sent_by:yi,via_host:Ai,via_port:tr,ttl:Ci,WWW_Authenticate:lo,Session_Expires:Ol,s_e_expires:sr,s_e_params:nr,s_e_refresher:Dl,extension_header:Nl,header_value:Ul,message_body:ao,uuid_URI:Pl,uuid:Ft,hex4:jt,hex8:Ri,hex12:xl,Refer_To:oo,Replaces:kl,call_id:rr,replaces_param:ir,to_tag:Ii,from_tag:bi,early_flag:Ml};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,d=0,h=[];function _(e){r<d||(r>d&&(d=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
2
+ `?(e=`\r
3
+ `,r+=2):(e=null,_('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9a-fA-F]")),e}function A(){var e;return e=H(),e===null&&(e=$()),e}function C(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_('["]')),e}function H(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,_('" "')),e}function $(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,_('"\\t"')),e}function oe(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","'))))))))))),e}function j(){var e;return e=oe(),e===null&&(e=Se()),e}function Se(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,_('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,_('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,_('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,_('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,_('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,_(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,_('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(r=f),e}function k(){var e,l,u,f,p,m;for(f=r,p=r,m=r,e=[],l=A();l!==null;)e.push(l),l=A();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,r=m)):(e=null,r=m),e=e!==null?e:"",e!==null){if(u=A(),u!==null)for(l=[];u!==null;)l.push(u),u=A();else l=null;l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(v){return" "}()),e===null&&(r=f),e}function D(){var e;return e=k(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=H(),l===null&&(l=$());l!==null;)e.push(l),l=H(),l===null&&(l=$());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function V(){var e,l,u,f,p,m,v;if(p=r,m=r,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=r,u=[],f=k();f!==null;)u.push(f),f=k();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=k();f!==null;)u.push(f),f=k();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v)}l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){return a.substring(r,S)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\uFFFF]")),e}function X(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-f]"))),e}function P(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function se(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function st(){var e;return a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,_('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e===null&&(e=I(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,_('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,_('"}"')),e===null&&(e=H(),e===null&&(e=$())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function W(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"*"}()),e===null&&(r=f),e}function G(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"/"}()),e===null&&(r=f),e}function re(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"="}()),e===null&&(r=f),e}function ge(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"("}()),e===null&&(r=f),e}function be(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function xe(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return">"}()),e===null&&(r=u),e}function Ce(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return"<"}()),e===null&&(r=u),e}function le(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return","}()),e===null&&(r=f),e}function ye(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return";"}()),e===null&&(r=f),e}function nt(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function at(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ee(){var e,l,u,f;return u=r,f=r,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ae(){var e,l,u,f;if(f=r,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));u!==null;)l.push(u),u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function Ie(){var e;return/^[!-']/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F(),e===null&&(e=k())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){return a.substring(r,v)}(p)),e===null&&(r=p),e}function pe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){var S=a.substring(r,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function ue(){var e;return e=k(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function we(){var e,l,u,f,p,m;return p=r,m=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e!==null&&(e=function(v){try{w.uri=new fs(w.scheme,w.user,w.host,w.port),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port}catch{w=-1}}()),e===null&&(r=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=r,S=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?(p=Un(),p!==null?(m=Xs(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S),e!==null&&(e=function(O){try{w.uri=new fs(w.scheme,w.user,w.host,w.port,w.uri_params,w.uri_headers),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port,delete w.uri_params,o==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function Qe(){var e;return e=Le(),e===null&&(e=Lt()),e}function Le(){var e,l;return l=r,a.substr(r,4).toLowerCase()==="sips"?(e=a.substr(r,4),r+=4):(e=null,_('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Lt(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function dt(){var e,l,u,f,p,m;return f=r,p=r,e=wn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ys(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(a.charCodeAt(r)===64?(u="@",r++):(u=null,_('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function wn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=On())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=On()));else e=null;return e}function On(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"'))))))))),e}function Ys(){var e,l,u;for(u=r,e=[],l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));return e!==null&&(e=function(f){w.password=a.substring(r,f)}(u)),e===null&&(r=u),e}function es(){var e,l,u,f,p;return f=r,e=us(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function us(){var e,l;return l=r,e=Js(),e===null&&(e=Wt(),e===null&&(e=zs())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function Js(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Nn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){return w.host_type="domain",a.substring(r,v)}(f)),e===null&&(r=f),e}function Dn(){var e,l,u,f;if(f=r,e=oe(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Nn(){var e,l,u,f;if(f=r,e=E(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function zs(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,_('"]"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R,Te;return M=r,R=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ae(),Ue!==null?(a.charCodeAt(r)===58?(wt=":",r++):(wt=null,_('":"')),wt!==null?(ks=ot(),ks!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ae(),ie!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,_('":"')),Ue!==null?(wt=ot(),wt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ot(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ot(),f!==null?e=[e,l,u,f]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ot(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,_('"::"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ot(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(a.substr(r,2)==="::"?(u="::",r+=2):(u=null,_('"::"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(a.substr(r,2)==="::"?(f="::",r+=2):(f=null,_('"::"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ot(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(a.substr(r,2)==="::"?(p="::",r+=2):(p=null,_('"::"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(a.substr(r,2)==="::"?(m="::",r+=2):(m=null,_('"::"')),m!==null?(v=ot(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(a.substr(r,2)==="::"?(v="::",r+=2):(v=null,_('"::"')),v!==null?(S=ae(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(Te=r,a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?v=[v,S]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(S="::",r+=2):(S=null,_('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R))))))))))))))),e!==null&&(e=function($h){return w.host_type="IPv6",a.substring(r,$h)}(M)),e===null&&(r=M),e}function ae(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l=l!==null?l:"",l!==null?(u=y(),u=u!==null?u:"",u!==null?(f=y(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function ot(){var e,l,u,f;return f=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(e=Wt()),e}function Wt(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=Cs(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=Cs(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=Cs(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=Cs(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O),e!==null&&(e=function(ie){return w.host_type="IPv4",a.substring(r,ie)}(S)),e===null&&(r=S),e}function Cs(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,_('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===50?(e="2",r++):(e=null,_('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===49?(e="1",r++):(e=null,_('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,/^[1-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(e=T())))),e}function Er(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Un(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Pn(){var e;return e=Sr(),e===null&&(e=yr(),e===null&&(e=Ar(),e===null&&(e=Cr(),e===null&&(e=Rr(),e===null&&(e=Ir(),e===null&&(e=br())))))),e}function Sr(){var e,l,u,f;return u=r,f=r,a.substr(r,10).toLowerCase()==="transport="?(e=a.substr(r,10),r+=10):(e=null,_('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,_('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,_('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,_('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,_('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function yr(){var e,l,u,f;return u=r,f=r,a.substr(r,5).toLowerCase()==="user="?(e=a.substr(r,5),r+=5):(e=null,_('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,_('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,_('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function Ar(){var e,l,u,f;return u=r,f=r,a.substr(r,7).toLowerCase()==="method="?(e=a.substr(r,7),r+=7):(e=null,_('"method="')),e!==null?(l=rn(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(r=u),e}function Cr(){var e,l,u,f;return u=r,f=r,a.substr(r,4).toLowerCase()==="ttl="?(e=a.substr(r,4),r+=4):(e=null,_('"ttl="')),e!==null?(l=Ci(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(r=u),e}function Rr(){var e,l,u,f;return u=r,f=r,a.substr(r,6).toLowerCase()==="maddr="?(e=a.substr(r,6),r+=6):(e=null,_('"maddr="')),e!==null?(l=us(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(r=u),e}function Ir(){var e,l,u,f,p,m;return f=r,p=r,a.substr(r,2).toLowerCase()==="lr"?(e=a.substr(r,2),r+=2):(e=null,_('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(r=f),e}function br(){var e,l,u,f,p,m;return f=r,p=r,e=wr(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Rs(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function wr(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Rs(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Is(){var e;return e=Or(),e===null&&(e=j(),e===null&&(e=ve())),e}function Or(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function Xs(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=Qs(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e}function Qs(){var e,l,u,f,p;return f=r,p=r,e=Dr(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=bs(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,S){v=v.join("").toLowerCase(),S=S.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(S):w.uri_headers[v]=[S]}(f,e[0],e[2])),e===null&&(r=f),e}function Dr(){var e,l;if(l=Zs(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function bs(){var e,l;for(e=[],l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));return e}function Zs(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function gl(){var e;return e=Wr(),e===null&&(e=Nr()),e}function Nr(){var e,l,u,f,p,m;return m=r,e=rn(),e!==null?(l=H(),l!==null?(u=xn(),u!==null?(f=H(),f!==null?(p=Ln(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function xn(){var e;return e=Ne(),e===null&&(e=kn()),e}function kn(){var e,l,u,f;return f=r,e=xr(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ur(),u===null&&(u=ws()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ur(){var e,l,u,f,p;return f=r,e=en(),e===null&&(e=tn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Mn(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function en(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=kr(),l!==null?(u=tn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function tn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=sn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function ws(){var e,l,u,f;if(f=r,e=Pr(),e!==null){for(l=[],u=Os();u!==null;)l.push(u),u=Os();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Os(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function Pr(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))))),e}function sn(){var e,l,u,f,p,m;if(p=r,e=Ds(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ds(){var e,l,u,f,p,m;for(p=r,e=[],l=Ns();l!==null;)e.push(l),l=Ns();if(e!==null){for(l=[],m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function cs(){var e,l;for(e=[],l=Ns();l!==null;)e.push(l),l=Ns();return e}function Ns(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))),e}function xr(){var e,l,u,f,p;if(f=r,p=r,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=a.substring(r,m)}(f)),e===null&&(r=f),e}function kr(){var e;return e=Mr(),e===null&&(e=Lr()),e}function Mr(){var e,l,u,f;return u=r,f=r,e=dt(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e=e!==null?e:"",e!==null?(l=es(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Lr(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')))))))))));else e=null;return e}function Mn(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Ln(){var e,l,u,f,p,m,v,S;if(v=r,S=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=S)}else e=null,r=S;else e=null,r=S}else e=null,r=S;else e=null,r=S;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function $r(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function Hr(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Fr(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function jr(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function qr(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Vr(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Br(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function Gr(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function nn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function rn(){var e,l;return l=r,e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=Vr(),e===null&&(e=Br(),e===null&&(e=Gr(),e===null&&(e=nn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function Wr(){var e,l,u,f,p,m;return m=r,e=Ln(),e!==null?(l=H(),l!==null?(u=Kr(),u!==null?(f=H(),f!==null?(p=Tl(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Kr(){var e,l;return l=r,e=Yr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Yr(){var e,l,u,f;return f=r,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Tl(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Ya(){var e,l,u,f,p,m;if(p=r,e=un(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ja(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w=a.substring(r,v)}(f)),e===null&&(r=f),e}function $n(){var e,l,u,f,p,m,v;if(p=r,e=W(),e===null)if(m=r,e=$t(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function $t(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Ht(){var e,l,u,f,p;return p=r,e=Us(),e=e!==null?e:"",e!==null?(l=Ce(),l!==null?(u=Ne(),u!==null?(f=xe(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Us(){var e,l,u,f,p,m,v;if(p=r,m=r,e=P(),e!==null){for(l=[],v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e===null&&(e=pe()),e!==null&&(e=function(S,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(ie,Ue){return ie+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function Hn(){var e;return e=Jr(),e===null&&(e=ts(),e===null&&(e=We())),e}function Jr(){var e,l,u,f,p;return f=r,p=r,a.substr(r,1).toLowerCase()==="q"?(e=a.substr(r,1),r++):(e=null,_('"q"')),e!==null?(l=re(),l!==null?(u=Ge(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(r=f),e}function ts(){var e,l,u,f,p;return f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(r=f),e}function ss(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){return parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Ge(){var e,l,u,f,p,m,v,S;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,_('"0"')),e!==null?(S=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=S)):(l=null,r=S)):(l=null,r=S)):(l=null,r=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(a.substring(r,O))}(m)),e===null&&(r=m),e}function We(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=vl(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function vl(){var e;return e=P(),e===null&&(e=us(),e===null&&(e=Oe())),e}function El(){var e,l,u,f,p,m;if(p=r,e=Fn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Fn(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,_('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,_('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,_('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,_('"alert"')),e===null&&(e=P())))),e}function jn(){var e;return e=Sl(),e===null&&(e=We()),e}function Sl(){var e,l,u,f;return f=r,a.substr(r,8).toLowerCase()==="handling"?(e=a.substr(r,8),r+=8):(e=null,_('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,_('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,_('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function za(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Xa(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function yl(){var e,l;return l=r,e=zr(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function zr(){var e,l,u,f,p,m,v,S;if(v=r,e=Xr(),e!==null)if(l=G(),l!==null)if(u=qn(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function Xr(){var e;return e=Qr(),e===null&&(e=ln()),e}function Qr(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,_('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,_('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,_('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,_('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,_('"application"')),e===null&&(e=an()))))),e}function ln(){var e;return a.substr(r,7).toLowerCase()==="message"?(e=a.substr(r,7),r+=7):(e=null,_('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,_('"multipart"')),e===null&&(e=an())),e}function an(){var e;return e=P(),e===null&&(e=Zr()),e}function Zr(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,_('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qn(){var e;return e=an(),e===null&&(e=P()),e}function Vn(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=Al(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Al(){var e;return e=P(),e===null&&(e=Oe()),e}function Cl(){var e,l,u,f;return f=r,e=Rl(),e!==null?(l=k(),l!==null?(u=rn(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Rl(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w.value=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Qa(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function on(){var e,l,u,f,p,m,v;if(p=r,m=r,e=un(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(r=p),e}function un(){var e,l,u,f,p,m;if(p=r,e=se(),e!==null){for(l=[],m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function ei(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function cn(){var e;return e=ti(),e===null&&(e=We()),e}function ti(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="tag"?(e=a.substr(r,3),r+=3):(e=null,_('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(r=f),e}function Za(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function eo(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function to(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Us();l!==null;)e.push(l),l=Us();if(e!==null)if(l=Ce(),l!==null)if(u=Ne(),u!==null)if(f=xe(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?e=[e,l,u,f,p]:(e=null,r=O)}else e=null,r=O;else e=null,r=O;else e=null,r=O;else e=null,r=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=S),e}function si(){var e;return e=Bn(),e}function Bn(){var e,l,u,f,p,m,v,S;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,_('"Digest"')),e!==null)if(l=k(),l!==null)if(u=fn(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e===null&&(e=Ps()),e}function Ps(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=ns(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function ns(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function fn(){var e;return e=ni(),e===null&&(e=hn(),e===null&&(e=ii(),e===null&&(e=ai(),e===null&&(e=oi(),e===null&&(e=ui(),e===null&&(e=_n(),e===null&&(e=ns()))))))),e}function ni(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,_('"realm"')),e!==null?(l=re(),l!==null?(u=ri(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ri(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function hn(){var e,l,u,f,p,m,v,S,O;if(S=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,_('"domain"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null)if(f=dn(),f!==null){if(p=[],O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function dn(){var e;return e=kn(),e===null&&(e=tn()),e}function ii(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,_('"nonce"')),e!==null?(l=re(),l!==null?(u=li(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function li(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function ai(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="opaque"?(e=a.substr(r,6),r+=6):(e=null,_('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(r=f),e}function oi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,_('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,_('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,a.substr(r,5).toLowerCase()==="false"?(u=a.substr(r,5),r+=5):(u=null,_('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(r=p)),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ui(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="algorithm"?(e=a.substr(r,9),r+=9):(e=null,_('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,_('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,_('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function _n(){var e,l,u,f,p,m,v,S,O,ie;if(S=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,_('"qop"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null){if(O=r,f=Gn(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function Gn(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,_('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,_('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function so(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Wn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Kn(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function Kn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Ht(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function ci(){var e,l,u,f,p,m,v;if(p=r,m=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ie=w.params.text;w.text=ie.substring(1,ie.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function Yn(){var e;return e=Il(),e===null&&(e=We()),e}function Il(){var e,l,u,f,p,m;if(p=r,m=r,a.substr(r,5).toLowerCase()==="cause"?(e=a.substr(r,5),r+=5):(e=null,_('"cause"')),e!==null)if(l=re(),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(r=p),e}function no(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Jn(){var e,l,u,f,p,m;if(p=r,e=zn(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function zn(){var e,l,u,f,p,m;if(p=r,e=Ht(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function bl(){var e,l,u,f,p,m;if(p=r,e=Xn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Xn(){var e,l;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,_('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,_('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,_('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function Qn(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="reason"?(e=a.substr(r,6),r+=6):(e=null,_('"reason"')),e!==null?(l=re(),l!==null?(u=wl(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,11).toLowerCase()==="retry_after"?(e=a.substr(r,11),r+=11):(e=null,_('"retry_after"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(r=f),e===null&&(e=We()))),e}function wl(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,_('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,_('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,_('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,_('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,_('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,_('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,_('"invariant"')),e===null&&(e=P()))))))),e}function ro(){var e;return e=V(),e=e!==null?e:"",e}function io(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e=e!==null?e:"",e}function fi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function hi(){var e;return e=ti(),e===null&&(e=We()),e}function Zn(){var e,l,u,f,p,m;if(p=r,e=xs(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function xs(){var e,l,u,f,p,m,v,S;if(v=r,e=vi(),e!==null)if(l=k(),l!==null)if(u=yi(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function er(){var e;return e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi(),e===null&&(e=gi(),e===null&&(e=We()))))),e}function di(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="ttl"?(e=a.substr(r,3),r+=3):(e=null,_('"ttl"')),e!==null?(l=re(),l!==null?(u=Ci(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(r=f),e}function _i(){var e,l,u,f,p;return f=r,p=r,a.substr(r,5).toLowerCase()==="maddr"?(e=a.substr(r,5),r+=5):(e=null,_('"maddr"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(r=f),e}function pi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8).toLowerCase()==="received"?(e=a.substr(r,8),r+=8):(e=null,_('"received"')),e!==null?(l=re(),l!==null?(u=Wt(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(r=f),e}function mi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="branch"?(e=a.substr(r,6),r+=6):(e=null,_('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(r=f),e}function gi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,_('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=Ti(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ti(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function vi(){var e,l,u,f,p,m;return m=r,e=Ei(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=Si(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Ei(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function Si(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="udp"?(e=a.substr(r,3),r+=3):(e=null,_('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,_('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,_('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,_('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function yi(){var e,l,u,f,p;return f=r,e=Ai(),e!==null?(p=r,l=nt(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ai(){var e,l;return l=r,e=Wt(),e===null&&(e=zs(),e===null&&(e=Js())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function tr(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function Ci(){var e,l,u,f,p;return f=r,p=r,e=T(),e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(r=f),e}function lo(){var e;return e=Bn(),e}function Ol(){var e,l,u,f,p,m;if(p=r,e=sr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function sr(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function nr(){var e;return e=Dl(),e===null&&(e=We()),e}function Dl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="refresher"?(e=a.substr(r,9),r+=9):(e=null,_('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,_('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,_('"uas"'))),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(r=f),e}function Nl(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Ul(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ul(){var e,l;for(e=[],l=J(),l===null&&(l=X(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=X(),l===null&&(l=k()));return e}function ao(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Pl(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Ft(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ft(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=Ri(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=jt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=jt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=jt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=xl(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue),e!==null&&(e=function(wt,ks){w=a.substring(r+5,wt)}(ie,e[0])),e===null&&(r=ie),e}function jt(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ri(){var e,l,u;return u=r,e=jt(),e!==null?(l=jt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function xl(){var e,l,u,f;return f=r,e=jt(),e!==null?(l=jt(),l!==null?(u=jt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function oo(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function kl(){var e,l,u,f,p,m;if(p=r,e=rr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function rr(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.call_id=a.substring(r,v)}(f)),e===null&&(r=f),e}function ir(){var e;return e=Ii(),e===null&&(e=bi(),e===null&&(e=Ml(),e===null&&(e=We()))),e}function Ii(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,_('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(r=f),e}function bi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,_('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Ml(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,_('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function uo(e){e.sort();for(var l=null,u=[],f=0;f<e.length;f++)e[f]!==l&&(u.push(e[f]),l=e[f]);return u}function Ll(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,d);f++){var p=a.charAt(f);p===`
4
+ `?(u||e++,l=1,u=!1):p==="\r"||p==="\u2028"||p==="\u2029"?(e++,l=1,u=!0):(l++,u=!1)}return{line:e,column:l}}var fs=Ks(),b=Ou(),w={},wi=s[o]();if(wi===null||r!==a.length){var Oi=Math.max(r,d),$l=Oi<a.length?a.charAt(Oi):null,i=Ll();return new this.SyntaxError(uo(h),$l,Oi,i.line,i.column),-1}return w},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),fo}var ho,Yu;function Ks(){if(Yu)return ho;Yu=1;function c(_,g){var T;if(typeof Symbol>"u"||_[Symbol.iterator]==null){if(Array.isArray(_)||(T=t(_))||g&&_&&typeof _.length=="number"){T&&(_=T);var E=0,y=function(){};return{s:y,n:function(){return E>=_.length?{done:!0}:{done:!1,value:_[E++]}},e:function($){throw $},f:y}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,C=!1,I;return{s:function(){T=_[Symbol.iterator]()},n:function(){var $=T.next();return A=$.done,$},e:function($){C=!0,I=$},f:function(){try{!A&&T.return!=null&&T.return()}finally{if(C)throw I}}}}function t(_,g){if(_){if(typeof _=="string")return n(_,g);var T=Object.prototype.toString.call(_).slice(8,-1);if(T==="Object"&&_.constructor&&(T=_.constructor.name),T==="Map"||T==="Set")return Array.from(_);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return n(_,g)}}function n(_,g){(g==null||g>_.length)&&(g=_.length);for(var T=0,E=new Array(g);T<g;T++)E[T]=_[T];return E}function a(_,g){if(!(_ instanceof g))throw new TypeError("Cannot call a class as a function")}function o(_,g){for(var T=0;T<g.length;T++){var E=g[T];E.enumerable=E.enumerable||!1,E.configurable=!0,"value"in E&&(E.writable=!0),Object.defineProperty(_,E.key,E)}}function s(_,g,T){return g&&o(_.prototype,g),T&&o(_,T),_}var r=lt,d=bt(),h=os();return ho=function(){s(_,null,[{key:"parse",value:function(T){if(T=h.parse(T,"SIP_URI"),T!==-1)return T}}]);function _(g,T,E,y){var A=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},C=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(a(this,_),!E)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=g||r.SIP,this._user=T,this._host=E,this._port=y;for(var I in A)Object.prototype.hasOwnProperty.call(A,I)&&this.setParam(I,A[I]);for(var H in C)Object.prototype.hasOwnProperty.call(C,H)&&this.setHeader(H,C[H])}return s(_,[{key:"setParam",value:function(T,E){T&&(this._parameters[T.toLowerCase()]=typeof E>"u"||E===null?null:E.toString())}},{key:"getParam",value:function(T){if(T)return this._parameters[T.toLowerCase()]}},{key:"hasParam",value:function(T){if(T)return this._parameters.hasOwnProperty(T.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(T){if(T=T.toLowerCase(),this._parameters.hasOwnProperty(T)){var E=this._parameters[T];return delete this._parameters[T],E}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(T,E){this._headers[d.headerize(T)]=Array.isArray(E)?E:[E]}},{key:"getHeader",value:function(T){if(T)return this._headers[d.headerize(T)]}},{key:"hasHeader",value:function(T){if(T)return this._headers.hasOwnProperty(d.headerize(T))&&!0||!1}},{key:"deleteHeader",value:function(T){if(T=d.headerize(T),this._headers.hasOwnProperty(T)){var E=this._headers[T];return delete this._headers[T],E}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new _(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var T=[],E="".concat(this._scheme,":");this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,(this._port||this._port===0)&&(E+=":".concat(this._port));for(var y in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,y)&&(E+=";".concat(y),this._parameters[y]!==null&&(E+="=".concat(this._parameters[y])));for(var A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var C=c(this._headers[A]),I;try{for(C.s();!(I=C.n()).done;){var H=I.value;T.push("".concat(A,"=").concat(H))}}catch($){C.e($)}finally{C.f()}}return T.length>0&&(E+="?".concat(T.join("&"))),E}},{key:"toAor",value:function(T){var E="".concat(this._scheme,":");return this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,T&&(this._port||this._port===0)&&(E+=":".concat(this._port)),E}},{key:"scheme",get:function(){return this._scheme},set:function(T){this._scheme=T.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(T){this._user=T}},{key:"host",get:function(){return this._host},set:function(T){this._host=T.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(T){this._port=T===0?T:parseInt(T,10)||null}}]),_}(),ho}var Ju;function bt(){if(Ju)return Ze;Ju=1;function c(g){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?c=function(E){return typeof E}:c=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},c(g)}function t(g,T){var E;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(E=n(g))||T&&g&&typeof g.length=="number"){E&&(g=E);var y=0,A=function(){};return{s:A,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(oe){throw oe},f:A}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
6
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var oe=E.next();return C=oe.done,oe},e:function(oe){I=!0,H=oe},f:function(){try{!C&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var E=Object.prototype.toString.call(g).slice(8,-1);if(E==="Object"&&g.constructor&&(E=g.constructor.name),E==="Map"||E==="Set")return Array.from(g);if(E==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(E))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var E=0,y=new Array(T);E<T;E++)y[E]=g[E];return y}var o=lt,s=Ks(),r=os();Ze.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var d=Ze.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};Ze.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},Ze.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},Ze.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},Ze.hasMethods=function(g){for(var T=arguments.length,E=new Array(T>1?T-1:0),y=1;y<T;y++)E[y-1]=arguments[y];for(var A=0,C=E;A<C.length;A++){var I=C[A];if(d(g[I]))return!1}return!0};var h=Ze.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,E,y,A="";for(E=0;E<g;E++)y=Math.random()*T|0,A+=y.toString(T);return A};Ze.newTag=function(){return h(10)},Ze.newUUID=function(){var g="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var E=Math.random()*16|0,y=T==="x"?E:E&3|8;return y.toString(16)});return g},Ze.hostType=function(g){if(g){if(g=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=Ze.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Ze.normalizeTarget=function(g,T){if(g){if(g instanceof s)return g;if(typeof g=="string"){var E=g.split("@"),y,A;switch(E.length){case 1:if(!T)return;y=g,A=T;break;case 2:y=E[0],A=E[1];break;default:y=E.slice(0,E.length-1).join("@"),A=E[E.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(_(y),"@").concat(A);var C;return(C=s.parse(g))?C:void 0}else return}else return},Ze.headerize=function(g){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},E=g.toLowerCase().replace(/_/g,"-").split("-"),y="",A=E.length,C;for(C=0;C<A;C++)C!==0&&(y+="-"),y+=E[C].charAt(0).toUpperCase()+E[C].substring(1);return T[y]&&(y=T[y]),y},Ze.sipErrorCause=function(g){for(var T in o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return o.causes[T];return o.causes.SIP_FAILURE_CODE},Ze.getRandomTestNetIP=function(){function g(T,E){return Math.floor(Math.random()*(E-T+1)+T)}return"192.0.2.".concat(g(1,254))},Ze.calculateMD5=function(g){function T(pe,ue){return pe<<ue|pe>>>32-ue}function E(pe,ue){var _e=pe&2147483648,we=ue&2147483648,Ne=pe&1073741824,Qe=ue&1073741824,Le=(pe&1073741823)+(ue&1073741823);return Ne&Qe?Le^2147483648^_e^we:Ne|Qe?Le&1073741824?Le^3221225472^_e^we:Le^1073741824^_e^we:Le^_e^we}function y(pe,ue,_e){return pe&ue|~pe&_e}function A(pe,ue,_e){return pe&_e|ue&~_e}function C(pe,ue,_e){return pe^ue^_e}function I(pe,ue,_e){return ue^(pe|~_e)}function H(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(y(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function $(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(A(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function oe(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(C(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function N(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(I(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function j(pe){for(var ue,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,Qe=(Ne+1)*16,Le=new Array(Qe-1),Lt=0,dt=0;dt<_e;)ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|pe.charCodeAt(dt)<<Lt,dt++;return ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|128<<Lt,Le[Qe-2]=_e<<3,Le[Qe-1]=_e>>>29,Le}function Se(pe){var ue="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),ue=ue+_e.substr(_e.length-2,2);return ue}function ve(pe){for(var ue="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);we<128?ue+=String.fromCharCode(we):we>127&&we<2048?(ue+=String.fromCharCode(we>>6|192),ue+=String.fromCharCode(we&63|128)):(ue+=String.fromCharCode(we>>12|224),ue+=String.fromCharCode(we>>6&63|128),ue+=String.fromCharCode(we&63|128))}return ue}var k=[],D,B,V,J,F,X,U,P,se,st=7,ee=12,W=17,G=22,re=5,ge=9,be=14,xe=20,Ce=4,le=11,ye=16,nt=23,at=6,Ee=10,Ae=15,Ie=21;for(g=ve(g),k=j(g),X=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=X,V=U,J=P,F=se,X=H(X,U,P,se,k[D+0],st,3614090360),se=H(se,X,U,P,k[D+1],ee,3905402710),P=H(P,se,X,U,k[D+2],W,606105819),U=H(U,P,se,X,k[D+3],G,3250441966),X=H(X,U,P,se,k[D+4],st,4118548399),se=H(se,X,U,P,k[D+5],ee,1200080426),P=H(P,se,X,U,k[D+6],W,2821735955),U=H(U,P,se,X,k[D+7],G,4249261313),X=H(X,U,P,se,k[D+8],st,1770035416),se=H(se,X,U,P,k[D+9],ee,2336552879),P=H(P,se,X,U,k[D+10],W,4294925233),U=H(U,P,se,X,k[D+11],G,2304563134),X=H(X,U,P,se,k[D+12],st,1804603682),se=H(se,X,U,P,k[D+13],ee,4254626195),P=H(P,se,X,U,k[D+14],W,2792965006),U=H(U,P,se,X,k[D+15],G,1236535329),X=$(X,U,P,se,k[D+1],re,4129170786),se=$(se,X,U,P,k[D+6],ge,3225465664),P=$(P,se,X,U,k[D+11],be,643717713),U=$(U,P,se,X,k[D+0],xe,3921069994),X=$(X,U,P,se,k[D+5],re,3593408605),se=$(se,X,U,P,k[D+10],ge,38016083),P=$(P,se,X,U,k[D+15],be,3634488961),U=$(U,P,se,X,k[D+4],xe,3889429448),X=$(X,U,P,se,k[D+9],re,568446438),se=$(se,X,U,P,k[D+14],ge,3275163606),P=$(P,se,X,U,k[D+3],be,4107603335),U=$(U,P,se,X,k[D+8],xe,1163531501),X=$(X,U,P,se,k[D+13],re,2850285829),se=$(se,X,U,P,k[D+2],ge,4243563512),P=$(P,se,X,U,k[D+7],be,1735328473),U=$(U,P,se,X,k[D+12],xe,2368359562),X=oe(X,U,P,se,k[D+5],Ce,4294588738),se=oe(se,X,U,P,k[D+8],le,2272392833),P=oe(P,se,X,U,k[D+11],ye,1839030562),U=oe(U,P,se,X,k[D+14],nt,4259657740),X=oe(X,U,P,se,k[D+1],Ce,2763975236),se=oe(se,X,U,P,k[D+4],le,1272893353),P=oe(P,se,X,U,k[D+7],ye,4139469664),U=oe(U,P,se,X,k[D+10],nt,3200236656),X=oe(X,U,P,se,k[D+13],Ce,681279174),se=oe(se,X,U,P,k[D+0],le,3936430074),P=oe(P,se,X,U,k[D+3],ye,3572445317),U=oe(U,P,se,X,k[D+6],nt,76029189),X=oe(X,U,P,se,k[D+9],Ce,3654602809),se=oe(se,X,U,P,k[D+12],le,3873151461),P=oe(P,se,X,U,k[D+15],ye,530742520),U=oe(U,P,se,X,k[D+2],nt,3299628645),X=N(X,U,P,se,k[D+0],at,4096336452),se=N(se,X,U,P,k[D+7],Ee,1126891415),P=N(P,se,X,U,k[D+14],Ae,2878612391),U=N(U,P,se,X,k[D+5],Ie,4237533241),X=N(X,U,P,se,k[D+12],at,1700485571),se=N(se,X,U,P,k[D+3],Ee,2399980690),P=N(P,se,X,U,k[D+10],Ae,4293915773),U=N(U,P,se,X,k[D+1],Ie,2240044497),X=N(X,U,P,se,k[D+8],at,1873313359),se=N(se,X,U,P,k[D+15],Ee,4264355552),P=N(P,se,X,U,k[D+6],Ae,2734768916),U=N(U,P,se,X,k[D+13],Ie,1309151649),X=N(X,U,P,se,k[D+4],at,4149444226),se=N(se,X,U,P,k[D+11],Ee,3174756917),P=N(P,se,X,U,k[D+2],Ae,718787259),U=N(U,P,se,X,k[D+9],Ie,3951481745),X=E(X,B),U=E(U,V),P=E(P,J),se=E(se,F);var Oe=Se(X)+Se(U)+Se(P)+Se(se);return Oe.toLowerCase()},Ze.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var E=t(T),y;try{for(E.s();!(y=E.n()).done;){var A=y.value;A.stop()}}catch(j){E.e(j)}finally{E.f()}}else{T=g.getAudioTracks();var C=t(T),I;try{for(C.s();!(I=C.n()).done;){var H=I.value;H.stop()}}catch(j){C.e(j)}finally{C.f()}T=g.getVideoTracks();var $=t(T),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;N.stop()}}catch(j){$.e(j)}finally{$.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},Ze.cloneArray=function(g){return g&&g.slice()||[]},Ze.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},Ze}var Du={exports:{}},_r=typeof Reflect=="object"?Reflect:null,zu=_r&&typeof _r.apply=="function"?_r.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},ga;_r&&typeof _r.ownKeys=="function"?ga=_r.ownKeys:Object.getOwnPropertySymbols?ga=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ga=function(t){return Object.getOwnPropertyNames(t)};function cd(c){console&&console.warn&&console.warn(c)}var Vf=Number.isNaN||function(t){return t!==t};function Me(){Me.init.call(this)}Du.exports=Me;Du.exports.once=_d;Me.EventEmitter=Me;Me.prototype._events=void 0;Me.prototype._eventsCount=0;Me.prototype._maxListeners=void 0;var Xu=10;function Va(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Me,"defaultMaxListeners",{enumerable:!0,get:function(){return Xu},set:function(c){if(typeof c!="number"||c<0||Vf(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Xu=c}});Me.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};Me.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Vf(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Bf(c){return c._maxListeners===void 0?Me.defaultMaxListeners:c._maxListeners}Me.prototype.getMaxListeners=function(){return Bf(this)};Me.prototype.emit=function(t){for(var n=[],a=1;a<arguments.length;a++)n.push(arguments[a]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var d=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw d.context=r,d}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")zu(h,this,n);else for(var _=h.length,g=Jf(h,_),a=0;a<_;++a)zu(g[a],this,n);return!0};function Gf(c,t,n,a){var o,s,r;if(Va(n),s=c._events,s===void 0?(s=c._events=Object.create(null),c._eventsCount=0):(s.newListener!==void 0&&(c.emit("newListener",t,n.listener?n.listener:n),s=c._events),r=s[t]),r===void 0)r=s[t]=n,++c._eventsCount;else if(typeof r=="function"?r=s[t]=a?[n,r]:[r,n]:a?r.unshift(n):r.push(n),o=Bf(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=t,d.count=r.length,cd(d)}return c}Me.prototype.addListener=function(t,n){return Gf(this,t,n,!1)};Me.prototype.on=Me.prototype.addListener;Me.prototype.prependListener=function(t,n){return Gf(this,t,n,!0)};function fd(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Wf(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=fd.bind(a);return o.listener=n,a.wrapFn=o,o}Me.prototype.once=function(t,n){return Va(n),this.on(t,Wf(this,t,n)),this};Me.prototype.prependOnceListener=function(t,n){return Va(n),this.prependListener(t,Wf(this,t,n)),this};Me.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Va(n),o=this._events,o===void 0)return this;if(a=o[t],a===void 0)return this;if(a===n||a.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,a.listener||n));else if(typeof a!="function"){for(s=-1,r=a.length-1;r>=0;r--)if(a[r]===n||a[r].listener===n){d=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():hd(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this};Me.prototype.off=Me.prototype.removeListener;Me.prototype.removeAllListeners=function(t){var n,a,o;if(a=this._events,a===void 0)return this;if(a.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):a[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete a[t]),this;if(arguments.length===0){var s=Object.keys(a),r;for(o=0;o<s.length;++o)r=s[o],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=a[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(o=n.length-1;o>=0;o--)this.removeListener(t,n[o]);return this};function Kf(c,t,n){var a=c._events;if(a===void 0)return[];var o=a[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?dd(o):Jf(o,o.length)}Me.prototype.listeners=function(t){return Kf(this,t,!0)};Me.prototype.rawListeners=function(t){return Kf(this,t,!1)};Me.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):Yf.call(c,t)};Me.prototype.listenerCount=Yf;function Yf(c){var t=this._events;if(t!==void 0){var n=t[c];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Me.prototype.eventNames=function(){return this._eventsCount>0?ga(this._events):[]};function Jf(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function hd(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function dd(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function _d(c,t){return new Promise(function(n,a){function o(r){c.removeListener(t,s),a(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",o),n([].slice.call(arguments))}zf(c,t,s,{once:!0}),t!=="error"&&pd(c,o,{once:!0})})}function pd(c,t,n){typeof c.on=="function"&&zf(c,"error",t,n)}function zf(c,t,n,a){if(typeof c.on=="function")a.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function o(s){a.once&&c.removeEventListener(t,o),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ft=Du.exports,uu={exports:{}},_o,Qu;function md(){if(Qu)return _o;Qu=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;_o=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return r(g);if(E==="number"&&isFinite(g))return T.long?h(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function r(g){if(g=String(g),!(g.length>100)){var T=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(T){var E=parseFloat(T[1]),y=(T[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return E*s;case"weeks":case"week":case"w":return E*o;case"days":case"day":case"d":return E*a;case"hours":case"hour":case"hrs":case"hr":case"h":return E*n;case"minutes":case"minute":case"mins":case"min":case"m":return E*t;case"seconds":case"second":case"secs":case"sec":case"s":return E*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return E;default:return}}}}function d(g){var T=Math.abs(g);return T>=a?Math.round(g/a)+"d":T>=n?Math.round(g/n)+"h":T>=t?Math.round(g/t)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function h(g){var T=Math.abs(g);return T>=a?_(g,T,a,"day"):T>=n?_(g,T,n,"hour"):T>=t?_(g,T,t,"minute"):T>=c?_(g,T,c,"second"):g+" ms"}function _(g,T,E,y){var A=T>=E*1.5;return Math.round(g/E)+" "+y+(A?"s":"")}return _o}function gd(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=md(),n.destroy=_,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,E=null,y,A;function C(...I){if(!C.enabled)return;const H=C,$=Number(new Date),oe=$-(T||$);H.diff=oe,H.prev=T,H.curr=$,T=$,I[0]=n.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let N=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Se,ve)=>{if(Se==="%%")return"%";N++;const k=n.formatters[ve];if(typeof k=="function"){const D=I[N];Se=k.call(H,D),I.splice(N,1),N--}return Se}),n.formatArgs.call(H,I),(H.log||n.log).apply(H,I)}return C.namespace=g,C.useColors=n.useColors(),C.color=n.selectColor(g),C.extend=a,C.destroy=n.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==n.namespaces&&(y=n.namespaces,A=n.enabled(g)),A),set:I=>{E=I}}),typeof n.init=="function"&&n.init(C),C}function a(g,T){const E=n(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const E=(typeof g=="string"?g:"").split(/[\s,]+/),y=E.length;for(T=0;T<y;T++)E[T]&&(g=E[T].replace(/\*/g,".*?"),g[0]==="-"?n.skips.push(new RegExp("^"+g.slice(1)+"$")):n.names.push(new RegExp("^"+g+"$")))}function s(){const g=[...n.names.map(d),...n.skips.map(d).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=n.skips.length;T<E;T++)if(n.skips[T].test(g))return!1;for(T=0,E=n.names.length;T<E;T++)if(n.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var Td=gd;(function(c,t){t.formatArgs=a,t.save=o,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function a(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const _="color: "+this.color;h.splice(1,0,_,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),h.splice(T,0,_)}t.log=console.debug||console.log||(()=>{});function o(h){try{h?t.storage.setItem("debug",h):t.storage.removeItem("debug")}catch{}}function s(){let h;try{h=t.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function r(){try{return localStorage}catch{}}c.exports=Td(t);const{formatters:d}=c.exports;d.j=function(h){try{return JSON.stringify(h)}catch(_){return"[UnexpectedJSONParseError]: "+_.message}}})(uu,uu.exports);var gr=uu.exports;function vd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Zu(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ed(c,t,n){return t&&Zu(c.prototype,t),n&&Zu(c,n),c}var lr=gr,ar="JsSIP",ht=function(){function c(t){vd(this,c),t?(this._debug=lr.default("".concat(ar,":").concat(t)),this._warn=lr.default("".concat(ar,":WARN:").concat(t)),this._error=lr.default("".concat(ar,":ERROR:").concat(t))):(this._debug=lr.default(ar),this._warn=lr.default("".concat(ar,":WARN")),this._error=lr.default("".concat(ar,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Ed(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),xt={},Xf={},Qf={exports:{}},ec=Qf.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(c){return c.encoding?"rtpmap:%d %s/%s/%s":c.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(c){return c.address!=null?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(c){return c.subtype!=null?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(c){return"extmap:%d"+(c.direction?"/%s":"%v")+(c["encrypt-uri"]?" %s":"%v")+" %s"+(c.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(c){return c.sessionConfig!=null?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(c){var t="candidate:%s %d %s %d %s %d typ %s";return t+=c.raddr!=null?" raddr %s rport %d":"%v%v",t+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(t+=" generation %d"),t+=c["network-id"]!=null?" network-id %d":"%v",t+=c["network-cost"]!=null?" network-cost %d":"%v",t}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(c){var t="ssrc:%d";return c.attribute!=null&&(t+=" %s",c.value!=null&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(c){return c.maxMessageSize!=null?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(c){return c.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(c){return"imageattr:%s %s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(c){return"simulcast:%s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(c){return"ts-refclk:%s"+(c.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(c){var t="mediaclk:";return t+=c.id!=null?"id=%s %s":"%v%s",t+=c.mediaClockValue!=null?"=%s":"",t+=c.rateNumerator!=null?" rate=%s":"",t+=c.rateDenominator!=null?"/%s":"",t}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(ec).forEach(function(c){var t=ec[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Zf=Qf.exports;(function(c){var t=function(d){return String(Number(d))===d?Number(d):d},n=function(d,h,_,g){if(g&&!_)h[g]=t(d[1]);else for(var T=0;T<_.length;T+=1)d[T+1]!=null&&(h[_[T]]=t(d[T+1]))},a=function(d,h,_){var g=d.name&&d.names;d.push&&!h[d.push]?h[d.push]=[]:g&&!h[d.name]&&(h[d.name]={});var T=d.push?{}:g?h[d.name]:h;n(_.match(d.reg),T,d.names,d.name),d.push&&h[d.push].push(T)},o=Zf,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var h={},_=[],g=h;return d.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(_.push({rtp:[],fmtp:[]}),g=_[_.length-1]);for(var A=0;A<(o[E]||[]).length;A+=1){var C=o[E][A];if(C.reg.test(y))return a(C,g,y)}}),h.media=_,h};var r=function(d,h){var _=h.split(/=(.+)/,2);return _.length===2?d[_[0]]=t(_[1]):_.length===1&&h.length>1&&(d[_[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var h=[],_=d.split(" ").map(t),g=0;g<_.length;g+=3)h.push({component:_[g],ip:_[g+1],port:_[g+2]});return h},c.parseImageAttributes=function(d){return d.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(h){return h.split(",").map(function(_){var g,T=!1;return _[0]!=="~"?g=t(_):(g=t(_.substring(1,_.length)),T=!0),{scid:g,paused:T}})})}})(Xf);var po=Zf,Sd=/%[sdv%]/g,yd=function(c){var t=1,n=arguments,a=n.length;return c.replace(Sd,function(o){if(t>=a)return o;var s=n[t];switch(t+=1,o){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Di=function(c,t,n){var a=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,o=[c+"="+a];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?o.push(n[t.name][r]):o.push(n[t.names[s]])}else o.push(n[t.name]);return yd.apply(null,o)},Ad=["v","o","s","i","u","e","p","c","b","t","r","z","a"],Cd=["i","c","b","a"],Rd=function(c,t){t=t||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var n=t.outerOrder||Ad,a=t.innerOrder||Cd,o=[];return n.forEach(function(s){po[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Di(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Di(s,r,d))})})}),c.media.forEach(function(s){o.push(Di("m",po.m[0],s)),a.forEach(function(r){po[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Di(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Di(r,d,h))})})})}),o.join(`\r
7
7
  `)+`\r
8
- `},gi=Bg,J0=X0;Qt.write=J0;Qt.parse=gi.parse;Qt.parseParams=gi.parseParams;Qt.parseFmtpConfig=gi.parseFmtpConfig;Qt.parsePayloads=gi.parsePayloads;Qt.parseRemoteCandidates=gi.parseRemoteCandidates;Qt.parseImageAttributes=gi.parseImageAttributes;Qt.parseSimulcastStreamList=gi.parseSimulcastStreamList;function qo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?qo=function(t){return typeof t}:qo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qo(u)}function Rf(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&Yh(u,e)}function Yh(u,e){return Yh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Yh(u,e)}function wf(u){var e=em();return function(){var r=iu(u),l;if(e){var s=iu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return Q0(this,l)}}function Q0(u,e){return e&&(qo(e)==="object"||typeof e=="function")?e:Z0(u)}function Z0(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function em(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function iu(u){return iu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},iu(u)}function us(u,e){var t;if(typeof Symbol>"u"||u[Symbol.iterator]==null){if(Array.isArray(u)||(t=tm(u))||e&&u&&typeof u.length=="number"){t&&(u=t);var r=0,l=function(){};return{s:l,n:function(){return r>=u.length?{done:!0}:{done:!1,value:u[r++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
9
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,i=!1,f;return{s:function(){t=u[Symbol.iterator]()},n:function(){var d=t.next();return s=d.done,d},e:function(d){i=!0,f=d},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(i)throw f}}}}function tm(u,e){if(u){if(typeof u=="string")return fd(u,e);var t=Object.prototype.toString.call(u).slice(8,-1);if(t==="Object"&&u.constructor&&(t=u.constructor.name),t==="Map"||t==="Set")return Array.from(u);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return fd(u,e)}}function fd(u,e){(e==null||e>u.length)&&(e=u.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=u[t];return r}function Sa(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function dd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Cu(u,e,t){return e&&dd(u.prototype,e),t&&dd(u,t),u}var Wg=Qt,sm=Ot,Lt=St,Tt=jt(),_d=Af(),nm=Ns(),Gc=new sm("SIPMessage"),Kg=function(){function u(e,t,r,l,s,i){if(Sa(this,u),!e||!t||!r)return null;l=l||{},this.ua=r,this.headers={},this.method=e,this.ruri=t,this.body=i,this.extraHeaders=Tt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),l.route_set?this.setHeader("route",l.route_set):r.configuration.use_preloaded_route&&this.setHeader("route","<".concat(r.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",Lt.MAX_FORWARDS);var f=l.to_uri||t,h=l.to_tag?{tag:l.to_tag}:null,d=typeof l.to_display_name<"u"?l.to_display_name:null;this.to=new _d(f,d,h),this.setHeader("to",this.to.toString());var p=l.from_uri||r.configuration.uri,v={tag:l.from_tag||Tt.newTag()},T;typeof l.from_display_name<"u"?T=l.from_display_name:r.configuration.display_name?T=r.configuration.display_name:T=null,this.from=new _d(p,T,v),this.setHeader("from",this.from.toString());var y=l.call_id||r.configuration.jssip_id+Tt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var S=l.cseq||Math.floor(Math.random()*1e4);this.cseq=S,this.setHeader("cseq","".concat(S," ").concat(e))}return Cu(u,[{key:"setHeader",value:function(t,r){for(var l=new RegExp("^\\s*".concat(t,"\\s*:"),"i"),s=0;s<this.extraHeaders.length;s++)l.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[Tt.headerize(t)]=Array.isArray(r)?r:[r]}},{key:"getHeader",value:function(t){var r=this.headers[Tt.headerize(t)];if(r){if(r[0])return r[0]}else{var l=new RegExp("^\\s*".concat(t,"\\s*:"),"i"),s=us(this.extraHeaders),i;try{for(s.s();!(i=s.n()).done;){var f=i.value;if(l.test(f))return f.substring(f.indexOf(":")+1).trim()}}catch(h){s.e(h)}finally{s.f()}}}},{key:"getHeaders",value:function(t){var r=this.headers[Tt.headerize(t)],l=[];if(r){var s=us(r),i;try{for(s.s();!(i=s.n()).done;){var f=i.value;l.push(f)}}catch(T){s.e(T)}finally{s.f()}return l}else{var h=new RegExp("^\\s*".concat(t,"\\s*:"),"i"),d=us(this.extraHeaders),p;try{for(d.s();!(p=d.n()).done;){var v=p.value;h.test(v)&&l.push(v.substring(v.indexOf(":")+1).trim())}}catch(T){d.e(T)}finally{d.f()}return l}}},{key:"hasHeader",value:function(t){if(this.headers[Tt.headerize(t)])return!0;var r=new RegExp("^\\s*".concat(t,"\\s*:"),"i"),l=us(this.extraHeaders),s;try{for(l.s();!(s=l.n()).done;){var i=s.value;if(r.test(i))return!0}}catch(f){l.e(f)}finally{l.f()}return!1}},{key:"parseSDP",value:function(t){return!t&&this.sdp?this.sdp:(this.sdp=Wg.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var t="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
- `);for(var r in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,r)){var l=us(this.headers[r]),s;try{for(l.s();!(s=l.n()).done;){var i=s.value;t+="".concat(r,": ").concat(i,`\r
11
- `)}}catch(y){l.e(y)}finally{l.f()}}var f=us(this.extraHeaders),h;try{for(f.s();!(h=f.n()).done;){var d=h.value;t+="".concat(d.trim(),`\r
12
- `)}}catch(y){f.e(y)}finally{f.f()}var p=[];switch(this.method){case Lt.REGISTER:p.push("path","gruu");break;case Lt.INVITE:this.ua.configuration.session_timers&&p.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&p.push("gruu"),p.push("ice","replaces");break;case Lt.UPDATE:this.ua.configuration.session_timers&&p.push("timer"),p.push("ice");break}p.push("outbound");var v=this.ua.configuration.user_agent||Lt.USER_AGENT;if(t+="Allow: ".concat(Lt.ALLOWED_METHODS,`\r
13
- `),t+="Supported: ".concat(p,`\r
14
- `),t+="User-Agent: ".concat(v,`\r
15
- `),this.body){var T=Tt.str_utf8_length(this.body);t+="Content-Length: ".concat(T,`\r
8
+ `},bn=Xf,Id=Rd;xt.write=Id;xt.parse=bn.parse;xt.parseParams=bn.parseParams;xt.parseFmtpConfig=bn.parseFmtpConfig;xt.parsePayloads=bn.parsePayloads;xt.parseRemoteCandidates=bn.parseRemoteCandidates;xt.parseImageAttributes=bn.parseImageAttributes;xt.parseSimulcastStreamList=bn.parseSimulcastStreamList;function Ta(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ta=function(n){return typeof n}:Ta=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ta(c)}function Nu(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&cu(c,t)}function cu(c,t){return cu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},cu(c,t)}function Uu(c){var t=Od();return function(){var a=Oa(c),o;if(t){var s=Oa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return bd(this,o)}}function bd(c,t){return t&&(Ta(t)==="object"||typeof t=="function")?t:wd(c)}function wd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Od(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Oa(c){return Oa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Oa(c)}function Bt(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Dd(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
9
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Dd(c,t){if(c){if(typeof c=="string")return tc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return tc(c,t)}}function tc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function il(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ba(c,t,n){return t&&sc(c.prototype,t),n&&sc(c,n),c}var eh=xt,Nd=ht,Et=lt,rt=bt(),nc=Ou(),Ud=os(),mo=new Nd("SIPMessage"),th=function(){function c(t,n,a,o,s,r){if(il(this,c),!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=rt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route","<".concat(a.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);var d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new nc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.newTag()},E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new nc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var A=o.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq","".concat(A," ").concat(t))}return Ba(c,[{key:"setHeader",value:function(n,a){for(var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=0;s<this.extraHeaders.length;s++)o.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[rt.headerize(n)]=Array.isArray(a)?a:[a]}},{key:"getHeader",value:function(n){var a=this.headers[rt.headerize(n)];if(a){if(a[0])return a[0]}else{var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=Bt(this.extraHeaders),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;if(o.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(h){s.e(h)}finally{s.f()}}}},{key:"getHeaders",value:function(n){var a=this.headers[rt.headerize(n)],o=[];if(a){var s=Bt(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d)}}catch(E){s.e(E)}finally{s.f()}return o}else{var h=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),_=Bt(this.extraHeaders),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;h.test(T)&&o.push(T.substring(T.indexOf(":")+1).trim())}}catch(E){_.e(E)}finally{_.f()}return o}}},{key:"hasHeader",value:function(n){if(this.headers[rt.headerize(n)])return!0;var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),o=Bt(this.extraHeaders),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;if(a.test(r))return!0}}catch(d){o.e(d)}finally{o.f()}return!1}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=eh.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var n="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
+ `);for(var a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a)){var o=Bt(this.headers[a]),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;n+="".concat(a,": ").concat(r,`\r
11
+ `)}}catch(y){o.e(y)}finally{o.f()}}var d=Bt(this.extraHeaders),h;try{for(d.s();!(h=d.n()).done;){var _=h.value;n+="".concat(_.trim(),`\r
12
+ `)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case Et.REGISTER:g.push("path","gruu");break;case Et.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case Et.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var T=this.ua.configuration.user_agent||Et.USER_AGENT;if(n+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
13
+ `),n+="Supported: ".concat(g,`\r
14
+ `),n+="User-Agent: ".concat(T,`\r
15
+ `),this.body){var E=rt.str_utf8_length(this.body);n+="Content-Length: ".concat(E,`\r
16
16
  \r
17
- `),t+=this.body}else t+=`Content-Length: 0\r
17
+ `),n+=this.body}else n+=`Content-Length: 0\r
18
18
  \r
19
- `;return t}},{key:"clone",value:function(){var t=new u(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(r){t.headers[r]=this.headers[r].slice()},this),t.body=this.body,t.extraHeaders=Tt.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}]),u}(),im=function(u){Rf(t,u);var e=wf(t);function t(r,l,s,i,f){var h;return Sa(this,t),h=e.call(this,Lt.INVITE,r,l,s,i,f),h.transaction=null,h}return Cu(t,[{key:"cancel",value:function(l){this.transaction.cancel(l)}},{key:"clone",value:function(){var l=new t(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){l.headers[s]=this.headers[s].slice()},this),l.body=this.body,l.extraHeaders=Tt.cloneArray(this.extraHeaders),l.to=this.to,l.from=this.from,l.call_id=this.call_id,l.cseq=this.cseq,l.transaction=this.transaction,l}}]),t}(Kg),Yg=function(){function u(){Sa(this,u),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 Cu(u,[{key:"addHeader",value:function(t,r){var l={raw:r};t=Tt.headerize(t),this.headers[t]?this.headers[t].push(l):this.headers[t]=[l]}},{key:"getHeader",value:function(t){var r=this.headers[Tt.headerize(t)];if(r){if(r[0])return r[0].raw}else return}},{key:"getHeaders",value:function(t){var r=this.headers[Tt.headerize(t)],l=[];if(!r)return[];var s=us(r),i;try{for(s.s();!(i=s.n()).done;){var f=i.value;l.push(f.raw)}}catch(h){s.e(h)}finally{s.f()}return l}},{key:"hasHeader",value:function(t){return!!this.headers[Tt.headerize(t)]}},{key:"parseHeader",value:function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(t=Tt.headerize(t),this.headers[t]){if(r>=this.headers[t].length){Gc.debug('not so many "'.concat(t,'" headers present'));return}}else{Gc.debug('header "'.concat(t,'" not present'));return}var l=this.headers[t][r],s=l.raw;if(l.parsed)return l.parsed;var i=nm.parse(s,t.replace(/-/g,"_"));if(i===-1){this.headers[t].splice(r,1),Gc.debug('error parsing "'.concat(t,'" header field with value "').concat(s,'"'));return}else return l.parsed=i,i}},{key:"s",value:function(t,r){return this.parseHeader(t,r)}},{key:"setHeader",value:function(t,r){var l={raw:r};this.headers[Tt.headerize(t)]=[l]}},{key:"parseSDP",value:function(t){return!t&&this.sdp?this.sdp:(this.sdp=Wg.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),u}(),rm=function(u){Rf(t,u);var e=wf(t);function t(r){var l;return Sa(this,t),l=e.call(this),l.ua=r,l.headers={},l.ruri=null,l.transport=null,l.server_transaction=null,l}return Cu(t,[{key:"reply",value:function(l,s,i,f,h,d){var p=[],v=this.getHeader("To");if(l=l||null,s=s||null,!l||l<100||l>699)throw new TypeError("Invalid status_code: ".concat(l));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Lt.REASON_PHRASE[l]||"",i=Tt.cloneArray(i),this.ua.configuration.extra_headers&&(i=i.concat(this.ua.configuration.extra_headers));var T="SIP/2.0 ".concat(l," ").concat(s,`\r
20
- `);if(this.method===Lt.INVITE&&l>100&&l<=200){var y=this.getHeaders("record-route"),S=us(y),A;try{for(S.s();!(A=S.n()).done;){var R=A.value;T+="Record-Route: ".concat(R,`\r
21
- `)}}catch(P){S.e(P)}finally{S.f()}}var O=this.getHeaders("via"),N=us(O),C;try{for(N.s();!(C=N.n()).done;){var b=C.value;T+="Via: ".concat(b,`\r
22
- `)}}catch(P){N.e(P)}finally{N.f()}!this.to_tag&&l>100?v+=";tag=".concat(Tt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(v+=";tag=".concat(this.to_tag)),T+="To: ".concat(v,`\r
23
- `),T+="From: ".concat(this.getHeader("From"),`\r
24
- `),T+="Call-ID: ".concat(this.call_id,`\r
25
- `),T+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
26
- `);var w=us(i),F;try{for(w.s();!(F=w.n()).done;){var q=F.value;T+="".concat(q.trim(),`\r
27
- `)}}catch(P){w.e(P)}finally{w.f()}switch(this.method){case Lt.INVITE:this.ua.configuration.session_timers&&p.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&p.push("gruu"),p.push("ice","replaces");break;case Lt.UPDATE:this.ua.configuration.session_timers&&p.push("timer"),f&&p.push("ice"),p.push("replaces")}if(p.push("outbound"),this.method===Lt.OPTIONS?(T+="Allow: ".concat(Lt.ALLOWED_METHODS,`\r
28
- `),T+="Accept: ".concat(Lt.ACCEPTED_BODY_TYPES,`\r
29
- `)):l===405?T+="Allow: ".concat(Lt.ALLOWED_METHODS,`\r
30
- `):l===415&&(T+="Accept: ".concat(Lt.ACCEPTED_BODY_TYPES,`\r
31
- `)),T+="Supported: ".concat(p,`\r
32
- `),f){var D=Tt.str_utf8_length(f);T+=`Content-Type: application/sdp\r
33
- `,T+="Content-Length: ".concat(D,`\r
19
+ `;return n}},{key:"clone",value:function(){var n=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(a){n.headers[a]=this.headers[a].slice()},this),n.body=this.body,n.extraHeaders=rt.cloneArray(this.extraHeaders),n.to=this.to,n.from=this.from,n.call_id=this.call_id,n.cseq=this.cseq,n}}]),c}(),Pd=function(c){Nu(n,c);var t=Uu(n);function n(a,o,s,r,d){var h;return il(this,n),h=t.call(this,Et.INVITE,a,o,s,r,d),h.transaction=null,h}return Ba(n,[{key:"cancel",value:function(o){this.transaction.cancel(o)}},{key:"clone",value:function(){var o=new n(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){o.headers[s]=this.headers[s].slice()},this),o.body=this.body,o.extraHeaders=rt.cloneArray(this.extraHeaders),o.to=this.to,o.from=this.from,o.call_id=this.call_id,o.cseq=this.cseq,o.transaction=this.transaction,o}}]),n}(th),sh=function(){function c(){il(this,c),this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}return Ba(c,[{key:"addHeader",value:function(n,a){var o={raw:a};n=rt.headerize(n),this.headers[n]?this.headers[n].push(o):this.headers[n]=[o]}},{key:"getHeader",value:function(n){var a=this.headers[rt.headerize(n)];if(a){if(a[0])return a[0].raw}else return}},{key:"getHeaders",value:function(n){var a=this.headers[rt.headerize(n)],o=[];if(!a)return[];var s=Bt(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d.raw)}}catch(h){s.e(h)}finally{s.f()}return o}},{key:"hasHeader",value:function(n){return!!this.headers[rt.headerize(n)]}},{key:"parseHeader",value:function(n){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=rt.headerize(n),this.headers[n]){if(a>=this.headers[n].length){mo.debug('not so many "'.concat(n,'" headers present'));return}}else{mo.debug('header "'.concat(n,'" not present'));return}var o=this.headers[n][a],s=o.raw;if(o.parsed)return o.parsed;var r=Ud.parse(s,n.replace(/-/g,"_"));if(r===-1){this.headers[n].splice(a,1),mo.debug('error parsing "'.concat(n,'" header field with value "').concat(s,'"'));return}else return o.parsed=r,r}},{key:"s",value:function(n,a){return this.parseHeader(n,a)}},{key:"setHeader",value:function(n,a){var o={raw:a};this.headers[rt.headerize(n)]=[o]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=eh.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),xd=function(c){Nu(n,c);var t=Uu(n);function n(a){var o;return il(this,n),o=t.call(this),o.ua=a,o.headers={},o.ruri=null,o.transport=null,o.server_transaction=null,o}return Ba(n,[{key:"reply",value:function(o,s,r,d,h,_){var g=[],T=this.getHeader("To");if(o=o||null,s=s||null,!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Et.REASON_PHRASE[o]||"",r=rt.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));var E="SIP/2.0 ".concat(o," ").concat(s,`\r
20
+ `);if(this.method===Et.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),A=Bt(y),C;try{for(A.s();!(C=A.n()).done;){var I=C.value;E+="Record-Route: ".concat(I,`\r
21
+ `)}}catch(D){A.e(D)}finally{A.f()}}var H=this.getHeaders("via"),$=Bt(H),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;E+="Via: ".concat(N,`\r
22
+ `)}}catch(D){$.e(D)}finally{$.f()}!this.to_tag&&o>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),E+="To: ".concat(T,`\r
23
+ `),E+="From: ".concat(this.getHeader("From"),`\r
24
+ `),E+="Call-ID: ".concat(this.call_id,`\r
25
+ `),E+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
26
+ `);var j=Bt(r),Se;try{for(j.s();!(Se=j.n()).done;){var ve=Se.value;E+="".concat(ve.trim(),`\r
27
+ `)}}catch(D){j.e(D)}finally{j.f()}switch(this.method){case Et.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case Et.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),d&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===Et.OPTIONS?(E+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
28
+ `),E+="Accept: ".concat(Et.ACCEPTED_BODY_TYPES,`\r
29
+ `)):o===405?E+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
30
+ `):o===415&&(E+="Accept: ".concat(Et.ACCEPTED_BODY_TYPES,`\r
31
+ `)),E+="Supported: ".concat(g,`\r
32
+ `),d){var k=rt.str_utf8_length(d);E+=`Content-Type: application/sdp\r
33
+ `,E+="Content-Length: ".concat(k,`\r
34
34
  \r
35
- `),T+=f}else T+="Content-Length: ".concat(0,`\r
35
+ `),E+=d}else E+="Content-Length: ".concat(0,`\r
36
36
  \r
37
- `);this.server_transaction.receiveResponse(l,T,h,d)}},{key:"reply_sl",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,i=this.getHeaders("via");if(!l||l<100||l>699)throw new TypeError("Invalid status_code: ".concat(l));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Lt.REASON_PHRASE[l]||"";var f="SIP/2.0 ".concat(l," ").concat(s,`\r
38
- `),h=us(i),d;try{for(h.s();!(d=h.n()).done;){var p=d.value;f+="Via: ".concat(p,`\r
39
- `)}}catch(A){h.e(A)}finally{h.f()}var v=this.getHeader("To");if(!this.to_tag&&l>100?v+=";tag=".concat(Tt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(v+=";tag=".concat(this.to_tag)),f+="To: ".concat(v,`\r
40
- `),f+="From: ".concat(this.getHeader("From"),`\r
41
- `),f+="Call-ID: ".concat(this.call_id,`\r
42
- `),f+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
43
- `),this.ua.configuration.extra_headers){var T=us(this.ua.configuration.extra_headers),y;try{for(T.s();!(y=T.n()).done;){var S=y.value;f+="".concat(S.trim(),`\r
44
- `)}}catch(A){T.e(A)}finally{T.f()}}f+="Content-Length: ".concat(0,`\r
37
+ `);this.server_transaction.receiveResponse(o,E,h,_)}},{key:"reply_sl",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,r=this.getHeaders("via");if(!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Et.REASON_PHRASE[o]||"";var d="SIP/2.0 ".concat(o," ").concat(s,`\r
38
+ `),h=Bt(r),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;d+="Via: ".concat(g,`\r
39
+ `)}}catch(C){h.e(C)}finally{h.f()}var T=this.getHeader("To");if(!this.to_tag&&o>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),d+="To: ".concat(T,`\r
40
+ `),d+="From: ".concat(this.getHeader("From"),`\r
41
+ `),d+="Call-ID: ".concat(this.call_id,`\r
42
+ `),d+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
43
+ `),this.ua.configuration.extra_headers){var E=Bt(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var A=y.value;d+="".concat(A.trim(),`\r
44
+ `)}}catch(C){E.e(C)}finally{E.f()}}d+="Content-Length: ".concat(0,`\r
45
45
  \r
46
- `),this.transport.send(f)}}]),t}(Yg),lm=function(u){Rf(t,u);var e=wf(t);function t(){var r;return Sa(this,t),r=e.call(this),r.headers={},r.status_code=null,r.reason_phrase=null,r}return t}(Yg),zs={OutgoingRequest:Kg,InitialOutgoingInviteRequest:im,IncomingRequest:rm,IncomingResponse:lm};function am(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function gd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function om(u,e,t){return e&&gd(u.prototype,e),t&&gd(u,t),u}var um=Ot,Ls=jt(),ds=new um("DigestAuthentication"),cm=function(){function u(e){am(this,u),this._credentials=e,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 om(u,[{key:"get",value:function(t){switch(t){case"realm":return this._realm;case"ha1":return this._ha1;default:ds.warn('get() | cannot get "%s" parameter',t);return}}},{key:"authenticate",value:function(t,r){var l=t.method,s=t.ruri,i=t.body,f=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=r.algorithm,this._realm=r.realm,this._nonce=r.nonce,this._opaque=r.opaque,this._stale=r.stale,this._algorithm){if(this._algorithm!=="MD5")return ds.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return ds.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return ds.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return ds.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return ds.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(r.qop)if(r.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(r.qop.indexOf("auth")>-1)this._qop="auth";else return ds.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=f||Ls.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=Ls.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var d,p;return this._qop==="auth"?(d="".concat(this._method,":").concat(this._uri),p=Ls.calculateMD5(d),ds.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=Ls.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(p))):this._qop==="auth-int"?(d="".concat(this._method,":").concat(this._uri,":").concat(Ls.calculateMD5(i||"")),p=Ls.calculateMD5(d),ds.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=Ls.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(p))):this._qop===null&&(d="".concat(this._method,":").concat(this._uri),p=Ls.calculateMD5(d),ds.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=Ls.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(p))),ds.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var t=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return t.push("algorithm=".concat(this._algorithm)),t.push('username="'.concat(this._credentials.username,'"')),t.push('realm="'.concat(this._realm,'"')),t.push('nonce="'.concat(this._nonce,'"')),t.push('uri="'.concat(this._uri,'"')),t.push('response="'.concat(this._response,'"')),this._opaque&&t.push('opaque="'.concat(this._opaque,'"')),this._qop&&(t.push("qop=".concat(this._qop)),t.push('cnonce="'.concat(this._cnonce,'"')),t.push("nc=".concat(this._ncHex))),"Digest ".concat(t.join(", "))}}]),u}(),Fs=500,hm=4e3,pd=5e3,zg={T1:Fs,T2:hm,T4:pd,TIMER_B:64*Fs,TIMER_D:0*Fs,TIMER_F:64*Fs,TIMER_H:64*Fs,TIMER_I:0*Fs,TIMER_J:0*Fs,TIMER_K:0*pd,TIMER_L:64*Fs,TIMER_M:64*Fs,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Wo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Wo=function(t){return typeof t}:Wo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Wo(u)}function Ea(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function md(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Ca(u,e,t){return e&&md(u.prototype,e),t&&md(u,t),u}function Aa(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&zh(u,e)}function zh(u,e){return zh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},zh(u,e)}function ba(u){var e=dm();return function(){var r=ru(u),l;if(e){var s=ru(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return fm(this,l)}}function fm(u,e){return e&&(Wo(e)==="object"||typeof e=="function")?e:bn(u)}function bn(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function dm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function ru(u){return ru=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},ru(u)}var Ra=It.EventEmitter,wa=Ot,ca=St,vd=zs,Os=zg,Td=new wa("NonInviteClientTransaction"),lo=new wa("InviteClientTransaction"),_m=new wa("AckClientTransaction"),yd=new wa("NonInviteServerTransaction"),ao=new wa("InviteServerTransaction"),ye={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"},gm=function(u){Aa(t,u);var e=ba(t);function t(r,l,s,i){var f;Ea(this,t),f=e.call(this),f.type=ye.NON_INVITE_CLIENT,f.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),f.ua=r,f.transport=l,f.request=s,f.eventHandlers=i;var h="SIP/2.0/".concat(l.via_transport);return h+=" ".concat(r.configuration.via_host,";branch=").concat(f.id),f.request.setHeader("via",h),f.ua.newTransaction(bn(f)),f}return Ca(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"send",value:function(){var l=this;this.stateChanged(ye.STATUS_TRYING),this.F=setTimeout(function(){l.timer_F()},Os.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Td.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Td.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(l){var s=this,i=l.status_code;if(i<200)switch(this.state){case ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(l);break}else switch(this.state){case ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),clearTimeout(this.F),i===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(l),this.K=setTimeout(function(){s.timer_K()},Os.TIMER_K);break;case ye.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ye}}]),t}(Ra),pm=function(u){Aa(t,u);var e=ba(t);function t(r,l,s,i){var f;Ea(this,t),f=e.call(this),f.type=ye.INVITE_CLIENT,f.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),f.ua=r,f.transport=l,f.request=s,f.eventHandlers=i,s.transaction=bn(f);var h="SIP/2.0/".concat(l.via_transport);return h+=" ".concat(r.configuration.via_host,";branch=").concat(f.id),f.request.setHeader("via",h),f.ua.newTransaction(bn(f)),f}return Ca(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"send",value:function(){var l=this;this.stateChanged(ye.STATUS_CALLING),this.B=setTimeout(function(){l.timer_B()},Os.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ye.STATUS_ACCEPTED&&(lo.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){lo.debug("Timer M expired for transaction ".concat(this.id)),this.state===ye.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){lo.debug("Timer B expired for transaction ".concat(this.id)),this.state===ye.STATUS_CALLING&&(this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){lo.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(l){var s=this,i=new vd.OutgoingRequest(ca.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});i.setHeader("from",this.request.getHeader("from")),i.setHeader("via",this.request.getHeader("via")),i.setHeader("to",l.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},Os.TIMER_D),this.transport.send(i)}},{key:"cancel",value:function(l){if(this.state===ye.STATUS_PROCEEDING){var s=new vd.OutgoingRequest(ca.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),l&&s.setHeader("reason",l),this.transport.send(s)}}},{key:"receiveResponse",value:function(l){var s=this,i=l.status_code;if(i>=100&&i<=199)switch(this.state){case ye.STATUS_CALLING:this.stateChanged(ye.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(l);break;case ye.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(l);break}else if(i>=200&&i<=299)switch(this.state){case ye.STATUS_CALLING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},Os.TIMER_M),this.eventHandlers.onReceiveResponse(l);break;case ye.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(l);break}else if(i>=300&&i<=699)switch(this.state){case ye.STATUS_CALLING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),this.sendACK(l),this.eventHandlers.onReceiveResponse(l);break;case ye.STATUS_COMPLETED:this.sendACK(l);break}}},{key:"C",get:function(){return ye}}]),t}(Ra),mm=function(u){Aa(t,u);var e=ba(t);function t(r,l,s,i){var f;Ea(this,t),f=e.call(this),f.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),f.transport=l,f.request=s,f.eventHandlers=i;var h="SIP/2.0/".concat(l.via_transport);return h+=" ".concat(r.configuration.via_host,";branch=").concat(f.id),f.request.setHeader("via",h),f}return Ca(t,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){_m.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ye}}]),t}(Ra),vm=function(u){Aa(t,u);var e=ba(t);function t(r,l,s){var i;return Ea(this,t),i=e.call(this),i.type=ye.NON_INVITE_SERVER,i.id=s.via_branch,i.ua=r,i.transport=l,i.request=s,i.last_response="",s.server_transaction=bn(i),i.state=ye.STATUS_TRYING,r.newTransaction(bn(i)),i}return Ca(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"timer_J",value:function(){yd.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,yd.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(l,s,i,f){var h=this;if(l===100)switch(this.state){case ye.STATUS_TRYING:this.stateChanged(ye.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ye.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?i&&i():(this.onTransportError(),f&&f());break}else if(l>=200&&l<=699)switch(this.state){case ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},Os.TIMER_J),this.transport.send(s)?i&&i():(this.onTransportError(),f&&f());break;case ye.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ye}}]),t}(Ra),Tm=function(u){Aa(t,u);var e=ba(t);function t(r,l,s){var i;return Ea(this,t),i=e.call(this),i.type=ye.INVITE_SERVER,i.id=s.via_branch,i.ua=r,i.transport=l,i.request=s,i.last_response="",s.server_transaction=bn(i),i.state=ye.STATUS_PROCEEDING,r.newTransaction(bn(i)),i.resendProvisionalTimer=null,s.reply(100),i}return Ca(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"timer_H",value:function(){ao.debug("Timer H expired for transaction ".concat(this.id)),this.state===ye.STATUS_COMPLETED&&ao.debug("ACK not received, dialog will be terminated"),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){ao.debug("Timer L expired for transaction ".concat(this.id)),this.state===ye.STATUS_ACCEPTED&&(this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,ao.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(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(l,s,i,f){var h=this;if(l>=100&&l<=199)switch(this.state){case ye.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(l>100&&l<=199&&this.state===ye.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},Os.PROVISIONAL_RESPONSE_INTERVAL));else if(l>=200&&l<=299)switch(this.state){case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},Os.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ye.STATUS_ACCEPTED:this.transport.send(s)?i&&i():(this.onTransportError(),f&&f());break}else if(l>=300&&l<=699)switch(this.state){case ye.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ye.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},Os.TIMER_H),i&&i()):(this.onTransportError(),f&&f());break}}},{key:"C",get:function(){return ye}}]),t}(Ra);function ym(u,e){var t=u._transactions,r;switch(e.method){case ca.INVITE:if(r=t.ist[e.via_branch],r){switch(r.state){case ye.STATUS_PROCEEDING:r.transport.send(r.last_response);break;case ye.STATUS_ACCEPTED:break}return!0}break;case ca.ACK:if(r=t.ist[e.via_branch],r){if(r.state===ye.STATUS_ACCEPTED)return!1;if(r.state===ye.STATUS_COMPLETED)return r.state=ye.STATUS_CONFIRMED,r.I=setTimeout(function(){r.timer_I()},Os.TIMER_I),!0}else return!1;break;case ca.CANCEL:return r=t.ist[e.via_branch],r?(e.reply_sl(200),r.state!==ye.STATUS_PROCEEDING):(e.reply_sl(481),!0);default:if(r=t.nist[e.via_branch],r){switch(r.state){case ye.STATUS_TRYING:break;case ye.STATUS_PROCEEDING:case ye.STATUS_COMPLETED:r.transport.send(r.last_response);break}return!0}break}}var Ia={C:ye,NonInviteClientTransaction:gm,InviteClientTransaction:pm,AckClientTransaction:mm,NonInviteServerTransaction:vm,InviteServerTransaction:Tm,checkTransaction:ym};function Sm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Sd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Em(u,e,t){return e&&Sd(u.prototype,e),t&&Sd(u,t),u}var Cm=Ot,Ed=St,Am=cm,Vc=Ia,bm=new Cm("RequestSender"),Bc={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},Oa=function(){function u(e,t,r){Sm(this,u),this._ua=e,this._eventHandlers=r,this._method=t.method,this._request=t,this._auth=null,this._challenged=!1,this._staled=!1;for(var l in Bc)Object.prototype.hasOwnProperty.call(Bc,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=Bc[l]));e.status===e.C.STATUS_USER_CLOSED&&(this._method!==Ed.BYE||this._method!==Ed.ACK)&&this._eventHandlers.onTransportError()}return Em(u,[{key:"send",value:function(){var t=this,r={onRequestTimeout:function(){t._eventHandlers.onRequestTimeout()},onTransportError:function(){t._eventHandlers.onTransportError()},onReceiveResponse:function(s){t._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new Vc.InviteClientTransaction(this._ua,this._ua.transport,this._request,r);break;case"ACK":this.clientTransaction=new Vc.AckClientTransaction(this._ua,this._ua.transport,this._request,r);break;default:this.clientTransaction=new Vc.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,r)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(t){var r,l,s=t.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(r=t.parseHeader("www-authenticate"),l="authorization"):(r=t.parseHeader("proxy-authenticate"),l="proxy-authorization"),!r){bm.debug("".concat(t.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(t);return}if(!this._challenged||!this._staled&&r.stale===!0){if(this._auth||(this._auth=new Am({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,r)){this._eventHandlers.onReceiveResponse(t);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),r.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(l,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}}]),u}();function Rm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Cd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function wm(u,e,t){return e&&Cd(u.prototype,e),t&&Cd(u,t),u}var Im=Ot,jc=jt(),si=St,Ad=zs,bd=Oa,Gl=new Im("Registrator"),oo=10,Om=function(){function u(e,t){Rm(this,u),this._reg_id=1,this._ua=e,this._transport=t,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=jc.createRandomToken(22),this._cseq=0,this._to_uri=e.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 wm(u,[{key:"setExtraHeaders",value:function(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}},{key:"setExtraContactParams",value:function(t){t instanceof Object||(t={}),this._extraContactParams="";for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var l=t[r];this._extraContactParams+=";".concat(r),l&&(this._extraContactParams+="=".concat(l))}}},{key:"register",value:function(){var t=this;if(this._registering){Gl.debug("Register request in progress...");return}var r=this._extraHeaders.slice();r.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),r.push("Expires: ".concat(this._expires));var l=new Ad.OutgoingRequest(si.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},r),s=new bd(this._ua,l,{onRequestTimeout:function(){t._registrationFailure(null,si.causes.REQUEST_TIMEOUT)},onTransportError:function(){t._registrationFailure(null,si.causes.CONNECTION_ERROR)},onAuthenticated:function(){t._cseq+=1},onReceiveResponse:function(f){if(f.cseq===t._cseq)switch(t._registrationTimer!==null&&(clearTimeout(t._registrationTimer),t._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(f.status_code):break;case/^2[0-9]{2}$/.test(f.status_code):{if(t._registering=!1,!f.hasHeader("Contact")){Gl.debug("no Contact header in response to REGISTER, response ignored");break}var h=f.headers.Contact.reduce(function(y,S){return y.concat(S.parsed)},[]),d=h.find(function(y){return t._sipInstance===y.getParam("+sip.instance")&&t._reg_id===parseInt(y.getParam("reg-id"))});if(d||(d=h.find(function(y){return y.uri.user===t._ua.contact.uri.user})),!d){Gl.debug("no Contact header pointing to us, response ignored");break}var p=d.getParam("expires");!p&&f.hasHeader("expires")&&(p=f.getHeader("expires")),p||(p=t._expires),p=Number(p),p<oo&&(p=oo);var v=p>64?p*1e3/2+Math.floor((p/2-32)*1e3*Math.random()):p*1e3-5e3;t._registrationTimer=setTimeout(function(){t._registrationTimer=null,t._ua.listeners("registrationExpiring").length===0?t.register():t._ua.emit("registrationExpiring")},v),d.hasParam("temp-gruu")&&(t._ua.contact.temp_gruu=d.getParam("temp-gruu").replace(/"/g,"")),d.hasParam("pub-gruu")&&(t._ua.contact.pub_gruu=d.getParam("pub-gruu").replace(/"/g,"")),t._registered||(t._registered=!0,t._ua.registered({response:f}));break}case/^423$/.test(f.status_code):{f.hasHeader("min-expires")?(t._expires=Number(f.getHeader("min-expires")),t._expires<oo&&(t._expires=oo),t.register()):(Gl.debug("423 response received for REGISTER without Min-Expires"),t._registrationFailure(f,si.causes.SIP_FAILURE_CODE));break}default:{var T=jc.sipErrorCause(f.status_code);t._registrationFailure(f,T)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var t=this,r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){Gl.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var l=this._extraHeaders.slice();r.all?l.push("Contact: *".concat(this._extraContactParams)):l.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),l.push("Expires: 0");var s=new Ad.OutgoingRequest(si.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l),i=new bd(this._ua,s,{onRequestTimeout:function(){t._unregistered(null,si.causes.REQUEST_TIMEOUT)},onTransportError:function(){t._unregistered(null,si.causes.CONNECTION_ERROR)},onAuthenticated:function(){t._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):t._unregistered(h);break;default:{var d=jc.sipErrorCause(h.status_code);t._unregistered(h,d)}}}});i.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(t,r){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:r}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:r}))}},{key:"_unregistered",value:function(t,r){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:r||null})}},{key:"registered",get:function(){return this._registered}}]),u}();function Dm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Rd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Nm(u,e,t){return e&&Rd(u.prototype,e),t&&Rd(u,t),u}var qc=St,uo=Ia,Pm=Oa,Wc={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},xm=function(){function u(e,t,r){Dm(this,u),this._dialog=e,this._ua=e._ua,this._request=t,this._eventHandlers=r,this._reattempt=!1,this._reattemptTimer=null;for(var l in Wc)Object.prototype.hasOwnProperty.call(Wc,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=Wc[l]))}return Nm(u,[{key:"send",value:function(){var t=this,r=new Pm(this._ua,this._request,{onRequestTimeout:function(){t._eventHandlers.onRequestTimeout()},onTransportError:function(){t._eventHandlers.onTransportError()},onAuthenticated:function(i){t._eventHandlers.onAuthenticated(i)},onReceiveResponse:function(i){t._receiveResponse(i)}});if(r.send(),(this._request.method===qc.INVITE||this._request.method===qc.UPDATE&&this._request.body)&&r.clientTransaction.state!==uo.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var l=function s(){(r.clientTransaction.state===uo.C.STATUS_ACCEPTED||r.clientTransaction.state===uo.C.STATUS_COMPLETED||r.clientTransaction.state===uo.C.STATUS_TERMINATED)&&(r.clientTransaction.removeListener("stateChanged",s),t._dialog.uac_pending_reply=!1)};r.clientTransaction.on("stateChanged",l)}}},{key:"_receiveResponse",value:function(t){var r=this;t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===qc.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){r._dialog.isTerminated()||(r._reattempt=!0,r.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}},{key:"request",get:function(){return this._request}}]),u}();function km(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function wd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Id(u,e,t){return e&&wd(u.prototype,e),t&&wd(u,t),u}var Mm=Ot,Od=zs,gn=St,Vl=Ia,Um=xm,Kc=jt(),Yc=new Mm("Dialog"),pn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Lm=function(){Id(u,null,[{key:"C",get:function(){return pn}}]);function u(e,t,r){var l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:pn.STATUS_CONFIRMED;if(km(this,u),this._owner=e,this._ua=e._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!t.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};t instanceof Od.IncomingResponse&&(l=t.status_code<200?pn.STATUS_EARLY:pn.STATUS_CONFIRMED);var s=t.parseHeader("contact");r==="UAS"?(this._id={call_id:t.call_id,local_tag:t.to_tag,remote_tag:t.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._remote_seqnum=t.cseq,this._local_uri=t.parseHeader("to").uri,this._remote_uri=t.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=t.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):r==="UAC"&&(this._id={call_id:t.call_id,local_tag:t.from_tag,remote_tag:t.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._local_seqnum=t.cseq,this._local_uri=t.parseHeader("from").uri,this._remote_uri=t.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=t.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Yc.debug("new ".concat(r," dialog created with status ").concat(this._state===pn.STATUS_EARLY?"EARLY":"CONFIRMED"))}return Id(u,[{key:"isTerminated",value:function(){return this._status===pn.STATUS_TERMINATED}},{key:"update",value:function(t,r){this._state=pn.STATUS_CONFIRMED,Yc.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),r==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Yc.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=pn.STATUS_TERMINATED}},{key:"sendRequest",value:function(t){var r=this,l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=Kc.cloneArray(l.extraHeaders),i=Kc.cloneObject(l.eventHandlers),f=l.body||null,h=this._createRequest(t,s,f);i.onAuthenticated=function(){r._local_seqnum+=1};var d=new Um(this,h,i);return d.send(),h}},{key:"receiveRequest",value:function(t){this._checkInDialogRequest(t)&&(t.method===gn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===gn.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}},{key:"_createRequest",value:function(t,r,l){r=Kc.cloneArray(r),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=t===gn.CANCEL||t===gn.ACK?this._local_seqnum:this._local_seqnum+=1,i=new Od.OutgoingRequest(t,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},r,l);return i}},{key:"_checkInDialogRequest",value:function(t){var r=this;if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===gn.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===gn.INVITE||t.method===gn.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){var l=(Math.random()*10|0)+1;return t.reply(500,null,["Retry-After:".concat(l)]),!1}else{this._uas_pending_reply=!0;var s=function i(){(t.server_transaction.state===Vl.C.STATUS_ACCEPTED||t.server_transaction.state===Vl.C.STATUS_COMPLETED||t.server_transaction.state===Vl.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",i),r._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",s)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",function(){t.server_transaction.state===Vl.C.STATUS_ACCEPTED&&(r._remote_target=t.parseHeader("contact").uri)})}else t.method===gn.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",function(){t.server_transaction.state===Vl.C.STATUS_COMPLETED&&(r._remote_target=t.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(t){this._local_seqnum=t}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(t){this._uac_pending_reply=t}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),u}(),If={exports:{}};function Ko(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ko=function(t){return typeof t}:Ko=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ko(u)}function Fm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Dd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function $m(u,e,t){return e&&Dd(u.prototype,e),t&&Dd(u,t),u}function Hm(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&Xh(u,e)}function Xh(u,e){return Xh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Xh(u,e)}function Gm(u){var e=jm();return function(){var r=lu(u),l;if(e){var s=lu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return Vm(this,l)}}function Vm(u,e){return e&&(Ko(e)==="object"||typeof e=="function")?e:Bm(u)}function Bm(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function jm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function lu(u){return lu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},lu(u)}var qm=It.EventEmitter,Wm=Ot,Km=St,Ym=In,Nd=jt(),zm=new Wm("RTCSession:DTMF"),Xg={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};If.exports=function(u){Hm(t,u);var e=Gm(t);function t(r){var l;return Fm(this,t),l=e.call(this),l._session=r,l._direction=null,l._tone=null,l._duration=null,l._request=null,l}return $m(t,[{key:"send",value:function(l){var s=this,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};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 Ym.InvalidStateError(this._session.status);var f=Nd.cloneArray(i.extraHeaders);if(this.eventHandlers=Nd.cloneObject(i.eventHandlers),typeof l=="string")l=l.toUpperCase();else if(typeof l=="number")l=l.toString();else throw new TypeError("Invalid tone: ".concat(l));if(l.match(/^[0-9A-DR#*]$/))this._tone=l;else throw new TypeError("Invalid tone: ".concat(l));this._duration=i.duration,f.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
47
- `);h+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(Km.INFO,{extraHeaders:f,eventHandlers:{onSuccessResponse:function(p){s.emit("succeeded",{originator:"remote",response:p})},onErrorResponse:function(p){s.eventHandlers.onFailed&&s.eventHandlers.onFailed(),s.emit("failed",{originator:"remote",response:p})},onRequestTimeout:function(){s._session.onRequestTimeout()},onTransportError:function(){s._session.onTransportError()},onDialogError:function(){s._session.onDialogError()}},body:h})}},{key:"init_incoming",value:function(l){var s=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,i=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=l,l.reply(200),l.body){var f=l.body.split(`
48
- `);f.length>=1&&s.test(f[0])&&(this._tone=f[0].replace(s,"$2")),f.length>=2&&i.test(f[1])&&(this._duration=parseInt(f[1].replace(i,"$2"),10))}this._duration||(this._duration=Xg.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:l}):zm.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),t}(qm);If.exports.C=Xg;var Xm=If.exports;function Yo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Yo=function(t){return typeof t}:Yo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Yo(u)}function Jm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Pd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Qm(u,e,t){return e&&Pd(u.prototype,e),t&&Pd(u,t),u}function Zm(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&Jh(u,e)}function Jh(u,e){return Jh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Jh(u,e)}function ev(u){var e=nv();return function(){var r=au(u),l;if(e){var s=au(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return tv(this,l)}}function tv(u,e){return e&&(Yo(e)==="object"||typeof e=="function")?e:sv(u)}function sv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function nv(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function au(u){return au=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},au(u)}var iv=It.EventEmitter,rv=St,lv=In,av=jt(),ov=function(u){Zm(t,u);var e=ev(t);function t(r){var l;return Jm(this,t),l=e.call(this),l._session=r,l._direction=null,l._contentType=null,l._body=null,l}return Qm(t,[{key:"send",value:function(l,s){var i=this,f=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};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 lv.InvalidStateError(this._session.status);this._contentType=l,this._body=s;var h=av.cloneArray(f.extraHeaders);h.push("Content-Type: ".concat(l)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(rv.INFO,{extraHeaders:h,eventHandlers:{onSuccessResponse:function(p){i.emit("succeeded",{originator:"remote",response:p})},onErrorResponse:function(p){i.emit("failed",{originator:"remote",response:p})},onTransportError:function(){i._session.onTransportError()},onRequestTimeout:function(){i._session.onRequestTimeout()},onDialogError:function(){i._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(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})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),t}(iv);function uv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function xd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function cv(u,e,t){return e&&xd(u.prototype,e),t&&xd(u,t),u}var hv=Ot,kd=St,fv=new hv("RTCSession:ReferNotifier"),zc={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},dv=function(){function u(e,t,r){uv(this,u),this._session=e,this._id=t,this._expires=r||zc.expires,this._active=!0,this.notify(100)}return cv(u,[{key:"notify",value:function(t,r){if(fv.debug("notify()"),this._active!==!1){r=r||kd.REASON_PHRASE[t]||"";var l;t>=200?l="terminated;reason=noresource":l="active;expires=".concat(this._expires),this._session.sendRequest(kd.NOTIFY,{extraHeaders:["Event: ".concat(zc.event_type,";id=").concat(this._id),"Subscription-State: ".concat(l),"Content-Type: ".concat(zc.body_type)],body:"SIP/2.0 ".concat(t," ").concat(r),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),u}();function zo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?zo=function(t){return typeof t}:zo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},zo(u)}function _v(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Md(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function gv(u,e,t){return e&&Md(u.prototype,e),t&&Md(u,t),u}function pv(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&Qh(u,e)}function Qh(u,e){return Qh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Qh(u,e)}function mv(u){var e=yv();return function(){var r=ou(u),l;if(e){var s=ou(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return vv(this,l)}}function vv(u,e){return e&&(zo(e)==="object"||typeof e=="function")?e:Tv(u)}function Tv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function yv(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function ou(u){return ou=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},ou(u)}var Sv=It.EventEmitter,Ev=Ot,Bl=St,Cv=Ns(),Ud=jt(),ni=new Ev("RTCSession:ReferSubscriber"),Av=function(u){pv(t,u);var e=mv(t);function t(r){var l;return _v(this,t),l=e.call(this),l._id=null,l._session=r,l}return gv(t,[{key:"sendRefer",value:function(l){var s=this,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ni.debug("sendRefer()");var f=Ud.cloneArray(i.extraHeaders),h=Ud.cloneObject(i.eventHandlers);for(var d in h)Object.prototype.hasOwnProperty.call(h,d)&&this.on(d,h[d]);var p=null;i.replaces&&(p=i.replaces._request.call_id,p+=";to-tag=".concat(i.replaces._to_tag),p+=";from-tag=".concat(i.replaces._from_tag),p=encodeURIComponent(p));var v="Refer-To: <".concat(l).concat(p?"?Replaces=".concat(p):"",">");if(f.push(v),!f.some(function(S){return S.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,">");f.push(T)}f.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(Bl.REFER,{extraHeaders:f,eventHandlers:{onSuccessResponse:function(A){s._requestSucceeded(A)},onErrorResponse:function(A){s._requestFailed(A,Bl.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,Bl.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,Bl.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,Bl.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(l){if(ni.debug("receiveNotify()"),!!l.body){var s=Cv.parse(l.body.trim().split(`\r
49
- `,1)[0],"Status_Line");if(s===-1){ni.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(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}}}},{key:"_requestSucceeded",value:function(l){ni.debug("REFER succeeded"),ni.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:l})}},{key:"_requestFailed",value:function(l,s){ni.debug("REFER failed"),ni.debug('emit "requestFailed"'),this.emit("requestFailed",{response:l||null,cause:s})}},{key:"id",get:function(){return this._id}}]),t}(Sv);function Xo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Xo=function(t){return typeof t}:Xo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Xo(u)}function $s(u,e){var t;if(typeof Symbol>"u"||u[Symbol.iterator]==null){if(Array.isArray(u)||(t=bv(u))||e&&u&&typeof u.length=="number"){t&&(u=t);var r=0,l=function(){};return{s:l,n:function(){return r>=u.length?{done:!0}:{done:!1,value:u[r++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
50
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,i=!1,f;return{s:function(){t=u[Symbol.iterator]()},n:function(){var d=t.next();return s=d.done,d},e:function(d){i=!0,f=d},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(i)throw f}}}}function bv(u,e){if(u){if(typeof u=="string")return Ld(u,e);var t=Object.prototype.toString.call(u).slice(8,-1);if(t==="Object"&&u.constructor&&(t=u.constructor.name),t==="Map"||t==="Set")return Array.from(u);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Ld(u,e)}}function Ld(u,e){(e==null||e>u.length)&&(e=u.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=u[t];return r}function Rv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Fd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function $d(u,e,t){return e&&Fd(u.prototype,e),t&&Fd(u,t),u}function wv(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&Zh(u,e)}function Zh(u,e){return Zh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Zh(u,e)}function Iv(u){var e=Nv();return function(){var r=uu(u),l;if(e){var s=uu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return Ov(this,l)}}function Ov(u,e){return e&&(Xo(e)==="object"||typeof e=="function")?e:Dv(u)}function Dv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function Nv(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function uu(u){return uu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},uu(u)}var Pv=It.EventEmitter,Hd=Qt,xv=Ot,ve=St,ii=In,Gd=Ia,tt=jt(),jl=zg,kv=zs,co=Lm,Mv=Oa,Zt=Xm,Vd=ov,Uv=dv,Lv=Av,Bd=On(),se=new xv("RTCSession"),le={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},ho=["audio","video"],Fv=function(u){wv(t,u);var e=Iv(t);$d(t,null,[{key:"C",get:function(){return le}}]);function t(r){var l;return Rv(this,t),se.debug("new"),l=e.call(this),l._id=null,l._ua=r,l._status=le.STATUS_NULL,l._dialog=null,l._earlyDialogs={},l._contact=null,l._from_tag=null,l._to_tag=null,l._connection=null,l._connectionPromiseQueue=Promise.resolve(),l._request=null,l._is_canceled=!1,l._cancel_reason="",l._is_confirmed=!1,l._late_sdp=!1,l._rtcOfferConstraints=null,l._rtcAnswerConstraints=null,l._localMediaStream=null,l._localMediaStreamLocallyGenerated=!1,l._rtcReady=!0,l._iceReady=!1,l._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},l._direction=null,l._local_identity=null,l._remote_identity=null,l._start_time=null,l._end_time=null,l._tones=null,l._audioMuted=!1,l._videoMuted=!1,l._localHold=!1,l._remoteHold=!1,l._sessionTimers={enabled:l._ua.configuration.session_timers,refreshMethod:l._ua.configuration.session_timers_refresh_method,defaultExpires:ve.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},l._referSubscribers={},l._data={},l}return $d(t,[{key:"isInProgress",value:function(){switch(this._status){case le.STATUS_NULL:case le.STATUS_INVITE_SENT:case le.STATUS_1XX_RECEIVED:case le.STATUS_INVITE_RECEIVED:case le.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case le.STATUS_ANSWERED:case le.STATUS_WAITING_FOR_ACK:case le.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case le.STATUS_CANCELED:case le.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(l){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;se.debug("connect()");var f=l,h=tt.cloneObject(s.eventHandlers),d=tt.cloneArray(s.extraHeaders),p=tt.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),v=s.mediaStream||null,T=tt.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,S=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=S,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,l===void 0)throw new TypeError("Not enough arguments");if(this._status!==le.STATUS_NULL)throw new ii.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new ii.NotSupportedError("WebRTC not supported");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError("Invalid target: ".concat(f));this._sessionTimers.enabled&&tt.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ve.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ve.SESSION_EXPIRES);for(var A in h)Object.prototype.hasOwnProperty.call(h,A)&&this.on(A,h[A]);this._from_tag=tt.newTag();var R=s.anonymous||!1,O={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:R,outbound:!0}),R?(O.from_display_name="Anonymous",O.from_uri=new Bd("sip","anonymous","anonymous.invalid"),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),d.push("Privacy: id")):s.fromUserName&&(O.from_uri=new Bd("sip",s.fromUserName,this._ua.configuration.uri.host),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(O.from_display_name=s.fromDisplayName),d.push("Contact: ".concat(this._contact)),d.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&d.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new kv.InitialOutgoingInviteRequest(l,this._ua,O,d),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,i&&i(this),this._newRTCSession("local",this._request),this._sendInitialRequest(p,S,v)}},{key:"init_incoming",value:function(l,s){var i=this;se.debug("init_incoming()");var f,h=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0;if(l.body&&h!=="application/sdp"){l.reply(415);return}if(this._status=le.STATUS_INVITE_RECEIVED,this._from_tag=l.from_tag,this._id=l.call_id+this._from_tag,this._request=l,this._contact=this._ua.contact.toString(),l.hasHeader("expires")&&(f=l.getHeader("expires")*1e3),l.to_tag=tt.newTag(),!this._createDialog(l,"UAS",!0)){l.reply(500,"Missing Contact header field");return}l.body?this._late_sdp=!1:this._late_sdp=!0,this._status=le.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){l.reply(408),i._failed("local",null,ve.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),f&&(this._timers.expiresTimer=setTimeout(function(){i._status===le.STATUS_WAITING_FOR_ANSWER&&(l.reply(487),i._failed("system",null,ve.causes.EXPIRES))},f)),this._direction="incoming",this._local_identity=l.to,this._remote_identity=l.from,s&&s(this),this._newRTCSession("remote",l),this._status!==le.STATUS_TERMINATED&&(l.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};se.debug("answer()");var i=this._request,f=tt.cloneArray(s.extraHeaders),h=tt.cloneObject(s.mediaConstraints),d=s.mediaStream||null,p=tt.cloneObject(s.pcConfig,{iceServers:[]}),v=s.rtcConstraints||null,T=s.rtcAnswerConstraints||null,y=tt.cloneObject(s.rtcOfferConstraints),S,A=!1,R=!1,O=!1,N=!1;if(this._rtcAnswerConstraints=T,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new ii.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==le.STATUS_WAITING_FOR_ANSWER)throw new ii.InvalidStateError(this._status);if(this._sessionTimers.enabled&&tt.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ve.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ve.SESSION_EXPIRES),this._status=le.STATUS_ANSWERED,!this._createDialog(i,"UAS")){i.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),f.unshift("Contact: ".concat(this._contact));var C=i.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);var b=$s(C.media),w;try{for(b.s();!(w=b.n()).done;){var F=w.value;F.type==="audio"&&(A=!0,(!F.direction||F.direction==="sendrecv")&&(O=!0)),F.type==="video"&&(R=!0,(!F.direction||F.direction==="sendrecv")&&(N=!0))}}catch(B){b.e(B)}finally{b.f()}if(d&&h.audio===!1){S=d.getAudioTracks();var q=$s(S),D;try{for(q.s();!(D=q.n()).done;){var P=D.value;d.removeTrack(P)}}catch(B){q.e(B)}finally{q.f()}}if(d&&h.video===!1){S=d.getVideoTracks();var I=$s(S),x;try{for(I.s();!(x=I.n()).done;){var U=x.value;d.removeTrack(U)}}catch(B){I.e(B)}finally{I.f()}}!d&&h.audio===void 0&&(h.audio=O),!d&&h.video===void 0&&(h.video=N),!d&&!A&&!y.offerToReceiveAudio&&(h.audio=!1),!d&&!R&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(p,v),Promise.resolve().then(function(){if(d)return d;if(h.audio||h.video)return l._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(B){throw l._status===le.STATUS_TERMINATED?new Error("terminated"):(i.reply(480),l._failed("local",null,ve.causes.USER_DENIED_MEDIA_ACCESS),se.warn('emit "getusermediafailed" [error:%o]',B),l.emit("getusermediafailed",B),new Error("getUserMedia() failed"))})}).then(function(B){if(l._status===le.STATUS_TERMINATED)throw new Error("terminated");l._localMediaStream=B,B&&B.getTracks().forEach(function(z){l._connection.addTrack(z,B)})}).then(function(){if(!l._late_sdp){var B={originator:"remote",type:"offer",sdp:i.body};se.debug('emit "sdp"'),l.emit("sdp",B);var z=new RTCSessionDescription({type:"offer",sdp:B.sdp});return l._connectionPromiseQueue=l._connectionPromiseQueue.then(function(){return l._connection.setRemoteDescription(z)}).catch(function(L){throw i.reply(488),l._failed("system",null,ve.causes.WEBRTC_ERROR),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',L),l.emit("peerconnection:setremotedescriptionfailed",L),new Error("peerconnection.setRemoteDescription() failed")}),l._connectionPromiseQueue}}).then(function(){if(l._status===le.STATUS_TERMINATED)throw new Error("terminated");return l._connecting(i),l._late_sdp?l._createLocalDescription("offer",l._rtcOfferConstraints).catch(function(){throw i.reply(500),new Error("_createLocalDescription() failed")}):l._createLocalDescription("answer",T).catch(function(){throw i.reply(500),new Error("_createLocalDescription() failed")})}).then(function(B){if(l._status===le.STATUS_TERMINATED)throw new Error("terminated");l._handleSessionTimersInIncomingRequest(i,f),i.reply(200,null,f,B,function(){l._status=le.STATUS_WAITING_FOR_ACK,l._setInvite2xxTimer(i,B),l._setACKTimer(),l._accepted("local")},function(){l._failed("system",null,ve.causes.CONNECTION_ERROR)})}).catch(function(B){l._status!==le.STATUS_TERMINATED&&se.warn(B)})}},{key:"terminate",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};se.debug("terminate()");var i=s.cause||ve.causes.BYE,f=tt.cloneArray(s.extraHeaders),h=s.body,d,p=s.status_code,v=s.reason_phrase;if(this._status===le.STATUS_TERMINATED)throw new ii.InvalidStateError(this._status);switch(this._status){case le.STATUS_NULL:case le.STATUS_INVITE_SENT:case le.STATUS_1XX_RECEIVED:if(se.debug("canceling session"),p&&(p<200||p>=700))throw new TypeError("Invalid status_code: ".concat(p));p&&(v=v||ve.REASON_PHRASE[p]||"",d="SIP ;cause=".concat(p,' ;text="').concat(v,'"')),this._status===le.STATUS_NULL||this._status===le.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=d):this._status===le.STATUS_1XX_RECEIVED&&this._request.cancel(d),this._status=le.STATUS_CANCELED,this._failed("local",null,ve.causes.CANCELED);break;case le.STATUS_WAITING_FOR_ANSWER:case le.STATUS_ANSWERED:if(se.debug("rejecting session"),p=p||480,p<300||p>=700)throw new TypeError("Invalid status_code: ".concat(p));this._request.reply(p,v,f,h),this._failed("local",null,ve.causes.REJECTED);break;case le.STATUS_WAITING_FOR_ACK:case le.STATUS_CONFIRMED:if(se.debug("terminating session"),v=s.reason_phrase||ve.REASON_PHRASE[p]||"",p&&(p<200||p>=700))throw new TypeError("Invalid status_code: ".concat(p));if(p&&f.push("Reason: SIP ;cause=".concat(p,'; text="').concat(v,'"')),this._status===le.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gd.C.STATUS_TERMINATED){var T=this._dialog;this.receiveRequest=function(y){var S=y.method;S===ve.ACK&&(l.sendRequest(ve.BYE,{extraHeaders:f,body:h}),T.terminate())},this._request.server_transaction.on("stateChanged",function(){l._request.server_transaction.state===Gd.C.STATUS_TERMINATED&&(l.sendRequest(ve.BYE,{extraHeaders:f,body:h}),T.terminate())}),this._ended("local",null,i),this._dialog=T,this._ua.newDialog(T)}else this.sendRequest(ve.BYE,{extraHeaders:f,body:h}),this._ended("local",null,i)}}},{key:"sendDTMF",value:function(l){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};se.debug("sendDTMF() | tones: %s",l);var i=0,f=s.duration||null,h=s.interToneGap||null,d=s.transportType||ve.DTMF_TRANSPORT.INFO;if(l===void 0)throw new TypeError("Not enough arguments");if(this._status!==le.STATUS_CONFIRMED&&this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_1XX_RECEIVED)throw new ii.InvalidStateError(this._status);if(d!==ve.DTMF_TRANSPORT.INFO&&d!==ve.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(d));if(typeof l=="number"&&(l=l.toString()),!l||typeof l!="string"||!l.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(l));if(f&&!tt.isDecimal(f))throw new TypeError("Invalid tone duration: ".concat(f));if(f?f<Zt.C.MIN_DURATION?(se.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(Zt.C.MIN_DURATION," milliseconds")),f=Zt.C.MIN_DURATION):f>Zt.C.MAX_DURATION?(se.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(Zt.C.MAX_DURATION," milliseconds")),f=Zt.C.MAX_DURATION):f=Math.abs(f):f=Zt.C.DEFAULT_DURATION,s.duration=f,h&&!tt.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<Zt.C.MIN_INTER_TONE_GAP?(se.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(Zt.C.MIN_INTER_TONE_GAP," milliseconds")),h=Zt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=Zt.C.DEFAULT_INTER_TONE_GAP,d===ve.DTMF_TRANSPORT.RFC2833){var p=this._getDTMFRTPSender();p&&(l=p.toneBuffer+l,p.insertDTMF(l,f,h));return}if(this._tones){this._tones+=l;return}this._tones=l,v.call(this);function v(){var T=this,y;if(this._status===le.STATUS_TERMINATED||!this._tones||i>=this._tones.length){this._tones=null;return}var S=this._tones[i];if(i+=1,S===",")y=2e3;else{var A=new Zt(this);s.eventHandlers={onFailed:function(){T._tones=null}},A.send(S,s),y=f+h}setTimeout(v.bind(this),y)}}},{key:"sendInfo",value:function(l,s){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(se.debug("sendInfo()"),this._status!==le.STATUS_CONFIRMED&&this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_1XX_RECEIVED)throw new ii.InvalidStateError(this._status);var f=new Vd(this);f.send(l,s,i)}},{key:"mute",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};se.debug("mute()");var s=!1,i=!1;this._audioMuted===!1&&l.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&l.video&&(i=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||i===!0)&&this._onmute({audio:s,video:i})}},{key:"unmute",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};se.debug("unmute()");var s=!1,i=!1;this._audioMuted===!0&&l.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&l.video&&(i=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||i===!0)&&this._onunmute({audio:s,video:i})}},{key:"hold",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=arguments.length>1?arguments[1]:void 0;if(se.debug("hold()"),this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var f={succeeded:function(){i&&i()},failed:function(){l.terminate({cause:ve.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:f,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:f,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=arguments.length>1?arguments[1]:void 0;if(se.debug("unhold()"),this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var f={succeeded:function(){i&&i()},failed:function(){l.terminate({cause:ve.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:f,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:f,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=arguments.length>1?arguments[1]:void 0;se.debug("renegotiate()");var f=s.rtcOfferConstraints||null;if(this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){i&&i()},failed:function(){l.terminate({cause:ve.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:f,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:f,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(l,s){var i=this;se.debug("refer()");var f=l;if(this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED)return!1;if(l=this._ua.normalizeTarget(l),!l)throw new TypeError("Invalid target: ".concat(f));var h=new Lv(this);h.sendRefer(l,s);var d=h.id;return this._referSubscribers[d]=h,h.on("requestFailed",function(){delete i._referSubscribers[d]}),h.on("accepted",function(){delete i._referSubscribers[d]}),h.on("failed",function(){delete i._referSubscribers[d]}),h}},{key:"sendRequest",value:function(l,s){return se.debug("sendRequest()"),this._dialog.sendRequest(l,s)}},{key:"receiveRequest",value:function(l){var s=this;if(se.debug("receiveRequest()"),l.method===ve.CANCEL)(this._status===le.STATUS_WAITING_FOR_ANSWER||this._status===le.STATUS_ANSWERED)&&(this._status=le.STATUS_CANCELED,this._request.reply(487),this._failed("remote",l,ve.causes.CANCELED));else switch(l.method){case ve.ACK:if(this._status!==le.STATUS_WAITING_FOR_ACK)return;if(this._status=le.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!l.body){this.terminate({cause:ve.causes.MISSING_SDP,status_code:400});break}var i={originator:"remote",type:"answer",sdp:l.body};se.debug('emit "sdp"'),this.emit("sdp",i);var f=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(f)}).then(function(){s._is_confirmed||s._confirmed("remote",l)}).catch(function(d){s.terminate({cause:ve.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',d),s.emit("peerconnection:setremotedescriptionfailed",d)})}else this._is_confirmed||this._confirmed("remote",l);break;case ve.BYE:this._status===le.STATUS_CONFIRMED||this._status===le.STATUS_WAITING_FOR_ACK?(l.reply(200),this._ended("remote",l,ve.causes.BYE)):this._status===le.STATUS_INVITE_RECEIVED||this._status===le.STATUS_WAITING_FOR_ANSWER?(l.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",l,ve.causes.BYE)):l.reply(403,"Wrong Status");break;case ve.INVITE:this._status===le.STATUS_CONFIRMED?l.hasHeader("replaces")?this._receiveReplaces(l):this._receiveReinvite(l):l.reply(403,"Wrong Status");break;case ve.INFO:if(this._status===le.STATUS_1XX_RECEIVED||this._status===le.STATUS_WAITING_FOR_ANSWER||this._status===le.STATUS_ANSWERED||this._status===le.STATUS_WAITING_FOR_ACK||this._status===le.STATUS_CONFIRMED){var h=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new Zt(this).init_incoming(l):h!==void 0?new Vd(this).init_incoming(l):l.reply(415)}else l.reply(403,"Wrong Status");break;case ve.UPDATE:this._status===le.STATUS_CONFIRMED?this._receiveUpdate(l):l.reply(403,"Wrong Status");break;case ve.REFER:this._status===le.STATUS_CONFIRMED?this._receiveRefer(l):l.reply(403,"Wrong Status");break;case ve.NOTIFY:this._status===le.STATUS_CONFIRMED?this._receiveNotify(l):l.reply(403,"Wrong Status");break;default:l.reply(501)}}},{key:"onTransportError",value:function(){se.warn("onTransportError()"),this._status!==le.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ve.causes.CONNECTION_ERROR,cause:ve.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){se.warn("onRequestTimeout()"),this._status!==le.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ve.causes.REQUEST_TIMEOUT,cause:ve.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){se.warn("onDialogError()"),this._status!==le.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ve.causes.DIALOG_ERROR,cause:ve.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(l){se.debug("newDTMF()"),this.emit("newDTMF",l)}},{key:"newInfo",value:function(l){se.debug("newInfo()"),this.emit("newInfo",l)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(se.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(se.debug("_isReadyToReOffer() | session not established yet"),!1):(se.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(se.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(se.debug("close() | closing local MediaStream"),tt.closeMediaStream(this._localMediaStream)),this._status!==le.STATUS_TERMINATED){if(this._status=le.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(f){se.warn("close() | error closing the RTCPeerConnection: %o",f)}for(var l in this._timers)Object.prototype.hasOwnProperty.call(this._timers,l)&&clearTimeout(this._timers[l]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var i in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,i)&&delete this._referSubscribers[i];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(l,s){var i=jl.T1;function f(){this._status===le.STATUS_WAITING_FOR_ACK&&(l.reply(200,null,["Contact: ".concat(this._contact)],s),i<jl.T2&&(i=i*2,i>jl.T2&&(i=jl.T2)),this._timers.invite2xxTimer=setTimeout(f.bind(this),i))}this._timers.invite2xxTimer=setTimeout(f.bind(this),i)}},{key:"_setACKTimer",value:function(){var l=this;this._timers.ackTimer=setTimeout(function(){l._status===le.STATUS_WAITING_FOR_ACK&&(se.debug("no ACK received, terminating the session"),clearTimeout(l._timers.invite2xxTimer),l.sendRequest(ve.BYE),l._ended("remote",null,ve.causes.NO_ACK))},jl.TIMER_H)}},{key:"_createRTCConnection",value:function(l,s){var i=this;this._connection=new RTCPeerConnection(l,s),this._connection.addEventListener("iceconnectionstatechange",function(){var f=i._connection.iceConnectionState;f==="failed"&&i.terminate({cause:ve.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ve.causes.RTP_TIMEOUT})}),se.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(l,s){var i=this;if(se.debug("createLocalDescription()"),l!=="offer"&&l!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(l,'"'));var f=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return l==="offer"?f.createOffer(s).catch(function(h){return se.warn('emit "peerconnection:createofferfailed" [error:%o]',h),i.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):f.createAnswer(s).catch(function(h){return se.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),i.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return f.setLocalDescription(h).catch(function(d){return i._rtcReady=!0,se.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',d),i.emit("peerconnection:setlocaldescriptionfailed",d),Promise.reject(d)})}).then(function(){var h=s&&s.iceRestart;if(f.iceGatheringState==="complete"&&!h||f.iceGatheringState==="gathering"&&i._iceReady){i._rtcReady=!0;var d={originator:"local",type:l,sdp:f.localDescription.sdp};return se.debug('emit "sdp"'),i.emit("sdp",d),Promise.resolve(d.sdp)}return new Promise(function(p){var v=!1,T,y;i._iceReady=!1;var S=function(){f.removeEventListener("icecandidate",T),f.removeEventListener("icegatheringstatechange",y),v=!0,i._rtcReady=!0,i._iceReady=!0;var R={originator:"local",type:l,sdp:f.localDescription.sdp};se.debug('emit "sdp"'),i.emit("sdp",R),p(R.sdp)};f.addEventListener("icecandidate",T=function(R){var O=R.candidate;O?i.emit("icecandidate",{candidate:O,ready:S}):v||S()}),f.addEventListener("icegatheringstatechange",y=function(){f.iceGatheringState==="complete"&&!v&&S()})})})}},{key:"_createDialog",value:function(l,s,i){var f=s==="UAS"?l.to_tag:l.from_tag,h=s==="UAS"?l.from_tag:l.to_tag,d=l.call_id+f+h,p=this._earlyDialogs[d];if(i)return p?!0:(p=new co(this,l,s,co.C.STATUS_EARLY),p.error?(se.debug(p.error),this._failed("remote",l,ve.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[d]=p,!0));if(this._from_tag=l.from_tag,this._to_tag=l.to_tag,p)return p.update(l,s),this._dialog=p,delete this._earlyDialogs[d],!0;var v=new co(this,l,s);return v.error?(se.debug(v.error),this._failed("remote",l,ve.causes.INTERNAL_ERROR),!1):(this._dialog=v,!0)}},{key:"_receiveReinvite",value:function(l){var s=this;se.debug("receiveReinvite()");var i=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0,f={request:l,callback:void 0,reject:d.bind(this)},h=!1;function d(){var v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var T=v.status_code||403,y=v.reason_phrase||"",S=tt.cloneArray(v.extraHeaders);if(this._status!==le.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));l.reply(T,y,S)}if(this.emit("reinvite",f),h)return;if(this._late_sdp=!1,!l.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(v){p.call(s,v)}).catch(function(){l.reply(500)});return}if(i!=="application/sdp"){se.debug("invalid Content-Type"),l.reply(415);return}this._processInDialogSdpOffer(l).then(function(v){s._status!==le.STATUS_TERMINATED&&p.call(s,v)}).catch(function(v){se.warn(v)});function p(v){var T=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(l,y),this._late_sdp&&(v=this._mangleOffer(v)),l.reply(200,null,y,v,function(){T._status=le.STATUS_WAITING_FOR_ACK,T._setInvite2xxTimer(l,v),T._setACKTimer()}),typeof f.callback=="function"&&f.callback()}}},{key:"_receiveUpdate",value:function(l){var s=this;se.debug("receiveUpdate()");var i=l.hasHeader("Content-Type")?l.getHeader("Content-Type").toLowerCase():void 0,f={request:l,callback:void 0,reject:d.bind(this)},h=!1;function d(){var v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var T=v.status_code||403,y=v.reason_phrase||"",S=tt.cloneArray(v.extraHeaders);if(this._status!==le.STATUS_CONFIRMED)return!1;if(T<300||T>=700)throw new TypeError("Invalid status_code: ".concat(T));l.reply(T,y,S)}if(this.emit("update",f),h)return;if(!l.body){p.call(this,null);return}if(i!=="application/sdp"){se.debug("invalid Content-Type"),l.reply(415);return}this._processInDialogSdpOffer(l).then(function(v){s._status!==le.STATUS_TERMINATED&&p.call(s,v)}).catch(function(v){se.warn(v)});function p(v){var T=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(l,T),l.reply(200,null,T,v),typeof f.callback=="function"&&f.callback()}}},{key:"_processInDialogSdpOffer",value:function(l){var s=this;se.debug("_processInDialogSdpOffer()");var i=l.parseSDP(),f=!1,h=$s(i.media),d;try{for(h.s();!(d=h.n()).done;){var p=d.value;if(ho.indexOf(p.type)!==-1){var v=p.direction||i.direction||"sendrecv";if(v==="sendonly"||v==="inactive")f=!0;else{f=!1;break}}}}catch(S){h.e(S)}finally{h.f()}var T={originator:"remote",type:"offer",sdp:l.body};se.debug('emit "sdp"'),this.emit("sdp",T);var y=new RTCSessionDescription({type:"offer",sdp:T.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===le.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(S){throw l.reply(488),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),s.emit("peerconnection:setremotedescriptionfailed",S),S})}).then(function(){if(s._status===le.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&f===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&f===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===le.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(S){throw l.reply(500),se.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',S),S})}).catch(function(S){se.warn("_processInDialogSdpOffer() failed [error: %o]",S)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(l){var s=this;if(se.debug("receiveRefer()"),!l.refer_to){se.debug("no Refer-To header field present in REFER"),l.reply(400);return}if(l.refer_to.uri.scheme!==ve.SIP){se.debug("Refer-To header field points to a non-SIP URI scheme"),l.reply(416);return}l.reply(202);var i=new Uv(this,l.cseq);se.debug('emit "refer"'),this.emit("refer",{request:l,accept:function(p,v){f.call(s,p,v)},reject:function(){h.call(s)}});function f(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(d=typeof d=="function"?d:null,this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED)return!1;var v=new t(this._ua);if(v.on("progress",function(y){var S=y.response;i.notify(S.status_code,S.reason_phrase)}),v.on("accepted",function(y){var S=y.response;i.notify(S.status_code,S.reason_phrase)}),v.on("_failed",function(y){var S=y.message,A=y.cause;S?i.notify(S.status_code,S.reason_phrase):i.notify(487,A)}),l.refer_to.uri.hasHeader("replaces")){var T=decodeURIComponent(l.refer_to.uri.getHeader("replaces"));p.extraHeaders=tt.cloneArray(p.extraHeaders),p.extraHeaders.push("Replaces: ".concat(T))}v.connect(l.refer_to.uri.toAor(),p,d)}function h(){i.notify(603)}}},{key:"_receiveNotify",value:function(l){switch(se.debug("receiveNotify()"),l.event||l.reply(400),l.event.event){case"refer":{var s,i;if(l.event.params&&l.event.params.id)s=l.event.params.id,i=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)i=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{l.reply(400,"Missing event id parameter");return}if(!i){l.reply(481,"Subscription does not exist");return}i.receiveNotify(l),l.reply(200);break}default:l.reply(489)}}},{key:"_receiveReplaces",value:function(l){var s=this;se.debug("receiveReplaces()");function i(h){var d=this;if(this._status!==le.STATUS_WAITING_FOR_ACK&&this._status!==le.STATUS_CONFIRMED)return!1;var p=new t(this._ua);p.on("confirmed",function(){d.terminate()}),p.init_incoming(l,h)}function f(){se.debug("Replaced INVITE rejected by the user"),l.reply(486)}this.emit("replaces",{request:l,accept:function(d){i.call(s,d)},reject:function(){f.call(s)}})}},{key:"_sendInitialRequest",value:function(l,s,i){var f=this,h=new Mv(this._ua,this._request,{onRequestTimeout:function(){f.onRequestTimeout()},onTransportError:function(){f.onTransportError()},onAuthenticated:function(p){f._request=p},onReceiveResponse:function(p){f._receiveInviteResponse(p)}});Promise.resolve().then(function(){if(i)return i;if(l.audio||l.video)return f._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(l).catch(function(d){throw f._status===le.STATUS_TERMINATED?new Error("terminated"):(f._failed("local",null,ve.causes.USER_DENIED_MEDIA_ACCESS),se.warn('emit "getusermediafailed" [error:%o]',d),f.emit("getusermediafailed",d),d)})}).then(function(d){if(f._status===le.STATUS_TERMINATED)throw new Error("terminated");return f._localMediaStream=d,d&&d.getTracks().forEach(function(p){f._connection.addTrack(p,d)}),f._connecting(f._request),f._createLocalDescription("offer",s).catch(function(p){throw f._failed("local",null,ve.causes.WEBRTC_ERROR),p})}).then(function(d){if(f._is_canceled||f._status===le.STATUS_TERMINATED)throw new Error("terminated");f._request.body=d,f._status=le.STATUS_INVITE_SENT,se.debug('emit "sending" [request:%o]',f._request),f.emit("sending",{request:f._request}),h.send()}).catch(function(d){f._status!==le.STATUS_TERMINATED&&se.warn(d)})}},{key:"_getDTMFRTPSender",value:function(){var l=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(l&&l.dtmf)){se.warn("sendDTMF() | no local audio track to send DTMF with");return}return l.dtmf}},{key:"_receiveInviteResponse",value:function(l){var s=this;if(se.debug("receiveInviteResponse()"),this._dialog&&l.status_code>=200&&l.status_code<=299)if(this._dialog.id.call_id===l.call_id&&this._dialog.id.local_tag===l.from_tag&&this._dialog.id.remote_tag===l.to_tag){this.sendRequest(ve.ACK);return}else{var i=new co(this,l,"UAC");if(i.error!==void 0){se.debug(i.error);return}this.sendRequest(ve.ACK),this.sendRequest(ve.BYE);return}if(this._is_canceled){l.status_code>=100&&l.status_code<200?this._request.cancel(this._cancel_reason):l.status_code>=200&&l.status_code<299&&this._acceptAndTerminate(l);return}if(!(this._status!==le.STATUS_INVITE_SENT&&this._status!==le.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(l.status_code):this._status=le.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(l.status_code):{if(!l.to_tag){se.debug("1xx response received without to tag");break}if(l.hasHeader("contact")&&!this._createDialog(l,"UAC",!0))break;if(this._status=le.STATUS_1XX_RECEIVED,!l.body){this._progress("remote",l);break}var f={originator:"remote",type:"answer",sdp:l.body};se.debug('emit "sdp"'),this.emit("sdp",f);var h=new RTCSessionDescription({type:"answer",sdp:f.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",l)}).catch(function(T){se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),s.emit("peerconnection:setremotedescriptionfailed",T)});break}case/^2[0-9]{2}$/.test(l.status_code):{if(this._status=le.STATUS_CONFIRMED,!l.body){this._acceptAndTerminate(l,400,ve.causes.MISSING_SDP),this._failed("remote",l,ve.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(l,"UAC"))break;var d={originator:"remote",type:"answer",sdp:l.body};se.debug('emit "sdp"'),this.emit("sdp",d);var p=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(T){return s._connection.setLocalDescription(T)}).catch(function(T){s._acceptAndTerminate(l,500,T.toString()),s._failed("local",l,ve.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(p).then(function(){s._handleSessionTimersInIncomingResponse(l),s._accepted("remote",l),s.sendRequest(ve.ACK),s._confirmed("local",null)}).catch(function(T){s._acceptAndTerminate(l,488,"Not Acceptable Here"),s._failed("remote",l,ve.causes.BAD_MEDIA_DESCRIPTION),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),s.emit("peerconnection:setremotedescriptionfailed",T)})});break}default:{var v=tt.sipErrorCause(l.status_code);this._failed("remote",l,v)}}}},{key:"_sendReinvite",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};se.debug("sendReinvite()");var i=tt.cloneArray(s.extraHeaders),f=tt.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,d=!1;i.push("Contact: ".concat(this._contact)),i.push("Content-Type: application/sdp"),this._sessionTimers.running&&i.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return l._createLocalDescription("offer",h)}).then(function(T){T=l._mangleOffer(T);var y={originator:"local",type:"offer",sdp:T};se.debug('emit "sdp"'),l.emit("sdp",y),l.sendRequest(ve.INVITE,{extraHeaders:i,body:T,eventHandlers:{onSuccessResponse:function(A){p.call(l,A),d=!0},onErrorResponse:function(A){v.call(l,A)},onTransportError:function(){l.onTransportError()},onRequestTimeout:function(){l.onRequestTimeout()},onDialogError:function(){l.onDialogError()}}})}).catch(function(){v()});function p(T){var y=this;if(this._status!==le.STATUS_TERMINATED&&(this.sendRequest(ve.ACK),!d)){if(this._handleSessionTimersInIncomingResponse(T),T.body){if(!T.hasHeader("Content-Type")||T.getHeader("Content-Type").toLowerCase()!=="application/sdp"){v.call(this);return}}else{v.call(this);return}var S={originator:"remote",type:"answer",sdp:T.body};se.debug('emit "sdp"'),this.emit("sdp",S);var A=new RTCSessionDescription({type:"answer",sdp:S.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(A)}).then(function(){f.succeeded&&f.succeeded(T)}).catch(function(R){v.call(y),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',R),y.emit("peerconnection:setremotedescriptionfailed",R)})}}function v(T){f.failed&&f.failed(T)}}},{key:"_sendUpdate",value:function(){var l=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};se.debug("sendUpdate()");var i=tt.cloneArray(s.extraHeaders),f=tt.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,d=s.sdpOffer||!1,p=!1;i.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&i.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),d?(i.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return l._createLocalDescription("offer",h)}).then(function(y){y=l._mangleOffer(y);var S={originator:"local",type:"offer",sdp:y};se.debug('emit "sdp"'),l.emit("sdp",S),l.sendRequest(ve.UPDATE,{extraHeaders:i,body:y,eventHandlers:{onSuccessResponse:function(R){v.call(l,R),p=!0},onErrorResponse:function(R){T.call(l,R)},onTransportError:function(){l.onTransportError()},onRequestTimeout:function(){l.onRequestTimeout()},onDialogError:function(){l.onDialogError()}}})}).catch(function(){T.call(l)})):this.sendRequest(ve.UPDATE,{extraHeaders:i,eventHandlers:{onSuccessResponse:function(S){v.call(l,S)},onErrorResponse:function(S){T.call(l,S)},onTransportError:function(){l.onTransportError()},onRequestTimeout:function(){l.onRequestTimeout()},onDialogError:function(){l.onDialogError()}}});function v(y){var S=this;if(this._status!==le.STATUS_TERMINATED&&!p)if(this._handleSessionTimersInIncomingResponse(y),d){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 A={originator:"remote",type:"answer",sdp:y.body};se.debug('emit "sdp"'),this.emit("sdp",A);var R=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return S._connection.setRemoteDescription(R)}).then(function(){f.succeeded&&f.succeeded(y)}).catch(function(O){T.call(S),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',O),S.emit("peerconnection:setremotedescriptionfailed",O)})}else f.succeeded&&f.succeeded(y)}function T(y){f.failed&&f.failed(y)}}},{key:"_acceptAndTerminate",value:function(l,s,i){se.debug("acceptAndTerminate()");var f=[];s&&(i=i||ve.REASON_PHRASE[s]||"",f.push("Reason: SIP ;cause=".concat(s,'; text="').concat(i,'"'))),(this._dialog||this._createDialog(l,"UAC"))&&(this.sendRequest(ve.ACK),this.sendRequest(ve.BYE,{extraHeaders:f})),this._status=le.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(l){if(!this._localHold&&!this._remoteHold)return l;if(l=Hd.parse(l),this._localHold&&!this._remoteHold){se.debug("mangleOffer() | me on hold, mangling offer");var s=$s(l.media),i;try{for(s.s();!(i=s.n()).done;){var f=i.value;ho.indexOf(f.type)!==-1&&(f.direction?f.direction==="sendrecv"?f.direction="sendonly":f.direction==="recvonly"&&(f.direction="inactive"):f.direction="sendonly")}}catch(S){s.e(S)}finally{s.f()}}else if(this._localHold&&this._remoteHold){se.debug("mangleOffer() | both on hold, mangling offer");var h=$s(l.media),d;try{for(h.s();!(d=h.n()).done;){var p=d.value;ho.indexOf(p.type)!==-1&&(p.direction="inactive")}}catch(S){h.e(S)}finally{h.f()}}else if(this._remoteHold){se.debug("mangleOffer() | remote on hold, mangling offer");var v=$s(l.media),T;try{for(v.s();!(T=v.n()).done;){var y=T.value;ho.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(S){v.e(S)}finally{v.f()}}return Hd.write(l)}},{key:"_setLocalMediaStatus",value:function(){var l=!0,s=!0;(this._localHold||this._remoteHold)&&(l=!1,s=!1),this._audioMuted&&(l=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!l),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(l,s){if(this._sessionTimers.enabled){var i;l.session_expires&&l.session_expires>=ve.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=l.session_expires,i=l.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(i)),this._sessionTimers.refresher=i==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(l){if(this._sessionTimers.enabled){var s;l.session_expires&&l.session_expires>=ve.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=l.session_expires,s=l.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var l=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){l._status!==le.STATUS_TERMINATED&&l._isReadyToReOffer()&&(se.debug("runSessionTimer() | sending session refresh request"),l._sessionTimers.refreshMethod===ve.UPDATE?l._sendUpdate():l._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){l._status!==le.STATUS_TERMINATED&&(se.warn("runSessionTimer() | timer expired, terminating the session"),l.terminate({cause:ve.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(l){var s=this._connection.getSenders().filter(function(d){return d.track&&d.track.kind==="audio"}),i=$s(s),f;try{for(i.s();!(f=i.n()).done;){var h=f.value;h.track.enabled=!l}}catch(d){i.e(d)}finally{i.f()}}},{key:"_toggleMuteVideo",value:function(l){var s=this._connection.getSenders().filter(function(d){return d.track&&d.track.kind==="video"}),i=$s(s),f;try{for(i.s();!(f=i.n()).done;){var h=f.value;h.track.enabled=!l}}catch(d){i.e(d)}finally{i.f()}}},{key:"_newRTCSession",value:function(l,s){se.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:l,session:this,request:s})}},{key:"_connecting",value:function(l){se.debug("session connecting"),se.debug('emit "connecting"'),this.emit("connecting",{request:l})}},{key:"_progress",value:function(l,s){se.debug("session progress"),se.debug('emit "progress"'),this.emit("progress",{originator:l,response:s||null})}},{key:"_accepted",value:function(l,s){se.debug("session accepted"),this._start_time=new Date,se.debug('emit "accepted"'),this.emit("accepted",{originator:l,response:s||null})}},{key:"_confirmed",value:function(l,s){se.debug("session confirmed"),this._is_confirmed=!0,se.debug('emit "confirmed"'),this.emit("confirmed",{originator:l,ack:s||null})}},{key:"_ended",value:function(l,s,i){se.debug("session ended"),this._end_time=new Date,this._close(),se.debug('emit "ended"'),this.emit("ended",{originator:l,message:s||null,cause:i})}},{key:"_failed",value:function(l,s,i){se.debug("session failed"),se.debug('emit "_failed"'),this.emit("_failed",{originator:l,message:s||null,cause:i}),this._close(),se.debug('emit "failed"'),this.emit("failed",{originator:l,message:s||null,cause:i})}},{key:"_onhold",value:function(l){se.debug("session onhold"),this._setLocalMediaStatus(),se.debug('emit "hold"'),this.emit("hold",{originator:l})}},{key:"_onunhold",value:function(l){se.debug("session onunhold"),this._setLocalMediaStatus(),se.debug('emit "unhold"'),this.emit("unhold",{originator:l})}},{key:"_onmute",value:function(l){var s=l.audio,i=l.video;se.debug("session onmute"),this._setLocalMediaStatus(),se.debug('emit "muted"'),this.emit("muted",{audio:s,video:i})}},{key:"_onunmute",value:function(l){var s=l.audio,i=l.video;se.debug("session onunmute"),this._setLocalMediaStatus(),se.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:i})}},{key:"C",get:function(){return le}},{key:"causes",get:function(){return ve.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(l){this._data=l}},{key:"status",get:function(){return this._status}}]),t}(Pv);function Jo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Jo=function(t){return typeof t}:Jo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Jo(u)}function $v(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function jd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Hv(u,e,t){return e&&jd(u.prototype,e),t&&jd(u,t),u}function Gv(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&ef(u,e)}function ef(u,e){return ef=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},ef(u,e)}function Vv(u){var e=qv();return function(){var r=cu(u),l;if(e){var s=cu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return Bv(this,l)}}function Bv(u,e){return e&&(Jo(e)==="object"||typeof e=="function")?e:jv(u)}function jv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function qv(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function cu(u){return cu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},cu(u)}var Wv=It.EventEmitter,Kv=Ot,Xc=St,Yv=zs,ql=jt(),zv=Oa,qd=In,Xv=On(),fo=new Kv("Message"),Jv=function(u){Gv(t,u);var e=Vv(t);function t(r){var l;return $v(this,t),l=e.call(this),l._ua=r,l._request=null,l._closed=!1,l._direction=null,l._local_identity=null,l._remote_identity=null,l._is_replied=!1,l._data={},l}return Hv(t,[{key:"send",value:function(l,s){var i=this,f=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=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: ".concat(h));var d=ql.cloneArray(f.extraHeaders),p=ql.cloneObject(f.eventHandlers),v=f.contentType||"text/plain",T={};f.fromUserName&&(T.from_uri=new Xv("sip",f.fromUserName,this._ua.configuration.uri.host),d.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),f.fromDisplayName&&(T.from_display_name=f.fromDisplayName);for(var y in p)Object.prototype.hasOwnProperty.call(p,y)&&this.on(y,p[y]);d.push("Content-Type: ".concat(v)),this._request=new Yv.OutgoingRequest(Xc.MESSAGE,l,this._ua,T,d),s&&(this._request.body=s);var S=new zv(this._ua,this._request,{onRequestTimeout:function(){i._onRequestTimeout()},onTransportError:function(){i._onTransportError()},onReceiveResponse:function(R){i._receiveResponse(R)}});this._newMessage("local",this._request),S.send()}},{key:"init_incoming",value:function(l){this._request=l,this._newMessage("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}},{key:"accept",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=ql.cloneArray(l.extraHeaders),i=l.body;if(this._direction!=="incoming")throw new qd.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,i)}},{key:"reject",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=l.status_code||480,i=l.reason_phrase,f=ql.cloneArray(l.extraHeaders),h=l.body;if(this._direction!=="incoming")throw new qd.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,i,f,h)}},{key:"_receiveResponse",value:function(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:{var s=ql.sipErrorCause(l.status_code);this._failed("remote",l,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Xc.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Xc.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(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})}},{key:"_failed",value:function(l,s,i){fo.debug("MESSAGE failed"),this._close(),fo.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:i})}},{key:"_succeeded",value:function(l,s){fo.debug("MESSAGE succeeded"),this._close(),fo.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),t}(Wv);function Qo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Qo=function(t){return typeof t}:Qo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Qo(u)}function Qv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Wd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function Zv(u,e,t){return e&&Wd(u.prototype,e),t&&Wd(u,t),u}function e1(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&tf(u,e)}function tf(u,e){return tf=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},tf(u,e)}function t1(u){var e=i1();return function(){var r=hu(u),l;if(e){var s=hu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return s1(this,l)}}function s1(u,e){return e&&(Qo(e)==="object"||typeof e=="function")?e:n1(u)}function n1(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function i1(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function hu(u){return hu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},hu(u)}var r1=It.EventEmitter,l1=Ot,Jc=St,a1=zs,Wl=jt(),o1=Oa,Kd=In,_o=new l1("Options"),u1=function(u){e1(t,u);var e=t1(t);function t(r){var l;return Qv(this,t),l=e.call(this),l._ua=r,l._request=null,l._closed=!1,l._direction=null,l._local_identity=null,l._remote_identity=null,l._is_replied=!1,l._data={},l}return Zv(t,[{key:"send",value:function(l,s){var i=this,f=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=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: ".concat(h));var d=Wl.cloneArray(f.extraHeaders),p=Wl.cloneObject(f.eventHandlers),v=f.contentType||"application/sdp";for(var T in p)Object.prototype.hasOwnProperty.call(p,T)&&this.on(T,p[T]);d.push("Content-Type: ".concat(v)),this._request=new a1.OutgoingRequest(Jc.OPTIONS,l,this._ua,null,d),s&&(this._request.body=s);var y=new o1(this._ua,this._request,{onRequestTimeout:function(){i._onRequestTimeout()},onTransportError:function(){i._onTransportError()},onReceiveResponse:function(A){i._receiveResponse(A)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(l){this._request=l,this._newOptions("remote",l),this._is_replied||(this._is_replied=!0,l.reply(200)),this._close()}},{key:"accept",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Wl.cloneArray(l.extraHeaders),i=l.body;if(this._direction!=="incoming")throw new Kd.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,i)}},{key:"reject",value:function(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=l.status_code||480,i=l.reason_phrase,f=Wl.cloneArray(l.extraHeaders),h=l.body;if(this._direction!=="incoming")throw new Kd.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,i,f,h)}},{key:"_receiveResponse",value:function(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:{var s=Wl.sipErrorCause(l.status_code);this._failed("remote",l,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Jc.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Jc.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(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})}},{key:"_failed",value:function(l,s,i){_o.debug("OPTIONS failed"),this._close(),_o.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:i})}},{key:"_succeeded",value:function(l,s){_o.debug("OPTIONS succeeded"),this._close(),_o.debug('emit "succeeded"'),this.emit("succeeded",{originator:l,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),t}(r1),Of={},c1=Ot,Qc=jt(),h1=Ns(),Kl=new c1("Socket");Of.isSocket=function(u){if(Array.isArray(u))return!1;if(typeof u>"u")return Kl.warn("undefined JsSIP.Socket instance"),!1;try{if(!Qc.isString(u.url))throw Kl.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Qc.isString(u.via_transport))throw Kl.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(h1.parse(u.sip_uri,"SIP_URI")===-1)throw Kl.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(e){if(!Qc.isFunction(u[e]))throw Kl.warn("missing or invalid JsSIP.Socket method: ".concat(e)),new Error("Missing or invalid JsSIP.Socket method: ".concat(e))})}catch{return!1}return!0};function f1(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Yd(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function d1(u,e,t){return e&&Yd(u.prototype,e),t&&Yd(u,t),u}var _1=Ot,g1=Of,zd=St,zt=new _1("Transport"),ls={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:zd.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:zd.CONNECTION_RECOVERY_MAX_INTERVAL}},p1=function(){function u(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ls.recovery_options;f1(this,u),zt.debug("new()"),this.status=ls.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=t,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(r){zt.warn("cannot use TextDecoder: ".concat(r))}if(typeof e>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");e instanceof Array||(e=[e]),e.forEach(function(r){if(!g1.isSocket(r.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(r.weight&&!Number(r.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:r.socket,weight:r.weight||0,status:ls.SOCKET_STATUS_READY})},this),this._getSocket()}return d1(u,[{key:"connect",value:function(){if(zt.debug("connect()"),this.isConnected()){zt.debug("Transport is already connected");return}else if(this.isConnecting()){zt.debug("Transport is connecting");return}this.close_requested=!1,this.status=ls.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(){zt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=ls.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(t){if(zt.debug("send()"),!this.isConnected())return zt.warn("unable to send message, transport is not connected"),!1;var r=t.toString();return zt.debug(`sending message:
46
+ `),this.transport.send(d)}}]),n}(sh),kd=function(c){Nu(n,c);var t=Uu(n);function n(){var a;return il(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(sh),Ss={OutgoingRequest:th,InitialOutgoingInviteRequest:Pd,IncomingRequest:xd,IncomingResponse:kd};function Md(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function rc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ld(c,t,n){return t&&rc(c.prototype,t),n&&rc(c,n),c}var $d=ht,hs=bt(),Yt=new $d("DigestAuthentication"),Hd=function(){function c(t){Md(this,c),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return Ld(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,a){var o=n.method,s=n.ruri,r=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Yt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Yt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Yt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Yt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Yt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=o,this._uri=s,this._cnonce=d||hs.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var _,g;return this._qop==="auth"?(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(_="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var n=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return n.push("algorithm=".concat(this._algorithm)),n.push('username="'.concat(this._credentials.username,'"')),n.push('realm="'.concat(this._realm,'"')),n.push('nonce="'.concat(this._nonce,'"')),n.push('uri="'.concat(this._uri,'"')),n.push('response="'.concat(this._response,'"')),this._opaque&&n.push('opaque="'.concat(this._opaque,'"')),this._qop&&(n.push("qop=".concat(this._qop)),n.push('cnonce="'.concat(this._cnonce,'"')),n.push("nc=".concat(this._ncHex))),"Digest ".concat(n.join(", "))}}]),c}(),ds=500,Fd=4e3,ic=5e3,nh={T1:ds,T2:Fd,T4:ic,TIMER_B:64*ds,TIMER_D:0*ds,TIMER_F:64*ds,TIMER_H:64*ds,TIMER_I:0*ds,TIMER_J:0*ds,TIMER_K:0*ic,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function va(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?va=function(n){return typeof n}:va=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},va(c)}function ll(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function al(c,t,n){return t&&lc(c.prototype,t),n&&lc(c,n),c}function ol(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&fu(c,t)}function fu(c,t){return fu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},fu(c,t)}function ul(c){var t=qd();return function(){var a=Da(c),o;if(t){var s=Da(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return jd(this,o)}}function jd(c,t){return t&&(va(t)==="object"||typeof t=="function")?t:Bs(c)}function Bs(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function qd(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Da(c){return Da=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Da(c)}var cl=ft.EventEmitter,fl=ht,zi=lt,ac=Ss,ls=nh,oc=new fl("NonInviteClientTransaction"),Hl=new fl("InviteClientTransaction"),Vd=new fl("AckClientTransaction"),uc=new fl("NonInviteServerTransaction"),Fl=new fl("InviteServerTransaction"),he={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},Bd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ls.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){oc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){oc.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break}else switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(o),this.K=setTimeout(function(){s.timer_K()},ls.TIMER_K);break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Gd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r,s.transaction=Bs(d);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ls.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(Hl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Hl.debug("Timer M expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Hl.debug("Timer B expired for transaction ".concat(this.id)),this.state===he.STATUS_CALLING&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Hl.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new ac.OutgoingRequest(zi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});r.setHeader("from",this.request.getHeader("from")),r.setHeader("via",this.request.getHeader("via")),r.setHeader("to",o.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ls.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===he.STATUS_PROCEEDING){var s=new ac.OutgoingRequest(zi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),o&&s.setHeader("reason",o),this.transport.send(s)}}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r>=100&&r<=199)switch(this.state){case he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);break}else if(r>=200&&r<=299)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},ls.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);break}else if(r>=300&&r<=699)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.sendACK(o),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return he}}]),n}(cl),Wd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d}return al(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Vd.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return he}}]),n}(cl),Kd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_TRYING,a.newTransaction(Bs(r)),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){uc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,uc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case he.STATUS_TRYING:this.stateChanged(he.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case he.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=200&&o<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ls.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Yd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_PROCEEDING,a.newTransaction(Bs(r)),r.resendProvisionalTimer=null,s.reply(100),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Fl.debug("Timer H expired for transaction ".concat(this.id)),this.state===he.STATUS_COMPLETED&&Fl.debug("ACK not received, dialog will be terminated"),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Fl.debug("Timer L expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Fl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ls.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ls.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ls.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return he}}]),n}(cl);function Jd(c,t){var n=c._transactions,a;switch(t.method){case zi.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case he.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case he.STATUS_ACCEPTED:break}return!0}break;case zi.ACK:if(a=n.ist[t.via_branch],a){if(a.state===he.STATUS_ACCEPTED)return!1;if(a.state===he.STATUS_COMPLETED)return a.state=he.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ls.TIMER_I),!0}else return!1;break;case zi.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==he.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case he.STATUS_TRYING:break;case he.STATUS_PROCEEDING:case he.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var hl={C:he,NonInviteClientTransaction:Bd,InviteClientTransaction:Gd,AckClientTransaction:Wd,NonInviteServerTransaction:Kd,InviteServerTransaction:Yd,checkTransaction:Jd};function zd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Xd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Qd=ht,fc=lt,Zd=Hd,go=hl,e_=new Qd("RequestSender"),To={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},dl=function(){function c(t,n,a){zd(this,c),this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var o in To)Object.prototype.hasOwnProperty.call(To,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=To[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==fc.BYE||this._method!==fc.ACK)&&this._eventHandlers.onTransportError()}return Xd(c,[{key:"send",value:function(){var n=this,a={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new go.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new go.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new go.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,a)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var a,o,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(a=n.parseHeader("www-authenticate"),o="authorization"):(a=n.parseHeader("proxy-authenticate"),o="proxy-authorization"),!a){e_.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&a.stale===!0){if(this._auth||(this._auth=new Zd({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,a)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),a.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),c}();function t_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function hc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function s_(c,t,n){return t&&hc(c.prototype,t),n&&hc(c,n),c}var n_=ht,vo=bt(),pn=lt,dc=Ss,_c=dl,Ni=new n_("Registrator"),jl=10,r_=function(){function c(t,n){t_(this,c),this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=vo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return s_(c,[{key:"setExtraHeaders",value:function(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}},{key:"setExtraContactParams",value:function(n){n instanceof Object||(n={}),this._extraContactParams="";for(var a in n)if(Object.prototype.hasOwnProperty.call(n,a)){var o=n[a];this._extraContactParams+=";".concat(a),o&&(this._extraContactParams+="=".concat(o))}}},{key:"register",value:function(){var n=this;if(this._registering){Ni.debug("Register request in progress...");return}var a=this._extraHeaders.slice();a.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),a.push("Expires: ".concat(this._expires));var o=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new _c(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(d){if(d.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(n._registering=!1,!d.hasHeader("Contact")){Ni.debug("no Contact header in response to REGISTER, response ignored");break}var h=d.headers.Contact.reduce(function(y,A){return y.concat(A.parsed)},[]),_=h.find(function(y){return n._sipInstance===y.getParam("+sip.instance")&&n._reg_id===parseInt(y.getParam("reg-id"))});if(_||(_=h.find(function(y){return y.uri.user===n._ua.contact.uri.user})),!_){Ni.debug("no Contact header pointing to us, response ignored");break}var g=_.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=n._expires),g=Number(g),g<jl&&(g=jl);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},T),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(n._expires=Number(d.getHeader("min-expires")),n._expires<jl&&(n._expires=jl),n.register()):(Ni.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,pn.causes.SIP_FAILURE_CODE));break}default:{var E=vo.sipErrorCause(d.status_code);n._registrationFailure(d,E)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){Ni.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var o=this._extraHeaders.slice();a.all?o.push("Contact: *".concat(this._extraContactParams)):o.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),o.push("Expires: 0");var s=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new _c(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):n._unregistered(h);break;default:{var _=vo.sipErrorCause(h.status_code);n._unregistered(h,_)}}}});r.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,a){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:a}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:a}))}},{key:"_unregistered",value:function(n,a){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:a||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function i_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function l_(c,t,n){return t&&pc(c.prototype,t),n&&pc(c,n),c}var Eo=lt,ql=hl,a_=dl,So={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},o_=function(){function c(t,n,a){i_(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(var o in So)Object.prototype.hasOwnProperty.call(So,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=So[o]))}return l_(c,[{key:"send",value:function(){var n=this,a=new a_(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(r){n._eventHandlers.onAuthenticated(r)},onReceiveResponse:function(r){n._receiveResponse(r)}});if(a.send(),(this._request.method===Eo.INVITE||this._request.method===Eo.UPDATE&&this._request.body)&&a.clientTransaction.state!==ql.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===ql.C.STATUS_ACCEPTED||a.clientTransaction.state===ql.C.STATUS_COMPLETED||a.clientTransaction.state===ql.C.STATUS_TERMINATED)&&(a.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};a.clientTransaction.on("stateChanged",o)}}},{key:"_receiveResponse",value:function(n){var a=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===Eo.INVITE&&n.status_code===491?this._reattempt?n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){a._dialog.isTerminated()||(a._reattempt=!0,a.send())},1e3)):n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n)}},{key:"request",get:function(){return this._request}}]),c}();function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function mc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function gc(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var c_=ht,Tc=Ss,Ms=lt,Ui=hl,f_=o_,yo=bt(),Ao=new c_("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},h_=function(){gc(c,null,[{key:"C",get:function(){return Ls}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ls.STATUS_CONFIRMED;if(u_(this,c),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Tc.IncomingResponse&&(o=n.status_code<200?Ls.STATUS_EARLY:Ls.STATUS_CONFIRMED);var s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Ao.debug("new ".concat(a," dialog created with status ").concat(this._state===Ls.STATUS_EARLY?"EARLY":"CONFIRMED"))}return gc(c,[{key:"isTerminated",value:function(){return this._status===Ls.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ls.STATUS_CONFIRMED,Ao.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Ao.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ls.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=yo.cloneArray(o.extraHeaders),r=yo.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new f_(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Ms.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Ms.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=yo.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Ms.CANCEL||n===Ms.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Tc.OutgoingRequest(n,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},a,o);return r}},{key:"_checkInDialogRequest",value:function(n){var a=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Ms.ACK){if(this._ack_seqnum===null||n.cseq!==this._ack_seqnum)return!1}else return n.reply(500),!1;else n.cseq>this._remote_seqnum&&(this._remote_seqnum=n.cseq);if(n.method===Ms.INVITE||n.method===Ms.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var o=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(o)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Ui.C.STATUS_ACCEPTED||n.server_transaction.state===Ui.C.STATUS_COMPLETED||n.server_transaction.state===Ui.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),a._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Ms.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_COMPLETED&&(a._remote_target=n.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(n){this._local_seqnum=n}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(n){this._uac_pending_reply=n}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),Pu={exports:{}};function Ea(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ea=function(n){return typeof n}:Ea=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ea(c)}function d_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function vc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function __(c,t,n){return t&&vc(c.prototype,t),n&&vc(c,n),c}function p_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&hu(c,t)}function hu(c,t){return hu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},hu(c,t)}function m_(c){var t=v_();return function(){var a=Na(c),o;if(t){var s=Na(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return g_(this,o)}}function g_(c,t){return t&&(Ea(t)==="object"||typeof t=="function")?t:T_(c)}function T_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function v_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Na(c){return Na=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Na(c)}var E_=ft.EventEmitter,S_=ht,y_=lt,A_=Ws,Ec=bt(),C_=new S_("RTCSession:DTMF"),rh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Pu.exports=function(c){p_(n,c);var t=m_(n);function n(a){var o;return d_(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return __(n,[{key:"send",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new A_.InvalidStateError(this._session.status);var d=Ec.cloneArray(r.extraHeaders);if(this.eventHandlers=Ec.cloneObject(r.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError("Invalid tone: ".concat(o));if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError("Invalid tone: ".concat(o));this._duration=r.duration,d.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
47
+ `);h+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(y_.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(g){s.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){s.eventHandlers.onFailed&&s.eventHandlers.onFailed(),s.emit("failed",{originator:"remote",response:g})},onRequestTimeout:function(){s._session.onRequestTimeout()},onTransportError:function(){s._session.onTransportError()},onDialogError:function(){s._session.onDialogError()}},body:h})}},{key:"init_incoming",value:function(o){var s=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,r=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=o,o.reply(200),o.body){var d=o.body.split(`
48
+ `);d.length>=1&&s.test(d[0])&&(this._tone=d[0].replace(s,"$2")),d.length>=2&&r.test(d[1])&&(this._duration=parseInt(d[1].replace(r,"$2"),10))}this._duration||(this._duration=rh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):C_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(E_);Pu.exports.C=rh;var R_=Pu.exports;function Sa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Sa=function(n){return typeof n}:Sa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Sa(c)}function I_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function b_(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(c,n),c}function w_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&du(c,t)}function du(c,t){return du=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},du(c,t)}function O_(c){var t=U_();return function(){var a=Ua(c),o;if(t){var s=Ua(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return D_(this,o)}}function D_(c,t){return t&&(Sa(t)==="object"||typeof t=="function")?t:N_(c)}function N_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function U_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ua(c){return Ua=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ua(c)}var P_=ft.EventEmitter,x_=lt,k_=Ws,M_=bt(),L_=function(c){w_(n,c);var t=O_(n);function n(a){var o;return I_(this,n),o=t.call(this),o._session=a,o._direction=null,o._contentType=null,o._body=null,o}return b_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",o===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new k_.InvalidStateError(this._session.status);this._contentType=o,this._body=s;var h=M_.cloneArray(d.extraHeaders);h.push("Content-Type: ".concat(o)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(x_.INFO,{extraHeaders:h,eventHandlers:{onSuccessResponse:function(g){r.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){r.emit("failed",{originator:"remote",response:g})},onTransportError:function(){r._session.onTransportError()},onRequestTimeout:function(){r._session.onRequestTimeout()},onDialogError:function(){r._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(o){this._direction="incoming",this.request=o,o.reply(200),this._contentType=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,this._body=o.body,this._session.newInfo({originator:"remote",info:this,request:o})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(P_);function $_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function yc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function H_(c,t,n){return t&&yc(c.prototype,t),n&&yc(c,n),c}var F_=ht,Ac=lt,j_=new F_("RTCSession:ReferNotifier"),Co={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},q_=function(){function c(t,n,a){$_(this,c),this._session=t,this._id=n,this._expires=a||Co.expires,this._active=!0,this.notify(100)}return H_(c,[{key:"notify",value:function(n,a){if(j_.debug("notify()"),this._active!==!1){a=a||Ac.REASON_PHRASE[n]||"";var o;n>=200?o="terminated;reason=noresource":o="active;expires=".concat(this._expires),this._session.sendRequest(Ac.NOTIFY,{extraHeaders:["Event: ".concat(Co.event_type,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(Co.body_type)],body:"SIP/2.0 ".concat(n," ").concat(a),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function ya(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ya=function(n){return typeof n}:ya=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ya(c)}function V_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function B_(c,t,n){return t&&Cc(c.prototype,t),n&&Cc(c,n),c}function G_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&_u(c,t)}function _u(c,t){return _u=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},_u(c,t)}function W_(c){var t=J_();return function(){var a=Pa(c),o;if(t){var s=Pa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return K_(this,o)}}function K_(c,t){return t&&(ya(t)==="object"||typeof t=="function")?t:Y_(c)}function Y_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function J_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Pa(c){return Pa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Pa(c)}var z_=ft.EventEmitter,X_=ht,Pi=lt,Q_=os(),Rc=bt(),mn=new X_("RTCSession:ReferSubscriber"),Z_=function(c){G_(n,c);var t=W_(n);function n(a){var o;return V_(this,n),o=t.call(this),o._id=null,o._session=a,o}return B_(n,[{key:"sendRefer",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};mn.debug("sendRefer()");var d=Rc.cloneArray(r.extraHeaders),h=Rc.cloneObject(r.eventHandlers);for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.on(_,h[_]);var g=null;r.replaces&&(g=r.replaces._request.call_id,g+=";to-tag=".concat(r.replaces._to_tag),g+=";from-tag=".concat(r.replaces._from_tag),g=encodeURIComponent(g));var T="Refer-To: <".concat(o).concat(g?"?Replaces=".concat(g):"",">");if(d.push(T),!d.some(function(A){return A.toLowerCase().startsWith("referred-by:")})){var E="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");d.push(E)}d.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(Pi.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(C){s._requestSucceeded(C)},onErrorResponse:function(C){s._requestFailed(C,Pi.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,Pi.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,Pi.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,Pi.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(o){if(mn.debug("receiveNotify()"),!!o.body){var s=Q_.parse(o.body.trim().split(`\r
49
+ `,1)[0],"Status_Line");if(s===-1){mn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(o.body,'"'));return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:o,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:o,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:o,status_line:s});break;default:this.emit("failed",{request:o,status_line:s});break}}}},{key:"_requestSucceeded",value:function(o){mn.debug("REFER succeeded"),mn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}},{key:"_requestFailed",value:function(o,s){mn.debug("REFER failed"),mn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(z_);function Aa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Aa=function(n){return typeof n}:Aa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Aa(c)}function _s(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=ep(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
50
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function ep(c,t){if(c){if(typeof c=="string")return Ic(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ic(c,t)}}function Ic(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function tp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function bc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wc(c,t,n){return t&&bc(c.prototype,t),n&&bc(c,n),c}function sp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&pu(c,t)}function pu(c,t){return pu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},pu(c,t)}function np(c){var t=lp();return function(){var a=xa(c),o;if(t){var s=xa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return rp(this,o)}}function rp(c,t){return t&&(Aa(t)==="object"||typeof t=="function")?t:ip(c)}function ip(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function lp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function xa(c){return xa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},xa(c)}var ap=ft.EventEmitter,Oc=xt,op=ht,ce=lt,gn=Ws,Dc=hl,Ve=bt(),xi=nh,up=Ss,Vl=h_,cp=dl,kt=R_,Nc=L_,fp=q_,hp=Z_,Uc=Ks(),K=new op("RTCSession"),Q={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Bl=["audio","video"],dp=function(c){sp(n,c);var t=np(n);wc(n,null,[{key:"C",get:function(){return Q}}]);function n(a){var o;return tp(this,n),K.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=Q.STATUS_NULL,o._dialog=null,o._earlyDialogs={},o._contact=null,o._from_tag=null,o._to_tag=null,o._connection=null,o._connectionPromiseQueue=Promise.resolve(),o._request=null,o._is_canceled=!1,o._cancel_reason="",o._is_confirmed=!1,o._late_sdp=!1,o._rtcOfferConstraints=null,o._rtcAnswerConstraints=null,o._localMediaStream=null,o._localMediaStreamLocallyGenerated=!1,o._rtcReady=!0,o._iceReady=!1,o._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},o._direction=null,o._local_identity=null,o._remote_identity=null,o._start_time=null,o._end_time=null,o._tones=null,o._audioMuted=!1,o._videoMuted=!1,o._localHold=!1,o._remoteHold=!1,o._sessionTimers={enabled:o._ua.configuration.session_timers,refreshMethod:o._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},o._referSubscribers={},o._data={},o}return wc(n,[{key:"isInProgress",value:function(){switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:case Q.STATUS_INVITE_RECEIVED:case Q.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case Q.STATUS_CANCELED:case Q.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;K.debug("connect()");var d=o,h=Ve.cloneObject(s.eventHandlers),_=Ve.cloneArray(s.extraHeaders),g=Ve.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Ve.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,A=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new gn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new gn.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var C in h)Object.prototype.hasOwnProperty.call(h,C)&&this.on(C,h[C]);this._from_tag=Ve.newTag();var I=s.anonymous||!1,H={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(H.from_display_name="Anonymous",H.from_uri=new Uc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Uc("sip",s.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(H.from_display_name=s.fromDisplayName),_.push("Contact: ".concat(this._contact)),_.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&_.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new up.InitialOutgoingInviteRequest(o,this._ua,H,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(E,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,T)}},{key:"init_incoming",value:function(o,s){var r=this;K.debug("init_incoming()");var d,h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;if(o.body&&h!=="application/sdp"){o.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=o.from_tag,this._id=o.call_id+this._from_tag,this._request=o,this._contact=this._ua.contact.toString(),o.hasHeader("expires")&&(d=o.getHeader("expires")*1e3),o.to_tag=Ve.newTag(),!this._createDialog(o,"UAS",!0)){o.reply(500,"Missing Contact header field");return}o.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){o.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){r._status===Q.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=o.to,this._remote_identity=o.from,s&&s(this),this._newRTCSession("remote",o),this._status!==Q.STATUS_TERMINATED&&(o.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("answer()");var r=this._request,d=Ve.cloneArray(s.extraHeaders),h=Ve.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Ve.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Ve.cloneObject(s.rtcOfferConstraints),A,C=!1,I=!1,H=!1,$=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new gn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new gn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var oe=r.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var N=_s(oe.media),j;try{for(N.s();!(j=N.n()).done;){var Se=j.value;Se.type==="audio"&&(C=!0,(!Se.direction||Se.direction==="sendrecv")&&(H=!0)),Se.type==="video"&&(I=!0,(!Se.direction||Se.direction==="sendrecv")&&($=!0))}}catch(F){N.e(F)}finally{N.f()}if(_&&h.audio===!1){A=_.getAudioTracks();var ve=_s(A),k;try{for(ve.s();!(k=ve.n()).done;){var D=k.value;_.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(_&&h.video===!1){A=_.getVideoTracks();var B=_s(A),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;_.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!_&&h.audio===void 0&&(h.audio=H),!_&&h.video===void 0&&(h.video=$),!_&&!C&&!y.offerToReceiveAudio&&(h.audio=!1),!_&&!I&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(_)return _;if(h.audio||h.video)return o._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(F){throw o._status===Q.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(X){o._connection.addTrack(X,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};K.debug('emit "sdp"'),o.emit("sdp",F);var X=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(X)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");return o._connecting(r),o._late_sdp?o._createLocalDescription("offer",o._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):o._createLocalDescription("answer",E).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=Q.STATUS_WAITING_FOR_ACK,o._setInvite2xxTimer(r,F),o._setACKTimer(),o._accepted("local")},function(){o._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){o._status!==Q.STATUS_TERMINATED&&K.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Ve.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new gn.InvalidStateError(this._status);switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:if(K.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(T=T||ce.REASON_PHRASE[g]||"",_="SIP ;cause=".concat(g,' ;text="').concat(T,'"')),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=Q.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,T,d,h),this._failed("local",null,ce.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),T=s.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Dc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var A=y.method;A===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Dc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())}),this._ended("local",null,r),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:h}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};K.debug("sendDTMF() | tones: %s",o);var r=0,d=s.duration||null,h=s.interToneGap||null,_=s.transportType||ce.DTMF_TRANSPORT.INFO;if(o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);if(_!==ce.DTMF_TRANSPORT.INFO&&_!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(_));if(typeof o=="number"&&(o=o.toString()),!o||typeof o!="string"||!o.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(o));if(d&&!Ve.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<kt.C.MIN_DURATION?(K.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_DURATION," milliseconds")),d=kt.C.MIN_DURATION):d>kt.C.MAX_DURATION?(K.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(kt.C.MAX_DURATION," milliseconds")),d=kt.C.MAX_DURATION):d=Math.abs(d):d=kt.C.DEFAULT_DURATION,s.duration=d,h&&!Ve.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<kt.C.MIN_INTER_TONE_GAP?(K.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_INTER_TONE_GAP," milliseconds")),h=kt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=kt.C.DEFAULT_INTER_TONE_GAP,_===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,d,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var E=this,y;if(this._status===Q.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var A=this._tones[r];if(r+=1,A===",")y=2e3;else{var C=new kt(this);s.eventHandlers={onFailed:function(){E._tones=null}},C.send(A,s),y=d+h}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(o,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);var d=new Nc(this);d.send(o,s,r)}},{key:"mute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};K.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&o.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&o.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};K.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&o.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&o.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||r===!0)&&this._onunmute({audio:s,video:r})}},{key:"hold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(K.debug("hold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(K.debug("unhold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;K.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;K.debug("refer()");var d=o;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new hp(this);h.sendRefer(o,s);var _=h.id;return this._referSubscribers[_]=h,h.on("requestFailed",function(){delete r._referSubscribers[_]}),h.on("accepted",function(){delete r._referSubscribers[_]}),h.on("failed",function(){delete r._referSubscribers[_]}),h}},{key:"sendRequest",value:function(o,s){return K.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(K.debug("receiveRequest()"),o.method===ce.CANCEL)(this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED)&&(this._status=Q.STATUS_CANCELED,this._request.reply(487),this._failed("remote",o,ce.causes.CANCELED));else switch(o.method){case ce.ACK:if(this._status!==Q.STATUS_WAITING_FOR_ACK)return;if(this._status=Q.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",r);var d=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(_){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(o.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",o,ce.causes.BYE)):o.reply(403,"Wrong Status");break;case ce.INVITE:this._status===Q.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===Q.STATUS_1XX_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED||this._status===Q.STATUS_WAITING_FOR_ACK||this._status===Q.STATUS_CONFIRMED){var h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new kt(this).init_incoming(o):h!==void 0?new Nc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.reply(501)}}},{key:"onTransportError",value:function(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(o){K.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){K.debug("newInfo()"),this.emit("newInfo",o)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Ve.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){K.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var o in this._timers)Object.prototype.hasOwnProperty.call(this._timers,o)&&clearTimeout(this._timers[o]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var r in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,r)&&delete this._referSubscribers[r];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(o,s){var r=xi.T1;function d(){this._status===Q.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<xi.T2&&(r=r*2,r>xi.T2&&(r=xi.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),r))}this._timers.invite2xxTimer=setTimeout(d.bind(this),r)}},{key:"_setACKTimer",value:function(){var o=this;this._timers.ackTimer=setTimeout(function(){o._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},xi.TIMER_H)}},{key:"_createRTCConnection",value:function(o,s){var r=this;this._connection=new RTCPeerConnection(o,s),this._connection.addEventListener("iceconnectionstatechange",function(){var d=r._connection.iceConnectionState;d==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(K.debug("createLocalDescription()"),o!=="offer"&&o!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(o,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?d.createOffer(s).catch(function(h){return K.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return K.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),r.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return d.setLocalDescription(h).catch(function(_){return r._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),r.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)})}).then(function(){var h=s&&s.iceRestart;if(d.iceGatheringState==="complete"&&!h||d.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var _={originator:"local",type:o,sdp:d.localDescription.sdp};return K.debug('emit "sdp"'),r.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(function(g){var T=!1,E,y;r._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,r._rtcReady=!0,r._iceReady=!0;var I={originator:"local",type:o,sdp:d.localDescription.sdp};K.debug('emit "sdp"'),r.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?r.emit("icecandidate",{candidate:H,ready:A}):T||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(o,s,r){var d=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,_=o.call_id+d+h,g=this._earlyDialogs[_];if(r)return g?!0:(g=new Vl(this,o,s,Vl.C.STATUS_EARLY),g.error?(K.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[_]=g,!0));if(this._from_tag=o.from_tag,this._to_tag=o.to_tag,g)return g.update(o,s),this._dialog=g,delete this._earlyDialogs[_],!0;var T=new Vl(this,o,s);return T.error?(K.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;K.debug("receiveReinvite()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Ve.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,A)}if(this.emit("reinvite",d),h)return;if(this._late_sdp=!1,!o.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){o.reply(500)});return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,y),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,y,T,function(){E._status=Q.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;K.debug("receiveUpdate()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Ve.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,A)}if(this.emit("update",d),h)return;if(!o.body){g.call(this,null);return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),o.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;K.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Bl.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(A){h.e(A)}finally{h.f()}var E={originator:"remote",type:"offer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",E);var y=new RTCSessionDescription({type:"offer",sdp:E.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(A){throw o.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),s.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&d===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&d===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(A){throw o.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){K.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(o){var s=this;if(K.debug("receiveRefer()"),!o.refer_to){K.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new fp(this,o.cseq);K.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){d.call(s,g,T)},reject:function(){h.call(s)}});function d(_){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_=typeof _=="function"?_:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(y){var A=y.message,C=y.cause;A?r.notify(A.status_code,A.reason_phrase):r.notify(487,C)}),o.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ve.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(o.refer_to.uri.toAor(),g,_)}function h(){r.notify(603)}}},{key:"_receiveNotify",value:function(o){switch(K.debug("receiveNotify()"),o.event||o.reply(400),o.event.event){case"refer":{var s,r;if(o.event.params&&o.event.params.id)s=o.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{o.reply(400,"Missing event id parameter");return}if(!r){o.reply(481,"Subscription does not exist");return}r.receiveNotify(o),o.reply(200);break}default:o.reply(489)}}},{key:"_receiveReplaces",value:function(o){var s=this;K.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){K.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(_){r.call(s,_)},reject:function(){d.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var d=this,h=new cp(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(g){d._request=g},onReceiveResponse:function(g){d._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(_){throw d._status===Q.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===Q.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=_,_&&_.getTracks().forEach(function(g){d._connection.addTrack(g,_)}),d._connecting(d._request),d._createLocalDescription("offer",s).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(_){if(d._is_canceled||d._status===Q.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==Q.STATUS_TERMINATED&&K.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(K.debug("receiveInviteResponse()"),this._dialog&&o.status_code>=200&&o.status_code<=299)if(this._dialog.id.call_id===o.call_id&&this._dialog.id.local_tag===o.from_tag&&this._dialog.id.remote_tag===o.to_tag){this.sendRequest(ce.ACK);return}else{var r=new Vl(this,o,"UAC");if(r.error!==void 0){K.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){o.status_code>=100&&o.status_code<200?this._request.cancel(this._cancel_reason):o.status_code>=200&&o.status_code<299&&this._acceptAndTerminate(o);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){K.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",d);var h=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(E){K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(o.status_code):{if(this._status=Q.STATUS_CONFIRMED,!o.body){this._acceptAndTerminate(o,400,ce.causes.MISSING_SDP),this._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(o,"UAC"))break;var _={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",_);var g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(E){return s._connection.setLocalDescription(E)}).catch(function(E){s._acceptAndTerminate(o,500,E.toString()),s._failed("local",o,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(o),s._accepted("remote",o),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(E){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Ve.sipErrorCause(o.status_code);this._failed("remote",o,T)}}}},{key:"_sendReinvite",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendReinvite()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=!1;r.push("Contact: ".concat(this._contact)),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};K.debug('emit "sdp"'),o.emit("sdp",y),o.sendRequest(ce.INVITE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(C){g.call(o,C),_=!0},onErrorResponse:function(C){T.call(o,C)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==Q.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!_)){if(this._handleSessionTimersInIncomingResponse(E),E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var A={originator:"remote",type:"answer",sdp:E.body};K.debug('emit "sdp"'),this.emit("sdp",A);var C=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(C)}).then(function(){d.succeeded&&d.succeeded(E)}).catch(function(I){T.call(y),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',I),y.emit("peerconnection:setremotedescriptionfailed",I)})}}function T(E){d.failed&&d.failed(E)}}},{key:"_sendUpdate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendUpdate()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1,g=!1;r.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),_?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(y){y=o._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};K.debug('emit "sdp"'),o.emit("sdp",A),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(o,I),g=!0},onErrorResponse:function(I){E.call(o,I)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){E.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(A){T.call(o,A)},onErrorResponse:function(A){E.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(y){var A=this;if(this._status!==Q.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),_){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){E.call(this);return}}else{E.call(this);return}var C={originator:"remote",type:"answer",sdp:y.body};K.debug('emit "sdp"'),this.emit("sdp",C);var I=new RTCSessionDescription({type:"answer",sdp:C.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(I)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(H){E.call(A),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',H),A.emit("peerconnection:setremotedescriptionfailed",H)})}else d.succeeded&&d.succeeded(y)}function E(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(o,s,r){K.debug("acceptAndTerminate()");var d=[];s&&(r=r||ce.REASON_PHRASE[s]||"",d.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=Q.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Oc.parse(o),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");var s=_s(o.media),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;Bl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){s.e(A)}finally{s.f()}}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Bl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){h.e(A)}finally{h.f()}}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(o.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Bl.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(A){T.e(A)}finally{T.f()}}return Oc.write(o)}},{key:"_setLocalMediaStatus",value:function(){var o=!0,s=!0;(this._localHold||this._remoteHold)&&(o=!1,s=!1),this._audioMuted&&(o=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!o),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(o,s){if(this._sessionTimers.enabled){var r;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,r=o.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(r)),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(o){if(this._sessionTimers.enabled){var s;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,s=o.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var o=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&o._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),o.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="audio"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="video"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_newRTCSession",value:function(o,s){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{key:"C",get:function(){return Q}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(ap);function Ca(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ca=function(n){return typeof n}:Ca=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ca(c)}function _p(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function pp(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}function mp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&mu(c,t)}function mu(c,t){return mu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},mu(c,t)}function gp(c){var t=Ep();return function(){var a=ka(c),o;if(t){var s=ka(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Tp(this,o)}}function Tp(c,t){return t&&(Ca(t)==="object"||typeof t=="function")?t:vp(c)}function vp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Ep(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function ka(c){return ka=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},ka(c)}var Sp=ft.EventEmitter,yp=ht,Ro=lt,Ap=Ss,ki=bt(),Cp=dl,xc=Ws,Rp=Ks(),Gl=new yp("Message"),Ip=function(c){mp(n,c);var t=gp(n);function n(a){var o;return _p(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return pp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=ki.cloneArray(d.extraHeaders),g=ki.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new Rp("sip",d.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(E.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);_.push("Content-Type: ".concat(T)),this._request=new Ap.OutgoingRequest(Ro.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var A=new Cp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=ki.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new xc.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=ki.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new xc.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=ki.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Ro.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Ro.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Gl.debug("MESSAGE failed"),this._close(),Gl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Gl.debug("MESSAGE succeeded"),this._close(),Gl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(Sp);function Ra(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ra=function(n){return typeof n}:Ra=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ra(c)}function bp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function kc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wp(c,t,n){return t&&kc(c.prototype,t),n&&kc(c,n),c}function Op(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&gu(c,t)}function gu(c,t){return gu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},gu(c,t)}function Dp(c){var t=Pp();return function(){var a=Ma(c),o;if(t){var s=Ma(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Np(this,o)}}function Np(c,t){return t&&(Ra(t)==="object"||typeof t=="function")?t:Up(c)}function Up(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Pp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ma(c){return Ma=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ma(c)}var xp=ft.EventEmitter,kp=ht,Io=lt,Mp=Ss,Mi=bt(),Lp=dl,Mc=Ws,Wl=new kp("Options"),$p=function(c){Op(n,c);var t=Dp(n);function n(a){var o;return bp(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return wp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Mi.cloneArray(d.extraHeaders),g=Mi.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);_.push("Content-Type: ".concat(T)),this._request=new Mp.OutgoingRequest(Io.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Lp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(C){r._receiveResponse(C)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Mi.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Mi.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Mi.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Io.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Io.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Wl.debug("OPTIONS failed"),this._close(),Wl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Wl.debug("OPTIONS succeeded"),this._close(),Wl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(xp),xu={},Hp=ht,bo=bt(),Fp=os(),Li=new Hp("Socket");xu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return Li.warn("undefined JsSIP.Socket instance"),!1;try{if(!bo.isString(c.url))throw Li.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!bo.isString(c.via_transport))throw Li.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Fp.parse(c.sip_uri,"SIP_URI")===-1)throw Li.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!bo.isFunction(c[t]))throw Li.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch{return!1}return!0};function jp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function qp(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}var Vp=ht,Bp=xu,$c=lt,Nt=new Vp("Transport"),qt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:$c.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:$c.CONNECTION_RECOVERY_MAX_INTERVAL}},Gp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qt.recovery_options;jp(this,c),Nt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Nt.warn("cannot use TextDecoder: ".concat(a))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Bp.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}return qp(c,[{key:"connect",value:function(){if(Nt.debug("connect()"),this.isConnected()){Nt.debug("Transport is already connected");return}else if(this.isConnecting()){Nt.debug("Transport is connecting");return}this.close_requested=!1,this.status=qt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Nt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=qt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Nt.debug("send()"),!this.isConnected())return Nt.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Nt.debug(`sending message:
51
51
 
52
- `.concat(r,`
53
- `)),this.socket.send(r)}},{key:"isConnected",value:function(){return this.status===ls.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===ls.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var t=this;this.recover_attempts+=1;var r=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);r<this.recovery_options.min_interval?r=this.recovery_options.min_interval:r>this.recovery_options.max_interval&&(r=this.recovery_options.max_interval),zt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(r," seconds")),this.recovery_timer=setTimeout(function(){!t.close_requested&&!(t.isConnected()||t.isConnecting())&&(t._getSocket(),t.connect())},r*1e3)}},{key:"_getSocket",value:function(){var t=[];if(this.sockets.forEach(function(l){l.status!==ls.SOCKET_STATUS_ERROR&&(t.length===0?t.push(l):l.weight>t[0].weight?t=[l]:l.weight===t[0].weight&&t.push(l))}),t.length===0){this.sockets.forEach(function(l){l.status=ls.SOCKET_STATUS_READY}),this._getSocket();return}var r=Math.floor(Math.random()*t.length);this.socket=t[r].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=ls.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(t,r,l){this.status=ls.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:t,code:r,reason:l}),!this.close_requested&&(this.sockets.forEach(function(s){this.socket===s.socket&&(s.status=ls.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}},{key:"_onData",value:function(t){if(t===`\r
54
- `){zt.debug("received message with CRLF Keep Alive response");return}else if(typeof t!="string"){try{this.textDecoder?t=this.textDecoder.decode(t):t=String.fromCharCode.apply(null,new Uint8Array(t))}catch{zt.debug("received binary message failed to be converted into string, message discarded");return}zt.debug(`received binary message:
52
+ `.concat(a,`
53
+ `)),this.socket.send(a)}},{key:"isConnected",value:function(){return this.status===qt.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===qt.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var n=this;this.recover_attempts+=1;var a=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);a<this.recovery_options.min_interval?a=this.recovery_options.min_interval:a>this.recovery_options.max_interval&&(a=this.recovery_options.max_interval),Nt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(a," seconds")),this.recovery_timer=setTimeout(function(){!n.close_requested&&!(n.isConnected()||n.isConnecting())&&(n._getSocket(),n.connect())},a*1e3)}},{key:"_getSocket",value:function(){var n=[];if(this.sockets.forEach(function(o){o.status!==qt.SOCKET_STATUS_ERROR&&(n.length===0?n.push(o):o.weight>n[0].weight?n=[o]:o.weight===n[0].weight&&n.push(o))}),n.length===0){this.sockets.forEach(function(o){o.status=qt.SOCKET_STATUS_READY}),this._getSocket();return}var a=Math.floor(Math.random()*n.length);this.socket=n[a].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=qt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(n,a,o){this.status=qt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:n,code:a,reason:o}),!this.close_requested&&(this.sockets.forEach(function(s){this.socket===s.socket&&(s.status=qt.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
54
+ `){Nt.debug("received message with CRLF Keep Alive response");return}else if(typeof n!="string"){try{this.textDecoder?n=this.textDecoder.decode(n):n=String.fromCharCode.apply(null,new Uint8Array(n))}catch{Nt.debug("received binary message failed to be converted into string, message discarded");return}Nt.debug(`received binary message:
55
55
 
56
- `.concat(t,`
57
- `))}else zt.debug(`received text message:
56
+ `.concat(n,`
57
+ `))}else Nt.debug(`received text message:
58
58
 
59
- `.concat(t,`
60
- `));this.ondata({transport:this,message:t})}},{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}}]),u}(),Jg={};function Xd(u,e){var t;if(typeof Symbol>"u"||u[Symbol.iterator]==null){if(Array.isArray(u)||(t=m1(u))||e&&u&&typeof u.length=="number"){t&&(u=t);var r=0,l=function(){};return{s:l,n:function(){return r>=u.length?{done:!0}:{done:!1,value:u[r++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
61
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,i=!1,f;return{s:function(){t=u[Symbol.iterator]()},n:function(){var d=t.next();return s=d.done,d},e:function(d){i=!0,f=d},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(i)throw f}}}}function m1(u,e){if(u){if(typeof u=="string")return Jd(u,e);var t=Object.prototype.toString.call(u).slice(8,-1);if(t==="Object"&&u.constructor&&(t=u.constructor.name),t==="Map"||t==="Set")return Array.from(u);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Jd(u,e)}}function Jd(u,e){(e==null||e>u.length)&&(e=u.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=u[t];return r}var v1=Ot,sf=Ns(),nf=zs,go=new v1("Parser");Jg.parseMessage=function(u,e){var t,r,l=u.indexOf(`\r
62
- `);if(l===-1){go.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=u.substring(0,l),i=sf.parse(s,"Request_Response");if(i===-1){go.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else i.status_code?(t=new nf.IncomingResponse,t.status_code=i.status_code,t.reason_phrase=i.reason_phrase):(t=new nf.IncomingRequest(e),t.method=i.method,t.ruri=i.uri);t.data=u;for(var f=l+2;;){if(l=T1(u,f),l===-2){r=f+2;break}else if(l===-1){go.warn("parseMessage() | malformed message");return}if(i=y1(t,u,f,l),i!==!0){go.warn("parseMessage() |",i.error);return}f=l+2}if(t.hasHeader("content-length")){var h=t.getHeader("content-length");t.body=u.substr(r,h)}else t.body=u.substring(r);return t};function T1(u,e){var t=e,r=0,l=0;if(u.substring(t,t+2).match(/(^\r\n)/))return-2;for(;r===0;){if(l=u.indexOf(`\r
63
- `,t),l===-1)return l;!u.substring(l+2,l+4).match(/(^\r\n)/)&&u.charAt(l+2).match(/(^\s+)/)?t=l+2:r=l}return r}function y1(u,e,t,r){var l,s=e.indexOf(":",t),i=e.substring(t,s).trim(),f=e.substring(s+1,r).trim();switch(i.toLowerCase()){case"via":case"v":u.addHeader("via",f),u.getHeaders("via").length===1?(l=u.parseHeader("Via"),l&&(u.via=l,u.via_branch=l.branch)):l=0;break;case"from":case"f":u.setHeader("from",f),l=u.parseHeader("from"),l&&(u.from=l,u.from_tag=l.getParam("tag"));break;case"to":case"t":u.setHeader("to",f),l=u.parseHeader("to"),l&&(u.to=l,u.to_tag=l.getParam("tag"));break;case"record-route":if(l=sf.parse(f,"Record_Route"),l===-1)l=void 0;else{var h=Xd(l),d;try{for(h.s();!(d=h.n()).done;){var p=d.value;u.addHeader("record-route",f.substring(p.possition,p.offset)),u.headers["Record-Route"][u.getHeaders("record-route").length-1].parsed=p.parsed}}catch(S){h.e(S)}finally{h.f()}}break;case"call-id":case"i":u.setHeader("call-id",f),l=u.parseHeader("call-id"),l&&(u.call_id=f);break;case"contact":case"m":if(l=sf.parse(f,"Contact"),l===-1)l=void 0;else{var v=Xd(l),T;try{for(v.s();!(T=v.n()).done;){var y=T.value;u.addHeader("contact",f.substring(y.possition,y.offset)),u.headers.Contact[u.getHeaders("contact").length-1].parsed=y.parsed}}catch(S){v.e(S)}finally{v.f()}}break;case"content-length":case"l":u.setHeader("content-length",f),l=u.parseHeader("content-length");break;case"content-type":case"c":u.setHeader("content-type",f),l=u.parseHeader("content-type");break;case"cseq":u.setHeader("cseq",f),l=u.parseHeader("cseq"),l&&(u.cseq=l.value),u instanceof nf.IncomingResponse&&(u.method=l.method);break;case"max-forwards":u.setHeader("max-forwards",f),l=u.parseHeader("max-forwards");break;case"www-authenticate":u.setHeader("www-authenticate",f),l=u.parseHeader("www-authenticate");break;case"proxy-authenticate":u.setHeader("proxy-authenticate",f),l=u.parseHeader("proxy-authenticate");break;case"session-expires":case"x":u.setHeader("session-expires",f),l=u.parseHeader("session-expires"),l&&(u.session_expires=l.expires,u.session_expires_refresher=l.refresher);break;case"refer-to":case"r":u.setHeader("refer-to",f),l=u.parseHeader("refer-to"),l&&(u.refer_to=l);break;case"replaces":u.setHeader("replaces",f),l=u.parseHeader("replaces"),l&&(u.replaces=l);break;case"event":case"o":u.setHeader("event",f),l=u.parseHeader("event"),l&&(u.event=l);break;default:u.addHeader(i,f),l=0}return l===void 0?{error:'error parsing header "'.concat(i,'"')}:!0}function Zo(u,e){var t;if(typeof Symbol>"u"||u[Symbol.iterator]==null){if(Array.isArray(u)||(t=S1(u))||e&&u&&typeof u.length=="number"){t&&(u=t);var r=0,l=function(){};return{s:l,n:function(){return r>=u.length?{done:!0}:{done:!1,value:u[r++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
64
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,i=!1,f;return{s:function(){t=u[Symbol.iterator]()},n:function(){var d=t.next();return s=d.done,d},e:function(d){i=!0,f=d},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(i)throw f}}}}function S1(u,e){if(u){if(typeof u=="string")return Qd(u,e);var t=Object.prototype.toString.call(u).slice(8,-1);if(t==="Object"&&u.constructor&&(t=u.constructor.name),t==="Map"||t==="Set")return Array.from(u);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Qd(u,e)}}function Qd(u,e){(e==null||e>u.length)&&(e=u.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=u[t];return r}var E1=Ot,Qg=St,Zd=zs,Df=jt(),Nf=new E1("sanityCheck"),C1=[x1],A1=[w1,I1,O1,D1],b1=[N1,P1],Je,Rs,Zg,R1=function(u,e,t){Je=u,Rs=e,Zg=t;var r=Zo(C1),l;try{for(r.s();!(l=r.n()).done;){var s=l.value;if(s()===!1)return!1}}catch(T){r.e(T)}finally{r.f()}if(Je instanceof Zd.IncomingRequest){var i=Zo(A1),f;try{for(i.s();!(f=i.n()).done;){var h=f.value;if(h()===!1)return!1}}catch(T){i.e(T)}finally{i.f()}}else if(Je instanceof Zd.IncomingResponse){var d=Zo(b1),p;try{for(d.s();!(p=d.n()).done;){var v=p.value;if(v()===!1)return!1}}catch(T){d.e(T)}finally{d.f()}}return!0};function w1(){if(Je.s("to").uri.scheme!=="sip")return ga(416),!1}function I1(){if(!Je.to_tag&&Je.call_id.substr(0,5)===Rs.configuration.jssip_id)return ga(482),!1}function O1(){var u=Df.str_utf8_length(Je.body),e=Je.getHeader("content-length");if(u<e)return ga(400),!1}function D1(){var u=Je.from_tag,e=Je.call_id,t=Je.cseq,r;if(!Je.to_tag)if(Je.method===Qg.INVITE){if(Rs._transactions.ist[Je.via_branch])return!1;for(var l in Rs._transactions.ist)if(Object.prototype.hasOwnProperty.call(Rs._transactions.ist,l)&&(r=Rs._transactions.ist[l],r.request.from_tag===u&&r.request.call_id===e&&r.request.cseq===t))return ga(482),!1}else{if(Rs._transactions.nist[Je.via_branch])return!1;for(var s in Rs._transactions.nist)if(Object.prototype.hasOwnProperty.call(Rs._transactions.nist,s)&&(r=Rs._transactions.nist[s],r.request.from_tag===u&&r.request.call_id===e&&r.request.cseq===t))return ga(482),!1}}function N1(){if(Je.getHeaders("via").length>1)return Nf.debug("more than one Via header field present in the response, dropping the response"),!1}function P1(){var u=Df.str_utf8_length(Je.body),e=Je.getHeader("content-length");if(u<e)return Nf.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function x1(){for(var u=["from","to","call_id","cseq","via"],e=0,t=u;e<t.length;e++){var r=t[e];if(!Je.hasHeader(r))return Nf.debug("missing mandatory header field : ".concat(r,", dropping the response")),!1}}function ga(u){var e=Je.getHeaders("via"),t,r="SIP/2.0 ".concat(u," ").concat(Qg.REASON_PHRASE[u],`\r
65
- `),l=Zo(e),s;try{for(l.s();!(s=l.n()).done;){var i=s.value;r+="Via: ".concat(i,`\r
66
- `)}}catch(f){l.e(f)}finally{l.f()}t=Je.getHeader("To"),Je.to_tag||(t+=";tag=".concat(Df.newTag())),r+="To: ".concat(t,`\r
67
- `),r+="From: ".concat(Je.getHeader("From"),`\r
68
- `),r+="Call-ID: ".concat(Je.call_id,`\r
69
- `),r+="CSeq: ".concat(Je.cseq," ").concat(Je.method,`\r
70
- `),r+=`\r
71
- `,Zg.send(r)}var Pf={};function e_(u,e){var t;if(typeof Symbol>"u"||u[Symbol.iterator]==null){if(Array.isArray(u)||(t=k1(u))||e&&u&&typeof u.length=="number"){t&&(u=t);var r=0,l=function(){};return{s:l,n:function(){return r>=u.length?{done:!0}:{done:!1,value:u[r++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
72
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,i=!1,f;return{s:function(){t=u[Symbol.iterator]()},n:function(){var d=t.next();return s=d.done,d},e:function(d){i=!0,f=d},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(i)throw f}}}}function k1(u,e){if(u){if(typeof u=="string")return t_(u,e);var t=Object.prototype.toString.call(u).slice(8,-1);if(t==="Object"&&u.constructor&&(t=u.constructor.name),t==="Map"||t==="Set")return Array.from(u);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return t_(u,e)}}function t_(u,e){(e==null||e>u.length)&&(e=u.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=u[t];return r}var hr=jt(),ci=St,Zc=Ns(),s_=On(),eh=Of,th=In;Pf.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:ci.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:ci.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:ci.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(hr.createRandomToken(12),".invalid")};var po={mandatory:{sockets:function(e){var t=[];if(eh.isSocket(e))t.push({socket:e});else if(Array.isArray(e)&&e.length){var r=e_(e),l;try{for(r.s();!(l=r.n()).done;){var s=l.value;Object.prototype.hasOwnProperty.call(s,"socket")&&eh.isSocket(s.socket)?t.push(s):eh.isSocket(s)&&t.push({socket:s})}}catch(i){r.e(i)}finally{r.f()}}else return;return t},uri:function(e){/^sip:/i.test(e)||(e="".concat(ci.SIP,":").concat(e));var t=s_.parse(e);if(t)return t.user?t:void 0}},optional:{authorization_user:function(e){if(Zc.parse('"'.concat(e,'"'),"quoted_string")!==-1)return e},authorization_jwt:function(e){if(typeof e=="string")return e},user_agent:function(e){if(typeof e=="string")return e},connection_recovery_max_interval:function(e){if(hr.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(hr.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if(typeof e=="string"){var t=Zc.parse(e,"SIP_URI");if(t!==-1)return t}},display_name:function(e){return e},instance_id:function(e){if(/^uuid:/i.test(e)&&(e=e.substr(5)),Zc.parse(e,"uuid")!==-1)return e},no_answer_timeout:function(e){if(hr.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if(typeof e=="boolean")return e},session_timers_refresh_method:function(e){if(typeof e=="string"&&(e=e.toUpperCase(),e===ci.INVITE||e===ci.UPDATE))return e},session_timers_force_refresher:function(e){if(typeof e=="boolean")return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if(typeof e=="boolean")return e},register_expires:function(e){if(hr.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(ci.SIP,":").concat(e));var t=s_.parse(e);if(t)return t.user?void 0:t},use_preloaded_route:function(e){if(typeof e=="boolean")return e},extra_headers:function(e){var t=[];if(Array.isArray(e)&&e.length){var r=e_(e),l;try{for(r.s();!(l=r.n()).done;){var s=l.value;typeof s=="string"&&t.push(s)}}catch(i){r.e(i)}finally{r.f()}}else return;return t}}};Pf.load=function(u,e){for(var t in po.mandatory)if(e.hasOwnProperty(t)){var r=e[t],l=po.mandatory[t](r);if(l!==void 0)u[t]=l;else throw new th.ConfigurationError(t,r)}else throw new th.ConfigurationError(t);for(var s in po.optional)if(e.hasOwnProperty(s)){var i=e[s];if(hr.isEmpty(i))continue;var f=po.optional[s](i);if(f!==void 0)u[s]=f;else throw new th.ConfigurationError(s,i)}};function eu(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?eu=function(t){return typeof t}:eu=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},eu(u)}function M1(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function n_(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function i_(u,e,t){return e&&n_(u.prototype,e),t&&n_(u,t),u}function U1(u,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");u.prototype=Object.create(e&&e.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),e&&rf(u,e)}function rf(u,e){return rf=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},rf(u,e)}function L1(u){var e=$1();return function(){var r=fu(u),l;if(e){var s=fu(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return F1(this,l)}}function F1(u,e){return e&&(eu(e)==="object"||typeof e=="function")?e:ep(u)}function ep(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function $1(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function fu(u){return fu=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},fu(u)}var H1=It.EventEmitter,G1=Ot,Pt=St,V1=Om,r_=Fv,l_=Jv,a_=u1,sh=Ia,B1=p1,mo=jt(),j1=In,q1=On(),W1=Jg,nh=zs,K1=R1,ih=Pf,Ze=new G1("UA"),Mt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Y1=function(u){U1(t,u);var e=L1(t);i_(t,null,[{key:"C",get:function(){return Mt}}]);function t(r){var l;if(M1(this,t),Ze.debug("new() [configuration:%o]",r),l=e.call(this),l._cache={credentials:{}},l._configuration=Object.assign({},ih.settings),l._dynConfiguration={},l._dialogs={},l._applicants={},l._sessions={},l._transport=null,l._contact=null,l._status=Mt.STATUS_INIT,l._error=null,l._transactions={nist:{},nict:{},ist:{},ict:{}},l._data={},l._closeTimer=null,r===void 0)throw new TypeError("Not enough arguments");try{l._loadConfig(r)}catch(s){throw l._status=Mt.STATUS_NOT_READY,l._error=Mt.CONFIGURATION_ERROR,s}return l._registrator=new V1(ep(l)),l}return i_(t,[{key:"start",value:function(){Ze.debug("start()"),this._status===Mt.STATUS_INIT?this._transport.connect():this._status===Mt.STATUS_USER_CLOSED?(Ze.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Mt.STATUS_INIT,this._transport.connect()):this._status===Mt.STATUS_READY?Ze.debug("UA is in READY status, not restarted"):Ze.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){Ze.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(l){Ze.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(l)}},{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(l,s){Ze.debug("call()");var i=new r_(this);return i.connect(l,s),i}},{key:"sendMessage",value:function(l,s,i){Ze.debug("sendMessage()");var f=new l_(this);return f.send(l,s,i),f}},{key:"sendOptions",value:function(l,s,i){Ze.debug("sendOptions()");var f=new a_(this);return f.send(l,s,i),f}},{key:"terminateSessions",value:function(l){Ze.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(l)}},{key:"stop",value:function(){var l=this;if(Ze.debug("stop()"),this._dynConfiguration={},this._status===Mt.STATUS_USER_CLOSED){Ze.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var i in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,i)){Ze.debug("closing session ".concat(i));try{this._sessions[i].terminate()}catch{}}for(var f in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,f))try{this._applicants[f].close()}catch{}this._status=Mt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){l._closeTimer=null,l._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(l){return mo.normalizeTarget(l,this._configuration.hostport_params)}},{key:"get",value:function(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:Ze.warn('get() | cannot get "%s" parameter in runtime',l);return}}},{key:"set",value:function(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 Ze.warn('set() | cannot set "%s" parameter in runtime',l),!1}return!0}},{key:"newTransaction",value:function(l){this._transactions[l.type][l.id]=l,this.emit("newTransaction",{transaction:l})}},{key:"destroyTransaction",value:function(l){delete this._transactions[l.type][l.id],this.emit("transactionDestroyed",{transaction:l})}},{key:"newDialog",value:function(l){this._dialogs[l.id]=l}},{key:"destroyDialog",value:function(l){delete this._dialogs[l.id]}},{key:"newMessage",value:function(l,s){this._applicants[l]=l,this.emit("newMessage",s)}},{key:"newOptions",value:function(l,s){this._applicants[l]=l,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(l){delete this._applicants[l]}},{key:"newRTCSession",value:function(l,s){this._sessions[l.id]=l,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(l){delete this._sessions[l.id]}},{key:"registered",value:function(l){this.emit("registered",l)}},{key:"unregistered",value:function(l){this.emit("unregistered",l)}},{key:"registrationFailed",value:function(l){this.emit("registrationFailed",l)}},{key:"receiveRequest",value:function(l){var s=l.method;if(l.ruri.user!==this._configuration.uri.user&&l.ruri.user!==this._contact.uri.user){Ze.debug("Request-URI does not point to us"),l.method!==Pt.ACK&&l.reply_sl(404);return}if(l.ruri.scheme===Pt.SIPS){l.reply_sl(416);return}if(!sh.checkTransaction(this,l)){if(s===Pt.INVITE?new sh.InviteServerTransaction(this,this._transport,l):s!==Pt.ACK&&s!==Pt.CANCEL&&new sh.NonInviteServerTransaction(this,this._transport,l),s===Pt.OPTIONS){if(this.listeners("newOptions").length===0){l.reply(200);return}var i=new a_(this);i.init_incoming(l)}else if(s===Pt.MESSAGE){if(this.listeners("newMessage").length===0){l.reply(405);return}var f=new l_(this);f.init_incoming(l)}else if(s===Pt.INVITE&&!l.to_tag&&this.listeners("newRTCSession").length===0){l.reply(405);return}var h,d;if(l.to_tag)h=this._findDialog(l.call_id,l.from_tag,l.to_tag),h?h.receiveRequest(l):s===Pt.NOTIFY?(d=this._findSession(l),d?d.receiveRequest(l):(Ze.debug("received NOTIFY request for a non existent subscription"),l.reply(481,"Subscription does not exist"))):s!==Pt.ACK&&l.reply(481);else switch(s){case Pt.INVITE:if(window.RTCPeerConnection)if(l.hasHeader("replaces")){var p=l.replaces;h=this._findDialog(p.call_id,p.from_tag,p.to_tag),h?(d=h.owner,d.isEnded()?l.reply(603):d.receiveRequest(l)):l.reply(481)}else d=new r_(this),d.init_incoming(l);else Ze.warn("INVITE received but WebRTC is not supported"),l.reply(488);break;case Pt.BYE:l.reply(481);break;case Pt.CANCEL:d=this._findSession(l),d?d.receiveRequest(l):Ze.debug("received CANCEL request for a non existent session");break;case Pt.ACK:break;case Pt.NOTIFY:this.emit("sipEvent",{event:l.event,request:l}),l.reply(200);break;default:l.reply(405);break}}}},{key:"_findSession",value:function(l){var s=l.call_id,i=l.from_tag,f=l.to_tag,h=s+i,d=this._sessions[h],p=s+f,v=this._sessions[p];return d||v||null}},{key:"_findDialog",value:function(l,s,i){var f=l+s+i,h=this._dialogs[f];return h||(f=l+i+s,h=this._dialogs[f],h||null)}},{key:"_loadConfig",value:function(l){try{ih.load(this._configuration,l)}catch(p){throw p}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=mo.newUUID()),this._configuration.jssip_id=mo.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new B1(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=z1.bind(this),this._transport.onconnect=X1.bind(this),this._transport.ondisconnect=J1.bind(this),this._transport.ondata=Q1.bind(this)}catch(p){throw Ze.warn(p),new j1.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 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 q1("sip",mo.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 v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},T=v.anonymous||null,y=v.outbound||null,S="<";return T?S+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":S+=this.pub_gruu||this.uri.toString(),y&&(T?!this.temp_gruu:!this.pub_gruu)&&(S+=";ob"),S+=">",S}};var f=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(f.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));Ze.debug("configuration parameters after validation:");for(var d in this._configuration)if(Object.prototype.hasOwnProperty.call(ih.settings,d))switch(d){case"uri":case"registrar_server":Ze.debug("- ".concat(d,": ").concat(this._configuration[d]));break;case"password":case"ha1":case"authorization_jwt":Ze.debug("- ".concat(d,": NOT SHOWN"));break;default:Ze.debug("- ".concat(d,": ").concat(JSON.stringify(this._configuration[d])))}}},{key:"C",get:function(){return Mt}},{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}}]),t}(H1);function z1(u){this.emit("connecting",u)}function X1(u){this._status!==Mt.STATUS_USER_CLOSED&&(this._status=Mt.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function J1(u){for(var e=["nict","ict","nist","ist"],t=0,r=e;t<r.length;t++){var l=r[t];for(var s in this._transactions[l])Object.prototype.hasOwnProperty.call(this._transactions[l],s)&&this._transactions[l][s].onTransportError()}this.emit("disconnected",u),this._registrator.onTransportClosed(),this._status!==Mt.STATUS_USER_CLOSED&&(this._status=Mt.STATUS_NOT_READY,this._error=Mt.NETWORK_ERROR)}function Q1(u){var e=u.transport,t=u.message;if(t=W1.parseMessage(t,this),!!t&&!(this._status===Mt.STATUS_USER_CLOSED&&t instanceof nh.IncomingRequest)&&K1(t,this,e)){if(t instanceof nh.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof nh.IncomingResponse){var r;switch(t.method){case Pt.INVITE:r=this._transactions.ict[t.via_branch],r&&r.receiveResponse(t);break;case Pt.ACK:break;default:r=this._transactions.nict[t.via_branch],r&&r.receiveResponse(t);break}}}}function Z1(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function o_(u,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(u,r.key,r)}}function eT(u,e,t){return e&&o_(u.prototype,e),t&&o_(u,t),u}var tT=Ot,sT=Ns(),Kt=new tT("WebSocketInterface"),nT=function(){function u(e){Z1(this,u),Kt.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;var t=sT.parse(e,"absoluteURI");if(t===-1)throw Kt.warn("invalid WebSocket URI: ".concat(e)),new TypeError("Invalid argument: ".concat(e));if(t.scheme!=="wss"&&t.scheme!=="ws")throw Kt.warn("invalid WebSocket URI scheme: ".concat(t.scheme)),new TypeError("Invalid argument: ".concat(e));this._sip_uri="sip:".concat(t.host).concat(t.port?":".concat(t.port):"",";transport=ws"),this._via_transport=t.scheme.toUpperCase()}return eT(u,[{key:"connect",value:function(){if(Kt.debug("connect()"),this.isConnected()){Kt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Kt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Kt.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(t){this._onError(t)}}},{key:"disconnect",value:function(){Kt.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(t){return Kt.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Kt.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(){Kt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(t){var r=t.wasClean,l=t.code,s=t.reason;Kt.debug("WebSocket ".concat(this._url," closed")),r===!1&&Kt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!r,l,s)}},{key:"_onMessage",value:function(t){var r=t.data;Kt.debug("received WebSocket message"),this.ondata(r)}},{key:"_onError",value:function(t){Kt.warn("WebSocket ".concat(this._url," error: "),t)}},{key:"via_transport",get:function(){return this._via_transport},set:function(t){this._via_transport=t.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),u}(),lf=vu,iT=St,rT=In,lT=jt(),aT=Y1,oT=On(),uT=Af(),cT=Ns(),hT=nT,fT=yr("JsSIP");fT("version %s",lf.version);var u_={C:iT,Exceptions:rT,Utils:lT,UA:aT,URI:oT,NameAddrHeader:uT,WebSocketInterface:hT,Grammar:cT,debug:yr,get name(){return lf.title},get version(){return lf.version}};const ir=yr,rr="JsSIP";var At=class{constructor(e){e?(this._debug=ir.default(`${rr}:${e}`),this._warn=ir.default(`${rr}:WARN:${e}`),this._error=ir.default(`${rr}:ERROR:${e}`)):(this._debug=ir.default(rr),this._warn=ir.default(`${rr}:WARN`),this._error=ir.default(`${rr}: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 Au=nt(At),c_=vu;var Ue={USER_AGENT:`${c_.title} ${c_.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 Z=nt(Ue);var pt={},rh,h_;function xf(){if(h_)return rh;h_=1;const u=Xs(),e=ys();return rh=class tp{static parse(r){if(r=e.parse(r,"Name_Addr_Header"),r!==-1)return r}constructor(r,l,s){if(!r||!(r instanceof u))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=l;for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.setParam(i,s[i])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(r){this._display_name=r===0?"0":r}setParam(r,l){r&&(this._parameters[r.toLowerCase()]=typeof l>"u"||l===null?null:l.toString())}getParam(r){if(r)return this._parameters[r.toLowerCase()]}hasParam(r){if(r)return this._parameters.hasOwnProperty(r.toLowerCase())&&!0||!1}deleteParam(r){if(r=r.toLowerCase(),this._parameters.hasOwnProperty(r)){const l=this._parameters[r];return delete this._parameters[r],l}}clearParams(){this._parameters={}}clone(){return new tp(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let r=this._display_name?`"${this._quote(this._display_name)}" `:"";r+=`<${this._uri.toString()}>`;for(const l in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,l)&&(r+=`;${l}`,this._parameters[l]!==null&&(r+=`=${this._parameters[l]}`));return r}},rh}var lh,f_;function ys(){return f_||(f_=1,lh=function(){function u(t){return'"'+t.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 e={parse:function(t,r){var l={CRLF:d,DIGIT:p,ALPHA:v,HEXDIG:T,WSP:y,OCTET:S,DQUOTE:A,SP:R,HTAB:O,alphanum:N,reserved:C,unreserved:b,mark:w,escaped:F,LWS:q,SWS:D,HCOLON:P,TEXT_UTF8_TRIM:I,TEXT_UTF8char:x,UTF8_NONASCII:U,UTF8_CONT:B,LHEX:z,token:L,token_nodot:V,separators:J,word:Pe,STAR:ee,SLASH:j,EQUAL:K,LPAREN:ie,RPAREN:ue,RAQUOT:Ce,LAQUOT:ke,COMMA:be,SEMI:M,COLON:Y,LDQUOT:Ee,RDQUOT:Me,comment:fe,ctext:_e,quoted_string:we,quoted_string_clean:De,qdtext:ce,quoted_pair:de,SIP_URI_noparams:ge,SIP_URI:Oe,uri_scheme:$e,uri_scheme_sips:_t,uri_scheme_sip:Ye,userinfo:ts,user:Dt,user_unreserved:Ai,password:bi,hostport:Un,host:Es,hostname:ks,domainlabel:Ln,toplabel:Ri,IPv6reference:wi,IPv6address:Fn,h16:Ae,ls32:me,IPv4address:Et,dec_octet:hs,port:sn,uri_parameters:Dr,uri_parameter:Ii,transport_param:Oi,user_param:Nr,method_param:Pr,ttl_param:xr,maddr_param:kr,lr_param:Mr,other_param:Ur,pname:Lr,pvalue:Fr,paramchar:nn,param_unreserved:rn,headers:$r,header:$n,hname:Hn,hvalue:Hr,hnv_unreserved:ln,Request_Response:Gn,Request_Line:Fa,Request_URI:Gr,absoluteURI:Di,hier_part:Ni,net_path:Vr,abs_path:Vn,opaque_part:Bn,uric:an,uric_no_slash:on,path_segments:Br,segment:jn,param:un,pchar:Ms,scheme:cn,authority:jr,srvr:qr,reg_name:Wr,query:Kr,SIP_Version:Pi,INVITEm:xi,ACKm:Yr,OPTIONSm:zr,BYEm:Xr,CANCELm:Jr,REGISTERm:Qr,SUBSCRIBEm:Zr,NOTIFYm:el,REFERm:tl,Method:qn,Status_Line:Wn,Status_Code:sl,extension_code:nl,Reason_Phrase:il,Allow_Events:$a,Call_ID:yc,Contact:Sc,contact_param:ki,name_addr:ss,display_name:ns,contact_params:hn,c_p_q:Mi,c_p_expires:rl,delta_seconds:Cs,qvalue:As,generic_param:rt,gen_value:lt,Content_Disposition:Ha,disp_type:Ga,disp_param:Ui,handling_param:Li,Content_Encoding:Va,Content_Length:Ec,Content_Type:Cc,media_type:Ba,m_type:ll,discrete_type:al,composite_type:ol,extension_token:Kn,x_token:Yn,m_subtype:ul,m_parameter:Fi,m_value:$i,CSeq:ja,CSeq_value:qa,Expires:Wa,Event:Ac,event_type:zn,From:Xn,from_param:cl,tag_param:Jn,Max_Forwards:hl,Min_Expires:bc,Name_Addr_Header:Rc,Proxy_Authenticate:wc,challenge:fl,other_challenge:Hi,auth_param:fn,digest_cln:bs,realm:Qn,realm_value:dl,domain:_l,URI:Zn,nonce:ei,nonce_value:gl,opaque:pl,stale:ml,algorithm:vl,qop_options:Tl,qop_value:ti,Proxy_Require:Gi,Record_Route:Ic,rec_route:Vi,Reason:Bi,reason_param:yl,reason_cause:ji,Require:Ka,Route:Oc,route_param:qi,Subscription_State:Wi,substate_value:Ya,subexp_params:Ki,event_reason_value:Yi,Subject:za,Supported:Dc,To:Nc,to_param:Sl,Via:El,via_param:zi,via_params:dn,via_ttl:Xi,via_maddr:Cl,via_received:Al,via_branch:bl,response_port:Rl,rport:wl,sent_protocol:Il,protocol_name:Ol,transport:Dl,sent_by:Nl,via_host:Pl,via_port:xl,ttl:Ji,WWW_Authenticate:kl,Session_Expires:Pc,s_e_expires:Xa,s_e_params:Qi,s_e_refresher:Zi,extension_header:Ja,header_value:Qa,message_body:Za,uuid_URI:xc,uuid:eo,hex4:is,hex8:rs,hex12:Ml,Refer_To:to,Replaces:kc,call_id:so,replaces_param:er,to_tag:tr,from_tag:Ul,early_flag:Ll};if(r!==void 0){if(l[r]===void 0)throw new Error("Invalid rule name: "+u(r)+".")}else r="CRLF";var s=0,i=0,f=[];function h(a){s<i||(s>i&&(i=s,f=[]),f.push(a))}function d(){var a;return t.substr(s,2)===`\r
73
- `?(a=`\r
74
- `,s+=2):(a=null,h('"\\r\\n"')),a}function p(){var a;return/^[0-9]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[0-9]")),a}function v(){var a;return/^[a-zA-Z]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[a-zA-Z]")),a}function T(){var a;return/^[0-9a-fA-F]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[0-9a-fA-F]")),a}function y(){var a;return a=R(),a===null&&(a=O()),a}function S(){var a;return/^[\0-\xFF]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[\\0-\\xFF]")),a}function A(){var a;return/^["]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h('["]')),a}function R(){var a;return t.charCodeAt(s)===32?(a=" ",s++):(a=null,h('" "')),a}function O(){var a;return t.charCodeAt(s)===9?(a=" ",s++):(a=null,h('"\\t"')),a}function N(){var a;return/^[a-zA-Z0-9]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[a-zA-Z0-9]")),a}function C(){var a;return t.charCodeAt(s)===59?(a=";",s++):(a=null,h('";"')),a===null&&(t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a===null&&(t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===64?(a="@",s++):(a=null,h('"@"')),a===null&&(t.charCodeAt(s)===38?(a="&",s++):(a=null,h('"&"')),a===null&&(t.charCodeAt(s)===61?(a="=",s++):(a=null,h('"="')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')),a===null&&(t.charCodeAt(s)===44?(a=",",s++):(a=null,h('","'))))))))))),a}function b(){var a;return a=N(),a===null&&(a=w()),a}function w(){var a;return t.charCodeAt(s)===45?(a="-",s++):(a=null,h('"-"')),a===null&&(t.charCodeAt(s)===95?(a="_",s++):(a=null,h('"_"')),a===null&&(t.charCodeAt(s)===46?(a=".",s++):(a=null,h('"."')),a===null&&(t.charCodeAt(s)===33?(a="!",s++):(a=null,h('"!"')),a===null&&(t.charCodeAt(s)===126?(a="~",s++):(a=null,h('"~"')),a===null&&(t.charCodeAt(s)===42?(a="*",s++):(a=null,h('"*"')),a===null&&(t.charCodeAt(s)===39?(a="'",s++):(a=null,h(`"'"`)),a===null&&(t.charCodeAt(s)===40?(a="(",s++):(a=null,h('"("')),a===null&&(t.charCodeAt(s)===41?(a=")",s++):(a=null,h('")"')))))))))),a}function F(){var a,n,o,c,_;return c=s,_=s,t.charCodeAt(s)===37?(a="%",s++):(a=null,h('"%"')),a!==null?(n=T(),n!==null?(o=T(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){return m.join("")}(c,a)),a===null&&(s=c),a}function q(){var a,n,o,c,_,g;for(c=s,_=s,g=s,a=[],n=y();n!==null;)a.push(n),n=y();if(a!==null?(n=d(),n!==null?a=[a,n]:(a=null,s=g)):(a=null,s=g),a=a!==null?a:"",a!==null){if(o=y(),o!==null)for(n=[];o!==null;)n.push(o),o=y();else n=null;n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a!==null&&(a=function(m){return" "}()),a===null&&(s=c),a}function D(){var a;return a=q(),a=a!==null?a:"",a}function P(){var a,n,o,c,_;for(c=s,_=s,a=[],n=R(),n===null&&(n=O());n!==null;)a.push(n),n=R(),n===null&&(n=O());return a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return":"}()),a===null&&(s=c),a}function I(){var a,n,o,c,_,g,m;if(_=s,g=s,n=x(),n!==null)for(a=[];n!==null;)a.push(n),n=x();else a=null;if(a!==null){for(n=[],m=s,o=[],c=q();c!==null;)o.push(c),c=q();for(o!==null?(c=x(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;){for(n.push(o),m=s,o=[],c=q();c!==null;)o.push(c),c=q();o!==null?(c=x(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m)}n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){return t.substring(s,E)}(_)),a===null&&(s=_),a}function x(){var a;return/^[!-~]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[!-~]")),a===null&&(a=U()),a}function U(){var a;return/^[\x80-\uFFFF]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[\\x80-\\uFFFF]")),a}function B(){var a;return/^[\x80-\xBF]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[\\x80-\\xBF]")),a}function z(){var a;return a=p(),a===null&&(/^[a-f]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[a-f]"))),a}function L(){var a,n,o;if(o=s,n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"')))))))))))),n!==null)for(a=[];n!==null;)a.push(n),n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"'))))))))))));else a=null;return a!==null&&(a=function(c){return t.substring(s,c)}(o)),a===null&&(s=o),a}function V(){var a,n,o;if(o=s,n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"'))))))))))),n!==null)for(a=[];n!==null;)a.push(n),n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"')))))))))));else a=null;return a!==null&&(a=function(c){return t.substring(s,c)}(o)),a===null&&(s=o),a}function J(){var a;return t.charCodeAt(s)===40?(a="(",s++):(a=null,h('"("')),a===null&&(t.charCodeAt(s)===41?(a=")",s++):(a=null,h('")"')),a===null&&(t.charCodeAt(s)===60?(a="<",s++):(a=null,h('"<"')),a===null&&(t.charCodeAt(s)===62?(a=">",s++):(a=null,h('">"')),a===null&&(t.charCodeAt(s)===64?(a="@",s++):(a=null,h('"@"')),a===null&&(t.charCodeAt(s)===44?(a=",",s++):(a=null,h('","')),a===null&&(t.charCodeAt(s)===59?(a=";",s++):(a=null,h('";"')),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===92?(a="\\",s++):(a=null,h('"\\\\"')),a===null&&(a=A(),a===null&&(t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a===null&&(t.charCodeAt(s)===91?(a="[",s++):(a=null,h('"["')),a===null&&(t.charCodeAt(s)===93?(a="]",s++):(a=null,h('"]"')),a===null&&(t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a===null&&(t.charCodeAt(s)===61?(a="=",s++):(a=null,h('"="')),a===null&&(t.charCodeAt(s)===123?(a="{",s++):(a=null,h('"{"')),a===null&&(t.charCodeAt(s)===125?(a="}",s++):(a=null,h('"}"')),a===null&&(a=R(),a===null&&(a=O())))))))))))))))))),a}function Pe(){var a,n,o;if(o=s,n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"')),n===null&&(t.charCodeAt(s)===40?(n="(",s++):(n=null,h('"("')),n===null&&(t.charCodeAt(s)===41?(n=")",s++):(n=null,h('")"')),n===null&&(t.charCodeAt(s)===60?(n="<",s++):(n=null,h('"<"')),n===null&&(t.charCodeAt(s)===62?(n=">",s++):(n=null,h('">"')),n===null&&(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n===null&&(t.charCodeAt(s)===92?(n="\\",s++):(n=null,h('"\\\\"')),n===null&&(n=A(),n===null&&(t.charCodeAt(s)===47?(n="/",s++):(n=null,h('"/"')),n===null&&(t.charCodeAt(s)===91?(n="[",s++):(n=null,h('"["')),n===null&&(t.charCodeAt(s)===93?(n="]",s++):(n=null,h('"]"')),n===null&&(t.charCodeAt(s)===63?(n="?",s++):(n=null,h('"?"')),n===null&&(t.charCodeAt(s)===123?(n="{",s++):(n=null,h('"{"')),n===null&&(t.charCodeAt(s)===125?(n="}",s++):(n=null,h('"}"'))))))))))))))))))))))))),n!==null)for(a=[];n!==null;)a.push(n),n=N(),n===null&&(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n===null&&(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n===null&&(t.charCodeAt(s)===33?(n="!",s++):(n=null,h('"!"')),n===null&&(t.charCodeAt(s)===37?(n="%",s++):(n=null,h('"%"')),n===null&&(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n===null&&(t.charCodeAt(s)===95?(n="_",s++):(n=null,h('"_"')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===96?(n="`",s++):(n=null,h('"`"')),n===null&&(t.charCodeAt(s)===39?(n="'",s++):(n=null,h(`"'"`)),n===null&&(t.charCodeAt(s)===126?(n="~",s++):(n=null,h('"~"')),n===null&&(t.charCodeAt(s)===40?(n="(",s++):(n=null,h('"("')),n===null&&(t.charCodeAt(s)===41?(n=")",s++):(n=null,h('")"')),n===null&&(t.charCodeAt(s)===60?(n="<",s++):(n=null,h('"<"')),n===null&&(t.charCodeAt(s)===62?(n=">",s++):(n=null,h('">"')),n===null&&(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n===null&&(t.charCodeAt(s)===92?(n="\\",s++):(n=null,h('"\\\\"')),n===null&&(n=A(),n===null&&(t.charCodeAt(s)===47?(n="/",s++):(n=null,h('"/"')),n===null&&(t.charCodeAt(s)===91?(n="[",s++):(n=null,h('"["')),n===null&&(t.charCodeAt(s)===93?(n="]",s++):(n=null,h('"]"')),n===null&&(t.charCodeAt(s)===63?(n="?",s++):(n=null,h('"?"')),n===null&&(t.charCodeAt(s)===123?(n="{",s++):(n=null,h('"{"')),n===null&&(t.charCodeAt(s)===125?(n="}",s++):(n=null,h('"}"')))))))))))))))))))))))));else a=null;return a!==null&&(a=function(c){return t.substring(s,c)}(o)),a===null&&(s=o),a}function ee(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===42?(n="*",s++):(n=null,h('"*"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return"*"}()),a===null&&(s=c),a}function j(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===47?(n="/",s++):(n=null,h('"/"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return"/"}()),a===null&&(s=c),a}function K(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return"="}()),a===null&&(s=c),a}function ie(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===40?(n="(",s++):(n=null,h('"("')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return"("}()),a===null&&(s=c),a}function ue(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===41?(n=")",s++):(n=null,h('")"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return")"}()),a===null&&(s=c),a}function Ce(){var a,n,o,c;return o=s,c=s,t.charCodeAt(s)===62?(a=">",s++):(a=null,h('">"')),a!==null?(n=D(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_){return">"}()),a===null&&(s=o),a}function ke(){var a,n,o,c;return o=s,c=s,a=D(),a!==null?(t.charCodeAt(s)===60?(n="<",s++):(n=null,h('"<"')),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_){return"<"}()),a===null&&(s=o),a}function be(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===44?(n=",",s++):(n=null,h('","')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return","}()),a===null&&(s=c),a}function M(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return";"}()),a===null&&(s=c),a}function Y(){var a,n,o,c,_;return c=s,_=s,a=D(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=D(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return":"}()),a===null&&(s=c),a}function Ee(){var a,n,o,c;return o=s,c=s,a=D(),a!==null?(n=A(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_){return'"'}()),a===null&&(s=o),a}function Me(){var a,n,o,c;return o=s,c=s,a=A(),a!==null?(n=D(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_){return'"'}()),a===null&&(s=o),a}function fe(){var a,n,o,c;if(c=s,a=ie(),a!==null){for(n=[],o=_e(),o===null&&(o=de(),o===null&&(o=fe()));o!==null;)n.push(o),o=_e(),o===null&&(o=de(),o===null&&(o=fe()));n!==null?(o=ue(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)}else a=null,s=c;return a}function _e(){var a;return/^[!-']/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[!-']")),a===null&&(/^[*-[]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[*-[]")),a===null&&(/^[\]-~]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[\\]-~]")),a===null&&(a=U(),a===null&&(a=q())))),a}function we(){var a,n,o,c,_,g;if(_=s,g=s,a=D(),a!==null)if(n=A(),n!==null){for(o=[],c=ce(),c===null&&(c=de());c!==null;)o.push(c),c=ce(),c===null&&(c=de());o!==null?(c=A(),c!==null?a=[a,n,o,c]:(a=null,s=g)):(a=null,s=g)}else a=null,s=g;else a=null,s=g;return a!==null&&(a=function(m){return t.substring(s,m)}(_)),a===null&&(s=_),a}function De(){var a,n,o,c,_,g;if(_=s,g=s,a=D(),a!==null)if(n=A(),n!==null){for(o=[],c=ce(),c===null&&(c=de());c!==null;)o.push(c),c=ce(),c===null&&(c=de());o!==null?(c=A(),c!==null?a=[a,n,o,c]:(a=null,s=g)):(a=null,s=g)}else a=null,s=g;else a=null,s=g;return a!==null&&(a=function(m){var E=t.substring(s,m).trim();return E.substring(1,E.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(_)),a===null&&(s=_),a}function ce(){var a;return a=q(),a===null&&(t.charCodeAt(s)===33?(a="!",s++):(a=null,h('"!"')),a===null&&(/^[#-[]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[#-[]")),a===null&&(/^[\]-~]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[\\]-~]")),a===null&&(a=U())))),a}function de(){var a,n,o;return o=s,t.charCodeAt(s)===92?(a="\\",s++):(a=null,h('"\\\\"')),a!==null?(/^[\0-\t]/.test(t.charAt(s))?(n=t.charAt(s),s++):(n=null,h("[\\0-\\t]")),n===null&&(/^[\x0B-\f]/.test(t.charAt(s))?(n=t.charAt(s),s++):(n=null,h("[\\x0B-\\f]")),n===null&&(/^[\x0E-]/.test(t.charAt(s))?(n=t.charAt(s),s++):(n=null,h("[\\x0E-]")))),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function ge(){var a,n,o,c,_,g;return _=s,g=s,a=$e(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=ts(),o=o!==null?o:"",o!==null?(c=Un(),c!==null?a=[a,n,o,c]:(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g),a!==null&&(a=function(m){try{H.uri=new io(H.scheme,H.user,H.host,H.port),delete H.scheme,delete H.user,delete H.host,delete H.host_type,delete H.port}catch{H=-1}}()),a===null&&(s=_),a}function Oe(){var a,n,o,c,_,g,m,E;return m=s,E=s,a=$e(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=ts(),o=o!==null?o:"",o!==null?(c=Un(),c!==null?(_=Dr(),_!==null?(g=$r(),g=g!==null?g:"",g!==null?a=[a,n,o,c,_,g]:(a=null,s=E)):(a=null,s=E)):(a=null,s=E)):(a=null,s=E)):(a=null,s=E)):(a=null,s=E),a!==null&&(a=function(k){try{H.uri=new io(H.scheme,H.user,H.host,H.port,H.uri_params,H.uri_headers),delete H.scheme,delete H.user,delete H.host,delete H.host_type,delete H.port,delete H.uri_params,r==="SIP_URI"&&(H=H.uri)}catch{H=-1}}()),a===null&&(s=m),a}function $e(){var a;return a=_t(),a===null&&(a=Ye()),a}function _t(){var a,n;return n=s,t.substr(s,4).toLowerCase()==="sips"?(a=t.substr(s,4),s+=4):(a=null,h('"sips"')),a!==null&&(a=function(o,c){H.scheme=c.toLowerCase()}(n,a)),a===null&&(s=n),a}function Ye(){var a,n;return n=s,t.substr(s,3).toLowerCase()==="sip"?(a=t.substr(s,3),s+=3):(a=null,h('"sip"')),a!==null&&(a=function(o,c){H.scheme=c.toLowerCase()}(n,a)),a===null&&(s=n),a}function ts(){var a,n,o,c,_,g;return c=s,_=s,a=Dt(),a!==null?(g=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=bi(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?(t.charCodeAt(s)===64?(o="@",s++):(o=null,h('"@"')),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m){H.user=decodeURIComponent(t.substring(s-1,m))}(c)),a===null&&(s=c),a}function Dt(){var a,n;if(n=b(),n===null&&(n=F(),n===null&&(n=Ai())),n!==null)for(a=[];n!==null;)a.push(n),n=b(),n===null&&(n=F(),n===null&&(n=Ai()));else a=null;return a}function Ai(){var a;return t.charCodeAt(s)===38?(a="&",s++):(a=null,h('"&"')),a===null&&(t.charCodeAt(s)===61?(a="=",s++):(a=null,h('"="')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')),a===null&&(t.charCodeAt(s)===44?(a=",",s++):(a=null,h('","')),a===null&&(t.charCodeAt(s)===59?(a=";",s++):(a=null,h('";"')),a===null&&(t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a===null&&(t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"'))))))))),a}function bi(){var a,n,o;for(o=s,a=[],n=b(),n===null&&(n=F(),n===null&&(t.charCodeAt(s)===38?(n="&",s++):(n=null,h('"&"')),n===null&&(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===36?(n="$",s++):(n=null,h('"$"')),n===null&&(t.charCodeAt(s)===44?(n=",",s++):(n=null,h('","'))))))));n!==null;)a.push(n),n=b(),n===null&&(n=F(),n===null&&(t.charCodeAt(s)===38?(n="&",s++):(n=null,h('"&"')),n===null&&(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')),n===null&&(t.charCodeAt(s)===36?(n="$",s++):(n=null,h('"$"')),n===null&&(t.charCodeAt(s)===44?(n=",",s++):(n=null,h('","'))))))));return a!==null&&(a=function(c){H.password=t.substring(s,c)}(o)),a===null&&(s=o),a}function Un(){var a,n,o,c,_;return c=s,a=Es(),a!==null?(_=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=sn(),o!==null?n=[n,o]:(n=null,s=_)):(n=null,s=_),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a}function Es(){var a,n;return n=s,a=ks(),a===null&&(a=Et(),a===null&&(a=wi())),a!==null&&(a=function(o){return H.host=t.substring(s,o).toLowerCase(),H.host}(n)),a===null&&(s=n),a}function ks(){var a,n,o,c,_,g;for(c=s,_=s,a=[],g=s,n=Ln(),n!==null?(t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."')),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g);n!==null;)a.push(n),g=s,n=Ln(),n!==null?(t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."')),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g);return a!==null?(n=Ri(),n!==null?(t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."')),o=o!==null?o:"",o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m){return H.host_type="domain",t.substring(s,m)}(c)),a===null&&(s=c),a}function Ln(){var a,n,o,c;if(c=s,a=N(),a!==null){for(n=[],o=N(),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===95?(o="_",s++):(o=null,h('"_"'))));o!==null;)n.push(o),o=N(),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===95?(o="_",s++):(o=null,h('"_"'))));n!==null?a=[a,n]:(a=null,s=c)}else a=null,s=c;return a}function Ri(){var a,n,o,c;if(c=s,a=v(),a!==null){for(n=[],o=N(),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===95?(o="_",s++):(o=null,h('"_"'))));o!==null;)n.push(o),o=N(),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===95?(o="_",s++):(o=null,h('"_"'))));n!==null?a=[a,n]:(a=null,s=c)}else a=null,s=c;return a}function wi(){var a,n,o,c,_;return c=s,_=s,t.charCodeAt(s)===91?(a="[",s++):(a=null,h('"["')),a!==null?(n=Fn(),n!==null?(t.charCodeAt(s)===93?(o="]",s++):(o=null,h('"]"')),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g){return H.host_type="IPv6",t.substring(s,g)}(c)),a===null&&(s=c),a}function Fn(){var a,n,o,c,_,g,m,E,k,W,pe,He,Wt,_n,Q,$;return _n=s,Q=s,a=Ae(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?(t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?(t.charCodeAt(s)===58?(g=":",s++):(g=null,h('":"')),g!==null?(m=Ae(),m!==null?(t.charCodeAt(s)===58?(E=":",s++):(E=null,h('":"')),E!==null?(k=Ae(),k!==null?(t.charCodeAt(s)===58?(W=":",s++):(W=null,h('":"')),W!==null?(pe=Ae(),pe!==null?(t.charCodeAt(s)===58?(He=":",s++):(He=null,h('":"')),He!==null?(Wt=me(),Wt!==null?a=[a,n,o,c,_,g,m,E,k,W,pe,He,Wt]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?(t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?(t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?(t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=Ae(),E!==null?(t.charCodeAt(s)===58?(k=":",s++):(k=null,h('":"')),k!==null?(W=Ae(),W!==null?(t.charCodeAt(s)===58?(pe=":",s++):(pe=null,h('":"')),pe!==null?(He=me(),He!==null?a=[a,n,o,c,_,g,m,E,k,W,pe,He]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?(t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?(t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?(t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=Ae(),E!==null?(t.charCodeAt(s)===58?(k=":",s++):(k=null,h('":"')),k!==null?(W=me(),W!==null?a=[a,n,o,c,_,g,m,E,k,W]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?(t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?(t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?(t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=me(),E!==null?a=[a,n,o,c,_,g,m,E]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?(t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?(t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=me(),g!==null?a=[a,n,o,c,_,g]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?(t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=me(),c!==null?a=[a,n,o,c]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=me(),n!==null?a=[a,n]:(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,t.substr(s,2)==="::"?(a="::",s+=2):(a=null,h('"::"')),a!==null?(n=Ae(),n!==null?a=[a,n]:(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?(t.substr(s,2)==="::"?(n="::",s+=2):(n=null,h('"::"')),n!==null?(o=Ae(),o!==null?(t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?(t.charCodeAt(s)===58?(g=":",s++):(g=null,h('":"')),g!==null?(m=Ae(),m!==null?(t.charCodeAt(s)===58?(E=":",s++):(E=null,h('":"')),E!==null?(k=Ae(),k!==null?(t.charCodeAt(s)===58?(W=":",s++):(W=null,h('":"')),W!==null?(pe=me(),pe!==null?a=[a,n,o,c,_,g,m,E,k,W,pe]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?(t.substr(s,2)==="::"?(o="::",s+=2):(o=null,h('"::"')),o!==null?(c=Ae(),c!==null?(t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?(t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=Ae(),E!==null?(t.charCodeAt(s)===58?(k=":",s++):(k=null,h('":"')),k!==null?(W=me(),W!==null?a=[a,n,o,c,_,g,m,E,k,W]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?($=s,t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?o=[o,c]:(o=null,s=$)):(o=null,s=$),o=o!==null?o:"",o!==null?(t.substr(s,2)==="::"?(c="::",s+=2):(c=null,h('"::"')),c!==null?(_=Ae(),_!==null?(t.charCodeAt(s)===58?(g=":",s++):(g=null,h('":"')),g!==null?(m=Ae(),m!==null?(t.charCodeAt(s)===58?(E=":",s++):(E=null,h('":"')),E!==null?(k=me(),k!==null?a=[a,n,o,c,_,g,m,E,k]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?($=s,t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?o=[o,c]:(o=null,s=$)):(o=null,s=$),o=o!==null?o:"",o!==null?($=s,t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?c=[c,_]:(c=null,s=$)):(c=null,s=$),c=c!==null?c:"",c!==null?(t.substr(s,2)==="::"?(_="::",s+=2):(_=null,h('"::"')),_!==null?(g=Ae(),g!==null?(t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=me(),E!==null?a=[a,n,o,c,_,g,m,E]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?($=s,t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?o=[o,c]:(o=null,s=$)):(o=null,s=$),o=o!==null?o:"",o!==null?($=s,t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?c=[c,_]:(c=null,s=$)):(c=null,s=$),c=c!==null?c:"",c!==null?($=s,t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?_=[_,g]:(_=null,s=$)):(_=null,s=$),_=_!==null?_:"",_!==null?(t.substr(s,2)==="::"?(g="::",s+=2):(g=null,h('"::"')),g!==null?(m=me(),m!==null?a=[a,n,o,c,_,g,m]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?($=s,t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?o=[o,c]:(o=null,s=$)):(o=null,s=$),o=o!==null?o:"",o!==null?($=s,t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?c=[c,_]:(c=null,s=$)):(c=null,s=$),c=c!==null?c:"",c!==null?($=s,t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?_=[_,g]:(_=null,s=$)):(_=null,s=$),_=_!==null?_:"",_!==null?($=s,t.charCodeAt(s)===58?(g=":",s++):(g=null,h('":"')),g!==null?(m=Ae(),m!==null?g=[g,m]:(g=null,s=$)):(g=null,s=$),g=g!==null?g:"",g!==null?(t.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(E=Ae(),E!==null?a=[a,n,o,c,_,g,m,E]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q),a===null&&(Q=s,a=Ae(),a!==null?($=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?n=[n,o]:(n=null,s=$)):(n=null,s=$),n=n!==null?n:"",n!==null?($=s,t.charCodeAt(s)===58?(o=":",s++):(o=null,h('":"')),o!==null?(c=Ae(),c!==null?o=[o,c]:(o=null,s=$)):(o=null,s=$),o=o!==null?o:"",o!==null?($=s,t.charCodeAt(s)===58?(c=":",s++):(c=null,h('":"')),c!==null?(_=Ae(),_!==null?c=[c,_]:(c=null,s=$)):(c=null,s=$),c=c!==null?c:"",c!==null?($=s,t.charCodeAt(s)===58?(_=":",s++):(_=null,h('":"')),_!==null?(g=Ae(),g!==null?_=[_,g]:(_=null,s=$)):(_=null,s=$),_=_!==null?_:"",_!==null?($=s,t.charCodeAt(s)===58?(g=":",s++):(g=null,h('":"')),g!==null?(m=Ae(),m!==null?g=[g,m]:(g=null,s=$)):(g=null,s=$),g=g!==null?g:"",g!==null?($=s,t.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(E=Ae(),E!==null?m=[m,E]:(m=null,s=$)):(m=null,s=$),m=m!==null?m:"",m!==null?(t.substr(s,2)==="::"?(E="::",s+=2):(E=null,h('"::"')),E!==null?a=[a,n,o,c,_,g,m,E]:(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q)):(a=null,s=Q))))))))))))))),a!==null&&(a=function(Re){return H.host_type="IPv6",t.substring(s,Re)}(_n)),a===null&&(s=_n),a}function Ae(){var a,n,o,c,_;return _=s,a=T(),a!==null?(n=T(),n=n!==null?n:"",n!==null?(o=T(),o=o!==null?o:"",o!==null?(c=T(),c=c!==null?c:"",c!==null?a=[a,n,o,c]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a}function me(){var a,n,o,c;return c=s,a=Ae(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ae(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a===null&&(a=Et()),a}function Et(){var a,n,o,c,_,g,m,E,k;return E=s,k=s,a=hs(),a!==null?(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n!==null?(o=hs(),o!==null?(t.charCodeAt(s)===46?(c=".",s++):(c=null,h('"."')),c!==null?(_=hs(),_!==null?(t.charCodeAt(s)===46?(g=".",s++):(g=null,h('"."')),g!==null?(m=hs(),m!==null?a=[a,n,o,c,_,g,m]:(a=null,s=k)):(a=null,s=k)):(a=null,s=k)):(a=null,s=k)):(a=null,s=k)):(a=null,s=k)):(a=null,s=k),a!==null&&(a=function(W){return H.host_type="IPv4",t.substring(s,W)}(E)),a===null&&(s=E),a}function hs(){var a,n,o,c;return c=s,t.substr(s,2)==="25"?(a="25",s+=2):(a=null,h('"25"')),a!==null?(/^[0-5]/.test(t.charAt(s))?(n=t.charAt(s),s++):(n=null,h("[0-5]")),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a===null&&(c=s,t.charCodeAt(s)===50?(a="2",s++):(a=null,h('"2"')),a!==null?(/^[0-4]/.test(t.charAt(s))?(n=t.charAt(s),s++):(n=null,h("[0-4]")),n!==null?(o=p(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a===null&&(c=s,t.charCodeAt(s)===49?(a="1",s++):(a=null,h('"1"')),a!==null?(n=p(),n!==null?(o=p(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a===null&&(c=s,/^[1-9]/.test(t.charAt(s))?(a=t.charAt(s),s++):(a=null,h("[1-9]")),a!==null?(n=p(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a===null&&(a=p())))),a}function sn(){var a,n,o,c,_,g,m;return g=s,m=s,a=p(),a=a!==null?a:"",a!==null?(n=p(),n=n!==null?n:"",n!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(_=p(),_=_!==null?_:"",_!==null?a=[a,n,o,c,_]:(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m),a!==null&&(a=function(E,k){return k=parseInt(k.join("")),H.port=k,k}(g,a)),a===null&&(s=g),a}function Dr(){var a,n,o,c;for(a=[],c=s,t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n!==null?(o=Ii(),o!==null?n=[n,o]:(n=null,s=c)):(n=null,s=c);n!==null;)a.push(n),c=s,t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n!==null?(o=Ii(),o!==null?n=[n,o]:(n=null,s=c)):(n=null,s=c);return a}function Ii(){var a;return a=Oi(),a===null&&(a=Nr(),a===null&&(a=Pr(),a===null&&(a=xr(),a===null&&(a=kr(),a===null&&(a=Mr(),a===null&&(a=Ur())))))),a}function Oi(){var a,n,o,c;return o=s,c=s,t.substr(s,10).toLowerCase()==="transport="?(a=t.substr(s,10),s+=10):(a=null,h('"transport="')),a!==null?(t.substr(s,3).toLowerCase()==="udp"?(n=t.substr(s,3),s+=3):(n=null,h('"udp"')),n===null&&(t.substr(s,3).toLowerCase()==="tcp"?(n=t.substr(s,3),s+=3):(n=null,h('"tcp"')),n===null&&(t.substr(s,4).toLowerCase()==="sctp"?(n=t.substr(s,4),s+=4):(n=null,h('"sctp"')),n===null&&(t.substr(s,3).toLowerCase()==="tls"?(n=t.substr(s,3),s+=3):(n=null,h('"tls"')),n===null&&(n=L())))),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_,g){H.uri_params||(H.uri_params={}),H.uri_params.transport=g.toLowerCase()}(o,a[1])),a===null&&(s=o),a}function Nr(){var a,n,o,c;return o=s,c=s,t.substr(s,5).toLowerCase()==="user="?(a=t.substr(s,5),s+=5):(a=null,h('"user="')),a!==null?(t.substr(s,5).toLowerCase()==="phone"?(n=t.substr(s,5),s+=5):(n=null,h('"phone"')),n===null&&(t.substr(s,2).toLowerCase()==="ip"?(n=t.substr(s,2),s+=2):(n=null,h('"ip"')),n===null&&(n=L())),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_,g){H.uri_params||(H.uri_params={}),H.uri_params.user=g.toLowerCase()}(o,a[1])),a===null&&(s=o),a}function Pr(){var a,n,o,c;return o=s,c=s,t.substr(s,7).toLowerCase()==="method="?(a=t.substr(s,7),s+=7):(a=null,h('"method="')),a!==null?(n=qn(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_,g){H.uri_params||(H.uri_params={}),H.uri_params.method=g}(o,a[1])),a===null&&(s=o),a}function xr(){var a,n,o,c;return o=s,c=s,t.substr(s,4).toLowerCase()==="ttl="?(a=t.substr(s,4),s+=4):(a=null,h('"ttl="')),a!==null?(n=Ji(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_,g){H.params||(H.params={}),H.params.ttl=g}(o,a[1])),a===null&&(s=o),a}function kr(){var a,n,o,c;return o=s,c=s,t.substr(s,6).toLowerCase()==="maddr="?(a=t.substr(s,6),s+=6):(a=null,h('"maddr="')),a!==null?(n=Es(),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a!==null&&(a=function(_,g){H.uri_params||(H.uri_params={}),H.uri_params.maddr=g}(o,a[1])),a===null&&(s=o),a}function Mr(){var a,n,o,c,_,g;return c=s,_=s,t.substr(s,2).toLowerCase()==="lr"?(a=t.substr(s,2),s+=2):(a=null,h('"lr"')),a!==null?(g=s,t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=L(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m){H.uri_params||(H.uri_params={}),H.uri_params.lr=void 0}()),a===null&&(s=c),a}function Ur(){var a,n,o,c,_,g;return c=s,_=s,a=Lr(),a!==null?(g=s,t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=Fr(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m,E,k){H.uri_params||(H.uri_params={}),typeof k>"u"?k=void 0:k=k[1],H.uri_params[E.toLowerCase()]=k}(c,a[0],a[1])),a===null&&(s=c),a}function Lr(){var a,n,o;if(o=s,n=nn(),n!==null)for(a=[];n!==null;)a.push(n),n=nn();else a=null;return a!==null&&(a=function(c,_){return _.join("")}(o,a)),a===null&&(s=o),a}function Fr(){var a,n,o;if(o=s,n=nn(),n!==null)for(a=[];n!==null;)a.push(n),n=nn();else a=null;return a!==null&&(a=function(c,_){return _.join("")}(o,a)),a===null&&(s=o),a}function nn(){var a;return a=rn(),a===null&&(a=b(),a===null&&(a=F())),a}function rn(){var a;return t.charCodeAt(s)===91?(a="[",s++):(a=null,h('"["')),a===null&&(t.charCodeAt(s)===93?(a="]",s++):(a=null,h('"]"')),a===null&&(t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===38?(a="&",s++):(a=null,h('"&"')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')))))))),a}function $r(){var a,n,o,c,_,g,m;if(g=s,t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a!==null)if(n=$n(),n!==null){for(o=[],m=s,t.charCodeAt(s)===38?(c="&",s++):(c=null,h('"&"')),c!==null?(_=$n(),_!==null?c=[c,_]:(c=null,s=m)):(c=null,s=m);c!==null;)o.push(c),m=s,t.charCodeAt(s)===38?(c="&",s++):(c=null,h('"&"')),c!==null?(_=$n(),_!==null?c=[c,_]:(c=null,s=m)):(c=null,s=m);o!==null?a=[a,n,o]:(a=null,s=g)}else a=null,s=g;else a=null,s=g;return a}function $n(){var a,n,o,c,_;return c=s,_=s,a=Hn(),a!==null?(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=Hr(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m,E){m=m.join("").toLowerCase(),E=E.join(""),H.uri_headers||(H.uri_headers={}),H.uri_headers[m]?H.uri_headers[m].push(E):H.uri_headers[m]=[E]}(c,a[0],a[2])),a===null&&(s=c),a}function Hn(){var a,n;if(n=ln(),n===null&&(n=b(),n===null&&(n=F())),n!==null)for(a=[];n!==null;)a.push(n),n=ln(),n===null&&(n=b(),n===null&&(n=F()));else a=null;return a}function Hr(){var a,n;for(a=[],n=ln(),n===null&&(n=b(),n===null&&(n=F()));n!==null;)a.push(n),n=ln(),n===null&&(n=b(),n===null&&(n=F()));return a}function ln(){var a;return t.charCodeAt(s)===91?(a="[",s++):(a=null,h('"["')),a===null&&(t.charCodeAt(s)===93?(a="]",s++):(a=null,h('"]"')),a===null&&(t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a===null&&(t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')))))))),a}function Gn(){var a;return a=Wn(),a===null&&(a=Fa()),a}function Fa(){var a,n,o,c,_,g;return g=s,a=qn(),a!==null?(n=R(),n!==null?(o=Gr(),o!==null?(c=R(),c!==null?(_=Pi(),_!==null?a=[a,n,o,c,_]:(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g),a}function Gr(){var a;return a=Oe(),a===null&&(a=Di()),a}function Di(){var a,n,o,c;return c=s,a=cn(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Ni(),o===null&&(o=Bn()),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function Ni(){var a,n,o,c,_;return c=s,a=Vr(),a===null&&(a=Vn()),a!==null?(_=s,t.charCodeAt(s)===63?(n="?",s++):(n=null,h('"?"')),n!==null?(o=Kr(),o!==null?n=[n,o]:(n=null,s=_)):(n=null,s=_),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a}function Vr(){var a,n,o,c;return c=s,t.substr(s,2)==="//"?(a="//",s+=2):(a=null,h('"//"')),a!==null?(n=jr(),n!==null?(o=Vn(),o=o!==null?o:"",o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function Vn(){var a,n,o;return o=s,t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a!==null?(n=Br(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function Bn(){var a,n,o,c;if(c=s,a=on(),a!==null){for(n=[],o=an();o!==null;)n.push(o),o=an();n!==null?a=[a,n]:(a=null,s=c)}else a=null,s=c;return a}function an(){var a;return a=C(),a===null&&(a=b(),a===null&&(a=F())),a}function on(){var a;return a=b(),a===null&&(a=F(),a===null&&(t.charCodeAt(s)===59?(a=";",s++):(a=null,h('";"')),a===null&&(t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===64?(a="@",s++):(a=null,h('"@"')),a===null&&(t.charCodeAt(s)===38?(a="&",s++):(a=null,h('"&"')),a===null&&(t.charCodeAt(s)===61?(a="=",s++):(a=null,h('"="')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')),a===null&&(t.charCodeAt(s)===44?(a=",",s++):(a=null,h('","')))))))))))),a}function Br(){var a,n,o,c,_,g;if(_=s,a=jn(),a!==null){for(n=[],g=s,t.charCodeAt(s)===47?(o="/",s++):(o=null,h('"/"')),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,t.charCodeAt(s)===47?(o="/",s++):(o=null,h('"/"')),o!==null?(c=jn(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function jn(){var a,n,o,c,_,g;for(_=s,a=[],n=Ms();n!==null;)a.push(n),n=Ms();if(a!==null){for(n=[],g=s,t.charCodeAt(s)===59?(o=";",s++):(o=null,h('";"')),o!==null?(c=un(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,t.charCodeAt(s)===59?(o=";",s++):(o=null,h('";"')),o!==null?(c=un(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function un(){var a,n;for(a=[],n=Ms();n!==null;)a.push(n),n=Ms();return a}function Ms(){var a;return a=b(),a===null&&(a=F(),a===null&&(t.charCodeAt(s)===58?(a=":",s++):(a=null,h('":"')),a===null&&(t.charCodeAt(s)===64?(a="@",s++):(a=null,h('"@"')),a===null&&(t.charCodeAt(s)===38?(a="&",s++):(a=null,h('"&"')),a===null&&(t.charCodeAt(s)===61?(a="=",s++):(a=null,h('"="')),a===null&&(t.charCodeAt(s)===43?(a="+",s++):(a=null,h('"+"')),a===null&&(t.charCodeAt(s)===36?(a="$",s++):(a=null,h('"$"')),a===null&&(t.charCodeAt(s)===44?(a=",",s++):(a=null,h('","')))))))))),a}function cn(){var a,n,o,c,_;if(c=s,_=s,a=v(),a!==null){for(n=[],o=v(),o===null&&(o=p(),o===null&&(t.charCodeAt(s)===43?(o="+",s++):(o=null,h('"+"')),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."'))))));o!==null;)n.push(o),o=v(),o===null&&(o=p(),o===null&&(t.charCodeAt(s)===43?(o="+",s++):(o=null,h('"+"')),o===null&&(t.charCodeAt(s)===45?(o="-",s++):(o=null,h('"-"')),o===null&&(t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."'))))));n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a!==null&&(a=function(g){H.scheme=t.substring(s,g)}(c)),a===null&&(s=c),a}function jr(){var a;return a=qr(),a===null&&(a=Wr()),a}function qr(){var a,n,o,c;return o=s,c=s,a=ts(),a!==null?(t.charCodeAt(s)===64?(n="@",s++):(n=null,h('"@"')),n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a=a!==null?a:"",a!==null?(n=Un(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a=a!==null?a:"",a}function Wr(){var a,n;if(n=b(),n===null&&(n=F(),n===null&&(t.charCodeAt(s)===36?(n="$",s++):(n=null,h('"$"')),n===null&&(t.charCodeAt(s)===44?(n=",",s++):(n=null,h('","')),n===null&&(t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n===null&&(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n===null&&(t.charCodeAt(s)===64?(n="@",s++):(n=null,h('"@"')),n===null&&(t.charCodeAt(s)===38?(n="&",s++):(n=null,h('"&"')),n===null&&(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"'))))))))))),n!==null)for(a=[];n!==null;)a.push(n),n=b(),n===null&&(n=F(),n===null&&(t.charCodeAt(s)===36?(n="$",s++):(n=null,h('"$"')),n===null&&(t.charCodeAt(s)===44?(n=",",s++):(n=null,h('","')),n===null&&(t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n===null&&(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n===null&&(t.charCodeAt(s)===64?(n="@",s++):(n=null,h('"@"')),n===null&&(t.charCodeAt(s)===38?(n="&",s++):(n=null,h('"&"')),n===null&&(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n===null&&(t.charCodeAt(s)===43?(n="+",s++):(n=null,h('"+"')))))))))));else a=null;return a}function Kr(){var a,n;for(a=[],n=an();n!==null;)a.push(n),n=an();return a}function Pi(){var a,n,o,c,_,g,m,E;if(m=s,E=s,t.substr(s,3).toLowerCase()==="sip"?(a=t.substr(s,3),s+=3):(a=null,h('"SIP"')),a!==null)if(t.charCodeAt(s)===47?(n="/",s++):(n=null,h('"/"')),n!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;if(o!==null)if(t.charCodeAt(s)===46?(c=".",s++):(c=null,h('"."')),c!==null){if(g=p(),g!==null)for(_=[];g!==null;)_.push(g),g=p();else _=null;_!==null?a=[a,n,o,c,_]:(a=null,s=E)}else a=null,s=E;else a=null,s=E}else a=null,s=E;else a=null,s=E;return a!==null&&(a=function(k){H.sip_version=t.substring(s,k)}(m)),a===null&&(s=m),a}function xi(){var a;return t.substr(s,6)==="INVITE"?(a="INVITE",s+=6):(a=null,h('"INVITE"')),a}function Yr(){var a;return t.substr(s,3)==="ACK"?(a="ACK",s+=3):(a=null,h('"ACK"')),a}function zr(){var a;return t.substr(s,7)==="OPTIONS"?(a="OPTIONS",s+=7):(a=null,h('"OPTIONS"')),a}function Xr(){var a;return t.substr(s,3)==="BYE"?(a="BYE",s+=3):(a=null,h('"BYE"')),a}function Jr(){var a;return t.substr(s,6)==="CANCEL"?(a="CANCEL",s+=6):(a=null,h('"CANCEL"')),a}function Qr(){var a;return t.substr(s,8)==="REGISTER"?(a="REGISTER",s+=8):(a=null,h('"REGISTER"')),a}function Zr(){var a;return t.substr(s,9)==="SUBSCRIBE"?(a="SUBSCRIBE",s+=9):(a=null,h('"SUBSCRIBE"')),a}function el(){var a;return t.substr(s,6)==="NOTIFY"?(a="NOTIFY",s+=6):(a=null,h('"NOTIFY"')),a}function tl(){var a;return t.substr(s,5)==="REFER"?(a="REFER",s+=5):(a=null,h('"REFER"')),a}function qn(){var a,n;return n=s,a=xi(),a===null&&(a=Yr(),a===null&&(a=zr(),a===null&&(a=Xr(),a===null&&(a=Jr(),a===null&&(a=Qr(),a===null&&(a=Zr(),a===null&&(a=el(),a===null&&(a=tl(),a===null&&(a=L()))))))))),a!==null&&(a=function(o){return H.method=t.substring(s,o),H.method}(n)),a===null&&(s=n),a}function Wn(){var a,n,o,c,_,g;return g=s,a=Pi(),a!==null?(n=R(),n!==null?(o=sl(),o!==null?(c=R(),c!==null?(_=il(),_!==null?a=[a,n,o,c,_]:(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g),a}function sl(){var a,n;return n=s,a=nl(),a!==null&&(a=function(o,c){H.status_code=parseInt(c.join(""))}(n,a)),a===null&&(s=n),a}function nl(){var a,n,o,c;return c=s,a=p(),a!==null?(n=p(),n!==null?(o=p(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function il(){var a,n,o;for(o=s,a=[],n=C(),n===null&&(n=b(),n===null&&(n=F(),n===null&&(n=U(),n===null&&(n=B(),n===null&&(n=R(),n===null&&(n=O()))))));n!==null;)a.push(n),n=C(),n===null&&(n=b(),n===null&&(n=F(),n===null&&(n=U(),n===null&&(n=B(),n===null&&(n=R(),n===null&&(n=O()))))));return a!==null&&(a=function(c){H.reason_phrase=t.substring(s,c)}(o)),a===null&&(s=o),a}function $a(){var a,n,o,c,_,g;if(_=s,a=zn(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=zn(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=zn(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function yc(){var a,n,o,c,_,g;return c=s,_=s,a=Pe(),a!==null?(g=s,t.charCodeAt(s)===64?(n="@",s++):(n=null,h('"@"')),n!==null?(o=Pe(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m){H=t.substring(s,m)}(c)),a===null&&(s=c),a}function Sc(){var a,n,o,c,_,g,m;if(_=s,a=ee(),a===null)if(g=s,a=ki(),a!==null){for(n=[],m=s,o=be(),o!==null?(c=ki(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=be(),o!==null?(c=ki(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k,W;for(W=H.multi_header.length,k=0;k<W;k++)if(H.multi_header[k].parsed===null){H=null;break}H!==null?H=H.multi_header:H=-1}()),a===null&&(s=_),a}function ki(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=ss()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=hn(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=hn(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k;H.multi_header||(H.multi_header=[]);try{k=new Us(H.uri,H.display_name,H.params),delete H.uri,delete H.display_name,delete H.params}catch{k=null}H.multi_header.push({possition:s,offset:E,parsed:k})}(_)),a===null&&(s=_),a}function ss(){var a,n,o,c,_;return _=s,a=ns(),a=a!==null?a:"",a!==null?(n=ke(),n!==null?(o=Oe(),o!==null?(c=Ce(),c!==null?a=[a,n,o,c]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a}function ns(){var a,n,o,c,_,g,m;if(_=s,g=s,a=L(),a!==null){for(n=[],m=s,o=q(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=q(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a===null&&(a=De()),a!==null&&(a=function(E,k){typeof k=="string"?H.display_name=k:H.display_name=k[1].reduce(function(W,pe){return W+pe[0]+pe[1]},k[0])}(_,a)),a===null&&(s=_),a}function hn(){var a;return a=Mi(),a===null&&(a=rl(),a===null&&(a=rt())),a}function Mi(){var a,n,o,c,_;return c=s,_=s,t.substr(s,1).toLowerCase()==="q"?(a=t.substr(s,1),s++):(a=null,h('"q"')),a!==null?(n=K(),n!==null?(o=As(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.params||(H.params={}),H.params.q=m}(c,a[2])),a===null&&(s=c),a}function rl(){var a,n,o,c,_;return c=s,_=s,t.substr(s,7).toLowerCase()==="expires"?(a=t.substr(s,7),s+=7):(a=null,h('"expires"')),a!==null?(n=K(),n!==null?(o=Cs(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.params||(H.params={}),H.params.expires=m}(c,a[2])),a===null&&(s=c),a}function Cs(){var a,n,o;if(o=s,n=p(),n!==null)for(a=[];n!==null;)a.push(n),n=p();else a=null;return a!==null&&(a=function(c,_){return parseInt(_.join(""))}(o,a)),a===null&&(s=o),a}function As(){var a,n,o,c,_,g,m,E;return g=s,m=s,t.charCodeAt(s)===48?(a="0",s++):(a=null,h('"0"')),a!==null?(E=s,t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(_=p(),_=_!==null?_:"",_!==null?n=[n,o,c,_]:(n=null,s=E)):(n=null,s=E)):(n=null,s=E)):(n=null,s=E),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=m)):(a=null,s=m),a!==null&&(a=function(k){return parseFloat(t.substring(s,k))}(g)),a===null&&(s=g),a}function rt(){var a,n,o,c,_,g;return c=s,_=s,a=L(),a!==null?(g=s,n=K(),n!==null?(o=lt(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m,E,k){H.params||(H.params={}),typeof k>"u"?k=void 0:k=k[1],H.params[E.toLowerCase()]=k}(c,a[0],a[1])),a===null&&(s=c),a}function lt(){var a;return a=L(),a===null&&(a=Es(),a===null&&(a=we())),a}function Ha(){var a,n,o,c,_,g;if(_=s,a=Ga(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Ui(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=M(),o!==null?(c=Ui(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Ga(){var a;return t.substr(s,6).toLowerCase()==="render"?(a=t.substr(s,6),s+=6):(a=null,h('"render"')),a===null&&(t.substr(s,7).toLowerCase()==="session"?(a=t.substr(s,7),s+=7):(a=null,h('"session"')),a===null&&(t.substr(s,4).toLowerCase()==="icon"?(a=t.substr(s,4),s+=4):(a=null,h('"icon"')),a===null&&(t.substr(s,5).toLowerCase()==="alert"?(a=t.substr(s,5),s+=5):(a=null,h('"alert"')),a===null&&(a=L())))),a}function Ui(){var a;return a=Li(),a===null&&(a=rt()),a}function Li(){var a,n,o,c;return c=s,t.substr(s,8).toLowerCase()==="handling"?(a=t.substr(s,8),s+=8):(a=null,h('"handling"')),a!==null?(n=K(),n!==null?(t.substr(s,8).toLowerCase()==="optional"?(o=t.substr(s,8),s+=8):(o=null,h('"optional"')),o===null&&(t.substr(s,8).toLowerCase()==="required"?(o=t.substr(s,8),s+=8):(o=null,h('"required"')),o===null&&(o=L())),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function Va(){var a,n,o,c,_,g;if(_=s,a=L(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Ec(){var a,n,o;if(o=s,n=p(),n!==null)for(a=[];n!==null;)a.push(n),n=p();else a=null;return a!==null&&(a=function(c,_){H=parseInt(_.join(""))}(o,a)),a===null&&(s=o),a}function Cc(){var a,n;return n=s,a=Ba(),a!==null&&(a=function(o){H=t.substring(s,o)}(n)),a===null&&(s=n),a}function Ba(){var a,n,o,c,_,g,m,E;if(m=s,a=ll(),a!==null)if(n=j(),n!==null)if(o=ul(),o!==null){for(c=[],E=s,_=M(),_!==null?(g=Fi(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=M(),_!==null?(g=Fi(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);c!==null?a=[a,n,o,c]:(a=null,s=m)}else a=null,s=m;else a=null,s=m;else a=null,s=m;return a}function ll(){var a;return a=al(),a===null&&(a=ol()),a}function al(){var a;return t.substr(s,4).toLowerCase()==="text"?(a=t.substr(s,4),s+=4):(a=null,h('"text"')),a===null&&(t.substr(s,5).toLowerCase()==="image"?(a=t.substr(s,5),s+=5):(a=null,h('"image"')),a===null&&(t.substr(s,5).toLowerCase()==="audio"?(a=t.substr(s,5),s+=5):(a=null,h('"audio"')),a===null&&(t.substr(s,5).toLowerCase()==="video"?(a=t.substr(s,5),s+=5):(a=null,h('"video"')),a===null&&(t.substr(s,11).toLowerCase()==="application"?(a=t.substr(s,11),s+=11):(a=null,h('"application"')),a===null&&(a=Kn()))))),a}function ol(){var a;return t.substr(s,7).toLowerCase()==="message"?(a=t.substr(s,7),s+=7):(a=null,h('"message"')),a===null&&(t.substr(s,9).toLowerCase()==="multipart"?(a=t.substr(s,9),s+=9):(a=null,h('"multipart"')),a===null&&(a=Kn())),a}function Kn(){var a;return a=L(),a===null&&(a=Yn()),a}function Yn(){var a,n,o;return o=s,t.substr(s,2).toLowerCase()==="x-"?(a=t.substr(s,2),s+=2):(a=null,h('"x-"')),a!==null?(n=L(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function ul(){var a;return a=Kn(),a===null&&(a=L()),a}function Fi(){var a,n,o,c;return c=s,a=L(),a!==null?(n=K(),n!==null?(o=$i(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function $i(){var a;return a=L(),a===null&&(a=we()),a}function ja(){var a,n,o,c;return c=s,a=qa(),a!==null?(n=q(),n!==null?(o=qn(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function qa(){var a,n,o;if(o=s,n=p(),n!==null)for(a=[];n!==null;)a.push(n),n=p();else a=null;return a!==null&&(a=function(c,_){H.value=parseInt(_.join(""))}(o,a)),a===null&&(s=o),a}function Wa(){var a,n;return n=s,a=Cs(),a!==null&&(a=function(o,c){H=c}(n,a)),a===null&&(s=n),a}function Ac(){var a,n,o,c,_,g,m;if(_=s,g=s,a=zn(),a!==null){for(n=[],m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E,k){H.event=k.join("").toLowerCase()}(_,a[0])),a===null&&(s=_),a}function zn(){var a,n,o,c,_,g;if(_=s,a=V(),a!==null){for(n=[],g=s,t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."')),o!==null?(c=V(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,t.charCodeAt(s)===46?(o=".",s++):(o=null,h('"."')),o!==null?(c=V(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Xn(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=ss()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=cl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=cl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k=H.tag;try{H=new Us(H.uri,H.display_name,H.params),k&&H.setParam("tag",k)}catch{H=-1}}()),a===null&&(s=_),a}function cl(){var a;return a=Jn(),a===null&&(a=rt()),a}function Jn(){var a,n,o,c,_;return c=s,_=s,t.substr(s,3).toLowerCase()==="tag"?(a=t.substr(s,3),s+=3):(a=null,h('"tag"')),a!==null?(n=K(),n!==null?(o=L(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.tag=m}(c,a[2])),a===null&&(s=c),a}function hl(){var a,n,o;if(o=s,n=p(),n!==null)for(a=[];n!==null;)a.push(n),n=p();else a=null;return a!==null&&(a=function(c,_){H=parseInt(_.join(""))}(o,a)),a===null&&(s=o),a}function bc(){var a,n;return n=s,a=Cs(),a!==null&&(a=function(o,c){H=c}(n,a)),a===null&&(s=n),a}function Rc(){var a,n,o,c,_,g,m,E,k,W;for(E=s,k=s,a=[],n=ns();n!==null;)a.push(n),n=ns();if(a!==null)if(n=ke(),n!==null)if(o=Oe(),o!==null)if(c=Ce(),c!==null){for(_=[],W=s,g=M(),g!==null?(m=rt(),m!==null?g=[g,m]:(g=null,s=W)):(g=null,s=W);g!==null;)_.push(g),W=s,g=M(),g!==null?(m=rt(),m!==null?g=[g,m]:(g=null,s=W)):(g=null,s=W);_!==null?a=[a,n,o,c,_]:(a=null,s=k)}else a=null,s=k;else a=null,s=k;else a=null,s=k;else a=null,s=k;return a!==null&&(a=function(pe){try{H=new Us(H.uri,H.display_name,H.params)}catch{H=-1}}()),a===null&&(s=E),a}function wc(){var a;return a=fl(),a}function fl(){var a,n,o,c,_,g,m,E;if(m=s,t.substr(s,6).toLowerCase()==="digest"?(a=t.substr(s,6),s+=6):(a=null,h('"Digest"')),a!==null)if(n=q(),n!==null)if(o=bs(),o!==null){for(c=[],E=s,_=be(),_!==null?(g=bs(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=be(),_!==null?(g=bs(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);c!==null?a=[a,n,o,c]:(a=null,s=m)}else a=null,s=m;else a=null,s=m;else a=null,s=m;return a===null&&(a=Hi()),a}function Hi(){var a,n,o,c,_,g,m,E;if(m=s,a=L(),a!==null)if(n=q(),n!==null)if(o=fn(),o!==null){for(c=[],E=s,_=be(),_!==null?(g=fn(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=be(),_!==null?(g=fn(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);c!==null?a=[a,n,o,c]:(a=null,s=m)}else a=null,s=m;else a=null,s=m;else a=null,s=m;return a}function fn(){var a,n,o,c;return c=s,a=L(),a!==null?(n=K(),n!==null?(o=L(),o===null&&(o=we()),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function bs(){var a;return a=Qn(),a===null&&(a=_l(),a===null&&(a=ei(),a===null&&(a=pl(),a===null&&(a=ml(),a===null&&(a=vl(),a===null&&(a=Tl(),a===null&&(a=fn()))))))),a}function Qn(){var a,n,o,c;return c=s,t.substr(s,5).toLowerCase()==="realm"?(a=t.substr(s,5),s+=5):(a=null,h('"realm"')),a!==null?(n=K(),n!==null?(o=dl(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function dl(){var a,n;return n=s,a=De(),a!==null&&(a=function(o,c){H.realm=c}(n,a)),a===null&&(s=n),a}function _l(){var a,n,o,c,_,g,m,E,k;if(E=s,t.substr(s,6).toLowerCase()==="domain"?(a=t.substr(s,6),s+=6):(a=null,h('"domain"')),a!==null)if(n=K(),n!==null)if(o=Ee(),o!==null)if(c=Zn(),c!==null){if(_=[],k=s,m=R(),m!==null)for(g=[];m!==null;)g.push(m),m=R();else g=null;for(g!==null?(m=Zn(),m!==null?g=[g,m]:(g=null,s=k)):(g=null,s=k);g!==null;){if(_.push(g),k=s,m=R(),m!==null)for(g=[];m!==null;)g.push(m),m=R();else g=null;g!==null?(m=Zn(),m!==null?g=[g,m]:(g=null,s=k)):(g=null,s=k)}_!==null?(g=Me(),g!==null?a=[a,n,o,c,_,g]:(a=null,s=E)):(a=null,s=E)}else a=null,s=E;else a=null,s=E;else a=null,s=E;else a=null,s=E;return a}function Zn(){var a;return a=Di(),a===null&&(a=Vn()),a}function ei(){var a,n,o,c;return c=s,t.substr(s,5).toLowerCase()==="nonce"?(a=t.substr(s,5),s+=5):(a=null,h('"nonce"')),a!==null?(n=K(),n!==null?(o=gl(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function gl(){var a,n;return n=s,a=De(),a!==null&&(a=function(o,c){H.nonce=c}(n,a)),a===null&&(s=n),a}function pl(){var a,n,o,c,_;return c=s,_=s,t.substr(s,6).toLowerCase()==="opaque"?(a=t.substr(s,6),s+=6):(a=null,h('"opaque"')),a!==null?(n=K(),n!==null?(o=De(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.opaque=m}(c,a[2])),a===null&&(s=c),a}function ml(){var a,n,o,c,_;return c=s,t.substr(s,5).toLowerCase()==="stale"?(a=t.substr(s,5),s+=5):(a=null,h('"stale"')),a!==null?(n=K(),n!==null?(_=s,t.substr(s,4).toLowerCase()==="true"?(o=t.substr(s,4),s+=4):(o=null,h('"true"')),o!==null&&(o=function(g){H.stale=!0}()),o===null&&(s=_),o===null&&(_=s,t.substr(s,5).toLowerCase()==="false"?(o=t.substr(s,5),s+=5):(o=null,h('"false"')),o!==null&&(o=function(g){H.stale=!1}()),o===null&&(s=_)),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function vl(){var a,n,o,c,_;return c=s,_=s,t.substr(s,9).toLowerCase()==="algorithm"?(a=t.substr(s,9),s+=9):(a=null,h('"algorithm"')),a!==null?(n=K(),n!==null?(t.substr(s,3).toLowerCase()==="md5"?(o=t.substr(s,3),s+=3):(o=null,h('"MD5"')),o===null&&(t.substr(s,8).toLowerCase()==="md5-sess"?(o=t.substr(s,8),s+=8):(o=null,h('"MD5-sess"')),o===null&&(o=L())),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.algorithm=m.toUpperCase()}(c,a[2])),a===null&&(s=c),a}function Tl(){var a,n,o,c,_,g,m,E,k,W;if(E=s,t.substr(s,3).toLowerCase()==="qop"?(a=t.substr(s,3),s+=3):(a=null,h('"qop"')),a!==null)if(n=K(),n!==null)if(o=Ee(),o!==null){if(k=s,c=ti(),c!==null){for(_=[],W=s,t.charCodeAt(s)===44?(g=",",s++):(g=null,h('","')),g!==null?(m=ti(),m!==null?g=[g,m]:(g=null,s=W)):(g=null,s=W);g!==null;)_.push(g),W=s,t.charCodeAt(s)===44?(g=",",s++):(g=null,h('","')),g!==null?(m=ti(),m!==null?g=[g,m]:(g=null,s=W)):(g=null,s=W);_!==null?c=[c,_]:(c=null,s=k)}else c=null,s=k;c!==null?(_=Me(),_!==null?a=[a,n,o,c,_]:(a=null,s=E)):(a=null,s=E)}else a=null,s=E;else a=null,s=E;else a=null,s=E;return a}function ti(){var a,n;return n=s,t.substr(s,8).toLowerCase()==="auth-int"?(a=t.substr(s,8),s+=8):(a=null,h('"auth-int"')),a===null&&(t.substr(s,4).toLowerCase()==="auth"?(a=t.substr(s,4),s+=4):(a=null,h('"auth"')),a===null&&(a=L())),a!==null&&(a=function(o,c){H.qop||(H.qop=[]),H.qop.push(c.toLowerCase())}(n,a)),a===null&&(s=n),a}function Gi(){var a,n,o,c,_,g;if(_=s,a=L(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Ic(){var a,n,o,c,_,g,m;if(_=s,g=s,a=Vi(),a!==null){for(n=[],m=s,o=be(),o!==null?(c=Vi(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=be(),o!==null?(c=Vi(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k,W;for(W=H.multi_header.length,k=0;k<W;k++)if(H.multi_header[k].parsed===null){H=null;break}H!==null?H=H.multi_header:H=-1}()),a===null&&(s=_),a}function Vi(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ss(),a!==null){for(n=[],m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k;H.multi_header||(H.multi_header=[]);try{k=new Us(H.uri,H.display_name,H.params),delete H.uri,delete H.display_name,delete H.params}catch{k=null}H.multi_header.push({possition:s,offset:E,parsed:k})}(_)),a===null&&(s=_),a}function Bi(){var a,n,o,c,_,g,m;if(_=s,g=s,t.substr(s,3).toLowerCase()==="sip"?(a=t.substr(s,3),s+=3):(a=null,h('"SIP"')),a===null&&(a=L()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=yl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=yl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E,k){if(H.protocol=k.toLowerCase(),H.params||(H.params={}),H.params.text&&H.params.text[0]==='"'){var W=H.params.text;H.text=W.substring(1,W.length-1),delete H.params.text}}(_,a[0])),a===null&&(s=_),a}function yl(){var a;return a=ji(),a===null&&(a=rt()),a}function ji(){var a,n,o,c,_,g;if(_=s,g=s,t.substr(s,5).toLowerCase()==="cause"?(a=t.substr(s,5),s+=5):(a=null,h('"cause"')),a!==null)if(n=K(),n!==null){if(c=p(),c!==null)for(o=[];c!==null;)o.push(c),c=p();else o=null;o!==null?a=[a,n,o]:(a=null,s=g)}else a=null,s=g;else a=null,s=g;return a!==null&&(a=function(m,E){H.cause=parseInt(E.join(""))}(_,a[2])),a===null&&(s=_),a}function Ka(){var a,n,o,c,_,g;if(_=s,a=L(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Oc(){var a,n,o,c,_,g;if(_=s,a=qi(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=qi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=qi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function qi(){var a,n,o,c,_,g;if(_=s,a=ss(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Wi(){var a,n,o,c,_,g;if(_=s,a=Ya(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Ki(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=M(),o!==null?(c=Ki(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Ya(){var a,n;return n=s,t.substr(s,6).toLowerCase()==="active"?(a=t.substr(s,6),s+=6):(a=null,h('"active"')),a===null&&(t.substr(s,7).toLowerCase()==="pending"?(a=t.substr(s,7),s+=7):(a=null,h('"pending"')),a===null&&(t.substr(s,10).toLowerCase()==="terminated"?(a=t.substr(s,10),s+=10):(a=null,h('"terminated"')),a===null&&(a=L()))),a!==null&&(a=function(o){H.state=t.substring(s,o)}(n)),a===null&&(s=n),a}function Ki(){var a,n,o,c,_;return c=s,_=s,t.substr(s,6).toLowerCase()==="reason"?(a=t.substr(s,6),s+=6):(a=null,h('"reason"')),a!==null?(n=K(),n!==null?(o=Yi(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){typeof m<"u"&&(H.reason=m)}(c,a[2])),a===null&&(s=c),a===null&&(c=s,_=s,t.substr(s,7).toLowerCase()==="expires"?(a=t.substr(s,7),s+=7):(a=null,h('"expires"')),a!==null?(n=K(),n!==null?(o=Cs(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){typeof m<"u"&&(H.expires=m)}(c,a[2])),a===null&&(s=c),a===null&&(c=s,_=s,t.substr(s,11).toLowerCase()==="retry_after"?(a=t.substr(s,11),s+=11):(a=null,h('"retry_after"')),a!==null?(n=K(),n!==null?(o=Cs(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){typeof m<"u"&&(H.retry_after=m)}(c,a[2])),a===null&&(s=c),a===null&&(a=rt()))),a}function Yi(){var a;return t.substr(s,11).toLowerCase()==="deactivated"?(a=t.substr(s,11),s+=11):(a=null,h('"deactivated"')),a===null&&(t.substr(s,9).toLowerCase()==="probation"?(a=t.substr(s,9),s+=9):(a=null,h('"probation"')),a===null&&(t.substr(s,8).toLowerCase()==="rejected"?(a=t.substr(s,8),s+=8):(a=null,h('"rejected"')),a===null&&(t.substr(s,7).toLowerCase()==="timeout"?(a=t.substr(s,7),s+=7):(a=null,h('"timeout"')),a===null&&(t.substr(s,6).toLowerCase()==="giveup"?(a=t.substr(s,6),s+=6):(a=null,h('"giveup"')),a===null&&(t.substr(s,10).toLowerCase()==="noresource"?(a=t.substr(s,10),s+=10):(a=null,h('"noresource"')),a===null&&(t.substr(s,9).toLowerCase()==="invariant"?(a=t.substr(s,9),s+=9):(a=null,h('"invariant"')),a===null&&(a=L()))))))),a}function za(){var a;return a=I(),a=a!==null?a:"",a}function Dc(){var a,n,o,c,_,g;if(_=s,a=L(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=L(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a=a!==null?a:"",a}function Nc(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=ss()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=Sl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=Sl(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){var k=H.tag;try{H=new Us(H.uri,H.display_name,H.params),k&&H.setParam("tag",k)}catch{H=-1}}()),a===null&&(s=_),a}function Sl(){var a;return a=Jn(),a===null&&(a=rt()),a}function El(){var a,n,o,c,_,g;if(_=s,a=zi(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=zi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=be(),o!==null?(c=zi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function zi(){var a,n,o,c,_,g,m,E;if(m=s,a=Il(),a!==null)if(n=q(),n!==null)if(o=Nl(),o!==null){for(c=[],E=s,_=M(),_!==null?(g=dn(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=M(),_!==null?(g=dn(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);c!==null?a=[a,n,o,c]:(a=null,s=m)}else a=null,s=m;else a=null,s=m;else a=null,s=m;return a}function dn(){var a;return a=Xi(),a===null&&(a=Cl(),a===null&&(a=Al(),a===null&&(a=bl(),a===null&&(a=Rl(),a===null&&(a=rt()))))),a}function Xi(){var a,n,o,c,_;return c=s,_=s,t.substr(s,3).toLowerCase()==="ttl"?(a=t.substr(s,3),s+=3):(a=null,h('"ttl"')),a!==null?(n=K(),n!==null?(o=Ji(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.ttl=m}(c,a[2])),a===null&&(s=c),a}function Cl(){var a,n,o,c,_;return c=s,_=s,t.substr(s,5).toLowerCase()==="maddr"?(a=t.substr(s,5),s+=5):(a=null,h('"maddr"')),a!==null?(n=K(),n!==null?(o=Es(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.maddr=m}(c,a[2])),a===null&&(s=c),a}function Al(){var a,n,o,c,_;return c=s,_=s,t.substr(s,8).toLowerCase()==="received"?(a=t.substr(s,8),s+=8):(a=null,h('"received"')),a!==null?(n=K(),n!==null?(o=Et(),o===null&&(o=Fn()),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.received=m}(c,a[2])),a===null&&(s=c),a}function bl(){var a,n,o,c,_;return c=s,_=s,t.substr(s,6).toLowerCase()==="branch"?(a=t.substr(s,6),s+=6):(a=null,h('"branch"')),a!==null?(n=K(),n!==null?(o=L(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.branch=m}(c,a[2])),a===null&&(s=c),a}function Rl(){var a,n,o,c,_;return c=s,t.substr(s,5).toLowerCase()==="rport"?(a=t.substr(s,5),s+=5):(a=null,h('"rport"')),a!==null?(_=s,n=K(),n!==null?(o=wl(),o!==null?n=[n,o]:(n=null,s=_)):(n=null,s=_),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a}function wl(){var a,n,o,c,_,g,m;return g=s,m=s,a=p(),a=a!==null?a:"",a!==null?(n=p(),n=n!==null?n:"",n!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(_=p(),_=_!==null?_:"",_!==null?a=[a,n,o,c,_]:(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m),a!==null&&(a=function(E,k){H.rport=parseInt(k.join(""))}(g,a)),a===null&&(s=g),a}function Il(){var a,n,o,c,_,g;return g=s,a=Ol(),a!==null?(n=j(),n!==null?(o=L(),o!==null?(c=j(),c!==null?(_=Dl(),_!==null?a=[a,n,o,c,_]:(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g)):(a=null,s=g),a}function Ol(){var a,n;return n=s,t.substr(s,3).toLowerCase()==="sip"?(a=t.substr(s,3),s+=3):(a=null,h('"SIP"')),a===null&&(a=L()),a!==null&&(a=function(o,c){H.protocol=c}(n,a)),a===null&&(s=n),a}function Dl(){var a,n;return n=s,t.substr(s,3).toLowerCase()==="udp"?(a=t.substr(s,3),s+=3):(a=null,h('"UDP"')),a===null&&(t.substr(s,3).toLowerCase()==="tcp"?(a=t.substr(s,3),s+=3):(a=null,h('"TCP"')),a===null&&(t.substr(s,3).toLowerCase()==="tls"?(a=t.substr(s,3),s+=3):(a=null,h('"TLS"')),a===null&&(t.substr(s,4).toLowerCase()==="sctp"?(a=t.substr(s,4),s+=4):(a=null,h('"SCTP"')),a===null&&(a=L())))),a!==null&&(a=function(o,c){H.transport=c}(n,a)),a===null&&(s=n),a}function Nl(){var a,n,o,c,_;return c=s,a=Pl(),a!==null?(_=s,n=Y(),n!==null?(o=xl(),o!==null?n=[n,o]:(n=null,s=_)):(n=null,s=_),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=c)):(a=null,s=c),a}function Pl(){var a,n;return n=s,a=Et(),a===null&&(a=wi(),a===null&&(a=ks())),a!==null&&(a=function(o){H.host=t.substring(s,o)}(n)),a===null&&(s=n),a}function xl(){var a,n,o,c,_,g,m;return g=s,m=s,a=p(),a=a!==null?a:"",a!==null?(n=p(),n=n!==null?n:"",n!==null?(o=p(),o=o!==null?o:"",o!==null?(c=p(),c=c!==null?c:"",c!==null?(_=p(),_=_!==null?_:"",_!==null?a=[a,n,o,c,_]:(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m)):(a=null,s=m),a!==null&&(a=function(E,k){H.port=parseInt(k.join(""))}(g,a)),a===null&&(s=g),a}function Ji(){var a,n,o,c,_;return c=s,_=s,a=p(),a!==null?(n=p(),n=n!==null?n:"",n!==null?(o=p(),o=o!==null?o:"",o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){return parseInt(m.join(""))}(c,a)),a===null&&(s=c),a}function kl(){var a;return a=fl(),a}function Pc(){var a,n,o,c,_,g;if(_=s,a=Xa(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Qi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=M(),o!==null?(c=Qi(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function Xa(){var a,n;return n=s,a=Cs(),a!==null&&(a=function(o,c){H.expires=c}(n,a)),a===null&&(s=n),a}function Qi(){var a;return a=Zi(),a===null&&(a=rt()),a}function Zi(){var a,n,o,c,_;return c=s,_=s,t.substr(s,9).toLowerCase()==="refresher"?(a=t.substr(s,9),s+=9):(a=null,h('"refresher"')),a!==null?(n=K(),n!==null?(t.substr(s,3).toLowerCase()==="uac"?(o=t.substr(s,3),s+=3):(o=null,h('"uac"')),o===null&&(t.substr(s,3).toLowerCase()==="uas"?(o=t.substr(s,3),s+=3):(o=null,h('"uas"'))),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.refresher=m.toLowerCase()}(c,a[2])),a===null&&(s=c),a}function Ja(){var a,n,o,c;return c=s,a=L(),a!==null?(n=P(),n!==null?(o=Qa(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function Qa(){var a,n;for(a=[],n=x(),n===null&&(n=B(),n===null&&(n=q()));n!==null;)a.push(n),n=x(),n===null&&(n=B(),n===null&&(n=q()));return a}function Za(){var a,n;for(a=[],n=S();n!==null;)a.push(n),n=S();return a}function xc(){var a,n,o;return o=s,t.substr(s,5)==="uuid:"?(a="uuid:",s+=5):(a=null,h('"uuid:"')),a!==null?(n=eo(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function eo(){var a,n,o,c,_,g,m,E,k,W,pe;return W=s,pe=s,a=rs(),a!==null?(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n!==null?(o=is(),o!==null?(t.charCodeAt(s)===45?(c="-",s++):(c=null,h('"-"')),c!==null?(_=is(),_!==null?(t.charCodeAt(s)===45?(g="-",s++):(g=null,h('"-"')),g!==null?(m=is(),m!==null?(t.charCodeAt(s)===45?(E="-",s++):(E=null,h('"-"')),E!==null?(k=Ml(),k!==null?a=[a,n,o,c,_,g,m,E,k]:(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe)):(a=null,s=pe),a!==null&&(a=function(He,Wt){H=t.substring(s+5,He)}(W,a[0])),a===null&&(s=W),a}function is(){var a,n,o,c,_;return _=s,a=T(),a!==null?(n=T(),n!==null?(o=T(),o!==null?(c=T(),c!==null?a=[a,n,o,c]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a}function rs(){var a,n,o;return o=s,a=is(),a!==null?(n=is(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function Ml(){var a,n,o,c;return c=s,a=is(),a!==null?(n=is(),n!==null?(o=is(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function to(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=ss()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);o!==null;)n.push(o),m=s,o=M(),o!==null?(c=rt(),c!==null?o=[o,c]:(o=null,s=m)):(o=null,s=m);n!==null?a=[a,n]:(a=null,s=g)}else a=null,s=g;return a!==null&&(a=function(E){try{H=new Us(H.uri,H.display_name,H.params)}catch{H=-1}}()),a===null&&(s=_),a}function kc(){var a,n,o,c,_,g;if(_=s,a=so(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=er(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);o!==null;)n.push(o),g=s,o=M(),o!==null?(c=er(),c!==null?o=[o,c]:(o=null,s=g)):(o=null,s=g);n!==null?a=[a,n]:(a=null,s=_)}else a=null,s=_;return a}function so(){var a,n,o,c,_,g;return c=s,_=s,a=Pe(),a!==null?(g=s,t.charCodeAt(s)===64?(n="@",s++):(n=null,h('"@"')),n!==null?(o=Pe(),o!==null?n=[n,o]:(n=null,s=g)):(n=null,s=g),n=n!==null?n:"",n!==null?a=[a,n]:(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(m){H.call_id=t.substring(s,m)}(c)),a===null&&(s=c),a}function er(){var a;return a=tr(),a===null&&(a=Ul(),a===null&&(a=Ll(),a===null&&(a=rt()))),a}function tr(){var a,n,o,c,_;return c=s,_=s,t.substr(s,6)==="to-tag"?(a="to-tag",s+=6):(a=null,h('"to-tag"')),a!==null?(n=K(),n!==null?(o=L(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.to_tag=m}(c,a[2])),a===null&&(s=c),a}function Ul(){var a,n,o,c,_;return c=s,_=s,t.substr(s,8)==="from-tag"?(a="from-tag",s+=8):(a=null,h('"from-tag"')),a!==null?(n=K(),n!==null?(o=L(),o!==null?a=[a,n,o]:(a=null,s=_)):(a=null,s=_)):(a=null,s=_),a!==null&&(a=function(g,m){H.from_tag=m}(c,a[2])),a===null&&(s=c),a}function Ll(){var a,n;return n=s,t.substr(s,10)==="early-only"?(a="early-only",s+=10):(a=null,h('"early-only"')),a!==null&&(a=function(o){H.early_only=!0}()),a===null&&(s=n),a}function no(a){a.sort();for(var n=null,o=[],c=0;c<a.length;c++)a[c]!==n&&(o.push(a[c]),n=a[c]);return o}function Mc(){for(var a=1,n=1,o=!1,c=0;c<Math.max(s,i);c++){var _=t.charAt(c);_===`
75
- `?(o||a++,n=1,o=!1):_==="\r"||_==="\u2028"||_==="\u2029"?(a++,n=1,o=!0):(n++,o=!1)}return{line:a,column:n}}var io=Xs(),Us=xf(),H={},G=l[r]();if(G===null||s!==t.length){var Fl=Math.max(s,i),$l=Fl<t.length?t.charAt(Fl):null,ro=Mc();return new this.SyntaxError(no(f),$l,Fl,ro.line,ro.column),-1}return H},toSource:function(){return this._source}};return e.SyntaxError=function(t,r,l,s,i){function f(h,d){var p,v;switch(h.length){case 0:p="end of input";break;case 1:p=h[0];break;default:p=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return v=d?u(d):"end of input","Expected "+p+" but "+v+" found."}this.name="SyntaxError",this.expected=t,this.found=r,this.message=f(t,r),this.offset=l,this.line=s,this.column=i},e.SyntaxError.prototype=Error.prototype,e}()),lh}var ah,d_;function Xs(){if(d_)return ah;d_=1;const u=Ue,e=Ht(),t=ys();return ah=class sp{static parse(l){if(l=t.parse(l,"SIP_URI"),l!==-1)return l}constructor(l,s,i,f,h={},d={}){if(!i)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=l||u.SIP,this._user=s,this._host=i,this._port=f;for(const p in h)Object.prototype.hasOwnProperty.call(h,p)&&this.setParam(p,h[p]);for(const p in d)Object.prototype.hasOwnProperty.call(d,p)&&this.setHeader(p,d[p])}get scheme(){return this._scheme}set scheme(l){this._scheme=l.toLowerCase()}get user(){return this._user}set user(l){this._user=l}get host(){return this._host}set host(l){this._host=l.toLowerCase()}get port(){return this._port}set port(l){this._port=l===0?l:parseInt(l,10)||null}setParam(l,s){l&&(this._parameters[l.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(l){if(l)return this._parameters[l.toLowerCase()]}hasParam(l){if(l)return this._parameters.hasOwnProperty(l.toLowerCase())&&!0||!1}deleteParam(l){if(l=l.toLowerCase(),this._parameters.hasOwnProperty(l)){const s=this._parameters[l];return delete this._parameters[l],s}}clearParams(){this._parameters={}}setHeader(l,s){this._headers[e.headerize(l)]=Array.isArray(s)?s:[s]}getHeader(l){if(l)return this._headers[e.headerize(l)]}hasHeader(l){if(l)return this._headers.hasOwnProperty(e.headerize(l))&&!0||!1}deleteHeader(l){if(l=e.headerize(l),this._headers.hasOwnProperty(l)){const s=this._headers[l];return delete this._headers[l],s}}clearHeaders(){this._headers={}}clone(){return new sp(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const l=[];let s=`${this._scheme}:`;this._user&&(s+=`${e.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const i in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,i)&&(s+=`;${i}`,this._parameters[i]!==null&&(s+=`=${this._parameters[i]}`));for(const i in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,i))for(const f of this._headers[i])l.push(`${i}=${f}`);return l.length>0&&(s+=`?${l.join("&")}`),s}toAor(l){let s=`${this._scheme}:`;return this._user&&(s+=`${e.escapeUser(this._user)}@`),s+=this._host,l&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},ah}var __;function Ht(){if(__)return pt;__=1;const u=Ue,e=Xs(),t=ys();pt.str_utf8_length=i=>unescape(encodeURIComponent(i)).length;const r=pt.isFunction=i=>i!==void 0?Object.prototype.toString.call(i)==="[object Function]":!1;pt.isString=i=>i!==void 0?Object.prototype.toString.call(i)==="[object String]":!1,pt.isDecimal=i=>!isNaN(i)&&parseFloat(i)===parseInt(i,10),pt.isEmpty=i=>i===null||i===""||i===void 0||Array.isArray(i)&&i.length===0||typeof i=="number"&&isNaN(i),pt.hasMethods=function(i,...f){for(const h of f)if(r(i[h]))return!1;return!0};const l=pt.createRandomToken=(i,f=32)=>{let h,d,p="";for(h=0;h<i;h++)d=Math.random()*f|0,p+=d.toString(f);return p};pt.newTag=()=>l(10),pt.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,f=>{const h=Math.random()*16|0;return(f==="x"?h:h&3|8).toString(16)}),pt.hostType=i=>{if(i){if(i=t.parse(i,"host"),i!==-1)return i.host_type}else return};const s=pt.escapeUser=i=>encodeURIComponent(decodeURIComponent(i)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return pt.normalizeTarget=(i,f)=>{if(i){if(i instanceof e)return i;if(typeof i=="string"){const h=i.split("@");let d,p;switch(h.length){case 1:if(!f)return;d=i,p=f;break;case 2:d=h[0],p=h[1];break;default:d=h.slice(0,h.length-1).join("@"),p=h[h.length-1]}d=d.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(d)&&(d=d.replace(/[-.()]/g,"")),i=`${u.SIP}:${s(d)}@${p}`;let v;return(v=e.parse(i))?v:void 0}else return}else return},pt.headerize=i=>{const f={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=i.toLowerCase().replace(/_/g,"-").split("-");let d="";const p=h.length;let v;for(v=0;v<p;v++)v!==0&&(d+="-"),d+=h[v].charAt(0).toUpperCase()+h[v].substring(1);return f[d]&&(d=f[d]),d},pt.sipErrorCause=i=>{for(const f in u.SIP_ERROR_CAUSES)if(u.SIP_ERROR_CAUSES[f].indexOf(i)!==-1)return u.causes[f];return u.causes.SIP_FAILURE_CODE},pt.getRandomTestNetIP=()=>{function i(f,h){return Math.floor(Math.random()*(h-f+1)+f)}return`192.0.2.${i(1,254)}`},pt.calculateMD5=i=>{function f(fe,_e){return fe<<_e|fe>>>32-_e}function h(fe,_e){const we=fe&2147483648,De=_e&2147483648,ce=fe&1073741824,de=_e&1073741824,ge=(fe&1073741823)+(_e&1073741823);return ce&de?ge^2147483648^we^De:ce|de?ge&1073741824?ge^3221225472^we^De:ge^1073741824^we^De:ge^we^De}function d(fe,_e,we){return fe&_e|~fe&we}function p(fe,_e,we){return fe&we|_e&~we}function v(fe,_e,we){return fe^_e^we}function T(fe,_e,we){return _e^(fe|~we)}function y(fe,_e,we,De,ce,de,ge){return fe=h(fe,h(h(d(_e,we,De),ce),ge)),h(f(fe,de),_e)}function S(fe,_e,we,De,ce,de,ge){return fe=h(fe,h(h(p(_e,we,De),ce),ge)),h(f(fe,de),_e)}function A(fe,_e,we,De,ce,de,ge){return fe=h(fe,h(h(v(_e,we,De),ce),ge)),h(f(fe,de),_e)}function R(fe,_e,we,De,ce,de,ge){return fe=h(fe,h(h(T(_e,we,De),ce),ge)),h(f(fe,de),_e)}function O(fe){let _e;const we=fe.length,De=we+8,de=((De-De%64)/64+1)*16,ge=new Array(de-1);let Oe=0,$e=0;for(;$e<we;)_e=($e-$e%4)/4,Oe=$e%4*8,ge[_e]=ge[_e]|fe.charCodeAt($e)<<Oe,$e++;return _e=($e-$e%4)/4,Oe=$e%4*8,ge[_e]=ge[_e]|128<<Oe,ge[de-2]=we<<3,ge[de-1]=we>>>29,ge}function N(fe){let _e="",we="",De,ce;for(ce=0;ce<=3;ce++)De=fe>>>ce*8&255,we=`0${De.toString(16)}`,_e=_e+we.substr(we.length-2,2);return _e}function C(fe){let _e="";for(let we=0;we<fe.length;we++){const De=fe.charCodeAt(we);De<128?_e+=String.fromCharCode(De):De>127&&De<2048?(_e+=String.fromCharCode(De>>6|192),_e+=String.fromCharCode(De&63|128)):(_e+=String.fromCharCode(De>>12|224),_e+=String.fromCharCode(De>>6&63|128),_e+=String.fromCharCode(De&63|128))}return _e}let b=[],w,F,q,D,P,I,x,U,B;const z=7,L=12,V=17,J=22,Pe=5,ee=9,j=14,K=20,ie=4,ue=11,Ce=16,ke=23,be=6,M=10,Y=15,Ee=21;for(i=C(i),b=O(i),I=1732584193,x=4023233417,U=2562383102,B=271733878,w=0;w<b.length;w+=16)F=I,q=x,D=U,P=B,I=y(I,x,U,B,b[w+0],z,3614090360),B=y(B,I,x,U,b[w+1],L,3905402710),U=y(U,B,I,x,b[w+2],V,606105819),x=y(x,U,B,I,b[w+3],J,3250441966),I=y(I,x,U,B,b[w+4],z,4118548399),B=y(B,I,x,U,b[w+5],L,1200080426),U=y(U,B,I,x,b[w+6],V,2821735955),x=y(x,U,B,I,b[w+7],J,4249261313),I=y(I,x,U,B,b[w+8],z,1770035416),B=y(B,I,x,U,b[w+9],L,2336552879),U=y(U,B,I,x,b[w+10],V,4294925233),x=y(x,U,B,I,b[w+11],J,2304563134),I=y(I,x,U,B,b[w+12],z,1804603682),B=y(B,I,x,U,b[w+13],L,4254626195),U=y(U,B,I,x,b[w+14],V,2792965006),x=y(x,U,B,I,b[w+15],J,1236535329),I=S(I,x,U,B,b[w+1],Pe,4129170786),B=S(B,I,x,U,b[w+6],ee,3225465664),U=S(U,B,I,x,b[w+11],j,643717713),x=S(x,U,B,I,b[w+0],K,3921069994),I=S(I,x,U,B,b[w+5],Pe,3593408605),B=S(B,I,x,U,b[w+10],ee,38016083),U=S(U,B,I,x,b[w+15],j,3634488961),x=S(x,U,B,I,b[w+4],K,3889429448),I=S(I,x,U,B,b[w+9],Pe,568446438),B=S(B,I,x,U,b[w+14],ee,3275163606),U=S(U,B,I,x,b[w+3],j,4107603335),x=S(x,U,B,I,b[w+8],K,1163531501),I=S(I,x,U,B,b[w+13],Pe,2850285829),B=S(B,I,x,U,b[w+2],ee,4243563512),U=S(U,B,I,x,b[w+7],j,1735328473),x=S(x,U,B,I,b[w+12],K,2368359562),I=A(I,x,U,B,b[w+5],ie,4294588738),B=A(B,I,x,U,b[w+8],ue,2272392833),U=A(U,B,I,x,b[w+11],Ce,1839030562),x=A(x,U,B,I,b[w+14],ke,4259657740),I=A(I,x,U,B,b[w+1],ie,2763975236),B=A(B,I,x,U,b[w+4],ue,1272893353),U=A(U,B,I,x,b[w+7],Ce,4139469664),x=A(x,U,B,I,b[w+10],ke,3200236656),I=A(I,x,U,B,b[w+13],ie,681279174),B=A(B,I,x,U,b[w+0],ue,3936430074),U=A(U,B,I,x,b[w+3],Ce,3572445317),x=A(x,U,B,I,b[w+6],ke,76029189),I=A(I,x,U,B,b[w+9],ie,3654602809),B=A(B,I,x,U,b[w+12],ue,3873151461),U=A(U,B,I,x,b[w+15],Ce,530742520),x=A(x,U,B,I,b[w+2],ke,3299628645),I=R(I,x,U,B,b[w+0],be,4096336452),B=R(B,I,x,U,b[w+7],M,1126891415),U=R(U,B,I,x,b[w+14],Y,2878612391),x=R(x,U,B,I,b[w+5],Ee,4237533241),I=R(I,x,U,B,b[w+12],be,1700485571),B=R(B,I,x,U,b[w+3],M,2399980690),U=R(U,B,I,x,b[w+10],Y,4293915773),x=R(x,U,B,I,b[w+1],Ee,2240044497),I=R(I,x,U,B,b[w+8],be,1873313359),B=R(B,I,x,U,b[w+15],M,4264355552),U=R(U,B,I,x,b[w+6],Y,2734768916),x=R(x,U,B,I,b[w+13],Ee,1309151649),I=R(I,x,U,B,b[w+4],be,4149444226),B=R(B,I,x,U,b[w+11],M,3174756917),U=R(U,B,I,x,b[w+2],Y,718787259),x=R(x,U,B,I,b[w+9],Ee,3951481745),I=h(I,F),x=h(x,q),U=h(U,D),B=h(B,P);return(N(I)+N(x)+N(U)+N(B)).toLowerCase()},pt.closeMediaStream=i=>{if(i)try{let f;if(i.getTracks){f=i.getTracks();for(const h of f)h.stop()}else{f=i.getAudioTracks();for(const h of f)h.stop();f=i.getVideoTracks();for(const h of f)h.stop()}}catch{(typeof i.stop=="function"||typeof i.stop=="object")&&i.stop()}},pt.cloneArray=i=>i&&i.slice()||[],pt.cloneObject=(i,f={})=>i&&Object.assign({},i)||f,pt}const np=Qt,dT=At,Ft=Ue,yt=Ht(),g_=xf(),_T=ys(),oh=new dT("SIPMessage");class bu{constructor(e,t,r,l,s,i){if(!e||!t||!r)return null;l=l||{},this.ua=r,this.headers={},this.method=e,this.ruri=t,this.body=i,this.extraHeaders=yt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),l.route_set?this.setHeader("route",l.route_set):r.configuration.use_preloaded_route&&this.setHeader("route",`<${r.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",Ft.MAX_FORWARDS);const f=l.to_uri||t,h=l.to_tag?{tag:l.to_tag}:null,d=typeof l.to_display_name<"u"?l.to_display_name:null;this.to=new g_(f,d,h),this.setHeader("to",this.to.toString());const p=l.from_uri||r.configuration.uri,v={tag:l.from_tag||yt.newTag()};let T;typeof l.from_display_name<"u"?T=l.from_display_name:r.configuration.display_name?T=r.configuration.display_name:T=null,this.from=new g_(p,T,v),this.setHeader("from",this.from.toString());const y=l.call_id||r.configuration.jssip_id+yt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const S=l.cseq||Math.floor(Math.random()*1e4);this.cseq=S,this.setHeader("cseq",`${S} ${e}`)}setHeader(e,t){const r=new RegExp(`^\\s*${e}\\s*:`,"i");for(let l=0;l<this.extraHeaders.length;l++)r.test(this.extraHeaders[l])&&this.extraHeaders.splice(l,1);this.headers[yt.headerize(e)]=Array.isArray(t)?t:[t]}getHeader(e){const t=this.headers[yt.headerize(e)];if(t){if(t[0])return t[0]}else{const r=new RegExp(`^\\s*${e}\\s*:`,"i");for(const l of this.extraHeaders)if(r.test(l))return l.substring(l.indexOf(":")+1).trim()}}getHeaders(e){const t=this.headers[yt.headerize(e)],r=[];if(t){for(const l of t)r.push(l);return r}else{const l=new RegExp(`^\\s*${e}\\s*:`,"i");for(const s of this.extraHeaders)l.test(s)&&r.push(s.substring(s.indexOf(":")+1).trim());return r}}hasHeader(e){if(this.headers[yt.headerize(e)])return!0;{const t=new RegExp(`^\\s*${e}\\s*:`,"i");for(const r of this.extraHeaders)if(t.test(r))return!0}return!1}parseSDP(e){return!e&&this.sdp?this.sdp:(this.sdp=np.parse(this.body||""),this.sdp)}toString(){let e=`${this.method} ${this.ruri} SIP/2.0\r
76
- `;for(const l in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,l))for(const s of this.headers[l])e+=`${l}: ${s}\r
77
- `;for(const l of this.extraHeaders)e+=`${l.trim()}\r
78
- `;const t=[];switch(this.method){case Ft.REGISTER:t.push("path","gruu");break;case Ft.INVITE:this.ua.configuration.session_timers&&t.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&t.push("gruu"),t.push("ice","replaces");break;case Ft.UPDATE:this.ua.configuration.session_timers&&t.push("timer"),t.push("ice");break}t.push("outbound");const r=this.ua.configuration.user_agent||Ft.USER_AGENT;if(e+=`Allow: ${Ft.ALLOWED_METHODS}\r
79
- `,e+=`Supported: ${t}\r
80
- `,e+=`User-Agent: ${r}\r
81
- `,this.body){const l=yt.str_utf8_length(this.body);e+=`Content-Length: ${l}\r
59
+ `.concat(n,`
60
+ `));this.ondata({transport:this,message:n})}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}]),c}(),ih={};function Hc(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Wp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
61
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Wp(c,t){if(c){if(typeof c=="string")return Fc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Fc(c,t)}}function Fc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var Kp=ht,Tu=os(),vu=Ss,Kl=new Kp("Parser");ih.parseMessage=function(c,t){var n,a,o=c.indexOf(`\r
62
+ `);if(o===-1){Kl.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=c.substring(0,o),r=Tu.parse(s,"Request_Response");if(r===-1){Kl.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else r.status_code?(n=new vu.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new vu.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;for(var d=o+2;;){if(o=Yp(c,d),o===-2){a=d+2;break}else if(o===-1){Kl.warn("parseMessage() | malformed message");return}if(r=Jp(n,c,d,o),r!==!0){Kl.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){var h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function Yp(c,t){var n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
63
+ `,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function Jp(c,t,n,a){var o,s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Tu.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=Hc(o),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;c.addHeader("record-route",d.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(A){h.e(A)}finally{h.f()}}break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Tu.parse(d,"Contact"),o===-1)o=void 0;else{var T=Hc(o),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;c.addHeader("contact",d.substring(y.possition,y.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=y.parsed}}catch(A){T.e(A)}finally{T.f()}}break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof vu.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:'error parsing header "'.concat(r,'"')}:!0}function Ia(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=zp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
64
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function zp(c,t){if(c){if(typeof c=="string")return jc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return jc(c,t)}}function jc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var Xp=ht,lh=lt,qc=Ss,ku=bt(),Mu=new Xp("sanityCheck"),Qp=[om],Zp=[sm,nm,rm,im],em=[lm,am],He,rs,ah,tm=function(c,t,n){He=c,rs=t,ah=n;var a=Ia(Qp),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(s()===!1)return!1}}catch(E){a.e(E)}finally{a.f()}if(He instanceof qc.IncomingRequest){var r=Ia(Zp),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;if(h()===!1)return!1}}catch(E){r.e(E)}finally{r.f()}}else if(He instanceof qc.IncomingResponse){var _=Ia(em),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;if(T()===!1)return!1}}catch(E){_.e(E)}finally{_.f()}}return!0};function sm(){if(He.s("to").uri.scheme!=="sip")return tl(416),!1}function nm(){if(!He.to_tag&&He.call_id.substr(0,5)===rs.configuration.jssip_id)return tl(482),!1}function rm(){var c=ku.str_utf8_length(He.body),t=He.getHeader("content-length");if(c<t)return tl(400),!1}function im(){var c=He.from_tag,t=He.call_id,n=He.cseq,a;if(!He.to_tag)if(He.method===lh.INVITE){if(rs._transactions.ist[He.via_branch])return!1;for(var o in rs._transactions.ist)if(Object.prototype.hasOwnProperty.call(rs._transactions.ist,o)&&(a=rs._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return tl(482),!1}else{if(rs._transactions.nist[He.via_branch])return!1;for(var s in rs._transactions.nist)if(Object.prototype.hasOwnProperty.call(rs._transactions.nist,s)&&(a=rs._transactions.nist[s],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return tl(482),!1}}function lm(){if(He.getHeaders("via").length>1)return Mu.debug("more than one Via header field present in the response, dropping the response"),!1}function am(){var c=ku.str_utf8_length(He.body),t=He.getHeader("content-length");if(c<t)return Mu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function om(){for(var c=["from","to","call_id","cseq","via"],t=0,n=c;t<n.length;t++){var a=n[t];if(!He.hasHeader(a))return Mu.debug("missing mandatory header field : ".concat(a,", dropping the response")),!1}}function tl(c){var t=He.getHeaders("via"),n,a="SIP/2.0 ".concat(c," ").concat(lh.REASON_PHRASE[c],`\r
65
+ `),o=Ia(t),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;a+="Via: ".concat(r,`\r
66
+ `)}}catch(d){o.e(d)}finally{o.f()}n=He.getHeader("To"),He.to_tag||(n+=";tag=".concat(ku.newTag())),a+="To: ".concat(n,`\r
67
+ `),a+="From: ".concat(He.getHeader("From"),`\r
68
+ `),a+="Call-ID: ".concat(He.call_id,`\r
69
+ `),a+="CSeq: ".concat(He.cseq," ").concat(He.method,`\r
70
+ `),a+=`\r
71
+ `,ah.send(a)}var Lu={};function Vc(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=um(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
72
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function um(c,t){if(c){if(typeof c=="string")return Bc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Bc(c,t)}}function Bc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var fr=bt(),yn=lt,wo=os(),Gc=Ks(),Oo=xu,Do=Ws;Lu.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:yn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:yn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:yn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(fr.createRandomToken(12),".invalid")};var Yl={mandatory:{sockets:function(t){var n=[];if(Oo.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&Oo.isSocket(s.socket)?n.push(s):Oo.isSocket(s)&&n.push({socket:s})}}catch(r){a.e(r)}finally{a.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(wo.parse('"'.concat(t,'"'),"quoted_string")!==-1)return t},authorization_jwt:function(t){if(typeof t=="string")return t},user_agent:function(t){if(typeof t=="string")return t},connection_recovery_max_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=wo.parse(t,"SIP_URI");if(n!==-1)return n}},display_name:function(t){return t},instance_id:function(t){if(/^uuid:/i.test(t)&&(t=t.substr(5)),wo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},session_timers:function(t){if(typeof t=="boolean")return t},session_timers_refresh_method:function(t){if(typeof t=="string"&&(t=t.toUpperCase(),t===yn.INVITE||t===yn.UPDATE))return t},session_timers_force_refresher:function(t){if(typeof t=="boolean")return t},password:function(t){return String(t)},realm:function(t){return String(t)},ha1:function(t){return String(t)},register:function(t){if(typeof t=="boolean")return t},register_expires:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?void 0:n},use_preloaded_route:function(t){if(typeof t=="boolean")return t},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;typeof s=="string"&&n.push(s)}}catch(r){a.e(r)}finally{a.f()}}else return;return n}}};Lu.load=function(c,t){for(var n in Yl.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=Yl.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Do.ConfigurationError(n,a)}else throw new Do.ConfigurationError(n);for(var s in Yl.optional)if(t.hasOwnProperty(s)){var r=t[s];if(fr.isEmpty(r))continue;var d=Yl.optional[s](r);if(d!==void 0)c[s]=d;else throw new Do.ConfigurationError(s,r)}};function ba(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ba=function(n){return typeof n}:ba=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ba(c)}function cm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Kc(c,t,n){return t&&Wc(c.prototype,t),n&&Wc(c,n),c}function fm(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Eu(c,t)}function Eu(c,t){return Eu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Eu(c,t)}function hm(c){var t=_m();return function(){var a=La(c),o;if(t){var s=La(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return dm(this,o)}}function dm(c,t){return t&&(ba(t)==="object"||typeof t=="function")?t:oh(c)}function oh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function _m(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function La(c){return La=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},La(c)}var pm=ft.EventEmitter,mm=ht,pt=lt,gm=r_,Yc=dp,Jc=Ip,zc=$p,No=hl,Tm=Gp,Jl=bt(),vm=Ws,Em=Ks(),Sm=ih,Uo=Ss,ym=tm,Po=Lu,je=new mm("UA"),Tt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Am=function(c){fm(n,c);var t=hm(n);Kc(n,null,[{key:"C",get:function(){return Tt}}]);function n(a){var o;if(cm(this,n),je.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},Po.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=Tt.STATUS_INIT,o._error=null,o._transactions={nist:{},nict:{},ist:{},ict:{}},o._data={},o._closeTimer=null,a===void 0)throw new TypeError("Not enough arguments");try{o._loadConfig(a)}catch(s){throw o._status=Tt.STATUS_NOT_READY,o._error=Tt.CONFIGURATION_ERROR,s}return o._registrator=new gm(oh(o)),o}return Kc(n,[{key:"start",value:function(){je.debug("start()"),this._status===Tt.STATUS_INIT?this._transport.connect():this._status===Tt.STATUS_USER_CLOSED?(je.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Tt.STATUS_INIT,this._transport.connect()):this._status===Tt.STATUS_READY?je.debug("UA is in READY status, not restarted"):je.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){je.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(o){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){je.debug("call()");var r=new Yc(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){je.debug("sendMessage()");var d=new Jc(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){je.debug("sendOptions()");var d=new zc(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){je.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(je.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){je.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=Tt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){o._closeTimer=null,o._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(o){return Jl.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:je.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return je.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),o.method!==pt.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===pt.SIPS){o.reply_sl(416);return}if(!No.checkTransaction(this,o)){if(s===pt.INVITE?new No.InviteServerTransaction(this,this._transport,o):s!==pt.ACK&&s!==pt.CANCEL&&new No.NonInviteServerTransaction(this,this._transport,o),s===pt.OPTIONS){if(this.listeners("newOptions").length===0){o.reply(200);return}var r=new zc(this);r.init_incoming(o)}else if(s===pt.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new Jc(this);d.init_incoming(o)}else if(s===pt.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,_;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===pt.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(je.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==pt.ACK&&o.reply(481);else switch(s){case pt.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){var g=o.replaces;h=this._findDialog(g.call_id,g.from_tag,g.to_tag),h?(_=h.owner,_.isEnded()?o.reply(603):_.receiveRequest(o)):o.reply(481)}else _=new Yc(this),_.init_incoming(o);else je.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case pt.BYE:o.reply(481);break;case pt.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):je.debug("received CANCEL request for a non existent session");break;case pt.ACK:break;case pt.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}}},{key:"_findSession",value:function(o){var s=o.call_id,r=o.from_tag,d=o.to_tag,h=s+r,_=this._sessions[h],g=s+d,T=this._sessions[g];return _||T||null}},{key:"_findDialog",value:function(o,s,r){var d=o+s+r,h=this._dialogs[d];return h||(d=o+r+s,h=this._dialogs[d],h||null)}},{key:"_loadConfig",value:function(o){try{Po.load(this._configuration,o)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Jl.newUUID()),this._configuration.jssip_id=Jl.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new Tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Cm.bind(this),this._transport.onconnect=Rm.bind(this),this._transport.ondisconnect=Im.bind(this),this._transport.ondata=bm.bind(this)}catch(g){throw je.warn(g),new vm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var r=this._configuration.uri.clone();r.user=null,r.clearParams(),r.clearHeaders(),this._configuration.registrar_server=r}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Em("sip",Jl.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.anonymous||null,y=T.outbound||null,A="<";return E?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),y&&(E?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(d.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(Po.settings,_))switch(_){case"uri":case"registrar_server":je.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":je.debug("- ".concat(_,": NOT SHOWN"));break;default:je.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{key:"C",get:function(){return Tt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}(pm);function Cm(c){this.emit("connecting",c)}function Rm(c){this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function Im(c){for(var t=["nict","ict","nist","ist"],n=0,a=t;n<a.length;n++){var o=a[n];for(var s in this._transactions[o])Object.prototype.hasOwnProperty.call(this._transactions[o],s)&&this._transactions[o][s].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_NOT_READY,this._error=Tt.NETWORK_ERROR)}function bm(c){var t=c.transport,n=c.message;if(n=Sm.parseMessage(n,this),!!n&&!(this._status===Tt.STATUS_USER_CLOSED&&n instanceof Uo.IncomingRequest)&&ym(n,this,t)){if(n instanceof Uo.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Uo.IncomingResponse){var a;switch(n.method){case pt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case pt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function wm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Xc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Om(c,t,n){return t&&Xc(c.prototype,t),n&&Xc(c,n),c}var Dm=ht,Nm=os(),Ot=new Dm("WebSocketInterface"),Um=function(){function c(t){wm(this,c),Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=Nm.parse(t,"absoluteURI");if(n===-1)throw Ot.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return Om(c,[{key:"connect",value:function(){if(Ot.debug("connect()"),this.isConnected()){Ot.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Ot.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Ot.debug("connecting to WebSocket ".concat(this._url));try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(n){this._onError(n)}}},{key:"disconnect",value:function(){Ot.debug("disconnect()"),this._ws&&(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),this._ws=null)}},{key:"send",value:function(n){return Ot.debug("send()"),this.isConnected()?(this._ws.send(n),!0):(Ot.warn("unable to send message, WebSocket is not open"),!1)}},{key:"isConnected",value:function(){return this._ws&&this._ws.readyState===this._ws.OPEN}},{key:"isConnecting",value:function(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}},{key:"_onOpen",value:function(){Ot.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(n){var a=n.wasClean,o=n.code,s=n.reason;Ot.debug("WebSocket ".concat(this._url," closed")),a===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;Ot.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){Ot.warn("WebSocket ".concat(this._url," error: "),n)}},{key:"via_transport",get:function(){return this._via_transport},set:function(n){this._via_transport=n.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),Su=Ha,Pm=lt,xm=Ws,km=bt(),Mm=Am,Lm=Ks(),$m=Ou(),Hm=os(),Fm=Um,jm=gr("JsSIP");jm("version %s",Su.version);var Qc={C:Pm,Exceptions:xm,Utils:km,UA:Mm,URI:Lm,NameAddrHeader:$m,WebSocketInterface:Fm,Grammar:Hm,debug:gr,get name(){return Su.title},get version(){return Su.version}};const or=gr,ur="JsSIP";var ut=class{constructor(t){t?(this._debug=or.default(`${ur}:${t}`),this._warn=or.default(`${ur}:WARN:${t}`),this._error=or.default(`${ur}:ERROR:${t}`)):(this._debug=or.default(ur),this._warn=or.default(`${ur}:WARN`),this._error=or.default(`${ur}:ERROR`)),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}get debug(){return this._debug}get warn(){return this._warn}get error(){return this._error}};const Ga=ze(ut),Zc=Ha;var De={USER_AGENT:`${Zc.title} ${Zc.version}`,SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};const L=ze(De);var et={},xo,ef;function $u(){if(ef)return xo;ef=1;const c=ys(),t=Zt();return xo=class uh{static parse(a){if(a=t.parse(a,"Name_Addr_Header"),a!==-1)return a}constructor(a,o,s){if(!a||!(a instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=a,this._parameters={},this.display_name=o;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&this.setParam(r,s[r])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(a){this._display_name=a===0?"0":a}setParam(a,o){a&&(this._parameters[a.toLowerCase()]=typeof o>"u"||o===null?null:o.toString())}getParam(a){if(a)return this._parameters[a.toLowerCase()]}hasParam(a){if(a)return this._parameters.hasOwnProperty(a.toLowerCase())&&!0||!1}deleteParam(a){if(a=a.toLowerCase(),this._parameters.hasOwnProperty(a)){const o=this._parameters[a];return delete this._parameters[a],o}}clearParams(){this._parameters={}}clone(){return new uh(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(a){return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let a=this._display_name?`"${this._quote(this._display_name)}" `:"";a+=`<${this._uri.toString()}>`;for(const o in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,o)&&(a+=`;${o}`,this._parameters[o]!==null&&(a+=`=${this._parameters[o]}`));return a}},xo}var ko,tf;function Zt(){return tf||(tf=1,ko=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(n,a){var o={CRLF:_,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:A,DQUOTE:C,SP:I,HTAB:H,alphanum:$,reserved:oe,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:k,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:X,token:U,token_nodot:P,separators:se,word:st,STAR:ee,SLASH:W,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:xe,COMMA:Ce,SEMI:le,COLON:ye,LDQUOT:nt,RDQUOT:at,comment:Ee,ctext:Ae,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:ue,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:Qe,uri_scheme_sip:Le,userinfo:Lt,user:dt,user_unreserved:wn,password:On,hostport:Ys,host:es,hostname:us,domainlabel:Js,toplabel:Dn,IPv6reference:Nn,IPv6address:zs,h16:me,ls32:ae,IPv4address:ot,dec_octet:Wt,port:Cs,uri_parameters:Er,uri_parameter:Un,transport_param:Pn,user_param:Sr,method_param:yr,ttl_param:Ar,maddr_param:Cr,lr_param:Rr,other_param:Ir,pname:br,pvalue:wr,paramchar:Rs,param_unreserved:Is,headers:Or,header:Xs,hname:Qs,hvalue:Dr,hnv_unreserved:bs,Request_Response:Zs,Request_Line:gl,Request_URI:Nr,absoluteURI:xn,hier_part:kn,net_path:Ur,abs_path:en,opaque_part:tn,uric:ws,uric_no_slash:Os,path_segments:Pr,segment:sn,param:Ds,pchar:cs,scheme:Ns,authority:xr,srvr:kr,reg_name:Mr,query:Lr,SIP_Version:Mn,INVITEm:Ln,ACKm:$r,OPTIONSm:Hr,BYEm:Fr,CANCELm:jr,REGISTERm:qr,SUBSCRIBEm:Vr,NOTIFYm:Br,REFERm:Gr,Method:nn,Status_Line:rn,Status_Code:Wr,extension_code:Kr,Reason_Phrase:Yr,Allow_Events:Tl,Call_ID:Ya,Contact:Ja,contact_param:$n,name_addr:$t,display_name:Ht,contact_params:Us,c_p_q:Hn,c_p_expires:Jr,delta_seconds:ts,qvalue:ss,generic_param:Ge,gen_value:We,Content_Disposition:vl,disp_type:El,disp_param:Fn,handling_param:jn,Content_Encoding:Sl,Content_Length:za,Content_Type:Xa,media_type:yl,m_type:zr,discrete_type:Xr,composite_type:Qr,extension_token:ln,x_token:an,m_subtype:Zr,m_parameter:qn,m_value:Vn,CSeq:Al,CSeq_value:Cl,Expires:Rl,Event:Qa,event_type:on,From:un,from_param:ei,tag_param:cn,Max_Forwards:ti,Min_Expires:Za,Name_Addr_Header:eo,Proxy_Authenticate:to,challenge:si,other_challenge:Bn,auth_param:Ps,digest_cln:ns,realm:fn,realm_value:ni,domain:ri,URI:hn,nonce:dn,nonce_value:ii,opaque:li,stale:ai,algorithm:oi,qop_options:ui,qop_value:_n,Proxy_Require:Gn,Record_Route:so,rec_route:Wn,Reason:Kn,reason_param:ci,reason_cause:Yn,Require:Il,Route:no,route_param:Jn,Subscription_State:zn,substate_value:bl,subexp_params:Xn,event_reason_value:Qn,Subject:wl,Supported:ro,To:io,to_param:fi,Via:hi,via_param:Zn,via_params:xs,via_ttl:er,via_maddr:di,via_received:_i,via_branch:pi,response_port:mi,rport:gi,sent_protocol:Ti,protocol_name:vi,transport:Ei,sent_by:Si,via_host:yi,via_port:Ai,ttl:tr,WWW_Authenticate:Ci,Session_Expires:lo,s_e_expires:Ol,s_e_params:sr,s_e_refresher:nr,extension_header:Dl,header_value:Nl,message_body:Ul,uuid_URI:ao,uuid:Pl,hex4:Ft,hex8:jt,hex12:Ri,Refer_To:xl,Replaces:oo,call_id:kl,replaces_param:rr,to_tag:ir,from_tag:Ii,early_flag:bi};if(a!==void 0){if(o[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var s=0,r=0,d=[];function h(i){s<r||(s>r&&(r=s,d=[]),d.push(i))}function _(){var i;return n.substr(s,2)===`\r
73
+ `?(i=`\r
74
+ `,s+=2):(i=null,h('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9a-fA-F]")),i}function y(){var i;return i=I(),i===null&&(i=H()),i}function A(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\0-\\xFF]")),i}function C(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h('["]')),i}function I(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function H(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function $(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z0-9]")),i}function oe(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","'))))))))))),i}function N(){var i;return i=$(),i===null&&(i=j()),i}function j(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,h('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,h('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,h('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,h('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,h('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,h(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(s=u),i}function ve(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=_(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=y(),l!==null)for(e=[];l!==null;)e.push(l),l=y();else e=null;e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(m){return" "}()),i===null&&(s=u),i}function k(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=s,f=s,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function B(){var i,e,l,u,f,p,m;if(f=s,p=s,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m)}e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){return n.substring(s,v)}(f)),i===null&&(s=f),i}function V(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\xBF]")),i}function X(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-f]"))),i}function U(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function P(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function se(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,h('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i===null&&(i=C(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,h('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,h('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function st(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function ee(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"*"}()),i===null&&(s=u),i}function W(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"/"}()),i===null&&(s=u),i}function G(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"="}()),i===null&&(s=u),i}function re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"("}()),i===null&&(s=u),i}function ge(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return")"}()),i===null&&(s=u),i}function be(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function xe(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return"<"}()),i===null&&(s=l),i}function Ce(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return","}()),i===null&&(s=u),i}function le(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return";"}()),i===null&&(s=u),i}function ye(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function nt(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(e=C(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function at(){var i,e,l,u;return l=s,u=s,i=C(),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function Ee(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ae(),l===null&&(l=ue(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ae(),l===null&&(l=ue(),l===null&&(l=Ee()));e!==null?(l=ge(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)}else i=null,s=u;return i}function Ae(){var i;return/^[!-']/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){return n.substring(s,m)}(f)),i===null&&(s=f),i}function Oe(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){var v=n.substring(s,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(s=f),i}function pe(){var i;return i=ve(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J())))),i}function ue(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _e(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i!==null&&(i=function(m){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port}catch{b=-1}}()),i===null&&(s=f),i}function we(){var i,e,l,u,f,p,m,v;return m=s,v=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?(f=Er(),f!==null?(p=Or(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v),i!==null&&(i=function(S){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port,b.uri_params,b.uri_headers),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port,delete b.uri_params,a==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=Qe(),i===null&&(i=Le()),i}function Qe(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,h('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Le(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Lt(){var i,e,l,u,f,p;return u=s,f=s,i=dt(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=On(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?(n.charCodeAt(s)===64?(l="@",s++):(l=null,h('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function dt(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=wn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=wn()));else i=null;return i}function wn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function On(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));return i!==null&&(i=function(u){b.password=n.substring(s,u)}(l)),i===null&&(s=l),i}function Ys(){var i,e,l,u,f;return u=s,i=es(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Cs(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function es(){var i,e;return e=s,i=us(),i===null&&(i=ot(),i===null&&(i=Nn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function us(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);e!==null;)i.push(e),p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=Dn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){return b.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function Js(){var i,e,l,u;if(u=s,i=$(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Dn(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Nn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=zs(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,h('"]"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return b.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function zs(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R;return ks=s,M=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=me(),ie!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(wt=ae(),wt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(ie=":",s++):(ie=null,h('":"')),ie!==null?(Ue=ae(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,h('"::"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=ae(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,h('"::"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,h('"::"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=ae(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,h('"::"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(R=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=R)):(m=null,s=R),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,h('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",n.substring(s,Te)}(ks)),i===null&&(s=ks),i}function me(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e=e!==null?e:"",e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function ae(){var i,e,l,u;return u=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=ot()),i}function ot(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=Wt(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=Wt(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S),i!==null&&(i=function(O){return b.host_type="IPv4",n.substring(s,O)}(v)),i===null&&(s=v),i}function Wt(){var i,e,l,u;return u=s,n.substr(s,2)==="25"?(i="25",s+=2):(i=null,h('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-5]")),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===50?(i="2",s++):(i=null,h('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===49?(i="1",s++):(i=null,h('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,/^[1-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(i=g())))),i}function Cs(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(s=p),i}function Er(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);e!==null;)i.push(e),u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Un(){var i;return i=Pn(),i===null&&(i=Sr(),i===null&&(i=yr(),i===null&&(i=Ar(),i===null&&(i=Cr(),i===null&&(i=Rr(),i===null&&(i=Ir())))))),i}function Pn(){var i,e,l,u;return l=s,u=s,n.substr(s,10).toLowerCase()==="transport="?(i=n.substr(s,10),s+=10):(i=null,h('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,h('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,h('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,h('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,h('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function Sr(){var i,e,l,u;return l=s,u=s,n.substr(s,5).toLowerCase()==="user="?(i=n.substr(s,5),s+=5):(i=null,h('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,h('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,h('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function yr(){var i,e,l,u;return l=s,u=s,n.substr(s,7).toLowerCase()==="method="?(i=n.substr(s,7),s+=7):(i=null,h('"method="')),i!==null?(e=nn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function Ar(){var i,e,l,u;return l=s,u=s,n.substr(s,4).toLowerCase()==="ttl="?(i=n.substr(s,4),s+=4):(i=null,h('"ttl="')),i!==null?(e=tr(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(s=l),i}function Cr(){var i,e,l,u;return l=s,u=s,n.substr(s,6).toLowerCase()==="maddr="?(i=n.substr(s,6),s+=6):(i=null,h('"maddr="')),i!==null?(e=es(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function Rr(){var i,e,l,u,f,p;return u=s,f=s,n.substr(s,2).toLowerCase()==="lr"?(i=n.substr(s,2),s+=2):(i=null,h('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(s=u),i}function Ir(){var i,e,l,u,f,p;return u=s,f=s,i=br(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=wr(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.uri_params||(b.uri_params={}),typeof S>"u"?S=void 0:S=S[1],b.uri_params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function br(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function wr(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Rs(){var i;return i=Is(),i===null&&(i=N(),i===null&&(i=Se())),i}function Is(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Or(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=Xs(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);u!==null;)l.push(u),m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i}function Xs(){var i,e,l,u,f;return u=s,f=s,i=Qs(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=Dr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m,v){m=m.join("").toLowerCase(),v=v.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[m]?b.uri_headers[m].push(v):b.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function Qs(){var i,e;if(e=bs(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function Dr(){var i,e;for(i=[],e=bs(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));return i}function bs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Zs(){var i;return i=rn(),i===null&&(i=gl()),i}function gl(){var i,e,l,u,f,p;return p=s,i=nn(),i!==null?(e=I(),e!==null?(l=Nr(),l!==null?(u=I(),u!==null?(f=Mn(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Nr(){var i;return i=we(),i===null&&(i=xn()),i}function xn(){var i,e,l,u;return u=s,i=Ns(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=kn(),l===null&&(l=tn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function kn(){var i,e,l,u,f;return u=s,i=Ur(),i===null&&(i=en()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Lr(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function Ur(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=xr(),e!==null?(l=en(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function en(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=Pr(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function tn(){var i,e,l,u;if(u=s,i=Os(),i!==null){for(e=[],l=ws();l!==null;)e.push(l),l=ws();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function ws(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Os(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))))),i}function Pr(){var i,e,l,u,f,p;if(f=s,i=sn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function sn(){var i,e,l,u,f,p;for(f=s,i=[],e=cs();e!==null;)i.push(e),e=cs();if(i!==null){for(e=[],p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ds(){var i,e;for(i=[],e=cs();e!==null;)i.push(e),e=cs();return i}function cs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))),i}function Ns(){var i,e,l,u,f;if(u=s,f=s,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){b.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function xr(){var i;return i=kr(),i===null&&(i=Mr()),i}function kr(){var i,e,l,u;return l=s,u=s,i=Lt(),i!==null?(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i=i!==null?i:"",i!==null?(e=Ys(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Mr(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')))))))))));else i=null;return i}function Lr(){var i,e;for(i=[],e=ws();e!==null;)i.push(e),e=ws();return i}function Mn(){var i,e,l,u,f,p,m,v;if(m=s,v=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null){if(p=g(),p!==null)for(f=[];p!==null;)f.push(p),p=g();else f=null;f!==null?i=[i,e,l,u,f]:(i=null,s=v)}else i=null,s=v;else i=null,s=v}else i=null,s=v;else i=null,s=v;return i!==null&&(i=function(S){b.sip_version=n.substring(s,S)}(m)),i===null&&(s=m),i}function Ln(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function $r(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function Hr(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Fr(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function jr(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function qr(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Vr(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Br(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function Gr(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function nn(){var i,e;return e=s,i=Ln(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=Vr(),i===null&&(i=Br(),i===null&&(i=Gr(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=n.substring(s,l),b.method}(e)),i===null&&(s=e),i}function rn(){var i,e,l,u,f,p;return p=s,i=Mn(),i!==null?(e=I(),e!==null?(l=Wr(),l!==null?(u=I(),u!==null?(f=Yr(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Wr(){var i,e;return e=s,i=Kr(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Kr(){var i,e,l,u;return u=s,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yr(){var i,e,l;for(l=s,i=[],e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));e!==null;)i.push(e),e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function Tl(){var i,e,l,u,f,p;if(f=s,i=on(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ya(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b=n.substring(s,m)}(u)),i===null&&(s=u),i}function Ja(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=$n(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ce(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function $n(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function $t(){var i,e,l,u,f;return f=s,i=Ht(),i=i!==null?i:"",i!==null?(e=xe(),e!==null?(l=we(),l!==null?(u=be(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Ht(){var i,e,l,u,f,p,m;if(f=s,p=s,i=U(),i!==null){for(e=[],m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i===null&&(i=Oe()),i!==null&&(i=function(v,S){typeof S=="string"?b.display_name=S:b.display_name=S[1].reduce(function(O,ie){return O+ie[0]+ie[1]},S[0])}(f,i)),i===null&&(s=f),i}function Us(){var i;return i=Hn(),i===null&&(i=Jr(),i===null&&(i=Ge())),i}function Hn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,1).toLowerCase()==="q"?(i=n.substr(s,1),s++):(i=null,h('"q"')),i!==null?(e=G(),e!==null?(l=ss(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(s=u),i}function Jr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(s=u),i}function ts(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){return parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ss(){var i,e,l,u,f,p,m,v;return p=s,m=s,n.charCodeAt(s)===48?(i="0",s++):(i=null,h('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,s=v)):(e=null,s=v)):(e=null,s=v)):(e=null,s=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(S){return parseFloat(n.substring(s,S))}(p)),i===null&&(s=p),i}function Ge(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=We(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.params||(b.params={}),typeof S>"u"?S=void 0:S=S[1],b.params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function We(){var i;return i=U(),i===null&&(i=es(),i===null&&(i=Ie())),i}function vl(){var i,e,l,u,f,p;if(f=s,i=El(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function El(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,h('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,h('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,h('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,h('"alert"')),i===null&&(i=U())))),i}function Fn(){var i;return i=jn(),i===null&&(i=Ge()),i}function jn(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,h('"handling"')),i!==null?(e=G(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,h('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,h('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Sl(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function za(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Xa(){var i,e;return e=s,i=yl(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function yl(){var i,e,l,u,f,p,m,v;if(m=s,i=zr(),i!==null)if(e=W(),e!==null)if(l=Zr(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function zr(){var i;return i=Xr(),i===null&&(i=Qr()),i}function Xr(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,h('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,h('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,h('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,h('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,h('"application"')),i===null&&(i=ln()))))),i}function Qr(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,h('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,h('"multipart"')),i===null&&(i=ln())),i}function ln(){var i;return i=U(),i===null&&(i=an()),i}function an(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,h('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Zr(){var i;return i=ln(),i===null&&(i=U()),i}function qn(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=Vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Vn(){var i;return i=U(),i===null&&(i=Ie()),i}function Al(){var i,e,l,u;return u=s,i=Cl(),i!==null?(e=ve(),e!==null?(l=nn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Cl(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Rl(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Qa(){var i,e,l,u,f,p,m;if(f=s,p=s,i=on(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function on(){var i,e,l,u,f,p;if(f=s,i=P(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function un(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function ei(){var i;return i=cn(),i===null&&(i=Ge()),i}function cn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="tag"?(i=n.substr(s,3),s+=3):(i=null,h('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(s=u),i}function ti(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Za(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function eo(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Ht();e!==null;)i.push(e),e=Ht();if(i!==null)if(e=xe(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=S)}else i=null,s=S;else i=null,s=S;else i=null,s=S;else i=null,s=S;return i!==null&&(i=function(ie){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function to(){var i;return i=si(),i}function si(){var i,e,l,u,f,p,m,v;if(m=s,n.substr(s,6).toLowerCase()==="digest"?(i=n.substr(s,6),s+=6):(i=null,h('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=ns(),l!==null){for(u=[],v=s,f=Ce(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ce(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=Bn()),i}function Bn(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ps(),l!==null){for(u=[],v=s,f=Ce(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ce(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ps(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ns(){var i;return i=fn(),i===null&&(i=ri(),i===null&&(i=dn(),i===null&&(i=li(),i===null&&(i=ai(),i===null&&(i=oi(),i===null&&(i=ui(),i===null&&(i=Ps()))))))),i}function fn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="realm"?(i=n.substr(s,5),s+=5):(i=null,h('"realm"')),i!==null?(e=G(),e!==null?(l=ni(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ni(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(s=e),i}function ri(){var i,e,l,u,f,p,m,v,S;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,h('"domain"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null)if(u=hn(),u!==null){if(f=[],S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S);p!==null;){if(f.push(p),S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=at(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function hn(){var i;return i=xn(),i===null&&(i=en()),i}function dn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,h('"nonce"')),i!==null?(e=G(),e!==null?(l=ii(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ii(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(s=e),i}function li(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="opaque"?(i=n.substr(s,6),s+=6):(i=null,h('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(s=u),i}function ai(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,h('"stale"')),i!==null?(e=G(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,h('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(s=f),l===null&&(f=s,n.substr(s,5).toLowerCase()==="false"?(l=n.substr(s,5),s+=5):(l=null,h('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(s=f)),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function oi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="algorithm"?(i=n.substr(s,9),s+=9):(i=null,h('"algorithm"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,h('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,h('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function ui(){var i,e,l,u,f,p,m,v,S,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,h('"qop"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null){if(S=s,u=_n(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?u=[u,f]:(u=null,s=S)}else u=null,s=S;u!==null?(f=at(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function _n(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,h('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,h('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function Gn(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function so(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Wn(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function Wn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=$t(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function Kn(){var i,e,l,u,f,p,m;if(f=s,p=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){if(b.protocol=S.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var O=b.params.text;b.text=O.substring(1,O.length-1),delete b.params.text}}(f,i[0])),i===null&&(s=f),i}function ci(){var i;return i=Yn(),i===null&&(i=Ge()),i}function Yn(){var i,e,l,u,f,p;if(f=s,p=s,n.substr(s,5).toLowerCase()==="cause"?(i=n.substr(s,5),s+=5):(i=null,h('"cause"')),i!==null)if(e=G(),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function Il(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function no(){var i,e,l,u,f,p;if(f=s,i=Jn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Jn(){var i,e,l,u,f,p;if(f=s,i=$t(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function zn(){var i,e,l,u,f,p;if(f=s,i=bl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function bl(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,h('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,h('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,h('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function Xn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="reason"?(i=n.substr(s,6),s+=6):(i=null,h('"reason"')),i!==null?(e=G(),e!==null?(l=Qn(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,11).toLowerCase()==="retry_after"?(i=n.substr(s,11),s+=11):(i=null,h('"retry_after"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=Ge()))),i}function Qn(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,h('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,h('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,h('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,h('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,h('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,h('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,h('"invariant"')),i===null&&(i=U()))))))),i}function wl(){var i;return i=B(),i=i!==null?i:"",i}function ro(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i=i!==null?i:"",i}function io(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function fi(){var i;return i=cn(),i===null&&(i=Ge()),i}function hi(){var i,e,l,u,f,p;if(f=s,i=Zn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Zn(){var i,e,l,u,f,p,m,v;if(m=s,i=Ti(),i!==null)if(e=ve(),e!==null)if(l=Si(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function xs(){var i;return i=er(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi(),i===null&&(i=mi(),i===null&&(i=Ge()))))),i}function er(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="ttl"?(i=n.substr(s,3),s+=3):(i=null,h('"ttl"')),i!==null?(e=G(),e!==null?(l=tr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(s=u),i}function di(){var i,e,l,u,f;return u=s,f=s,n.substr(s,5).toLowerCase()==="maddr"?(i=n.substr(s,5),s+=5):(i=null,h('"maddr"')),i!==null?(e=G(),e!==null?(l=es(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(s=u),i}function _i(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8).toLowerCase()==="received"?(i=n.substr(s,8),s+=8):(i=null,h('"received"')),i!==null?(e=G(),e!==null?(l=ot(),l===null&&(l=zs()),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(s=u),i}function pi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,h('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(s=u),i}function mi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,h('"rport"')),i!==null?(f=s,e=G(),e!==null?(l=gi(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function gi(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function Ti(){var i,e,l,u,f,p;return p=s,i=vi(),i!==null?(e=W(),e!==null?(l=U(),l!==null?(u=W(),u!==null?(f=Ei(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function vi(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(s=e),i}function Ei(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,h('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,h('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,h('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,h('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(s=e),i}function Si(){var i,e,l,u,f;return u=s,i=yi(),i!==null?(f=s,e=ye(),e!==null?(l=Ai(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function yi(){var i,e;return e=s,i=ot(),i===null&&(i=Nn(),i===null&&(i=us())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function Ai(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function tr(){var i,e,l,u,f;return u=s,f=s,i=g(),i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(s=u),i}function Ci(){var i;return i=si(),i}function lo(){var i,e,l,u,f,p;if(f=s,i=Ol(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ol(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function sr(){var i;return i=nr(),i===null&&(i=Ge()),i}function nr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="refresher"?(i=n.substr(s,9),s+=9):(i=null,h('"refresher"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,h('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,h('"uas"'))),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function Dl(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=Nl(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Nl(){var i,e;for(i=[],e=V(),e===null&&(e=F(),e===null&&(e=ve()));e!==null;)i.push(e),e=V(),e===null&&(e=F(),e===null&&(e=ve()));return i}function Ul(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function ao(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Pl(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Pl(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=jt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Ft(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Ft(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Ft(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=Ri(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie),i!==null&&(i=function(Ue,wt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Ft(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function jt(){var i,e,l;return l=s,i=Ft(),i!==null?(e=Ft(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ri(){var i,e,l,u;return u=s,i=Ft(),i!==null?(e=Ft(),e!==null?(l=Ft(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function xl(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function oo(){var i,e,l,u,f,p;if(f=s,i=kl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function kl(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function rr(){var i;return i=ir(),i===null&&(i=Ii(),i===null&&(i=bi(),i===null&&(i=Ge()))),i}function ir(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,h('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(s=u),i}function Ii(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,h('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(s=u),i}function bi(){var i,e;return e=s,n.substr(s,10)==="early-only"?(i="early-only",s+=10):(i=null,h('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(s=e),i}function Ml(i){i.sort();for(var e=null,l=[],u=0;u<i.length;u++)i[u]!==e&&(l.push(i[u]),e=i[u]);return l}function uo(){for(var i=1,e=1,l=!1,u=0;u<Math.max(s,r);u++){var f=n.charAt(u);f===`
75
+ `?(l||i++,e=1,l=!1):f==="\r"||f==="\u2028"||f==="\u2029"?(i++,e=1,l=!0):(e++,l=!1)}return{line:i,column:e}}var Ll=ys(),fs=$u(),b={},w=o[a]();if(w===null||s!==n.length){var wi=Math.max(s,r),Oi=wi<n.length?n.charAt(wi):null,$l=uo();return new this.SyntaxError(Ml(d),Oi,wi,$l.line,$l.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),ko}var Mo,sf;function ys(){if(sf)return Mo;sf=1;const c=De,t=At(),n=Zt();return Mo=class ch{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,d,h={},_={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=o||c.SIP,this._user=s,this._host=r,this._port=d;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setHeader(g,_[g])}get scheme(){return this._scheme}set scheme(o){this._scheme=o.toLowerCase()}get user(){return this._user}set user(o){this._user=o}get host(){return this._host}set host(o){this._host=o.toLowerCase()}get port(){return this._port}set port(o){this._port=o===0?o:parseInt(o,10)||null}setParam(o,s){o&&(this._parameters[o.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const s=this._parameters[o];return delete this._parameters[o],s}}clearParams(){this._parameters={}}setHeader(o,s){this._headers[t.headerize(o)]=Array.isArray(s)?s:[s]}getHeader(o){if(o)return this._headers[t.headerize(o)]}hasHeader(o){if(o)return this._headers.hasOwnProperty(t.headerize(o))&&!0||!1}deleteHeader(o){if(o=t.headerize(o),this._headers.hasOwnProperty(o)){const s=this._headers[o];return delete this._headers[o],s}}clearHeaders(){this._headers={}}clone(){return new ch(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const o=[];let s=`${this._scheme}:`;this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const r in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(s+=`;${r}`,this._parameters[r]!==null&&(s+=`=${this._parameters[r]}`));for(const r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r))for(const d of this._headers[r])o.push(`${r}=${d}`);return o.length>0&&(s+=`?${o.join("&")}`),s}toAor(o){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,o&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},Mo}var nf;function At(){if(nf)return et;nf=1;const c=De,t=ys(),n=Zt();et.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=et.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;et.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,et.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),et.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),et.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=et.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};et.newTag=()=>o(10),et.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const h=Math.random()*16|0;return(d==="x"?h:h&3|8).toString(16)}),et.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=et.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return et.normalizeTarget=(r,d)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let _,g;switch(h.length){case 1:if(!d)return;_=r,g=d;break;case 2:_=h[0],g=h[1];break;default:_=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}_=_.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(_)&&(_=_.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(_)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},et.headerize=r=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let _="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(_+="-"),_+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return d[_]&&(_=d[_]),_},et.sipErrorCause=r=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(r)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},et.calculateMD5=r=>{function d(Ee,Ae){return Ee<<Ae|Ee>>>32-Ae}function h(Ee,Ae){const Ie=Ee&2147483648,Oe=Ae&2147483648,pe=Ee&1073741824,ue=Ae&1073741824,_e=(Ee&1073741823)+(Ae&1073741823);return pe&ue?_e^2147483648^Ie^Oe:pe|ue?_e&1073741824?_e^3221225472^Ie^Oe:_e^1073741824^Ie^Oe:_e^Ie^Oe}function _(Ee,Ae,Ie){return Ee&Ae|~Ee&Ie}function g(Ee,Ae,Ie){return Ee&Ie|Ae&~Ie}function T(Ee,Ae,Ie){return Ee^Ae^Ie}function E(Ee,Ae,Ie){return Ae^(Ee|~Ie)}function y(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(_(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function A(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(g(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function C(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(T(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function I(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(E(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function H(Ee){let Ae;const Ie=Ee.length,Oe=Ie+8,ue=((Oe-Oe%64)/64+1)*16,_e=new Array(ue-1);let we=0,Ne=0;for(;Ne<Ie;)Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|Ee.charCodeAt(Ne)<<we,Ne++;return Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|128<<we,_e[ue-2]=Ie<<3,_e[ue-1]=Ie>>>29,_e}function $(Ee){let Ae="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Ee>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ae=Ae+Ie.substr(Ie.length-2,2);return Ae}function oe(Ee){let Ae="";for(let Ie=0;Ie<Ee.length;Ie++){const Oe=Ee.charCodeAt(Ie);Oe<128?Ae+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(Ae+=String.fromCharCode(Oe>>6|192),Ae+=String.fromCharCode(Oe&63|128)):(Ae+=String.fromCharCode(Oe>>12|224),Ae+=String.fromCharCode(Oe>>6&63|128),Ae+=String.fromCharCode(Oe&63|128))}return Ae}let N=[],j,Se,ve,k,D,B,V,J,F;const X=7,U=12,P=17,se=22,st=5,ee=9,W=14,G=20,re=4,ge=11,be=16,xe=23,Ce=6,le=10,ye=15,nt=21;for(r=oe(r),N=H(r),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,k=J,D=F,B=y(B,V,J,F,N[j+0],X,3614090360),F=y(F,B,V,J,N[j+1],U,3905402710),J=y(J,F,B,V,N[j+2],P,606105819),V=y(V,J,F,B,N[j+3],se,3250441966),B=y(B,V,J,F,N[j+4],X,4118548399),F=y(F,B,V,J,N[j+5],U,1200080426),J=y(J,F,B,V,N[j+6],P,2821735955),V=y(V,J,F,B,N[j+7],se,4249261313),B=y(B,V,J,F,N[j+8],X,1770035416),F=y(F,B,V,J,N[j+9],U,2336552879),J=y(J,F,B,V,N[j+10],P,4294925233),V=y(V,J,F,B,N[j+11],se,2304563134),B=y(B,V,J,F,N[j+12],X,1804603682),F=y(F,B,V,J,N[j+13],U,4254626195),J=y(J,F,B,V,N[j+14],P,2792965006),V=y(V,J,F,B,N[j+15],se,1236535329),B=A(B,V,J,F,N[j+1],st,4129170786),F=A(F,B,V,J,N[j+6],ee,3225465664),J=A(J,F,B,V,N[j+11],W,643717713),V=A(V,J,F,B,N[j+0],G,3921069994),B=A(B,V,J,F,N[j+5],st,3593408605),F=A(F,B,V,J,N[j+10],ee,38016083),J=A(J,F,B,V,N[j+15],W,3634488961),V=A(V,J,F,B,N[j+4],G,3889429448),B=A(B,V,J,F,N[j+9],st,568446438),F=A(F,B,V,J,N[j+14],ee,3275163606),J=A(J,F,B,V,N[j+3],W,4107603335),V=A(V,J,F,B,N[j+8],G,1163531501),B=A(B,V,J,F,N[j+13],st,2850285829),F=A(F,B,V,J,N[j+2],ee,4243563512),J=A(J,F,B,V,N[j+7],W,1735328473),V=A(V,J,F,B,N[j+12],G,2368359562),B=C(B,V,J,F,N[j+5],re,4294588738),F=C(F,B,V,J,N[j+8],ge,2272392833),J=C(J,F,B,V,N[j+11],be,1839030562),V=C(V,J,F,B,N[j+14],xe,4259657740),B=C(B,V,J,F,N[j+1],re,2763975236),F=C(F,B,V,J,N[j+4],ge,1272893353),J=C(J,F,B,V,N[j+7],be,4139469664),V=C(V,J,F,B,N[j+10],xe,3200236656),B=C(B,V,J,F,N[j+13],re,681279174),F=C(F,B,V,J,N[j+0],ge,3936430074),J=C(J,F,B,V,N[j+3],be,3572445317),V=C(V,J,F,B,N[j+6],xe,76029189),B=C(B,V,J,F,N[j+9],re,3654602809),F=C(F,B,V,J,N[j+12],ge,3873151461),J=C(J,F,B,V,N[j+15],be,530742520),V=C(V,J,F,B,N[j+2],xe,3299628645),B=I(B,V,J,F,N[j+0],Ce,4096336452),F=I(F,B,V,J,N[j+7],le,1126891415),J=I(J,F,B,V,N[j+14],ye,2878612391),V=I(V,J,F,B,N[j+5],nt,4237533241),B=I(B,V,J,F,N[j+12],Ce,1700485571),F=I(F,B,V,J,N[j+3],le,2399980690),J=I(J,F,B,V,N[j+10],ye,4293915773),V=I(V,J,F,B,N[j+1],nt,2240044497),B=I(B,V,J,F,N[j+8],Ce,1873313359),F=I(F,B,V,J,N[j+15],le,4264355552),J=I(J,F,B,V,N[j+6],ye,2734768916),V=I(V,J,F,B,N[j+13],nt,1309151649),B=I(B,V,J,F,N[j+4],Ce,4149444226),F=I(F,B,V,J,N[j+11],le,3174756917),J=I(J,F,B,V,N[j+2],ye,718787259),V=I(V,J,F,B,N[j+9],nt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},et.closeMediaStream=r=>{if(r)try{let d;if(r.getTracks){d=r.getTracks();for(const h of d)h.stop()}else{d=r.getAudioTracks();for(const h of d)h.stop();d=r.getVideoTracks();for(const h of d)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},et.cloneArray=r=>r&&r.slice()||[],et.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,et}const fh=xt,qm=ut,St=De,it=At(),rf=$u(),Vm=Zt(),Lo=new qm("SIPMessage");class Wa{constructor(t,n,a,o,s,r){if(!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=it.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",St.MAX_FORWARDS);const d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new rf(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||it.newTag()};let E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new rf(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+it.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const A=o.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${t}`)}setHeader(t,n){const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(let o=0;o<this.extraHeaders.length;o++)a.test(this.extraHeaders[o])&&this.extraHeaders.splice(o,1);this.headers[it.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[it.headerize(t)];if(n){if(n[0])return n[0]}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(a.test(o))return o.substring(o.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[it.headerize(t)],a=[];if(n){for(const o of n)a.push(o);return a}else{const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)o.test(s)&&a.push(s.substring(s.indexOf(":")+1).trim());return a}}hasHeader(t){if(this.headers[it.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(n.test(a))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fh.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
76
+ `;for(const o in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,o))for(const s of this.headers[o])t+=`${o}: ${s}\r
77
+ `;for(const o of this.extraHeaders)t+=`${o.trim()}\r
78
+ `;const n=[];switch(this.method){case St.REGISTER:n.push("path","gruu");break;case St.INVITE:this.ua.configuration.session_timers&&n.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&n.push("gruu"),n.push("ice","replaces");break;case St.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const a=this.ua.configuration.user_agent||St.USER_AGENT;if(t+=`Allow: ${St.ALLOWED_METHODS}\r
79
+ `,t+=`Supported: ${n}\r
80
+ `,t+=`User-Agent: ${a}\r
81
+ `,this.body){const o=it.str_utf8_length(this.body);t+=`Content-Length: ${o}\r
82
82
  \r
83
- `,e+=this.body}else e+=`Content-Length: 0\r
83
+ `,t+=this.body}else t+=`Content-Length: 0\r
84
84
  \r
85
- `;return e}clone(){const e=new bu(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=yt.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e}}class kf extends bu{constructor(e,t,r,l,s){super(Ft.INVITE,e,t,r,l,s),this.transaction=null}cancel(e){this.transaction.cancel(e)}clone(){const e=new kf(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=yt.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e.transaction=this.transaction,e}}class ip{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(e,t){const r={raw:t};e=yt.headerize(e),this.headers[e]?this.headers[e].push(r):this.headers[e]=[r]}getHeader(e){const t=this.headers[yt.headerize(e)];if(t){if(t[0])return t[0].raw}else return}getHeaders(e){const t=this.headers[yt.headerize(e)],r=[];if(!t)return[];for(const l of t)r.push(l.raw);return r}hasHeader(e){return!!this.headers[yt.headerize(e)]}parseHeader(e,t=0){if(e=yt.headerize(e),this.headers[e]){if(t>=this.headers[e].length){oh.debug(`not so many "${e}" headers present`);return}}else{oh.debug(`header "${e}" not present`);return}const r=this.headers[e][t],l=r.raw;if(r.parsed)return r.parsed;const s=_T.parse(l,e.replace(/-/g,"_"));if(s===-1){this.headers[e].splice(t,1),oh.debug(`error parsing "${e}" header field with value "${l}"`);return}else return r.parsed=s,s}s(e,t){return this.parseHeader(e,t)}setHeader(e,t){const r={raw:t};this.headers[yt.headerize(e)]=[r]}parseSDP(e){return!e&&this.sdp?this.sdp:(this.sdp=np.parse(this.body||""),this.sdp)}toString(){return this.data}}class gT extends ip{constructor(e){super(),this.ua=e,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(e,t,r,l,s,i){const f=[];let h=this.getHeader("To");if(e=e||null,t=t||null,!e||e<100||e>699)throw new TypeError(`Invalid status_code: ${e}`);if(t&&typeof t!="string"&&!(t instanceof String))throw new TypeError(`Invalid reason_phrase: ${t}`);t=t||Ft.REASON_PHRASE[e]||"",r=yt.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));let d=`SIP/2.0 ${e} ${t}\r
86
- `;if(this.method===Ft.INVITE&&e>100&&e<=200){const v=this.getHeaders("record-route");for(const T of v)d+=`Record-Route: ${T}\r
87
- `}const p=this.getHeaders("via");for(const v of p)d+=`Via: ${v}\r
88
- `;!this.to_tag&&e>100?h+=`;tag=${yt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(h+=`;tag=${this.to_tag}`),d+=`To: ${h}\r
89
- `,d+=`From: ${this.getHeader("From")}\r
90
- `,d+=`Call-ID: ${this.call_id}\r
91
- `,d+=`CSeq: ${this.cseq} ${this.method}\r
92
- `;for(const v of r)d+=`${v.trim()}\r
93
- `;switch(this.method){case Ft.INVITE:this.ua.configuration.session_timers&&f.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&f.push("gruu"),f.push("ice","replaces");break;case Ft.UPDATE:this.ua.configuration.session_timers&&f.push("timer"),l&&f.push("ice"),f.push("replaces")}if(f.push("outbound"),this.method===Ft.OPTIONS?(d+=`Allow: ${Ft.ALLOWED_METHODS}\r
94
- `,d+=`Accept: ${Ft.ACCEPTED_BODY_TYPES}\r
95
- `):e===405?d+=`Allow: ${Ft.ALLOWED_METHODS}\r
96
- `:e===415&&(d+=`Accept: ${Ft.ACCEPTED_BODY_TYPES}\r
97
- `),d+=`Supported: ${f}\r
98
- `,l){const v=yt.str_utf8_length(l);d+=`Content-Type: application/sdp\r
99
- `,d+=`Content-Length: ${v}\r
85
+ `;return t}clone(){const t=new Wa(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){t.headers[n]=this.headers[n].slice()},this),t.body=this.body,t.extraHeaders=it.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}class Hu extends Wa{constructor(t,n,a,o,s){super(St.INVITE,t,n,a,o,s),this.transaction=null}cancel(t){this.transaction.cancel(t)}clone(){const t=new Hu(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(n){t.headers[n]=this.headers[n].slice()},this),t.body=this.body,t.extraHeaders=it.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t.transaction=this.transaction,t}}class hh{constructor(){this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}addHeader(t,n){const a={raw:n};t=it.headerize(t),this.headers[t]?this.headers[t].push(a):this.headers[t]=[a]}getHeader(t){const n=this.headers[it.headerize(t)];if(n){if(n[0])return n[0].raw}else return}getHeaders(t){const n=this.headers[it.headerize(t)],a=[];if(!n)return[];for(const o of n)a.push(o.raw);return a}hasHeader(t){return!!this.headers[it.headerize(t)]}parseHeader(t,n=0){if(t=it.headerize(t),this.headers[t]){if(n>=this.headers[t].length){Lo.debug(`not so many "${t}" headers present`);return}}else{Lo.debug(`header "${t}" not present`);return}const a=this.headers[t][n],o=a.raw;if(a.parsed)return a.parsed;const s=Vm.parse(o,t.replace(/-/g,"_"));if(s===-1){this.headers[t].splice(n,1),Lo.debug(`error parsing "${t}" header field with value "${o}"`);return}else return a.parsed=s,s}s(t,n){return this.parseHeader(t,n)}setHeader(t,n){const a={raw:n};this.headers[it.headerize(t)]=[a]}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fh.parse(this.body||""),this.sdp)}toString(){return this.data}}class Bm extends hh{constructor(t){super(),this.ua=t,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(t,n,a,o,s,r){const d=[];let h=this.getHeader("To");if(t=t||null,n=n||null,!t||t<100||t>699)throw new TypeError(`Invalid status_code: ${t}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||St.REASON_PHRASE[t]||"",a=it.cloneArray(a),this.ua.configuration.extra_headers&&(a=a.concat(this.ua.configuration.extra_headers));let _=`SIP/2.0 ${t} ${n}\r
86
+ `;if(this.method===St.INVITE&&t>100&&t<=200){const T=this.getHeaders("record-route");for(const E of T)_+=`Record-Route: ${E}\r
87
+ `}const g=this.getHeaders("via");for(const T of g)_+=`Via: ${T}\r
88
+ `;!this.to_tag&&t>100?h+=`;tag=${it.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(h+=`;tag=${this.to_tag}`),_+=`To: ${h}\r
89
+ `,_+=`From: ${this.getHeader("From")}\r
90
+ `,_+=`Call-ID: ${this.call_id}\r
91
+ `,_+=`CSeq: ${this.cseq} ${this.method}\r
92
+ `;for(const T of a)_+=`${T.trim()}\r
93
+ `;switch(this.method){case St.INVITE:this.ua.configuration.session_timers&&d.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&d.push("gruu"),d.push("ice","replaces");break;case St.UPDATE:this.ua.configuration.session_timers&&d.push("timer"),o&&d.push("ice"),d.push("replaces")}if(d.push("outbound"),this.method===St.OPTIONS?(_+=`Allow: ${St.ALLOWED_METHODS}\r
94
+ `,_+=`Accept: ${St.ACCEPTED_BODY_TYPES}\r
95
+ `):t===405?_+=`Allow: ${St.ALLOWED_METHODS}\r
96
+ `:t===415&&(_+=`Accept: ${St.ACCEPTED_BODY_TYPES}\r
97
+ `),_+=`Supported: ${d}\r
98
+ `,o){const T=it.str_utf8_length(o);_+=`Content-Type: application/sdp\r
99
+ `,_+=`Content-Length: ${T}\r
100
100
  \r
101
- `,d+=l}else d+=`Content-Length: 0\r
101
+ `,_+=o}else _+=`Content-Length: 0\r
102
102
  \r
103
- `;this.server_transaction.receiveResponse(e,d,s,i)}reply_sl(e=null,t=null){const r=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError(`Invalid status_code: ${e}`);if(t&&typeof t!="string"&&!(t instanceof String))throw new TypeError(`Invalid reason_phrase: ${t}`);t=t||Ft.REASON_PHRASE[e]||"";let l=`SIP/2.0 ${e} ${t}\r
104
- `;for(const i of r)l+=`Via: ${i}\r
105
- `;let s=this.getHeader("To");if(!this.to_tag&&e>100?s+=`;tag=${yt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(s+=`;tag=${this.to_tag}`),l+=`To: ${s}\r
106
- `,l+=`From: ${this.getHeader("From")}\r
107
- `,l+=`Call-ID: ${this.call_id}\r
108
- `,l+=`CSeq: ${this.cseq} ${this.method}\r
109
- `,this.ua.configuration.extra_headers)for(const i of this.ua.configuration.extra_headers)l+=`${i.trim()}\r
110
- `;l+=`Content-Length: 0\r
103
+ `;this.server_transaction.receiveResponse(t,_,s,r)}reply_sl(t=null,n=null){const a=this.getHeaders("via");if(!t||t<100||t>699)throw new TypeError(`Invalid status_code: ${t}`);if(n&&typeof n!="string"&&!(n instanceof String))throw new TypeError(`Invalid reason_phrase: ${n}`);n=n||St.REASON_PHRASE[t]||"";let o=`SIP/2.0 ${t} ${n}\r
104
+ `;for(const r of a)o+=`Via: ${r}\r
105
+ `;let s=this.getHeader("To");if(!this.to_tag&&t>100?s+=`;tag=${it.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(s+=`;tag=${this.to_tag}`),o+=`To: ${s}\r
106
+ `,o+=`From: ${this.getHeader("From")}\r
107
+ `,o+=`Call-ID: ${this.call_id}\r
108
+ `,o+=`CSeq: ${this.cseq} ${this.method}\r
109
+ `,this.ua.configuration.extra_headers)for(const r of this.ua.configuration.extra_headers)o+=`${r.trim()}\r
110
+ `;o+=`Content-Length: 0\r
111
111
  \r
112
- `,this.transport.send(l)}}class pT extends ip{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var $t={OutgoingRequest:bu,InitialOutgoingInviteRequest:kf,IncomingRequest:gT,IncomingResponse:pT};const gr=nt($t),mT=At,Hs=Ht(),_s=new mT("DigestAuthentication");var rp=class{constructor(e){this._credentials=e,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(e){switch(e){case"realm":return this._realm;case"ha1":return this._ha1;default:_s.warn('get() | cannot get "%s" parameter',e);return}}authenticate({method:e,ruri:t,body:r},l,s=null){if(this._algorithm=l.algorithm,this._realm=l.realm,this._nonce=l.nonce,this._opaque=l.opaque,this._stale=l.stale,this._algorithm){if(this._algorithm!=="MD5")return _s.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return _s.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return _s.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return _s.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return _s.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(l.qop)if(l.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(l.qop.indexOf("auth")>-1)this._qop="auth";else return _s.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=e,this._uri=t,this._cnonce=s||Hs.createRandomToken(12),this._nc+=1;const i=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-i.length)+i,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=Hs.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let f,h;return this._qop==="auth"?(f=`${this._method}:${this._uri}`,h=Hs.calculateMD5(f),_s.debug('authenticate() | using qop=auth [a2:"%s"]',f),this._response=Hs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(f=`${this._method}:${this._uri}:${Hs.calculateMD5(r||"")}`,h=Hs.calculateMD5(f),_s.debug('authenticate() | using qop=auth-int [a2:"%s"]',f),this._response=Hs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(f=`${this._method}:${this._uri}`,h=Hs.calculateMD5(f),_s.debug('authenticate() | using qop=null [a2:"%s"]',f),this._response=Hs.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),_s.debug("authenticate() | response generated"),!0}toString(){const e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push(`algorithm=${this._algorithm}`),e.push(`username="${this._credentials.username}"`),e.push(`realm="${this._realm}"`),e.push(`nonce="${this._nonce}"`),e.push(`uri="${this._uri}"`),e.push(`response="${this._response}"`),this._opaque&&e.push(`opaque="${this._opaque}"`),this._qop&&(e.push(`qop=${this._qop}`),e.push(`cnonce="${this._cnonce}"`),e.push(`nc=${this._ncHex}`)),`Digest ${e.join(", ")}`}};const vT=nt(rp),Gs=500,TT=4e3,p_=5e3;var Mf={T1:Gs,T2:TT,T4:p_,TIMER_B:64*Gs,TIMER_D:0*Gs,TIMER_F:64*Gs,TIMER_H:64*Gs,TIMER_I:0*Gs,TIMER_J:0*Gs,TIMER_K:0*p_,TIMER_L:64*Gs,TIMER_M:64*Gs,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Yl=nt(Mf),Da=It.EventEmitter,Na=At,ha=Ue,m_=$t,Ds=Mf,v_=new Na("NonInviteClientTransaction"),vo=new Na("InviteClientTransaction"),yT=new Na("AckClientTransaction"),T_=new Na("NonInviteServerTransaction"),To=new Na("InviteServerTransaction"),Se={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 ST extends Da{constructor(e,t,r,l){super(),this.type=Se.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=e,this.transport=t,this.request=r,this.eventHandlers=l;let s=`SIP/2.0/${t.via_transport}`;s+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return Se}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(Se.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},Ds.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){v_.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){v_.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(e){const t=e.status_code;if(t<200)switch(this.state){case Se.STATUS_TRYING:case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break}else switch(this.state){case Se.STATUS_TRYING:case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_COMPLETED),clearTimeout(this.F),t===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(()=>{this.timer_K()},Ds.TIMER_K);break;case Se.STATUS_COMPLETED:break}}}class ET extends Da{constructor(e,t,r,l){super(),this.type=Se.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=e,this.transport=t,this.request=r,this.eventHandlers=l,r.transaction=this;let s=`SIP/2.0/${t.via_transport}`;s+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return Se}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(Se.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},Ds.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==Se.STATUS_ACCEPTED&&(vo.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){vo.debug(`Timer M expired for transaction ${this.id}`),this.state===Se.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){vo.debug(`Timer B expired for transaction ${this.id}`),this.state===Se.STATUS_CALLING&&(this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){vo.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(e){const t=new m_.OutgoingRequest(ha.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});t.setHeader("from",this.request.getHeader("from")),t.setHeader("via",this.request.getHeader("via")),t.setHeader("to",e.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},Ds.TIMER_D),this.transport.send(t)}cancel(e){if(this.state!==Se.STATUS_PROCEEDING)return;const t=new m_.OutgoingRequest(ha.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});t.setHeader("from",this.request.getHeader("from")),t.setHeader("via",this.request.getHeader("via")),t.setHeader("to",this.request.getHeader("to")),e&&t.setHeader("reason",e),this.transport.send(t)}receiveResponse(e){const t=e.status_code;if(t>=100&&t<=199)switch(this.state){case Se.STATUS_CALLING:this.stateChanged(Se.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case Se.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e);break}else if(t>=200&&t<=299)switch(this.state){case Se.STATUS_CALLING:case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},Ds.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case Se.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e);break}else if(t>=300&&t<=699)switch(this.state){case Se.STATUS_CALLING:case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case Se.STATUS_COMPLETED:this.sendACK(e);break}}}class CT extends Da{constructor(e,t,r,l){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=t,this.request=r,this.eventHandlers=l;let s=`SIP/2.0/${t.via_transport}`;s+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return Se}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){yT.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class AT extends Da{constructor(e,t,r){super(),this.type=Se.NON_INVITE_SERVER,this.id=r.via_branch,this.ua=e,this.transport=t,this.request=r,this.last_response="",r.server_transaction=this,this.state=Se.STATUS_TRYING,e.newTransaction(this)}get C(){return Se}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_J(){T_.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,T_.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(e,t,r,l){if(e===100)switch(this.state){case Se.STATUS_TRYING:this.stateChanged(Se.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case Se.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?r&&r():(this.onTransportError(),l&&l());break}else if(e>=200&&e<=699)switch(this.state){case Se.STATUS_TRYING:case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(()=>{this.timer_J()},Ds.TIMER_J),this.transport.send(t)?r&&r():(this.onTransportError(),l&&l());break;case Se.STATUS_COMPLETED:break}}}class bT extends Da{constructor(e,t,r){super(),this.type=Se.INVITE_SERVER,this.id=r.via_branch,this.ua=e,this.transport=t,this.request=r,this.last_response="",r.server_transaction=this,this.state=Se.STATUS_PROCEEDING,e.newTransaction(this),this.resendProvisionalTimer=null,r.reply(100)}get C(){return Se}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_H(){To.debug(`Timer H expired for transaction ${this.id}`),this.state===Se.STATUS_COMPLETED&&To.debug("ACK not received, dialog will be terminated"),this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){To.debug(`Timer L expired for transaction ${this.id}`),this.state===Se.STATUS_ACCEPTED&&(this.stateChanged(Se.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(Se.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(e,t,r,l){if(e>=100&&e<=199)switch(this.state){case Se.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t;break}if(e>100&&e<=199&&this.state===Se.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},Ds.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case Se.STATUS_PROCEEDING:this.stateChanged(Se.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(()=>{this.timer_L()},Ds.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case Se.STATUS_ACCEPTED:this.transport.send(t)?r&&r():(this.onTransportError(),l&&l());break}else if(e>=300&&e<=699)switch(this.state){case Se.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(Se.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},Ds.TIMER_H),r&&r()):(this.onTransportError(),l&&l());break}}}function RT({_transactions:u},e){let t;switch(e.method){case ha.INVITE:if(t=u.ist[e.via_branch],t){switch(t.state){case Se.STATUS_PROCEEDING:t.transport.send(t.last_response);break;case Se.STATUS_ACCEPTED:break}return!0}break;case ha.ACK:if(t=u.ist[e.via_branch],t){if(t.state===Se.STATUS_ACCEPTED)return!1;if(t.state===Se.STATUS_COMPLETED)return t.state=Se.STATUS_CONFIRMED,t.I=setTimeout(()=>{t.timer_I()},Ds.TIMER_I),!0}else return!1;break;case ha.CANCEL:return t=u.ist[e.via_branch],t?(e.reply_sl(200),t.state!==Se.STATUS_PROCEEDING):(e.reply_sl(481),!0);default:if(t=u.nist[e.via_branch],t){switch(t.state){case Se.STATUS_TRYING:break;case Se.STATUS_PROCEEDING:case Se.STATUS_COMPLETED:t.transport.send(t.last_response);break}return!0}break}}var Sr={C:Se,NonInviteClientTransaction:ST,InviteClientTransaction:ET,AckClientTransaction:CT,NonInviteServerTransaction:AT,InviteServerTransaction:bT,checkTransaction:RT};const cs=nt(Sr),wT=At,y_=Ue,IT=rp,uh=Sr,OT=new wT("RequestSender"),ch={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Er=class{constructor(e,t,r){this._ua=e,this._eventHandlers=r,this._method=t.method,this._request=t,this._auth=null,this._challenged=!1,this._staled=!1;for(const l in ch)Object.prototype.hasOwnProperty.call(ch,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=ch[l]));e.status===e.C.STATUS_USER_CLOSED&&(this._method!==y_.BYE||this._method!==y_.ACK)&&this._eventHandlers.onTransportError()}send(){const e={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:t=>{this._receiveResponse(t)}};switch(this._method){case"INVITE":this.clientTransaction=new uh.InviteClientTransaction(this._ua,this._ua.transport,this._request,e);break;case"ACK":this.clientTransaction=new uh.AckClientTransaction(this._ua,this._ua.transport,this._request,e);break;default:this.clientTransaction=new uh.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,e)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(e){let t,r;const l=e.status_code;if((l===401||l===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(e.status_code===401?(t=e.parseHeader("www-authenticate"),r="authorization"):(t=e.parseHeader("proxy-authenticate"),r="proxy-authorization"),!t){OT.debug(`${e.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(e);return}if(!this._challenged||!this._staled&&t.stale===!0){if(this._auth||(this._auth=new IT({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,t)){this._eventHandlers.onReceiveResponse(e);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),t.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(r,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}else this._eventHandlers.onReceiveResponse(e)}};const pa=nt(Er),DT=At,hh=Ht(),ri=Ue,S_=$t,E_=Er,zl=new DT("Registrator"),yo=10;var NT=class{constructor(e,t){this._reg_id=1,this._ua=e,this._transport=t,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=hh.createRandomToken(22),this._cseq=0,this._to_uri=e.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(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}setExtraContactParams(e){e instanceof Object||(e={}),this._extraContactParams="";for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this._extraContactParams+=`;${t}`,r&&(this._extraContactParams+=`=${r}`)}}register(){if(this._registering){zl.debug("Register request in progress...");return}const e=this._extraHeaders.slice();e.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),e.push(`Expires: ${this._expires}`);const t=new S_.OutgoingRequest(ri.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},e),r=new E_(this._ua,t,{onRequestTimeout:()=>{this._registrationFailure(null,ri.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,ri.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:l=>{if(l.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):{if(this._registering=!1,!l.hasHeader("Contact")){zl.debug("no Contact header in response to REGISTER, response ignored");break}const s=l.headers.Contact.reduce((d,p)=>d.concat(p.parsed),[]);let i=s.find(d=>this._sipInstance===d.getParam("+sip.instance")&&this._reg_id===parseInt(d.getParam("reg-id")));if(i||(i=s.find(d=>d.uri.user===this._ua.contact.uri.user)),!i){zl.debug("no Contact header pointing to us, response ignored");break}let f=i.getParam("expires");!f&&l.hasHeader("expires")&&(f=l.getHeader("expires")),f||(f=this._expires),f=Number(f),f<yo&&(f=yo);const h=f>64?f*1e3/2+Math.floor((f/2-32)*1e3*Math.random()):f*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),i.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=i.getParam("temp-gruu").replace(/"/g,"")),i.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=i.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:l}));break}case/^423$/.test(l.status_code):{l.hasHeader("min-expires")?(this._expires=Number(l.getHeader("min-expires")),this._expires<yo&&(this._expires=yo),this.register()):(zl.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(l,ri.causes.SIP_FAILURE_CODE));break}default:{const s=hh.sipErrorCause(l.status_code);this._registrationFailure(l,s)}}}});this._registering=!0,r.send()}unregister(e={}){if(!this._registered){zl.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const t=this._extraHeaders.slice();e.all?t.push(`Contact: *${this._extraContactParams}`):t.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),t.push("Expires: 0");const r=new S_.OutgoingRequest(ri.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t);new E_(this._ua,r,{onRequestTimeout:()=>{this._unregistered(null,ri.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,ri.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const i=hh.sipErrorCause(s.status_code);this._unregistered(s,i)}}}}).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(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}_unregistered(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}};class PT extends Error{constructor(e,t){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=e,this.value=t,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class xT extends Error{constructor(e){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=e,this.message=`Invalid status: ${e}`}}class kT extends Error{constructor(e){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=e}}class MT extends Error{constructor(e){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=e}}var Js={ConfigurationError:PT,InvalidStateError:xT,NotSupportedError:kT,NotReadyError:MT};const Cn=nt(Js),fh=Ue,So=Sr,UT=Er,dh={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var lp=class{constructor(e,t,r){this._dialog=e,this._ua=e._ua,this._request=t,this._eventHandlers=r,this._reattempt=!1,this._reattemptTimer=null;for(const l in dh)Object.prototype.hasOwnProperty.call(dh,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=dh[l]))}get request(){return this._request}send(){const e=new UT(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:t=>{this._eventHandlers.onAuthenticated(t)},onReceiveResponse:t=>{this._receiveResponse(t)}});if(e.send(),(this._request.method===fh.INVITE||this._request.method===fh.UPDATE&&this._request.body)&&e.clientTransaction.state!==So.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const t=()=>{(e.clientTransaction.state===So.C.STATUS_ACCEPTED||e.clientTransaction.state===So.C.STATUS_COMPLETED||e.clientTransaction.state===So.C.STATUS_TERMINATED)&&(e.clientTransaction.removeListener("stateChanged",t),this._dialog.uac_pending_reply=!1)};e.clientTransaction.on("stateChanged",t)}}_receiveResponse(e){e.status_code===408||e.status_code===481?this._eventHandlers.onDialogError(e):e.method===fh.INVITE&&e.status_code===491?this._reattempt?e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}};const LT=nt(lp),FT=At,C_=$t,mn=Ue,Xl=Sr,$T=lp,_h=Ht(),gh=new FT("Dialog"),vn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var ap=class{static get C(){return vn}constructor(e,t,r,l=vn.STATUS_CONFIRMED){if(this._owner=e,this._ua=e._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!t.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};t instanceof C_.IncomingResponse&&(l=t.status_code<200?vn.STATUS_EARLY:vn.STATUS_CONFIRMED);const s=t.parseHeader("contact");r==="UAS"?(this._id={call_id:t.call_id,local_tag:t.to_tag,remote_tag:t.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._remote_seqnum=t.cseq,this._local_uri=t.parseHeader("to").uri,this._remote_uri=t.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=t.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):r==="UAC"&&(this._id={call_id:t.call_id,local_tag:t.from_tag,remote_tag:t.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._local_seqnum=t.cseq,this._local_uri=t.parseHeader("from").uri,this._remote_uri=t.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=t.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),gh.debug(`new ${r} dialog created with status ${this._state===vn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(e){this._local_seqnum=e}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(e){this._uac_pending_reply=e}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===vn.STATUS_TERMINATED}update(e,t){this._state=vn.STATUS_CONFIRMED,gh.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t==="UAC"&&(this._route_set=e.getHeaders("record-route").reverse())}terminate(){gh.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=vn.STATUS_TERMINATED}sendRequest(e,t={}){const r=_h.cloneArray(t.extraHeaders),l=_h.cloneObject(t.eventHandlers),s=t.body||null,i=this._createRequest(e,r,s);return l.onAuthenticated=()=>{this._local_seqnum+=1},new $T(this,i,l).send(),i}receiveRequest(e){this._checkInDialogRequest(e)&&(e.method===mn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:e.method===mn.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}_createRequest(e,t,r){t=_h.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const l=e===mn.CANCEL||e===mn.ACK?this._local_seqnum:this._local_seqnum+=1;return new C_.OutgoingRequest(e,this._remote_target,this._ua,{cseq:l,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},t,r)}_checkInDialogRequest(e){if(!this._remote_seqnum)this._remote_seqnum=e.cseq;else if(e.cseq<this._remote_seqnum)if(e.method===mn.ACK){if(this._ack_seqnum===null||e.cseq!==this._ack_seqnum)return!1}else return e.reply(500),!1;else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);if(e.method===mn.INVITE||e.method===mn.UPDATE&&e.body){if(this._uac_pending_reply===!0)e.reply(491);else if(this._uas_pending_reply===!0){const t=(Math.random()*10|0)+1;return e.reply(500,null,[`Retry-After:${t}`]),!1}else{this._uas_pending_reply=!0;const t=()=>{(e.server_transaction.state===Xl.C.STATUS_ACCEPTED||e.server_transaction.state===Xl.C.STATUS_COMPLETED||e.server_transaction.state===Xl.C.STATUS_TERMINATED)&&(e.server_transaction.removeListener("stateChanged",t),this._uas_pending_reply=!1)};e.server_transaction.on("stateChanged",t)}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===Xl.C.STATUS_ACCEPTED&&(this._remote_target=e.parseHeader("contact").uri)})}else e.method===mn.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===Xl.C.STATUS_COMPLETED&&(this._remote_target=e.parseHeader("contact").uri)});return!0}};const Eo=nt(ap);var Uf={exports:{}};const HT=It.EventEmitter,GT=At,VT=Ue,BT=Js,A_=Ht(),jT=new GT("RTCSession:DTMF"),op={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Uf.exports=class extends HT{constructor(e){super(),this._session=e,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(e,t={}){if(e===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 BT.InvalidStateError(this._session.status);const r=A_.cloneArray(t.extraHeaders);if(this.eventHandlers=A_.cloneObject(t.eventHandlers),typeof e=="string")e=e.toUpperCase();else if(typeof e=="number")e=e.toString();else throw new TypeError(`Invalid tone: ${e}`);if(e.match(/^[0-9A-DR#*]$/))this._tone=e;else throw new TypeError(`Invalid tone: ${e}`);this._duration=t.duration,r.push("Content-Type: application/dtmf-relay");let l=`Signal=${this._tone}\r
113
- `;l+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(VT.INFO,{extraHeaders:r,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:s})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:l})}init_incoming(e){const t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,r=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=e,e.reply(200),e.body){const l=e.body.split(`
114
- `);l.length>=1&&t.test(l[0])&&(this._tone=l[0].replace(t,"$2")),l.length>=2&&r.test(l[1])&&(this._duration=parseInt(l[1].replace(r,"$2"),10))}this._duration||(this._duration=op.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):jT.debug("invalid INFO DTMF received, discarded")}};Uf.exports.C=op;var up=Uf.exports;const qT=nt(up),WT=It.EventEmitter,KT=Ue,YT=Js,zT=Ht();var cp=class extends WT{constructor(e){super(),this._session=e,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(e,t,r={}){if(this._direction="outgoing",e===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 YT.InvalidStateError(this._session.status);this._contentType=e,this._body=t;const l=zT.cloneArray(r.extraHeaders);l.push(`Content-Type: ${e}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(KT.INFO,{extraHeaders:l,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.emit("failed",{originator:"remote",response:s})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:t})}init_incoming(e){this._direction="incoming",this.request=e,e.reply(200),this._contentType=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,this._body=e.body,this._session.newInfo({originator:"remote",info:this,request:e})}};const af=nt(cp),XT=At,b_=Ue,JT=new XT("RTCSession:ReferNotifier"),ph={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var hp=class{constructor(e,t,r){this._session=e,this._id=t,this._expires=r||ph.expires,this._active=!0,this.notify(100)}notify(e,t){if(JT.debug("notify()"),this._active===!1)return;t=t||b_.REASON_PHRASE[e]||"";let r;e>=200?r="terminated;reason=noresource":r=`active;expires=${this._expires}`,this._session.sendRequest(b_.NOTIFY,{extraHeaders:[`Event: ${ph.event_type};id=${this._id}`,`Subscription-State: ${r}`,`Content-Type: ${ph.body_type}`],body:`SIP/2.0 ${e} ${t}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const QT=nt(hp),ZT=It.EventEmitter,ey=At,Jl=Ue,ty=ys(),R_=Ht(),li=new ey("RTCSession:ReferSubscriber");var fp=class extends ZT{constructor(e){super(),this._id=null,this._session=e}get id(){return this._id}sendRefer(e,t={}){li.debug("sendRefer()");const r=R_.cloneArray(t.extraHeaders),l=R_.cloneObject(t.eventHandlers);for(const h in l)Object.prototype.hasOwnProperty.call(l,h)&&this.on(h,l[h]);let s=null;t.replaces&&(s=t.replaces._request.call_id,s+=`;to-tag=${t.replaces._to_tag}`,s+=`;from-tag=${t.replaces._from_tag}`,s=encodeURIComponent(s));const i=`Refer-To: <${e}${s?`?Replaces=${s}`:""}>`;if(r.push(i),!r.some(h=>h.toLowerCase().startsWith("referred-by:"))){const h=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;r.push(h)}r.push(`Contact: ${this._session.contact}`);const f=this._session.sendRequest(Jl.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:h=>{this._requestSucceeded(h)},onErrorResponse:h=>{this._requestFailed(h,Jl.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,Jl.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,Jl.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,Jl.causes.DIALOG_ERROR)}}});this._id=f.cseq}receiveNotify(e){if(li.debug("receiveNotify()"),!e.body)return;const t=ty.parse(e.body.trim().split(`\r
115
- `,1)[0],"Status_Line");if(t===-1){li.debug(`receiveNotify() | error parsing NOTIFY body: "${e.body}"`);return}switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t});break}}_requestSucceeded(e){li.debug("REFER succeeded"),li.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}_requestFailed(e,t){li.debug("REFER failed"),li.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}};const sy=nt(fp),ny=It.EventEmitter,w_=Qt,iy=At,Te=Ue,ai=Js,I_=Sr,st=Ht(),Ql=Mf,ry=$t,Co=ap,ly=Er,es=up,O_=cp,ay=hp,oy=fp,D_=Xs(),ne=new iy("RTCSession"),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},Ao=["audio","video"];var dp=class of extends ny{static get C(){return ae}constructor(e){ne.debug("new"),super(),this._id=null,this._ua=e,this._status=ae.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:Te.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return ae}get causes(){return Te.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(e){this._data=e}get status(){return this._status}isInProgress(){switch(this._status){case ae.STATUS_NULL:case ae.STATUS_INVITE_SENT:case ae.STATUS_1XX_RECEIVED:case ae.STATUS_INVITE_RECEIVED:case ae.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case ae.STATUS_ANSWERED:case ae.STATUS_WAITING_FOR_ACK:case ae.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case ae.STATUS_CANCELED:case ae.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(e,t={},r){ne.debug("connect()");const l=e,s=st.cloneObject(t.eventHandlers),i=st.cloneArray(t.extraHeaders),f=st.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),h=t.mediaStream||null,d=st.cloneObject(t.pcConfig,{iceServers:[]}),p=t.rtcConstraints||null,v=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=v,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,e===void 0)throw new TypeError("Not enough arguments");if(this._status!==ae.STATUS_NULL)throw new ai.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new ai.NotSupportedError("WebRTC not supported");if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${l}`);this._sessionTimers.enabled&&st.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=Te.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=Te.SESSION_EXPIRES);for(const S in s)Object.prototype.hasOwnProperty.call(s,S)&&this.on(S,s[S]);this._from_tag=st.newTag();const T=t.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:T,outbound:!0}),T?(y.from_display_name="Anonymous",y.from_uri=new D_("sip","anonymous","anonymous.invalid"),i.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),i.push("Privacy: id")):t.fromUserName&&(y.from_uri=new D_("sip",t.fromUserName,this._ua.configuration.uri.host),i.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(y.from_display_name=t.fromDisplayName),i.push(`Contact: ${this._contact}`),i.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&i.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new ry.InitialOutgoingInviteRequest(e,this._ua,y,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(d,p),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(f,v,h)}init_incoming(e,t){ne.debug("init_incoming()");let r;const l=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;if(e.body&&l!=="application/sdp"){e.reply(415);return}if(this._status=ae.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(r=e.getHeader("expires")*1e3),e.to_tag=st.newTag(),!this._createDialog(e,"UAS",!0)){e.reply(500,"Missing Contact header field");return}e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=ae.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{e.reply(408),this._failed("local",null,Te.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),r&&(this._timers.expiresTimer=setTimeout(()=>{this._status===ae.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),this._failed("system",null,Te.causes.EXPIRES))},r)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==ae.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(e={}){ne.debug("answer()");const t=this._request,r=st.cloneArray(e.extraHeaders),l=st.cloneObject(e.mediaConstraints),s=e.mediaStream||null,i=st.cloneObject(e.pcConfig,{iceServers:[]}),f=e.rtcConstraints||null,h=e.rtcAnswerConstraints||null,d=st.cloneObject(e.rtcOfferConstraints);let p,v=!1,T=!1,y=!1,S=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=e.rtcOfferConstraints||null,this._data=e.data||this._data,this._direction!=="incoming")throw new ai.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==ae.STATUS_WAITING_FOR_ANSWER)throw new ai.InvalidStateError(this._status);if(this._sessionTimers.enabled&&st.isDecimal(e.sessionTimersExpires)&&(e.sessionTimersExpires>=Te.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=e.sessionTimersExpires:this._sessionTimers.defaultExpires=Te.SESSION_EXPIRES),this._status=ae.STATUS_ANSWERED,!this._createDialog(t,"UAS")){t.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),r.unshift(`Contact: ${this._contact}`);const A=t.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const R of A.media)R.type==="audio"&&(v=!0,(!R.direction||R.direction==="sendrecv")&&(y=!0)),R.type==="video"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(S=!0));if(s&&l.audio===!1){p=s.getAudioTracks();for(const R of p)s.removeTrack(R)}if(s&&l.video===!1){p=s.getVideoTracks();for(const R of p)s.removeTrack(R)}!s&&l.audio===void 0&&(l.audio=y),!s&&l.video===void 0&&(l.video=S),!s&&!v&&!d.offerToReceiveAudio&&(l.audio=!1),!s&&!T&&!d.offerToReceiveVideo&&(l.video=!1),this._createRTCConnection(i,f),Promise.resolve().then(()=>{if(s)return s;if(l.audio||l.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(l).catch(R=>{throw this._status===ae.STATUS_TERMINATED?new Error("terminated"):(t.reply(480),this._failed("local",null,Te.causes.USER_DENIED_MEDIA_ACCESS),ne.warn('emit "getusermediafailed" [error:%o]',R),this.emit("getusermediafailed",R),new Error("getUserMedia() failed"))})}).then(R=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(O=>{this._connection.addTrack(O,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:t.body};ne.debug('emit "sdp"'),this.emit("sdp",R);const O=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(O)).catch(N=>{throw t.reply(488),this._failed("system",null,Te.causes.WEBRTC_ERROR),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',N),this.emit("peerconnection:setremotedescriptionfailed",N),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(t),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw t.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw t.reply(500),new Error("_createLocalDescription() failed")})}).then(R=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(t,r),t.reply(200,null,r,R,()=>{this._status=ae.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,Te.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==ae.STATUS_TERMINATED&&ne.warn(R)})}terminate(e={}){ne.debug("terminate()");const t=e.cause||Te.causes.BYE,r=st.cloneArray(e.extraHeaders),l=e.body;let s,i=e.status_code,f=e.reason_phrase;if(this._status===ae.STATUS_TERMINATED)throw new ai.InvalidStateError(this._status);switch(this._status){case ae.STATUS_NULL:case ae.STATUS_INVITE_SENT:case ae.STATUS_1XX_RECEIVED:if(ne.debug("canceling session"),i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);i&&(f=f||Te.REASON_PHRASE[i]||"",s=`SIP ;cause=${i} ;text="${f}"`),this._status===ae.STATUS_NULL||this._status===ae.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===ae.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=ae.STATUS_CANCELED,this._failed("local",null,Te.causes.CANCELED);break;case ae.STATUS_WAITING_FOR_ANSWER:case ae.STATUS_ANSWERED:if(ne.debug("rejecting session"),i=i||480,i<300||i>=700)throw new TypeError(`Invalid status_code: ${i}`);this._request.reply(i,f,r,l),this._failed("local",null,Te.causes.REJECTED);break;case ae.STATUS_WAITING_FOR_ACK:case ae.STATUS_CONFIRMED:if(ne.debug("terminating session"),f=e.reason_phrase||Te.REASON_PHRASE[i]||"",i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);if(i&&r.push(`Reason: SIP ;cause=${i}; text="${f}"`),this._status===ae.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==I_.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:d})=>{d===Te.ACK&&(this.sendRequest(Te.BYE,{extraHeaders:r,body:l}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===I_.C.STATUS_TERMINATED&&(this.sendRequest(Te.BYE,{extraHeaders:r,body:l}),h.terminate())}),this._ended("local",null,t),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(Te.BYE,{extraHeaders:r,body:l}),this._ended("local",null,t)}}sendDTMF(e,t={}){ne.debug("sendDTMF() | tones: %s",e);let r=0,l=t.duration||null,s=t.interToneGap||null;const i=t.transportType||Te.DTMF_TRANSPORT.INFO;if(e===void 0)throw new TypeError("Not enough arguments");if(this._status!==ae.STATUS_CONFIRMED&&this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_1XX_RECEIVED)throw new ai.InvalidStateError(this._status);if(i!==Te.DTMF_TRANSPORT.INFO&&i!==Te.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${i}`);if(typeof e=="number"&&(e=e.toString()),!e||typeof e!="string"||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${e}`);if(l&&!st.isDecimal(l))throw new TypeError(`Invalid tone duration: ${l}`);if(l?l<es.C.MIN_DURATION?(ne.debug(`"duration" value is lower than the minimum allowed, setting it to ${es.C.MIN_DURATION} milliseconds`),l=es.C.MIN_DURATION):l>es.C.MAX_DURATION?(ne.debug(`"duration" value is greater than the maximum allowed, setting it to ${es.C.MAX_DURATION} milliseconds`),l=es.C.MAX_DURATION):l=Math.abs(l):l=es.C.DEFAULT_DURATION,t.duration=l,s&&!st.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<es.C.MIN_INTER_TONE_GAP?(ne.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${es.C.MIN_INTER_TONE_GAP} milliseconds`),s=es.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=es.C.DEFAULT_INTER_TONE_GAP,i===Te.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(e=h.toneBuffer+e,h.insertDTMF(e,l,s));return}if(this._tones){this._tones+=e;return}this._tones=e,f.call(this);function f(){let h;if(this._status===ae.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}const d=this._tones[r];if(r+=1,d===",")h=2e3;else{const p=new es(this);t.eventHandlers={onFailed:()=>{this._tones=null}},p.send(d,t),h=l+s}setTimeout(f.bind(this),h)}}sendInfo(e,t,r={}){if(ne.debug("sendInfo()"),this._status!==ae.STATUS_CONFIRMED&&this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_1XX_RECEIVED)throw new ai.InvalidStateError(this._status);new O_(this).send(e,t,r)}mute(e={audio:!0,video:!1}){ne.debug("mute()");let t=!1,r=!1;this._audioMuted===!1&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&e.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(t===!0||r===!0)&&this._onmute({audio:t,video:r})}unmute(e={audio:!0,video:!0}){ne.debug("unmute()");let t=!1,r=!1;this._audioMuted===!0&&e.audio&&(t=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&e.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(t===!0||r===!0)&&this._onunmute({audio:t,video:r})}hold(e={},t){if(ne.debug("hold()"),this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const r={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Te.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:e.extraHeaders}),!0}unhold(e={},t){if(ne.debug("unhold()"),this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const r={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Te.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:e.extraHeaders}),!0}renegotiate(e={},t){ne.debug("renegotiate()");const r=e.rtcOfferConstraints||null;if(this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const l={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Te.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,rtcOfferConstraints:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:l,rtcOfferConstraints:r,extraHeaders:e.extraHeaders}),!0}refer(e,t){ne.debug("refer()");const r=e;if(this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED)return!1;if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${r}`);const l=new oy(this);l.sendRefer(e,t);const s=l.id;return this._referSubscribers[s]=l,l.on("requestFailed",()=>{delete this._referSubscribers[s]}),l.on("accepted",()=>{delete this._referSubscribers[s]}),l.on("failed",()=>{delete this._referSubscribers[s]}),l}sendRequest(e,t){return ne.debug("sendRequest()"),this._dialog.sendRequest(e,t)}receiveRequest(e){if(ne.debug("receiveRequest()"),e.method===Te.CANCEL)(this._status===ae.STATUS_WAITING_FOR_ANSWER||this._status===ae.STATUS_ANSWERED)&&(this._status=ae.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,Te.causes.CANCELED));else switch(e.method){case Te.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(!e.body){this.terminate({cause:Te.causes.MISSING_SDP,status_code:400});break}const t={originator:"remote",type:"answer",sdp:e.body};ne.debug('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>{this._is_confirmed||this._confirmed("remote",e)}).catch(l=>{this.terminate({cause:Te.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)})}else this._is_confirmed||this._confirmed("remote",e);break;case Te.BYE:this._status===ae.STATUS_CONFIRMED||this._status===ae.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,Te.causes.BYE)):this._status===ae.STATUS_INVITE_RECEIVED||this._status===ae.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,Te.causes.BYE)):e.reply(403,"Wrong Status");break;case Te.INVITE:this._status===ae.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case Te.INFO:if(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){const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;t&&t.match(/^application\/dtmf-relay/i)?new es(this).init_incoming(e):t!==void 0?new O_(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case Te.UPDATE:this._status===ae.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case Te.REFER:this._status===ae.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case Te.NOTIFY:this._status===ae.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}onTransportError(){ne.warn("onTransportError()"),this._status!==ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Te.causes.CONNECTION_ERROR,cause:Te.causes.CONNECTION_ERROR})}onRequestTimeout(){ne.warn("onRequestTimeout()"),this._status!==ae.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:Te.causes.REQUEST_TIMEOUT,cause:Te.causes.REQUEST_TIMEOUT})}onDialogError(){ne.warn("onDialogError()"),this._status!==ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Te.causes.DIALOG_ERROR,cause:Te.causes.DIALOG_ERROR})}newDTMF(e){ne.debug("newDTMF()"),this.emit("newDTMF",e)}newInfo(e){ne.debug("newInfo()"),this.emit("newInfo",e)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(ne.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(ne.debug("_isReadyToReOffer() | session not established yet"),!1):(ne.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(ne.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(ne.debug("close() | closing local MediaStream"),st.closeMediaStream(this._localMediaStream)),this._status!==ae.STATUS_TERMINATED){if(this._status=ae.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){ne.warn("close() | error closing the RTCPeerConnection: %o",e)}for(const e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const e in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,e)&&(this._earlyDialogs[e].terminate(),delete this._earlyDialogs[e]);for(const e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(e,t){let r=Ql.T1;function l(){this._status===ae.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),r<Ql.T2&&(r=r*2,r>Ql.T2&&(r=Ql.T2)),this._timers.invite2xxTimer=setTimeout(l.bind(this),r))}this._timers.invite2xxTimer=setTimeout(l.bind(this),r)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===ae.STATUS_WAITING_FOR_ACK&&(ne.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(Te.BYE),this._ended("remote",null,Te.causes.NO_ACK))},Ql.TIMER_H)}_createRTCConnection(e,t){this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:Te.causes.RTP_TIMEOUT,status_code:408,reason_phrase:Te.causes.RTP_TIMEOUT})}),ne.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(e,t){if(ne.debug("createLocalDescription()"),e!=="offer"&&e!=="answer")throw new Error(`createLocalDescription() | invalid type "${e}"`);const r=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>e==="offer"?r.createOffer(t).catch(l=>(ne.warn('emit "peerconnection:createofferfailed" [error:%o]',l),this.emit("peerconnection:createofferfailed",l),Promise.reject(l))):r.createAnswer(t).catch(l=>(ne.warn('emit "peerconnection:createanswerfailed" [error:%o]',l),this.emit("peerconnection:createanswerfailed",l),Promise.reject(l)))).then(l=>r.setLocalDescription(l).catch(s=>(this._rtcReady=!0,ne.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const l=t&&t.iceRestart;if(r.iceGatheringState==="complete"&&!l||r.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:e,sdp:r.localDescription.sdp};return ne.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let i=!1,f,h;this._iceReady=!1;const d=()=>{r.removeEventListener("icecandidate",f),r.removeEventListener("icegatheringstatechange",h),i=!0,this._rtcReady=!0,this._iceReady=!0;const p={originator:"local",type:e,sdp:r.localDescription.sdp};ne.debug('emit "sdp"'),this.emit("sdp",p),s(p.sdp)};r.addEventListener("icecandidate",f=p=>{const v=p.candidate;v?this.emit("icecandidate",{candidate:v,ready:d}):i||d()}),r.addEventListener("icegatheringstatechange",h=()=>{r.iceGatheringState==="complete"&&!i&&d()})})})}_createDialog(e,t,r){const l=t==="UAS"?e.to_tag:e.from_tag,s=t==="UAS"?e.from_tag:e.to_tag,i=e.call_id+l+s;let f=this._earlyDialogs[i];if(r)return f?!0:(f=new Co(this,e,t,Co.C.STATUS_EARLY),f.error?(ne.debug(f.error),this._failed("remote",e,Te.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=f,!0));{if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,f)return f.update(e,t),this._dialog=f,delete this._earlyDialogs[i],!0;const h=new Co(this,e,t);return h.error?(ne.debug(h.error),this._failed("remote",e,Te.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(e){ne.debug("receiveReinvite()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:s.bind(this)};let l=!1;function s(f={}){l=!0;const h=f.status_code||403,d=f.reason_phrase||"",p=st.cloneArray(f.extraHeaders);if(this._status!==ae.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);e.reply(h,d,p)}if(this.emit("reinvite",r),l)return;if(this._late_sdp=!1,!e.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(f=>{i.call(this,f)}).catch(()=>{e.reply(500)});return}if(t!=="application/sdp"){ne.debug("invalid Content-Type"),e.reply(415);return}this._processInDialogSdpOffer(e).then(f=>{this._status!==ae.STATUS_TERMINATED&&i.call(this,f)}).catch(f=>{ne.warn(f)});function i(f){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,h),this._late_sdp&&(f=this._mangleOffer(f)),e.reply(200,null,h,f,()=>{this._status=ae.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(e,f),this._setACKTimer()}),typeof r.callback=="function"&&r.callback()}}_receiveUpdate(e){ne.debug("receiveUpdate()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:s.bind(this)};let l=!1;function s(f={}){l=!0;const h=f.status_code||403,d=f.reason_phrase||"",p=st.cloneArray(f.extraHeaders);if(this._status!==ae.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);e.reply(h,d,p)}if(this.emit("update",r),l)return;if(!e.body){i.call(this,null);return}if(t!=="application/sdp"){ne.debug("invalid Content-Type"),e.reply(415);return}this._processInDialogSdpOffer(e).then(f=>{this._status!==ae.STATUS_TERMINATED&&i.call(this,f)}).catch(f=>{ne.warn(f)});function i(f){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,h),e.reply(200,null,h,f),typeof r.callback=="function"&&r.callback()}}_processInDialogSdpOffer(e){ne.debug("_processInDialogSdpOffer()");const t=e.parseSDP();let r=!1;for(const i of t.media){if(Ao.indexOf(i.type)===-1)continue;const f=i.direction||t.direction||"sendrecv";if(f==="sendonly"||f==="inactive")r=!0;else{r=!1;break}}const l={originator:"remote",type:"offer",sdp:e.body};ne.debug('emit "sdp"'),this.emit("sdp",l);const s=new RTCSessionDescription({type:"offer",sdp:l.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(i=>{throw e.reply(488),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',i),this.emit("peerconnection:setremotedescriptionfailed",i),i})}).then(()=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&r===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&r===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(i=>{throw e.reply(500),ne.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',i),i})}).catch(i=>{ne.warn("_processInDialogSdpOffer() failed [error: %o]",i)}),this._connectionPromiseQueue}_receiveRefer(e){if(ne.debug("receiveRefer()"),!e.refer_to){ne.debug("no Refer-To header field present in REFER"),e.reply(400);return}if(e.refer_to.uri.scheme!==Te.SIP){ne.debug("Refer-To header field points to a non-SIP URI scheme"),e.reply(416);return}e.reply(202);const t=new ay(this,e.cseq);ne.debug('emit "refer"'),this.emit("refer",{request:e,accept:(s,i)=>{r.call(this,s,i)},reject:()=>{l.call(this)}});function r(s,i={}){if(s=typeof s=="function"?s:null,this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED)return!1;const f=new of(this._ua);if(f.on("progress",({response:h})=>{t.notify(h.status_code,h.reason_phrase)}),f.on("accepted",({response:h})=>{t.notify(h.status_code,h.reason_phrase)}),f.on("_failed",({message:h,cause:d})=>{h?t.notify(h.status_code,h.reason_phrase):t.notify(487,d)}),e.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));i.extraHeaders=st.cloneArray(i.extraHeaders),i.extraHeaders.push(`Replaces: ${h}`)}f.connect(e.refer_to.uri.toAor(),i,s)}function l(){t.notify(603)}}_receiveNotify(e){switch(ne.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":{let t,r;if(e.event.params&&e.event.params.id)t=e.event.params.id,r=this._referSubscribers[t];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{e.reply(400,"Missing event id parameter");return}if(!r){e.reply(481,"Subscription does not exist");return}r.receiveNotify(e),e.reply(200);break}default:e.reply(489)}}_receiveReplaces(e){ne.debug("receiveReplaces()");function t(l){if(this._status!==ae.STATUS_WAITING_FOR_ACK&&this._status!==ae.STATUS_CONFIRMED)return!1;const s=new of(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(e,l)}function r(){ne.debug("Replaced INVITE rejected by the user"),e.reply(486)}this.emit("replaces",{request:e,accept:l=>{t.call(this,l)},reject:()=>{r.call(this)}})}_sendInitialRequest(e,t,r){const l=new ly(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(r)return r;if(e.audio||e.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(s=>{throw this._status===ae.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,Te.causes.USER_DENIED_MEDIA_ACCESS),ne.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===ae.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(i=>{this._connection.addTrack(i,s)}),this._connecting(this._request),this._createLocalDescription("offer",t).catch(i=>{throw this._failed("local",null,Te.causes.WEBRTC_ERROR),i})}).then(s=>{if(this._is_canceled||this._status===ae.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=ae.STATUS_INVITE_SENT,ne.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),l.send()}).catch(s=>{this._status!==ae.STATUS_TERMINATED&&ne.warn(s)})}_getDTMFRTPSender(){const e=this._connection.getSenders().find(t=>t.track&&t.track.kind==="audio");if(!(e&&e.dtmf)){ne.warn("sendDTMF() | no local audio track to send DTMF with");return}return e.dtmf}_receiveInviteResponse(e){if(ne.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299)if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag){this.sendRequest(Te.ACK);return}else{const t=new Co(this,e,"UAC");if(t.error!==void 0){ne.debug(t.error);return}this.sendRequest(Te.ACK),this.sendRequest(Te.BYE);return}if(this._is_canceled){e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);return}if(!(this._status!==ae.STATUS_INVITE_SENT&&this._status!==ae.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(e.status_code):this._status=ae.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):{if(!e.to_tag){ne.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=ae.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}const t={originator:"remote",type:"answer",sdp:e.body};ne.debug('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>this._progress("remote",e)).catch(l=>{ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)});break}case/^2[0-9]{2}$/.test(e.status_code):{if(this._status=ae.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,Te.causes.MISSING_SDP),this._failed("remote",e,Te.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;const t={originator:"remote",type:"answer",sdp:e.body};ne.debug('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(l=>this._connection.setLocalDescription(l)).catch(l=>{this._acceptAndTerminate(e,500,l.toString()),this._failed("local",e,Te.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(r).then(()=>{this._handleSessionTimersInIncomingResponse(e),this._accepted("remote",e),this.sendRequest(Te.ACK),this._confirmed("local",null)}).catch(l=>{this._acceptAndTerminate(e,488,"Not Acceptable Here"),this._failed("remote",e,Te.causes.BAD_MEDIA_DESCRIPTION),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)})});break}default:{const t=st.sipErrorCause(e.status_code);this._failed("remote",e,t)}}}_sendReinvite(e={}){ne.debug("sendReinvite()");const t=st.cloneArray(e.extraHeaders),r=st.cloneObject(e.eventHandlers),l=e.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;t.push(`Contact: ${this._contact}`),t.push("Content-Type: application/sdp"),this._sessionTimers.running&&t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",l)).then(h=>{h=this._mangleOffer(h);const d={originator:"local",type:"offer",sdp:h};ne.debug('emit "sdp"'),this.emit("sdp",d),this.sendRequest(Te.INVITE,{extraHeaders:t,body:h,eventHandlers:{onSuccessResponse:p=>{i.call(this,p),s=!0},onErrorResponse:p=>{f.call(this,p)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{f()});function i(h){if(this._status===ae.STATUS_TERMINATED||(this.sendRequest(Te.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){f.call(this);return}}else{f.call(this);return}const d={originator:"remote",type:"answer",sdp:h.body};ne.debug('emit "sdp"'),this.emit("sdp",d);const p=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(p)).then(()=>{r.succeeded&&r.succeeded(h)}).catch(v=>{f.call(this),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',v),this.emit("peerconnection:setremotedescriptionfailed",v)})}function f(h){r.failed&&r.failed(h)}}_sendUpdate(e={}){ne.debug("sendUpdate()");const t=st.cloneArray(e.extraHeaders),r=st.cloneObject(e.eventHandlers),l=e.rtcOfferConstraints||this._rtcOfferConstraints||null,s=e.sdpOffer||!1;let i=!1;t.push(`Contact: ${this._contact}`),this._sessionTimers.running&&t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(t.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",l)).then(d=>{d=this._mangleOffer(d);const p={originator:"local",type:"offer",sdp:d};ne.debug('emit "sdp"'),this.emit("sdp",p),this.sendRequest(Te.UPDATE,{extraHeaders:t,body:d,eventHandlers:{onSuccessResponse:v=>{f.call(this,v),i=!0},onErrorResponse:v=>{h.call(this,v)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(Te.UPDATE,{extraHeaders:t,eventHandlers:{onSuccessResponse:d=>{f.call(this,d)},onErrorResponse:d=>{h.call(this,d)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function f(d){if(this._status!==ae.STATUS_TERMINATED&&!i)if(this._handleSessionTimersInIncomingResponse(d),s){if(d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const p={originator:"remote",type:"answer",sdp:d.body};ne.debug('emit "sdp"'),this.emit("sdp",p);const v=new RTCSessionDescription({type:"answer",sdp:p.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(v)).then(()=>{r.succeeded&&r.succeeded(d)}).catch(T=>{h.call(this),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}else r.succeeded&&r.succeeded(d)}function h(d){r.failed&&r.failed(d)}}_acceptAndTerminate(e,t,r){ne.debug("acceptAndTerminate()");const l=[];t&&(r=r||Te.REASON_PHRASE[t]||"",l.push(`Reason: SIP ;cause=${t}; text="${r}"`)),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(Te.ACK),this.sendRequest(Te.BYE,{extraHeaders:l})),this._status=ae.STATUS_TERMINATED}_mangleOffer(e){if(!this._localHold&&!this._remoteHold)return e;if(e=w_.parse(e),this._localHold&&!this._remoteHold){ne.debug("mangleOffer() | me on hold, mangling offer");for(const t of e.media)Ao.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="sendonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="sendonly")}else if(this._localHold&&this._remoteHold){ne.debug("mangleOffer() | both on hold, mangling offer");for(const t of e.media)Ao.indexOf(t.type)!==-1&&(t.direction="inactive")}else if(this._remoteHold){ne.debug("mangleOffer() | remote on hold, mangling offer");for(const t of e.media)Ao.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="recvonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="recvonly")}return w_.write(e)}_setLocalMediaStatus(){let e=!0,t=!0;(this._localHold||this._remoteHold)&&(e=!1,t=!1),this._audioMuted&&(e=!1),this._videoMuted&&(t=!1),this._toggleMuteAudio(!e),this._toggleMuteVideo(!t)}_handleSessionTimersInIncomingRequest(e,t){if(!this._sessionTimers.enabled)return;let r;e.session_expires&&e.session_expires>=Te.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,r=e.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${r}`),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(e){if(!this._sessionTimers.enabled)return;let t;e.session_expires&&e.session_expires>=Te.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher=t==="uac",this._runSessionTimer()}_runSessionTimer(){const e=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==ae.STATUS_TERMINATED&&this._isReadyToReOffer()&&(ne.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===Te.UPDATE?this._sendUpdate():this._sendReinvite())},e*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==ae.STATUS_TERMINATED&&(ne.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:Te.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},e*1100)}_toggleMuteAudio(e){const t=this._connection.getSenders().filter(r=>r.track&&r.track.kind==="audio");for(const r of t)r.track.enabled=!e}_toggleMuteVideo(e){const t=this._connection.getSenders().filter(r=>r.track&&r.track.kind==="video");for(const r of t)r.track.enabled=!e}_newRTCSession(e,t){ne.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}_connecting(e){ne.debug("session connecting"),ne.debug('emit "connecting"'),this.emit("connecting",{request:e})}_progress(e,t){ne.debug("session progress"),ne.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}_accepted(e,t){ne.debug("session accepted"),this._start_time=new Date,ne.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}_confirmed(e,t){ne.debug("session confirmed"),this._is_confirmed=!0,ne.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}_ended(e,t,r){ne.debug("session ended"),this._end_time=new Date,this._close(),ne.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:r})}_failed(e,t,r){ne.debug("session failed"),ne.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:r}),this._close(),ne.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:r})}_onhold(e){ne.debug("session onhold"),this._setLocalMediaStatus(),ne.debug('emit "hold"'),this.emit("hold",{originator:e})}_onunhold(e){ne.debug("session onunhold"),this._setLocalMediaStatus(),ne.debug('emit "unhold"'),this.emit("unhold",{originator:e})}_onmute({audio:e,video:t}){ne.debug("session onmute"),this._setLocalMediaStatus(),ne.debug('emit "muted"'),this.emit("muted",{audio:e,video:t})}_onunmute({audio:e,video:t}){ne.debug("session onunmute"),this._setLocalMediaStatus(),ne.debug('emit "unmuted"'),this.emit("unmuted",{audio:e,video:t})}};const uy=nt(dp),cy=It.EventEmitter,hy=At,mh=Ue,fy=$t,Zl=Ht(),dy=Er,N_=Js,_y=Xs(),bo=new hy("Message");var gy=class extends cy{constructor(e){super(),this._ua=e,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(e,t,r={}){const l=e;if(e===void 0||t===void 0)throw new TypeError("Not enough arguments");if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${l}`);const s=Zl.cloneArray(r.extraHeaders),i=Zl.cloneObject(r.eventHandlers),f=r.contentType||"text/plain",h={};r.fromUserName&&(h.from_uri=new _y("sip",r.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),r.fromDisplayName&&(h.from_display_name=r.fromDisplayName);for(const p in i)Object.prototype.hasOwnProperty.call(i,p)&&this.on(p,i[p]);s.push(`Content-Type: ${f}`),this._request=new fy.OutgoingRequest(mh.MESSAGE,e,this._ua,h,s),t&&(this._request.body=t);const d=new dy(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:p=>{this._receiveResponse(p)}});this._newMessage("local",this._request),d.send()}init_incoming(e){this._request=e,this._newMessage("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}accept(e={}){const t=Zl.cloneArray(e.extraHeaders),r=e.body;if(this._direction!=="incoming")throw new N_.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,t,r)}reject(e={}){const t=e.status_code||480,r=e.reason_phrase,l=Zl.cloneArray(e.extraHeaders),s=e.body;if(this._direction!=="incoming")throw new N_.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,r,l,s)}_receiveResponse(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:{const t=Zl.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,mh.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,mh.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(e,t){e==="remote"?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):e==="local"&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}_failed(e,t,r){bo.debug("MESSAGE failed"),this._close(),bo.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:r})}_succeeded(e,t){bo.debug("MESSAGE succeeded"),this._close(),bo.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}};const py=It.EventEmitter,my=At,vh=Ue,vy=$t,ea=Ht(),Ty=Er,P_=Js,Ro=new my("Options");var yy=class extends py{constructor(e){super(),this._ua=e,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(e,t,r={}){const l=e;if(e===void 0)throw new TypeError("A target is required for OPTIONS");if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${l}`);const s=ea.cloneArray(r.extraHeaders),i=ea.cloneObject(r.eventHandlers),f=r.contentType||"application/sdp";for(const d in i)Object.prototype.hasOwnProperty.call(i,d)&&this.on(d,i[d]);s.push(`Content-Type: ${f}`),this._request=new vy.OutgoingRequest(vh.OPTIONS,e,this._ua,null,s),t&&(this._request.body=t);const h=new Ty(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:d=>{this._receiveResponse(d)}});this._newOptions("local",this._request),h.send()}init_incoming(e){this._request=e,this._newOptions("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}accept(e={}){const t=ea.cloneArray(e.extraHeaders),r=e.body;if(this._direction!=="incoming")throw new P_.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,r)}reject(e={}){const t=e.status_code||480,r=e.reason_phrase,l=ea.cloneArray(e.extraHeaders),s=e.body;if(this._direction!=="incoming")throw new P_.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,r,l,s)}_receiveResponse(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:{const t=ea.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,vh.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,vh.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(e,t){e==="remote"?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):e==="local"&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}_failed(e,t,r){Ro.debug("OPTIONS failed"),this._close(),Ro.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:r})}_succeeded(e,t){Ro.debug("OPTIONS succeeded"),this._close(),Ro.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},Lf={};const Sy=At,Th=Ht(),Ey=ys(),ta=new Sy("Socket");Lf.isSocket=u=>{if(Array.isArray(u))return!1;if(typeof u>"u")return ta.warn("undefined JsSIP.Socket instance"),!1;try{if(!Th.isString(u.url))throw ta.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Th.isString(u.via_transport))throw ta.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Ey.parse(u.sip_uri,"SIP_URI")===-1)throw ta.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(e=>{if(!Th.isFunction(u[e]))throw ta.warn(`missing or invalid JsSIP.Socket method: ${e}`),new Error(`Missing or invalid JsSIP.Socket method: ${e}`)})}catch{return!1}return!0};const Cy=At,Ay=Lf,x_=Ue,Xt=new Cy("Transport"),as={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:x_.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:x_.CONNECTION_RECOVERY_MAX_INTERVAL}};var _p=class{constructor(e,t=as.recovery_options){Xt.debug("new()"),this.status=as.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=t,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(r){Xt.warn(`cannot use TextDecoder: ${r}`)}if(typeof e>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");e instanceof Array||(e=[e]),e.forEach(function(r){if(!Ay.isSocket(r.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(r.weight&&!Number(r.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:r.socket,weight:r.weight||0,status:as.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(Xt.debug("connect()"),this.isConnected()){Xt.debug("Transport is already connected");return}else if(this.isConnecting()){Xt.debug("Transport is connecting");return}this.close_requested=!1,this.status=as.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){Xt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=as.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(e){if(Xt.debug("send()"),!this.isConnected())return Xt.warn("unable to send message, transport is not connected"),!1;const t=e.toString();return Xt.debug(`sending message:
112
+ `,this.transport.send(o)}}class Gm extends hh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var yt={OutgoingRequest:Wa,InitialOutgoingInviteRequest:Hu,IncomingRequest:Bm,IncomingResponse:Gm};const pr=ze(yt),Wm=ut,ps=At(),Jt=new Wm("DigestAuthentication");var dh=class{constructor(t){this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}get(t){switch(t){case"realm":return this._realm;case"ha1":return this._ha1;default:Jt.warn('get() | cannot get "%s" parameter',t);return}}authenticate({method:t,ruri:n,body:a},o,s=null){if(this._algorithm=o.algorithm,this._realm=o.realm,this._nonce=o.nonce,this._opaque=o.opaque,this._stale=o.stale,this._algorithm){if(this._algorithm!=="MD5")return Jt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Jt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Jt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Jt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Jt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(o.qop)if(o.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(o.qop.indexOf("auth")>-1)this._qop="auth";else return Jt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=t,this._uri=n,this._cnonce=s||ps.createRandomToken(12),this._nc+=1;const r=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-r.length)+r,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ps.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,h;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${ps.calculateMD5(a||"")}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),Jt.debug("authenticate() | response generated"),!0}toString(){const t=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return t.push(`algorithm=${this._algorithm}`),t.push(`username="${this._credentials.username}"`),t.push(`realm="${this._realm}"`),t.push(`nonce="${this._nonce}"`),t.push(`uri="${this._uri}"`),t.push(`response="${this._response}"`),this._opaque&&t.push(`opaque="${this._opaque}"`),this._qop&&(t.push(`qop=${this._qop}`),t.push(`cnonce="${this._cnonce}"`),t.push(`nc=${this._ncHex}`)),`Digest ${t.join(", ")}`}};const Km=ze(dh),ms=500,Ym=4e3,lf=5e3;var Fu={T1:ms,T2:Ym,T4:lf,TIMER_B:64*ms,TIMER_D:0*ms,TIMER_F:64*ms,TIMER_H:64*ms,TIMER_I:0*ms,TIMER_J:0*ms,TIMER_K:0*lf,TIMER_L:64*ms,TIMER_M:64*ms,PROVISIONAL_RESPONSE_INTERVAL:6e4};const $i=ze(Fu),_l=ft.EventEmitter,pl=ut,Xi=De,af=yt,as=Fu,of=new pl("NonInviteClientTransaction"),zl=new pl("InviteClientTransaction"),Jm=new pl("AckClientTransaction"),uf=new pl("NonInviteServerTransaction"),Xl=new pl("InviteServerTransaction"),de={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"};class zm extends _l{constructor(t,n,a,o){super(),this.type=de.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},as.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){of.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){of.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},as.TIMER_K);break;case de.STATUS_COMPLETED:break}}}class Xm extends _l{constructor(t,n,a,o){super(),this.type=de.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o,a.transaction=this;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},as.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==de.STATUS_ACCEPTED&&(zl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){zl.debug(`Timer M expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){zl.debug(`Timer B expired for transaction ${this.id}`),this.state===de.STATUS_CALLING&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){zl.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new af.OutgoingRequest(Xi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",t.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},as.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==de.STATUS_PROCEEDING)return;const n=new af.OutgoingRequest(Xi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",this.request.getHeader("to")),t&&n.setHeader("reason",t),this.transport.send(n)}receiveResponse(t){const n=t.status_code;if(n>=100&&n<=199)switch(this.state){case de.STATUS_CALLING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},as.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_COMPLETED:this.sendACK(t);break}}}class Qm extends _l{constructor(t,n,a,o){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return de}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Jm.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Zm extends _l{constructor(t,n,a){super(),this.type=de.NON_INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_TRYING,t.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){uf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,uf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,a,o){if(t===100)switch(this.state){case de.STATUS_TRYING:this.stateChanged(de.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case de.STATUS_PROCEEDING:this.last_response=n,this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=200&&t<=699)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},as.TIMER_J),this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break;case de.STATUS_COMPLETED:break}}}class eg extends _l{constructor(t,n,a){super(),this.type=de.INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,a.reply(100)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){Xl.debug(`Timer H expired for transaction ${this.id}`),this.state===de.STATUS_COMPLETED&&Xl.debug("ACK not received, dialog will be terminated"),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){Xl.debug(`Timer L expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,Xl.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(t,n,a,o){if(t>=100&&t<=199)switch(this.state){case de.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===de.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},as.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},as.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case de.STATUS_ACCEPTED:this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=300&&t<=699)switch(this.state){case de.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(de.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},as.TIMER_H),a&&a()):(this.onTransportError(),o&&o());break}}}function tg({_transactions:c},t){let n;switch(t.method){case Xi.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case de.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case de.STATUS_ACCEPTED:break}return!0}break;case Xi.ACK:if(n=c.ist[t.via_branch],n){if(n.state===de.STATUS_ACCEPTED)return!1;if(n.state===de.STATUS_COMPLETED)return n.state=de.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},as.TIMER_I),!0}else return!1;break;case Xi.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==de.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case de.STATUS_TRYING:break;case de.STATUS_PROCEEDING:case de.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var Tr={C:de,NonInviteClientTransaction:zm,InviteClientTransaction:Xm,AckClientTransaction:Qm,NonInviteServerTransaction:Zm,InviteServerTransaction:eg,checkTransaction:tg};const Gt=ze(Tr),sg=ut,cf=De,ng=dh,$o=Tr,rg=new sg("RequestSender"),Ho={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var vr=class{constructor(t,n,a){this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const o in Ho)Object.prototype.hasOwnProperty.call(Ho,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Ho[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==cf.BYE||this._method!==cf.ACK)&&this._eventHandlers.onTransportError()}send(){const t={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}};switch(this._method){case"INVITE":this.clientTransaction=new $o.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new $o.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new $o.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(t){let n,a;const o=t.status_code;if((o===401||o===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(n=t.parseHeader("www-authenticate"),a="authorization"):(n=t.parseHeader("proxy-authenticate"),a="proxy-authorization"),!n){rg.debug(`${t.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(t);return}if(!this._challenged||!this._staled&&n.stale===!0){if(this._auth||(this._auth=new ng({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,n)){this._eventHandlers.onReceiveResponse(t);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),n.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq",`${this._request.cseq} ${this._method}`),this._request.setHeader(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}};const sl=ze(vr),ig=ut,Fo=At(),Tn=De,ff=yt,hf=vr,Hi=new ig("Registrator"),Ql=10;var lg=class{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Fo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Hi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);const n=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new hf(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Hi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Hi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Ql&&(d=Ql);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<Ql&&(this._expires=Ql),this.register()):(Hi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,Tn.causes.SIP_FAILURE_CODE));break}default:{const s=Fo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Hi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push("Expires: 0");const a=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new hf(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=Fo.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}};class ag extends Error{constructor(t,n){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=t,this.value=n,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class og extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class ug extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class cg extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var As={ConfigurationError:ag,InvalidStateError:og,NotSupportedError:ug,NotReadyError:cg};const qs=ze(As),jo=De,Zl=Tr,fg=vr,qo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var _h=class{constructor(t,n,a){this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(const o in qo)Object.prototype.hasOwnProperty.call(qo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=qo[o]))}get request(){return this._request}send(){const t=new fg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(t.send(),(this._request.method===jo.INVITE||this._request.method===jo.UPDATE&&this._request.body)&&t.clientTransaction.state!==Zl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===Zl.C.STATUS_ACCEPTED||t.clientTransaction.state===Zl.C.STATUS_COMPLETED||t.clientTransaction.state===Zl.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};t.clientTransaction.on("stateChanged",n)}}_receiveResponse(t){t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===jo.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}};const hg=ze(_h),dg=ut,df=yt,$s=De,Fi=Tr,_g=_h,Vo=At(),Bo=new dg("Dialog"),Hs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var ph=class{static get C(){return Hs}constructor(t,n,a,o=Hs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof df.IncomingResponse&&(o=n.status_code<200?Hs.STATUS_EARLY:Hs.STATUS_CONFIRMED);const s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Bo.debug(`new ${a} dialog created with status ${this._state===Hs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Hs.STATUS_TERMINATED}update(t,n){this._state=Hs.STATUS_CONFIRMED,Bo.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Bo.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Hs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Vo.cloneArray(n.extraHeaders),o=Vo.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new _g(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===$s.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===$s.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Vo.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===$s.CANCEL||t===$s.ACK?this._local_seqnum:this._local_seqnum+=1;return new df.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===$s.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===$s.INVITE||t.method===$s.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Fi.C.STATUS_ACCEPTED||t.server_transaction.state===Fi.C.STATUS_COMPLETED||t.server_transaction.state===Fi.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===$s.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const ea=ze(ph);var ju={exports:{}};const pg=ft.EventEmitter,mg=ut,gg=De,Tg=As,_f=At(),vg=new mg("RTCSession:DTMF"),mh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ju.exports=class extends pg{constructor(t){super(),this._session=t,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(t,n={}){if(t===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Tg.InvalidStateError(this._session.status);const a=_f.cloneArray(n.extraHeaders);if(this.eventHandlers=_f.cloneObject(n.eventHandlers),typeof t=="string")t=t.toUpperCase();else if(typeof t=="number")t=t.toString();else throw new TypeError(`Invalid tone: ${t}`);if(t.match(/^[0-9A-DR#*]$/))this._tone=t;else throw new TypeError(`Invalid tone: ${t}`);this._duration=n.duration,a.push("Content-Type: application/dtmf-relay");let o=`Signal=${this._tone}\r
113
+ `;o+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(gg.INFO,{extraHeaders:a,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:s})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:o})}init_incoming(t){const n=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,a=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=t,t.reply(200),t.body){const o=t.body.split(`
114
+ `);o.length>=1&&n.test(o[0])&&(this._tone=o[0].replace(n,"$2")),o.length>=2&&a.test(o[1])&&(this._duration=parseInt(o[1].replace(a,"$2"),10))}this._duration||(this._duration=mh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):vg.debug("invalid INFO DTMF received, discarded")}};ju.exports.C=mh;var gh=ju.exports;const Eg=ze(gh),Sg=ft.EventEmitter,yg=De,Ag=As,Cg=At();var Th=class extends Sg{constructor(t){super(),this._session=t,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(t,n,a={}){if(this._direction="outgoing",t===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Ag.InvalidStateError(this._session.status);this._contentType=t,this._body=n;const o=Cg.cloneArray(a.extraHeaders);o.push(`Content-Type: ${t}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(yg.INFO,{extraHeaders:o,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.emit("failed",{originator:"remote",response:s})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:n})}init_incoming(t){this._direction="incoming",this.request=t,t.reply(200),this._contentType=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,this._body=t.body,this._session.newInfo({originator:"remote",info:this,request:t})}};const yu=ze(Th),Rg=ut,pf=De,Ig=new Rg("RTCSession:ReferNotifier"),Go={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var vh=class{constructor(t,n,a){this._session=t,this._id=n,this._expires=a||Go.expires,this._active=!0,this.notify(100)}notify(t,n){if(Ig.debug("notify()"),this._active===!1)return;n=n||pf.REASON_PHRASE[t]||"";let a;t>=200?a="terminated;reason=noresource":a=`active;expires=${this._expires}`,this._session.sendRequest(pf.NOTIFY,{extraHeaders:[`Event: ${Go.event_type};id=${this._id}`,`Subscription-State: ${a}`,`Content-Type: ${Go.body_type}`],body:`SIP/2.0 ${t} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const bg=ze(vh),wg=ft.EventEmitter,Og=ut,ji=De,Dg=Zt(),mf=At(),vn=new Og("RTCSession:ReferSubscriber");var Eh=class extends wg{constructor(t){super(),this._id=null,this._session=t}get id(){return this._id}sendRefer(t,n={}){vn.debug("sendRefer()");const a=mf.cloneArray(n.extraHeaders),o=mf.cloneObject(n.eventHandlers);for(const h in o)Object.prototype.hasOwnProperty.call(o,h)&&this.on(h,o[h]);let s=null;n.replaces&&(s=n.replaces._request.call_id,s+=`;to-tag=${n.replaces._to_tag}`,s+=`;from-tag=${n.replaces._from_tag}`,s=encodeURIComponent(s));const r=`Refer-To: <${t}${s?`?Replaces=${s}`:""}>`;if(a.push(r),!a.some(h=>h.toLowerCase().startsWith("referred-by:"))){const h=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;a.push(h)}a.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest(ji.REFER,{extraHeaders:a,eventHandlers:{onSuccessResponse:h=>{this._requestSucceeded(h)},onErrorResponse:h=>{this._requestFailed(h,ji.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,ji.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,ji.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,ji.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(t){if(vn.debug("receiveNotify()"),!t.body)return;const n=Dg.parse(t.body.trim().split(`\r
115
+ `,1)[0],"Status_Line");if(n===-1){vn.debug(`receiveNotify() | error parsing NOTIFY body: "${t.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:t,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:t,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:t,status_line:n});break;default:this.emit("failed",{request:t,status_line:n});break}}_requestSucceeded(t){vn.debug("REFER succeeded"),vn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){vn.debug("REFER failed"),vn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const Ng=ze(Eh),Ug=ft.EventEmitter,gf=xt,Pg=ut,fe=De,En=As,Tf=Tr,Be=At(),qi=Fu,xg=yt,ta=ph,kg=vr,Mt=gh,vf=Th,Mg=vh,Lg=Eh,Ef=ys(),Y=new Pg("RTCSession"),Z={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},sa=["audio","video"];var Sh=class Au extends Ug{static get C(){return Z}constructor(t){Y.debug("new"),super(),this._id=null,this._ua=t,this._status=Z.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:fe.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Z}get causes(){return fe.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case Z.STATUS_NULL:case Z.STATUS_INVITE_SENT:case Z.STATUS_1XX_RECEIVED:case Z.STATUS_INVITE_RECEIVED:case Z.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Z.STATUS_ANSWERED:case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Z.STATUS_CANCELED:case Z.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(t,n={},a){Y.debug("connect()");const o=t,s=Be.cloneObject(n.eventHandlers),r=Be.cloneArray(n.extraHeaders),d=Be.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Be.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new En.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new En.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Be.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES);for(const A in s)Object.prototype.hasOwnProperty.call(s,A)&&this.on(A,s[A]);this._from_tag=Be.newTag();const E=n.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(y.from_display_name="Anonymous",y.from_uri=new Ef("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Ef("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(y.from_display_name=n.fromDisplayName),r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&r.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new xg.InitialOutgoingInviteRequest(t,this._ua,y,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(_,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,a&&a(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,h)}init_incoming(t,n){Y.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=Be.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,fe.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,fe.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==Z.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){Y.debug("answer()");const n=this._request,a=Be.cloneArray(t.extraHeaders),o=Be.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Be.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Be.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new En.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new En.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(I=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};Y.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,fe.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(I)})}terminate(t={}){Y.debug("terminate()");const n=t.cause||fe.causes.BYE,a=Be.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new En.InvalidStateError(this._status);switch(this._status){case Z.STATUS_NULL:case Z.STATUS_INVITE_SENT:case Z.STATUS_1XX_RECEIVED:if(Y.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||fe.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Z.STATUS_CANCELED,this._failed("local",null,fe.causes.CANCELED);break;case Z.STATUS_WAITING_FOR_ANSWER:case Z.STATUS_ANSWERED:if(Y.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,fe.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(Y.debug("terminating session"),d=t.reason_phrase||fe.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Tf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===fe.ACK&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Tf.C.STATUS_TERMINATED&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendDTMF(t,n={}){Y.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||fe.DTMF_TRANSPORT.INFO;if(t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new En.InvalidStateError(this._status);if(r!==fe.DTMF_TRANSPORT.INFO&&r!==fe.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${r}`);if(typeof t=="number"&&(t=t.toString()),!t||typeof t!="string"||!t.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${t}`);if(o&&!Be.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<Mt.C.MIN_DURATION?(Y.debug(`"duration" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_DURATION} milliseconds`),o=Mt.C.MIN_DURATION):o>Mt.C.MAX_DURATION?(Y.debug(`"duration" value is greater than the maximum allowed, setting it to ${Mt.C.MAX_DURATION} milliseconds`),o=Mt.C.MAX_DURATION):o=Math.abs(o):o=Mt.C.DEFAULT_DURATION,n.duration=o,s&&!Be.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<Mt.C.MIN_INTER_TONE_GAP?(Y.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_INTER_TONE_GAP} milliseconds`),s=Mt.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=Mt.C.DEFAULT_INTER_TONE_GAP,r===fe.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(t=h.toneBuffer+t,h.insertDTMF(t,o,s));return}if(this._tones){this._tones+=t;return}this._tones=t,d.call(this);function d(){let h;if(this._status===Z.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const _=this._tones[a];if(a+=1,_===",")h=2e3;else{const g=new Mt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(_,n),h=o+s}setTimeout(d.bind(this),h)}}sendInfo(t,n,a={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new En.InvalidStateError(this._status);new vf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){Y.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){Y.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(Y.debug("hold()"),this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(Y.debug("unhold()"),this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){Y.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){Y.debug("refer()");const a=t;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Lg(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return Y.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(Y.debug("receiveRequest()"),t.method===fe.CANCEL)(this._status===Z.STATUS_WAITING_FOR_ANSWER||this._status===Z.STATUS_ANSWERED)&&(this._status=Z.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,fe.causes.CANCELED));else switch(t.method){case fe.ACK:if(this._status!==Z.STATUS_WAITING_FOR_ACK)return;if(this._status=Z.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:fe.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:fe.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case fe.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,fe.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,fe.causes.BYE)):t.reply(403,"Wrong Status");break;case fe.INVITE:this._status===Z.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case fe.INFO:if(this._status===Z.STATUS_1XX_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER||this._status===Z.STATUS_ANSWERED||this._status===Z.STATUS_WAITING_FOR_ACK||this._status===Z.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Mt(this).init_incoming(t):n!==void 0?new vf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case fe.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case fe.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case fe.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){Y.warn("onTransportError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.CONNECTION_ERROR,cause:fe.causes.CONNECTION_ERROR})}onRequestTimeout(){Y.warn("onRequestTimeout()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:fe.causes.REQUEST_TIMEOUT,cause:fe.causes.REQUEST_TIMEOUT})}onDialogError(){Y.warn("onDialogError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.DIALOG_ERROR,cause:fe.causes.DIALOG_ERROR})}newDTMF(t){Y.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){Y.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(Y.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(Y.debug("_isReadyToReOffer() | session not established yet"),!1):(Y.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(Y.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(Y.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==Z.STATUS_TERMINATED){if(this._status=Z.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){Y.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=qi.T1;function o(){this._status===Z.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<qi.T2&&(a=a*2,a>qi.T2&&(a=qi.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ACK&&(Y.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(fe.BYE),this._ended("remote",null,fe.causes.NO_ACK))},qi.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:fe.causes.RTP_TIMEOUT,status_code:408,reason_phrase:fe.causes.RTP_TIMEOUT})}),Y.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(Y.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ta(this,t,n,ta.C.STATUS_EARLY),d.error?(Y.debug(d.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ta(this,t,n);return h.error?(Y.debug(h.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){Y.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){Y.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){Y.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(sa.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(Y.debug("receiveRefer()"),!t.refer_to){Y.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==fe.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new Mg(this,t.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const d=new Au(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Be.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(Y.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){Y.debug("receiveReplaces()");function n(o){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const s=new Au(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){Y.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_sendInitialRequest(t,n,a){const o=new kg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,fe.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){Y.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(Y.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(fe.ACK);return}else{const n=new ta(this,t,"UAC");if(n.error!==void 0){Y.debug(n.error);return}this.sendRequest(fe.ACK),this.sendRequest(fe.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){Y.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=Z.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,fe.causes.MISSING_SDP),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),this._failed("local",t,fe.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(fe.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Be.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){Y.debug("sendReinvite()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};Y.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(fe.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(fe.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};Y.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){Y.debug("sendUpdate()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(fe.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==Z.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};Y.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){Y.debug("acceptAndTerminate()");const o=[];n&&(a=a||fe.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(fe.ACK),this.sendRequest(fe.BYE,{extraHeaders:o})),this._status=Z.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=gf.parse(t),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return gf.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===fe.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&(Y.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:fe.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newRTCSession(t,n){Y.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const $g=ze(Sh),Hg=ft.EventEmitter,Fg=ut,Wo=De,jg=yt,Vi=At(),qg=vr,Sf=As,Vg=ys(),na=new Fg("Message");var Bg=class extends Hg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0||n===void 0)throw new TypeError("Not enough arguments");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Vi.cloneArray(a.extraHeaders),r=Vi.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Vg("sip",a.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(h.from_display_name=a.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${d}`),this._request=new jg.OutgoingRequest(Wo.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new qg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),_.send()}init_incoming(t){this._request=t,this._newMessage("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Vi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Vi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Vi.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Wo.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Wo.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:t,message:this,request:n})}_failed(t,n,a){na.debug("MESSAGE failed"),this._close(),na.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){na.debug("MESSAGE succeeded"),this._close(),na.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const Gg=ft.EventEmitter,Wg=ut,Ko=De,Kg=yt,Bi=At(),Yg=vr,yf=As,ra=new Wg("Options");var Jg=class extends Gg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0)throw new TypeError("A target is required for OPTIONS");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Bi.cloneArray(a.extraHeaders),r=Bi.cloneObject(a.eventHandlers),d=a.contentType||"application/sdp";for(const _ in r)Object.prototype.hasOwnProperty.call(r,_)&&this.on(_,r[_]);s.push(`Content-Type: ${d}`),this._request=new Kg.OutgoingRequest(Ko.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Yg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:_=>{this._receiveResponse(_)}});this._newOptions("local",this._request),h.send()}init_incoming(t){this._request=t,this._newOptions("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Bi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Bi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Bi.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Ko.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Ko.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:t,message:this,request:n})}_failed(t,n,a){ra.debug("OPTIONS failed"),this._close(),ra.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){ra.debug("OPTIONS succeeded"),this._close(),ra.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},qu={};const zg=ut,Yo=At(),Xg=Zt(),Gi=new zg("Socket");qu.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return Gi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Yo.isString(c.url))throw Gi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Yo.isString(c.via_transport))throw Gi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Xg.parse(c.sip_uri,"SIP_URI")===-1)throw Gi.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(t=>{if(!Yo.isFunction(c[t]))throw Gi.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const Qg=ut,Zg=qu,Af=De,Ut=new Qg("Transport"),Vt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Af.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Af.CONNECTION_RECOVERY_MAX_INTERVAL}};var yh=class{constructor(t,n=Vt.recovery_options){Ut.debug("new()"),this.status=Vt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Ut.warn(`cannot use TextDecoder: ${a}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Zg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:Vt.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(Ut.debug("connect()"),this.isConnected()){Ut.debug("Transport is already connected");return}else if(this.isConnecting()){Ut.debug("Transport is connecting");return}this.close_requested=!1,this.status=Vt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){Ut.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Vt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return Ut.debug(`sending message:
116
116
 
117
- ${t}
118
- `),this.socket.send(t)}isConnected(){return this.status===as.STATUS_CONNECTED}isConnecting(){return this.status===as.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let e=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);e<this.recovery_options.min_interval?e=this.recovery_options.min_interval:e>this.recovery_options.max_interval&&(e=this.recovery_options.max_interval),Xt.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${e} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},e*1e3)}_getSocket(){let e=[];if(this.sockets.forEach(r=>{r.status!==as.SOCKET_STATUS_ERROR&&(e.length===0?e.push(r):r.weight>e[0].weight?e=[r]:r.weight===e[0].weight&&e.push(r))}),e.length===0){this.sockets.forEach(r=>{r.status=as.SOCKET_STATUS_READY}),this._getSocket();return}const t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}_onConnect(){this.recover_attempts=0,this.status=as.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(e,t,r){this.status=as.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:r}),!this.close_requested&&(this.sockets.forEach(function(l){this.socket===l.socket&&(l.status=as.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}_onData(e){if(e===`\r
119
- `){Xt.debug("received message with CRLF Keep Alive response");return}else if(typeof e!="string"){try{this.textDecoder?e=this.textDecoder.decode(e):e=String.fromCharCode.apply(null,new Uint8Array(e))}catch{Xt.debug("received binary message failed to be converted into string, message discarded");return}Xt.debug(`received binary message:
117
+ ${n}
118
+ `),this.socket.send(n)}isConnected(){return this.status===Vt.STATUS_CONNECTED}isConnecting(){return this.status===Vt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),Ut.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${t} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},t*1e3)}_getSocket(){let t=[];if(this.sockets.forEach(a=>{a.status!==Vt.SOCKET_STATUS_ERROR&&(t.length===0?t.push(a):a.weight>t[0].weight?t=[a]:a.weight===t[0].weight&&t.push(a))}),t.length===0){this.sockets.forEach(a=>{a.status=Vt.SOCKET_STATUS_READY}),this._getSocket();return}const n=Math.floor(Math.random()*t.length);this.socket=t[n].socket}_onConnect(){this.recover_attempts=0,this.status=Vt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(t,n,a){this.status=Vt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:t,code:n,reason:a}),!this.close_requested&&(this.sockets.forEach(function(o){this.socket===o.socket&&(o.status=Vt.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}_onData(t){if(t===`\r
119
+ `){Ut.debug("received message with CRLF Keep Alive response");return}else if(typeof t!="string"){try{this.textDecoder?t=this.textDecoder.decode(t):t=String.fromCharCode.apply(null,new Uint8Array(t))}catch{Ut.debug("received binary message failed to be converted into string, message discarded");return}Ut.debug(`received binary message:
120
120
 
121
- ${e}
122
- `)}else Xt.debug(`received text message:
121
+ ${t}
122
+ `)}else Ut.debug(`received text message:
123
123
 
124
- ${e}
125
- `);this.ondata({transport:this,message:e})}};const by=nt(_p);var gp={};const Ry=At,uf=ys(),cf=$t,wo=new Ry("Parser");gp.parseMessage=(u,e)=>{let t,r,l=u.indexOf(`\r
126
- `);if(l===-1){wo.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=u.substring(0,l);let i=uf.parse(s,"Request_Response");if(i===-1){wo.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else i.status_code?(t=new cf.IncomingResponse,t.status_code=i.status_code,t.reason_phrase=i.reason_phrase):(t=new cf.IncomingRequest(e),t.method=i.method,t.ruri=i.uri);t.data=u;let f=l+2;for(;;){if(l=wy(u,f),l===-2){r=f+2;break}else if(l===-1){wo.warn("parseMessage() | malformed message");return}if(i=Iy(t,u,f,l),i!==!0){wo.warn("parseMessage() |",i.error);return}f=l+2}if(t.hasHeader("content-length")){const h=t.getHeader("content-length");t.body=u.substr(r,h)}else t.body=u.substring(r);return t};function wy(u,e){let t=e,r=0,l=0;if(u.substring(t,t+2).match(/(^\r\n)/))return-2;for(;r===0;){if(l=u.indexOf(`\r
127
- `,t),l===-1)return l;!u.substring(l+2,l+4).match(/(^\r\n)/)&&u.charAt(l+2).match(/(^\s+)/)?t=l+2:r=l}return r}function Iy(u,e,t,r){let l;const s=e.indexOf(":",t),i=e.substring(t,s).trim(),f=e.substring(s+1,r).trim();switch(i.toLowerCase()){case"via":case"v":u.addHeader("via",f),u.getHeaders("via").length===1?(l=u.parseHeader("Via"),l&&(u.via=l,u.via_branch=l.branch)):l=0;break;case"from":case"f":u.setHeader("from",f),l=u.parseHeader("from"),l&&(u.from=l,u.from_tag=l.getParam("tag"));break;case"to":case"t":u.setHeader("to",f),l=u.parseHeader("to"),l&&(u.to=l,u.to_tag=l.getParam("tag"));break;case"record-route":if(l=uf.parse(f,"Record_Route"),l===-1)l=void 0;else for(const h of l)u.addHeader("record-route",f.substring(h.possition,h.offset)),u.headers["Record-Route"][u.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":u.setHeader("call-id",f),l=u.parseHeader("call-id"),l&&(u.call_id=f);break;case"contact":case"m":if(l=uf.parse(f,"Contact"),l===-1)l=void 0;else for(const h of l)u.addHeader("contact",f.substring(h.possition,h.offset)),u.headers.Contact[u.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":u.setHeader("content-length",f),l=u.parseHeader("content-length");break;case"content-type":case"c":u.setHeader("content-type",f),l=u.parseHeader("content-type");break;case"cseq":u.setHeader("cseq",f),l=u.parseHeader("cseq"),l&&(u.cseq=l.value),u instanceof cf.IncomingResponse&&(u.method=l.method);break;case"max-forwards":u.setHeader("max-forwards",f),l=u.parseHeader("max-forwards");break;case"www-authenticate":u.setHeader("www-authenticate",f),l=u.parseHeader("www-authenticate");break;case"proxy-authenticate":u.setHeader("proxy-authenticate",f),l=u.parseHeader("proxy-authenticate");break;case"session-expires":case"x":u.setHeader("session-expires",f),l=u.parseHeader("session-expires"),l&&(u.session_expires=l.expires,u.session_expires_refresher=l.refresher);break;case"refer-to":case"r":u.setHeader("refer-to",f),l=u.parseHeader("refer-to"),l&&(u.refer_to=l);break;case"replaces":u.setHeader("replaces",f),l=u.parseHeader("replaces"),l&&(u.replaces=l);break;case"event":case"o":u.setHeader("event",f),l=u.parseHeader("event"),l&&(u.event=l);break;default:u.addHeader(i,f),l=0}return l===void 0?{error:`error parsing header "${i}"`}:!0}const Oy=At,pp=Ue,k_=$t,Ff=Ht(),$f=new Oy("sanityCheck"),Dy=[$y],Ny=[xy,ky,My,Uy],Py=[Ly,Fy];let Qe,ws,mp;var vp=(u,e,t)=>{Qe=u,ws=e,mp=t;for(const r of Dy)if(r()===!1)return!1;if(Qe instanceof k_.IncomingRequest){for(const r of Ny)if(r()===!1)return!1}else if(Qe instanceof k_.IncomingResponse){for(const r of Py)if(r()===!1)return!1}return!0};function xy(){if(Qe.s("to").uri.scheme!=="sip")return ma(416),!1}function ky(){if(!Qe.to_tag&&Qe.call_id.substr(0,5)===ws.configuration.jssip_id)return ma(482),!1}function My(){const u=Ff.str_utf8_length(Qe.body),e=Qe.getHeader("content-length");if(u<e)return ma(400),!1}function Uy(){const u=Qe.from_tag,e=Qe.call_id,t=Qe.cseq;let r;if(!Qe.to_tag)if(Qe.method===pp.INVITE){if(ws._transactions.ist[Qe.via_branch])return!1;for(const l in ws._transactions.ist)if(Object.prototype.hasOwnProperty.call(ws._transactions.ist,l)&&(r=ws._transactions.ist[l],r.request.from_tag===u&&r.request.call_id===e&&r.request.cseq===t))return ma(482),!1}else{if(ws._transactions.nist[Qe.via_branch])return!1;for(const l in ws._transactions.nist)if(Object.prototype.hasOwnProperty.call(ws._transactions.nist,l)&&(r=ws._transactions.nist[l],r.request.from_tag===u&&r.request.call_id===e&&r.request.cseq===t))return ma(482),!1}}function Ly(){if(Qe.getHeaders("via").length>1)return $f.debug("more than one Via header field present in the response, dropping the response"),!1}function Fy(){const u=Ff.str_utf8_length(Qe.body),e=Qe.getHeader("content-length");if(u<e)return $f.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function $y(){const u=["from","to","call_id","cseq","via"];for(const e of u)if(!Qe.hasHeader(e))return $f.debug(`missing mandatory header field : ${e}, dropping the response`),!1}function ma(u){const e=Qe.getHeaders("via");let t,r=`SIP/2.0 ${u} ${pp.REASON_PHRASE[u]}\r
128
- `;for(const l of e)r+=`Via: ${l}\r
129
- `;t=Qe.getHeader("To"),Qe.to_tag||(t+=`;tag=${Ff.newTag()}`),r+=`To: ${t}\r
130
- `,r+=`From: ${Qe.getHeader("From")}\r
131
- `,r+=`Call-ID: ${Qe.call_id}\r
132
- `,r+=`CSeq: ${Qe.cseq} ${Qe.method}\r
133
- `,r+=`\r
134
- `,mp.send(r)}const Hy=nt(vp);var va={};const fr=Ht(),hi=Ue,yh=ys(),M_=Xs(),Sh=Lf,Eh=Js;va.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:hi.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:hi.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:hi.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${fr.createRandomToken(12)}.invalid`};const Io={mandatory:{sockets(u){const e=[];if(Sh.isSocket(u))e.push({socket:u});else if(Array.isArray(u)&&u.length)for(const t of u)Object.prototype.hasOwnProperty.call(t,"socket")&&Sh.isSocket(t.socket)?e.push(t):Sh.isSocket(t)&&e.push({socket:t});else return;return e},uri(u){/^sip:/i.test(u)||(u=`${hi.SIP}:${u}`);const e=M_.parse(u);if(e)return e.user?e:void 0}},optional:{authorization_user(u){if(yh.parse(`"${u}"`,"quoted_string")!==-1)return u},authorization_jwt(u){if(typeof u=="string")return u},user_agent(u){if(typeof u=="string")return u},connection_recovery_max_interval(u){if(fr.isDecimal(u)){const e=Number(u);if(e>0)return e}},connection_recovery_min_interval(u){if(fr.isDecimal(u)){const e=Number(u);if(e>0)return e}},contact_uri(u){if(typeof u=="string"){const e=yh.parse(u,"SIP_URI");if(e!==-1)return e}},display_name(u){return u},instance_id(u){if(/^uuid:/i.test(u)&&(u=u.substr(5)),yh.parse(u,"uuid")!==-1)return u},no_answer_timeout(u){if(fr.isDecimal(u)){const e=Number(u);if(e>0)return e}},session_timers(u){if(typeof u=="boolean")return u},session_timers_refresh_method(u){if(typeof u=="string"&&(u=u.toUpperCase(),u===hi.INVITE||u===hi.UPDATE))return u},session_timers_force_refresher(u){if(typeof u=="boolean")return u},password(u){return String(u)},realm(u){return String(u)},ha1(u){return String(u)},register(u){if(typeof u=="boolean")return u},register_expires(u){if(fr.isDecimal(u)){const e=Number(u);if(e>0)return e}},registrar_server(u){/^sip:/i.test(u)||(u=`${hi.SIP}:${u}`);const e=M_.parse(u);if(e)return e.user?void 0:e},use_preloaded_route(u){if(typeof u=="boolean")return u},extra_headers(u){const e=[];if(Array.isArray(u)&&u.length)for(const t of u)typeof t=="string"&&e.push(t);else return;return e}}};va.load=(u,e)=>{for(const t in Io.mandatory)if(e.hasOwnProperty(t)){const r=e[t],l=Io.mandatory[t](r);if(l!==void 0)u[t]=l;else throw new Eh.ConfigurationError(t,r)}else throw new Eh.ConfigurationError(t);for(const t in Io.optional)if(e.hasOwnProperty(t)){const r=e[t];if(fr.isEmpty(r))continue;const l=Io.optional[t](r);if(l!==void 0)u[t]=l;else throw new Eh.ConfigurationError(t,r)}};const Gy=It.EventEmitter,Vy=At,xt=Ue,By=NT,U_=dp,L_=gy,F_=yy,Ch=Sr,jy=_p,Oo=Ht(),qy=Js,Wy=Xs(),Ky=gp,Ah=$t,Yy=vp,bh=va,et=new Vy("UA"),Ut={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var Tp=class extends Gy{static get C(){return Ut}constructor(e){if(et.debug("new() [configuration:%o]",e),super(),this._cache={credentials:{}},this._configuration=Object.assign({},bh.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=Ut.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,e===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(e)}catch(t){throw this._status=Ut.STATUS_NOT_READY,this._error=Ut.CONFIGURATION_ERROR,t}this._registrator=new By(this)}get C(){return Ut}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){et.debug("start()"),this._status===Ut.STATUS_INIT?this._transport.connect():this._status===Ut.STATUS_USER_CLOSED?(et.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Ut.STATUS_INIT,this._transport.connect()):this._status===Ut.STATUS_READY?et.debug("UA is in READY status, not restarted"):et.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){et.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(e){et.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(e)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(e,t){et.debug("call()");const r=new U_(this);return r.connect(e,t),r}sendMessage(e,t,r){et.debug("sendMessage()");const l=new L_(this);return l.send(e,t,r),l}sendOptions(e,t,r){et.debug("sendOptions()");const l=new F_(this);return l.send(e,t,r),l}terminateSessions(e){et.debug("terminateSessions()");for(const t in this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}stop(){if(et.debug("stop()"),this._dynConfiguration={},this._status===Ut.STATUS_USER_CLOSED){et.debug("UA already closed");return}this._registrator.close();const e=Object.keys(this._sessions).length;for(const r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){et.debug(`closing session ${r}`);try{this._sessions[r].terminate()}catch{}}for(const r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch{}this._status=Ut.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&&e===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(e){return Oo.normalizeTarget(e,this._configuration.hostport_params)}get(e){switch(e){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:et.warn('get() | cannot get "%s" parameter in runtime',e);return}}set(e,t){switch(e){case"authorization_user":{this._configuration.authorization_user=String(t);break}case"password":{this._configuration.password=String(t);break}case"realm":{this._configuration.realm=String(t);break}case"ha1":{this._configuration.ha1=String(t),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(t);break}case"display_name":{this._configuration.display_name=t;break}default:return et.warn('set() | cannot set "%s" parameter in runtime',e),!1}return!0}newTransaction(e){this._transactions[e.type][e.id]=e,this.emit("newTransaction",{transaction:e})}destroyTransaction(e){delete this._transactions[e.type][e.id],this.emit("transactionDestroyed",{transaction:e})}newDialog(e){this._dialogs[e.id]=e}destroyDialog(e){delete this._dialogs[e.id]}newMessage(e,t){this._applicants[e]=e,this.emit("newMessage",t)}newOptions(e,t){this._applicants[e]=e,this.emit("newOptions",t)}destroyMessage(e){delete this._applicants[e]}newRTCSession(e,t){this._sessions[e.id]=e,this.emit("newRTCSession",t)}destroyRTCSession(e){delete this._sessions[e.id]}registered(e){this.emit("registered",e)}unregistered(e){this.emit("unregistered",e)}registrationFailed(e){this.emit("registrationFailed",e)}receiveRequest(e){const t=e.method;if(e.ruri.user!==this._configuration.uri.user&&e.ruri.user!==this._contact.uri.user){et.debug("Request-URI does not point to us"),e.method!==xt.ACK&&e.reply_sl(404);return}if(e.ruri.scheme===xt.SIPS){e.reply_sl(416);return}if(Ch.checkTransaction(this,e))return;if(t===xt.INVITE?new Ch.InviteServerTransaction(this,this._transport,e):t!==xt.ACK&&t!==xt.CANCEL&&new Ch.NonInviteServerTransaction(this,this._transport,e),t===xt.OPTIONS){if(this.listeners("newOptions").length===0){e.reply(200);return}new F_(this).init_incoming(e)}else if(t===xt.MESSAGE){if(this.listeners("newMessage").length===0){e.reply(405);return}new L_(this).init_incoming(e)}else if(t===xt.INVITE&&!e.to_tag&&this.listeners("newRTCSession").length===0){e.reply(405);return}let r,l;if(e.to_tag)r=this._findDialog(e.call_id,e.from_tag,e.to_tag),r?r.receiveRequest(e):t===xt.NOTIFY?(l=this._findSession(e),l?l.receiveRequest(e):(et.debug("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist"))):t!==xt.ACK&&e.reply(481);else switch(t){case xt.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){const s=e.replaces;r=this._findDialog(s.call_id,s.from_tag,s.to_tag),r?(l=r.owner,l.isEnded()?e.reply(603):l.receiveRequest(e)):e.reply(481)}else l=new U_(this),l.init_incoming(e);else et.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case xt.BYE:e.reply(481);break;case xt.CANCEL:l=this._findSession(e),l?l.receiveRequest(e):et.debug("received CANCEL request for a non existent session");break;case xt.ACK:break;case xt.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;default:e.reply(405);break}}_findSession({call_id:e,from_tag:t,to_tag:r}){const l=e+t,s=this._sessions[l],i=e+r,f=this._sessions[i];return s||f||null}_findDialog(e,t,r){let l=e+t+r,s=this._dialogs[l];return s||(l=e+r+t,s=this._dialogs[l],s||null)}_loadConfig(e){try{bh.load(this._configuration,e)}catch(l){throw l}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Oo.newUUID()),this._configuration.jssip_id=Oo.createRandomToken(5);const t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new jy(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=zy.bind(this),this._transport.onconnect=Xy.bind(this),this._transport.ondisconnect=Jy.bind(this),this._transport.ondata=Qy.bind(this)}catch(l){throw et.warn(l),new qy.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 l=this._configuration.uri.clone();l.user=null,l.clearParams(),l.clearHeaders(),this._configuration.registrar_server=l}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Wy("sip",Oo.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(l={}){const s=l.anonymous||null,i=l.outbound||null;let f="<";return s?f+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":f+=this.pub_gruu||this.uri.toString(),i&&(s?!this.temp_gruu:!this.pub_gruu)&&(f+=";ob"),f+=">",f}};const r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const l in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,l)&&(r.indexOf(l)!==-1?Object.defineProperty(this._configuration,l,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,l,{writable:!1,configurable:!1}));et.debug("configuration parameters after validation:");for(const l in this._configuration)if(Object.prototype.hasOwnProperty.call(bh.settings,l))switch(l){case"uri":case"registrar_server":et.debug(`- ${l}: ${this._configuration[l]}`);break;case"password":case"ha1":case"authorization_jwt":et.debug(`- ${l}: NOT SHOWN`);break;default:et.debug(`- ${l}: ${JSON.stringify(this._configuration[l])}`)}}};function zy(u){this.emit("connecting",u)}function Xy(u){this._status!==Ut.STATUS_USER_CLOSED&&(this._status=Ut.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function Jy(u){const e=["nict","ict","nist","ist"];for(const t of e)for(const r in this._transactions[t])Object.prototype.hasOwnProperty.call(this._transactions[t],r)&&this._transactions[t][r].onTransportError();this.emit("disconnected",u),this._registrator.onTransportClosed(),this._status!==Ut.STATUS_USER_CLOSED&&(this._status=Ut.STATUS_NOT_READY,this._error=Ut.NETWORK_ERROR)}function Qy(u){const e=u.transport;let t=u.message;if(t=Ky.parseMessage(t,this),!!t&&!(this._status===Ut.STATUS_USER_CLOSED&&t instanceof Ah.IncomingRequest)&&Yy(t,this,e)){if(t instanceof Ah.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof Ah.IncomingResponse){let r;switch(t.method){case xt.INVITE:r=this._transactions.ict[t.via_branch],r&&r.receiveResponse(t);break;case xt.ACK:break;default:r=this._transactions.nict[t.via_branch],r&&r.receiveResponse(t);break}}}}const Zy=nt(Tp);var Nt=[];for(var Rh=0;Rh<256;++Rh)Nt.push((Rh+256).toString(16).slice(1));function eS(u,e=0){return(Nt[u[e+0]]+Nt[u[e+1]]+Nt[u[e+2]]+Nt[u[e+3]]+"-"+Nt[u[e+4]]+Nt[u[e+5]]+"-"+Nt[u[e+6]]+Nt[u[e+7]]+"-"+Nt[u[e+8]]+Nt[u[e+9]]+"-"+Nt[u[e+10]]+Nt[u[e+11]]+Nt[u[e+12]]+Nt[u[e+13]]+Nt[u[e+14]]+Nt[u[e+15]]).toLowerCase()}var Do,tS=new Uint8Array(16);function sS(){if(!Do&&(Do=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Do))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Do(tS)}var nS=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const $_={randomUUID:nS};function H_(u,e,t){if($_.randomUUID&&!e&&!u)return $_.randomUUID();u=u||{};var r=u.random||(u.rng||sS)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){t=t||0;for(var l=0;l<16;++l)e[t+l]=r[l];return e}return eS(r)}var je=Ht();const qs=nt(je),wh=new Au("Dialog"),Tn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class No{static get C(){return Tn}constructor(e,t,r,l=Tn.STATUS_CONFIRMED){if(this._owner=e,this._ua=e._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,t instanceof $t.IncomingResponse&&(l=t.status_code<200?Tn.STATUS_EARLY:Tn.STATUS_CONFIRMED),r==="UAS"){this._id={call_id:t.call_id,local_tag:t.to_tag,remote_tag:t.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._remote_seqnum=t.cseq,this._local_uri=t.parseHeader("to").uri,this._remote_uri=t.parseHeader("from").uri;let s=t.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=t.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(r==="UAC"){this._id={call_id:t.call_id,local_tag:t.from_tag,remote_tag:t.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=l,this._local_seqnum=t.cseq,this._local_uri=t.parseHeader("from").uri,this._remote_uri=t.parseHeader("to").uri;let s=t.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=t.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),wh.debug(`new ${r} dialog created with status ${this._state===Tn.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(e){this._local_seqnum=e}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(e){this._uac_pending_reply=e}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Tn.STATUS_TERMINATED}update(e,t){this._state=Tn.STATUS_CONFIRMED,wh.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t==="UAC"&&(this._route_set=e.getHeaders("record-route").reverse())}terminate(){wh.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Tn.STATUS_TERMINATED}sendRequest(e,t={}){const r=qs.cloneArray(t.extraHeaders),l=qs.cloneObject(t.eventHandlers),s=t.body||null,i=this._createRequest(e,r,s);return l.onAuthenticated=()=>{this._local_seqnum+=1},new LT(this,i,l).send(),i}receiveRequest(e){this._checkInDialogRequest(e)&&(e.method===Z.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:e.method===Z.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}_createRequest(e,t,r){t=qs.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const l=e===Z.CANCEL||e===Z.ACK?this._local_seqnum:this._local_seqnum+=1;return new $t.OutgoingRequest(e,this._remote_target,this._ua,{cseq:l,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},t,r)}_checkInDialogRequest(e){if(!this._remote_seqnum)this._remote_seqnum=e.cseq;else if(e.cseq<this._remote_seqnum)if(e.method===Z.ACK){if(this._ack_seqnum===null||e.cseq!==this._ack_seqnum)return!1}else return e.reply(500),!1;else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);if(e.method===Z.INVITE||e.method===Z.UPDATE&&e.body){if(this._uac_pending_reply===!0)e.reply(491);else if(this._uas_pending_reply===!0){const t=(Math.random()*10|0)+1;return e.reply(500,null,[`Retry-After:${t}`]),!1}else{this._uas_pending_reply=!0;const t=()=>{(e.server_transaction.state===cs.C.STATUS_ACCEPTED||e.server_transaction.state===cs.C.STATUS_COMPLETED||e.server_transaction.state===cs.C.STATUS_TERMINATED)&&(e.server_transaction.removeListener("stateChanged",t),this._uas_pending_reply=!1)};e.server_transaction.on("stateChanged",t)}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===cs.C.STATUS_ACCEPTED&&(this._remote_target=e.parseHeader("contact").uri)})}else e.method===Z.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===cs.C.STATUS_COMPLETED&&(this._remote_target=e.parseHeader("contact").uri)});return!0}}class iS{constructor(e,t){fs(this,"plugin",null);fs(this,"rtcpPeer",null);fs(this,"handleId",0);fs(this,"info",null);fs(this,"joinResult",null);fs(this,"state",{});fs(this,"stream",null);fs(this,"loaded",!1);fs(this,"aTracks",[]);fs(this,"vTracks",[]);this.info=e,this.plugin=t,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(e){var t;this.state={...this.state,...e||{}},(t=this.plugin)==null||t.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(e){var s,i,f,h;const t=(i=(s=e==null?void 0:e.plugindata)==null?void 0:s.data)==null?void 0:i.newStatePublisher,l=((h=(f=e==null?void 0:e.plugindata)==null?void 0:f.data)==null?void 0:h.publisher_state).find(d=>d.id===t);this.updateMemberState(l==null?void 0:l.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(e=>{e.stop()})}}class vs{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(e){return vs.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(r=>r.kind===e):[]}static async getMicrophoneList(){return(await vs.getDevices("audioinput")).map((t,r)=>({...t,deviceId:t.deviceId,label:t.label||`microphone ${r+1}`,kind:t.kind,groupId:t.groupId}))}static async getSpeakerList(){return(await vs.getDevices("audiooutput")).map((t,r)=>({...t,deviceId:t.deviceId,label:t.label||`speaker ${r+1}`,kind:t.kind,groupId:t.groupId}))}static async getCameraList(){return(await vs.getDevices("videoinput")).map((t,r)=>({...t,deviceId:t.deviceId,label:t.label||`camera ${r+1}`,kind:t.kind,groupId:t.groupId}))}static stopStreamTracks(e){e&&e.getTracks().forEach(t=>{t.stop()})}static async getMediaFromInputs({videoInput:e,audioInput:t}){let r,l;e==="default"?r=!0:e&&e!=="default"&&(r={deviceId:{exact:e}}),t==="default"?l=!0:t&&t!=="default"&&(l={deviceId:{exact:t}});const s={audio:l,video:r};return vs.getUserMedia(s)}static async getUserMedia(e){return await navigator.mediaDevices.getUserMedia(e)}static async changeAudioOutput(e,t){if(!(!e||!t))if(typeof e.sinkId<"u")try{await e.setSinkId(t)}catch(r){let l=r;r.name==="SecurityError"&&(l=`You need to use HTTPS for selecting audio output device: ${r}`),console.error(l)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(e){const t=e.getAudioTracks();if(t.length!==0)return t.forEach(r=>{r.enabled=!r.enabled}),t[0].enabled}static toggleVideoMute(e){const t=e.getVideoTracks();if(t.length!==0)return t.forEach(r=>{r.enabled=!r.enabled}),t[0].enabled}static async getStream(e={video:!0,audio:!0}){try{const t=await navigator.mediaDevices.getUserMedia(e);let r=t.getTracks();return e.video?r=t.getVideoTracks():e.audio&&(r=t.getAudioTracks()),r.length===0?{stream:t,track:null}:{stream:t,track:r[0]}}catch(t){return console.warn(t),{stream:null,track:null}}}}var rS=Xs();const _i=nt(rS),Jt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},re=new Au("JanusSession"),lS="/opt/recordings/",oe={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},Po=["audio","video"];class du extends It.EventEmitter{static get C(){return oe}constructor(e){re.debug("new"),super(),this._id=null,this._ua=e,this._status=oe.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:Z.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 oe}get causes(){return Z.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(e){this._data=e}get status(){return this._status}isInProgress(){switch(this._status){case oe.STATUS_NULL:case oe.STATUS_INVITE_SENT:case oe.STATUS_1XX_RECEIVED:case oe.STATUS_INVITE_RECEIVED:case oe.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case oe.STATUS_ANSWERED:case oe.STATUS_WAITING_FOR_ACK:case oe.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case oe.STATUS_CANCELED:case oe.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(e){return`PTYPE: ${e}`}generateOpaqueId(){return`videoroomtest-${H_().replace(/-/g,"").slice(0,12)}`}connect(e,t,r={},l){re.debug("connect()"),this.display_name=t;const s=e,i=je.cloneObject(r.eventHandlers),f=je.cloneArray(r.extraHeaders),h=je.cloneObject(r.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const d=r.mediaStream||null,p=je.cloneObject(r.pcConfig,{iceServers:[]}),v=r.rtcConstraints||null,T=r.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=r.rtcAnswerConstraints||null,this._data=r.data||this._data,e===void 0)throw new TypeError("Not enough arguments");if(this._status!==oe.STATUS_NULL)throw new Cn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Cn.NotSupportedError("WebRTC not supported");if(e=this._ua.normalizeTarget(e),this.room_id=e.user,this.target=e,!e)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&je.isDecimal(r.sessionTimersExpires)&&(r.sessionTimersExpires>=Z.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=r.sessionTimersExpires:this._sessionTimers.defaultExpires=Z.SESSION_EXPIRES);for(const A in i)Object.prototype.hasOwnProperty.call(i,A)&&this.on(A,i[A]);this._from_tag=je.newTag();const y=r.anonymous||!1,S={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(S.from_display_name="Anonymous",S.from_uri=new _i("sip","anonymous","anonymous.invalid"),f.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),f.push("Privacy: id")):r.fromUserName&&(S.from_uri=new _i("sip",r.fromUserName,this._ua.configuration.uri.host),f.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),r.fromDisplayName&&(S.from_display_name=r.fromDisplayName),f.push(`Contact: ${this._contact}`),f.push("Content-Type: application/json"),this._sessionTimers.enabled&&f.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new $t.InitialOutgoingInviteRequest(e,this._ua,S,f),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(p,v),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,l&&l(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,T,d)}_overrideSenderTracks(e,t){e.getTracks().forEach(r=>{t.getSenders().forEach(async s=>{s.track.kind===r.kind&&(r.kind==="audio"&&!this.isAudioOn&&(r.enabled=!1),r.kind==="video"&&!this.isVideoOn&&(r.enabled=!1),await s.replaceTrack(r))})})}init_incoming(e,t){re.debug("init_incoming()");let r;const l=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;if(e.body&&l!=="application/sdp"){e.reply(415);return}if(this._status=oe.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(r=e.getHeader("expires")*1e3),e.to_tag=je.newTag(),!this._createDialog(e,"UAS",!0)){e.reply(500,"Missing Contact header field");return}e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=oe.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{e.reply(408),this._failed("local",null,Z.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),r&&(this._timers.expiresTimer=setTimeout(()=>{this._status===oe.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),this._failed("system",null,Z.causes.EXPIRES))},r)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newJanusSession("remote",e),this._status!==oe.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(e={}){re.debug("answer()");const t=this._request,r=je.cloneArray(e.extraHeaders),l=je.cloneObject(e.mediaConstraints),s=e.mediaStream||null,i=je.cloneObject(e.pcConfig,{iceServers:[]}),f=e.rtcConstraints||null,h=e.rtcAnswerConstraints||null,d=je.cloneObject(e.rtcOfferConstraints);let p,v=!1,T=!1,y=!1,S=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=e.rtcOfferConstraints||null,this._data=e.data||this._data,this._direction!=="incoming")throw new Cn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==oe.STATUS_WAITING_FOR_ANSWER)throw new Cn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&je.isDecimal(e.sessionTimersExpires)&&(e.sessionTimersExpires>=Z.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=e.sessionTimersExpires:this._sessionTimers.defaultExpires=Z.SESSION_EXPIRES),this._status=oe.STATUS_ANSWERED,!this._createDialog(t,"UAS")){t.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),r.unshift(`Contact: ${this._contact}`);const A=t.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const R of A.media)R.type==="audio"&&(v=!0,(!R.direction||R.direction==="sendrecv")&&(y=!0)),R.type==="video"&&(T=!0,(!R.direction||R.direction==="sendrecv")&&(S=!0));if(s&&l.audio===!1){p=s.getAudioTracks();for(const R of p)s.removeTrack(R)}if(s&&l.video===!1){p=s.getVideoTracks();for(const R of p)s.removeTrack(R)}!s&&l.audio===void 0&&(l.audio=y),!s&&l.video===void 0&&(l.video=S),!s&&!v&&!d.offerToReceiveAudio&&(l.audio=!1),!s&&!T&&!d.offerToReceiveVideo&&(l.video=!1),this._createRTCConnection(i,f),Promise.resolve().then(()=>{if(s)return s;if(l.audio||l.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(R=>{throw this._status===oe.STATUS_TERMINATED?new Error("terminated"):(t.reply(480),this._failed("local",null,Z.causes.USER_DENIED_MEDIA_ACCESS),re.warn('emit "getusermediafailed" [error:%o]',R),this.emit("getusermediafailed",R),new Error("getUserMedia() failed"))})}).then(R=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=R,R&&R.getTracks().forEach(O=>{this._connection.addTrack(O,R)})}).then(()=>{if(this._late_sdp)return;const R={originator:"remote",type:"offer",sdp:t.body};re.debug('emit "sdp"'),this.emit("sdp",R);const O=new RTCSessionDescription({type:"offer",sdp:R.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(O)).catch(N=>{throw t.reply(488),this._failed("system",null,Z.causes.WEBRTC_ERROR),re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',N),this.emit("peerconnection:setremotedescriptionfailed",N),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(t),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw t.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw t.reply(500),new Error("_createLocalDescription() failed")})}).then(R=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(t,r),t.reply(200,null,r,R,()=>{this._status=oe.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,R),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,Z.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==oe.STATUS_TERMINATED&&re.warn(R)})}terminate(e={}){re.debug("terminate()");const t=e.cause||Z.causes.BYE,r=je.cloneArray(e.extraHeaders),l=e.body;let s,i=e.status_code,f=e.reason_phrase;if(this._status===oe.STATUS_TERMINATED)throw new Cn.InvalidStateError(this._status);switch(this._status){case oe.STATUS_NULL:case oe.STATUS_INVITE_SENT:case oe.STATUS_1XX_RECEIVED:if(re.debug("canceling session"),i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);i&&(f=f||Z.REASON_PHRASE[i]||"",s=`SIP ;cause=${i} ;text="${f}"`),this._status===oe.STATUS_NULL||this._status===oe.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===oe.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=oe.STATUS_CANCELED,this._failed("local",null,Z.causes.CANCELED);break;case oe.STATUS_WAITING_FOR_ANSWER:case oe.STATUS_ANSWERED:if(re.debug("rejecting session"),i=i||480,i<300||i>=700)throw new TypeError(`Invalid status_code: ${i}`);this._request.reply(i,f,r,l),this._failed("local",null,Z.causes.REJECTED);break;case oe.STATUS_WAITING_FOR_ACK:case oe.STATUS_CONFIRMED:if(re.debug("terminating session"),f=e.reason_phrase||Z.REASON_PHRASE[i]||"",i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);if(i&&r.push(`Reason: SIP ;cause=${i}; text="${f}"`),this._status===oe.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==cs.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:d})=>{d===Z.ACK&&(this.sendRequest(Z.BYE,{extraHeaders:r,body:l}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===cs.C.STATUS_TERMINATED&&(this.sendRequest(Z.BYE,{extraHeaders:r,body:l}),h.terminate(),this.closeSession())}),this._ended("local",null,t),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},d=["Content-Type: application/json",this.getPTypeHeader(Jt.LEAVE)];this.sendRequest(Z.BYE,{extraHeaders:d,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,t)}}}configureMedia(e){this.isAudioOn=e.audio,this.isVideoOn=e.video}enableAudio(e){const t={janus:"message",body:{audio:e},handle_id:this.handle_id,session_id:this.session_id},r=["Content-Type: application/json",this.getPTypeHeader(Jt.AUDIO_CHANGE)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t),eventHandlers:{onSuccessResponse:async l=>{l.status_code===200&&(this._ua.emit("changeAudioState",e),this.sendStateMessage({audio:e}))}}})}startAudio(){vs.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){vs.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(e){const t={janus:"message",body:{video:e},handle_id:this.handle_id,session_id:this.session_id},r=["Content-Type: application/json",this.getPTypeHeader(Jt.VIDEO_CHANGE)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t),eventHandlers:{onSuccessResponse:async l=>{l.status_code===200&&(this._ua.emit("changeVideoState",e),this.sendStateMessage({video:e}))}}})}startVideo(){vs.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){vs.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(e){const t={janus:"message",body:{request:"state",data:e},handle_id:this.handle_id,session_id:this.session_id},r=["Content-Type: application/json",this.getPTypeHeader(Jt.STATE)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t)})}sendInfo(e,t,r={}){if(re.debug("sendInfo()"),this._status!==oe.STATUS_CONFIRMED&&this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_1XX_RECEIVED)throw new Cn.InvalidStateError(this._status);new af(this).send(e,t,r)}mute(e={audio:!0,video:!1}){re.debug("mute()");let t=!1,r=!1;this._audioMuted===!1&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&e.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(t===!0||r===!0)&&this._onmute({audio:t,video:r})}unmute(e={audio:!0,video:!0}){re.debug("unmute()");let t=!1,r=!1;this._audioMuted===!0&&e.audio&&(t=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&e.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(t===!0||r===!0)&&this._onunmute({audio:t,video:r})}hold(e={},t){if(re.debug("hold()"),this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const r={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Z.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:e.extraHeaders}),!0}unhold(e={},t){if(re.debug("unhold()"),this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const r={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Z.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:e.extraHeaders}),!0}renegotiate(e={},t){re.debug("renegotiate()");const r=e.rtcOfferConstraints||null;if(this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const l={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:Z.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,rtcOfferConstraints:r,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:l,rtcOfferConstraints:r,extraHeaders:e.extraHeaders}),!0}refer(e,t){re.debug("refer()");const r=e;if(this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED)return!1;if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${r}`);const l=new sy(this);l.sendRefer(e,t);const s=l.id;return this._referSubscribers[s]=l,l.on("requestFailed",()=>{delete this._referSubscribers[s]}),l.on("accepted",()=>{delete this._referSubscribers[s]}),l.on("failed",()=>{delete this._referSubscribers[s]}),l}sendRequest(e,t){return re.debug("sendRequest()"),this._dialog.sendRequest(e,t)}receiveNotify(e){re.debug("receiveRequest()")}receiveRequest(e){if(re.debug("receiveRequest()"),e.method===Z.CANCEL)(this._status===oe.STATUS_WAITING_FOR_ANSWER||this._status===oe.STATUS_ANSWERED)&&(this._status=oe.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,Z.causes.CANCELED));else switch(e.method){case Z.ACK:if(this._status!==oe.STATUS_WAITING_FOR_ACK)return;if(this._status=oe.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:Z.causes.MISSING_SDP,status_code:400});break}const t={originator:"remote",type:"answer",sdp:e.body};re.debug('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>{this._is_confirmed||this._confirmed("remote",e)}).catch(l=>{this.terminate({cause:Z.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)})}else this._is_confirmed||this._confirmed("remote",e);break;case Z.BYE:this._status===oe.STATUS_CONFIRMED||this._status===oe.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,Z.causes.BYE)):this._status===oe.STATUS_INVITE_RECEIVED||this._status===oe.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,Z.causes.BYE)):e.reply(403,"Wrong Status");break;case Z.INVITE:this._status===oe.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case Z.INFO:if(this._status===oe.STATUS_1XX_RECEIVED||this._status===oe.STATUS_WAITING_FOR_ANSWER||this._status===oe.STATUS_ANSWERED||this._status===oe.STATUS_WAITING_FOR_ACK||this._status===oe.STATUS_CONFIRMED){const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;t&&t.match(/^application\/dtmf-relay/i)?new qT(this).init_incoming(e):t!==void 0?new af(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case Z.UPDATE:this._status===oe.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case Z.REFER:this._status===oe.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case Z.NOTIFY:this._status===oe.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}onTransportError(){re.warn("onTransportError()"),this._status!==oe.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Z.causes.CONNECTION_ERROR,cause:Z.causes.CONNECTION_ERROR})}onRequestTimeout(){re.warn("onRequestTimeout()"),this._status!==oe.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:Z.causes.REQUEST_TIMEOUT,cause:Z.causes.REQUEST_TIMEOUT})}onDialogError(){re.warn("onDialogError()"),this._status!==oe.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Z.causes.DIALOG_ERROR,cause:Z.causes.DIALOG_ERROR})}newDTMF(e){re.debug("newDTMF()"),this.emit("newDTMF",e)}newInfo(e){re.debug("newInfo()"),this.emit("newInfo",e)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(re.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(re.debug("_isReadyToReOffer() | session not established yet"),!1):(re.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(re.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(re.debug("close() | closing local MediaStream"),je.closeMediaStream(this._localMediaStream)),this._status!==oe.STATUS_TERMINATED){if(this._status=oe.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){re.warn("close() | error closing the RTCPeerConnection: %o",e)}for(const e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const e in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,e)&&(this._earlyDialogs[e].terminate(),delete this._earlyDialogs[e]);for(const e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(e,t){let r=Yl.T1;function l(){this._status===oe.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),r<Yl.T2&&(r=r*2,r>Yl.T2&&(r=Yl.T2)),this._timers.invite2xxTimer=setTimeout(l.bind(this),r))}this._timers.invite2xxTimer=setTimeout(l.bind(this),r)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===oe.STATUS_WAITING_FOR_ACK&&(re.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(Z.BYE),this._ended("remote",null,Z.causes.NO_ACK))},Yl.TIMER_H)}_createRTCConnection(e,t){this.stunServers,this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:Z.causes.RTP_TIMEOUT,status_code:408,reason_phrase:Z.causes.RTP_TIMEOUT})});let r;const l=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(r),r=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=l,re.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(e,t){if(re.debug("createLocalDescription()"),e!=="offer"&&e!=="answer")throw new Error(`createLocalDescription() | invalid type "${e}"`);const r=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>e==="offer"?r.createOffer(t).catch(l=>(re.warn('emit "peerconnection:createofferfailed" [error:%o]',l),this.emit("peerconnection:createofferfailed",l),Promise.reject(l))):r.createAnswer(t).catch(l=>(re.warn('emit "peerconnection:createanswerfailed" [error:%o]',l),this.emit("peerconnection:createanswerfailed",l),Promise.reject(l)))).then(l=>(this.jsepOffer=l,r.setLocalDescription(l).catch(s=>(this._rtcReady=!0,re.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const l=t&&t.iceRestart;if(r.iceGatheringState==="complete"&&!l||r.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:e,sdp:r.localDescription.sdp};return re.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let i=!1,f,h;this._iceReady=!1;const d=()=>{r.removeEventListener("icecandidate",f),r.removeEventListener("icegatheringstatechange",h),i=!0,this._rtcReady=!0,this._iceReady=!0;const p={originator:"local",type:e,sdp:r.localDescription.sdp};re.debug('emit "sdp"'),this.emit("sdp",p),s(p.sdp)};r.addEventListener("icecandidate",f=p=>{const v=p.candidate;v?this.emit("icecandidate",{candidate:v,ready:d}):i||d()}),r.addEventListener("icegatheringstatechange",h=()=>{r.iceGatheringState==="complete"&&!i&&d()})})})}_createDialog(e,t,r){const l=t==="UAS"?e.to_tag:e.from_tag,s=t==="UAS"?e.from_tag:e.to_tag,i=e.call_id+l+s;let f=this._earlyDialogs[i];if(r)return f?!0:(f=new No(this,e,t,No.C.STATUS_EARLY),f.error?(re.debug(f.error),this._failed("remote",e,Z.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=f,!0));{if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,f)return f.update(e,t),this._dialog=f,delete this._earlyDialogs[i],!0;const h=new No(this,e,t);return h.error?(re.debug(h.error),this._failed("remote",e,Z.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(e){re.debug("receiveReinvite()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:s.bind(this)};let l=!1;function s(f={}){l=!0;const h=f.status_code||403,d=f.reason_phrase||"",p=je.cloneArray(f.extraHeaders);if(this._status!==oe.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);e.reply(h,d,p)}if(this.emit("reinvite",r),l)return;if(this._late_sdp=!1,!e.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(f=>{i.call(this,f)}).catch(()=>{e.reply(500)});return}if(t!=="application/sdp"){re.debug("invalid Content-Type"),e.reply(415);return}this._processInDialogSdpOffer(e).then(f=>{this._status!==oe.STATUS_TERMINATED&&i.call(this,f)}).catch(f=>{re.warn(f)});function i(f){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,h),this._late_sdp&&(f=this._mangleOffer(f)),e.reply(200,null,h,f,()=>{this._status=oe.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(e,f),this._setACKTimer()}),typeof r.callback=="function"&&r.callback()}}_receiveUpdate(e){re.debug("receiveUpdate()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:s.bind(this)};let l=!1;function s(f={}){l=!0;const h=f.status_code||403,d=f.reason_phrase||"",p=je.cloneArray(f.extraHeaders);if(this._status!==oe.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);e.reply(h,d,p)}if(this.emit("update",r),l)return;if(!e.body){i.call(this,null);return}if(t!=="application/sdp"){re.debug("invalid Content-Type"),e.reply(415);return}this._processInDialogSdpOffer(e).then(f=>{this._status!==oe.STATUS_TERMINATED&&i.call(this,f)}).catch(f=>{re.warn(f)});function i(f){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,h),e.reply(200,null,h,f),typeof r.callback=="function"&&r.callback()}}_processInDialogSdpOffer(e){re.debug("_processInDialogSdpOffer()");const t=e.parseSDP();let r=!1;for(const i of t.media){if(Po.indexOf(i.type)===-1)continue;const f=i.direction||t.direction||"sendrecv";if(f==="sendonly"||f==="inactive")r=!0;else{r=!1;break}}const l={originator:"remote",type:"offer",sdp:e.body};re.debug('emit "sdp"'),this.emit("sdp",l);const s=new RTCSessionDescription({type:"offer",sdp:l.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(i=>{throw e.reply(488),re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',i),this.emit("peerconnection:setremotedescriptionfailed",i),i})}).then(()=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&r===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&r===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(i=>{throw e.reply(500),re.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',i),i})}).catch(i=>{re.warn("_processInDialogSdpOffer() failed [error: %o]",i)}),this._connectionPromiseQueue}_receiveRefer(e){if(re.debug("receiveRefer()"),!e.refer_to){re.debug("no Refer-To header field present in REFER"),e.reply(400);return}if(e.refer_to.uri.scheme!==Z.SIP){re.debug("Refer-To header field points to a non-SIP URI scheme"),e.reply(416);return}e.reply(202);const t=new QT(this,e.cseq);re.debug('emit "refer"'),this.emit("refer",{request:e,accept:(s,i)=>{r.call(this,s,i)},reject:()=>{l.call(this)}});function r(s,i={}){if(s=typeof s=="function"?s:null,this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED)return!1;const f=new du(this._ua);if(f.on("progress",({response:h})=>{t.notify(h.status_code,h.reason_phrase)}),f.on("accepted",({response:h})=>{t.notify(h.status_code,h.reason_phrase)}),f.on("_failed",({message:h,cause:d})=>{h?t.notify(h.status_code,h.reason_phrase):t.notify(487,d)}),e.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));i.extraHeaders=je.cloneArray(i.extraHeaders),i.extraHeaders.push(`Replaces: ${h}`)}f.connect(e.refer_to.uri.toAor(),i,s)}function l(){t.notify(603)}}_receiveNotify(e){switch(re.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":{let t,r;if(e.event.params&&e.event.params.id)t=e.event.params.id,r=this._referSubscribers[t];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{e.reply(400,"Missing event id parameter");return}if(!r){e.reply(481,"Subscription does not exist");return}r.receiveNotify(e),e.reply(200);break}default:e.reply(489)}}_receiveReplaces(e){re.debug("receiveReplaces()");function t(l){if(this._status!==oe.STATUS_WAITING_FOR_ACK&&this._status!==oe.STATUS_CONFIRMED)return!1;const s=new du(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(e,l)}function r(){re.debug("Replaced INVITE rejected by the user"),e.reply(486)}this.emit("replaces",{request:e,accept:l=>{t.call(this,l)},reject:()=>{r.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(e,t,r){this.ackSent=!1,this.publisherSubscribeSent=!1;const l=new pa(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(r)return r;if(e.audio||e.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===oe.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,Z.causes.USER_DENIED_MEDIA_ACCESS),re.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===oe.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(i=>{this._connection.addTrack(i,s)}),this._connecting(this._request),this._createLocalDescription("offer",t).catch(i=>{throw this._failed("local",null,Z.causes.WEBRTC_ERROR),i})}).then(s=>{if(this._is_canceled||this._status===oe.STATUS_TERMINATED)throw new Error("terminated");const i={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},f=JSON.stringify(i);this._request.body=f,this._status=oe.STATUS_INVITE_SENT,re.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),l.send()}).catch(s=>{this._status!==oe.STATUS_TERMINATED&&re.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(e){this.mediaConstraints={...e},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const e={};this.isAudioOn?this.mediaConstraints.audio?e.audio=this.mediaConstraints.audio:e.audio=!0:e.audio=!1,this.isVideoOn?this.mediaConstraints.video?e.video=this.mediaConstraints.video:e.video=!0:e.video=!1;let t=null;try{t=await navigator.mediaDevices.getUserMedia(e)}catch{try{e.video=!1,t=await navigator.mediaDevices.getUserMedia(e)}catch{e.audio=!1,e.video=!1,t=await navigator.mediaDevices.getUserMedia(e)}}return t}addTracks(e){this._connection.getSenders().forEach(t=>{this._connection.removeTrack(t)}),e.forEach(t=>{this._connection.addTrack(t)})}getRecordFileName(){return lS+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let e=0;e<this.iceCandidates.length;e++)await this._connection.addIceCandidate(this.iceCandidates[e]);this.iceCandidates=[]}async _sendConfigureMessage(e){const t=this._candidates.map(i=>({janus:"trickle",candidate:i,handle_id:this.handle_id,session_id:this.session_id})),l={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...e},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...t]},s=["Content-Type: application/json",this.getPTypeHeader(Jt.ICE)];this.sendRequest(Z.INFO,{extraHeaders:s,body:JSON.stringify(l),eventHandlers:{onSuccessResponse:async i=>{this.isConfigureSent=!0;const h=i.data.split(`\r
135
- `),d=h[h.length-1],p=JSON.parse(d);await this._connection.setRemoteDescription(p.jsep),this._candidates=[]}}})}_sendMemberStartMessage(e,t){const r={janus:"message",body:{request:"start",room:this.room_id},handle_id:e.handleId,session_id:this.session_id,jsep:t},l=["Content-Type: application/json",this.getPTypeHeader(Jt.CONFIGURE)];this.sendRequest(Z.INFO,{extraHeaders:l,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await e.rtcpPeer.setLocalDescription(t)}}})}_sendTrickleMessage(e){const r={trickles:[...e.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},l=[this.getPTypeHeader(Jt.TRICKLE)];this.sendRequest(Z.INFO,{extraHeaders:l,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(e,t){let r=null;const l=async h=>{if(!e.rtcpPeer||e.loaded)return;{e.loaded=!0;const y={audio:!0,video:!0};await new Promise(S=>{setTimeout(S,100)}),r=await e.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(e,r)}const d=h.streams[0].getAudioTracks(),p=h.streams[0].getVideoTracks(),v=[];d[0]&&v.push(d[0]),p[0]&&v.push(p[0]);const T=new MediaStream(v);e.stream=T,this._ua.emit("memberJoin",e.memberInfo)};let s,i=[];const f=h=>{e.rtcpPeer.signalingState!=="stable"&&e.rtcpPeer.signalingState!=="have-local-offer"||(i.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(i)},500))};e.rtcpPeer=new RTCPeerConnection,e.rtcpPeer.ontrack=l,e.rtcpPeer.onicecandidate=f,e.rtcpPeer.sender=t.sender,await e.rtcpPeer.setRemoteDescription(t.jsep)}_sendJoinMemberRequest(e){const t={janus:"message",body:{request:"join",room:this.room_id,feed:e.info.id,ptype:"subscriber"},handle_id:e.handleId,session_id:this.session_id},r=[this.getPTypeHeader(Jt.SUBSCRIBER)];this.sendRequest(Z.SUBSCRIBE,{extraHeaders:r,body:JSON.stringify(t),eventHandlers:{onSuccessResponse:async l=>{var s,i;if(l.status_code===200){const f=JSON.parse(l.body);(i=(s=f==null?void 0:f.plugindata)==null?void 0:s.data)!=null&&i.id&&await this._answerAttachedStream(e,f)}}}})}_attachMember(e){const t={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},r=[this.getPTypeHeader(Jt.SUBSCRIBER)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t),eventHandlers:{onSuccessResponse:async l=>{if(l.status_code===200){const i=JSON.parse(l.body).data.id;e.handleId=i,this._sendJoinMemberRequest(e)}}}})}_detachMember(e){const t={janus:"detach",handle_id:e.handleId,session_id:this.session_id},r=[this.getPTypeHeader(Jt.SUBSCRIBER)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t)}),vs.stopStreamTracks(e.memberInfo.stream),this._ua.emit("memberHangup",e.memberInfo)}receivePublishers(e){var r,l,s,i,f,h,d,p;const t={...this.memberList};(l=(r=e==null?void 0:e.plugindata)==null?void 0:r.data)==null||l.publishers.forEach(v=>{delete t[v.id],!this.memberList[v.id]&&!this.myFeedList.includes(v.id)&&v.clientID!==this.client_id&&(this.memberList[v.id]=new iS(v,this),this._attachMember(this.memberList[v.id]))}),((i=(s=e==null?void 0:e.plugindata)==null?void 0:s.data)==null?void 0:i.videoroom)==="synced"&&Object.keys(t).forEach(v=>{t[v].hangup(),delete this.memberList[v]}),this.publishers=(h=(f=e==null?void 0:e.plugindata)==null?void 0:f.data)==null?void 0:h.publishers,this.private_id=(p=(d=e==null?void 0:e.plugindata)==null?void 0:d.data)==null?void 0:p.private_id}receiveUnpublished(e){const t=this.memberList[e];t&&(t.hangup(),this._detachMember(t),delete this.memberList[e])}closeSession(){this.stream&&this.stream.getTracks().forEach(t=>{t.stop()}),Object.values(this.memberList).forEach(t=>{t.hangup(),this._detachMember(t)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const e=this._ua.processStreamPlugins;let t=await this.loadStream();for(const r of e)t=await r.process(t);this.stream.getTracks().forEach(r=>{this.stream.removeTrack(r),r.stop()}),t.getTracks().forEach(r=>{this.stream.addTrack(r)})}async resyncPlugins(e){const t=this._ua.processStreamPlugins.filter(r=>r.type===e);for(const r of t)r.running&&r.terminate();if(e==="video"){let r=await this.loadStream();for(const l of t)l.running&&(r=await l.start(r));this.stream.getTracks().forEach(l=>{this.stream.removeTrack(l),l.stop()}),r.getTracks().forEach(l=>{this.stream.addTrack(l)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const r=this._ua.newStreamPlugins.find(f=>f.type===e);let s=r.getStream().clone();for(const f of t)f.running&&(s=await f.start(s));const i=r.getConnection();this._overrideSenderTracks(s,i),this._ua.emit("changePluginStream",{type:e,stream:s})}}stopProcessPlugins(e){const t=this._ua.processStreamPlugins.filter(r=>r.type===e);for(const r of t)r.running&&r.kill()}_receiveInviteResponse(e){if(re.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag){this.ackSent=!0,this.sendRequest(Z.ACK);return}else{const t=new No(this,e,"UAC");if(t.error!==void 0){re.debug(t.error);return}this.sendRequest(Z.ACK),this.sendRequest(Z.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const t=JSON.parse(e.body);this.setupMediaStream().then(()=>{this.session_id=t.session_id,this.handle_id=t.data.id,this.client_id=H_();const r={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},l=[this.getPTypeHeader(Jt.PUBLISHER)];this.sendRequest(Z.SUBSCRIBE,{extraHeaders:l,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async s=>{var i,f,h,d;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const p=JSON.parse(s.body)||{};((f=(i=p.plugindata)==null?void 0:i.data)==null?void 0:f.videoroom)==="joined"&&this.myFeedList.push(p.plugindata.data.id),(d=(h=p.plugindata)==null?void 0:h.data)!=null&&d.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){e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);return}if(!(this._status!==oe.STATUS_INVITE_SENT&&this._status!==oe.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(e.status_code):this._status=oe.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):{if(!e.to_tag){re.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=oe.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}const t={originator:"remote",type:"answer",sdp:e.body};re.debug('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>this._progress("remote",e)).catch(l=>{re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)});break}case/^2[0-9]{2}$/.test(e.status_code):{if(this._status=oe.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,Z.causes.MISSING_SDP),this._failed("remote",e,Z.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;break}default:{const t=je.sipErrorCause(e.status_code);this._failed("remote",e,t)}}}_sendReinvite(e={}){re.debug("sendReinvite()");const t=je.cloneArray(e.extraHeaders),r=je.cloneObject(e.eventHandlers),l=e.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;t.push(`Contact: ${this._contact}`),t.push("Content-Type: application/sdp"),this._sessionTimers.running&&t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",l)).then(h=>{h=this._mangleOffer(h);const d={originator:"local",type:"offer",sdp:h};re.debug('emit "sdp"'),this.emit("sdp",d),this.sendRequest(Z.INVITE,{extraHeaders:t,body:h,eventHandlers:{onSuccessResponse:p=>{i.call(this,p),s=!0},onErrorResponse:p=>{f.call(this,p)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{f()});function i(h){if(this._status===oe.STATUS_TERMINATED||(this.sendRequest(Z.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){f.call(this);return}}else{f.call(this);return}const d={originator:"remote",type:"answer",sdp:h.body};re.debug('emit "sdp"'),this.emit("sdp",d);const p=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(p)).then(()=>{r.succeeded&&r.succeeded(h)}).catch(v=>{f.call(this),re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',v),this.emit("peerconnection:setremotedescriptionfailed",v)})}function f(h){r.failed&&r.failed(h)}}_sendUpdate(e={}){re.debug("sendUpdate()");const t=je.cloneArray(e.extraHeaders),r=je.cloneObject(e.eventHandlers),l=e.rtcOfferConstraints||this._rtcOfferConstraints||null,s=e.sdpOffer||!1;let i=!1;t.push(`Contact: ${this._contact}`),this._sessionTimers.running&&t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(t.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",l)).then(d=>{d=this._mangleOffer(d);const p={originator:"local",type:"offer",sdp:d};re.debug('emit "sdp"'),this.emit("sdp",p),this.sendRequest(Z.UPDATE,{extraHeaders:t,body:d,eventHandlers:{onSuccessResponse:v=>{f.call(this,v),i=!0},onErrorResponse:v=>{h.call(this,v)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(Z.UPDATE,{extraHeaders:t,eventHandlers:{onSuccessResponse:d=>{f.call(this,d)},onErrorResponse:d=>{h.call(this,d)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function f(d){if(this._status!==oe.STATUS_TERMINATED&&!i)if(this._handleSessionTimersInIncomingResponse(d),s){if(d.body){if(!d.hasHeader("Content-Type")||d.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const p={originator:"remote",type:"answer",sdp:d.body};re.debug('emit "sdp"'),this.emit("sdp",p);const v=new RTCSessionDescription({type:"answer",sdp:p.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(v)).then(()=>{r.succeeded&&r.succeeded(d)}).catch(T=>{h.call(this),re.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}else r.succeeded&&r.succeeded(d)}function h(d){r.failed&&r.failed(d)}}_acceptAndTerminate(e,t,r){re.debug("acceptAndTerminate()");const l=[];t&&(r=r||Z.REASON_PHRASE[t]||"",l.push(`Reason: SIP ;cause=${t}; text="${r}"`)),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(Z.ACK),this.sendRequest(Z.BYE,{extraHeaders:l})),this._status=oe.STATUS_TERMINATED}_mangleOffer(e){if(!this._localHold&&!this._remoteHold)return e;if(e=Qt.parse(e),this._localHold&&!this._remoteHold){re.debug("mangleOffer() | me on hold, mangling offer");for(const t of e.media)Po.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="sendonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="sendonly")}else if(this._localHold&&this._remoteHold){re.debug("mangleOffer() | both on hold, mangling offer");for(const t of e.media)Po.indexOf(t.type)!==-1&&(t.direction="inactive")}else if(this._remoteHold){re.debug("mangleOffer() | remote on hold, mangling offer");for(const t of e.media)Po.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="recvonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="recvonly")}return Qt.write(e)}_setLocalMediaStatus(){let e=!0,t=!0;(this._localHold||this._remoteHold)&&(e=!1,t=!1),this._audioMuted&&(e=!1),this._videoMuted&&(t=!1),this._toggleMuteAudio(!e),this._toggleMuteVideo(!t)}_handleSessionTimersInIncomingRequest(e,t){if(!this._sessionTimers.enabled)return;let r;e.session_expires&&e.session_expires>=Z.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,r=e.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${r}`),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(e){if(!this._sessionTimers.enabled)return;let t;e.session_expires&&e.session_expires>=Z.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher=t==="uac",this._runSessionTimer()}_runSessionTimer(){const e=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==oe.STATUS_TERMINATED&&this._isReadyToReOffer()&&(re.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===Z.UPDATE?this._sendUpdate():this._sendReinvite())},e*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==oe.STATUS_TERMINATED&&(re.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:Z.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},e*1100)}_toggleMuteAudio(e){const t=this._connection.getSenders().filter(r=>r.track&&r.track.kind==="audio");for(const r of t)r.track.enabled=!e}_toggleMuteVideo(e){const t=this._connection.getSenders().filter(r=>r.track&&r.track.kind==="video");for(const r of t)r.track.enabled=!e}_newJanusSession(e,t){re.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:e,session:this,request:t})}_connecting(e){re.debug("session connecting"),re.debug('emit "connecting"'),this.emit("connecting",{request:e})}_progress(e,t){re.debug("session progress"),re.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}_accepted(e,t){re.debug("session accepted"),this._start_time=new Date,re.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}_confirmed(e,t){re.debug("session confirmed"),this._is_confirmed=!0,re.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}_ended(e,t,r){re.debug("session ended"),this._end_time=new Date,this._close(),re.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:r})}_failed(e,t,r){re.debug("session failed"),re.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:r}),this._close(),re.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:r})}_onhold(e){re.debug("session onhold"),this._setLocalMediaStatus(),re.debug('emit "hold"'),this.emit("hold",{originator:e})}_onunhold(e){re.debug("session onunhold"),this._setLocalMediaStatus(),re.debug('emit "unhold"'),this.emit("unhold",{originator:e})}_onmute({audio:e,video:t}){re.debug("session onmute"),this._setLocalMediaStatus(),re.debug('emit "muted"'),this.emit("muted",{audio:e,video:t})}_onunmute({audio:e,video:t}){re.debug("session onunmute"),this._setLocalMediaStatus(),re.debug('emit "unmuted"'),this.emit("unmuted",{audio:e,video:t})}}class lr{constructor(e){if(this.headers={},e.length>0){let t=!1;const r=e.split(`\r
136
- `),l=r.shift().split(/\s/);this.protocol=l[0],this.ident=l[1],this.code=l.length>3?parseInt(l[2]):0,this.method=l.length>3?l[3]:l[2],this.body="";for(const s of r){if(s==`-------${this.ident}$`)break;if(s===""){t=!0;continue}if(s&&t)this.body+=`${s}\r
137
- `;else{const i=s.split(": ");this.addHeader(i[0],i[1].trim())}}}else this.ident=je.createRandomToken(12),this.protocol="MSRP"}addHeader(e,t){this.headers[e]=t}getHeader(e){return this.headers[e]}toString(){let e=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
- `;for(const t in this.headers)e+=`${t}: ${this.headers[t]}\r
139
- `;return this.body&&(e+=`\r
124
+ ${t}
125
+ `);this.ondata({transport:this,message:t})}};const eT=ze(yh);var Ah={};const tT=ut,Cu=Zt(),Ru=yt,ia=new tT("Parser");Ah.parseMessage=(c,t)=>{let n,a,o=c.indexOf(`\r
126
+ `);if(o===-1){ia.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=Cu.parse(s,"Request_Response");if(r===-1){ia.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new Ru.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new Ru.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=sT(c,d),o===-2){a=d+2;break}else if(o===-1){ia.warn("parseMessage() | malformed message");return}if(r=nT(n,c,d,o),r!==!0){ia.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){const h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function sT(c,t){let n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
127
+ `,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function nT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Cu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Cu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof Ru.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const rT=ut,Ch=De,Cf=yt,Vu=At(),Bu=new rT("sanityCheck"),iT=[_T],lT=[oT,uT,cT,fT],aT=[hT,dT];let Fe,is,Rh;var Ih=(c,t,n)=>{Fe=c,is=t,Rh=n;for(const a of iT)if(a()===!1)return!1;if(Fe instanceof Cf.IncomingRequest){for(const a of lT)if(a()===!1)return!1}else if(Fe instanceof Cf.IncomingResponse){for(const a of aT)if(a()===!1)return!1}return!0};function oT(){if(Fe.s("to").uri.scheme!=="sip")return nl(416),!1}function uT(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===is.configuration.jssip_id)return nl(482),!1}function cT(){const c=Vu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return nl(400),!1}function fT(){const c=Fe.from_tag,t=Fe.call_id,n=Fe.cseq;let a;if(!Fe.to_tag)if(Fe.method===Ch.INVITE){if(is._transactions.ist[Fe.via_branch])return!1;for(const o in is._transactions.ist)if(Object.prototype.hasOwnProperty.call(is._transactions.ist,o)&&(a=is._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return nl(482),!1}else{if(is._transactions.nist[Fe.via_branch])return!1;for(const o in is._transactions.nist)if(Object.prototype.hasOwnProperty.call(is._transactions.nist,o)&&(a=is._transactions.nist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return nl(482),!1}}function hT(){if(Fe.getHeaders("via").length>1)return Bu.debug("more than one Via header field present in the response, dropping the response"),!1}function dT(){const c=Vu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return Bu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function _T(){const c=["from","to","call_id","cseq","via"];for(const t of c)if(!Fe.hasHeader(t))return Bu.debug(`missing mandatory header field : ${t}, dropping the response`),!1}function nl(c){const t=Fe.getHeaders("via");let n,a=`SIP/2.0 ${c} ${Ch.REASON_PHRASE[c]}\r
128
+ `;for(const o of t)a+=`Via: ${o}\r
129
+ `;n=Fe.getHeader("To"),Fe.to_tag||(n+=`;tag=${Vu.newTag()}`),a+=`To: ${n}\r
130
+ `,a+=`From: ${Fe.getHeader("From")}\r
131
+ `,a+=`Call-ID: ${Fe.call_id}\r
132
+ `,a+=`CSeq: ${Fe.cseq} ${Fe.method}\r
133
+ `,a+=`\r
134
+ `,Rh.send(a)}const pT=ze(Ih);var rl={};const hr=At(),An=De,Jo=Zt(),Rf=ys(),zo=qu,Xo=As;rl.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:An.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:An.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:An.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${hr.createRandomToken(12)}.invalid`};const la={mandatory:{sockets(c){const t=[];if(zo.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&zo.isSocket(n.socket)?t.push(n):zo.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${An.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(Jo.parse(`"${c}"`,"quoted_string")!==-1)return c},authorization_jwt(c){if(typeof c=="string")return c},user_agent(c){if(typeof c=="string")return c},connection_recovery_max_interval(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=Jo.parse(c,"SIP_URI");if(t!==-1)return t}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),Jo.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===An.INVITE||c===An.UPDATE))return c},session_timers_force_refresher(c){if(typeof c=="boolean")return c},password(c){return String(c)},realm(c){return String(c)},ha1(c){return String(c)},register(c){if(typeof c=="boolean")return c},register_expires(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${An.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?void 0:t},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const t=[];if(Array.isArray(c)&&c.length)for(const n of c)typeof n=="string"&&t.push(n);else return;return t}}};rl.load=(c,t)=>{for(const n in la.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=la.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Xo.ConfigurationError(n,a)}else throw new Xo.ConfigurationError(n);for(const n in la.optional)if(t.hasOwnProperty(n)){const a=t[n];if(hr.isEmpty(a))continue;const o=la.optional[n](a);if(o!==void 0)c[n]=o;else throw new Xo.ConfigurationError(n,a)}};const mT=ft.EventEmitter,gT=ut,mt=De,TT=lg,If=Sh,bf=Bg,wf=Jg,Qo=Tr,vT=yh,aa=At(),ET=As,ST=ys(),yT=Ah,Zo=yt,AT=Ih,eu=rl,qe=new gT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var bh=class extends mT{static get C(){return vt}constructor(t){if(qe.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},eu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=vt.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,t===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(t)}catch(n){throw this._status=vt.STATUS_NOT_READY,this._error=vt.CONFIGURATION_ERROR,n}this._registrator=new TT(this)}get C(){return vt}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){qe.debug("start()"),this._status===vt.STATUS_INIT?this._transport.connect():this._status===vt.STATUS_USER_CLOSED?(qe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=vt.STATUS_INIT,this._transport.connect()):this._status===vt.STATUS_READY?qe.debug("UA is in READY status, not restarted"):qe.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){qe.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(t){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(t)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(t,n){qe.debug("call()");const a=new If(this);return a.connect(t,n),a}sendMessage(t,n,a){qe.debug("sendMessage()");const o=new bf(this);return o.send(t,n,a),o}sendOptions(t,n,a){qe.debug("sendOptions()");const o=new wf(this);return o.send(t,n,a),o}terminateSessions(t){qe.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){qe.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch{}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch{}this._status=vt.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return aa.normalizeTarget(t,this._configuration.hostport_params)}get(t){switch(t){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:qe.warn('get() | cannot get "%s" parameter in runtime',t);return}}set(t,n){switch(t){case"authorization_user":{this._configuration.authorization_user=String(n);break}case"password":{this._configuration.password=String(n);break}case"realm":{this._configuration.realm=String(n);break}case"ha1":{this._configuration.ha1=String(n),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(n);break}case"display_name":{this._configuration.display_name=n;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',t),!1}return!0}newTransaction(t){this._transactions[t.type][t.id]=t,this.emit("newTransaction",{transaction:t})}destroyTransaction(t){delete this._transactions[t.type][t.id],this.emit("transactionDestroyed",{transaction:t})}newDialog(t){this._dialogs[t.id]=t}destroyDialog(t){delete this._dialogs[t.id]}newMessage(t,n){this._applicants[t]=t,this.emit("newMessage",n)}newOptions(t,n){this._applicants[t]=t,this.emit("newOptions",n)}destroyMessage(t){delete this._applicants[t]}newRTCSession(t,n){this._sessions[t.id]=t,this.emit("newRTCSession",n)}destroyRTCSession(t){delete this._sessions[t.id]}registered(t){this.emit("registered",t)}unregistered(t){this.emit("unregistered",t)}registrationFailed(t){this.emit("registrationFailed",t)}receiveRequest(t){const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),t.method!==mt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===mt.SIPS){t.reply_sl(416);return}if(Qo.checkTransaction(this,t))return;if(n===mt.INVITE?new Qo.InviteServerTransaction(this,this._transport,t):n!==mt.ACK&&n!==mt.CANCEL&&new Qo.NonInviteServerTransaction(this,this._transport,t),n===mt.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new wf(this).init_incoming(t)}else if(n===mt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new bf(this).init_incoming(t)}else if(n===mt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a?a.receiveRequest(t):n===mt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(qe.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==mt.ACK&&t.reply(481);else switch(n){case mt.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const s=t.replaces;a=this._findDialog(s.call_id,s.from_tag,s.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else o=new If(this),o.init_incoming(t);else qe.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case mt.BYE:t.reply(481);break;case mt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):qe.debug("received CANCEL request for a non existent session");break;case mt.ACK:break;case mt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){try{eu.load(this._configuration,t)}catch(o){throw o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=aa.newUUID()),this._configuration.jssip_id=aa.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new vT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=CT.bind(this),this._transport.onconnect=RT.bind(this),this._transport.ondisconnect=IT.bind(this),this._transport.ondata=bT.bind(this)}catch(o){throw qe.warn(o),new ET.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const o=this._configuration.uri.clone();o.user=null,o.clearParams(),o.clearHeaders(),this._configuration.registrar_server=o}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ST("sip",aa.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(o={}){const s=o.anonymous||null,r=o.outbound||null;let d="<";return s?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(a.indexOf(o)!==-1?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:");for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(eu.settings,o))switch(o){case"uri":case"registrar_server":qe.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${o}: NOT SHOWN`);break;default:qe.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}}};function CT(c){this.emit("connecting",c)}function RT(c){this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function IT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function bT(c){const t=c.transport;let n=c.message;if(n=yT.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof Zo.IncomingRequest)&&AT(n,this,t)){if(n instanceof Zo.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Zo.IncomingResponse){let a;switch(n.method){case mt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case mt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const wT=ze(bh);var _t=[];for(var tu=0;tu<256;++tu)_t.push((tu+256).toString(16).slice(1));function OT(c,t=0){return(_t[c[t+0]]+_t[c[t+1]]+_t[c[t+2]]+_t[c[t+3]]+"-"+_t[c[t+4]]+_t[c[t+5]]+"-"+_t[c[t+6]]+_t[c[t+7]]+"-"+_t[c[t+8]]+_t[c[t+9]]+"-"+_t[c[t+10]]+_t[c[t+11]]+_t[c[t+12]]+_t[c[t+13]]+_t[c[t+14]]+_t[c[t+15]]).toLowerCase()}var oa,DT=new Uint8Array(16);function NT(){if(!oa&&(oa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oa(DT)}var UT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Of={randomUUID:UT};function Df(c,t,n){if(Of.randomUUID&&!t&&!c)return Of.randomUUID();c=c||{};var a=c.random||(c.rng||NT)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=a[o];return t}return OT(a)}var ke=At();const Ts=ze(ke),su=new Ga("Dialog"),Fs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class ua{static get C(){return Fs}constructor(t,n,a,o=Fs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof yt.IncomingResponse&&(o=n.status_code<200?Fs.STATUS_EARLY:Fs.STATUS_CONFIRMED),a==="UAS"){this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(a==="UAC"){this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),su.debug(`new ${a} dialog created with status ${this._state===Fs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Fs.STATUS_TERMINATED}update(t,n){this._state=Fs.STATUS_CONFIRMED,su.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){su.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Fs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Ts.cloneArray(n.extraHeaders),o=Ts.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new hg(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===L.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===L.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Ts.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===L.CANCEL||t===L.ACK?this._local_seqnum:this._local_seqnum+=1;return new yt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===L.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===L.INVITE||t.method===L.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Gt.C.STATUS_ACCEPTED||t.server_transaction.state===Gt.C.STATUS_COMPLETED||t.server_transaction.state===Gt.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===L.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class PT{constructor(t,n){Kt(this,"plugin",null);Kt(this,"rtcpPeer",null);Kt(this,"handleId",0);Kt(this,"info",null);Kt(this,"joinResult",null);Kt(this,"state",{});Kt(this,"stream",null);Kt(this,"loaded",!1);Kt(this,"aTracks",[]);Kt(this,"vTracks",[]);this.info=t,this.plugin=n,this.rtcpPeer=new RTCPeerConnection({iceServers:[]})}get memberInfo(){return{stream:this.stream,joinResult:this.joinResult,sender:this.handleId,type:"subscriber",name:this.info.display,state:this.state,id:this.handleId}}updateMemberState(t){var n;this.state={...this.state,...t||{}},(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(t){var s,r,d,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publisher_state).find(_=>_.id===n);this.updateMemberState(o==null?void 0:o.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(t=>{t.stop()})}}class Qt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return Qt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await Qt.getDevices("audioinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Qt.getDevices("audiooutput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Qt.getDevices("videoinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${a+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(t){t&&t.getTracks().forEach(n=>{n.stop()})}static async getMediaFromInputs({videoInput:t,audioInput:n}){let a,o;t==="default"?a=!0:t&&t!=="default"&&(a={deviceId:{exact:t}}),n==="default"?o=!0:n&&n!=="default"&&(o={deviceId:{exact:n}});const s={audio:o,video:a};return Qt.getUserMedia(s)}static async getUserMedia(t){return await navigator.mediaDevices.getUserMedia(t)}static async changeAudioOutput(t,n){if(!(!t||!n))if(typeof t.sinkId<"u")try{await t.setSinkId(n)}catch(a){let o=a;a.name==="SecurityError"&&(o=`You need to use HTTPS for selecting audio output device: ${a}`),console.error(o)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let a=n.getTracks();return t.video?a=n.getVideoTracks():t.audio&&(a=n.getAudioTracks()),a.length===0?{stream:n,track:null}:{stream:n,track:a[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var xT=ys();const In=ze(xT),Pt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new Ga("JanusSession"),kT="/opt/recordings/",te={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},ca=["audio","video"];class $a extends ft.EventEmitter{static get C(){return te}constructor(t){z.debug("new"),super(),this._id=null,this._ua=t,this._status=te.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.lastTransaction=0,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._candidates=[],this.publishers=[],this.private_id=null,this.memberList={},this.myFeedList=[],this.display_name="",this.stunServers=[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}],this.opaque_id=this.generateOpaqueId(),this.screen_share_opaque_id=this.generateOpaqueId(),this._data={},this.isAudioOn=!0,this.isVideoOn=!0,this.mediaConstraints={}}get C(){return te}get causes(){return L.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(t){return`PTYPE: ${t}`}generateOpaqueId(){return`videoroomtest-${Df().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=ke.cloneObject(a.eventHandlers),d=ke.cloneArray(a.extraHeaders),h=ke.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=ke.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,E=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new qs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new qs.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),this.room_id=t.user,this.target=t,!t)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&ke.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES);for(const C in r)Object.prototype.hasOwnProperty.call(r,C)&&this.on(C,r[C]);this._from_tag=ke.newTag();const y=a.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(A.from_display_name="Anonymous",A.from_uri=new In("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(A.from_uri=new In("sip",a.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(A.from_display_name=a.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/json"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(t,this._ua,A,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,T),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,E,_)}_overrideSenderTracks(t,n){t.getTracks().forEach(a=>{n.getSenders().forEach(async s=>{s.track.kind===a.kind&&(a.kind==="audio"&&!this.isAudioOn&&(a.enabled=!1),a.kind==="video"&&!this.isVideoOn&&(a.enabled=!1),await s.replaceTrack(a))})})}init_incoming(t,n){z.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=ke.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){z.debug("answer()");const n=this._request,a=ke.cloneArray(t.extraHeaders),o=ke.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=ke.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=ke.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new qs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new qs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&ke.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,L.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,L.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(t={}){z.debug("terminate()");const n=t.cause||L.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new qs.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=te.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},_=["Content-Type: application/json",this.getPTypeHeader(Pt.LEAVE)];this.sendRequest(L.BYE,{extraHeaders:_,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(t){this.isAudioOn=t.audio,this.isVideoOn=t.video}enableAudio(t){const n={janus:"message",body:{audio:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.AUDIO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeAudioState",t),this.sendStateMessage({audio:t}))}}})}startAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.VIDEO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeVideoState",t),this.sendStateMessage({video:t}))}}})}startVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.STATE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)})}sendInfo(t,n,a={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new qs.InvalidStateError(this._status);new yu(this).send(t,n,a)}mute(t={audio:!0,video:!1}){z.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){z.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(z.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(z.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){z.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){z.debug("refer()");const a=t;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Ng(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return z.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveNotify(t){z.debug("receiveRequest()")}receiveRequest(t){if(z.debug("receiveRequest()"),t.method===L.CANCEL)(this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED)&&(this._status=te.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==te.STATUS_WAITING_FOR_ACK)return;if(this._status=te.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:if(this._status===te.STATUS_1XX_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED||this._status===te.STATUS_WAITING_FOR_ACK||this._status===te.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Eg(this).init_incoming(t):n!==void 0?new yu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}newDTMF(t){z.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){z.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(z.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(z.debug("_isReadyToReOffer() | session not established yet"),!1):(z.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(z.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(z.debug("close() | closing local MediaStream"),ke.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){z.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=$i.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<$i.T2&&(a=a*2,a>$i.T2&&(a=$i.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(L.BYE),this._ended("remote",null,L.causes.NO_ACK))},$i.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:L.causes.RTP_TIMEOUT,status_code:408,reason_phrase:L.causes.RTP_TIMEOUT})});let a;const o=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(a),a=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=o,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>(this.jsepOffer=o,a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ua(this,t,n,ua.C.STATUS_EARLY),d.error?(z.debug(d.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ua(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ca.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(z.debug("receiveRefer()"),!t.refer_to){z.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==L.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new bg(this,t.cseq);z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new $a(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=ke.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){z.debug("receiveReplaces()");function n(o){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new $a(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,a){this.ackSent=!1,this.publisherSubscribeSent=!1;const o=new sl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,L.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(r);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&z.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(t){this.mediaConstraints={...t},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const t={};this.isAudioOn?this.mediaConstraints.audio?t.audio=this.mediaConstraints.audio:t.audio=!0:t.audio=!1,this.isVideoOn?this.mediaConstraints.video?t.video=this.mediaConstraints.video:t.video=!0:t.video=!1;let n=null;try{n=await navigator.mediaDevices.getUserMedia(t)}catch{try{t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}catch{t.audio=!1,t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}}return n}addTracks(t){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),t.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return kT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(Pt.ICE)];this.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
135
+ `),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const a={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},o=["Content-Type: application/json",this.getPTypeHeader(Pt.CONFIGURE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const a={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},o=[this.getPTypeHeader(Pt.TRICKLE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let a=null;const o=async h=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const y={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),a=await t.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(t,a)}const _=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];_[0]&&T.push(_[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);t.stream=E,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const d=h=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=o,t.rtcpPeer.onicecandidate=d,t.rtcpPeer.sender=n.sender,await t.rtcpPeer.setRemoteDescription(n.jsep)}_sendJoinMemberRequest(t){const n={janus:"message",body:{request:"join",room:this.room_id,feed:t.info.id,ptype:"subscriber"},handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const d=JSON.parse(o.body);(r=(s=d==null?void 0:d.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,d)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{if(o.status_code===200){const r=JSON.parse(o.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),Qt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var a,o,s,r,d,h,_,g;const n={...this.memberList};(o=(a=t==null?void 0:t.plugindata)==null?void 0:a.data)==null||o.publishers.forEach(T=>{delete n[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new PT(T,this),this._attachMember(this.memberList[T.id]))}),((r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.videoroom)==="synced"&&Object.keys(n).forEach(T=>{n[T].hangup(),delete this.memberList[T]}),this.publishers=(h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publishers,this.private_id=(g=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:g.private_id}receiveUnpublished(t){const n=this.memberList[t];n&&(n.hangup(),this._detachMember(n),delete this.memberList[t])}closeSession(){this.stream&&this.stream.getTracks().forEach(n=>{n.stop()}),Object.values(this.memberList).forEach(n=>{n.hangup(),this._detachMember(n)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const t=this._ua.processStreamPlugins;let n=await this.loadStream();for(const a of t)n=await a.process(n);this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),n.getTracks().forEach(a=>{this.stream.addTrack(a)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.terminate();if(t==="video"){let a=await this.loadStream();for(const o of n)o.running&&(a=await o.start(a));this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),a.getTracks().forEach(o=>{this.stream.addTrack(o)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const a=this._ua.newStreamPlugins.find(d=>d.type===t);let s=a.getStream().clone();for(const d of n)d.running&&(s=await d.start(s));const r=a.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.kill()}_receiveInviteResponse(t){if(z.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.ackSent=!0,this.sendRequest(L.ACK);return}else{const n=new ua(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(t.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=Df();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(Pt.PUBLISHER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.receivePublishers(g)}catch(g){console.error(g)}this.lastTrickleReceived&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{})),this._ua.emit("conferenceStart")}}}}),this.publisherSubscribeSent=!0})}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){z.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=ke.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(L.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(L.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){z.debug("sendUpdate()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(L.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(L.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||L.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(L.ACK),this.sendRequest(L.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=xt.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return xt.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===L.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:L.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newJanusSession(t,n){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:t,session:this,request:n})}_connecting(t){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}class cr{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
136
+ `),o=a.shift().split(/\s/);this.protocol=o[0],this.ident=o[1],this.code=o.length>3?parseInt(o[2]):0,this.method=o.length>3?o[3]:o[2],this.body="";for(const s of a){if(s==`-------${this.ident}$`)break;if(s===""){n=!0;continue}if(s&&n)this.body+=`${s}\r
137
+ `;else{const r=s.split(": ");this.addHeader(r[0],r[1].trim())}}}else this.ident=ke.createRandomToken(12),this.protocol="MSRP"}addHeader(t,n){this.headers[t]=n}getHeader(t){return this.headers[t]}toString(){let t=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
+ `;for(const n in this.headers)t+=`${n}: ${this.headers[n]}\r
139
+ `;return this.body&&(t+=`\r
140
140
  ${this.body}\r
141
- `),e+=`-------${this.ident}$\r
142
- `,e}}const Ie={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 Ih extends It.EventEmitter{constructor(e){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=e,this.auth_id=je.createRandomToken(10),this._status=Ie.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:e._configuration.authorization_user,ha1:e._configuration.ha1,realm:e._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:Z.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Ie}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(e=""){e!==""&&(this._direction="outgoing"),this.target=e,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=t=>{console.log("open",t),this.onopen()},this._connection.onclose=t=>{console.log("close",t),this.onclose()},this._connection.onmessage=t=>{console.log("msg",t),this.onmessage(t)},this._connection.onerror=t=>{console.log("error",t),this.onerror()}}_sendKeepAlive(){const e=new lr("");e.method="SEND",e.addHeader("To-Path",`${this.my_addr[1]}`),e.addHeader("From-Path",`${this.my_addr[0]}`),e.addHeader("Message-ID",je.createRandomToken(10)),this._connection.send(e.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Ie.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(e){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
141
+ `),t+=`-------${this.ident}$\r
142
+ `,t}}const Re={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class nu extends ft.EventEmitter{constructor(t){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=t,this.auth_id=ke.createRandomToken(10),this._status=Re.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username:t._configuration.authorization_user,ha1:t._configuration.ha1,realm:t._configuration.realm},this._request=null,this.status="new",this.target="",this.message="",this._connectionPromiseQueue=Promise.resolve(),this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Re}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(t=""){t!==""&&(this._direction="outgoing"),this.target=t,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 t=new cr("");t.method="SEND",t.addHeader("To-Path",`${this.my_addr[1]}`),t.addHeader("From-Path",`${this.my_addr[0]}`),t.addHeader("Message-ID",ke.createRandomToken(10)),this._connection.send(t.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Re.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(t){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
143
143
  o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
144
144
  c=IN IP4 ${this.my_ip}
145
145
  t=0 0
146
146
  m=message 2856 TCP/TLS/MSRP *
147
147
  a=accept-types:text/plain text/html
148
- a=path: ${e.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
149
- `)}inviteParty(e){const t={},r=[];t.to_uri=new _i("sip",this.target,this._ua._configuration.realm),t.from_uri=new _i("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),r.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),r.push("Content-Type: application/sdp"),this._request=new $t.InitialOutgoingInviteRequest(new _i("sip",this.target,this._ua._configuration.realm).clone(),this._ua,t,r,`v=0
148
+ a=path: ${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
149
+ `)}inviteParty(t){const n={},a=[];n.to_uri=new In("sip",this.target,this._ua._configuration.realm),n.from_uri=new In("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),a.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),a.push("Content-Type: application/sdp"),this._request=new yt.InitialOutgoingInviteRequest(new In("sip",this.target,this._ua._configuration.realm).clone(),this._ua,n,a,`v=0
150
150
  o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
151
151
  c=IN IP4 ${this.my_ip}
152
152
  t=0 0
153
153
  m=message 2856 TCP/TLS/MSRP *
154
154
  a=accept-types:text/plain text/html
155
- a=path:${e.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 pa(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:s=>{this.onTransportError(),console.log(s)},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s),s.status_code===200&&(s.parseSDP(!0),this._status=Ie.STATUS_CONFIRMED,this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Ie.STATUS_INVITE_SENT}terminate(e={}){const t=e.cause||Z.causes.BYE,r=je.cloneArray(e.extraHeaders),l=e.body;let s,i=e.status_code,f=e.reason_phrase;if(this._status===Ie.STATUS_TERMINATED)throw new Cn.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ie.STATUS_NULL:case Ie.STATUS_INVITE_SENT:case Ie.STATUS_1XX_RECEIVED:if(i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);i&&(f=f||Z.REASON_PHRASE[i]||"",s=`SIP ;cause=${i} ;text="${f}"`),this._status===Ie.STATUS_NULL||this._status===Ie.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Ie.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Ie.STATUS_CANCELED,this._failed("local",null,Z.causes.CANCELED);break;case Ie.STATUS_WAITING_FOR_ANSWER:case Ie.STATUS_ANSWERED:if(i=i||480,i<300||i>=700)throw new TypeError(`Invalid status_code: ${i}`);this._request.reply(i,f,r,l),this._failed("local",null,Z.causes.REJECTED);break;case Ie.STATUS_WAITING_FOR_ACK:case Ie.STATUS_CONFIRMED:if(f=e.reason_phrase||Z.REASON_PHRASE[i]||"",i&&(i<200||i>=700))throw new TypeError(`Invalid status_code: ${i}`);if(i&&r.push(`Reason: SIP ;cause=${i}; text="${f}"`),this._status===Ie.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==cs.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:d})=>{d===Z.ACK&&(this.sendRequest(Z.BYE,{extraHeaders:r,body:l}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===cs.C.STATUS_TERMINATED&&(this.sendRequest(Z.BYE,{extraHeaders:r,body:l}),h.terminate())}),this._ended("local",null,t),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(Z.BYE,{extraHeaders:r,body:l}),this._ended("local",null,t)}}sendRequest(e,t){return this._dialog.sendRequest(e,t)}authenticate(e){this.status="auth";let t=new lr("");t.method="AUTH",t.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),t.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),e&&t.addHeader("Authorization",e.toString());let r=t.toString(),l=[];for(var s=0;s<r.length;s++)l.push(r.charCodeAt(s).toString(16));this._connection.send(t.toString())}onmessage(e){const t=new lr(e.data);if(this.status==="auth"&&t.code===401){const r=this.parseAuth(t.getHeader("WWW-Authenticate")),l=new vT(this.credentials);l.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},r,je.createRandomToken(12)),this.authenticate(l)}this.status==="auth"&&t.code===200&&this._direction==="outgoing"?(this.my_addr.push(t.getHeader("To-Path")),this.my_addr.push(t.getHeader("Use-Path")),this.status="active",this.inviteParty(t)):this.status==="auth"&&t.code===200&&this._direction==="incoming"?(this.my_addr.push(t.getHeader("To-Path")),this.my_addr.push(t.getHeader("Use-Path")),this.status="active",this.acceptParty(t),this.emit("confirmed")):t.method==="SEND"&&(this._sendOk(t),this._sendReport(t),t.direction="incoming",this.emit("newMessage",t),this._msgHistory.push(t),this.emit("msgHistoryUpdate",this._msgHistory)),t.code===480&&this._close()}onclose(){console.log("close")}onopen(){const e=new RTCPeerConnection({iceServers:[]});e.createDataChannel(""),e.createOffer().then(e.setLocalDescription.bind(e)),e.onicecandidate=t=>{if(!t||!t.candidate||!t.candidate.candidate)return;const r=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,l=t.candidate.candidate.match(r);this.my_ip=l&&l[1],e.onicecandidate=()=>{},this.authenticate(null)}}onerror(e){console.log(e)}_receiveInviteResponse(e){if(console.log("resp0000000000000",e),this._dialog&&e.status_code>=200&&e.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag){this.sendRequest(Z.ACK);return}else{const t=new Eo(this,e,"UAC");if(t.error!==void 0){console.log(t.error);return}this.sendRequest(Z.ACK),this.sendRequest(Z.BYE);return}if(this._is_canceled){e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);return}if(!(this._status!==Ie.STATUS_INVITE_SENT&&this._status!==Ie.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(e.status_code):this._status=Ie.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):{if(!e.to_tag){console.log("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=Ie.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}const t={originator:"remote",type:"answer",sdp:e.body};console.log('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>this._progress("remote",e)).catch(l=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)});break}case/^2[0-9]{2}$/.test(e.status_code):{if(console.log("maybe here???"),this._status=Ie.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,Z.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",e,Z.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;const t={originator:"remote",type:"answer",sdp:e.body};console.log('emit "sdp"'),this.emit("sdp",t),new RTCSessionDescription({type:"answer",sdp:t.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(r=>this._connection.setLocalDescription(r)).catch(r=>{this._acceptAndTerminate(e,500,r.toString()),console.log("failed 4"),this._failed("local",e,Z.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(e),this._accepted("remote",e),this.sendRequest(Z.ACK),this._confirmed("local",null)});break}default:{const t=je.sipErrorCause(e.status_code);console.log("failed 5"),this._failed("remote",e,t)}}}sendMSRP(e){const t=new lr("");t.method="SEND",t.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),t.addHeader("From-Path",`${this.my_addr[0]}`),t.addHeader("Message-ID",je.createRandomToken(10)),t.addHeader("Byte-Range","1-25/25"),t.addHeader("Content-Type","text/plain"),t.addHeader("Success-Report","yes"),t.addHeader("Failure-Report","yes"),t.body=e;let r=t.toString();console.log(r);let l=[];for(var s=0;s<r.length;s++)l.push(r.charCodeAt(s).toString(16));console.log(l),this._connection.send(t.toString()),t.direction="outgoing",this.emit("newMessage",t),this._msgHistory.push(t),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(e){let t=e.ident,r=e.getHeader("Message-ID"),l=new lr("");l.method="200 OK",l.addHeader("To-Path",`${this.my_addr[1]}`),l.addHeader("From-Path",`${this.my_addr[0]}`),l.addHeader("Message-ID",r),l.ident=t;let s=l.toString();console.log(s);let i=[];for(var f=0;f<s.length;f++)i.push(s.charCodeAt(f).toString(16));console.log(i),this._connection.send(l.toString())}_sendReport(e){let t=e.ident,r=e.getHeader("Message-ID"),l=new lr("");l.method="REPORT",l.addHeader("To-Path",`${e.getHeader("From-Path")}`),l.addHeader("From-Path",`${this.my_addr[0]}`),l.addHeader("Message-ID",r),l.addHeader("Byte-Range","1-25/25"),l.addHeader("Status","000 200 OK"),l.ident=t;let s=l.toString();console.log(s);let i=[];for(var f=0;f<s.length;f++)i.push(s.charCodeAt(f).toString(16));console.log(i),this._connection.send(l.toString())}parseAuth(e){const t={},r=e.replace("Digest","").split(",");for(const l of r){const s=l.trim().split("=");t[s[0]]=s[1].match('^"(.+)"$')[1]}return t}init_incoming(e,t){let r;const l=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;if(e.body&&l!=="application/sdp"){e.reply(415);return}if(this._status=Ie.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(r=e.getHeader("expires")*1e3),e.to_tag=je.newTag(),!this._createDialog(e,"UAS",!0)){e.reply(500,"Missing Contact header field");return}e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Ie.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{e.reply(408),console.log("failed 6"),this._failed("local",null,Z.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),r&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Ie.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),console.log("failed 7"),this._failed("system",null,Z.causes.EXPIRES))},r)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),e.parseSDP(!0),this.target_addr=e.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",e),this._status!==Ie.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(e,t,r){this.emit("_failed",{originator:e,message:t||null,cause:r}),this._close(),this.emit("failed",{originator:e,message:t||null,cause:r})}_close(){if(console.log("CLOSE SESSION"),this._status!==Ie.STATUS_TERMINATED){if(this._status=Ie.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){console.log("close() | error closing the RTCPeerConnection: %o",e)}for(const e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const e in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,e)&&(this._earlyDialogs[e].terminate(),delete this._earlyDialogs[e]);for(const e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyMSRPSession(this)}}_createDialog(e,t,r){const l=t==="UAS"?e.to_tag:e.from_tag,s=t==="UAS"?e.from_tag:e.to_tag,i=e.call_id+l+s;let f=this._earlyDialogs[i];if(r)return f?!0:(f=new Eo(this,e,t,Eo.C.STATUS_EARLY),f.error?(console.log("failed 8"),this._failed("remote",e,Z.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=f,!0));{if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,f)return f.update(e,t),this._dialog=f,delete this._earlyDialogs[i],!0;const h=new Eo(this,e,t);return h.error?(console.log("failed 9"),this._failed("remote",e,Z.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_newMSRPSession(e,t){this._ua.newMSRPSession(this,{originator:e,session:this,request:t})}_progress(e,t){this.emit("progress",{originator:e,response:t||null})}isEnded(){switch(this._status){case Ie.STATUS_CANCELED:case Ie.STATUS_TERMINATED:return!0;default:return!1}}_accepted(e,t){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}_confirmed(e,t){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}_ended(e,t,r){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:r})}_handleSessionTimersInIncomingResponse(e){if(!this._sessionTimers.enabled)return;let t;e.session_expires&&e.session_expires>=Z.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher=t==="uac",this._runSessionTimer()}receiveRequest(e){if(console.log("receiveRequest()"),e.method===Z.CANCEL)(this._status===Ie.STATUS_WAITING_FOR_ANSWER||this._status===Ie.STATUS_ANSWERED)&&(this._status=Ie.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",e,Z.causes.CANCELED));else switch(e.method){case Z.ACK:if(this._status!==Ie.STATUS_WAITING_FOR_ACK)return;if(this._status=Ie.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:Z.causes.MISSING_SDP,status_code:400});break}const t={originator:"remote",type:"answer",sdp:e.body};console.log('emit "sdp"'),this.emit("sdp",t);const r=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(r)).then(()=>{this._is_confirmed||this._confirmed("remote",e)}).catch(l=>{this.terminate({cause:Z.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)})}else this._is_confirmed||this._confirmed("remote",e);break;case Z.BYE:this._status===Ie.STATUS_CONFIRMED||this._status===Ie.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,Z.causes.BYE)):this._status===Ie.STATUS_INVITE_RECEIVED||this._status===Ie.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,Z.causes.BYE)):e.reply(403,"Wrong Status");break;case Z.INVITE:this._status===Ie.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case Z.INFO:this._status===Ie.STATUS_1XX_RECEIVED||this._status===Ie.STATUS_WAITING_FOR_ANSWER||this._status===Ie.STATUS_ANSWERED||this._status===Ie.STATUS_WAITING_FOR_ACK||this._status===Ie.STATUS_CONFIRMED?(e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new af(this).init_incoming(e):e.reply(415):e.reply(403,"Wrong Status");break;case Z.UPDATE:this._status===Ie.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case Z.REFER:this._status===Ie.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case Z.NOTIFY:this._status===Ie.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ie.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Z.causes.CONNECTION_ERROR,cause:Z.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ie.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:Z.causes.REQUEST_TIMEOUT,cause:Z.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ie.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Z.causes.DIALOG_ERROR,cause:Z.causes.DIALOG_ERROR})}}var aS=ys();const hf=nt(aS),xo=new Au("Parser"),oS=(u,e)=>{let t,r,l=u.indexOf(`\r
157
- `);if(l===-1){xo.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=u.substring(0,l);let i=hf.parse(s,"Request_Response");if(i===-1){xo.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else i.status_code?(t=new gr.IncomingResponse,t.status_code=i.status_code,t.reason_phrase=i.reason_phrase):(t=new gr.IncomingRequest(e),t.method=i.method,t.ruri=i.uri);t.data=u;let f=l+2;for(;;){if(l=uS(u,f),l===-2){r=f+2;break}else if(l===-1){xo.warn("parseMessage() | malformed message");return}if(i=cS(t,u,f,l),i!==!0){xo.warn("parseMessage() |",i.error);return}f=l+2}if(t.hasHeader("content-length")){const h=t.getHeader("content-length");t.body=u.substr(r,h)}else t.body=u.substring(r);return t};function uS(u,e){let t=e,r=0,l=0;if(u.substring(t,t+2).match(/(^\r\n)/))return-2;for(;r===0;){if(l=u.indexOf(`\r
158
- `,t),l===-1)return l;!u.substring(l+2,l+4).match(/(^\r\n)/)&&u.charAt(l+2).match(/(^\s+)/)?t=l+2:r=l}return r}function cS(u,e,t,r){let l;const s=e.indexOf(":",t),i=e.substring(t,s).trim(),f=e.substring(s+1,r).trim();switch(i.toLowerCase()){case"via":case"v":u.addHeader("via",f),u.getHeaders("via").length===1?(l=u.parseHeader("Via"),l&&(u.via=l,u.via_branch=l.branch)):l=0;break;case"from":case"f":u.setHeader("from",f),l=u.parseHeader("from"),l&&(u.from=l,u.from_tag=l.getParam("tag"));break;case"to":case"t":u.setHeader("to",f),l=u.parseHeader("to"),l&&(u.to=l,u.to_tag=l.getParam("tag"));break;case"record-route":if(l=hf.parse(f,"Record_Route"),l===-1)l=void 0;else for(const h of l)u.addHeader("record-route",f.substring(h.possition,h.offset)),u.headers["Record-Route"][u.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":u.setHeader("call-id",f),l=u.parseHeader("call-id"),l&&(u.call_id=f);break;case"contact":case"m":if(l=hf.parse(f,"Contact"),l===-1)l=void 0;else for(const h of l)u.addHeader("contact",f.substring(h.possition,h.offset)),u.headers.Contact[u.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":u.setHeader("content-length",f),l=u.parseHeader("content-length");break;case"content-type":case"c":u.setHeader("content-type",f),l=u.parseHeader("content-type");break;case"cseq":u.setHeader("cseq",f),l=u.parseHeader("cseq"),l&&(u.cseq=l.value),u instanceof gr.IncomingResponse&&(u.method=l.method);break;case"max-forwards":u.setHeader("max-forwards",f),l=u.parseHeader("max-forwards");break;case"www-authenticate":u.setHeader("www-authenticate",f),l=u.parseHeader("www-authenticate");break;case"proxy-authenticate":u.setHeader("proxy-authenticate",f),l=u.parseHeader("proxy-authenticate");break;case"session-expires":case"x":u.setHeader("session-expires",f),l=u.parseHeader("session-expires"),l&&(u.session_expires=l.expires,u.session_expires_refresher=l.refresher);break;case"refer-to":case"r":u.setHeader("refer-to",f),l=u.parseHeader("refer-to"),l&&(u.refer_to=l);break;case"replaces":u.setHeader("replaces",f),l=u.parseHeader("replaces"),l&&(u.replaces=l);break;case"event":case"o":u.setHeader("event",f),l=u.parseHeader("event"),l&&(u.event=l);break;default:u.addHeader(i,f),l=0}return l===void 0?{error:`error parsing header "${i}"`}:!0}const hS={parseMessage:oS},sa=new Au("Registrator"),ko=10;class fS{constructor(e,t){this._reg_id=1,this._ua=e,this._transport=t,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=qs.createRandomToken(22),this._cseq=0,this._to_uri=e.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const r=this._contact.indexOf(">");if(r!==-1){const l=this._contact.slice(0,r)+this._contact.slice(r+1,this._contact.length);this._contact=l}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(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}setExtraContactParams(e){e instanceof Object||(e={}),this._extraContactParams="";for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this._extraContactParams+=`;${t}`,r&&(this._extraContactParams+=`=${r}`)}}setExtraContactUriParams(e){e instanceof Object||(e={}),this._extraContactParams="";for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this._extraContactParams+=`;${t}`,r&&(this._extraContactParams+=`=${r}`)}}register(){if(this._registering){sa.debug("Register request in progress...");return}const e=this._extraHeaders.slice();e.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),e.push(`Expires: ${this._expires}`);const t=new $t.OutgoingRequest(Z.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},e),r=new pa(this._ua,t,{onRequestTimeout:()=>{this._registrationFailure(null,Z.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Z.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:l=>{if(l.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(l.status_code):break;case/^2[0-9]{2}$/.test(l.status_code):{if(this._registering=!1,!l.hasHeader("Contact")){sa.debug("no Contact header in response to REGISTER, response ignored");break}const s=l.headers.Contact.reduce((d,p)=>d.concat(p.parsed),[]);let i=s.find(d=>this._sipInstance===d.getParam("+sip.instance")&&this._reg_id===parseInt(d.getParam("reg-id")));if(i||(i=s.find(d=>d.uri.user===this._ua.contact.uri.user)),!i){sa.debug("no Contact header pointing to us, response ignored");break}let f=i.getParam("expires");!f&&l.hasHeader("expires")&&(f=l.getHeader("expires")),f||(f=this._expires),f=Number(f),f<ko&&(f=ko);const h=f>64?f*1e3/2+Math.floor((f/2-32)*1e3*Math.random()):f*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),i.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=i.getParam("temp-gruu").replace(/"/g,"")),i.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=i.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:l}));break}case/^423$/.test(l.status_code):{l.hasHeader("min-expires")?(this._expires=Number(l.getHeader("min-expires")),this._expires<ko&&(this._expires=ko),this.register()):(sa.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(l,Z.causes.SIP_FAILURE_CODE));break}default:{const s=qs.sipErrorCause(l.status_code);this._registrationFailure(l,s)}}}});this._registering=!0,r.send()}unregister(e={}){if(!this._registered){sa.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const t=this._extraHeaders.slice();e.all?t.push(`Contact: *${this._extraContactParams}`):t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),t.push("Expires: 0");const r=new $t.OutgoingRequest(Z.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t);new pa(this._ua,r,{onRequestTimeout:()=>{this._unregistered(null,Z.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Z.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const i=qs.sipErrorCause(s.status_code);this._unregistered(s,i)}}}}).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(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}_unregistered(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}}const mt=console,An={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},dS=Zy;class _S extends dS{constructor(e){super(e),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new fS(this)}call(e,t){return super.call(e,t)}joinVideoCall(e,t,r){mt.debug("call()");const l=new du(this);return l.configureMedia({audio:!0,video:!0}),l.connect(e,t,r),l}startScreenShare(){mt.debug("startScreenShare()");for(const e in this._janus_sessions)this._janus_sessions[e].connectScreenShare()}changeMediaConstraints(e){for(const t in this._janus_sessions)this._janus_sessions[t].changeMediaConstraints(e)}startBlur(){for(const e in this._janus_sessions)this._janus_sessions[e].connectBlur()}stopBlur(){for(const e in this._janus_sessions)this._janus_sessions[e].stopBlur()}_loadConfig(e){try{va.load(this._configuration,e)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=qs.newUUID());let t;typeof window<"u"&&typeof window.document<"u"?t=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(t=self.navigator.userAgent),t+=" "+Ue.USER_AGENT,this._configuration.user_agent=e.overrideUserAgent&&typeof e.overrideUserAgent=="function"?e.overrideUserAgent(t):t,this._configuration.jssip_id=qs.createRandomToken(5);const r=this._configuration.uri.clone();r.user=null,this._configuration.hostport_params=r.toString().replace(/^sip:/i,"");try{this._transport=new by(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=gS.bind(this),this._transport.onconnect=pS.bind(this),this._transport.ondisconnect=mS.bind(this),this._transport.ondata=vS.bind(this)}catch(s){throw mt.warn(s),new Cn.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new _i("sip",qs.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const i=s.anonymous||null,f=s.outbound||null;let h="<";return i?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),f&&(i?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const l=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(l.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));mt.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(va.settings,s))switch(s){case"uri":case"registrar_server":mt.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":mt.debug(`- ${s}: NOT SHOWN`);break;default:mt.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(e,t){e.on("msgHistoryUpdate",r=>{console.log(r)}),this._msrp_sessions[e.id]=e,this.emit("newMSRPSession",t)}newJanusSession(e,t){this._janus_sessions[e.id]=e,this.newStreamPlugins.forEach(r=>{r.setSession(e)}),this.processStreamPlugins.forEach(r=>{r.setSession(e)}),this.emit("newJanusSession",t)}kill(){}destroyMSRPSession(e){delete this._msrp_sessions[e.id]}destroyJanusSession(e){delete this._janus_sessions[e.id]}receiveRequest(e){var s,i,f,h;const t=e.method;if(e.ruri.user!==this._configuration.uri.user&&e.ruri.user!==this._contact.uri.user){mt.debug("Request-URI does not point to us"),e.method!==Ue.ACK&&e.reply_sl(404);return}if(e.ruri.scheme===Ue.SIPS){e.reply_sl(416);return}if(cs.checkTransaction(this,e))return;if(t===Ue.INVITE?new cs.InviteServerTransaction(this,this._transport,e):t!==Ue.ACK&&t!==Ue.CANCEL&&new cs.NonInviteServerTransaction(this,this._transport,e),t===Ue.OPTIONS){if(this.listeners("newOptions").length===0){e.reply(200);return}new u_.Options(this).init_incoming(e)}else if(t===Ue.MESSAGE){if(this.listeners("newMessage").length===0){e.reply(405);return}new u_.Message(this).init_incoming(e)}else if(t===Ue.INVITE&&!e.to_tag&&this.listeners("newRTCSession").length===0){e.reply(405);return}let r,l;if(e.to_tag)if(r=this._findDialog(e.call_id,e.from_tag,e.to_tag),r)r.receiveRequest(e);else if(t===Ue.NOTIFY)if(l=this._findSession(e),l)l.receiveRequest(e);else{if(e.body)try{const d=JSON.parse(e.body)||{};(i=(s=d.plugindata)==null?void 0:s.data)!=null&&i.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(d),(h=(f=d.plugindata)==null?void 0:f.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(d.plugindata.data.unpublished)}catch(d){console.error(d)}e.reply(200)}else t!==Ue.ACK&&e.reply(481);else switch(t){case Ue.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){const d=e.replaces;r=this._findDialog(d.call_id,d.from_tag,d.to_tag),r?(l=r.owner,l.isEnded()?e.reply(603):l.receiveRequest(e)):e.reply(481)}else e.body.search(/MSRP/ig)>-1?(l=new Ih(this),l.init_incoming(e)):e.body.search(/JANUS/ig)>-1||(l=new uy(this),l.init_incoming(e));else mt.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case Ue.BYE:e.reply(481);break;case Ue.CANCEL:l=this._findSession(e),l?l.receiveRequest(e):mt.debug("received CANCEL request for a non existent session");break;case Ue.ACK:break;case Ue.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;default:e.reply(405);break}}startMSRP(e,t){mt.debug("startMSRP()",t);const r=new Ih(this);return r.connect(e),r}startJanus(e,t){mt.debug("startJanus()",t);const r=new Ih(this);return r.connect(e),r}terminateMSRPSessions(e){mt.debug("terminateSessions()");for(const t in this._msrp_sessions)this._msrp_sessions[t].isEnded()||this._msrp_sessions[t].terminate(e)}terminateJanusSessions(e){mt.debug("terminateSessions()");for(const t in this._janus_sessions)this._janus_sessions[t].isEnded()||this._janus_sessions[t].terminate(e)}enableJanusAudio(e){mt.debug("enableJanusAudio()");for(const t in this._janus_sessions)this._janus_sessions[t].isEnded()||(e?this._janus_sessions[t].startAudio():this._janus_sessions[t].stopAudio())}enableJanusVideo(e){mt.debug("enableJanusVideo()");for(const t in this._janus_sessions)this._janus_sessions[t].isEnded()||(e?this._janus_sessions[t].startVideo():this._janus_sessions[t].stopVideo())}stop(){if(mt.debug("stop()"),this._dynConfiguration={},this._status===An.STATUS_USER_CLOSED){mt.debug("UA already closed");return}this._registrator.close();const e=Object.keys(this._sessions).length;for(const r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){mt.debug(`closing session ${r}`);try{this._sessions[r].terminate()}catch(l){console.error(l)}}for(const r in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,r)){mt.debug(`closing session ${r}`);try{this._msrp_sessions[r].terminate()}catch(l){console.error(l)}}for(const r in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,r)){mt.debug(`closing session ${r}`);try{this._janus_sessions[r].terminate()}catch(l){console.error(l)}}for(const r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch(l){console.error(l)}this._status=An.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&&e===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function gS(u){this.emit("connecting",u)}function pS(u){this._status!==An.STATUS_USER_CLOSED&&(this._status=An.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function mS(u){const e=["nict","ict","nist","ist"];for(const t of e)for(const r in this._transactions[t])Object.prototype.hasOwnProperty.call(this._transactions[t],r)&&this._transactions[t][r].onTransportError();this.emit("disconnected",u),this._registrator.onTransportClosed(),this._status!==An.STATUS_USER_CLOSED&&(this._status=An.STATUS_NOT_READY,this._error=An.NETWORK_ERROR)}function vS(u){const e=u.transport;let t=u.message;if(t=hS.parseMessage(t,this),!!t&&!(this._status===An.STATUS_USER_CLOSED&&t instanceof gr.IncomingRequest)&&Hy(t,this,e)){if(t instanceof gr.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof gr.IncomingResponse){let r;switch(t.method){case Ue.INVITE:r=this._transactions.ict[t.via_branch],r&&r.receiveResponse(t);break;case Ue.ACK:break;default:r=this._transactions.nict[t.via_branch],r&&r.receiveResponse(t);break}}}}const TS=["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"],yS=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function G_(u){const e={};return TS.forEach(t=>{u[t]!==void 0&&(e[t]=u[t])}),e.localHold=u._localHold,e}function V_(u){const e={};return yS.forEach(t=>{u[t]!==void 0&&(e[t]=u[t])}),e}function B_(u,e){const t=new AudioContext,r=t.createMediaStreamSource(u),l=t.createMediaStreamDestination(),s=t.createGain();return r.connect(s),s.connect(l),s.gain.value=e,l.stream}function SS(u,e,t,r){const l=document.createElement("audio");l.id=e._id,l.className="audioTag",l.srcObject=u,yp()||(l.setSinkId(t),l.volume=r),l.play(),e.audioTag=l}function ES(u){if(u&&typeof u.log=="function"&&typeof u.warn=="function"&&typeof u.error=="function")return!0}function yp(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}class Sp{constructor(e){this.opensips=null,this.session=null,this.name=null,this.name=e}setOpensips(e){this.opensips=e}setSession(e){this.session=e}kill(){this.opensips.kill(this.name)}}class Ru extends Sp{constructor(e,t){super(e),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=t}connect(e={}){this.opaqueId=this.session.generateOpaqueId();const t=je.cloneArray(e.extraHeaders),r={from_tag:this.session._from_tag};e.fromUserName&&(r.from_uri=new _i("sip",e.fromUserName,this.session._ua.configuration.uri.host),t.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),e.fromDisplayName&&(r.from_display_name=e.fromDisplayName),t.push(`Contact: ${this.session._contact}`),t.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&t.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new $t.InitialOutgoingInviteRequest(this.session.target,this.session._ua,r,t),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 e;this._connection.onicecandidate=t=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||t.candidate&&(this._candidates.push(t.candidate),clearTimeout(e),e=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(e){e.forEach(t=>{this._connection.addTrack(t)})}async _sendInitialRequest(){const e=new pa(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const t={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(t),await this._connection.setLocalDescription(this.jsep_offer);const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},l=JSON.stringify(r);this._request.body=l,e.send()}_receiveInviteResponse(e){if(this._publisherSubscribeSent||!e.body)return;const t=JSON.parse(e.body);this.handleId=t.data.id;const r={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},l=[this.session.getPTypeHeader(Jt.PUBLISHER)];this.session.sendRequest(Z.SUBSCRIBE,{extraHeaders:l,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async s=>{var i,f,h,d;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const p=JSON.parse(s.body)||{};((f=(i=p.plugindata)==null?void 0:i.data)==null?void 0:f.videoroom)==="joined"&&this.session.myFeedList.push(p.plugindata.data.id),(d=(h=p.plugindata)==null?void 0:h.data)!=null&&d.publishers&&this.session.receivePublishers(p)}catch(p){console.error(p)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(e){const t=this._candidates.map(i=>({janus:"trickle",candidate:i,handle_id:this.handleId,session_id:this.session.session_id})),l={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...e},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...t]},s=["Content-Type: application/json",this.session.getPTypeHeader(Jt.ICE)];this.session.sendRequest(Z.INFO,{extraHeaders:s,body:JSON.stringify(l),eventHandlers:{onSuccessResponse:async i=>{this._configureSent=!0;const h=i.data.split(`\r
159
- `),d=h[h.length-1],p=JSON.parse(d);await this._connection.setRemoteDescription(p.jsep),this._candidates=[]}}})}_sendDetach(){const e={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},t=[this.session.getPTypeHeader(Jt.DETACH)];this.session.sendRequest(Z.INFO,{extraHeaders:t,body:JSON.stringify(e)}),this.session._ua.emit("pluginDetach",this.name)}async stopMedia(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)}async stop(){await this.session.stopProcessPlugins(this.type);const e=this._connection.getSenders();e.forEach(t=>{const r=t.track;r&&r.stop()}),e.forEach(t=>{this._connection.removeTrack(t)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class CS extends Ru{constructor(){super("ScreenShare","screen")}async generateStream(){try{this.stream=await navigator.mediaDevices.getDisplayMedia(),this.stream.getVideoTracks()[0].onended=()=>{this.kill()},this.session._ua.emit("startScreenShare",{stream:this.stream,handleId:this.handleId,sender:"me",type:"publisher"})}catch(e){this.kill(),console.error(e)}return this.stream}async kill(){await this.stop(),this.session._ua.emit("stopScreenShare")}}var Hf={exports:{}},wu={},Ep={},Le={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u._registerNode=u.Konva=u.glob=void 0;const e=Math.PI/180;function t(){return typeof window<"u"&&({}.toString.call(window)==="[object Window]"||{}.toString.call(window)==="[object global]")}u.glob=typeof Wh<"u"?Wh:typeof window<"u"?window:typeof WorkerGlobalScope<"u"?self:{},u.Konva={_global:u.glob,version:"9.3.16",isBrowser:t(),isUnminified:/param/.test((function(l){}).toString()),dblClickWindow:400,getAngle(l){return u.Konva.angleDeg?l*e:l},enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_fixTextRendering:!1,pixelRatio:typeof window<"u"&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging(){return u.Konva.DD.isDragging},isTransforming(){var l;return(l=u.Konva.Transformer)===null||l===void 0?void 0:l.isTransforming()},isDragReady(){return!!u.Konva.DD.node},releaseCanvasOnDestroy:!0,document:u.glob.document,_injectGlobal(l){u.glob.Konva=l}};const r=l=>{u.Konva[l.prototype.getClassName()]=l};u._registerNode=r,u.Konva._injectGlobal(u.Konva)})(Le);var ct={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Util=u.Transform=void 0;const e=Le;class t{constructor(b=[1,0,0,1,0,0]){this.dirty=!1,this.m=b&&b.slice()||[1,0,0,1,0,0]}reset(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}copy(){return new t(this.m)}copyInto(b){b.m[0]=this.m[0],b.m[1]=this.m[1],b.m[2]=this.m[2],b.m[3]=this.m[3],b.m[4]=this.m[4],b.m[5]=this.m[5]}point(b){const w=this.m;return{x:w[0]*b.x+w[2]*b.y+w[4],y:w[1]*b.x+w[3]*b.y+w[5]}}translate(b,w){return this.m[4]+=this.m[0]*b+this.m[2]*w,this.m[5]+=this.m[1]*b+this.m[3]*w,this}scale(b,w){return this.m[0]*=b,this.m[1]*=b,this.m[2]*=w,this.m[3]*=w,this}rotate(b){const w=Math.cos(b),F=Math.sin(b),q=this.m[0]*w+this.m[2]*F,D=this.m[1]*w+this.m[3]*F,P=this.m[0]*-F+this.m[2]*w,I=this.m[1]*-F+this.m[3]*w;return this.m[0]=q,this.m[1]=D,this.m[2]=P,this.m[3]=I,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(b,w){const F=this.m[0]+this.m[2]*w,q=this.m[1]+this.m[3]*w,D=this.m[2]+this.m[0]*b,P=this.m[3]+this.m[1]*b;return this.m[0]=F,this.m[1]=q,this.m[2]=D,this.m[3]=P,this}multiply(b){const w=this.m[0]*b.m[0]+this.m[2]*b.m[1],F=this.m[1]*b.m[0]+this.m[3]*b.m[1],q=this.m[0]*b.m[2]+this.m[2]*b.m[3],D=this.m[1]*b.m[2]+this.m[3]*b.m[3],P=this.m[0]*b.m[4]+this.m[2]*b.m[5]+this.m[4],I=this.m[1]*b.m[4]+this.m[3]*b.m[5]+this.m[5];return this.m[0]=w,this.m[1]=F,this.m[2]=q,this.m[3]=D,this.m[4]=P,this.m[5]=I,this}invert(){const b=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),w=this.m[3]*b,F=-this.m[1]*b,q=-this.m[2]*b,D=this.m[0]*b,P=b*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),I=b*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=w,this.m[1]=F,this.m[2]=q,this.m[3]=D,this.m[4]=P,this.m[5]=I,this}getMatrix(){return this.m}decompose(){const b=this.m[0],w=this.m[1],F=this.m[2],q=this.m[3],D=this.m[4],P=this.m[5],I=b*q-w*F,x={x:D,y:P,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(b!=0||w!=0){const U=Math.sqrt(b*b+w*w);x.rotation=w>0?Math.acos(b/U):-Math.acos(b/U),x.scaleX=U,x.scaleY=I/U,x.skewX=(b*F+w*q)/I,x.skewY=0}else if(F!=0||q!=0){const U=Math.sqrt(F*F+q*q);x.rotation=Math.PI/2-(q>0?Math.acos(-F/U):-Math.acos(F/U)),x.scaleX=I/U,x.scaleY=U,x.skewX=0,x.skewY=(b*F+w*q)/I}return x.rotation=u.Util._getRotation(x.rotation),x}}u.Transform=t;let r="[object Array]",l="[object Number]",s="[object String]",i="[object Boolean]",f=Math.PI/180,h=180/Math.PI,d="#",p="",v="0",T="Konva warning: ",y="Konva error: ",S="rgb(",A={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},R=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,O=[];const N=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(C){setTimeout(C,60)};u.Util={_isElement(C){return!!(C&&C.nodeType==1)},_isFunction(C){return!!(C&&C.constructor&&C.call&&C.apply)},_isPlainObject(C){return!!C&&C.constructor===Object},_isArray(C){return Object.prototype.toString.call(C)===r},_isNumber(C){return Object.prototype.toString.call(C)===l&&!isNaN(C)&&isFinite(C)},_isString(C){return Object.prototype.toString.call(C)===s},_isBoolean(C){return Object.prototype.toString.call(C)===i},isObject(C){return C instanceof Object},isValidSelector(C){if(typeof C!="string")return!1;const b=C[0];return b==="#"||b==="."||b===b.toUpperCase()},_sign(C){return C===0||C>0?1:-1},requestAnimFrame(C){O.push(C),O.length===1&&N(function(){const b=O;O=[],b.forEach(function(w){w()})})},createCanvasElement(){const C=document.createElement("canvas");try{C.style=C.style||{}}catch{}return C},createImageElement(){return document.createElement("img")},_isInDocument(C){for(;C=C.parentNode;)if(C==document)return!0;return!1},_urlToImage(C,b){const w=u.Util.createImageElement();w.onload=function(){b(w)},w.src=C},_rgbToHex(C,b,w){return((1<<24)+(C<<16)+(b<<8)+w).toString(16).slice(1)},_hexToRgb(C){C=C.replace(d,p);const b=parseInt(C,16);return{r:b>>16&255,g:b>>8&255,b:b&255}},getRandomColor(){let C=(Math.random()*16777215<<0).toString(16);for(;C.length<6;)C=v+C;return d+C},getRGB(C){let b;return C in A?(b=A[C],{r:b[0],g:b[1],b:b[2]}):C[0]===d?this._hexToRgb(C.substring(1)):C.substr(0,4)===S?(b=R.exec(C.replace(/ /g,"")),{r:parseInt(b[1],10),g:parseInt(b[2],10),b:parseInt(b[3],10)}):{r:0,g:0,b:0}},colorToRGBA(C){return C=C||"black",u.Util._namedColorToRBA(C)||u.Util._hex3ColorToRGBA(C)||u.Util._hex4ColorToRGBA(C)||u.Util._hex6ColorToRGBA(C)||u.Util._hex8ColorToRGBA(C)||u.Util._rgbColorToRGBA(C)||u.Util._rgbaColorToRGBA(C)||u.Util._hslColorToRGBA(C)},_namedColorToRBA(C){const b=A[C.toLowerCase()];return b?{r:b[0],g:b[1],b:b[2],a:1}:null},_rgbColorToRGBA(C){if(C.indexOf("rgb(")===0){C=C.match(/rgb\(([^)]+)\)/)[1];const b=C.split(/ *, */).map(Number);return{r:b[0],g:b[1],b:b[2],a:1}}},_rgbaColorToRGBA(C){if(C.indexOf("rgba(")===0){C=C.match(/rgba\(([^)]+)\)/)[1];const b=C.split(/ *, */).map((w,F)=>w.slice(-1)==="%"?F===3?parseInt(w)/100:parseInt(w)/100*255:Number(w));return{r:b[0],g:b[1],b:b[2],a:b[3]}}},_hex8ColorToRGBA(C){if(C[0]==="#"&&C.length===9)return{r:parseInt(C.slice(1,3),16),g:parseInt(C.slice(3,5),16),b:parseInt(C.slice(5,7),16),a:parseInt(C.slice(7,9),16)/255}},_hex6ColorToRGBA(C){if(C[0]==="#"&&C.length===7)return{r:parseInt(C.slice(1,3),16),g:parseInt(C.slice(3,5),16),b:parseInt(C.slice(5,7),16),a:1}},_hex4ColorToRGBA(C){if(C[0]==="#"&&C.length===5)return{r:parseInt(C[1]+C[1],16),g:parseInt(C[2]+C[2],16),b:parseInt(C[3]+C[3],16),a:parseInt(C[4]+C[4],16)/255}},_hex3ColorToRGBA(C){if(C[0]==="#"&&C.length===4)return{r:parseInt(C[1]+C[1],16),g:parseInt(C[2]+C[2],16),b:parseInt(C[3]+C[3],16),a:1}},_hslColorToRGBA(C){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(C)){const[b,...w]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(C),F=Number(w[0])/360,q=Number(w[1])/100,D=Number(w[2])/100;let P,I,x;if(q===0)return x=D*255,{r:Math.round(x),g:Math.round(x),b:Math.round(x),a:1};D<.5?P=D*(1+q):P=D+q-D*q;const U=2*D-P,B=[0,0,0];for(let z=0;z<3;z++)I=F+1/3*-(z-1),I<0&&I++,I>1&&I--,6*I<1?x=U+(P-U)*6*I:2*I<1?x=P:3*I<2?x=U+(P-U)*(2/3-I)*6:x=U,B[z]=x*255;return{r:Math.round(B[0]),g:Math.round(B[1]),b:Math.round(B[2]),a:1}}},haveIntersection(C,b){return!(b.x>C.x+C.width||b.x+b.width<C.x||b.y>C.y+C.height||b.y+b.height<C.y)},cloneObject(C){const b={};for(const w in C)this._isPlainObject(C[w])?b[w]=this.cloneObject(C[w]):this._isArray(C[w])?b[w]=this.cloneArray(C[w]):b[w]=C[w];return b},cloneArray(C){return C.slice(0)},degToRad(C){return C*f},radToDeg(C){return C*h},_degToRad(C){return u.Util.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),u.Util.degToRad(C)},_radToDeg(C){return u.Util.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),u.Util.radToDeg(C)},_getRotation(C){return e.Konva.angleDeg?u.Util.radToDeg(C):C},_capitalize(C){return C.charAt(0).toUpperCase()+C.slice(1)},throw(C){throw new Error(y+C)},error(C){console.error(y+C)},warn(C){e.Konva.showWarnings&&console.warn(T+C)},each(C,b){for(const w in C)b(w,C[w])},_inRange(C,b,w){return b<=C&&C<w},_getProjectionToSegment(C,b,w,F,q,D){let P,I,x;const U=(C-w)*(C-w)+(b-F)*(b-F);if(U==0)P=C,I=b,x=(q-w)*(q-w)+(D-F)*(D-F);else{const B=((q-C)*(w-C)+(D-b)*(F-b))/U;B<0?(P=C,I=b,x=(C-q)*(C-q)+(b-D)*(b-D)):B>1?(P=w,I=F,x=(w-q)*(w-q)+(F-D)*(F-D)):(P=C+B*(w-C),I=b+B*(F-b),x=(P-q)*(P-q)+(I-D)*(I-D))}return[P,I,x]},_getProjectionToLine(C,b,w){const F=u.Util.cloneObject(C);let q=Number.MAX_VALUE;return b.forEach(function(D,P){if(!w&&P===b.length-1)return;const I=b[(P+1)%b.length],x=u.Util._getProjectionToSegment(D.x,D.y,I.x,I.y,C.x,C.y),U=x[0],B=x[1],z=x[2];z<q&&(F.x=U,F.y=B,q=z)}),F},_prepareArrayForTween(C,b,w){let F,q=[],D=[];if(C.length>b.length){const I=b;b=C,C=I}for(F=0;F<C.length;F+=2)q.push({x:C[F],y:C[F+1]});for(F=0;F<b.length;F+=2)D.push({x:b[F],y:b[F+1]});const P=[];return D.forEach(function(I){const x=u.Util._getProjectionToLine(I,q,w);P.push(x.x),P.push(x.y)}),P},_prepareToStringify(C){let b;C.visitedByCircularReferenceRemoval=!0;for(const w in C)if(C.hasOwnProperty(w)&&C[w]&&typeof C[w]=="object"){if(b=Object.getOwnPropertyDescriptor(C,w),C[w].visitedByCircularReferenceRemoval||u.Util._isElement(C[w]))if(b.configurable)delete C[w];else return null;else if(u.Util._prepareToStringify(C[w])===null)if(b.configurable)delete C[w];else return null}return delete C.visitedByCircularReferenceRemoval,C},_assign(C,b){for(const w in b)C[w]=b[w];return C},_getFirstPointerId(C){return C.touches?C.changedTouches[0].identifier:C.pointerId||999},releaseCanvas(...C){e.Konva.releaseCanvasOnDestroy&&C.forEach(b=>{b.width=0,b.height=0})},drawRoundedRectPath(C,b,w,F){let q=0,D=0,P=0,I=0;typeof F=="number"?q=D=P=I=Math.min(F,b/2,w/2):(q=Math.min(F[0]||0,b/2,w/2),D=Math.min(F[1]||0,b/2,w/2),I=Math.min(F[2]||0,b/2,w/2),P=Math.min(F[3]||0,b/2,w/2)),C.moveTo(q,0),C.lineTo(b-D,0),C.arc(b-D,D,D,Math.PI*3/2,0,!1),C.lineTo(b,w-I),C.arc(b-I,w-I,I,0,Math.PI/2,!1),C.lineTo(P,w),C.arc(P,w-P,P,Math.PI/2,Math.PI,!1),C.lineTo(0,q),C.arc(q,q,q,Math.PI,Math.PI*3/2,!1)}}})(ct);var it={},Fe={},Ne={};Object.defineProperty(Ne,"__esModule",{value:!0});Ne.RGBComponent=AS;Ne.alphaComponent=bS;Ne.getNumberValidator=RS;Ne.getNumberOrArrayOfNumbersValidator=wS;Ne.getNumberOrAutoValidator=IS;Ne.getStringValidator=OS;Ne.getStringOrGradientValidator=DS;Ne.getFunctionValidator=NS;Ne.getNumberArrayValidator=PS;Ne.getBooleanValidator=xS;Ne.getComponentValidator=kS;const Qs=Le,ft=ct;function Zs(u){return ft.Util._isString(u)?'"'+u+'"':Object.prototype.toString.call(u)==="[object Number]"||ft.Util._isBoolean(u)?u:Object.prototype.toString.call(u)}function AS(u){return u>255?255:u<0?0:Math.round(u)}function bS(u){return u>1?1:u<1e-4?1e-4:u}function RS(){if(Qs.Konva.isUnminified)return function(u,e){return ft.Util._isNumber(u)||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),u}}function wS(u){if(Qs.Konva.isUnminified)return function(e,t){const r=ft.Util._isNumber(e),l=ft.Util._isArray(e)&&e.length==u;return!r&&!l&&ft.Util.warn(Zs(e)+' is a not valid value for "'+t+'" attribute. The value should be a number or Array<number>('+u+")"),e}}function IS(){if(Qs.Konva.isUnminified)return function(u,e){return ft.Util._isNumber(u)||u==="auto"||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),u}}function OS(){if(Qs.Konva.isUnminified)return function(u,e){return ft.Util._isString(u)||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),u}}function DS(){if(Qs.Konva.isUnminified)return function(u,e){const t=ft.Util._isString(u),r=Object.prototype.toString.call(u)==="[object CanvasGradient]"||u&&u.addColorStop;return t||r||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),u}}function NS(){if(Qs.Konva.isUnminified)return function(u,e){return ft.Util._isFunction(u)||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a function.'),u}}function PS(){if(Qs.Konva.isUnminified)return function(u,e){const t=Int8Array?Object.getPrototypeOf(Int8Array):null;return t&&u instanceof t||(ft.Util._isArray(u)?u.forEach(function(r){ft.Util._isNumber(r)||ft.Util.warn('"'+e+'" attribute has non numeric element '+r+". Make sure that all elements are numbers.")}):ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),u}}function xS(){if(Qs.Konva.isUnminified)return function(u,e){return u===!0||u===!1||ft.Util.warn(Zs(u)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),u}}function kS(u){if(Qs.Konva.isUnminified)return function(e,t){return e==null||ft.Util.isObject(e)||ft.Util.warn(Zs(e)+' is a not valid value for "'+t+'" attribute. The value should be an object with properties '+u),e}}(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Factory=void 0;const e=ct,t=Ne,r="get",l="set";u.Factory={addGetterSetter(s,i,f,h,d){u.Factory.addGetter(s,i,f),u.Factory.addSetter(s,i,h,d),u.Factory.addOverloadedGetterSetter(s,i)},addGetter(s,i,f){const h=r+e.Util._capitalize(i);s.prototype[h]=s.prototype[h]||function(){const d=this.attrs[i];return d===void 0?f:d}},addSetter(s,i,f,h){const d=l+e.Util._capitalize(i);s.prototype[d]||u.Factory.overWriteSetter(s,i,f,h)},overWriteSetter(s,i,f,h){const d=l+e.Util._capitalize(i);s.prototype[d]=function(p){return f&&p!==void 0&&p!==null&&(p=f.call(this,p,i)),this._setAttr(i,p),h&&h.call(this),this}},addComponentsGetterSetter(s,i,f,h,d){let p=f.length,v=e.Util._capitalize,T=r+v(i),y=l+v(i),S,A;s.prototype[T]=function(){const O={};for(S=0;S<p;S++)A=f[S],O[A]=this.getAttr(i+v(A));return O};const R=(0,t.getComponentValidator)(f);s.prototype[y]=function(O){let N=this.attrs[i],C;h&&(O=h.call(this,O)),R&&R.call(this,O,i);for(C in O)O.hasOwnProperty(C)&&this._setAttr(i+v(C),O[C]);return O||f.forEach(b=>{this._setAttr(i+v(b),void 0)}),this._fireChangeEvent(i,N,O),d&&d.call(this),this},u.Factory.addOverloadedGetterSetter(s,i)},addOverloadedGetterSetter(s,i){const f=e.Util._capitalize(i),h=l+f,d=r+f;s.prototype[i]=function(){return arguments.length?(this[h](arguments[0]),this):this[d]()}},addDeprecatedGetterSetter(s,i,f,h){e.Util.error("Adding deprecated "+i);const d=r+e.Util._capitalize(i),p=i+" property is deprecated and will be removed soon. Look at Konva change log for more information.";s.prototype[d]=function(){e.Util.error(p);const v=this.attrs[i];return v===void 0?f:v},u.Factory.addSetter(s,i,h,function(){e.Util.error(p)}),u.Factory.addOverloadedGetterSetter(s,i)},backCompat(s,i){e.Util.each(i,function(f,h){const d=s.prototype[h],p=r+e.Util._capitalize(f),v=l+e.Util._capitalize(f);function T(){d.apply(this,arguments),e.Util.error('"'+f+'" method is deprecated and will be removed soon. Use ""'+h+'" instead.')}s.prototype[f]=T,s.prototype[p]=T,s.prototype[v]=T})},afterSetFilter(){this._filterUpToDate=!1}}})(Fe);var Ts={},Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});Ws.HitContext=Ws.SceneContext=Ws.Context=void 0;const Cp=ct,MS=Le;function US(u){let e=[],t=u.length,r=Cp.Util,l,s;for(l=0;l<t;l++)s=u[l],r._isNumber(s)?s=Math.round(s*1e3)/1e3:r._isString(s)||(s=s+""),e.push(s);return e}const j_=",",LS="(",FS=")",$S="([",HS="])",GS=";",VS="()",BS="=",q_=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","roundRect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],jS=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled"],qS=100;class Iu{constructor(e){this.canvas=e,MS.Konva.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(e){e.fillEnabled()&&this._fill(e)}_fill(e){}strokeShape(e){e.hasStroke()&&this._stroke(e)}_stroke(e){}fillStrokeShape(e){e.attrs.fillAfterStrokeEnabled?(this.strokeShape(e),this.fillShape(e)):(this.fillShape(e),this.strokeShape(e))}getTrace(e,t){let r=this.traceArr,l=r.length,s="",i,f,h,d;for(i=0;i<l;i++)f=r[i],h=f.method,h?(d=f.args,s+=h,e?s+=VS:Cp.Util._isArray(d[0])?s+=$S+d.join(j_)+HS:(t&&(d=d.map(p=>typeof p=="number"?Math.floor(p):p)),s+=LS+d.join(j_)+FS)):(s+=f.property,e||(s+=BS+f.val)),s+=GS;return s}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,r;t.push(e),r=t.length,r>=qS&&t.shift()}reset(){const e=this.getCanvas().getPixelRatio();this.setTransform(1*e,0,0,1*e,0,0)}getCanvas(){return this.canvas}clear(e){const t=this.getCanvas();e?this.clearRect(e.x||0,e.y||0,e.width||0,e.height||0):this.clearRect(0,0,t.getWidth()/t.pixelRatio,t.getHeight()/t.pixelRatio)}_applyLineCap(e){const t=e.attrs.lineCap;t&&this.setAttr("lineCap",t)}_applyOpacity(e){const t=e.getAbsoluteOpacity();t!==1&&this.setAttr("globalAlpha",t)}_applyLineJoin(e){const t=e.attrs.lineJoin;t&&this.setAttr("lineJoin",t)}setAttr(e,t){this._context[e]=t}arc(e,t,r,l,s,i){this._context.arc(e,t,r,l,s,i)}arcTo(e,t,r,l,s){this._context.arcTo(e,t,r,l,s)}beginPath(){this._context.beginPath()}bezierCurveTo(e,t,r,l,s,i){this._context.bezierCurveTo(e,t,r,l,s,i)}clearRect(e,t,r,l){this._context.clearRect(e,t,r,l)}clip(...e){this._context.clip.apply(this._context,e)}closePath(){this._context.closePath()}createImageData(e,t){const r=arguments;if(r.length===2)return this._context.createImageData(e,t);if(r.length===1)return this._context.createImageData(e)}createLinearGradient(e,t,r,l){return this._context.createLinearGradient(e,t,r,l)}createPattern(e,t){return this._context.createPattern(e,t)}createRadialGradient(e,t,r,l,s,i){return this._context.createRadialGradient(e,t,r,l,s,i)}drawImage(e,t,r,l,s,i,f,h,d){const p=arguments,v=this._context;p.length===3?v.drawImage(e,t,r):p.length===5?v.drawImage(e,t,r,l,s):p.length===9&&v.drawImage(e,t,r,l,s,i,f,h,d)}ellipse(e,t,r,l,s,i,f,h){this._context.ellipse(e,t,r,l,s,i,f,h)}isPointInPath(e,t,r,l){return r?this._context.isPointInPath(r,e,t,l):this._context.isPointInPath(e,t,l)}fill(...e){this._context.fill.apply(this._context,e)}fillRect(e,t,r,l){this._context.fillRect(e,t,r,l)}strokeRect(e,t,r,l){this._context.strokeRect(e,t,r,l)}fillText(e,t,r,l){l?this._context.fillText(e,t,r,l):this._context.fillText(e,t,r)}measureText(e){return this._context.measureText(e)}getImageData(e,t,r,l){return this._context.getImageData(e,t,r,l)}lineTo(e,t){this._context.lineTo(e,t)}moveTo(e,t){this._context.moveTo(e,t)}rect(e,t,r,l){this._context.rect(e,t,r,l)}roundRect(e,t,r,l,s){this._context.roundRect(e,t,r,l,s)}putImageData(e,t,r){this._context.putImageData(e,t,r)}quadraticCurveTo(e,t,r,l){this._context.quadraticCurveTo(e,t,r,l)}restore(){this._context.restore()}rotate(e){this._context.rotate(e)}save(){this._context.save()}scale(e,t){this._context.scale(e,t)}setLineDash(e){this._context.setLineDash?this._context.setLineDash(e):"mozDash"in this._context?this._context.mozDash=e:"webkitLineDash"in this._context&&(this._context.webkitLineDash=e)}getLineDash(){return this._context.getLineDash()}setTransform(e,t,r,l,s,i){this._context.setTransform(e,t,r,l,s,i)}stroke(e){e?this._context.stroke(e):this._context.stroke()}strokeText(e,t,r,l){this._context.strokeText(e,t,r,l)}transform(e,t,r,l,s,i){this._context.transform(e,t,r,l,s,i)}translate(e,t){this._context.translate(e,t)}_enableTrace(){let e=this,t=q_.length,r=this.setAttr,l,s;const i=function(f){let h=e[f],d;e[f]=function(){return s=US(Array.prototype.slice.call(arguments,0)),d=h.apply(e,arguments),e._trace({method:f,args:s}),d}};for(l=0;l<t;l++)i(q_[l]);e.setAttr=function(){r.apply(e,arguments);const f=arguments[0];let h=arguments[1];(f==="shadowOffsetX"||f==="shadowOffsetY"||f==="shadowBlur")&&(h=h/this.canvas.getPixelRatio()),e._trace({property:f,val:h})}}_applyGlobalCompositeOperation(e){const t=e.attrs.globalCompositeOperation;!t||t==="source-over"||this.setAttr("globalCompositeOperation",t)}}Ws.Context=Iu;jS.forEach(function(u){Object.defineProperty(Iu.prototype,u,{get(){return this._context[u]},set(e){this._context[u]=e}})});class WS extends Iu{constructor(e,{willReadFrequently:t=!1}={}){super(e),this._context=e._canvas.getContext("2d",{willReadFrequently:t})}_fillColor(e){const t=e.fill();this.setAttr("fillStyle",t),e._fillFunc(this)}_fillPattern(e){this.setAttr("fillStyle",e._getFillPattern()),e._fillFunc(this)}_fillLinearGradient(e){const t=e._getLinearGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fillRadialGradient(e){const t=e._getRadialGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fill(e){const t=e.fill(),r=e.getFillPriority();if(t&&r==="color"){this._fillColor(e);return}const l=e.getFillPatternImage();if(l&&r==="pattern"){this._fillPattern(e);return}const s=e.getFillLinearGradientColorStops();if(s&&r==="linear-gradient"){this._fillLinearGradient(e);return}const i=e.getFillRadialGradientColorStops();if(i&&r==="radial-gradient"){this._fillRadialGradient(e);return}t?this._fillColor(e):l?this._fillPattern(e):s?this._fillLinearGradient(e):i&&this._fillRadialGradient(e)}_strokeLinearGradient(e){const t=e.getStrokeLinearGradientStartPoint(),r=e.getStrokeLinearGradientEndPoint(),l=e.getStrokeLinearGradientColorStops(),s=this.createLinearGradient(t.x,t.y,r.x,r.y);if(l){for(let i=0;i<l.length;i+=2)s.addColorStop(l[i],l[i+1]);this.setAttr("strokeStyle",s)}}_stroke(e){const t=e.dash(),r=e.getStrokeScaleEnabled();if(e.hasStroke()){if(!r){this.save();const s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,0,0)}this._applyLineCap(e),t&&e.dashEnabled()&&(this.setLineDash(t),this.setAttr("lineDashOffset",e.dashOffset())),this.setAttr("lineWidth",e.strokeWidth()),e.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),e.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(e):this.setAttr("strokeStyle",e.stroke()),e._strokeFunc(this),r||this.restore()}}_applyShadow(e){var t,r,l;const s=(t=e.getShadowRGBA())!==null&&t!==void 0?t:"black",i=(r=e.getShadowBlur())!==null&&r!==void 0?r:5,f=(l=e.getShadowOffset())!==null&&l!==void 0?l:{x:0,y:0},h=e.getAbsoluteScale(),d=this.canvas.getPixelRatio(),p=h.x*d,v=h.y*d;this.setAttr("shadowColor",s),this.setAttr("shadowBlur",i*Math.min(Math.abs(p),Math.abs(v))),this.setAttr("shadowOffsetX",f.x*p),this.setAttr("shadowOffsetY",f.y*v)}}Ws.SceneContext=WS;class KS extends Iu{constructor(e){super(e),this._context=e._canvas.getContext("2d",{willReadFrequently:!0})}_fill(e){this.save(),this.setAttr("fillStyle",e.colorKey),e._fillFuncHit(this),this.restore()}strokeShape(e){e.hasHitStroke()&&this._stroke(e)}_stroke(e){if(e.hasHitStroke()){const t=e.getStrokeScaleEnabled();if(!t){this.save();const s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,0,0)}this._applyLineCap(e);const r=e.hitStrokeWidth(),l=r==="auto"?e.strokeWidth():r;this.setAttr("lineWidth",l),this.setAttr("strokeStyle",e.colorKey),e._strokeFuncHit(this),t||this.restore()}}}Ws.HitContext=KS;Object.defineProperty(Ts,"__esModule",{value:!0});Ts.HitCanvas=Ts.SceneCanvas=Ts.Canvas=void 0;const _u=ct,Ap=Ws,bp=Le,YS=Fe,zS=Ne;let Mo;function XS(){if(Mo)return Mo;const u=_u.Util.createCanvasElement(),e=u.getContext("2d");return Mo=function(){const t=bp.Konva._global.devicePixelRatio||1,r=e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return t/r}(),_u.Util.releaseCanvas(u),Mo}class Ou{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const r=(e||{}).pixelRatio||bp.Konva.pixelRatio||XS();this.pixelRatio=r,this._canvas=_u.Util.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(e){const t=this.pixelRatio;this.pixelRatio=e,this.setSize(this.getWidth()/t,this.getHeight()/t)}setWidth(e){this.width=this._canvas.width=e*this.pixelRatio,this._canvas.style.width=e+"px";const t=this.pixelRatio;this.getContext()._context.scale(t,t)}setHeight(e){this.height=this._canvas.height=e*this.pixelRatio,this._canvas.style.height=e+"px";const t=this.pixelRatio;this.getContext()._context.scale(t,t)}getWidth(){return this.width}getHeight(){return this.height}setSize(e,t){this.setWidth(e||0),this.setHeight(t||0)}toDataURL(e,t){try{return this._canvas.toDataURL(e,t)}catch{try{return this._canvas.toDataURL()}catch(l){return _u.Util.error("Unable to get data URL. "+l.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}Ts.Canvas=Ou;YS.Factory.addGetterSetter(Ou,"pixelRatio",void 0,(0,zS.getNumberValidator)());class JS extends Ou{constructor(e={width:0,height:0,willReadFrequently:!1}){super(e),this.context=new Ap.SceneContext(this,{willReadFrequently:e.willReadFrequently}),this.setSize(e.width,e.height)}}Ts.SceneCanvas=JS;class QS extends Ou{constructor(e={width:0,height:0}){super(e),this.hitCanvas=!0,this.context=new Ap.HitContext(this),this.setSize(e.width,e.height)}}Ts.HitCanvas=QS;var Du={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.DD=void 0;const e=Le,t=ct;u.DD={get isDragging(){let r=!1;return u.DD._dragElements.forEach(l=>{l.dragStatus==="dragging"&&(r=!0)}),r},justDragged:!1,get node(){let r;return u.DD._dragElements.forEach(l=>{r=l.node}),r},_dragElements:new Map,_drag(r){const l=[];u.DD._dragElements.forEach((s,i)=>{const{node:f}=s,h=f.getStage();h.setPointersPositions(r),s.pointerId===void 0&&(s.pointerId=t.Util._getFirstPointerId(r));const d=h._changedPointerPositions.find(p=>p.id===s.pointerId);if(d){if(s.dragStatus!=="dragging"){const p=f.dragDistance();if(Math.max(Math.abs(d.x-s.startPointerPos.x),Math.abs(d.y-s.startPointerPos.y))<p||(f.startDrag({evt:r}),!f.isDragging()))return}f._setDragPosition(r,s),l.push(f)}}),l.forEach(s=>{s.fire("dragmove",{type:"dragmove",target:s,evt:r},!0)})},_endDragBefore(r){const l=[];u.DD._dragElements.forEach(s=>{const{node:i}=s,f=i.getStage();if(r&&f.setPointersPositions(r),!f._changedPointerPositions.find(p=>p.id===s.pointerId))return;(s.dragStatus==="dragging"||s.dragStatus==="stopped")&&(u.DD.justDragged=!0,e.Konva._mouseListenClick=!1,e.Konva._touchListenClick=!1,e.Konva._pointerListenClick=!1,s.dragStatus="stopped");const d=s.node.getLayer()||s.node instanceof e.Konva.Stage&&s.node;d&&l.indexOf(d)===-1&&l.push(d)}),l.forEach(s=>{s.draw()})},_endDragAfter(r){u.DD._dragElements.forEach((l,s)=>{l.dragStatus==="stopped"&&l.node.fire("dragend",{type:"dragend",target:l.node,evt:r},!0),l.dragStatus!=="dragging"&&u.DD._dragElements.delete(s)})}},e.Konva.isBrowser&&(window.addEventListener("mouseup",u.DD._endDragBefore,!0),window.addEventListener("touchend",u.DD._endDragBefore,!0),window.addEventListener("touchcancel",u.DD._endDragBefore,!0),window.addEventListener("mousemove",u.DD._drag),window.addEventListener("touchmove",u.DD._drag),window.addEventListener("mouseup",u.DD._endDragAfter,!1),window.addEventListener("touchend",u.DD._endDragAfter,!1),window.addEventListener("touchcancel",u.DD._endDragAfter,!1))})(Du);Object.defineProperty(it,"__esModule",{value:!0});it.Node=void 0;const Ge=ct,Pa=Fe,na=Ts,yn=Le,os=Du,vt=Ne,tu="absoluteOpacity",Uo="allEventListeners",Bs="absoluteTransform",W_="absoluteScale",oi="canvas",ZS="Change",e2="children",t2="konva",ff="listening",K_="mouseenter",Y_="mouseleave",z_="set",X_="Shape",su=" ",J_="stage",En="transform",s2="Stage",df="visible",n2=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(su);let i2=1;class xe{constructor(e){this._id=i2++,this.eventListeners={},this.attrs={},this.index=0,this._allEventListeners=null,this.parent=null,this._cache=new Map,this._attachedDepsListeners=new Map,this._lastPos=null,this._batchingTransformChange=!1,this._needClearTransformCache=!1,this._filterUpToDate=!1,this._isUnderCache=!1,this._dragEventId=null,this._shouldFireChangeEvents=!1,this.setAttrs(e),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(e){(e===En||e===Bs)&&this._cache.get(e)?this._cache.get(e).dirty=!0:e?this._cache.delete(e):this._cache.clear()}_getCache(e,t){let r=this._cache.get(e);return(r===void 0||(e===En||e===Bs)&&r.dirty===!0)&&(r=t.call(this),this._cache.set(e,r)),r}_calculate(e,t,r){if(!this._attachedDepsListeners.get(e)){const l=t.map(s=>s+"Change.konva").join(su);this.on(l,()=>{this._clearCache(e)}),this._attachedDepsListeners.set(e,!0)}return this._getCache(e,r)}_getCanvasCache(){return this._cache.get(oi)}_clearSelfAndDescendantCache(e){this._clearCache(e),e===Bs&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(oi)){const{scene:e,filter:t,hit:r}=this._cache.get(oi);Ge.Util.releaseCanvas(e,t,r),this._cache.delete(oi)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(e){const t=e||{};let r={};(t.x===void 0||t.y===void 0||t.width===void 0||t.height===void 0)&&(r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let l=Math.ceil(t.width||r.width),s=Math.ceil(t.height||r.height),i=t.pixelRatio,f=t.x===void 0?Math.floor(r.x):t.x,h=t.y===void 0?Math.floor(r.y):t.y,d=t.offset||0,p=t.drawBorder||!1,v=t.hitCanvasPixelRatio||1;if(!l||!s){Ge.Util.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}const T=Math.abs(Math.round(r.x)-f)>.5?1:0,y=Math.abs(Math.round(r.y)-h)>.5?1:0;l+=d*2+T,s+=d*2+y,f-=d,h-=d;const S=new na.SceneCanvas({pixelRatio:i,width:l,height:s}),A=new na.SceneCanvas({pixelRatio:i,width:0,height:0,willReadFrequently:!0}),R=new na.HitCanvas({pixelRatio:v,width:l,height:s}),O=S.getContext(),N=R.getContext();return R.isCache=!0,S.isCache=!0,this._cache.delete(oi),this._filterUpToDate=!1,t.imageSmoothingEnabled===!1&&(S.getContext()._context.imageSmoothingEnabled=!1,A.getContext()._context.imageSmoothingEnabled=!1),O.save(),N.save(),O.translate(-f,-h),N.translate(-f,-h),this._isUnderCache=!0,this._clearSelfAndDescendantCache(tu),this._clearSelfAndDescendantCache(W_),this.drawScene(S,this),this.drawHit(R,this),this._isUnderCache=!1,O.restore(),N.restore(),p&&(O.save(),O.beginPath(),O.rect(0,0,l,s),O.closePath(),O.setAttr("strokeStyle","red"),O.setAttr("lineWidth",5),O.stroke(),O.restore()),this._cache.set(oi,{scene:S,filter:A,hit:R,x:f,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(oi)}getClientRect(e){throw new Error('abstract "getClientRect" method call')}_transformedRect(e,t){const r=[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height}];let l=1/0,s=1/0,i=-1/0,f=-1/0;const h=this.getAbsoluteTransform(t);return r.forEach(function(d){const p=h.point(d);l===void 0&&(l=i=p.x,s=f=p.y),l=Math.min(l,p.x),s=Math.min(s,p.y),i=Math.max(i,p.x),f=Math.max(f,p.y)}),{x:l,y:s,width:i-l,height:f-s}}_drawCachedSceneCanvas(e){e.save(),e._applyOpacity(this),e._applyGlobalCompositeOperation(this);const t=this._getCanvasCache();e.translate(t.x,t.y);const r=this._getCachedSceneCanvas(),l=r.pixelRatio;e.drawImage(r._canvas,0,0,r.width/l,r.height/l),e.restore()}_drawCachedHitCanvas(e){const t=this._getCanvasCache(),r=t.hit;e.save(),e.translate(t.x,t.y),e.drawImage(r._canvas,0,0,r.width/r.pixelRatio,r.height/r.pixelRatio),e.restore()}_getCachedSceneCanvas(){let e=this.filters(),t=this._getCanvasCache(),r=t.scene,l=t.filter,s=l.getContext(),i,f,h,d;if(e){if(!this._filterUpToDate){const p=r.pixelRatio;l.setSize(r.width/r.pixelRatio,r.height/r.pixelRatio);try{for(i=e.length,s.clear(),s.drawImage(r._canvas,0,0,r.getWidth()/p,r.getHeight()/p),f=s.getImageData(0,0,l.getWidth(),l.getHeight()),h=0;h<i;h++){if(d=e[h],typeof d!="function"){Ge.Util.error("Filter should be type of function, but got "+typeof d+" instead. Please check correct filters");continue}d.call(this,f),s.putImageData(f,0,0)}}catch(v){Ge.Util.error("Unable to apply filter. "+v.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}this._filterUpToDate=!0}return l}return r}on(e,t){if(this._cache&&this._cache.delete(Uo),arguments.length===3)return this._delegate.apply(this,arguments);let r=e.split(su),l=r.length,s,i,f,h,d;for(s=0;s<l;s++)i=r[s],f=i.split("."),h=f[0],d=f[1]||"",this.eventListeners[h]||(this.eventListeners[h]=[]),this.eventListeners[h].push({name:d,handler:t});return this}off(e,t){let r=(e||"").split(su),l=r.length,s,i,f,h,d,p;if(this._cache&&this._cache.delete(Uo),!e)for(i in this.eventListeners)this._off(i);for(s=0;s<l;s++)if(f=r[s],h=f.split("."),d=h[0],p=h[1],d)this.eventListeners[d]&&this._off(d,p,t);else for(i in this.eventListeners)this._off(i,p,t);return this}dispatchEvent(e){const t={target:this,type:e.type,evt:e};return this.fire(e.type,t),this}addEventListener(e,t){return this.on(e,function(r){t.call(this,r.evt)}),this}removeEventListener(e){return this.off(e),this}_delegate(e,t,r){const l=this;this.on(e,function(s){const i=s.target.findAncestors(t,!0,l);for(let f=0;f<i.length;f++)s=Ge.Util.cloneObject(s),s.currentTarget=i[f],r.call(i[f],s)})}remove(){return this.isDragging()&&this.stopDrag(),os.DD._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(Bs),this._clearSelfAndDescendantCache(tu),this._clearSelfAndDescendantCache(W_),this._clearSelfAndDescendantCache(J_),this._clearSelfAndDescendantCache(df),this._clearSelfAndDescendantCache(ff)}_remove(){this._clearCaches();const e=this.getParent();e&&e.children&&(e.children.splice(this.index,1),e._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(e){const t="get"+Ge.Util._capitalize(e);return Ge.Util._isFunction(this[t])?this[t]():this.attrs[e]}getAncestors(){let e=this.getParent(),t=[];for(;e;)t.push(e),e=e.getParent();return t}getAttrs(){return this.attrs||{}}setAttrs(e){return this._batchTransformChanges(()=>{let t,r;if(!e)return this;for(t in e)t!==e2&&(r=z_+Ge.Util._capitalize(t),Ge.Util._isFunction(this[r])?this[r](e[t]):this._setAttr(t,e[t]))}),this}isListening(){return this._getCache(ff,this._isListening)}_isListening(e){if(!this.listening())return!1;const r=this.getParent();return r&&r!==e&&this!==e?r._isListening(e):!0}isVisible(){return this._getCache(df,this._isVisible)}_isVisible(e){if(!this.visible())return!1;const r=this.getParent();return r&&r!==e&&this!==e?r._isVisible(e):!0}shouldDrawHit(e,t=!1){if(e)return this._isVisible(e)&&this._isListening(e);const r=this.getLayer();let l=!1;os.DD._dragElements.forEach(i=>{i.dragStatus==="dragging"&&(i.node.nodeType==="Stage"||i.node.getLayer()===r)&&(l=!0)});const s=!t&&!yn.Konva.hitOnDragEnabled&&(l||yn.Konva.isTransforming());return this.isListening()&&this.isVisible()&&!s}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let e=this.getDepth(),t=this,r=0,l,s,i,f;function h(p){for(l=[],s=p.length,i=0;i<s;i++)f=p[i],r++,f.nodeType!==X_&&(l=l.concat(f.getChildren().slice())),f._id===t._id&&(i=s);l.length>0&&l[0].getDepth()<=e&&h(l)}const d=this.getStage();return t.nodeType!==s2&&d&&h(d.getChildren()),r}getDepth(){let e=0,t=this.parent;for(;t;)e++,t=t.parent;return e}_batchTransformChanges(e){this._batchingTransformChange=!0,e(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(En),this._clearSelfAndDescendantCache(Bs)),this._needClearTransformCache=!1}setPosition(e){return this._batchTransformChanges(()=>{this.x(e.x),this.y(e.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const e=this.getStage();if(!e)return null;const t=e.getPointerPosition();if(!t)return null;const r=this.getAbsoluteTransform().copy();return r.invert(),r.point(t)}getAbsolutePosition(e){let t=!1,r=this.parent;for(;r;){if(r.isCached()){t=!0;break}r=r.parent}t&&!e&&(e=!0);const l=this.getAbsoluteTransform(e).getMatrix(),s=new Ge.Transform,i=this.offset();return s.m=l.slice(),s.translate(i.x,i.y),s.getTranslation()}setAbsolutePosition(e){const{x:t,y:r,...l}=this._clearTransform();this.attrs.x=t,this.attrs.y=r,this._clearCache(En);const s=this._getAbsoluteTransform().copy();return s.invert(),s.translate(e.x,e.y),e={x:this.attrs.x+s.getTranslation().x,y:this.attrs.y+s.getTranslation().y},this._setTransform(l),this.setPosition({x:e.x,y:e.y}),this._clearCache(En),this._clearSelfAndDescendantCache(Bs),this}_setTransform(e){let t;for(t in e)this.attrs[t]=e[t]}_clearTransform(){const e={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,e}move(e){let t=e.x,r=e.y,l=this.x(),s=this.y();return t!==void 0&&(l+=t),r!==void 0&&(s+=r),this.setPosition({x:l,y:s}),this}_eachAncestorReverse(e,t){let r=[],l=this.getParent(),s,i;if(!(t&&t._id===this._id)){for(r.unshift(this);l&&(!t||l._id!==t._id);)r.unshift(l),l=l.parent;for(s=r.length,i=0;i<s;i++)e(r[i])}}rotate(e){return this.rotation(this.rotation()+e),this}moveToTop(){if(!this.parent)return Ge.Util.warn("Node has no parent. moveToTop function is ignored."),!1;const e=this.index,t=this.parent.getChildren().length;return e<t-1?(this.parent.children.splice(e,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return Ge.Util.warn("Node has no parent. moveUp function is ignored."),!1;const e=this.index,t=this.parent.getChildren().length;return e<t-1?(this.parent.children.splice(e,1),this.parent.children.splice(e+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return Ge.Util.warn("Node has no parent. moveDown function is ignored."),!1;const e=this.index;return e>0?(this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return Ge.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;const e=this.index;return e>0?(this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(e){if(!this.parent)return Ge.Util.warn("Node has no parent. zIndex parameter is ignored."),this;(e<0||e>=this.parent.children.length)&&Ge.Util.warn("Unexpected value "+e+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");const t=this.index;return this.parent.children.splice(t,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(tu,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let e=this.opacity();const t=this.getParent();return t&&!t._isUnderCache&&(e*=t.getAbsoluteOpacity()),e}moveTo(e){return this.getParent()!==e&&(this._remove(),e.add(this)),this}toObject(){let e=this.getAttrs(),t,r,l,s,i;const f={attrs:{},className:this.getClassName()};for(t in e)r=e[t],i=Ge.Util.isObject(r)&&!Ge.Util._isPlainObject(r)&&!Ge.Util._isArray(r),!i&&(l=typeof this[t]=="function"&&this[t],delete e[t],s=l?l.call(this):null,e[t]=r,s!==r&&(f.attrs[t]=r));return Ge.Util._prepareToStringify(f)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(e,t,r){const l=[];t&&this._isMatch(e)&&l.push(this);let s=this.parent;for(;s;){if(s===r)return l;s._isMatch(e)&&l.push(s),s=s.parent}return l}isAncestorOf(e){return!1}findAncestor(e,t,r){return this.findAncestors(e,t,r)[0]}_isMatch(e){if(!e)return!1;if(typeof e=="function")return e(this);let t=e.replace(/ /g,"").split(","),r=t.length,l,s;for(l=0;l<r;l++)if(s=t[l],Ge.Util.isValidSelector(s)||(Ge.Util.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Ge.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Ge.Util.warn("Konva is awesome, right?")),s.charAt(0)==="#"){if(this.id()===s.slice(1))return!0}else if(s.charAt(0)==="."){if(this.hasName(s.slice(1)))return!0}else if(this.className===s||this.nodeType===s)return!0;return!1}getLayer(){const e=this.getParent();return e?e.getLayer():null}getStage(){return this._getCache(J_,this._getStage)}_getStage(){const e=this.getParent();return e?e.getStage():null}fire(e,t={},r){return t.target=t.target||this,r?this._fireAndBubble(e,t):this._fire(e,t),this}getAbsoluteTransform(e){return e?this._getAbsoluteTransform(e):this._getCache(Bs,this._getAbsoluteTransform)}_getAbsoluteTransform(e){let t;if(e)return t=new Ge.Transform,this._eachAncestorReverse(function(r){const l=r.transformsEnabled();l==="all"?t.multiply(r.getTransform()):l==="position"&&t.translate(r.x()-r.offsetX(),r.y()-r.offsetY())},e),t;{t=this._cache.get(Bs)||new Ge.Transform,this.parent?this.parent.getAbsoluteTransform().copyInto(t):t.reset();const r=this.transformsEnabled();if(r==="all")t.multiply(this.getTransform());else if(r==="position"){const l=this.attrs.x||0,s=this.attrs.y||0,i=this.attrs.offsetX||0,f=this.attrs.offsetY||0;t.translate(l-i,s-f)}return t.dirty=!1,t}}getAbsoluteScale(e){let t=this;for(;t;)t._isUnderCache&&(e=t),t=t.getParent();const l=this.getAbsoluteTransform(e).decompose();return{x:l.scaleX,y:l.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(En,this._getTransform)}_getTransform(){var e,t;const r=this._cache.get(En)||new Ge.Transform;r.reset();const l=this.x(),s=this.y(),i=yn.Konva.getAngle(this.rotation()),f=(e=this.attrs.scaleX)!==null&&e!==void 0?e:1,h=(t=this.attrs.scaleY)!==null&&t!==void 0?t:1,d=this.attrs.skewX||0,p=this.attrs.skewY||0,v=this.attrs.offsetX||0,T=this.attrs.offsetY||0;return(l!==0||s!==0)&&r.translate(l,s),i!==0&&r.rotate(i),(d!==0||p!==0)&&r.skew(d,p),(f!==1||h!==1)&&r.scale(f,h),(v!==0||T!==0)&&r.translate(-1*v,-1*T),r.dirty=!1,r}clone(e){let t=Ge.Util.cloneObject(this.attrs),r,l,s,i,f;for(r in e)t[r]=e[r];const h=new this.constructor(t);for(r in this.eventListeners)for(l=this.eventListeners[r],s=l.length,i=0;i<s;i++)f=l[i],f.name.indexOf(t2)<0&&(h.eventListeners[r]||(h.eventListeners[r]=[]),h.eventListeners[r].push(f));return h}_toKonvaCanvas(e){e=e||{};const t=this.getClientRect(),r=this.getStage(),l=e.x!==void 0?e.x:Math.floor(t.x),s=e.y!==void 0?e.y:Math.floor(t.y),i=e.pixelRatio||1,f=new na.SceneCanvas({width:e.width||Math.ceil(t.width)||(r?r.width():0),height:e.height||Math.ceil(t.height)||(r?r.height():0),pixelRatio:i}),h=f.getContext(),d=new na.SceneCanvas({width:f.width/f.pixelRatio+Math.abs(l),height:f.height/f.pixelRatio+Math.abs(s),pixelRatio:f.pixelRatio});return e.imageSmoothingEnabled===!1&&(h._context.imageSmoothingEnabled=!1),h.save(),(l||s)&&h.translate(-1*l,-1*s),this.drawScene(f,void 0,d),h.restore(),f}toCanvas(e){return this._toKonvaCanvas(e)._canvas}toDataURL(e){e=e||{};const t=e.mimeType||null,r=e.quality||null,l=this._toKonvaCanvas(e).toDataURL(t,r);return e.callback&&e.callback(l),l}toImage(e){return new Promise((t,r)=>{try{const l=e==null?void 0:e.callback;l&&delete e.callback,Ge.Util._urlToImage(this.toDataURL(e),function(s){t(s),l==null||l(s)})}catch(l){r(l)}})}toBlob(e){return new Promise((t,r)=>{try{const l=e==null?void 0:e.callback;l&&delete e.callback,this.toCanvas(e).toBlob(s=>{t(s),l==null||l(s)},e==null?void 0:e.mimeType,e==null?void 0:e.quality)}catch(l){r(l)}})}setSize(e){return this.width(e.width),this.height(e.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():yn.Konva.dragDistance}_off(e,t,r){let l=this.eventListeners[e],s,i,f;for(s=0;s<l.length;s++)if(i=l[s].name,f=l[s].handler,(i!=="konva"||t==="konva")&&(!t||i===t)&&(!r||r===f)){if(l.splice(s,1),l.length===0){delete this.eventListeners[e];break}s--}}_fireChangeEvent(e,t,r){this._fire(e+ZS,{oldVal:t,newVal:r})}addName(e){if(!this.hasName(e)){const t=this.name(),r=t?t+" "+e:e;this.name(r)}return this}hasName(e){if(!e)return!1;const t=this.name();return t?(t||"").split(/\s/g).indexOf(e)!==-1:!1}removeName(e){const t=(this.name()||"").split(/\s/g),r=t.indexOf(e);return r!==-1&&(t.splice(r,1),this.name(t.join(" "))),this}setAttr(e,t){const r=this[z_+Ge.Util._capitalize(e)];return Ge.Util._isFunction(r)?r.call(this,t):this._setAttr(e,t),this}_requestDraw(){if(yn.Konva.autoDrawEnabled){const e=this.getLayer()||this.getStage();e==null||e.batchDraw()}}_setAttr(e,t){const r=this.attrs[e];r===t&&!Ge.Util.isObject(t)||(t==null?delete this.attrs[e]:this.attrs[e]=t,this._shouldFireChangeEvents&&this._fireChangeEvent(e,r,t),this._requestDraw())}_setComponentAttr(e,t,r){let l;r!==void 0&&(l=this.attrs[e],l||(this.attrs[e]=this.getAttr(e)),this.attrs[e][t]=r,this._fireChangeEvent(e,l,r))}_fireAndBubble(e,t,r){if(t&&this.nodeType===X_&&(t.target=this),!((e===K_||e===Y_)&&(r&&(this===r||this.isAncestorOf&&this.isAncestorOf(r))||this.nodeType==="Stage"&&!r))){this._fire(e,t);const s=(e===K_||e===Y_)&&r&&r.isAncestorOf&&r.isAncestorOf(this)&&!r.isAncestorOf(this.parent);(t&&!t.cancelBubble||!t)&&this.parent&&this.parent.isListening()&&!s&&(r&&r.parent?this._fireAndBubble.call(this.parent,e,t,r):this._fireAndBubble.call(this.parent,e,t))}}_getProtoListeners(e){var t,r,l;const s=(t=this._cache.get(Uo))!==null&&t!==void 0?t:{};let i=s==null?void 0:s[e];if(i===void 0){i=[];let f=Object.getPrototypeOf(this);for(;f;){const h=(l=(r=f.eventListeners)===null||r===void 0?void 0:r[e])!==null&&l!==void 0?l:[];i.push(...h),f=Object.getPrototypeOf(f)}s[e]=i,this._cache.set(Uo,s)}return i}_fire(e,t){t=t||{},t.currentTarget=this,t.type=e;const r=this._getProtoListeners(e);if(r)for(var l=0;l<r.length;l++)r[l].handler.call(this,t);const s=this.eventListeners[e];if(s)for(var l=0;l<s.length;l++)s[l].handler.call(this,t)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(e){const t=e?e.pointerId:void 0,r=this.getStage(),l=this.getAbsolutePosition();if(!r)return;const s=r._getPointerById(t)||r._changedPointerPositions[0]||l;os.DD._dragElements.set(this._id,{node:this,startPointerPos:s,offset:{x:s.x-l.x,y:s.y-l.y},dragStatus:"ready",pointerId:t})}startDrag(e,t=!0){os.DD._dragElements.has(this._id)||this._createDragElement(e);const r=os.DD._dragElements.get(this._id);r.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:e&&e.evt},t)}_setDragPosition(e,t){const r=this.getStage()._getPointerById(t.pointerId);if(!r)return;let l={x:r.x-t.offset.x,y:r.y-t.offset.y};const s=this.dragBoundFunc();if(s!==void 0){const i=s.call(this,l,e);i?l=i:Ge.Util.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==l.x||this._lastPos.y!==l.y)&&(this.setAbsolutePosition(l),this._requestDraw()),this._lastPos=l}stopDrag(e){const t=os.DD._dragElements.get(this._id);t&&(t.dragStatus="stopped"),os.DD._endDragBefore(e),os.DD._endDragAfter(e)}setDraggable(e){this._setAttr("draggable",e),this._dragChange()}isDragging(){const e=os.DD._dragElements.get(this._id);return e?e.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(e){if(!(!(e.evt.button!==void 0)||yn.Konva.dragButtons.indexOf(e.evt.button)>=0)||this.isDragging())return;let l=!1;os.DD._dragElements.forEach(s=>{this.isAncestorOf(s.node)&&(l=!0)}),l||this._createDragElement(e)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const t=os.DD._dragElements.get(this._id),r=t&&t.dragStatus==="dragging",l=t&&t.dragStatus==="ready";r?this.stopDrag():l&&os.DD._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(e={x:0,y:0}){const t=this.getStage();if(!t)return!1;const r={x:-e.x,y:-e.y,width:t.width()+2*e.x,height:t.height()+2*e.y};return Ge.Util.haveIntersection(r,this.getClientRect())}static create(e,t){return Ge.Util._isString(e)&&(e=JSON.parse(e)),this._createNode(e,t)}static _createNode(e,t){let r=xe.prototype.getClassName.call(e),l=e.children,s,i,f;t&&(e.attrs.container=t),yn.Konva[r]||(Ge.Util.warn('Can not find a node with class name "'+r+'". Fallback to "Shape".'),r="Shape");const h=yn.Konva[r];if(s=new h(e.attrs),l)for(i=l.length,f=0;f<i;f++)s.add(xe._createNode(l[f]));return s}}it.Node=xe;xe.prototype.nodeType="Node";xe.prototype._attrsAffectingSize=[];xe.prototype.eventListeners={};xe.prototype.on.call(xe.prototype,n2,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(En),this._clearSelfAndDescendantCache(Bs)});xe.prototype.on.call(xe.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(df)});xe.prototype.on.call(xe.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(ff)});xe.prototype.on.call(xe.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(tu)});const Xe=Pa.Factory.addGetterSetter;Xe(xe,"zIndex");Xe(xe,"absolutePosition");Xe(xe,"position");Xe(xe,"x",0,(0,vt.getNumberValidator)());Xe(xe,"y",0,(0,vt.getNumberValidator)());Xe(xe,"globalCompositeOperation","source-over",(0,vt.getStringValidator)());Xe(xe,"opacity",1,(0,vt.getNumberValidator)());Xe(xe,"name","",(0,vt.getStringValidator)());Xe(xe,"id","",(0,vt.getStringValidator)());Xe(xe,"rotation",0,(0,vt.getNumberValidator)());Pa.Factory.addComponentsGetterSetter(xe,"scale",["x","y"]);Xe(xe,"scaleX",1,(0,vt.getNumberValidator)());Xe(xe,"scaleY",1,(0,vt.getNumberValidator)());Pa.Factory.addComponentsGetterSetter(xe,"skew",["x","y"]);Xe(xe,"skewX",0,(0,vt.getNumberValidator)());Xe(xe,"skewY",0,(0,vt.getNumberValidator)());Pa.Factory.addComponentsGetterSetter(xe,"offset",["x","y"]);Xe(xe,"offsetX",0,(0,vt.getNumberValidator)());Xe(xe,"offsetY",0,(0,vt.getNumberValidator)());Xe(xe,"dragDistance",null,(0,vt.getNumberValidator)());Xe(xe,"width",0,(0,vt.getNumberValidator)());Xe(xe,"height",0,(0,vt.getNumberValidator)());Xe(xe,"listening",!0,(0,vt.getBooleanValidator)());Xe(xe,"preventDefault",!0,(0,vt.getBooleanValidator)());Xe(xe,"filters",null,function(u){return this._filterUpToDate=!1,u});Xe(xe,"visible",!0,(0,vt.getBooleanValidator)());Xe(xe,"transformsEnabled","all",(0,vt.getStringValidator)());Xe(xe,"size");Xe(xe,"dragBoundFunc");Xe(xe,"draggable",!1,(0,vt.getBooleanValidator)());Pa.Factory.backCompat(xe,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var pi={};Object.defineProperty(pi,"__esModule",{value:!0});pi.Container=void 0;const Cr=Fe,Oh=it,Nu=Ne;class mi extends Oh.Node{constructor(){super(...arguments),this.children=[]}getChildren(e){if(!e)return this.children||[];const t=this.children||[],r=[];return t.forEach(function(l){e(l)&&r.push(l)}),r}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.destroy()}),this.children=[],this._requestDraw(),this}add(...e){if(e.length===0)return this;if(e.length>1){for(let r=0;r<e.length;r++)this.add(e[r]);return this}const t=e[0];return t.getParent()?(t.moveTo(this),this):(this._validateAdd(t),t.index=this.getChildren().length,t.parent=this,t._clearCaches(),this.getChildren().push(t),this._fire("add",{child:t}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(e){return this._generalFind(e,!1)}findOne(e){const t=this._generalFind(e,!0);return t.length>0?t[0]:void 0}_generalFind(e,t){const r=[];return this._descendants(l=>{const s=l._isMatch(e);return s&&r.push(l),!!(s&&t)}),r}_descendants(e){let t=!1;const r=this.getChildren();for(const l of r){if(t=e(l),t)return!0;if(l.hasChildren()&&(t=l._descendants(e),t))return!0}return!1}toObject(){const e=Oh.Node.prototype.toObject.call(this);return e.children=[],this.getChildren().forEach(t=>{e.children.push(t.toObject())}),e}isAncestorOf(e){let t=e.getParent();for(;t;){if(t._id===this._id)return!0;t=t.getParent()}return!1}clone(e){const t=Oh.Node.prototype.clone.call(this,e);return this.getChildren().forEach(function(r){t.add(r.clone())}),t}getAllIntersections(e){const t=[];return this.find("Shape").forEach(r=>{r.isVisible()&&r.intersects(e)&&t.push(r)}),t}_clearSelfAndDescendantCache(e){var t;super._clearSelfAndDescendantCache(e),!this.isCached()&&((t=this.children)===null||t===void 0||t.forEach(function(r){r._clearSelfAndDescendantCache(e)}))}_setChildrenIndices(){var e;(e=this.children)===null||e===void 0||e.forEach(function(t,r){t.index=r}),this._requestDraw()}drawScene(e,t,r){const l=this.getLayer(),s=e||l&&l.getCanvas(),i=s&&s.getContext(),f=this._getCanvasCache(),h=f&&f.scene,d=s&&s.isCache;if(!this.isVisible()&&!d)return this;if(h){i.save();const p=this.getAbsoluteTransform(t).getMatrix();i.transform(p[0],p[1],p[2],p[3],p[4],p[5]),this._drawCachedSceneCanvas(i),i.restore()}else this._drawChildren("drawScene",s,t,r);return this}drawHit(e,t){if(!this.shouldDrawHit(t))return this;const r=this.getLayer(),l=e||r&&r.hitCanvas,s=l&&l.getContext(),i=this._getCanvasCache();if(i&&i.hit){s.save();const h=this.getAbsoluteTransform(t).getMatrix();s.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedHitCanvas(s),s.restore()}else this._drawChildren("drawHit",l,t);return this}_drawChildren(e,t,r,l){var s;const i=t&&t.getContext(),f=this.clipWidth(),h=this.clipHeight(),d=this.clipFunc(),p=typeof f=="number"&&typeof h=="number"||d,v=r===this;if(p){i.save();const y=this.getAbsoluteTransform(r);let S=y.getMatrix();i.transform(S[0],S[1],S[2],S[3],S[4],S[5]),i.beginPath();let A;if(d)A=d.call(this,i,this);else{const R=this.clipX(),O=this.clipY();i.rect(R||0,O||0,f,h)}i.clip.apply(i,A),S=y.copy().invert().getMatrix(),i.transform(S[0],S[1],S[2],S[3],S[4],S[5])}const T=!v&&this.globalCompositeOperation()!=="source-over"&&e==="drawScene";T&&(i.save(),i._applyGlobalCompositeOperation(this)),(s=this.children)===null||s===void 0||s.forEach(function(y){y[e](t,r,l)}),T&&i.restore(),p&&i.restore()}getClientRect(e={}){var t;const r=e.skipTransform,l=e.relativeTo;let s,i,f,h,d={x:1/0,y:1/0,width:0,height:0};const p=this;(t=this.children)===null||t===void 0||t.forEach(function(y){if(!y.visible())return;const S=y.getClientRect({relativeTo:p,skipShadow:e.skipShadow,skipStroke:e.skipStroke});S.width===0&&S.height===0||(s===void 0?(s=S.x,i=S.y,f=S.x+S.width,h=S.y+S.height):(s=Math.min(s,S.x),i=Math.min(i,S.y),f=Math.max(f,S.x+S.width),h=Math.max(h,S.y+S.height)))});const v=this.find("Shape");let T=!1;for(let y=0;y<v.length;y++)if(v[y]._isVisible(this)){T=!0;break}return T&&s!==void 0?d={x:s,y:i,width:f-s,height:h-i}:d={x:0,y:0,width:0,height:0},r?d:this._transformedRect(d,l)}}pi.Container=mi;Cr.Factory.addComponentsGetterSetter(mi,"clip",["x","y","width","height"]);Cr.Factory.addGetterSetter(mi,"clipX",void 0,(0,Nu.getNumberValidator)());Cr.Factory.addGetterSetter(mi,"clipY",void 0,(0,Nu.getNumberValidator)());Cr.Factory.addGetterSetter(mi,"clipWidth",void 0,(0,Nu.getNumberValidator)());Cr.Factory.addGetterSetter(mi,"clipHeight",void 0,(0,Nu.getNumberValidator)());Cr.Factory.addGetterSetter(mi,"clipFunc");var Rp={},Dn={};Object.defineProperty(Dn,"__esModule",{value:!0});Dn.getCapturedShape=l2;Dn.createEvent=Gf;Dn.hasPointerCapture=a2;Dn.setPointerCapture=o2;Dn.releaseCapture=Ip;const r2=Le,Ta=new Map,wp=r2.Konva._global.PointerEvent!==void 0;function l2(u){return Ta.get(u)}function Gf(u){return{evt:u,pointerId:u.pointerId}}function a2(u,e){return Ta.get(u)===e}function o2(u,e){Ip(u),e.getStage()&&(Ta.set(u,e),wp&&e._fire("gotpointercapture",Gf(new PointerEvent("gotpointercapture"))))}function Ip(u,e){const t=Ta.get(u);if(!t)return;const r=t.getStage();r&&r.content,Ta.delete(u),wp&&t._fire("lostpointercapture",Gf(new PointerEvent("lostpointercapture")))}(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Stage=u.stages=void 0;const e=ct,t=Fe,r=pi,l=Le,s=Ts,i=Du,f=Le,h=Dn,d="Stage",p="string",v="px",T="mouseout",y="mouseleave",S="mouseover",A="mouseenter",R="mousemove",O="mousedown",N="mouseup",C="pointermove",b="pointerdown",w="pointerup",F="pointercancel",q="lostpointercapture",D="pointerout",P="pointerleave",I="pointerover",x="pointerenter",U="contextmenu",B="touchstart",z="touchend",L="touchmove",V="touchcancel",J="wheel",Pe=5,ee=[[A,"_pointerenter"],[O,"_pointerdown"],[R,"_pointermove"],[N,"_pointerup"],[y,"_pointerleave"],[B,"_pointerdown"],[L,"_pointermove"],[z,"_pointerup"],[V,"_pointercancel"],[S,"_pointerover"],[J,"_wheel"],[U,"_contextmenu"],[b,"_pointerdown"],[C,"_pointermove"],[w,"_pointerup"],[F,"_pointercancel"],[q,"_lostpointercapture"]],j={mouse:{[D]:T,[P]:y,[I]:S,[x]:A,[C]:R,[b]:O,[w]:N,[F]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[D]:"touchout",[P]:"touchleave",[I]:"touchover",[x]:"touchenter",[C]:L,[b]:B,[w]:z,[F]:V,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[D]:D,[P]:P,[I]:I,[x]:x,[C]:C,[b]:b,[w]:w,[F]:F,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},K=be=>be.indexOf("pointer")>=0?"pointer":be.indexOf("touch")>=0?"touch":"mouse",ie=be=>{const M=K(be);if(M==="pointer")return l.Konva.pointerEventsEnabled&&j.pointer;if(M==="touch")return j.touch;if(M==="mouse")return j.mouse};function ue(be={}){return(be.clipFunc||be.clipWidth||be.clipHeight)&&e.Util.warn("Stage does not support clipping. Please use clip for Layers or Groups."),be}const Ce="Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);";u.stages=[];class ke extends r.Container{constructor(M){super(ue(M)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),u.stages.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ue(this.attrs)}),this._checkVisibility()}_validateAdd(M){const Y=M.getType()==="Layer",Ee=M.getType()==="FastLayer";Y||Ee||e.Util.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const M=this.visible()?"":"none";this.content.style.display=M}setContainer(M){if(typeof M===p){if(M.charAt(0)==="."){const Ee=M.slice(1);M=document.getElementsByClassName(Ee)[0]}else{var Y;M.charAt(0)!=="#"?Y=M:Y=M.slice(1),M=document.getElementById(Y)}if(!M)throw"Can not find container in document with id "+Y}return this._setAttr("container",M),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),M.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){let M=this.children,Y=M.length,Ee;for(Ee=0;Ee<Y;Ee++)M[Ee].clear();return this}clone(M){return M||(M={}),M.container=typeof document<"u"&&document.createElement("div"),r.Container.prototype.clone.call(this,M)}destroy(){super.destroy();const M=this.content;M&&e.Util._isInDocument(M)&&this.container().removeChild(M);const Y=u.stages.indexOf(this);return Y>-1&&u.stages.splice(Y,1),e.Util.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const M=this._pointerPositions[0]||this._changedPointerPositions[0];return M?{x:M.x,y:M.y}:(e.Util.warn(Ce),null)}_getPointerById(M){return this._pointerPositions.find(Y=>Y.id===M)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(M){M=M||{},M.x=M.x||0,M.y=M.y||0,M.width=M.width||this.width(),M.height=M.height||this.height();const Y=new s.SceneCanvas({width:M.width,height:M.height,pixelRatio:M.pixelRatio||1}),Ee=Y.getContext()._context,Me=this.children;return(M.x||M.y)&&Ee.translate(-1*M.x,-1*M.y),Me.forEach(function(fe){if(!fe.isVisible())return;const _e=fe._toKonvaCanvas(M);Ee.drawImage(_e._canvas,M.x,M.y,_e.getWidth()/_e.getPixelRatio(),_e.getHeight()/_e.getPixelRatio())}),Y}getIntersection(M){if(!M)return null;let Y=this.children,Ee=Y.length,Me=Ee-1,fe;for(fe=Me;fe>=0;fe--){const _e=Y[fe].getIntersection(M);if(_e)return _e}return null}_resizeDOM(){const M=this.width(),Y=this.height();this.content&&(this.content.style.width=M+v,this.content.style.height=Y+v),this.bufferCanvas.setSize(M,Y),this.bufferHitCanvas.setSize(M,Y),this.children.forEach(Ee=>{Ee.setSize({width:M,height:Y}),Ee.draw()})}add(M,...Y){if(arguments.length>1){for(let Me=0;Me<arguments.length;Me++)this.add(arguments[Me]);return this}super.add(M);const Ee=this.children.length;return Ee>Pe&&e.Util.warn("The stage has "+Ee+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),M.setSize({width:this.width(),height:this.height()}),M.draw(),l.Konva.isBrowser&&this.content.appendChild(M.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(M){return h.hasPointerCapture(M,this)}setPointerCapture(M){h.setPointerCapture(M,this)}releaseCapture(M){h.releaseCapture(M,this)}getLayers(){return this.children}_bindContentEvents(){l.Konva.isBrowser&&ee.forEach(([M,Y])=>{this.content.addEventListener(M,Ee=>{this[Y](Ee)},{passive:!1})})}_pointerenter(M){this.setPointersPositions(M);const Y=ie(M.type);Y&&this._fire(Y.pointerenter,{evt:M,target:this,currentTarget:this})}_pointerover(M){this.setPointersPositions(M);const Y=ie(M.type);Y&&this._fire(Y.pointerover,{evt:M,target:this,currentTarget:this})}_getTargetShape(M){let Y=this[M+"targetShape"];return Y&&!Y.getStage()&&(Y=null),Y}_pointerleave(M){const Y=ie(M.type),Ee=K(M.type);if(!Y)return;this.setPointersPositions(M);const Me=this._getTargetShape(Ee),fe=!(l.Konva.isDragging()||l.Konva.isTransforming())||l.Konva.hitOnDragEnabled;Me&&fe?(Me._fireAndBubble(Y.pointerout,{evt:M}),Me._fireAndBubble(Y.pointerleave,{evt:M}),this._fire(Y.pointerleave,{evt:M,target:this,currentTarget:this}),this[Ee+"targetShape"]=null):fe&&(this._fire(Y.pointerleave,{evt:M,target:this,currentTarget:this}),this._fire(Y.pointerout,{evt:M,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(M){const Y=ie(M.type),Ee=K(M.type);if(!Y)return;this.setPointersPositions(M);let Me=!1;this._changedPointerPositions.forEach(fe=>{const _e=this.getIntersection(fe);if(i.DD.justDragged=!1,l.Konva["_"+Ee+"ListenClick"]=!0,!_e||!_e.isListening()){this[Ee+"ClickStartShape"]=void 0;return}l.Konva.capturePointerEventsEnabled&&_e.setPointerCapture(fe.id),this[Ee+"ClickStartShape"]=_e,_e._fireAndBubble(Y.pointerdown,{evt:M,pointerId:fe.id}),Me=!0;const we=M.type.indexOf("touch")>=0;_e.preventDefault()&&M.cancelable&&we&&M.preventDefault()}),Me||this._fire(Y.pointerdown,{evt:M,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(M){const Y=ie(M.type),Ee=K(M.type);if(!Y||(l.Konva.isDragging()&&i.DD.node.preventDefault()&&M.cancelable&&M.preventDefault(),this.setPointersPositions(M),!(!(l.Konva.isDragging()||l.Konva.isTransforming())||l.Konva.hitOnDragEnabled)))return;const fe={};let _e=!1;const we=this._getTargetShape(Ee);this._changedPointerPositions.forEach(De=>{const ce=h.getCapturedShape(De.id)||this.getIntersection(De),de=De.id,ge={evt:M,pointerId:de},Oe=we!==ce;if(Oe&&we&&(we._fireAndBubble(Y.pointerout,{...ge},ce),we._fireAndBubble(Y.pointerleave,{...ge},ce)),ce){if(fe[ce._id])return;fe[ce._id]=!0}ce&&ce.isListening()?(_e=!0,Oe&&(ce._fireAndBubble(Y.pointerover,{...ge},we),ce._fireAndBubble(Y.pointerenter,{...ge},we),this[Ee+"targetShape"]=ce),ce._fireAndBubble(Y.pointermove,{...ge})):we&&(this._fire(Y.pointerover,{evt:M,target:this,currentTarget:this,pointerId:de}),this[Ee+"targetShape"]=null)}),_e||this._fire(Y.pointermove,{evt:M,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(M){const Y=ie(M.type),Ee=K(M.type);if(!Y)return;this.setPointersPositions(M);const Me=this[Ee+"ClickStartShape"],fe=this[Ee+"ClickEndShape"],_e={};let we=!1;this._changedPointerPositions.forEach(De=>{const ce=h.getCapturedShape(De.id)||this.getIntersection(De);if(ce){if(ce.releaseCapture(De.id),_e[ce._id])return;_e[ce._id]=!0}const de=De.id,ge={evt:M,pointerId:de};let Oe=!1;l.Konva["_"+Ee+"InDblClickWindow"]?(Oe=!0,clearTimeout(this[Ee+"DblTimeout"])):i.DD.justDragged||(l.Konva["_"+Ee+"InDblClickWindow"]=!0,clearTimeout(this[Ee+"DblTimeout"])),this[Ee+"DblTimeout"]=setTimeout(function(){l.Konva["_"+Ee+"InDblClickWindow"]=!1},l.Konva.dblClickWindow),ce&&ce.isListening()?(we=!0,this[Ee+"ClickEndShape"]=ce,ce._fireAndBubble(Y.pointerup,{...ge}),l.Konva["_"+Ee+"ListenClick"]&&Me&&Me===ce&&(ce._fireAndBubble(Y.pointerclick,{...ge}),Oe&&fe&&fe===ce&&ce._fireAndBubble(Y.pointerdblclick,{...ge}))):(this[Ee+"ClickEndShape"]=null,l.Konva["_"+Ee+"ListenClick"]&&this._fire(Y.pointerclick,{evt:M,target:this,currentTarget:this,pointerId:de}),Oe&&this._fire(Y.pointerdblclick,{evt:M,target:this,currentTarget:this,pointerId:de}))}),we||this._fire(Y.pointerup,{evt:M,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),l.Konva["_"+Ee+"ListenClick"]=!1,M.cancelable&&Ee!=="touch"&&M.preventDefault()}_contextmenu(M){this.setPointersPositions(M);const Y=this.getIntersection(this.getPointerPosition());Y&&Y.isListening()?Y._fireAndBubble(U,{evt:M}):this._fire(U,{evt:M,target:this,currentTarget:this})}_wheel(M){this.setPointersPositions(M);const Y=this.getIntersection(this.getPointerPosition());Y&&Y.isListening()?Y._fireAndBubble(J,{evt:M}):this._fire(J,{evt:M,target:this,currentTarget:this})}_pointercancel(M){this.setPointersPositions(M);const Y=h.getCapturedShape(M.pointerId)||this.getIntersection(this.getPointerPosition());Y&&Y._fireAndBubble(w,h.createEvent(M)),h.releaseCapture(M.pointerId)}_lostpointercapture(M){h.releaseCapture(M.pointerId)}setPointersPositions(M){let Y=this._getContentPosition(),Ee=null,Me=null;M=M||window.event,M.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(M.touches,fe=>{this._pointerPositions.push({id:fe.identifier,x:(fe.clientX-Y.left)/Y.scaleX,y:(fe.clientY-Y.top)/Y.scaleY})}),Array.prototype.forEach.call(M.changedTouches||M.touches,fe=>{this._changedPointerPositions.push({id:fe.identifier,x:(fe.clientX-Y.left)/Y.scaleX,y:(fe.clientY-Y.top)/Y.scaleY})})):(Ee=(M.clientX-Y.left)/Y.scaleX,Me=(M.clientY-Y.top)/Y.scaleY,this.pointerPos={x:Ee,y:Me},this._pointerPositions=[{x:Ee,y:Me,id:e.Util._getFirstPointerId(M)}],this._changedPointerPositions=[{x:Ee,y:Me,id:e.Util._getFirstPointerId(M)}])}_setPointerPosition(M){e.Util.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(M)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};const M=this.content.getBoundingClientRect();return{top:M.top,left:M.left,scaleX:M.width/this.content.clientWidth||1,scaleY:M.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new s.SceneCanvas({width:this.width(),height:this.height()}),this.bufferHitCanvas=new s.HitCanvas({pixelRatio:1,width:this.width(),height:this.height()}),!l.Konva.isBrowser)return;const M=this.container();if(!M)throw"Stage has no container. A container is required.";M.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),M.appendChild(this.content),this._resizeDOM()}cache(){return e.Util.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."),this}clearCache(){return this}batchDraw(){return this.getChildren().forEach(function(M){M.batchDraw()}),this}}u.Stage=ke,ke.prototype.nodeType=d,(0,f._registerNode)(ke),t.Factory.addGetterSetter(ke,"container"),l.Konva.isBrowser&&document.addEventListener("visibilitychange",()=>{u.stages.forEach(be=>{be.batchDraw()})})})(Rp);var xa={},bt={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Shape=u.shapes=void 0;const e=Le,t=ct,r=Fe,l=it,s=Ne,i=Le,f=Dn,h="hasShadow",d="shadowRGBA",p="patternImage",v="linearGradient",T="radialGradient";let y;function S(){return y||(y=t.Util.createCanvasElement().getContext("2d"),y)}u.shapes={};function A(P){const I=this.attrs.fillRule;I?P.fill(I):P.fill()}function R(P){P.stroke()}function O(P){const I=this.attrs.fillRule;I?P.fill(I):P.fill()}function N(P){P.stroke()}function C(){this._clearCache(h)}function b(){this._clearCache(d)}function w(){this._clearCache(p)}function F(){this._clearCache(v)}function q(){this._clearCache(T)}class D extends l.Node{constructor(I){super(I);let x;for(;x=t.Util.getRandomColor(),!(x&&!(x in u.shapes)););this.colorKey=x,u.shapes[x]=this}getContext(){return t.Util.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return t.Util.warn("shape.getCanvas() method is deprecated. Please do not use it."),this.getLayer().getCanvas()}getSceneFunc(){return this.attrs.sceneFunc||this._sceneFunc}getHitFunc(){return this.attrs.hitFunc||this._hitFunc}hasShadow(){return this._getCache(h,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(p,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const x=S().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(x&&x.setTransform){const U=new t.Transform;U.translate(this.fillPatternX(),this.fillPatternY()),U.rotate(e.Konva.getAngle(this.fillPatternRotation())),U.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),U.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const B=U.getMatrix(),z=typeof DOMMatrix>"u"?{a:B[0],b:B[1],c:B[2],d:B[3],e:B[4],f:B[5]}:new DOMMatrix(B);x.setTransform(z)}return x}}_getLinearGradient(){return this._getCache(v,this.__getLinearGradient)}__getLinearGradient(){const I=this.fillLinearGradientColorStops();if(I){const x=S(),U=this.fillLinearGradientStartPoint(),B=this.fillLinearGradientEndPoint(),z=x.createLinearGradient(U.x,U.y,B.x,B.y);for(let L=0;L<I.length;L+=2)z.addColorStop(I[L],I[L+1]);return z}}_getRadialGradient(){return this._getCache(T,this.__getRadialGradient)}__getRadialGradient(){const I=this.fillRadialGradientColorStops();if(I){const x=S(),U=this.fillRadialGradientStartPoint(),B=this.fillRadialGradientEndPoint(),z=x.createRadialGradient(U.x,U.y,this.fillRadialGradientStartRadius(),B.x,B.y,this.fillRadialGradientEndRadius());for(let L=0;L<I.length;L+=2)z.addColorStop(I[L],I[L+1]);return z}}getShadowRGBA(){return this._getCache(d,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const I=t.Util.colorToRGBA(this.shadowColor());if(I)return"rgba("+I.r+","+I.g+","+I.b+","+I.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){const I=this.hitStrokeWidth();return I==="auto"?this.hasStroke():this.strokeEnabled()&&!!I}intersects(I){const x=this.getStage();if(!x)return!1;const U=x.bufferHitCanvas;return U.getContext().clear(),this.drawHit(U,void 0,!0),U.context.getImageData(Math.round(I.x),Math.round(I.y),1,1).data[3]>0}destroy(){return l.Node.prototype.destroy.call(this),delete u.shapes[this.colorKey],delete this.colorKey,this}_useBufferCanvas(I){var x;if(!((x=this.attrs.perfectDrawEnabled)!==null&&x!==void 0?x:!0))return!1;const B=I||this.hasFill(),z=this.hasStroke(),L=this.getAbsoluteOpacity()!==1;if(B&&z&&L)return!0;const V=this.hasShadow(),J=this.shadowForStrokeEnabled();return!!(B&&z&&V&&J)}setStrokeHitEnabled(I){t.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),I?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){const I=this.size();return{x:this._centroid?-I.width/2:0,y:this._centroid?-I.height/2:0,width:I.width,height:I.height}}getClientRect(I={}){let x=!1,U=this.getParent();for(;U;){if(U.isCached()){x=!0;break}U=U.getParent()}const B=I.skipTransform,z=I.relativeTo||x&&this.getStage()||void 0,L=this.getSelfRect(),J=!I.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,Pe=L.width+J,ee=L.height+J,j=!I.skipShadow&&this.hasShadow(),K=j?this.shadowOffsetX():0,ie=j?this.shadowOffsetY():0,ue=Pe+Math.abs(K),Ce=ee+Math.abs(ie),ke=j&&this.shadowBlur()||0,be=ue+ke*2,M=Ce+ke*2,Y={width:be,height:M,x:-(J/2+ke)+Math.min(K,0)+L.x,y:-(J/2+ke)+Math.min(ie,0)+L.y};return B?Y:this._transformedRect(Y,z)}drawScene(I,x,U){const B=this.getLayer();let z=I||B.getCanvas(),L=z.getContext(),V=this._getCanvasCache(),J=this.getSceneFunc(),Pe=this.hasShadow(),ee,j;const K=z.isCache,ie=x===this;if(!this.isVisible()&&!ie)return this;if(V){L.save();const Ce=this.getAbsoluteTransform(x).getMatrix();return L.transform(Ce[0],Ce[1],Ce[2],Ce[3],Ce[4],Ce[5]),this._drawCachedSceneCanvas(L),L.restore(),this}if(!J)return this;if(L.save(),this._useBufferCanvas()&&!K){ee=this.getStage();const Ce=U||ee.bufferCanvas;j=Ce.getContext(),j.clear(),j.save(),j._applyLineJoin(this);var ue=this.getAbsoluteTransform(x).getMatrix();j.transform(ue[0],ue[1],ue[2],ue[3],ue[4],ue[5]),J.call(this,j,this),j.restore();const ke=Ce.pixelRatio;Pe&&L._applyShadow(this),L._applyOpacity(this),L._applyGlobalCompositeOperation(this),L.drawImage(Ce._canvas,0,0,Ce.width/ke,Ce.height/ke)}else{if(L._applyLineJoin(this),!ie){var ue=this.getAbsoluteTransform(x).getMatrix();L.transform(ue[0],ue[1],ue[2],ue[3],ue[4],ue[5]),L._applyOpacity(this),L._applyGlobalCompositeOperation(this)}Pe&&L._applyShadow(this),J.call(this,L,this)}return L.restore(),this}drawHit(I,x,U=!1){if(!this.shouldDrawHit(x,U))return this;const B=this.getLayer(),z=I||B.hitCanvas,L=z&&z.getContext(),V=this.hitFunc()||this.sceneFunc(),J=this._getCanvasCache(),Pe=J&&J.hit;if(this.colorKey||t.Util.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),Pe){L.save();const j=this.getAbsoluteTransform(x).getMatrix();return L.transform(j[0],j[1],j[2],j[3],j[4],j[5]),this._drawCachedHitCanvas(L),L.restore(),this}if(!V)return this;if(L.save(),L._applyLineJoin(this),!(this===x)){const j=this.getAbsoluteTransform(x).getMatrix();L.transform(j[0],j[1],j[2],j[3],j[4],j[5])}return V.call(this,L,this),L.restore(),this}drawHitFromCache(I=0){let x=this._getCanvasCache(),U=this._getCachedSceneCanvas(),B=x.hit,z=B.getContext(),L=B.getWidth(),V=B.getHeight(),J,Pe,ee,j,K,ie;z.clear(),z.drawImage(U._canvas,0,0,L,V);try{for(J=z.getImageData(0,0,L,V),Pe=J.data,ee=Pe.length,j=t.Util._hexToRgb(this.colorKey),K=0;K<ee;K+=4)ie=Pe[K+3],ie>I?(Pe[K]=j.r,Pe[K+1]=j.g,Pe[K+2]=j.b,Pe[K+3]=255):Pe[K+3]=0;z.putImageData(J,0,0)}catch(ue){t.Util.error("Unable to draw hit graph from cached scene canvas. "+ue.message)}return this}hasPointerCapture(I){return f.hasPointerCapture(I,this)}setPointerCapture(I){f.setPointerCapture(I,this)}releaseCapture(I){f.releaseCapture(I,this)}}u.Shape=D,D.prototype._fillFunc=A,D.prototype._strokeFunc=R,D.prototype._fillFuncHit=O,D.prototype._strokeFuncHit=N,D.prototype._centroid=!1,D.prototype.nodeType="Shape",(0,i._registerNode)(D),D.prototype.eventListeners={},D.prototype.on.call(D.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",C),D.prototype.on.call(D.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",b),D.prototype.on.call(D.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",w),D.prototype.on.call(D.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",F),D.prototype.on.call(D.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",q),r.Factory.addGetterSetter(D,"stroke",void 0,(0,s.getStringOrGradientValidator)()),r.Factory.addGetterSetter(D,"strokeWidth",2,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillAfterStrokeEnabled",!1),r.Factory.addGetterSetter(D,"hitStrokeWidth","auto",(0,s.getNumberOrAutoValidator)()),r.Factory.addGetterSetter(D,"strokeHitEnabled",!0,(0,s.getBooleanValidator)()),r.Factory.addGetterSetter(D,"perfectDrawEnabled",!0,(0,s.getBooleanValidator)()),r.Factory.addGetterSetter(D,"shadowForStrokeEnabled",!0,(0,s.getBooleanValidator)()),r.Factory.addGetterSetter(D,"lineJoin"),r.Factory.addGetterSetter(D,"lineCap"),r.Factory.addGetterSetter(D,"sceneFunc"),r.Factory.addGetterSetter(D,"hitFunc"),r.Factory.addGetterSetter(D,"dash"),r.Factory.addGetterSetter(D,"dashOffset",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"shadowColor",void 0,(0,s.getStringValidator)()),r.Factory.addGetterSetter(D,"shadowBlur",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"shadowOpacity",1,(0,s.getNumberValidator)()),r.Factory.addComponentsGetterSetter(D,"shadowOffset",["x","y"]),r.Factory.addGetterSetter(D,"shadowOffsetX",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"shadowOffsetY",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillPatternImage"),r.Factory.addGetterSetter(D,"fill",void 0,(0,s.getStringOrGradientValidator)()),r.Factory.addGetterSetter(D,"fillPatternX",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillPatternY",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillLinearGradientColorStops"),r.Factory.addGetterSetter(D,"strokeLinearGradientColorStops"),r.Factory.addGetterSetter(D,"fillRadialGradientStartRadius",0),r.Factory.addGetterSetter(D,"fillRadialGradientEndRadius",0),r.Factory.addGetterSetter(D,"fillRadialGradientColorStops"),r.Factory.addGetterSetter(D,"fillPatternRepeat","repeat"),r.Factory.addGetterSetter(D,"fillEnabled",!0),r.Factory.addGetterSetter(D,"strokeEnabled",!0),r.Factory.addGetterSetter(D,"shadowEnabled",!0),r.Factory.addGetterSetter(D,"dashEnabled",!0),r.Factory.addGetterSetter(D,"strokeScaleEnabled",!0),r.Factory.addGetterSetter(D,"fillPriority","color"),r.Factory.addComponentsGetterSetter(D,"fillPatternOffset",["x","y"]),r.Factory.addGetterSetter(D,"fillPatternOffsetX",0,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillPatternOffsetY",0,(0,s.getNumberValidator)()),r.Factory.addComponentsGetterSetter(D,"fillPatternScale",["x","y"]),r.Factory.addGetterSetter(D,"fillPatternScaleX",1,(0,s.getNumberValidator)()),r.Factory.addGetterSetter(D,"fillPatternScaleY",1,(0,s.getNumberValidator)()),r.Factory.addComponentsGetterSetter(D,"fillLinearGradientStartPoint",["x","y"]),r.Factory.addComponentsGetterSetter(D,"strokeLinearGradientStartPoint",["x","y"]),r.Factory.addGetterSetter(D,"fillLinearGradientStartPointX",0),r.Factory.addGetterSetter(D,"strokeLinearGradientStartPointX",0),r.Factory.addGetterSetter(D,"fillLinearGradientStartPointY",0),r.Factory.addGetterSetter(D,"strokeLinearGradientStartPointY",0),r.Factory.addComponentsGetterSetter(D,"fillLinearGradientEndPoint",["x","y"]),r.Factory.addComponentsGetterSetter(D,"strokeLinearGradientEndPoint",["x","y"]),r.Factory.addGetterSetter(D,"fillLinearGradientEndPointX",0),r.Factory.addGetterSetter(D,"strokeLinearGradientEndPointX",0),r.Factory.addGetterSetter(D,"fillLinearGradientEndPointY",0),r.Factory.addGetterSetter(D,"strokeLinearGradientEndPointY",0),r.Factory.addComponentsGetterSetter(D,"fillRadialGradientStartPoint",["x","y"]),r.Factory.addGetterSetter(D,"fillRadialGradientStartPointX",0),r.Factory.addGetterSetter(D,"fillRadialGradientStartPointY",0),r.Factory.addComponentsGetterSetter(D,"fillRadialGradientEndPoint",["x","y"]),r.Factory.addGetterSetter(D,"fillRadialGradientEndPointX",0),r.Factory.addGetterSetter(D,"fillRadialGradientEndPointY",0),r.Factory.addGetterSetter(D,"fillPatternRotation",0),r.Factory.addGetterSetter(D,"fillRule",void 0,(0,s.getStringValidator)()),r.Factory.backCompat(D,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"})})(bt);Object.defineProperty(xa,"__esModule",{value:!0});xa.Layer=void 0;const Vs=ct,Dh=pi,ar=it,Vf=Fe,Q_=Ts,u2=Ne,c2=bt,h2=Le,f2="#",d2="beforeDraw",_2="draw",Op=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],g2=Op.length;class Ar extends Dh.Container{constructor(e){super(e),this.canvas=new Q_.SceneCanvas,this.hitCanvas=new Q_.HitCanvas({pixelRatio:1}),this._waitingForDraw=!1,this.on("visibleChange.konva",this._checkVisibility),this._checkVisibility(),this.on("imageSmoothingEnabledChange.konva",this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(e){return this.getContext().clear(e),this.getHitCanvas().getContext().clear(e),this}setZIndex(e){super.setZIndex(e);const t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),e<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[e+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement())),this}moveToTop(){ar.Node.prototype.moveToTop.call(this);const e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!ar.Node.prototype.moveUp.call(this))return!1;const t=this.getStage();return!t||!t.content?!1:(t.content.removeChild(this.getNativeCanvasElement()),this.index<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[this.index+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(ar.Node.prototype.moveDown.call(this)){const e=this.getStage();if(e){const t=e.children;e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.insertBefore(this.getNativeCanvasElement(),t[this.index+1].getCanvas()._canvas))}return!0}return!1}moveToBottom(){if(ar.Node.prototype.moveToBottom.call(this)){const e=this.getStage();if(e){const t=e.children;e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.insertBefore(this.getNativeCanvasElement(),t[1].getCanvas()._canvas))}return!0}return!1}getLayer(){return this}remove(){const e=this.getNativeCanvasElement();return ar.Node.prototype.remove.call(this),e&&e.parentNode&&Vs.Util._isInDocument(e)&&e.parentNode.removeChild(e),this}getStage(){return this.parent}setSize({width:e,height:t}){return this.canvas.setSize(e,t),this.hitCanvas.setSize(e,t),this._setSmoothEnabled(),this}_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&Vs.Util.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(e){return e=e||{},e.width=e.width||this.getWidth(),e.height=e.height||this.getHeight(),e.x=e.x!==void 0?e.x:this.x(),e.y=e.y!==void 0?e.y:this.y(),ar.Node.prototype._toKonvaCanvas.call(this,e)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){Vs.Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){Vs.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,Vs.Util.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(e){if(!this.isListening()||!this.isVisible())return null;let t=1,r=!1;for(;;){for(let l=0;l<g2;l++){const s=Op[l],i=this._getIntersection({x:e.x+s.x*t,y:e.y+s.y*t}),f=i.shape;if(f)return f;if(r=!!i.antialiased,!i.antialiased)break}if(r)t+=1;else return null}}_getIntersection(e){const t=this.hitCanvas.pixelRatio,r=this.hitCanvas.context.getImageData(Math.round(e.x*t),Math.round(e.y*t),1,1).data,l=r[3];if(l===255){const s=Vs.Util._rgbToHex(r[0],r[1],r[2]),i=c2.shapes[f2+s];return i?{shape:i}:{antialiased:!0}}else if(l>0)return{antialiased:!0};return{}}drawScene(e,t){const r=this.getLayer(),l=e||r&&r.getCanvas();return this._fire(d2,{node:this}),this.clearBeforeDraw()&&l.getContext().clear(),Dh.Container.prototype.drawScene.call(this,l,t),this._fire(_2,{node:this}),this}drawHit(e,t){const r=this.getLayer(),l=e||r&&r.hitCanvas;return r&&r.clearBeforeDraw()&&r.getHitCanvas().getContext().clear(),Dh.Container.prototype.drawHit.call(this,l,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){Vs.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(e)}getHitGraphEnabled(e){return Vs.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;const e=this.parent;!!this.hitCanvas._canvas.parentNode?e.content.removeChild(this.hitCanvas._canvas):e.content.appendChild(this.hitCanvas._canvas)}destroy(){return Vs.Util.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}xa.Layer=Ar;Ar.prototype.nodeType="Layer";(0,h2._registerNode)(Ar);Vf.Factory.addGetterSetter(Ar,"imageSmoothingEnabled",!0);Vf.Factory.addGetterSetter(Ar,"clearBeforeDraw",!0);Vf.Factory.addGetterSetter(Ar,"hitGraphEnabled",!0,(0,u2.getBooleanValidator)());var Pu={};Object.defineProperty(Pu,"__esModule",{value:!0});Pu.FastLayer=void 0;const p2=ct,m2=xa,v2=Le;class Bf extends m2.Layer{constructor(e){super(e),this.listening(!1),p2.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Pu.FastLayer=Bf;Bf.prototype.nodeType="FastLayer";(0,v2._registerNode)(Bf);var br={};Object.defineProperty(br,"__esModule",{value:!0});br.Group=void 0;const T2=ct,y2=pi,S2=Le;class jf extends y2.Container{_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&T2.Util.throw("You may only add groups and shapes to groups.")}}br.Group=jf;jf.prototype.nodeType="Group";(0,S2._registerNode)(jf);var Rr={};Object.defineProperty(Rr,"__esModule",{value:!0});Rr.Animation=void 0;const Nh=Le,Z_=ct,Ph=function(){return Nh.glob.performance&&Nh.glob.performance.now?function(){return Nh.glob.performance.now()}:function(){return new Date().getTime()}}();class Is{constructor(e,t){this.id=Is.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:Ph(),frameRate:0},this.func=e,this.setLayers(t)}setLayers(e){let t=[];return e&&(t=Array.isArray(e)?e:[e]),this.layers=t,this}getLayers(){return this.layers}addLayer(e){const t=this.layers,r=t.length;for(let l=0;l<r;l++)if(t[l]._id===e._id)return!1;return this.layers.push(e),!0}isRunning(){const t=Is.animations,r=t.length;for(let l=0;l<r;l++)if(t[l].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=Ph(),Is._addAnimation(this),this}stop(){return Is._removeAnimation(this),this}_updateFrameObject(e){this.frame.timeDiff=e-this.frame.lastTime,this.frame.lastTime=e,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(e){this.animations.push(e),this._handleAnimation()}static _removeAnimation(e){const t=e.id,r=this.animations,l=r.length;for(let s=0;s<l;s++)if(r[s].id===t){this.animations.splice(s,1);break}}static _runFrames(){const e={},t=this.animations;for(let r=0;r<t.length;r++){const l=t[r],s=l.layers,i=l.func;l._updateFrameObject(Ph());const f=s.length;let h;if(i?h=i.call(l,l.frame)!==!1:h=!0,!!h)for(let d=0;d<f;d++){const p=s[d];p._id!==void 0&&(e[p._id]=p)}}for(const r in e)e.hasOwnProperty(r)&&e[r].batchDraw()}static _animationLoop(){const e=Is;e.animations.length?(e._runFrames(),Z_.Util.requestAnimFrame(e._animationLoop)):e.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Z_.Util.requestAnimFrame(this._animationLoop))}}Rr.Animation=Is;Is.animations=[];Is.animIdCounter=0;Is.animRunning=!1;var Dp={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Easings=u.Tween=void 0;const e=ct,t=Rr,r=it,l=Le;let s={node:1,duration:1,easing:1,onFinish:1,yoyo:1},i=1,f=2,h=3,d=0,p=["fill","stroke","shadowColor"];class v{constructor(S,A,R,O,N,C,b){this.prop=S,this.propFunc=A,this.begin=O,this._pos=O,this.duration=C,this._change=0,this.prevPos=0,this.yoyo=b,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=R,this._change=N-this.begin,this.pause()}fire(S){const A=this[S];A&&A()}setTime(S){S>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():S<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=S,this.update())}getTime(){return this._time}setPosition(S){this.prevPos=this._pos,this.propFunc(S),this._pos=S}getPosition(S){return S===void 0&&(S=this._time),this.func(S,this.begin,this._change,this.duration)}play(){this.state=f,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=h,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(S){this.pause(),this._time=S,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const S=this.getTimer()-this._startTime;this.state===f?this.setTime(S):this.state===h&&this.setTime(this.duration-S)}pause(){this.state=i,this.fire("onPause")}getTimer(){return new Date().getTime()}}class T{constructor(S){let A=this,R=S.node,O=R._id,N,C=S.easing||u.Easings.Linear,b=!!S.yoyo,w;typeof S.duration>"u"?N=.3:S.duration===0?N=.001:N=S.duration,this.node=R,this._id=d++;const F=R.getLayer()||(R instanceof l.Konva.Stage?R.getLayers():null);F||e.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new t.Animation(function(){A.tween.onEnterFrame()},F),this.tween=new v(w,function(q){A._tweenFunc(q)},C,0,1,N*1e3,b),this._addListeners(),T.attrs[O]||(T.attrs[O]={}),T.attrs[O][this._id]||(T.attrs[O][this._id]={}),T.tweens[O]||(T.tweens[O]={});for(w in S)s[w]===void 0&&this._addAttr(w,S[w]);this.reset(),this.onFinish=S.onFinish,this.onReset=S.onReset,this.onUpdate=S.onUpdate}_addAttr(S,A){let R=this.node,O=R._id,N,C,b,w,F,q,D,P;if(b=T.tweens[O][S],b&&delete T.attrs[O][b][S],N=R.getAttr(S),e.Util._isArray(A))if(C=[],F=Math.max(A.length,N.length),S==="points"&&A.length!==N.length&&(A.length>N.length?(D=N,N=e.Util._prepareArrayForTween(N,A,R.closed())):(q=A,A=e.Util._prepareArrayForTween(A,N,R.closed()))),S.indexOf("fill")===0)for(w=0;w<F;w++)if(w%2===0)C.push(A[w]-N[w]);else{const I=e.Util.colorToRGBA(N[w]);P=e.Util.colorToRGBA(A[w]),N[w]=I,C.push({r:P.r-I.r,g:P.g-I.g,b:P.b-I.b,a:P.a-I.a})}else for(w=0;w<F;w++)C.push(A[w]-N[w]);else p.indexOf(S)!==-1?(N=e.Util.colorToRGBA(N),P=e.Util.colorToRGBA(A),C={r:P.r-N.r,g:P.g-N.g,b:P.b-N.b,a:P.a-N.a}):C=A-N;T.attrs[O][this._id][S]={start:N,diff:C,end:A,trueEnd:q,trueStart:D},T.tweens[O][S]=this._id}_tweenFunc(S){let A=this.node,R=T.attrs[A._id][this._id],O,N,C,b,w,F,q,D;for(O in R){if(N=R[O],C=N.start,b=N.diff,D=N.end,e.Util._isArray(C))if(w=[],q=Math.max(C.length,D.length),O.indexOf("fill")===0)for(F=0;F<q;F++)F%2===0?w.push((C[F]||0)+b[F]*S):w.push("rgba("+Math.round(C[F].r+b[F].r*S)+","+Math.round(C[F].g+b[F].g*S)+","+Math.round(C[F].b+b[F].b*S)+","+(C[F].a+b[F].a*S)+")");else for(F=0;F<q;F++)w.push((C[F]||0)+b[F]*S);else p.indexOf(O)!==-1?w="rgba("+Math.round(C.r+b.r*S)+","+Math.round(C.g+b.g*S)+","+Math.round(C.b+b.b*S)+","+(C.a+b.a*S)+")":w=C+b*S;A.setAttr(O,w)}}_addListeners(){this.tween.onPlay=()=>{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{const S=this.node,A=T.attrs[S._id][this._id];A.points&&A.points.trueEnd&&S.setAttr("points",A.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{const S=this.node,A=T.attrs[S._id][this._id];A.points&&A.points.trueStart&&S.points(A.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(S){return this.tween.seek(S*1e3),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){let S=this.node._id,A=this._id,R=T.tweens[S],O;this.pause();for(O in R)delete T.tweens[S][O];delete T.attrs[S][A]}}u.Tween=T,T.attrs={},T.tweens={},r.Node.prototype.to=function(y){const S=y.onFinish;y.node=this,y.onFinish=function(){this.destroy(),S&&S()},new T(y).play()},u.Easings={BackEaseIn(y,S,A,R){return A*(y/=R)*y*((1.70158+1)*y-1.70158)+S},BackEaseOut(y,S,A,R){return A*((y=y/R-1)*y*((1.70158+1)*y+1.70158)+1)+S},BackEaseInOut(y,S,A,R){let O=1.70158;return(y/=R/2)<1?A/2*(y*y*(((O*=1.525)+1)*y-O))+S:A/2*((y-=2)*y*(((O*=1.525)+1)*y+O)+2)+S},ElasticEaseIn(y,S,A,R,O,N){let C=0;return y===0?S:(y/=R)===1?S+A:(N||(N=R*.3),!O||O<Math.abs(A)?(O=A,C=N/4):C=N/(2*Math.PI)*Math.asin(A/O),-(O*Math.pow(2,10*(y-=1))*Math.sin((y*R-C)*(2*Math.PI)/N))+S)},ElasticEaseOut(y,S,A,R,O,N){let C=0;return y===0?S:(y/=R)===1?S+A:(N||(N=R*.3),!O||O<Math.abs(A)?(O=A,C=N/4):C=N/(2*Math.PI)*Math.asin(A/O),O*Math.pow(2,-10*y)*Math.sin((y*R-C)*(2*Math.PI)/N)+A+S)},ElasticEaseInOut(y,S,A,R,O,N){let C=0;return y===0?S:(y/=R/2)===2?S+A:(N||(N=R*(.3*1.5)),!O||O<Math.abs(A)?(O=A,C=N/4):C=N/(2*Math.PI)*Math.asin(A/O),y<1?-.5*(O*Math.pow(2,10*(y-=1))*Math.sin((y*R-C)*(2*Math.PI)/N))+S:O*Math.pow(2,-10*(y-=1))*Math.sin((y*R-C)*(2*Math.PI)/N)*.5+A+S)},BounceEaseOut(y,S,A,R){return(y/=R)<1/2.75?A*(7.5625*y*y)+S:y<2/2.75?A*(7.5625*(y-=1.5/2.75)*y+.75)+S:y<2.5/2.75?A*(7.5625*(y-=2.25/2.75)*y+.9375)+S:A*(7.5625*(y-=2.625/2.75)*y+.984375)+S},BounceEaseIn(y,S,A,R){return A-u.Easings.BounceEaseOut(R-y,0,A,R)+S},BounceEaseInOut(y,S,A,R){return y<R/2?u.Easings.BounceEaseIn(y*2,0,A,R)*.5+S:u.Easings.BounceEaseOut(y*2-R,0,A,R)*.5+A*.5+S},EaseIn(y,S,A,R){return A*(y/=R)*y+S},EaseOut(y,S,A,R){return-A*(y/=R)*(y-2)+S},EaseInOut(y,S,A,R){return(y/=R/2)<1?A/2*y*y+S:-A/2*(--y*(y-2)-1)+S},StrongEaseIn(y,S,A,R){return A*(y/=R)*y*y*y*y+S},StrongEaseOut(y,S,A,R){return A*((y=y/R-1)*y*y*y*y+1)+S},StrongEaseInOut(y,S,A,R){return(y/=R/2)<1?A/2*y*y*y*y*y+S:A/2*((y-=2)*y*y*y*y+2)+S},Linear(y,S,A,R){return A*y/R+S}}})(Dp);(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Konva=void 0;const e=Le,t=ct,r=it,l=pi,s=Rp,i=xa,f=Pu,h=br,d=Du,p=bt,v=Rr,T=Dp,y=Ws,S=Ts;u.Konva=t.Util._assign(e.Konva,{Util:t.Util,Transform:t.Transform,Node:r.Node,Container:l.Container,Stage:s.Stage,stages:s.stages,Layer:i.Layer,FastLayer:f.FastLayer,Group:h.Group,DD:d.DD,Shape:p.Shape,shapes:p.shapes,Animation:v.Animation,Tween:T.Tween,Easings:T.Easings,Context:y.Context,Canvas:S.Canvas}),u.default=u.Konva})(Ep);var xu={};Object.defineProperty(xu,"__esModule",{value:!0});xu.Arc=void 0;const ku=Fe,E2=bt,eg=Le,Mu=Ne,C2=Le;class en extends E2.Shape{_sceneFunc(e){const t=eg.Konva.getAngle(this.angle()),r=this.clockwise();e.beginPath(),e.arc(0,0,this.outerRadius(),0,t,r),e.arc(0,0,this.innerRadius(),t,0,!r),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}getSelfRect(){const e=this.innerRadius(),t=this.outerRadius(),r=this.clockwise(),l=eg.Konva.getAngle(r?360-this.angle():this.angle()),s=Math.cos(Math.min(l,Math.PI)),i=1,f=Math.sin(Math.min(Math.max(Math.PI,l),3*Math.PI/2)),h=Math.sin(Math.min(l,Math.PI/2)),d=s*(s>0?e:t),p=i*t,v=f*(f>0?e:t),T=h*(h>0?t:e);return{x:d,y:r?-1*T:v,width:p-d,height:T-v}}}xu.Arc=en;en.prototype._centroid=!0;en.prototype.className="Arc";en.prototype._attrsAffectingSize=["innerRadius","outerRadius"];(0,C2._registerNode)(en);ku.Factory.addGetterSetter(en,"innerRadius",0,(0,Mu.getNumberValidator)());ku.Factory.addGetterSetter(en,"outerRadius",0,(0,Mu.getNumberValidator)());ku.Factory.addGetterSetter(en,"angle",0,(0,Mu.getNumberValidator)());ku.Factory.addGetterSetter(en,"clockwise",!1,(0,Mu.getBooleanValidator)());var Uu={},ka={};Object.defineProperty(ka,"__esModule",{value:!0});ka.Line=void 0;const Lu=Fe,A2=Le,b2=bt,Np=Ne;function _f(u,e,t,r,l,s,i){const f=Math.sqrt(Math.pow(t-u,2)+Math.pow(r-e,2)),h=Math.sqrt(Math.pow(l-t,2)+Math.pow(s-r,2)),d=i*f/(f+h),p=i*h/(f+h),v=t-d*(l-u),T=r-d*(s-e),y=t+p*(l-u),S=r+p*(s-e);return[v,T,y,S]}function tg(u,e){const t=u.length,r=[];for(let l=2;l<t-2;l+=2){const s=_f(u[l-2],u[l-1],u[l],u[l+1],u[l+2],u[l+3],e);isNaN(s[0])||(r.push(s[0]),r.push(s[1]),r.push(u[l]),r.push(u[l+1]),r.push(s[2]),r.push(s[3]))}return r}class Nn extends b2.Shape{constructor(e){super(e),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(e){let t=this.points(),r=t.length,l=this.tension(),s=this.closed(),i=this.bezier(),f,h,d;if(r){if(e.beginPath(),e.moveTo(t[0],t[1]),l!==0&&r>4){for(f=this.getTensionPoints(),h=f.length,d=s?0:4,s||e.quadraticCurveTo(f[0],f[1],f[2],f[3]);d<h-2;)e.bezierCurveTo(f[d++],f[d++],f[d++],f[d++],f[d++],f[d++]);s||e.quadraticCurveTo(f[h-2],f[h-1],t[r-2],t[r-1])}else if(i)for(d=2;d<r;)e.bezierCurveTo(t[d++],t[d++],t[d++],t[d++],t[d++],t[d++]);else for(d=2;d<r;d+=2)e.lineTo(t[d],t[d+1]);s?(e.closePath(),e.fillStrokeShape(this)):e.strokeShape(this)}}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():tg(this.points(),this.tension())}_getTensionPointsClosed(){const e=this.points(),t=e.length,r=this.tension(),l=_f(e[t-2],e[t-1],e[0],e[1],e[2],e[3],r),s=_f(e[t-4],e[t-3],e[t-2],e[t-1],e[0],e[1],r),i=tg(e,r);return[l[2],l[3]].concat(i).concat([s[0],s[1],e[t-2],e[t-1],s[2],s[3],l[0],l[1],e[0],e[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let e=this.points();if(e.length<4)return{x:e[0]||0,y:e[1]||0,width:0,height:0};this.tension()!==0?e=[e[0],e[1],...this._getTensionPoints(),e[e.length-2],e[e.length-1]]:e=this.points();let t=e[0],r=e[0],l=e[1],s=e[1],i,f;for(let h=0;h<e.length/2;h++)i=e[h*2],f=e[h*2+1],t=Math.min(t,i),r=Math.max(r,i),l=Math.min(l,f),s=Math.max(s,f);return{x:t,y:l,width:r-t,height:s-l}}}ka.Line=Nn;Nn.prototype.className="Line";Nn.prototype._attrsAffectingSize=["points","bezier","tension"];(0,A2._registerNode)(Nn);Lu.Factory.addGetterSetter(Nn,"closed",!1);Lu.Factory.addGetterSetter(Nn,"bezier",!1);Lu.Factory.addGetterSetter(Nn,"tension",0,(0,Np.getNumberValidator)());Lu.Factory.addGetterSetter(Nn,"points",[],(0,Np.getNumberArrayValidator)());var wr={},Pp={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.t2length=u.getQuadraticArcLength=u.getCubicArcLength=u.binomialCoefficients=u.cValues=u.tValues=void 0,u.tValues=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],u.cValues=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],u.binomialCoefficients=[[1],[1,1],[1,2,1],[1,3,3,1]];const e=(i,f,h)=>{let d,p;const T=h/2;d=0;for(let y=0;y<20;y++)p=T*u.tValues[20][y]+T,d+=u.cValues[20][y]*r(i,f,p);return T*d};u.getCubicArcLength=e;const t=(i,f,h)=>{h===void 0&&(h=1);const d=i[0]-2*i[1]+i[2],p=f[0]-2*f[1]+f[2],v=2*i[1]-2*i[0],T=2*f[1]-2*f[0],y=4*(d*d+p*p),S=4*(d*v+p*T),A=v*v+T*T;if(y===0)return h*Math.sqrt(Math.pow(i[2]-i[0],2)+Math.pow(f[2]-f[0],2));const R=S/(2*y),O=A/y,N=h+R,C=O-R*R,b=N*N+C>0?Math.sqrt(N*N+C):0,w=R*R+C>0?Math.sqrt(R*R+C):0,F=R+Math.sqrt(R*R+C)!==0?C*Math.log(Math.abs((N+b)/(R+w))):0;return Math.sqrt(y)/2*(N*b-R*w+F)};u.getQuadraticArcLength=t;function r(i,f,h){const d=l(1,h,i),p=l(1,h,f),v=d*d+p*p;return Math.sqrt(v)}const l=(i,f,h)=>{const d=h.length-1;let p,v;if(d===0)return 0;if(i===0){v=0;for(let T=0;T<=d;T++)v+=u.binomialCoefficients[d][T]*Math.pow(1-f,d-T)*Math.pow(f,T)*h[T];return v}else{p=new Array(d);for(let T=0;T<d;T++)p[T]=d*(h[T+1]-h[T]);return l(i-1,f,p)}},s=(i,f,h)=>{let d=1,p=i/f,v=(i-h(p))/f,T=0;for(;d>.001;){const y=h(p+v),S=Math.abs(i-y)/f;if(S<d)d=S,p+=v;else{const A=h(p-v),R=Math.abs(i-A)/f;R<d?(d=R,p-=v):v/=2}if(T++,T>500)break}return p};u.t2length=s})(Pp);Object.defineProperty(wr,"__esModule",{value:!0});wr.Path=void 0;const R2=Fe,w2=bt,I2=Le,or=Pp;class Ct extends w2.Shape{constructor(e){super(e),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=Ct.parsePathData(this.data()),this.pathLength=Ct.getPathLength(this.dataArray)}_sceneFunc(e){const t=this.dataArray;e.beginPath();let r=!1;for(let A=0;A<t.length;A++){const R=t[A].command,O=t[A].points;switch(R){case"L":e.lineTo(O[0],O[1]);break;case"M":e.moveTo(O[0],O[1]);break;case"C":e.bezierCurveTo(O[0],O[1],O[2],O[3],O[4],O[5]);break;case"Q":e.quadraticCurveTo(O[0],O[1],O[2],O[3]);break;case"A":var l=O[0],s=O[1],i=O[2],f=O[3],h=O[4],d=O[5],p=O[6],v=O[7],T=i>f?i:f,y=i>f?1:i/f,S=i>f?f/i:1;e.translate(l,s),e.rotate(p),e.scale(y,S),e.arc(0,0,T,h,h+d,1-v),e.scale(1/y,1/S),e.rotate(-p),e.translate(-l,-s);break;case"z":r=!0,e.closePath();break}}!r&&!this.hasFill()?e.strokeShape(this):e.fillStrokeShape(this)}getSelfRect(){let e=[];this.dataArray.forEach(function(h){if(h.command==="A"){const d=h.points[4],p=h.points[5],v=h.points[4]+p;let T=Math.PI/180;if(Math.abs(d-v)<T&&(T=Math.abs(d-v)),p<0)for(let y=d-T;y>v;y-=T){const S=Ct.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],y,0);e.push(S.x,S.y)}else for(let y=d+T;y<v;y+=T){const S=Ct.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],y,0);e.push(S.x,S.y)}}else if(h.command==="C")for(let d=0;d<=1;d+=.01){const p=Ct.getPointOnCubicBezier(d,h.start.x,h.start.y,h.points[0],h.points[1],h.points[2],h.points[3],h.points[4],h.points[5]);e.push(p.x,p.y)}else e=e.concat(h.points)});let t=e[0],r=e[0],l=e[1],s=e[1],i,f;for(let h=0;h<e.length/2;h++)i=e[h*2],f=e[h*2+1],isNaN(i)||(t=Math.min(t,i),r=Math.max(r,i)),isNaN(f)||(l=Math.min(l,f),s=Math.max(s,f));return{x:t,y:l,width:r-t,height:s-l}}getLength(){return this.pathLength}getPointAtLength(e){return Ct.getPointAtLengthOfDataArray(e,this.dataArray)}static getLineLength(e,t,r,l){return Math.sqrt((r-e)*(r-e)+(l-t)*(l-t))}static getPathLength(e){let t=0;for(let r=0;r<e.length;++r)t+=e[r].pathLength;return t}static getPointAtLengthOfDataArray(e,t){let r,l=0,s=t.length;if(!s)return null;for(;l<s&&e>t[l].pathLength;)e-=t[l].pathLength,++l;if(l===s)return r=t[l-1].points.slice(-2),{x:r[0],y:r[1]};if(e<.01)return r=t[l].points.slice(0,2),{x:r[0],y:r[1]};const i=t[l],f=i.points;switch(i.command){case"L":return Ct.getPointOnLine(e,i.start.x,i.start.y,f[0],f[1]);case"C":return Ct.getPointOnCubicBezier((0,or.t2length)(e,Ct.getPathLength(t),A=>(0,or.getCubicArcLength)([i.start.x,f[0],f[2],f[4]],[i.start.y,f[1],f[3],f[5]],A)),i.start.x,i.start.y,f[0],f[1],f[2],f[3],f[4],f[5]);case"Q":return Ct.getPointOnQuadraticBezier((0,or.t2length)(e,Ct.getPathLength(t),A=>(0,or.getQuadraticArcLength)([i.start.x,f[0],f[2]],[i.start.y,f[1],f[3]],A)),i.start.x,i.start.y,f[0],f[1],f[2],f[3]);case"A":var h=f[0],d=f[1],p=f[2],v=f[3],T=f[4],y=f[5],S=f[6];return T+=y*e/i.pathLength,Ct.getPointOnEllipticalArc(h,d,p,v,T,S)}return null}static getPointOnLine(e,t,r,l,s,i,f){i=i??t,f=f??r;const h=this.getLineLength(t,r,l,s);if(h<1e-10)return{x:t,y:r};if(l===t)return{x:i,y:f+(s>r?e:-e)};const d=(s-r)/(l-t),p=Math.sqrt(e*e/(1+d*d))*(l<t?-1:1),v=d*p;if(Math.abs(f-r-d*(i-t))<1e-10)return{x:i+p,y:f+v};const T=((i-t)*(l-t)+(f-r)*(s-r))/(h*h),y=t+T*(l-t),S=r+T*(s-r),A=this.getLineLength(i,f,y,S),R=Math.sqrt(e*e-A*A),O=Math.sqrt(R*R/(1+d*d))*(l<t?-1:1),N=d*O;return{x:y+O,y:S+N}}static getPointOnCubicBezier(e,t,r,l,s,i,f,h,d){function p(R){return R*R*R}function v(R){return 3*R*R*(1-R)}function T(R){return 3*R*(1-R)*(1-R)}function y(R){return(1-R)*(1-R)*(1-R)}const S=h*p(e)+i*v(e)+l*T(e)+t*y(e),A=d*p(e)+f*v(e)+s*T(e)+r*y(e);return{x:S,y:A}}static getPointOnQuadraticBezier(e,t,r,l,s,i,f){function h(y){return y*y}function d(y){return 2*y*(1-y)}function p(y){return(1-y)*(1-y)}const v=i*h(e)+l*d(e)+t*p(e),T=f*h(e)+s*d(e)+r*p(e);return{x:v,y:T}}static getPointOnEllipticalArc(e,t,r,l,s,i){const f=Math.cos(i),h=Math.sin(i),d={x:r*Math.cos(s),y:l*Math.sin(s)};return{x:e+(d.x*f-d.y*h),y:t+(d.x*h+d.y*f)}}static parsePathData(e){if(!e)return[];let t=e;const r=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];t=t.replace(new RegExp(" ","g"),",");for(var l=0;l<r.length;l++)t=t.replace(new RegExp(r[l],"g"),"|"+r[l]);const s=t.split("|"),i=[],f=[];let h=0,d=0;const p=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let v;for(l=1;l<s.length;l++){let D=s[l],P=D.charAt(0);for(D=D.slice(1),f.length=0;v=p.exec(D);)f.push(v[0]);const I=[];for(let x=0,U=f.length;x<U;x++){if(f[x]==="00"){I.push(0,0);continue}const B=parseFloat(f[x]);isNaN(B)?I.push(0):I.push(B)}for(;I.length>0&&!isNaN(I[0]);){let x="",U=[];const B=h,z=d;var T,y,S,A,R,O,N,C,b,w;switch(P){case"l":h+=I.shift(),d+=I.shift(),x="L",U.push(h,d);break;case"L":h=I.shift(),d=I.shift(),U.push(h,d);break;case"m":var F=I.shift(),q=I.shift();if(h+=F,d+=q,x="M",i.length>2&&i[i.length-1].command==="z"){for(let L=i.length-2;L>=0;L--)if(i[L].command==="M"){h=i[L].points[0]+F,d=i[L].points[1]+q;break}}U.push(h,d),P="l";break;case"M":h=I.shift(),d=I.shift(),x="M",U.push(h,d),P="L";break;case"h":h+=I.shift(),x="L",U.push(h,d);break;case"H":h=I.shift(),x="L",U.push(h,d);break;case"v":d+=I.shift(),x="L",U.push(h,d);break;case"V":d=I.shift(),x="L",U.push(h,d);break;case"C":U.push(I.shift(),I.shift(),I.shift(),I.shift()),h=I.shift(),d=I.shift(),U.push(h,d);break;case"c":U.push(h+I.shift(),d+I.shift(),h+I.shift(),d+I.shift()),h+=I.shift(),d+=I.shift(),x="C",U.push(h,d);break;case"S":y=h,S=d,T=i[i.length-1],T.command==="C"&&(y=h+(h-T.points[2]),S=d+(d-T.points[3])),U.push(y,S,I.shift(),I.shift()),h=I.shift(),d=I.shift(),x="C",U.push(h,d);break;case"s":y=h,S=d,T=i[i.length-1],T.command==="C"&&(y=h+(h-T.points[2]),S=d+(d-T.points[3])),U.push(y,S,h+I.shift(),d+I.shift()),h+=I.shift(),d+=I.shift(),x="C",U.push(h,d);break;case"Q":U.push(I.shift(),I.shift()),h=I.shift(),d=I.shift(),U.push(h,d);break;case"q":U.push(h+I.shift(),d+I.shift()),h+=I.shift(),d+=I.shift(),x="Q",U.push(h,d);break;case"T":y=h,S=d,T=i[i.length-1],T.command==="Q"&&(y=h+(h-T.points[0]),S=d+(d-T.points[1])),h=I.shift(),d=I.shift(),x="Q",U.push(y,S,h,d);break;case"t":y=h,S=d,T=i[i.length-1],T.command==="Q"&&(y=h+(h-T.points[0]),S=d+(d-T.points[1])),h+=I.shift(),d+=I.shift(),x="Q",U.push(y,S,h,d);break;case"A":A=I.shift(),R=I.shift(),O=I.shift(),N=I.shift(),C=I.shift(),b=h,w=d,h=I.shift(),d=I.shift(),x="A",U=this.convertEndpointToCenterParameterization(b,w,h,d,N,C,A,R,O);break;case"a":A=I.shift(),R=I.shift(),O=I.shift(),N=I.shift(),C=I.shift(),b=h,w=d,h+=I.shift(),d+=I.shift(),x="A",U=this.convertEndpointToCenterParameterization(b,w,h,d,N,C,A,R,O);break}i.push({command:x||P,points:U,start:{x:B,y:z},pathLength:this.calcLength(B,z,x||P,U)})}(P==="z"||P==="Z")&&i.push({command:"z",points:[],start:void 0,pathLength:0})}return i}static calcLength(e,t,r,l){let s,i,f,h;const d=Ct;switch(r){case"L":return d.getLineLength(e,t,l[0],l[1]);case"C":return(0,or.getCubicArcLength)([e,l[0],l[2],l[4]],[t,l[1],l[3],l[5]],1);case"Q":return(0,or.getQuadraticArcLength)([e,l[0],l[2]],[t,l[1],l[3]],1);case"A":s=0;var p=l[4],v=l[5],T=l[4]+v,y=Math.PI/180;if(Math.abs(p-T)<y&&(y=Math.abs(p-T)),i=d.getPointOnEllipticalArc(l[0],l[1],l[2],l[3],p,0),v<0)for(h=p-y;h>T;h-=y)f=d.getPointOnEllipticalArc(l[0],l[1],l[2],l[3],h,0),s+=d.getLineLength(i.x,i.y,f.x,f.y),i=f;else for(h=p+y;h<T;h+=y)f=d.getPointOnEllipticalArc(l[0],l[1],l[2],l[3],h,0),s+=d.getLineLength(i.x,i.y,f.x,f.y),i=f;return f=d.getPointOnEllipticalArc(l[0],l[1],l[2],l[3],T,0),s+=d.getLineLength(i.x,i.y,f.x,f.y),s}return 0}static convertEndpointToCenterParameterization(e,t,r,l,s,i,f,h,d){const p=d*(Math.PI/180),v=Math.cos(p)*(e-r)/2+Math.sin(p)*(t-l)/2,T=-1*Math.sin(p)*(e-r)/2+Math.cos(p)*(t-l)/2,y=v*v/(f*f)+T*T/(h*h);y>1&&(f*=Math.sqrt(y),h*=Math.sqrt(y));let S=Math.sqrt((f*f*(h*h)-f*f*(T*T)-h*h*(v*v))/(f*f*(T*T)+h*h*(v*v)));s===i&&(S*=-1),isNaN(S)&&(S=0);const A=S*f*T/h,R=S*-h*v/f,O=(e+r)/2+Math.cos(p)*A-Math.sin(p)*R,N=(t+l)/2+Math.sin(p)*A+Math.cos(p)*R,C=function(I){return Math.sqrt(I[0]*I[0]+I[1]*I[1])},b=function(I,x){return(I[0]*x[0]+I[1]*x[1])/(C(I)*C(x))},w=function(I,x){return(I[0]*x[1]<I[1]*x[0]?-1:1)*Math.acos(b(I,x))},F=w([1,0],[(v-A)/f,(T-R)/h]),q=[(v-A)/f,(T-R)/h],D=[(-1*v-A)/f,(-1*T-R)/h];let P=w(q,D);return b(q,D)<=-1&&(P=Math.PI),b(q,D)>=1&&(P=0),i===0&&P>0&&(P=P-2*Math.PI),i===1&&P<0&&(P=P+2*Math.PI),[O,N,f,h,F,P,p,i]}}wr.Path=Ct;Ct.prototype.className="Path";Ct.prototype._attrsAffectingSize=["data"];(0,I2._registerNode)(Ct);R2.Factory.addGetterSetter(Ct,"data");Object.defineProperty(Uu,"__esModule",{value:!0});Uu.Arrow=void 0;const Fu=Fe,O2=ka,xp=Ne,D2=Le,sg=wr;class vi extends O2.Line{_sceneFunc(e){super._sceneFunc(e);const t=Math.PI*2,r=this.points();let l=r;const s=this.tension()!==0&&r.length>4;s&&(l=this.getTensionPoints());const i=this.pointerLength(),f=r.length;let h,d;if(s){const T=[l[l.length-4],l[l.length-3],l[l.length-2],l[l.length-1],r[f-2],r[f-1]],y=sg.Path.calcLength(l[l.length-4],l[l.length-3],"C",T),S=sg.Path.getPointOnQuadraticBezier(Math.min(1,1-i/y),T[0],T[1],T[2],T[3],T[4],T[5]);h=r[f-2]-S.x,d=r[f-1]-S.y}else h=r[f-2]-r[f-4],d=r[f-1]-r[f-3];const p=(Math.atan2(d,h)+t)%t,v=this.pointerWidth();this.pointerAtEnding()&&(e.save(),e.beginPath(),e.translate(r[f-2],r[f-1]),e.rotate(p),e.moveTo(0,0),e.lineTo(-i,v/2),e.lineTo(-i,-v/2),e.closePath(),e.restore(),this.__fillStroke(e)),this.pointerAtBeginning()&&(e.save(),e.beginPath(),e.translate(r[0],r[1]),s?(h=(l[0]+l[2])/2-r[0],d=(l[1]+l[3])/2-r[1]):(h=r[2]-r[0],d=r[3]-r[1]),e.rotate((Math.atan2(-d,-h)+t)%t),e.moveTo(0,0),e.lineTo(-i,v/2),e.lineTo(-i,-v/2),e.closePath(),e.restore(),this.__fillStroke(e))}__fillStroke(e){const t=this.dashEnabled();t&&(this.attrs.dashEnabled=!1,e.setLineDash([])),e.fillStrokeShape(this),t&&(this.attrs.dashEnabled=!0)}getSelfRect(){const e=super.getSelfRect(),t=this.pointerWidth()/2;return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}}Uu.Arrow=vi;vi.prototype.className="Arrow";(0,D2._registerNode)(vi);Fu.Factory.addGetterSetter(vi,"pointerLength",10,(0,xp.getNumberValidator)());Fu.Factory.addGetterSetter(vi,"pointerWidth",10,(0,xp.getNumberValidator)());Fu.Factory.addGetterSetter(vi,"pointerAtBeginning",!1);Fu.Factory.addGetterSetter(vi,"pointerAtEnding",!0);var $u={};Object.defineProperty($u,"__esModule",{value:!0});$u.Circle=void 0;const N2=Fe,P2=bt,x2=Ne,k2=Le;class Ir extends P2.Shape{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.attrs.radius||0,0,Math.PI*2,!1),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius()!==e/2&&this.radius(e/2)}setHeight(e){this.radius()!==e/2&&this.radius(e/2)}}$u.Circle=Ir;Ir.prototype._centroid=!0;Ir.prototype.className="Circle";Ir.prototype._attrsAffectingSize=["radius"];(0,k2._registerNode)(Ir);N2.Factory.addGetterSetter(Ir,"radius",0,(0,x2.getNumberValidator)());var Hu={};Object.defineProperty(Hu,"__esModule",{value:!0});Hu.Ellipse=void 0;const qf=Fe,M2=bt,kp=Ne,U2=Le;class Pn extends M2.Shape{_sceneFunc(e){const t=this.radiusX(),r=this.radiusY();e.beginPath(),e.save(),t!==r&&e.scale(1,r/t),e.arc(0,0,t,0,Math.PI*2,!1),e.restore(),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radiusX()*2}getHeight(){return this.radiusY()*2}setWidth(e){this.radiusX(e/2)}setHeight(e){this.radiusY(e/2)}}Hu.Ellipse=Pn;Pn.prototype.className="Ellipse";Pn.prototype._centroid=!0;Pn.prototype._attrsAffectingSize=["radiusX","radiusY"];(0,U2._registerNode)(Pn);qf.Factory.addComponentsGetterSetter(Pn,"radius",["x","y"]);qf.Factory.addGetterSetter(Pn,"radiusX",0,(0,kp.getNumberValidator)());qf.Factory.addGetterSetter(Pn,"radiusY",0,(0,kp.getNumberValidator)());var Gu={};Object.defineProperty(Gu,"__esModule",{value:!0});Gu.Image=void 0;const xh=ct,Ti=Fe,L2=bt,F2=Le,Ma=Ne;let Ps=class Mp extends L2.Shape{constructor(e){super(e),this.on("imageChange.konva",()=>{this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const e=this.image();e&&e.complete||e&&e.readyState===4||e&&e.addEventListener&&e.addEventListener("load",()=>{this._requestDraw()})}_useBufferCanvas(){const e=!!this.cornerRadius(),t=this.hasShadow();return e&&t?!0:super._useBufferCanvas(!0)}_sceneFunc(e){const t=this.getWidth(),r=this.getHeight(),l=this.cornerRadius(),s=this.attrs.image;let i;if(s){const f=this.attrs.cropWidth,h=this.attrs.cropHeight;f&&h?i=[s,this.cropX(),this.cropY(),f,h,0,0,t,r]:i=[s,0,0,t,r]}(this.hasFill()||this.hasStroke()||l)&&(e.beginPath(),l?xh.Util.drawRoundedRectPath(e,t,r,l):e.rect(0,0,t,r),e.closePath(),e.fillStrokeShape(this)),s&&(l&&e.clip(),e.drawImage.apply(e,i))}_hitFunc(e){const t=this.width(),r=this.height(),l=this.cornerRadius();e.beginPath(),l?xh.Util.drawRoundedRectPath(e,t,r,l):e.rect(0,0,t,r),e.closePath(),e.fillStrokeShape(this)}getWidth(){var e,t;return(e=this.attrs.width)!==null&&e!==void 0?e:(t=this.image())===null||t===void 0?void 0:t.width}getHeight(){var e,t;return(e=this.attrs.height)!==null&&e!==void 0?e:(t=this.image())===null||t===void 0?void 0:t.height}static fromURL(e,t,r=null){const l=xh.Util.createImageElement();l.onload=function(){const s=new Mp({image:l});t(s)},l.onerror=r,l.crossOrigin="Anonymous",l.src=e}};Gu.Image=Ps;Ps.prototype.className="Image";(0,F2._registerNode)(Ps);Ti.Factory.addGetterSetter(Ps,"cornerRadius",0,(0,Ma.getNumberOrArrayOfNumbersValidator)(4));Ti.Factory.addGetterSetter(Ps,"image");Ti.Factory.addComponentsGetterSetter(Ps,"crop",["x","y","width","height"]);Ti.Factory.addGetterSetter(Ps,"cropX",0,(0,Ma.getNumberValidator)());Ti.Factory.addGetterSetter(Ps,"cropY",0,(0,Ma.getNumberValidator)());Ti.Factory.addGetterSetter(Ps,"cropWidth",0,(0,Ma.getNumberValidator)());Ti.Factory.addGetterSetter(Ps,"cropHeight",0,(0,Ma.getNumberValidator)());var mr={};Object.defineProperty(mr,"__esModule",{value:!0});mr.Tag=mr.Label=void 0;const Vu=Fe,$2=bt,H2=br,Wf=Ne,Up=Le,Lp=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],G2="Change.konva",V2="none",gf="up",pf="right",mf="down",vf="left",B2=Lp.length;class Kf extends H2.Group{constructor(e){super(e),this.on("add.konva",function(t){this._addListeners(t.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(e){let t=this,r;const l=function(){t._sync()};for(r=0;r<B2;r++)e.on(Lp[r]+G2,l)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let e=this.getText(),t=this.getTag(),r,l,s,i,f,h,d;if(e&&t){switch(r=e.width(),l=e.height(),s=t.pointerDirection(),i=t.pointerWidth(),d=t.pointerHeight(),f=0,h=0,s){case gf:f=r/2,h=-1*d;break;case pf:f=r+i,h=l/2;break;case mf:f=r/2,h=l+d;break;case vf:f=-1*i,h=l/2;break}t.setAttrs({x:-1*f,y:-1*h,width:r,height:l}),e.setAttrs({x:-1*f,y:-1*h})}}}mr.Label=Kf;Kf.prototype.className="Label";(0,Up._registerNode)(Kf);class yi extends $2.Shape{_sceneFunc(e){const t=this.width(),r=this.height(),l=this.pointerDirection(),s=this.pointerWidth(),i=this.pointerHeight(),f=this.cornerRadius();let h=0,d=0,p=0,v=0;typeof f=="number"?h=d=p=v=Math.min(f,t/2,r/2):(h=Math.min(f[0]||0,t/2,r/2),d=Math.min(f[1]||0,t/2,r/2),v=Math.min(f[2]||0,t/2,r/2),p=Math.min(f[3]||0,t/2,r/2)),e.beginPath(),e.moveTo(h,0),l===gf&&(e.lineTo((t-s)/2,0),e.lineTo(t/2,-1*i),e.lineTo((t+s)/2,0)),e.lineTo(t-d,0),e.arc(t-d,d,d,Math.PI*3/2,0,!1),l===pf&&(e.lineTo(t,(r-i)/2),e.lineTo(t+s,r/2),e.lineTo(t,(r+i)/2)),e.lineTo(t,r-v),e.arc(t-v,r-v,v,0,Math.PI/2,!1),l===mf&&(e.lineTo((t+s)/2,r),e.lineTo(t/2,r+i),e.lineTo((t-s)/2,r)),e.lineTo(p,r),e.arc(p,r-p,p,Math.PI/2,Math.PI,!1),l===vf&&(e.lineTo(0,(r+i)/2),e.lineTo(-1*s,r/2),e.lineTo(0,(r-i)/2)),e.lineTo(0,h),e.arc(h,h,h,Math.PI,Math.PI*3/2,!1),e.closePath(),e.fillStrokeShape(this)}getSelfRect(){let e=0,t=0,r=this.pointerWidth(),l=this.pointerHeight(),s=this.pointerDirection(),i=this.width(),f=this.height();return s===gf?(t-=l,f+=l):s===mf?f+=l:s===vf?(e-=r*1.5,i+=r):s===pf&&(i+=r*1.5),{x:e,y:t,width:i,height:f}}}mr.Tag=yi;yi.prototype.className="Tag";(0,Up._registerNode)(yi);Vu.Factory.addGetterSetter(yi,"pointerDirection",V2);Vu.Factory.addGetterSetter(yi,"pointerWidth",0,(0,Wf.getNumberValidator)());Vu.Factory.addGetterSetter(yi,"pointerHeight",0,(0,Wf.getNumberValidator)());Vu.Factory.addGetterSetter(yi,"cornerRadius",0,(0,Wf.getNumberOrArrayOfNumbersValidator)(4));var Ua={};Object.defineProperty(Ua,"__esModule",{value:!0});Ua.Rect=void 0;const j2=Fe,q2=bt,W2=Le,K2=ct,Y2=Ne;class Bu extends q2.Shape{_sceneFunc(e){const t=this.cornerRadius(),r=this.width(),l=this.height();e.beginPath(),t?K2.Util.drawRoundedRectPath(e,r,l,t):e.rect(0,0,r,l),e.closePath(),e.fillStrokeShape(this)}}Ua.Rect=Bu;Bu.prototype.className="Rect";(0,W2._registerNode)(Bu);j2.Factory.addGetterSetter(Bu,"cornerRadius",0,(0,Y2.getNumberOrArrayOfNumbersValidator)(4));var ju={};Object.defineProperty(ju,"__esModule",{value:!0});ju.RegularPolygon=void 0;const Fp=Fe,z2=bt,$p=Ne,X2=Le;class Si extends z2.Shape{_sceneFunc(e){const t=this._getPoints();e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let r=1;r<t.length;r++)e.lineTo(t[r].x,t[r].y);e.closePath(),e.fillStrokeShape(this)}_getPoints(){const e=this.attrs.sides,t=this.attrs.radius||0,r=[];for(let l=0;l<e;l++)r.push({x:t*Math.sin(l*2*Math.PI/e),y:-1*t*Math.cos(l*2*Math.PI/e)});return r}getSelfRect(){const e=this._getPoints();let t=e[0].x,r=e[0].y,l=e[0].x,s=e[0].y;return e.forEach(i=>{t=Math.min(t,i.x),r=Math.max(r,i.x),l=Math.min(l,i.y),s=Math.max(s,i.y)}),{x:t,y:l,width:r-t,height:s-l}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}}ju.RegularPolygon=Si;Si.prototype.className="RegularPolygon";Si.prototype._centroid=!0;Si.prototype._attrsAffectingSize=["radius"];(0,X2._registerNode)(Si);Fp.Factory.addGetterSetter(Si,"radius",0,(0,$p.getNumberValidator)());Fp.Factory.addGetterSetter(Si,"sides",0,(0,$p.getNumberValidator)());var qu={};Object.defineProperty(qu,"__esModule",{value:!0});qu.Ring=void 0;const Hp=Fe,J2=bt,Gp=Ne,Q2=Le,ng=Math.PI*2;class Ei extends J2.Shape{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,ng,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),ng,0,!0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}}qu.Ring=Ei;Ei.prototype.className="Ring";Ei.prototype._centroid=!0;Ei.prototype._attrsAffectingSize=["innerRadius","outerRadius"];(0,Q2._registerNode)(Ei);Hp.Factory.addGetterSetter(Ei,"innerRadius",0,(0,Gp.getNumberValidator)());Hp.Factory.addGetterSetter(Ei,"outerRadius",0,(0,Gp.getNumberValidator)());var Wu={};Object.defineProperty(Wu,"__esModule",{value:!0});Wu.Sprite=void 0;const Ci=Fe,Z2=bt,eE=Rr,Vp=Ne,tE=Le;class xs extends Z2.Shape{constructor(e){super(e),this._updated=!0,this.anim=new eE.Animation(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(e){const t=this.animation(),r=this.frameIndex(),l=r*4,s=this.animations()[t],i=this.frameOffsets(),f=s[l+0],h=s[l+1],d=s[l+2],p=s[l+3],v=this.image();if((this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(0,0,d,p),e.closePath(),e.fillStrokeShape(this)),v)if(i){const T=i[t],y=r*2;e.drawImage(v,f,h,d,p,T[y+0],T[y+1],d,p)}else e.drawImage(v,f,h,d,p,0,0,d,p)}_hitFunc(e){const t=this.animation(),r=this.frameIndex(),l=r*4,s=this.animations()[t],i=this.frameOffsets(),f=s[l+2],h=s[l+3];if(e.beginPath(),i){const d=i[t],p=r*2;e.rect(d[p+0],d[p+1],f,h)}else e.rect(0,0,f,h);e.closePath(),e.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const e=this;this.interval=setInterval(function(){e._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const e=this.getLayer();this.anim.setLayers(e),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const e=this.frameIndex(),t=this.animation(),r=this.animations(),l=r[t],s=l.length/4;e<s-1?this.frameIndex(e+1):this.frameIndex(0)}}Wu.Sprite=xs;xs.prototype.className="Sprite";(0,tE._registerNode)(xs);Ci.Factory.addGetterSetter(xs,"animation");Ci.Factory.addGetterSetter(xs,"animations");Ci.Factory.addGetterSetter(xs,"frameOffsets");Ci.Factory.addGetterSetter(xs,"image");Ci.Factory.addGetterSetter(xs,"frameIndex",0,(0,Vp.getNumberValidator)());Ci.Factory.addGetterSetter(xs,"frameRate",17,(0,Vp.getNumberValidator)());Ci.Factory.backCompat(xs,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});var Ku={};Object.defineProperty(Ku,"__esModule",{value:!0});Ku.Star=void 0;const Yf=Fe,sE=bt,zf=Ne,nE=Le;class xn extends sE.Shape{_sceneFunc(e){const t=this.innerRadius(),r=this.outerRadius(),l=this.numPoints();e.beginPath(),e.moveTo(0,0-r);for(let s=1;s<l*2;s++){const i=s%2===0?r:t,f=i*Math.sin(s*Math.PI/l),h=-1*i*Math.cos(s*Math.PI/l);e.lineTo(f,h)}e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}}Ku.Star=xn;xn.prototype.className="Star";xn.prototype._centroid=!0;xn.prototype._attrsAffectingSize=["innerRadius","outerRadius"];(0,nE._registerNode)(xn);Yf.Factory.addGetterSetter(xn,"numPoints",5,(0,zf.getNumberValidator)());Yf.Factory.addGetterSetter(xn,"innerRadius",0,(0,zf.getNumberValidator)());Yf.Factory.addGetterSetter(xn,"outerRadius",0,(0,zf.getNumberValidator)());var Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.Text=void 0;Or.stringToArray=Bp;const Tf=ct,qt=Fe,iE=bt,kh=Le,kn=Ne,rE=Le;function Bp(u){return[...u].reduce((e,t,r,l)=>(/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(t)?e.push(t):/\p{Regional_Indicator}{2}/u.test(t+(l[r+1]||""))?e.push(t+l[r+1]):r>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(t)?e[e.length-1]+=t:e.push(t),e),[])}const ur="auto",lE="center",jp="inherit",ia="justify",aE="Change.konva",oE="2d",ig="-",qp="left",uE="text",cE="Text",hE="top",fE="bottom",rg="middle",Wp="normal",dE="px ",Lo=" ",_E="right",lg="rtl",gE="word",pE="char",ag="none",Mh="…",Kp=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],mE=Kp.length;function vE(u){return u.split(",").map(e=>{e=e.trim();const t=e.indexOf(" ")>=0,r=e.indexOf('"')>=0||e.indexOf("'")>=0;return t&&!r&&(e=`"${e}"`),e}).join(", ")}let Fo;function Uh(){return Fo||(Fo=Tf.Util.createCanvasElement().getContext(oE),Fo)}function TE(u){u.fillText(this._partialText,this._partialTextX,this._partialTextY)}function yE(u){u.setAttr("miterLimit",2),u.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function SE(u){return u=u||{},!u.fillLinearGradientColorStops&&!u.fillRadialGradientColorStops&&!u.fillPatternImage&&(u.fill=u.fill||"black"),u}class dt extends iE.Shape{constructor(e){super(SE(e)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<mE;t++)this.on(Kp[t]+aE,this._setTextData);this._setTextData()}_sceneFunc(e){const t=this.textArr,r=t.length;if(!this.text())return;let l=this.padding(),s=this.fontSize(),i=this.lineHeight()*s,f=this.verticalAlign(),h=this.direction(),d=0,p=this.align(),v=this.getWidth(),T=this.letterSpacing(),y=this.fill(),S=this.textDecoration(),A=S.indexOf("underline")!==-1,R=S.indexOf("line-through")!==-1,O;h=h===jp?e.direction:h;let N=i/2,C=rg;if(kh.Konva._fixTextRendering){const B=this.measureSize("M");C="alphabetic",N=(B.fontBoundingBoxAscent-B.fontBoundingBoxDescent)/2+i/2}var b=0,w=0;for(h===lg&&e.setAttr("direction",h),e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",C),e.setAttr("textAlign",qp),f===rg?d=(this.getHeight()-r*i-l*2)/2:f===fE&&(d=this.getHeight()-r*i-l*2),e.translate(l,d+l),O=0;O<r;O++){var b=0,w=0,F=t[O],q=F.text,D=F.width,P=F.lastInParagraph,I,x,U;if(e.save(),p===_E?b+=v-D-l*2:p===lE&&(b+=(v-D-l*2)/2),A){e.save(),e.beginPath();const L=kh.Konva._fixTextRendering?Math.round(s/4):Math.round(s/2),V=b,J=N+w+L;e.moveTo(V,J),I=q.split(" ").length-1,x=I===0,U=p===ia&&!P?v-l*2:D,e.lineTo(V+Math.round(U),J),e.lineWidth=s/15;const Pe=this._getLinearGradient();e.strokeStyle=Pe||y,e.stroke(),e.restore()}if(R){e.save(),e.beginPath();const L=kh.Konva._fixTextRendering?-Math.round(s/4):0;e.moveTo(b,N+w+L),I=q.split(" ").length-1,x=I===0,U=p===ia&&P&&!x?v-l*2:D,e.lineTo(b+Math.round(U),N+w+L),e.lineWidth=s/15;const V=this._getLinearGradient();e.strokeStyle=V||y,e.stroke(),e.restore()}if(h!==lg&&(T!==0||p===ia)){I=q.split(" ").length-1;const L=Bp(q);for(let V=0;V<L.length;V++){const J=L[V];J===" "&&!P&&p===ia&&(b+=(v-l*2-D)/I),this._partialTextX=b,this._partialTextY=N+w,this._partialText=J,e.fillStrokeShape(this),b+=this.measureSize(J).width+T}}else T!==0&&e.setAttr("letterSpacing",`${T}px`),this._partialTextX=b,this._partialTextY=N+w,this._partialText=q,e.fillStrokeShape(this);e.restore(),r>1&&(N+=i)}}_hitFunc(e){const t=this.getWidth(),r=this.getHeight();e.beginPath(),e.rect(0,0,t,r),e.closePath(),e.fillStrokeShape(this)}setText(e){const t=Tf.Util._isString(e)?e:e==null?"":e+"";return this._setAttr(uE,t),this}getWidth(){return this.attrs.width===ur||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===ur||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return Tf.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(e){var t,r,l,s,i,f,h,d,p,v,T;let y=Uh(),S=this.fontSize(),A;y.save(),y.font=this._getContextFont(),A=y.measureText(e),y.restore();const R=S/100;return{actualBoundingBoxAscent:(t=A.actualBoundingBoxAscent)!==null&&t!==void 0?t:71.58203125*R,actualBoundingBoxDescent:(r=A.actualBoundingBoxDescent)!==null&&r!==void 0?r:0,actualBoundingBoxLeft:(l=A.actualBoundingBoxLeft)!==null&&l!==void 0?l:-7.421875*R,actualBoundingBoxRight:(s=A.actualBoundingBoxRight)!==null&&s!==void 0?s:75.732421875*R,alphabeticBaseline:(i=A.alphabeticBaseline)!==null&&i!==void 0?i:0,emHeightAscent:(f=A.emHeightAscent)!==null&&f!==void 0?f:100*R,emHeightDescent:(h=A.emHeightDescent)!==null&&h!==void 0?h:-20*R,fontBoundingBoxAscent:(d=A.fontBoundingBoxAscent)!==null&&d!==void 0?d:91*R,fontBoundingBoxDescent:(p=A.fontBoundingBoxDescent)!==null&&p!==void 0?p:21*R,hangingBaseline:(v=A.hangingBaseline)!==null&&v!==void 0?v:72.80000305175781*R,ideographicBaseline:(T=A.ideographicBaseline)!==null&&T!==void 0?T:-21*R,width:A.width,height:S}}_getContextFont(){return this.fontStyle()+Lo+this.fontVariant()+Lo+(this.fontSize()+dE)+vE(this.fontFamily())}_addTextLine(e){this.align()===ia&&(e=e.trim());const r=this._getTextWidth(e);return this.textArr.push({text:e,width:r,lastInParagraph:!1})}_getTextWidth(e){const t=this.letterSpacing(),r=e.length;return Uh().measureText(e).width+(r?t*(r-1):0)}_setTextData(){let e=this.text().split(`
160
- `),t=+this.fontSize(),r=0,l=this.lineHeight()*t,s=this.attrs.width,i=this.attrs.height,f=s!==ur&&s!==void 0,h=i!==ur&&i!==void 0,d=this.padding(),p=s-d*2,v=i-d*2,T=0,y=this.wrap(),S=y!==ag,A=y!==pE&&S,R=this.ellipsis();this.textArr=[],Uh().font=this._getContextFont();const O=R?this._getTextWidth(Mh):0;for(let C=0,b=e.length;C<b;++C){let w=e[C],F=this._getTextWidth(w);if(f&&F>p)for(;w.length>0;){let q=0,D=w.length,P="",I=0;for(;q<D;){const x=q+D>>>1,U=w.slice(0,x+1),B=this._getTextWidth(U)+O;B<=p?(q=x+1,P=U,I=B):D=x}if(P){if(A){var N;const U=w[P.length];(U===Lo||U===ig)&&I<=p?N=P.length:N=Math.max(P.lastIndexOf(Lo),P.lastIndexOf(ig))+1,N>0&&(q=N,P=P.slice(0,q),I=this._getTextWidth(P))}if(P=P.trimRight(),this._addTextLine(P),r=Math.max(r,I),T+=l,this._shouldHandleEllipsis(T)){this._tryToAddEllipsisToLastLine();break}if(w=w.slice(q),w=w.trimLeft(),w.length>0&&(F=this._getTextWidth(w),F<=p)){this._addTextLine(w),T+=l,r=Math.max(r,F);break}}else break}else this._addTextLine(w),T+=l,r=Math.max(r,F),this._shouldHandleEllipsis(T)&&C<b-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),h&&T+l>v)break}this.textHeight=t,this.textWidth=r}_shouldHandleEllipsis(e){const t=+this.fontSize(),r=this.lineHeight()*t,l=this.attrs.height,s=l!==ur&&l!==void 0,i=this.padding(),f=l-i*2;return!(this.wrap()!==ag)||s&&e+r>f}_tryToAddEllipsisToLastLine(){const e=this.attrs.width,t=e!==ur&&e!==void 0,r=this.padding(),l=e-r*2,s=this.ellipsis(),i=this.textArr[this.textArr.length-1];!i||!s||(t&&(this._getTextWidth(i.text+Mh)<l||(i.text=i.text.slice(0,i.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(i.text+Mh))}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const e=this.textDecoration().indexOf("underline")!==-1||this.textDecoration().indexOf("line-through")!==-1,t=this.hasShadow();return e&&t?!0:super._useBufferCanvas()}}Or.Text=dt;dt.prototype._fillFunc=TE;dt.prototype._strokeFunc=yE;dt.prototype.className=cE;dt.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"];(0,rE._registerNode)(dt);qt.Factory.overWriteSetter(dt,"width",(0,kn.getNumberOrAutoValidator)());qt.Factory.overWriteSetter(dt,"height",(0,kn.getNumberOrAutoValidator)());qt.Factory.addGetterSetter(dt,"direction",jp);qt.Factory.addGetterSetter(dt,"fontFamily","Arial");qt.Factory.addGetterSetter(dt,"fontSize",12,(0,kn.getNumberValidator)());qt.Factory.addGetterSetter(dt,"fontStyle",Wp);qt.Factory.addGetterSetter(dt,"fontVariant",Wp);qt.Factory.addGetterSetter(dt,"padding",0,(0,kn.getNumberValidator)());qt.Factory.addGetterSetter(dt,"align",qp);qt.Factory.addGetterSetter(dt,"verticalAlign",hE);qt.Factory.addGetterSetter(dt,"lineHeight",1,(0,kn.getNumberValidator)());qt.Factory.addGetterSetter(dt,"wrap",gE);qt.Factory.addGetterSetter(dt,"ellipsis",!1,(0,kn.getBooleanValidator)());qt.Factory.addGetterSetter(dt,"letterSpacing",0,(0,kn.getNumberValidator)());qt.Factory.addGetterSetter(dt,"text","",(0,kn.getStringValidator)());qt.Factory.addGetterSetter(dt,"textDecoration","");var Yu={};Object.defineProperty(Yu,"__esModule",{value:!0});Yu.TextPath=void 0;const Lh=ct,Ss=Fe,EE=bt,ra=wr,Fh=Or,Yp=Ne,CE=Le,AE="",zp="normal";function Xp(u){u.fillText(this.partialText,0,0)}function Jp(u){u.strokeText(this.partialText,0,0)}class Rt extends EE.Shape{constructor(e){super(e),this.dummyCanvas=Lh.Util.createCanvasElement(),this.dataArray=[],this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute(),this._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva",this._setTextData),this._setTextData()}_getTextPathLength(){return ra.Path.getPathLength(this.dataArray)}_getPointAtLength(e){if(!this.attrs.data)return null;const t=this.pathLength;return e-1>t?null:ra.Path.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=ra.Path.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(e){e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",this.textBaseline()),e.setAttr("textAlign","left"),e.save();const t=this.textDecoration(),r=this.fill(),l=this.fontSize(),s=this.glyphInfo;t==="underline"&&e.beginPath();for(let i=0;i<s.length;i++){e.save();const f=s[i].p0;e.translate(f.x,f.y),e.rotate(s[i].rotation),this.partialText=s[i].text,e.fillStrokeShape(this),t==="underline"&&(i===0&&e.moveTo(0,l/2+1),e.lineTo(l,l/2+1)),e.restore()}t==="underline"&&(e.strokeStyle=r,e.lineWidth=l/20,e.stroke()),e.restore()}_hitFunc(e){e.beginPath();const t=this.glyphInfo;if(t.length>=1){const r=t[0].p0;e.moveTo(r.x,r.y)}for(let r=0;r<t.length;r++){const l=t[r].p1;e.lineTo(l.x,l.y)}e.setAttr("lineWidth",this.fontSize()),e.setAttr("strokeStyle",this.colorKey),e.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return Lh.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(e){return Fh.Text.prototype.setText.call(this,e)}_getContextFont(){return Fh.Text.prototype._getContextFont.call(this)}_getTextSize(e){const r=this.dummyCanvas.getContext("2d");r.save(),r.font=this._getContextFont();const l=r.measureText(e);return r.restore(),{width:l.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const{width:e,height:t}=this._getTextSize(this.attrs.text);if(this.textWidth=e,this.textHeight=t,this.glyphInfo=[],!this.attrs.data)return null;const r=this.letterSpacing(),l=this.align(),s=this.kerningFunc(),i=Math.max(this.textWidth+((this.attrs.text||"").length-1)*r,0);let f=0;l==="center"&&(f=Math.max(0,this.pathLength/2-i/2)),l==="right"&&(f=Math.max(0,this.pathLength-i));const h=(0,Fh.stringToArray)(this.text());let d=f;for(let p=0;p<h.length;p++){const v=this._getPointAtLength(d);if(!v)return;let T=this._getTextSize(h[p]).width+r;if(h[p]===" "&&l==="justify"){const N=this.text().split(" ").length-1;T+=(this.pathLength-i)/N}const y=this._getPointAtLength(d+T);if(!y)return;const S=ra.Path.getLineLength(v.x,v.y,y.x,y.y);let A=0;if(s)try{A=s(h[p-1],h[p])*this.fontSize()}catch{A=0}v.x+=A,y.x+=A,this.textWidth+=A;const R=ra.Path.getPointOnLine(A+S/2,v.x,v.y,y.x,y.y),O=Math.atan2(y.y-v.y,y.x-v.x);this.glyphInfo.push({transposeX:R.x,transposeY:R.y,text:h[p],rotation:O,p0:v,p1:y}),d+=T}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const e=[];this.glyphInfo.forEach(function(d){e.push(d.p0.x),e.push(d.p0.y),e.push(d.p1.x),e.push(d.p1.y)});let t=e[0]||0,r=e[0]||0,l=e[1]||0,s=e[1]||0,i,f;for(let d=0;d<e.length/2;d++)i=e[d*2],f=e[d*2+1],t=Math.min(t,i),r=Math.max(r,i),l=Math.min(l,f),s=Math.max(s,f);const h=this.fontSize();return{x:t-h/2,y:l-h/2,width:r-t+h,height:s-l+h}}destroy(){return Lh.Util.releaseCanvas(this.dummyCanvas),super.destroy()}}Yu.TextPath=Rt;Rt.prototype._fillFunc=Xp;Rt.prototype._strokeFunc=Jp;Rt.prototype._fillFuncHit=Xp;Rt.prototype._strokeFuncHit=Jp;Rt.prototype.className="TextPath";Rt.prototype._attrsAffectingSize=["text","fontSize","data"];(0,CE._registerNode)(Rt);Ss.Factory.addGetterSetter(Rt,"data");Ss.Factory.addGetterSetter(Rt,"fontFamily","Arial");Ss.Factory.addGetterSetter(Rt,"fontSize",12,(0,Yp.getNumberValidator)());Ss.Factory.addGetterSetter(Rt,"fontStyle",zp);Ss.Factory.addGetterSetter(Rt,"align","left");Ss.Factory.addGetterSetter(Rt,"letterSpacing",0,(0,Yp.getNumberValidator)());Ss.Factory.addGetterSetter(Rt,"textBaseline","middle");Ss.Factory.addGetterSetter(Rt,"fontVariant",zp);Ss.Factory.addGetterSetter(Rt,"text",AE);Ss.Factory.addGetterSetter(Rt,"textDecoration",null);Ss.Factory.addGetterSetter(Rt,"kerningFunc",null);var zu={};Object.defineProperty(zu,"__esModule",{value:!0});zu.Transformer=void 0;const We=ct,qe=Fe,og=it,bE=bt,RE=Ua,ug=br,gs=Le,Mn=Ne,wE=Le,Qp="tr-konva",IE=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(u=>u+`.${Qp}`).join(" "),cg="nodesRect",OE=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange"],DE={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},NE="ontouchstart"in gs.Konva._global;function PE(u,e,t){if(u==="rotater")return t;e+=We.Util.degToRad(DE[u]||0);const r=(We.Util.radToDeg(e)%360+360)%360;return We.Util._inRange(r,315+22.5,360)||We.Util._inRange(r,0,22.5)?"ns-resize":We.Util._inRange(r,45-22.5,45+22.5)?"nesw-resize":We.Util._inRange(r,90-22.5,90+22.5)?"ew-resize":We.Util._inRange(r,135-22.5,135+22.5)?"nwse-resize":We.Util._inRange(r,180-22.5,180+22.5)?"ns-resize":We.Util._inRange(r,225-22.5,225+22.5)?"nesw-resize":We.Util._inRange(r,270-22.5,270+22.5)?"ew-resize":We.Util._inRange(r,315-22.5,315+22.5)?"nwse-resize":(We.Util.error("Transformer has unknown angle for cursor detection: "+r),"pointer")}const gu=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"],hg=1e8;function xE(u){return{x:u.x+u.width/2*Math.cos(u.rotation)+u.height/2*Math.sin(-u.rotation),y:u.y+u.height/2*Math.cos(u.rotation)+u.width/2*Math.sin(u.rotation)}}function Zp(u,e,t){const r=t.x+(u.x-t.x)*Math.cos(e)-(u.y-t.y)*Math.sin(e),l=t.y+(u.x-t.x)*Math.sin(e)+(u.y-t.y)*Math.cos(e);return{...u,rotation:u.rotation+e,x:r,y:l}}function kE(u,e){const t=xE(u);return Zp(u,e,t)}function ME(u,e,t){let r=e;for(let l=0;l<u.length;l++){const s=gs.Konva.getAngle(u[l]),i=Math.abs(s-e)%(Math.PI*2);Math.min(i,Math.PI*2-i)<t&&(r=s)}return r}let yf=0;class Ve extends ug.Group{constructor(e){super(e),this._movingAnchorName=null,this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(IE,this.update),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return We.Util.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([e])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return Qp+this._id}setNodes(e=[]){this._nodes&&this._nodes.length&&this.detach();const t=e.filter(l=>l.isAncestorOf(this)?(We.Util.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0);return this._nodes=e=t,e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(l=>{const s=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()},i=l._attrsAffectingSize.map(f=>f+"Change."+this._getEventNamespace()).join(" ");l.on(i,s),l.on(OE.map(f=>f+`.${this._getEventNamespace()}`).join(" "),s),l.on(`absoluteTransformChange.${this._getEventNamespace()}`,s),this._proxyDrag(l)}),this._resetTransformCache(),!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(e){let t;e.on(`dragstart.${this._getEventNamespace()}`,r=>{t=e.getAbsolutePosition(),!this.isDragging()&&e!==this.findOne(".back")&&this.startDrag(r,!1)}),e.on(`dragmove.${this._getEventNamespace()}`,r=>{if(!t)return;const l=e.getAbsolutePosition(),s=l.x-t.x,i=l.y-t.y;this.nodes().forEach(f=>{if(f===e||f.isDragging())return;const h=f.getAbsolutePosition();f.setAbsolutePosition({x:h.x+s,y:h.y+i}),f.startDrag(r)}),t=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(e=>{e.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(cg),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(cg,this.__getNodeRect)}__getNodeShape(e,t=this.rotation(),r){const l=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=e.getAbsoluteScale(r),i=e.getAbsolutePosition(r),f=l.x*s.x-e.offsetX()*s.x,h=l.y*s.y-e.offsetY()*s.y,d=(gs.Konva.getAngle(e.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2),p={x:i.x+f*Math.cos(d)+h*Math.sin(-d),y:i.y+h*Math.cos(d)+f*Math.sin(d),width:l.width*s.x,height:l.height*s.y,rotation:d};return Zp(p,-gs.Konva.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-hg,y:-hg,width:0,height:0,rotation:0};const t=[];this.nodes().map(d=>{const p=d.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),v=[{x:p.x,y:p.y},{x:p.x+p.width,y:p.y},{x:p.x+p.width,y:p.y+p.height},{x:p.x,y:p.y+p.height}],T=d.getAbsoluteTransform();v.forEach(function(y){const S=T.point(y);t.push(S)})});const r=new We.Transform;r.rotate(-gs.Konva.getAngle(this.rotation()));let l=1/0,s=1/0,i=-1/0,f=-1/0;t.forEach(function(d){const p=r.point(d);l===void 0&&(l=i=p.x,s=f=p.y),l=Math.min(l,p.x),s=Math.min(s,p.y),i=Math.max(i,p.x),f=Math.max(f,p.y)}),r.invert();const h=r.point({x:l,y:s});return{x:h.x,y:h.y,width:i-l,height:f-s,rotation:gs.Konva.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),gu.forEach(e=>{this._createAnchor(e)}),this._createAnchor("rotater")}_createAnchor(e){const t=new RE.Rect({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:e+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:NE?10:"auto"}),r=this;t.on("mousedown touchstart",function(l){r._handleMouseDown(l)}),t.on("dragstart",l=>{t.stopDrag(),l.cancelBubble=!0}),t.on("dragend",l=>{l.cancelBubble=!0}),t.on("mouseenter",()=>{const l=gs.Konva.getAngle(this.rotation()),s=this.rotateAnchorCursor(),i=PE(e,l,s);t.getStage().content&&(t.getStage().content.style.cursor=i),this._cursorChange=!0}),t.on("mouseout",()=>{t.getStage().content&&(t.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(t)}_createBack(){const e=new bE.Shape({name:"back",width:0,height:0,draggable:!0,sceneFunc(t,r){const l=r.getParent(),s=l.padding();t.beginPath(),t.rect(-s,-s,r.width()+s*2,r.height()+s*2),t.moveTo(r.width()/2,-s),l.rotateEnabled()&&l.rotateLineVisible()&&t.lineTo(r.width()/2,-l.rotateAnchorOffset()*We.Util._sign(r.height())-s),t.fillStrokeShape(r)},hitFunc:(t,r)=>{if(!this.shouldOverdrawWholeArea())return;const l=this.padding();t.beginPath(),t.rect(-l,-l,r.width()+l*2,r.height()+l*2),t.fillStrokeShape(r)}});this.add(e),this._proxyDrag(e),e.on("dragstart",t=>{t.cancelBubble=!0}),e.on("dragmove",t=>{t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{this.update()})}_handleMouseDown(e){if(this._transforming)return;this._movingAnchorName=e.target.name().split(" ")[0];const t=this._getNodeRect(),r=t.width,l=t.height,s=Math.sqrt(Math.pow(r,2)+Math.pow(l,2));this.sin=Math.abs(l/s),this.cos=Math.abs(r/s),typeof window<"u"&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const i=e.target.getAbsolutePosition(),f=e.target.getStage().getPointerPosition();this._anchorDragOffset={x:f.x-i.x,y:f.y-i.y},yf++,this._fire("transformstart",{evt:e.evt,target:this.getNode()}),this._nodes.forEach(h=>{h._fire("transformstart",{evt:e.evt,target:h})})}_handleMouseMove(e){let t,r,l;const s=this.findOne("."+this._movingAnchorName),i=s.getStage();i.setPointersPositions(e);const f=i.getPointerPosition();let h={x:f.x-this._anchorDragOffset.x,y:f.y-this._anchorDragOffset.y};const d=s.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(d,h,e)),s.setAbsolutePosition(h);const p=s.getAbsolutePosition();if(d.x===p.x&&d.y===p.y)return;if(this._movingAnchorName==="rotater"){const w=this._getNodeRect();t=s.x()-w.width/2,r=-s.y()+w.height/2;let F=Math.atan2(-r,t)+Math.PI/2;w.height<0&&(F-=Math.PI);const D=gs.Konva.getAngle(this.rotation())+F,P=gs.Konva.getAngle(this.rotationSnapTolerance()),x=ME(this.rotationSnaps(),D,P)-w.rotation,U=kE(w,x);this._fitNodesInto(U,e);return}const v=this.shiftBehavior();let T;v==="inverted"?T=this.keepRatio()&&!e.shiftKey:v==="none"?T=this.keepRatio():T=this.keepRatio()||e.shiftKey;var O=this.centeredScaling()||e.altKey;if(this._movingAnchorName==="top-left"){if(T){var y=O?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};l=Math.sqrt(Math.pow(y.x-s.x(),2)+Math.pow(y.y-s.y(),2));var S=this.findOne(".top-left").x()>y.x?-1:1,A=this.findOne(".top-left").y()>y.y?-1:1;t=l*this.cos*S,r=l*this.sin*A,this.findOne(".top-left").x(y.x-t),this.findOne(".top-left").y(y.y-r)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(s.y());else if(this._movingAnchorName==="top-right"){if(T){var y=O?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};l=Math.sqrt(Math.pow(s.x()-y.x,2)+Math.pow(y.y-s.y(),2));var S=this.findOne(".top-right").x()<y.x?-1:1,A=this.findOne(".top-right").y()>y.y?-1:1;t=l*this.cos*S,r=l*this.sin*A,this.findOne(".top-right").x(y.x+t),this.findOne(".top-right").y(y.y-r)}var R=s.position();this.findOne(".top-left").y(R.y),this.findOne(".bottom-right").x(R.x)}else if(this._movingAnchorName==="middle-left")this.findOne(".top-left").x(s.x());else if(this._movingAnchorName==="middle-right")this.findOne(".bottom-right").x(s.x());else if(this._movingAnchorName==="bottom-left"){if(T){var y=O?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};l=Math.sqrt(Math.pow(y.x-s.x(),2)+Math.pow(s.y()-y.y,2));var S=y.x<s.x()?-1:1,A=s.y()<y.y?-1:1;t=l*this.cos*S,r=l*this.sin*A,s.x(y.x-t),s.y(y.y+r)}R=s.position(),this.findOne(".top-left").x(R.x),this.findOne(".bottom-right").y(R.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(s.y());else if(this._movingAnchorName==="bottom-right"){if(T){var y=O?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};l=Math.sqrt(Math.pow(s.x()-y.x,2)+Math.pow(s.y()-y.y,2));var S=this.findOne(".bottom-right").x()<y.x?-1:1,A=this.findOne(".bottom-right").y()<y.y?-1:1;t=l*this.cos*S,r=l*this.sin*A,this.findOne(".bottom-right").x(y.x+t),this.findOne(".bottom-right").y(y.y+r)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));var O=this.centeredScaling()||e.altKey;if(O){const w=this.findOne(".top-left"),F=this.findOne(".bottom-right"),q=w.x(),D=w.y(),P=this.getWidth()-F.x(),I=this.getHeight()-F.y();F.move({x:-q,y:-D}),w.move({x:P,y:I})}const N=this.findOne(".top-left").getAbsolutePosition();t=N.x,r=N.y;const C=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),b=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:t,y:r,width:C,height:b,rotation:gs.Konva.getAngle(this.rotation())},e)}_handleMouseUp(e){this._removeEvents(e)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(e){var t;if(this._transforming){this._transforming=!1,typeof window<"u"&&(window.removeEventListener("mousemove",this._handleMouseMove),window.removeEventListener("touchmove",this._handleMouseMove),window.removeEventListener("mouseup",this._handleMouseUp,!0),window.removeEventListener("touchend",this._handleMouseUp,!0));const r=this.getNode();yf--,this._fire("transformend",{evt:e,target:r}),(t=this.getLayer())===null||t===void 0||t.batchDraw(),r&&this._nodes.forEach(l=>{var s;l._fire("transformend",{evt:e,target:l}),(s=l.getLayer())===null||s===void 0||s.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(e,t){const r=this._getNodeRect(),l=1;if(We.Util._inRange(e.width,-this.padding()*2-l,l)){this.update();return}if(We.Util._inRange(e.height,-this.padding()*2-l,l)){this.update();return}const s=new We.Transform;if(s.rotate(gs.Konva.getAngle(this.rotation())),this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("left")>=0){const T=s.point({x:-this.padding()*2,y:0});e.x+=T.x,e.y+=T.y,e.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=T.x,this._anchorDragOffset.y-=T.y}else if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("right")>=0){const T=s.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=T.x,this._anchorDragOffset.y-=T.y,e.width+=this.padding()*2}if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("top")>=0){const T=s.point({x:0,y:-this.padding()*2});e.x+=T.x,e.y+=T.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=T.x,this._anchorDragOffset.y-=T.y,e.height+=this.padding()*2}else if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const T=s.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=T.x,this._anchorDragOffset.y-=T.y,e.height+=this.padding()*2}if(this.boundBoxFunc()){const T=this.boundBoxFunc()(r,e);T?e=T:We.Util.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const i=1e7,f=new We.Transform;f.translate(r.x,r.y),f.rotate(r.rotation),f.scale(r.width/i,r.height/i);const h=new We.Transform,d=e.width/i,p=e.height/i;this.flipEnabled()===!1?(h.translate(e.x,e.y),h.rotate(e.rotation),h.translate(e.width<0?e.width:0,e.height<0?e.height:0),h.scale(Math.abs(d),Math.abs(p))):(h.translate(e.x,e.y),h.rotate(e.rotation),h.scale(d,p));const v=h.multiply(f.invert());this._nodes.forEach(T=>{var y;const S=T.getParent().getAbsoluteTransform(),A=T.getTransform().copy();A.translate(T.offsetX(),T.offsetY());const R=new We.Transform;R.multiply(S.copy().invert()).multiply(v).multiply(S).multiply(A);const O=R.decompose();T.setAttrs(O),(y=T.getLayer())===null||y===void 0||y.batchDraw()}),this.rotation(We.Util._getRotation(e.rotation)),this._nodes.forEach(T=>{this._fire("transform",{evt:t,target:T}),T._fire("transform",{evt:t,target:T})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(e,t){this.findOne(e).setAttrs(t)}update(){var e;const t=this._getNodeRect();this.rotation(We.Util._getRotation(t.rotation));const r=t.width,l=t.height,s=this.enabledAnchors(),i=this.resizeEnabled(),f=this.padding(),h=this.anchorSize(),d=this.find("._anchor");d.forEach(v=>{v.setAttrs({width:h,height:h,offsetX:h/2,offsetY:h/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:h/2+f,offsetY:h/2+f,visible:i&&s.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:r/2,y:0,offsetY:h/2+f,visible:i&&s.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:r,y:0,offsetX:h/2-f,offsetY:h/2+f,visible:i&&s.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:l/2,offsetX:h/2+f,visible:i&&s.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:r,y:l/2,offsetX:h/2-f,visible:i&&s.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:l,offsetX:h/2+f,offsetY:h/2-f,visible:i&&s.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:r/2,y:l,offsetY:h/2-f,visible:i&&s.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:r,y:l,offsetX:h/2-f,offsetY:h/2-f,visible:i&&s.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:r/2,y:-this.rotateAnchorOffset()*We.Util._sign(l)-f,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:r,height:l,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),x:0,y:0});const p=this.anchorStyleFunc();p&&d.forEach(v=>{p(v)}),(e=this.getLayer())===null||e===void 0||e.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();const e=this.findOne("."+this._movingAnchorName);e&&e.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),ug.Group.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return og.Node.prototype.toObject.call(this)}clone(e){return og.Node.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}zu.Transformer=Ve;Ve.isTransforming=()=>yf>0;function UE(u){return u instanceof Array||We.Util.warn("enabledAnchors value should be an array"),u instanceof Array&&u.forEach(function(e){gu.indexOf(e)===-1&&We.Util.warn("Unknown anchor name: "+e+". Available names are: "+gu.join(", "))}),u||[]}Ve.prototype.className="Transformer";(0,wE._registerNode)(Ve);qe.Factory.addGetterSetter(Ve,"enabledAnchors",gu,UE);qe.Factory.addGetterSetter(Ve,"flipEnabled",!0,(0,Mn.getBooleanValidator)());qe.Factory.addGetterSetter(Ve,"resizeEnabled",!0);qe.Factory.addGetterSetter(Ve,"anchorSize",10,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"rotateEnabled",!0);qe.Factory.addGetterSetter(Ve,"rotateLineVisible",!0);qe.Factory.addGetterSetter(Ve,"rotationSnaps",[]);qe.Factory.addGetterSetter(Ve,"rotateAnchorOffset",50,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"rotateAnchorCursor","crosshair");qe.Factory.addGetterSetter(Ve,"rotationSnapTolerance",5,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"borderEnabled",!0);qe.Factory.addGetterSetter(Ve,"anchorStroke","rgb(0, 161, 255)");qe.Factory.addGetterSetter(Ve,"anchorStrokeWidth",1,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"anchorFill","white");qe.Factory.addGetterSetter(Ve,"anchorCornerRadius",0,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"borderStroke","rgb(0, 161, 255)");qe.Factory.addGetterSetter(Ve,"borderStrokeWidth",1,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"borderDash");qe.Factory.addGetterSetter(Ve,"keepRatio",!0);qe.Factory.addGetterSetter(Ve,"shiftBehavior","default");qe.Factory.addGetterSetter(Ve,"centeredScaling",!1);qe.Factory.addGetterSetter(Ve,"ignoreStroke",!1);qe.Factory.addGetterSetter(Ve,"padding",0,(0,Mn.getNumberValidator)());qe.Factory.addGetterSetter(Ve,"node");qe.Factory.addGetterSetter(Ve,"nodes");qe.Factory.addGetterSetter(Ve,"boundBoxFunc");qe.Factory.addGetterSetter(Ve,"anchorDragBoundFunc");qe.Factory.addGetterSetter(Ve,"anchorStyleFunc");qe.Factory.addGetterSetter(Ve,"shouldOverdrawWholeArea",!1);qe.Factory.addGetterSetter(Ve,"useSingleNodeRotation",!0);qe.Factory.backCompat(Ve,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});var Xu={};Object.defineProperty(Xu,"__esModule",{value:!0});Xu.Wedge=void 0;const Ju=Fe,LE=bt,FE=Le,e0=Ne,$E=Le;class tn extends LE.Shape{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,FE.Konva.getAngle(this.angle()),this.clockwise()),e.lineTo(0,0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}}Xu.Wedge=tn;tn.prototype.className="Wedge";tn.prototype._centroid=!0;tn.prototype._attrsAffectingSize=["radius"];(0,$E._registerNode)(tn);Ju.Factory.addGetterSetter(tn,"radius",0,(0,e0.getNumberValidator)());Ju.Factory.addGetterSetter(tn,"angle",0,(0,e0.getNumberValidator)());Ju.Factory.addGetterSetter(tn,"clockwise",!1);Ju.Factory.backCompat(tn,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});var Qu={};Object.defineProperty(Qu,"__esModule",{value:!0});Qu.Blur=void 0;const fg=Fe,HE=it,GE=Ne;function dg(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}const VE=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],BE=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function jE(u,e){const t=u.data,r=u.width,l=u.height;let s,i,f,h,d,p,v,T,y,S,A,R,O,N,C,b,w,F,q,D,P,I,x,U,B=e+e+1,z=r-1,L=l-1,V=e+1,J=V*(V+1)/2,Pe=new dg,ee=null,j=Pe,K=null,ie=null,ue=VE[e],Ce=BE[e];for(f=1;f<B;f++)j=j.next=new dg,f===V&&(ee=j);for(j.next=Pe,v=p=0,i=0;i<l;i++){for(b=w=F=q=T=y=S=A=0,R=V*(D=t[p]),O=V*(P=t[p+1]),N=V*(I=t[p+2]),C=V*(x=t[p+3]),T+=J*D,y+=J*P,S+=J*I,A+=J*x,j=Pe,f=0;f<V;f++)j.r=D,j.g=P,j.b=I,j.a=x,j=j.next;for(f=1;f<V;f++)h=p+((z<f?z:f)<<2),T+=(j.r=D=t[h])*(U=V-f),y+=(j.g=P=t[h+1])*U,S+=(j.b=I=t[h+2])*U,A+=(j.a=x=t[h+3])*U,b+=D,w+=P,F+=I,q+=x,j=j.next;for(K=Pe,ie=ee,s=0;s<r;s++)t[p+3]=x=A*ue>>Ce,x!==0?(x=255/x,t[p]=(T*ue>>Ce)*x,t[p+1]=(y*ue>>Ce)*x,t[p+2]=(S*ue>>Ce)*x):t[p]=t[p+1]=t[p+2]=0,T-=R,y-=O,S-=N,A-=C,R-=K.r,O-=K.g,N-=K.b,C-=K.a,h=v+((h=s+e+1)<z?h:z)<<2,b+=K.r=t[h],w+=K.g=t[h+1],F+=K.b=t[h+2],q+=K.a=t[h+3],T+=b,y+=w,S+=F,A+=q,K=K.next,R+=D=ie.r,O+=P=ie.g,N+=I=ie.b,C+=x=ie.a,b-=D,w-=P,F-=I,q-=x,ie=ie.next,p+=4;v+=r}for(s=0;s<r;s++){for(w=F=q=b=y=S=A=T=0,p=s<<2,R=V*(D=t[p]),O=V*(P=t[p+1]),N=V*(I=t[p+2]),C=V*(x=t[p+3]),T+=J*D,y+=J*P,S+=J*I,A+=J*x,j=Pe,f=0;f<V;f++)j.r=D,j.g=P,j.b=I,j.a=x,j=j.next;for(d=r,f=1;f<=e;f++)p=d+s<<2,T+=(j.r=D=t[p])*(U=V-f),y+=(j.g=P=t[p+1])*U,S+=(j.b=I=t[p+2])*U,A+=(j.a=x=t[p+3])*U,b+=D,w+=P,F+=I,q+=x,j=j.next,f<L&&(d+=r);for(p=s,K=Pe,ie=ee,i=0;i<l;i++)h=p<<2,t[h+3]=x=A*ue>>Ce,x>0?(x=255/x,t[h]=(T*ue>>Ce)*x,t[h+1]=(y*ue>>Ce)*x,t[h+2]=(S*ue>>Ce)*x):t[h]=t[h+1]=t[h+2]=0,T-=R,y-=O,S-=N,A-=C,R-=K.r,O-=K.g,N-=K.b,C-=K.a,h=s+((h=i+V)<L?h:L)*r<<2,T+=b+=K.r=t[h],y+=w+=K.g=t[h+1],S+=F+=K.b=t[h+2],A+=q+=K.a=t[h+3],K=K.next,R+=D=ie.r,O+=P=ie.g,N+=I=ie.b,C+=x=ie.a,b-=D,w-=P,F-=I,q-=x,ie=ie.next,p+=r}}const qE=function(e){const t=Math.round(this.blurRadius());t>0&&jE(e,t)};Qu.Blur=qE;fg.Factory.addGetterSetter(HE.Node,"blurRadius",0,(0,GE.getNumberValidator)(),fg.Factory.afterSetFilter);var Zu={};Object.defineProperty(Zu,"__esModule",{value:!0});Zu.Brighten=void 0;const _g=Fe,WE=it,KE=Ne,YE=function(u){let e=this.brightness()*255,t=u.data,r=t.length,l;for(l=0;l<r;l+=4)t[l]+=e,t[l+1]+=e,t[l+2]+=e};Zu.Brighten=YE;_g.Factory.addGetterSetter(WE.Node,"brightness",0,(0,KE.getNumberValidator)(),_g.Factory.afterSetFilter);var ec={};Object.defineProperty(ec,"__esModule",{value:!0});ec.Contrast=void 0;const gg=Fe,zE=it,XE=Ne,JE=function(u){const e=Math.pow((this.contrast()+100)/100,2);let t=u.data,r=t.length,l=150,s=150,i=150,f;for(f=0;f<r;f+=4)l=t[f],s=t[f+1],i=t[f+2],l/=255,l-=.5,l*=e,l+=.5,l*=255,s/=255,s-=.5,s*=e,s+=.5,s*=255,i/=255,i-=.5,i*=e,i+=.5,i*=255,l=l<0?0:l>255?255:l,s=s<0?0:s>255?255:s,i=i<0?0:i>255?255:i,t[f]=l,t[f+1]=s,t[f+2]=i};ec.Contrast=JE;gg.Factory.addGetterSetter(zE.Node,"contrast",0,(0,XE.getNumberValidator)(),gg.Factory.afterSetFilter);var tc={};Object.defineProperty(tc,"__esModule",{value:!0});tc.Emboss=void 0;const Rn=Fe,sc=it,QE=ct,t0=Ne,ZE=function(u){let e=this.embossStrength()*10,t=this.embossWhiteLevel()*255,r=this.embossDirection(),l=this.embossBlend(),s=0,i=0,f=u.data,h=u.width,d=u.height,p=h*4,v=d;switch(r){case"top-left":s=-1,i=-1;break;case"top":s=-1,i=0;break;case"top-right":s=-1,i=1;break;case"right":s=0,i=1;break;case"bottom-right":s=1,i=1;break;case"bottom":s=1,i=0;break;case"bottom-left":s=1,i=-1;break;case"left":s=0,i=-1;break;default:QE.Util.error("Unknown emboss direction: "+r)}do{const T=(v-1)*p;let y=s;v+y<1&&(y=0),v+y>d&&(y=0);const S=(v-1+y)*h*4;let A=h;do{const R=T+(A-1)*4;let O=i;A+O<1&&(O=0),A+O>h&&(O=0);const N=S+(A-1+O)*4,C=f[R]-f[N],b=f[R+1]-f[N+1],w=f[R+2]-f[N+2];let F=C;const q=F>0?F:-F,D=b>0?b:-b,P=w>0?w:-w;if(D>q&&(F=b),P>q&&(F=w),F*=e,l){const I=f[R]+F,x=f[R+1]+F,U=f[R+2]+F;f[R]=I>255?255:I<0?0:I,f[R+1]=x>255?255:x<0?0:x,f[R+2]=U>255?255:U<0?0:U}else{let I=t-F;I<0?I=0:I>255&&(I=255),f[R]=f[R+1]=f[R+2]=I}}while(--A)}while(--v)};tc.Emboss=ZE;Rn.Factory.addGetterSetter(sc.Node,"embossStrength",.5,(0,t0.getNumberValidator)(),Rn.Factory.afterSetFilter);Rn.Factory.addGetterSetter(sc.Node,"embossWhiteLevel",.5,(0,t0.getNumberValidator)(),Rn.Factory.afterSetFilter);Rn.Factory.addGetterSetter(sc.Node,"embossDirection","top-left",null,Rn.Factory.afterSetFilter);Rn.Factory.addGetterSetter(sc.Node,"embossBlend",!1,null,Rn.Factory.afterSetFilter);var nc={};Object.defineProperty(nc,"__esModule",{value:!0});nc.Enhance=void 0;const pg=Fe,eC=it,tC=Ne;function $h(u,e,t,r,l){let s=t-e,i=l-r,f;return s===0?r+i/2:i===0?r:(f=(u-e)/s,f=i*f+r,f)}const sC=function(u){let e=u.data,t=e.length,r=e[0],l=r,s,i=e[1],f=i,h,d=e[2],p=d,v,T;const y=this.enhance();if(y===0)return;for(T=0;T<t;T+=4)s=e[T+0],s<r?r=s:s>l&&(l=s),h=e[T+1],h<i?i=h:h>f&&(f=h),v=e[T+2],v<d?d=v:v>p&&(p=v);l===r&&(l=255,r=0),f===i&&(f=255,i=0),p===d&&(p=255,d=0);let S,A,R,O,N,C,b,w,F;for(y>0?(A=l+y*(255-l),R=r-y*(r-0),N=f+y*(255-f),C=i-y*(i-0),w=p+y*(255-p),F=d-y*(d-0)):(S=(l+r)*.5,A=l+y*(l-S),R=r+y*(r-S),O=(f+i)*.5,N=f+y*(f-O),C=i+y*(i-O),b=(p+d)*.5,w=p+y*(p-b),F=d+y*(d-b)),T=0;T<t;T+=4)e[T+0]=$h(e[T+0],r,l,R,A),e[T+1]=$h(e[T+1],i,f,C,N),e[T+2]=$h(e[T+2],d,p,F,w)};nc.Enhance=sC;pg.Factory.addGetterSetter(eC.Node,"enhance",0,(0,tC.getNumberValidator)(),pg.Factory.afterSetFilter);var ic={};Object.defineProperty(ic,"__esModule",{value:!0});ic.Grayscale=void 0;const nC=function(u){let e=u.data,t=e.length,r,l;for(r=0;r<t;r+=4)l=.34*e[r]+.5*e[r+1]+.16*e[r+2],e[r]=l,e[r+1]=l,e[r+2]=l};ic.Grayscale=nC;var rc={};Object.defineProperty(rc,"__esModule",{value:!0});rc.HSL=void 0;const vr=Fe,Xf=it,Jf=Ne;vr.Factory.addGetterSetter(Xf.Node,"hue",0,(0,Jf.getNumberValidator)(),vr.Factory.afterSetFilter);vr.Factory.addGetterSetter(Xf.Node,"saturation",0,(0,Jf.getNumberValidator)(),vr.Factory.afterSetFilter);vr.Factory.addGetterSetter(Xf.Node,"luminance",0,(0,Jf.getNumberValidator)(),vr.Factory.afterSetFilter);const iC=function(u){let e=u.data,t=e.length,r=1,l=Math.pow(2,this.saturation()),s=Math.abs(this.hue()+360)%360,i=this.luminance()*127,f;const h=r*l*Math.cos(s*Math.PI/180),d=r*l*Math.sin(s*Math.PI/180),p=.299*r+.701*h+.167*d,v=.587*r-.587*h+.33*d,T=.114*r-.114*h-.497*d,y=.299*r-.299*h-.328*d,S=.587*r+.413*h+.035*d,A=.114*r-.114*h+.293*d,R=.299*r-.3*h+1.25*d,O=.587*r-.586*h-1.05*d,N=.114*r+.886*h-.2*d;let C,b,w,F;for(f=0;f<t;f+=4)C=e[f+0],b=e[f+1],w=e[f+2],F=e[f+3],e[f+0]=p*C+v*b+T*w+i,e[f+1]=y*C+S*b+A*w+i,e[f+2]=R*C+O*b+N*w+i,e[f+3]=F};rc.HSL=iC;var lc={};Object.defineProperty(lc,"__esModule",{value:!0});lc.HSV=void 0;const Tr=Fe,Qf=it,Zf=Ne,rC=function(u){const e=u.data,t=e.length,r=Math.pow(2,this.value()),l=Math.pow(2,this.saturation()),s=Math.abs(this.hue()+360)%360,i=r*l*Math.cos(s*Math.PI/180),f=r*l*Math.sin(s*Math.PI/180),h=.299*r+.701*i+.167*f,d=.587*r-.587*i+.33*f,p=.114*r-.114*i-.497*f,v=.299*r-.299*i-.328*f,T=.587*r+.413*i+.035*f,y=.114*r-.114*i+.293*f,S=.299*r-.3*i+1.25*f,A=.587*r-.586*i-1.05*f,R=.114*r+.886*i-.2*f;let O,N,C,b;for(let w=0;w<t;w+=4)O=e[w+0],N=e[w+1],C=e[w+2],b=e[w+3],e[w+0]=h*O+d*N+p*C,e[w+1]=v*O+T*N+y*C,e[w+2]=S*O+A*N+R*C,e[w+3]=b};lc.HSV=rC;Tr.Factory.addGetterSetter(Qf.Node,"hue",0,(0,Zf.getNumberValidator)(),Tr.Factory.afterSetFilter);Tr.Factory.addGetterSetter(Qf.Node,"saturation",0,(0,Zf.getNumberValidator)(),Tr.Factory.afterSetFilter);Tr.Factory.addGetterSetter(Qf.Node,"value",0,(0,Zf.getNumberValidator)(),Tr.Factory.afterSetFilter);var ac={};Object.defineProperty(ac,"__esModule",{value:!0});ac.Invert=void 0;const lC=function(u){let e=u.data,t=e.length,r;for(r=0;r<t;r+=4)e[r]=255-e[r],e[r+1]=255-e[r+1],e[r+2]=255-e[r+2]};ac.Invert=lC;var oc={};Object.defineProperty(oc,"__esModule",{value:!0});oc.Kaleidoscope=void 0;const pu=Fe,s0=it,mg=ct,n0=Ne,aC=function(u,e,t){let r=u.data,l=e.data,s=u.width,i=u.height,f=t.polarCenterX||s/2,h=t.polarCenterY||i/2,d,p,v,T=0,y=0,S=0,A=0,R,O=Math.sqrt(f*f+h*h);p=s-f,v=i-h,R=Math.sqrt(p*p+v*v),O=R>O?R:O;let N=i,C=s,b,w,F=360/C*Math.PI/180,q,D;for(w=0;w<C;w+=1)for(q=Math.sin(w*F),D=Math.cos(w*F),b=0;b<N;b+=1)p=Math.floor(f+O*b/N*D),v=Math.floor(h+O*b/N*q),d=(v*s+p)*4,T=r[d+0],y=r[d+1],S=r[d+2],A=r[d+3],d=(w+b*s)*4,l[d+0]=T,l[d+1]=y,l[d+2]=S,l[d+3]=A},oC=function(u,e,t){let r=u.data,l=e.data,s=u.width,i=u.height,f=t.polarCenterX||s/2,h=t.polarCenterY||i/2,d,p,v,T,y,S=0,A=0,R=0,O=0,N,C=Math.sqrt(f*f+h*h);p=s-f,v=i-h,N=Math.sqrt(p*p+v*v),C=N>C?N:C;let b=i,w=s,F,q,D=t.polarRotation||0,P,I;for(p=0;p<s;p+=1)for(v=0;v<i;v+=1)T=p-f,y=v-h,F=Math.sqrt(T*T+y*y)*b/C,q=(Math.atan2(y,T)*180/Math.PI+360+D)%360,q=q*w/360,P=Math.floor(q),I=Math.floor(F),d=(I*s+P)*4,S=r[d+0],A=r[d+1],R=r[d+2],O=r[d+3],d=(v*s+p)*4,l[d+0]=S,l[d+1]=A,l[d+2]=R,l[d+3]=O},uC=function(u){const e=u.width,t=u.height;let r,l,s,i,f,h,d,p,v,T,y=Math.round(this.kaleidoscopePower());const S=Math.round(this.kaleidoscopeAngle()),A=Math.floor(e*(S%360)/360);if(y<1)return;const R=mg.Util.createCanvasElement();R.width=e,R.height=t;const O=R.getContext("2d").getImageData(0,0,e,t);mg.Util.releaseCanvas(R),aC(u,O,{polarCenterX:e/2,polarCenterY:t/2});let N=e/Math.pow(2,y);for(;N<=8;)N=N*2,y-=1;N=Math.ceil(N);let C=N,b=0,w=C,F=1;for(A+N>e&&(b=C,w=0,F=-1),l=0;l<t;l+=1)for(r=b;r!==w;r+=F)s=Math.round(r+A)%e,v=(e*l+s)*4,f=O.data[v+0],h=O.data[v+1],d=O.data[v+2],p=O.data[v+3],T=(e*l+r)*4,O.data[T+0]=f,O.data[T+1]=h,O.data[T+2]=d,O.data[T+3]=p;for(l=0;l<t;l+=1)for(C=Math.floor(N),i=0;i<y;i+=1){for(r=0;r<C+1;r+=1)v=(e*l+r)*4,f=O.data[v+0],h=O.data[v+1],d=O.data[v+2],p=O.data[v+3],T=(e*l+C*2-r-1)*4,O.data[T+0]=f,O.data[T+1]=h,O.data[T+2]=d,O.data[T+3]=p;C*=2}oC(O,u,{polarRotation:0})};oc.Kaleidoscope=uC;pu.Factory.addGetterSetter(s0.Node,"kaleidoscopePower",2,(0,n0.getNumberValidator)(),pu.Factory.afterSetFilter);pu.Factory.addGetterSetter(s0.Node,"kaleidoscopeAngle",0,(0,n0.getNumberValidator)(),pu.Factory.afterSetFilter);var uc={};Object.defineProperty(uc,"__esModule",{value:!0});uc.Mask=void 0;const vg=Fe,cC=it,hC=Ne;function $o(u,e,t){let r=(t*u.width+e)*4;const l=[];return l.push(u.data[r++],u.data[r++],u.data[r++],u.data[r++]),l}function la(u,e){return Math.sqrt(Math.pow(u[0]-e[0],2)+Math.pow(u[1]-e[1],2)+Math.pow(u[2]-e[2],2))}function fC(u){const e=[0,0,0];for(let t=0;t<u.length;t++)e[0]+=u[t][0],e[1]+=u[t][1],e[2]+=u[t][2];return e[0]/=u.length,e[1]/=u.length,e[2]/=u.length,e}function dC(u,e){const t=$o(u,0,0),r=$o(u,u.width-1,0),l=$o(u,0,u.height-1),s=$o(u,u.width-1,u.height-1),i=e||10;if(la(t,r)<i&&la(r,s)<i&&la(s,l)<i&&la(l,t)<i){const f=fC([r,t,s,l]),h=[];for(let d=0;d<u.width*u.height;d++){const p=la(f,[u.data[d*4],u.data[d*4+1],u.data[d*4+2]]);h[d]=p<i?0:255}return h}}function _C(u,e){for(let t=0;t<u.width*u.height;t++)u.data[4*t+3]=e[t]}function gC(u,e,t){const r=[1,1,1,1,0,1,1,1,1],l=Math.round(Math.sqrt(r.length)),s=Math.floor(l/2),i=[];for(let f=0;f<t;f++)for(let h=0;h<e;h++){const d=f*e+h;let p=0;for(let v=0;v<l;v++)for(let T=0;T<l;T++){const y=f+v-s,S=h+T-s;if(y>=0&&y<t&&S>=0&&S<e){const A=y*e+S,R=r[v*l+T];p+=u[A]*R}}i[d]=p===255*8?255:0}return i}function pC(u,e,t){const r=[1,1,1,1,1,1,1,1,1],l=Math.round(Math.sqrt(r.length)),s=Math.floor(l/2),i=[];for(let f=0;f<t;f++)for(let h=0;h<e;h++){const d=f*e+h;let p=0;for(let v=0;v<l;v++)for(let T=0;T<l;T++){const y=f+v-s,S=h+T-s;if(y>=0&&y<t&&S>=0&&S<e){const A=y*e+S,R=r[v*l+T];p+=u[A]*R}}i[d]=p>=255*4?255:0}return i}function mC(u,e,t){const r=[.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111],l=Math.round(Math.sqrt(r.length)),s=Math.floor(l/2),i=[];for(let f=0;f<t;f++)for(let h=0;h<e;h++){const d=f*e+h;let p=0;for(let v=0;v<l;v++)for(let T=0;T<l;T++){const y=f+v-s,S=h+T-s;if(y>=0&&y<t&&S>=0&&S<e){const A=y*e+S,R=r[v*l+T];p+=u[A]*R}}i[d]=p}return i}const vC=function(u){let e=this.threshold(),t=dC(u,e);return t&&(t=gC(t,u.width,u.height),t=pC(t,u.width,u.height),t=mC(t,u.width,u.height),_C(u,t)),u};uc.Mask=vC;vg.Factory.addGetterSetter(cC.Node,"threshold",0,(0,hC.getNumberValidator)(),vg.Factory.afterSetFilter);var cc={};Object.defineProperty(cc,"__esModule",{value:!0});cc.Noise=void 0;const Tg=Fe,TC=it,yC=Ne,SC=function(u){const e=this.noise()*255,t=u.data,r=t.length,l=e/2;for(let s=0;s<r;s+=4)t[s+0]+=l-2*l*Math.random(),t[s+1]+=l-2*l*Math.random(),t[s+2]+=l-2*l*Math.random()};cc.Noise=SC;Tg.Factory.addGetterSetter(TC.Node,"noise",.2,(0,yC.getNumberValidator)(),Tg.Factory.afterSetFilter);var hc={};Object.defineProperty(hc,"__esModule",{value:!0});hc.Pixelate=void 0;const yg=Fe,EC=ct,CC=it,AC=Ne,bC=function(u){let e=Math.ceil(this.pixelSize()),t=u.width,r=u.height,l,s,i,f,h,d,p,v=Math.ceil(t/e),T=Math.ceil(r/e),y,S,A,R,O,N,C,b=u.data;if(e<=0){EC.Util.error("pixelSize value can not be <= 0");return}for(O=0;O<v;O+=1)for(N=0;N<T;N+=1){for(f=0,h=0,d=0,p=0,y=O*e,S=y+e,A=N*e,R=A+e,C=0,l=y;l<S;l+=1)if(!(l>=t))for(s=A;s<R;s+=1)s>=r||(i=(t*s+l)*4,f+=b[i+0],h+=b[i+1],d+=b[i+2],p+=b[i+3],C+=1);for(f=f/C,h=h/C,d=d/C,p=p/C,l=y;l<S;l+=1)if(!(l>=t))for(s=A;s<R;s+=1)s>=r||(i=(t*s+l)*4,b[i+0]=f,b[i+1]=h,b[i+2]=d,b[i+3]=p)}};hc.Pixelate=bC;yg.Factory.addGetterSetter(CC.Node,"pixelSize",8,(0,AC.getNumberValidator)(),yg.Factory.afterSetFilter);var fc={};Object.defineProperty(fc,"__esModule",{value:!0});fc.Posterize=void 0;const Sg=Fe,RC=it,wC=Ne,IC=function(u){let e=Math.round(this.levels()*254)+1,t=u.data,r=t.length,l=255/e,s;for(s=0;s<r;s+=1)t[s]=Math.floor(t[s]/l)*l};fc.Posterize=IC;Sg.Factory.addGetterSetter(RC.Node,"levels",.5,(0,wC.getNumberValidator)(),Sg.Factory.afterSetFilter);var dc={};Object.defineProperty(dc,"__esModule",{value:!0});dc.RGB=void 0;const mu=Fe,ed=it,OC=Ne,DC=function(u){let e=u.data,t=e.length,r=this.red(),l=this.green(),s=this.blue(),i,f;for(i=0;i<t;i+=4)f=(.34*e[i]+.5*e[i+1]+.16*e[i+2])/255,e[i]=f*r,e[i+1]=f*l,e[i+2]=f*s,e[i+3]=e[i+3]};dc.RGB=DC;mu.Factory.addGetterSetter(ed.Node,"red",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)});mu.Factory.addGetterSetter(ed.Node,"green",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)});mu.Factory.addGetterSetter(ed.Node,"blue",0,OC.RGBComponent,mu.Factory.afterSetFilter);var _c={};Object.defineProperty(_c,"__esModule",{value:!0});_c.RGBA=void 0;const ya=Fe,gc=it,NC=Ne,PC=function(u){const e=u.data,t=e.length,r=this.red(),l=this.green(),s=this.blue(),i=this.alpha();for(let f=0;f<t;f+=4){const h=1-i;e[f]=r*i+e[f]*h,e[f+1]=l*i+e[f+1]*h,e[f+2]=s*i+e[f+2]*h}};_c.RGBA=PC;ya.Factory.addGetterSetter(gc.Node,"red",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)});ya.Factory.addGetterSetter(gc.Node,"green",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)});ya.Factory.addGetterSetter(gc.Node,"blue",0,NC.RGBComponent,ya.Factory.afterSetFilter);ya.Factory.addGetterSetter(gc.Node,"alpha",1,function(u){return this._filterUpToDate=!1,u>1?1:u<0?0:u});var pc={};Object.defineProperty(pc,"__esModule",{value:!0});pc.Sepia=void 0;const xC=function(u){let e=u.data,t=e.length,r,l,s,i;for(r=0;r<t;r+=4)l=e[r+0],s=e[r+1],i=e[r+2],e[r+0]=Math.min(255,l*.393+s*.769+i*.189),e[r+1]=Math.min(255,l*.349+s*.686+i*.168),e[r+2]=Math.min(255,l*.272+s*.534+i*.131)};pc.Sepia=xC;var mc={};Object.defineProperty(mc,"__esModule",{value:!0});mc.Solarize=void 0;const kC=function(u){const e=u.data,t=u.width,r=u.height,l=t*4;let s=r;do{const i=(s-1)*l;let f=t;do{const h=i+(f-1)*4;let d=e[h],p=e[h+1],v=e[h+2];d>127&&(d=255-d),p>127&&(p=255-p),v>127&&(v=255-v),e[h]=d,e[h+1]=p,e[h+2]=v}while(--f)}while(--s)};mc.Solarize=kC;var vc={};Object.defineProperty(vc,"__esModule",{value:!0});vc.Threshold=void 0;const Eg=Fe,MC=it,UC=Ne,LC=function(u){const e=this.threshold()*255,t=u.data,r=t.length;for(let l=0;l<r;l+=1)t[l]=t[l]<e?0:255};vc.Threshold=LC;Eg.Factory.addGetterSetter(MC.Node,"threshold",.5,(0,UC.getNumberValidator)(),Eg.Factory.afterSetFilter);Object.defineProperty(wu,"__esModule",{value:!0});wu.Konva=void 0;const Cg=Ep,FC=xu,$C=Uu,HC=$u,GC=Hu,VC=Gu,Ag=mr,BC=ka,jC=wr,qC=Ua,WC=ju,KC=qu,YC=Wu,zC=Ku,XC=Or,JC=Yu,QC=zu,ZC=Xu,eA=Qu,tA=Zu,sA=ec,nA=tc,iA=nc,rA=ic,lA=rc,aA=lc,oA=ac,uA=oc,cA=uc,hA=cc,fA=hc,dA=fc,_A=dc,gA=_c,pA=pc,mA=mc,vA=vc;wu.Konva=Cg.Konva.Util._assign(Cg.Konva,{Arc:FC.Arc,Arrow:$C.Arrow,Circle:HC.Circle,Ellipse:GC.Ellipse,Image:VC.Image,Label:Ag.Label,Tag:Ag.Tag,Line:BC.Line,Path:jC.Path,Rect:qC.Rect,RegularPolygon:WC.RegularPolygon,Ring:KC.Ring,Sprite:YC.Sprite,Star:zC.Star,Text:XC.Text,TextPath:JC.TextPath,Transformer:QC.Transformer,Wedge:ZC.Wedge,Filters:{Blur:eA.Blur,Brighten:tA.Brighten,Contrast:sA.Contrast,Emboss:nA.Emboss,Enhance:iA.Enhance,Grayscale:rA.Grayscale,HSL:lA.HSL,HSV:aA.HSV,Invert:oA.Invert,Kaleidoscope:uA.Kaleidoscope,Mask:cA.Mask,Noise:hA.Noise,Pixelate:fA.Pixelate,Posterize:dA.Posterize,RGB:_A.RGB,RGBA:gA.RGBA,Sepia:pA.Sepia,Solarize:mA.Solarize,Threshold:vA.Threshold}});var TA=Hf.exports;Object.defineProperty(TA,"__esModule",{value:!0});const yA=wu;Hf.exports=yA.Konva;var SA=Hf.exports;const cr=nt(SA),Hh={STROKE_WIDTH:5,STROKE_COLOR:"#f32",EMPTY_DRAWER_RECT_COLOR:"#fff"};class Sf{constructor(e){this.stage=null,this.strokeWidth=Hh.STROKE_WIDTH,this.strokeColor=Hh.STROKE_COLOR,this.emptyDrawerRectColor=Hh.EMPTY_DRAWER_RECT_COLOR,this.emptyDrawerRect=null;const{container:t,width:r,height:l}=e,s=new cr.Stage({container:t,width:r,height:l});this.stage=s,this.setupDrawerOptions(e)}setupDrawerOptions(e){e.strokeWidth&&(this.strokeWidth=e.strokeWidth),e.strokeColor&&(this.strokeColor=e.strokeColor),e.emptyDrawerRectColor&&(this.emptyDrawerRectColor=e.emptyDrawerRectColor,this.emptyDrawerRect&&this.emptyDrawerRect.fill(e.emptyDrawerRectColor))}addLayer(){const e=new cr.Layer;return this.stage.add(e),e}initFreeDrawing(e){let t=!1,r;this.stage.on("mousedown touchstart",l=>{t=!0;const s=this.stage.getPointerPosition();r=new cr.Line({stroke:this.strokeColor,strokeWidth:this.strokeWidth,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[s.x,s.y,s.x,s.y]}),e.add(r)}),this.stage.on("mouseup touchend",()=>{t=!1}),this.stage.on("mousemove touchmove",l=>{if(!t)return;l.evt.preventDefault();const s=this.stage.getPointerPosition(),i=r.points().concat([s.x,s.y]);r.points(i)})}addRect(e,t,r){const l=new cr.Rect({width:t,height:r,fill:this.emptyDrawerRectColor});return e.add(l),this.emptyDrawerRect=l,l}addImage(e,t){let r,l;const s=t.width/t.height;this.stage.width()<t.width?(r=this.stage.width(),l=this.stage.width()/s):(r=t.width,l=t.width/s);const i=new cr.Image({image:t,x:(this.stage.width()-r)/2,y:(this.stage.height()-l)/2,width:r,height:l});return e.add(i),i}addWakeupLine(e){const t=new cr.Line({stroke:"#ffffff",strokeWidth:1,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[0,0,0,0]});e.add(t)}}class td extends Sp{constructor(e,t,r={}){super(e),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=r.immediate||!1,this.type=t}start(e){return e}stop(){throw new Error("stop method is not implemented")}async process(e){if(this.immediate){const t=await this.start(e);return this.running=!0,t}return e}async connect(){this.running=!0,await this.session.resyncPlugins(this.type)}terminate(){this.stop()}async kill(){this.stop(),this.running=!1,await this.session.resyncPlugins(this.type)}}const EA={container:"screen-share-video-container",compositeCanvasContainer:"composite-canvas-container",compositeCanvas:"composite-canvas",drawerContainer:"container",videoElement:"whiteboard-source-video",videoElementContainer:"whiteboard-wrapper"};class CA extends td{constructor(e,t={}){super("ScreenShareWhiteboard","screen"),this.video=null,this.wrapperEl=null,this.screenShareKonvaDrawer=null,this.initialStream=null,this.imageSrc=null,this.konvaDrawer=null,this.mode=void 0,this.screenSharePlugin=null,this.selectors={},this.screenSharePlugin=e,this.selectors={...EA,...t.selectors||{}},this.selectors.document||(this.selectors.document=document)}createVideoElement(){const e=document.createElement("video");e.setAttribute("id",this.selectors.videoElement),e.setAttribute("autoplay",""),e.style.setProperty("visibility","hidden"),e.style.setProperty("width","auto"),e.style.setProperty("height","auto"),this.video=e;const t=document.createElement("div");t.classList.add(this.selectors.videoElementContainer),t.style.setProperty("display","none"),t.appendChild(e),this.wrapperEl=t,this.selectors.document.body?this.selectors.document.body.appendChild(t):this.selectors.document.appendChild(t)}getAspectRatioDimensions(e,t){const r=e.getTracks()[0].getSettings(),l=t.clientWidth,s=t.clientHeight,i=r.width,f=r.height,h=i/f,d=l/s;let p=0,v=0;return h>d?(p=l,v=l/h):(v=s,p=s*h),{width:p,height:v}}async start(e){this.createVideoElement(),this.initialStream=e,this.video.srcObject=e.clone();const t=this.selectors.document.getElementById(this.selectors.container);t.style.setProperty("position","relative"),t.style.setProperty("min-width","100%"),t.style.setProperty("height","100%"),t.style.setProperty("display","flex"),t.style.setProperty("justify-content","center");const r=this.selectors.document.getElementById(this.selectors.compositeCanvasContainer);r.style.setProperty("position","relative"),r.style.setProperty("margin","auto 0");const{width:l,height:s}=this.getAspectRatioDimensions(e,t);let i=l,f=s;const h=this.selectors.document.getElementById(this.selectors.drawerContainer);this.screenShareKonvaDrawer=new Sf({container:h,width:i,height:f});const d=this.screenShareKonvaDrawer.addLayer();this.screenShareKonvaDrawer.initFreeDrawing(d);const p=this.selectors.document.getElementById(this.selectors.drawerContainer),v=p.querySelector("canvas"),T=p.querySelector(".konvajs-content"),y=this.selectors.document.getElementById(this.selectors.compositeCanvas);y.style.setProperty("position","absolute"),y.style.setProperty("top","0"),y.style.setProperty("left","0");const S=y.getContext("2d"),A=()=>{const{width:N,height:C}=this.getAspectRatioDimensions(e,t);i=N,f=C,v.width=N,v.height=C,v.style.width=`${N}px`,v.style.height=`${C}px`,T.style.width=`${N}px`,T.style.height=`${C}px`,r.style.height=`${C}px`,y.width=N,y.height=C};A(),window.addEventListener("resize",()=>{A(),this.screenShareKonvaDrawer.addWakeupLine(d)});const R=this.video,O=()=>{S.drawImage(R,0,0,i,f),S.drawImage(v,0,0,i,f),requestAnimationFrame(O)};return O(),y.captureStream(30)}stop(){this.initialStream=null,this.video=null,this.wrapperEl=null,this.screenShareKonvaDrawer=null}setupScreenShareDrawerOptions(e){this.screenShareKonvaDrawer&&this.screenShareKonvaDrawer.setupDrawerOptions(e)}}function AA(u){return new Promise((e,t)=>{const r=new Image;r.onload=()=>{e(r)},r.onerror=l=>{t(l)},r.src=u})}const bg={WHITEBOARD:"whiteboard",IMAGE_WHITEBOARD:"imageWhiteboard"},bA={container:"presentation-video-container",drawerContainer:"presentationCanvasWrapper"};class RA extends Ru{constructor(e){super("WhiteBoard"),this.visualizationConfig={},this.rafId=null,this.imageSrc=null,this.konvaDrawer=null,this.selectors={},this.mode=void 0,this.mode=e.mode,e.imageSrc&&(this.imageSrc=e.imageSrc),this.selectors={...bA,...e.selectors||{}},this.selectors.document||(this.selectors.document=document)}setupDrawerOptions(e){this.konvaDrawer&&this.konvaDrawer.setupDrawerOptions(e)}setMode(e,t){this.mode=e,t&&(this.imageSrc=t)}setupDrawerImage(e){this.imageSrc=e}drawEmptyWhiteboard(){const e=this.selectors.document.getElementById(this.selectors.container);e.style.setProperty("min-width","100%"),e.style.setProperty("height","100%");const t=e.clientWidth,r=e.clientHeight,l=this.selectors.document.getElementById(this.selectors.drawerContainer);this.konvaDrawer=new Sf({container:l,width:t,height:r});const s=this.konvaDrawer.addLayer();this.konvaDrawer.addRect(s,t,r),this.konvaDrawer.initFreeDrawing(s)}async drawImageWhiteboard(){const e=this.selectors.document.getElementById(this.selectors.container);e.style.setProperty("min-width","100%"),e.style.setProperty("height","100%");const t=e.clientWidth,r=e.clientHeight,l=await AA(this.imageSrc),s=this.selectors.document.getElementById(this.selectors.drawerContainer);this.konvaDrawer=new Sf({container:s,width:t,height:r});const i=this.konvaDrawer.addLayer();this.konvaDrawer.addImage(i,l),i.batchDraw(),this.konvaDrawer.initFreeDrawing(i)}async generateStream(){if(this.mode===bg.WHITEBOARD)this.drawEmptyWhiteboard();else if(this.mode===bg.IMAGE_WHITEBOARD)await this.drawImageWhiteboard();else return;const t=this.selectors.document.getElementById(this.selectors.drawerContainer).querySelector("canvas"),r=t.getContext("2d");function l(){r.fillRect(0,0,1,1),requestAnimationFrame(l)}l();const s=t.captureStream(30);this.stream=s}async kill(){this.konvaDrawer=null,await this.stop(),this.session._ua.emit("stopWhiteboard")}}const wA=At,IA=ys(),Yt=new wA("WebSocketInterface");var OA=class{constructor(e){Yt.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;const t=IA.parse(e,"absoluteURI");if(t===-1)throw Yt.warn(`invalid WebSocket URI: ${e}`),new TypeError(`Invalid argument: ${e}`);if(t.scheme!=="wss"&&t.scheme!=="ws")throw Yt.warn(`invalid WebSocket URI scheme: ${t.scheme}`),new TypeError(`Invalid argument: ${e}`);this._sip_uri=`sip:${t.host}${t.port?`:${t.port}`:""};transport=ws`,this._via_transport=t.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(e){this._via_transport=e.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Yt.debug("connect()"),this.isConnected()){Yt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Yt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Yt.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(e){this._onError(e)}}disconnect(){Yt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(e){return Yt.debug("send()"),this.isConnected()?(this._ws.send(e),!0):(Yt.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(){Yt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:e,code:t,reason:r}){Yt.debug(`WebSocket ${this._url} closed`),e===!1&&Yt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!e,t,r)}_onMessage({data:e}){Yt.debug("received WebSocket message"),this.ondata(e)}_onError(e){Yt.warn(`WebSocket ${this._url} error: `,e)}};const Ef=vu,DA=Ue,NA=Js,PA=Ht(),xA=Tp,kA=Xs(),MA=xf(),UA=ys(),LA=OA,FA=yr("JsSIP");FA("version %s",Ef.version);var $A={C:DA,Exceptions:NA,Utils:PA,UA:xA,URI:kA,NameAddrHeader:MA,WebSocketInterface:LA,Grammar:UA,debug:yr,get name(){return Ef.title},get version(){return Ef.version}};const HA=nt($A);function Gh(u){return u<10?`0${u}`:`${u}`}function GA(u){let e=u.hours||0,t=u.minutes||0,r=u.seconds||0;r++,r===60&&(r=0,t++,t===60&&(t=0,e++));const l=`${Gh(e)}:${Gh(t)}:${Gh(r)}`;return{seconds:r,minutes:t,hours:e,formatted:l}}var Gt={};Gt.forEach=async(u,e,t)=>{const r=[];for(let l=0;l<u.length;l++)if(l in u){const s=Promise.resolve(u[l]).then(i=>e.call(t||globalThis,i,l,u));r.push(s)}await Promise.all(r)};Gt.forEachSeries=async(u,e,t)=>{for(let r=0;r<u.length;r++)r in u&&await e.call(t||globalThis,await u[r],r,u)};Gt.map=async(u,e,t)=>{const r=[];for(let l=0;l<u.length;l++)l in u&&(r[l]=Promise.resolve(u[l]).then(s=>e.call(t||globalThis,s,l,u)));return Promise.all(r)};Gt.mapSeries=async(u,e,t)=>{const r=[];for(let l=0;l<u.length;l++)l in u&&(r[l]=await e.call(t||globalThis,await u[l],l,u));return r};Gt.find=(u,e,t)=>new Promise((r,l)=>{if(u.length===0)return r();let s=1;for(let i=0;i<u.length;i++){const f=h=>{h?r(u[i]):s===u.length&&r(),s++};Promise.resolve(u[i]).then(h=>e.call(t||globalThis,h,i,u)).then(f).catch(l)}});Gt.findSeries=async(u,e,t)=>{for(let r=0;r<u.length;r++)if(await e.call(t||globalThis,await u[r],r,u))return u[r]};Gt.findIndex=(u,e,t)=>new Promise((r,l)=>{if(u.length===0)return r(-1);let s=1;for(let i=0;i<u.length;i++){const f=h=>{h?r(i):s===u.length&&r(-1),s++};Promise.resolve(u[i]).then(h=>e.call(t||globalThis,h,i,u)).then(f).catch(l)}});Gt.findIndexSeries=async(u,e,t)=>{for(let r=0;r<u.length;r++)if(await e.call(t||globalThis,await u[r],r,u))return r};Gt.some=(u,e,t)=>new Promise((r,l)=>{if(u.length===0)return r(!1);let s=1;for(let i=0;i<u.length;i++){if(!(i in u)){s++;continue}const f=h=>{h?r(!0):s===u.length&&r(!1),s++};Promise.resolve(u[i]).then(h=>e.call(t||globalThis,h,i,u)).then(f).catch(l)}});Gt.someSeries=async(u,e,t)=>{for(let r=0;r<u.length;r++)if(r in u&&await e.call(t||globalThis,await u[r],r,u))return!0;return!1};Gt.every=(u,e,t)=>new Promise((r,l)=>{if(u.length===0)return r(!0);let s=1;for(let i=0;i<u.length;i++){if(!(i in u)){s++;continue}const f=h=>{h?s===u.length&&r(!0):r(!1),s++};Promise.resolve(u[i]).then(h=>e.call(t||globalThis,h,i,u)).then(f).catch(l)}});Gt.everySeries=async(u,e,t)=>{for(let r=0;r<u.length;r++)if(r in u&&!await e.call(t||globalThis,await u[r],r,u))return!1;return!0};Gt.filter=(u,e,t)=>new Promise(async(r,l)=>{const s=[];for(let f=0;f<u.length;f++)f in u&&(s[f]=Promise.resolve(u[f]).then(h=>e.call(t||globalThis,h,f,u)).catch(l));const i=[];for(let f=0;f<s.length;f++)await s[f]&&i.push(await u[f]);r(i)});Gt.filterSeries=async(u,e,t)=>{const r=[];for(let l=0;l<u.length;l++)l in u&&await e.call(t||globalThis,await u[l],l,u)&&r.push(await u[l]);return r};Gt.reduce=async(u,e,t)=>{if(u.length===0&&t===void 0)throw TypeError("Reduce of empty array with no initial value");let r,l;for(t!==void 0?(l=t,r=0):(l=u[0],r=1),r;r<u.length;r++)r in u&&(l=await e(await l,await u[r],r,u));return l};var i0={};(function(u){const e=Gt;Object.keys(e).forEach(t=>{const r=t.charAt(0).toUpperCase()+t.slice(1);u[`async${r}`]=async function(...l){return e[t](this,...l)}})})(i0);const VA=Gt,BA=i0;var jA=Object.assign(VA,{instanceMethods:BA});const fi=new AudioContext,ms={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var qA={exports:{}};(function(u){var e=function(t){var r=Object.prototype,l=r.hasOwnProperty,s=Object.defineProperty||function(ee,j,K){ee[j]=K.value},i,f=typeof Symbol=="function"?Symbol:{},h=f.iterator||"@@iterator",d=f.asyncIterator||"@@asyncIterator",p=f.toStringTag||"@@toStringTag";function v(ee,j,K){return Object.defineProperty(ee,j,{value:K,enumerable:!0,configurable:!0,writable:!0}),ee[j]}try{v({},"")}catch{v=function(j,K,ie){return j[K]=ie}}function T(ee,j,K,ie){var ue=j&&j.prototype instanceof C?j:C,Ce=Object.create(ue.prototype),ke=new V(ie||[]);return s(Ce,"_invoke",{value:U(ee,K,ke)}),Ce}t.wrap=T;function y(ee,j,K){try{return{type:"normal",arg:ee.call(j,K)}}catch(ie){return{type:"throw",arg:ie}}}var S="suspendedStart",A="suspendedYield",R="executing",O="completed",N={};function C(){}function b(){}function w(){}var F={};v(F,h,function(){return this});var q=Object.getPrototypeOf,D=q&&q(q(J([])));D&&D!==r&&l.call(D,h)&&(F=D);var P=w.prototype=C.prototype=Object.create(F);b.prototype=w,s(P,"constructor",{value:w,configurable:!0}),s(w,"constructor",{value:b,configurable:!0}),b.displayName=v(w,p,"GeneratorFunction");function I(ee){["next","throw","return"].forEach(function(j){v(ee,j,function(K){return this._invoke(j,K)})})}t.isGeneratorFunction=function(ee){var j=typeof ee=="function"&&ee.constructor;return j?j===b||(j.displayName||j.name)==="GeneratorFunction":!1},t.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,w):(ee.__proto__=w,v(ee,p,"GeneratorFunction")),ee.prototype=Object.create(P),ee},t.awrap=function(ee){return{__await:ee}};function x(ee,j){function K(Ce,ke,be,M){var Y=y(ee[Ce],ee,ke);if(Y.type==="throw")M(Y.arg);else{var Ee=Y.arg,Me=Ee.value;return Me&&typeof Me=="object"&&l.call(Me,"__await")?j.resolve(Me.__await).then(function(fe){K("next",fe,be,M)},function(fe){K("throw",fe,be,M)}):j.resolve(Me).then(function(fe){Ee.value=fe,be(Ee)},function(fe){return K("throw",fe,be,M)})}}var ie;function ue(Ce,ke){function be(){return new j(function(M,Y){K(Ce,ke,M,Y)})}return ie=ie?ie.then(be,be):be()}s(this,"_invoke",{value:ue})}I(x.prototype),v(x.prototype,d,function(){return this}),t.AsyncIterator=x,t.async=function(ee,j,K,ie,ue){ue===void 0&&(ue=Promise);var Ce=new x(T(ee,j,K,ie),ue);return t.isGeneratorFunction(j)?Ce:Ce.next().then(function(ke){return ke.done?ke.value:Ce.next()})};function U(ee,j,K){var ie=S;return function(Ce,ke){if(ie===R)throw new Error("Generator is already running");if(ie===O){if(Ce==="throw")throw ke;return Pe()}for(K.method=Ce,K.arg=ke;;){var be=K.delegate;if(be){var M=B(be,K);if(M){if(M===N)continue;return M}}if(K.method==="next")K.sent=K._sent=K.arg;else if(K.method==="throw"){if(ie===S)throw ie=O,K.arg;K.dispatchException(K.arg)}else K.method==="return"&&K.abrupt("return",K.arg);ie=R;var Y=y(ee,j,K);if(Y.type==="normal"){if(ie=K.done?O:A,Y.arg===N)continue;return{value:Y.arg,done:K.done}}else Y.type==="throw"&&(ie=O,K.method="throw",K.arg=Y.arg)}}}function B(ee,j){var K=j.method,ie=ee.iterator[K];if(ie===i)return j.delegate=null,K==="throw"&&ee.iterator.return&&(j.method="return",j.arg=i,B(ee,j),j.method==="throw")||K!=="return"&&(j.method="throw",j.arg=new TypeError("The iterator does not provide a '"+K+"' method")),N;var ue=y(ie,ee.iterator,j.arg);if(ue.type==="throw")return j.method="throw",j.arg=ue.arg,j.delegate=null,N;var Ce=ue.arg;if(!Ce)return j.method="throw",j.arg=new TypeError("iterator result is not an object"),j.delegate=null,N;if(Ce.done)j[ee.resultName]=Ce.value,j.next=ee.nextLoc,j.method!=="return"&&(j.method="next",j.arg=i);else return Ce;return j.delegate=null,N}I(P),v(P,p,"Generator"),v(P,h,function(){return this}),v(P,"toString",function(){return"[object Generator]"});function z(ee){var j={tryLoc:ee[0]};1 in ee&&(j.catchLoc=ee[1]),2 in ee&&(j.finallyLoc=ee[2],j.afterLoc=ee[3]),this.tryEntries.push(j)}function L(ee){var j=ee.completion||{};j.type="normal",delete j.arg,ee.completion=j}function V(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(z,this),this.reset(!0)}t.keys=function(ee){var j=Object(ee),K=[];for(var ie in j)K.push(ie);return K.reverse(),function ue(){for(;K.length;){var Ce=K.pop();if(Ce in j)return ue.value=Ce,ue.done=!1,ue}return ue.done=!0,ue}};function J(ee){if(ee){var j=ee[h];if(j)return j.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var K=-1,ie=function ue(){for(;++K<ee.length;)if(l.call(ee,K))return ue.value=ee[K],ue.done=!1,ue;return ue.value=i,ue.done=!0,ue};return ie.next=ie}}return{next:Pe}}t.values=J;function Pe(){return{value:i,done:!0}}return V.prototype={constructor:V,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=i,this.done=!1,this.delegate=null,this.method="next",this.arg=i,this.tryEntries.forEach(L),!ee)for(var j in this)j.charAt(0)==="t"&&l.call(this,j)&&!isNaN(+j.slice(1))&&(this[j]=i)},stop:function(){this.done=!0;var ee=this.tryEntries[0],j=ee.completion;if(j.type==="throw")throw j.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var j=this;function K(M,Y){return Ce.type="throw",Ce.arg=ee,j.next=M,Y&&(j.method="next",j.arg=i),!!Y}for(var ie=this.tryEntries.length-1;ie>=0;--ie){var ue=this.tryEntries[ie],Ce=ue.completion;if(ue.tryLoc==="root")return K("end");if(ue.tryLoc<=this.prev){var ke=l.call(ue,"catchLoc"),be=l.call(ue,"finallyLoc");if(ke&&be){if(this.prev<ue.catchLoc)return K(ue.catchLoc,!0);if(this.prev<ue.finallyLoc)return K(ue.finallyLoc)}else if(ke){if(this.prev<ue.catchLoc)return K(ue.catchLoc,!0)}else if(be){if(this.prev<ue.finallyLoc)return K(ue.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,j){for(var K=this.tryEntries.length-1;K>=0;--K){var ie=this.tryEntries[K];if(ie.tryLoc<=this.prev&&l.call(ie,"finallyLoc")&&this.prev<ie.finallyLoc){var ue=ie;break}}ue&&(ee==="break"||ee==="continue")&&ue.tryLoc<=j&&j<=ue.finallyLoc&&(ue=null);var Ce=ue?ue.completion:{};return Ce.type=ee,Ce.arg=j,ue?(this.method="next",this.next=ue.finallyLoc,N):this.complete(Ce)},complete:function(ee,j){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"&&j&&(this.next=j),N},finish:function(ee){for(var j=this.tryEntries.length-1;j>=0;--j){var K=this.tryEntries[j];if(K.finallyLoc===ee)return this.complete(K.completion,K.afterLoc),L(K),N}},catch:function(ee){for(var j=this.tryEntries.length-1;j>=0;--j){var K=this.tryEntries[j];if(K.tryLoc===ee){var ie=K.completion;if(ie.type==="throw"){var ue=ie.arg;L(K)}return ue}}throw new Error("illegal catch attempt")},delegateYield:function(ee,j,K){return this.delegate={iterator:J(ee),resultName:j,nextLoc:K},this.method==="next"&&(this.arg=i),N}},t}(u.exports);try{regeneratorRuntime=e}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})(qA);var r0={exports:{}};(function(u){(function(e,t){u.exports?u.exports=t():e.log=t()})(Wh,function(){var e=function(){},t="undefined",r=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),l=["trace","debug","info","warn","error"];function s(A,R){var O=A[R];if(typeof O.bind=="function")return O.bind(A);try{return Function.prototype.bind.call(O,A)}catch{return function(){return Function.prototype.apply.apply(O,[A,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function f(A){return A==="debug"&&(A="log"),typeof console===t?!1:A==="trace"&&r?i:console[A]!==void 0?s(console,A):console.log!==void 0?s(console,"log"):e}function h(A,R){for(var O=0;O<l.length;O++){var N=l[O];this[N]=O<A?e:this.methodFactory(N,A,R)}this.log=this.debug}function d(A,R,O){return function(){typeof console!==t&&(h.call(this,R,O),this[A].apply(this,arguments))}}function p(A,R,O){return f(A)||d.apply(this,arguments)}function v(A,R,O){var N=this,C;R=R??"WARN";var b="loglevel";typeof A=="string"?b+=":"+A:typeof A=="symbol"&&(b=void 0);function w(P){var I=(l[P]||"silent").toUpperCase();if(!(typeof window===t||!b)){try{window.localStorage[b]=I;return}catch{}try{window.document.cookie=encodeURIComponent(b)+"="+I+";"}catch{}}}function F(){var P;if(!(typeof window===t||!b)){try{P=window.localStorage[b]}catch{}if(typeof P===t)try{var I=window.document.cookie,x=I.indexOf(encodeURIComponent(b)+"=");x!==-1&&(P=/^([^;]+)/.exec(I.slice(x))[1])}catch{}return N.levels[P]===void 0&&(P=void 0),P}}function q(){if(!(typeof window===t||!b)){try{window.localStorage.removeItem(b);return}catch{}try{window.document.cookie=encodeURIComponent(b)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}N.name=A,N.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},N.methodFactory=O||p,N.getLevel=function(){return C},N.setLevel=function(P,I){if(typeof P=="string"&&N.levels[P.toUpperCase()]!==void 0&&(P=N.levels[P.toUpperCase()]),typeof P=="number"&&P>=0&&P<=N.levels.SILENT){if(C=P,I!==!1&&w(P),h.call(N,P,A),typeof console===t&&P<N.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+P},N.setDefaultLevel=function(P){R=P,F()||N.setLevel(P,!1)},N.resetLevel=function(){N.setLevel(R,!1),q()},N.enableAll=function(P){N.setLevel(N.levels.TRACE,P)},N.disableAll=function(P){N.setLevel(N.levels.SILENT,P)};var D=F();D==null&&(D=R),N.setLevel(D,!1)}var T=new v,y={};T.getLogger=function(R){if(typeof R!="symbol"&&typeof R!="string"||R==="")throw new TypeError("You must supply a name when creating a logger.");var O=y[R];return O||(O=y[R]=new v(R,T.getLevel(),T.methodFactory)),O};var S=typeof window!==t?window.log:void 0;return T.noConflict=function(){return typeof window!==t&&window.log===T&&(window.log=S),T},T.getLoggers=function(){return y},T.default=T,T})})(r0);var Bt=r0.exports;const Ks=()=>`${new Date().toISOString()} | metrics`,Ys=(u,e,t)=>`${u} | ${e} | ${t}`;Bt.setDefaultLevel(Bt.levels.TRACE);const WA=u=>{Bt.info(Ys(Ks(),"log ",`set log level to ${u?"verbose":"info"}`)),Bt.setLevel(u?Bt.levels.TRACE:Bt.levels.INFO)},KA=u=>{const e=[...Object.keys(Bt.levels)];e.includes(u)?(Bt.info(Ys(Ks(),"log ",`update log level to ${u.toLowerCase()}`)),Bt.setLevel(u)):Bt.warn(Ys(Ks(),"log ","Incorrect log level please choose one of "),e)},Be=(u,e,t)=>{t?Bt.debug(Ys(Ks(),u,e),t):Bt.debug(Ys(Ks(),u,e))},Vh=(u,e)=>{Bt.info(Ys(Ks(),u,e))},di=(u,e)=>{Bt.info(Ys(Ks(),u,e))},nu=(u,e)=>{Bt.warn(Ys(Ks(),u,e))},dr=(u,e)=>{Bt.error(Ys(Ks(),u,e))};function YA(u){return Math.floor(Math.random()*u).toString()}function Rg(u,e){let t=e;return u.forEach(r=>{t=t.replace(r,"")}),t}function zA(u,e){let t="";for(let r=0;r<e;r+=1)t+=u[YA(u.length)];return t}function XA({length:u=20,useLetters:e=!0,useNumbers:t=!0,includeSymbols:r=[],excludeSymbols:l=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",i="0123456789",f=[],h=[],d=[];return e&&(l.length&&(s=Rg(l,s)),h=s.split("")),t&&(l.length&&(i=Rg(l,i)),d=i.split("")),f=[...h,...d,...r],zA(f,u)}var JA=XA;const fa=nt(JA),QA=()=>"WebRTCMetrics",ZA=()=>"5.0.3",ze={INBOUND:"inbound",OUTBOUND:"outbound"},js={IDLE:"idle",RUNNING:"running",MUTED:"muted"},aa={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},eb=()=>({...{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:[]}}),l0={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:ze.INBOUND},a0={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:ze.OUTBOUND},o0={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:ze.INBOUND},u0={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:ze.OUTBOUND},tb=u=>{const e={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(u){const t={...u,audio:{},video:{},data:{...u.data},network:{...u.network},experimental:{...u.experimental}};return Object.keys(u.audio).forEach(r=>{t.audio[r]={...u.audio[r]}}),Object.keys(u.video).forEach(r=>{t.video[r]={...u.video[r]}}),t}return{...e,audio:{},video:{},data:{...e.data},network:{...e.network},experimental:{...e.experimental}}},sb={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${fa()}`,cid:`c-${fa()}`,uid:`u-${fa()}`,record:!1,ticket:!0},ps={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"},te={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},X={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},oa={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},Bh={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},he={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},jh="config ",nb=(u,e={},t)=>{const r={...t,...e};return e.pname||nu(jh,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${t.pname}'`),e.cid||nu(jh,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${t.cid}'`),e.uid||nu(jh,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${t.uid}'`),r.pc=u,r},ib=(u={})=>{const e={...sb,...u};return e.name=QA(),e.version=ZA(),e},La=(u,e,t,r=!1,l)=>{let s=u.map(i=>{if(!t)return i[e];if(!l)return i[e][t];const f=i[e][l];return f?f[t]:null});return s=s.filter(i=>r?Number.isFinite(i)&&i>0:Number.isFinite(i)),s.length===0?[]:s},wn=u=>u.reduce((e,t)=>e+t,0)/u.length,rb=()=>`probe-${fa()}`,lb=()=>`coltr-${fa()}`,wg=u=>new Promise(e=>setTimeout(e,u)),Cf=(u,e,t)=>{e?u.call(e,t):u(t)},at=(u,e,t,r)=>{const l=La(u,e,t,!0,r);if(l.length===0)return null;const s=l.reduce((d,p)=>d+p,0)/l.length;return s===0?null:l.map(d=>Math.abs(s-d)).reduce((d,p)=>d+p,0)/l.length*100/s},ht=(u,e,t,r=!1,l)=>{const s=La(u,e,t,r,l);return s.length===0?null:s.reduce((i,f)=>i+f,0)/s.length},ui=(u,e,t)=>La(u,e,t).reduce((l,s)=>l+s,0),ot=(u,e,t,r)=>{const l=La(u,e,t,!0,r);return l.length===0?null:Math.min(...l)},ut=(u,e,t,r)=>{const l=La(u,e,t,!1,r);return l.length===0?null:Math.max(...l)},kt=(u,e,t,r)=>{const l=u.slice().pop();if(!l)return null;if(!t)return l[e];if(!r)return l[e][t];const s=l[e][r];return s?s[t]:null},ab=u=>u.slice().pop(),wt=(u,e,t)=>{if(!e)return null;const r={};let l=e[X.AUDIO][u];l||(l=t===ze.INBOUND?{...l0}:{...a0}),r[X.AUDIO]=l;let s=e[X.VIDEO][u];return s||(s=t===ze.INBOUND?{...o0}:{...u0}),r[X.VIDEO]=s,r},ua="exporter ",ob="2.0",Ig=(u,e,t)=>{if(!u||u.length===0)return 0;const r=u[u.length-1];if(!r)return 0;const l=r[e][t];if(l){const s=l.total_rtt_ms_out,i=l.total_rtt_measure_out;return!i||!s?ht(u,e,"delta_rtt_ms_out",!1,t):Number(s/i)}return null},ub=(u,e)=>{if(!u||u.length===0)return 0;const t=u[u.length-1];if(!t)return 0;const r=t[e].total_rtt_connectivity_ms,l=t[e].total_rtt_connectivity_measure;return!l||!r?ht(u,e,"delta_rtt_connectivity_ms"):Number(r/l)},cb=u=>kt(u,"network","local_candidate_type")!=="relay"?`direct/${kt(u,"network","local_candidate_protocol")}`:`turn/${kt(u,"network","local_candidate_relay_protocol")}`,hb=u=>{const e=kt(u,"network","remote_candidate_type"),t=kt(u,"network","remote_candidate_protocol");return e!=="relay"?`direct/${t}`:`turn/${t}`};class fb{constructor(e){this._start=null,this._end=null,this._cfg=e,this._referenceReport=null,this._reports=[],this._events=[]}start(){Vh(ua,"start() - start exporter...");const e=new Date;return this._start=e.toJSON(),e}stop(){Vh(ua,"stop() - stop exporter...");const e=new Date;return this._end=e.toJSON(),e}saveReferenceReport(e){this._referenceReport=e}getReferenceReport(){return this._referenceReport}addReport(e){this._cfg.ticket&&(Be(ua,`addReport() - add report to exporter at ${e.timestamp}`),this._reports.push(e))}addCustomEvent(e){this._events.push(e)}reset(){Vh(ua,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Be(ua,"ticket() - generate ticket");const e=kt(this._reports,"audio","total_packets_lost_in"),t=kt(this._reports,"audio","total_packets_in"),r=kt(this._reports,"video","total_packets_lost_in"),l=kt(this._reports,"video","total_packets_in"),s={},i=ab(this._reports);return i&&(Object.keys(i[X.AUDIO]).forEach(f=>{const h=i[X.AUDIO][f];if(s[h.ssrc]={type:X.AUDIO,direction:h.direction},h.direction===ze.INBOUND){const d={avg:ht(this._reports,X.AUDIO,"delta_jitter_ms_in",!1,f),min:ot(this._reports,X.AUDIO,"delta_jitter_ms_in",f),max:ut(this._reports,X.AUDIO,"delta_jitter_ms_in",f),volatility:at(this._reports,X.AUDIO,"delta_jitter_ms_in",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:ht(this._reports,X.AUDIO,"delta_kbs_in",!1,f),min:ot(this._reports,X.AUDIO,"delta_kbs_in",f),max:ut(this._reports,X.AUDIO,"delta_kbs_in",f),volatility:at(this._reports,X.AUDIO,"delta_kbs_in",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:ht(this._reports,X.AUDIO,"delta_KBytes_in",!1,f),min:ot(this._reports,X.AUDIO,"delta_KBytes_in",f),max:ut(this._reports,X.AUDIO,"delta_KBytes_in",f),volatility:at(this._reports,X.AUDIO,"delta_KBytes_in",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T={emodel:{avg:ht(this._reports,X.AUDIO,"mos_emodel_in",!1,f),min:ot(this._reports,X.AUDIO,"mos_emodel_in",f),max:ut(this._reports,X.AUDIO,"mos_emodel_in",f),volatility:at(this._reports,X.AUDIO,"mos_emodel_in",f)},effective:{avg:ht(this._reports,X.AUDIO,"mos_in",!1,f),min:ot(this._reports,X.AUDIO,"mos_in",f),max:ut(this._reports,X.AUDIO,"mos_in",f),volatility:at(this._reports,X.AUDIO,"mos_in",f)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=kt(this._reports,X.AUDIO,"total_packets_lost_in",f),S=kt(this._reports,X.AUDIO,"total_packets_in",f),A={lost:y,avg:Math.round((y/(y+S)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[f].jitter=d,s[f].mos=T,s[f].traffic=v,s[f].bitrate=p,s[f].loss=A}else{const d={avg:ht(this._reports,X.AUDIO,"delta_jitter_ms_out",!1,f),min:ot(this._reports,X.AUDIO,"delta_jitter_ms_out",f),max:ut(this._reports,X.AUDIO,"delta_jitter_ms_out",f),volatility:at(this._reports,X.AUDIO,"delta_jitter_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:ht(this._reports,X.AUDIO,"delta_kbs_out",!1,f),min:ot(this._reports,X.AUDIO,"delta_kbs_out",f),max:ut(this._reports,X.AUDIO,"delta_kbs_out",f),volatility:at(this._reports,X.AUDIO,"delta_kbs_out",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:ht(this._reports,X.AUDIO,"delta_KBytes_out",!1,f),min:ot(this._reports,X.AUDIO,"delta_KBytes_out",f),max:ut(this._reports,X.AUDIO,"delta_KBytes_out",f),volatility:at(this._reports,X.AUDIO,"delta_KBytes_out",f),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},T={avg:Ig(this._reports,X.AUDIO,f),min:ot(this._reports,X.AUDIO,"delta_rtt_ms_out",f),max:ut(this._reports,X.AUDIO,"delta_rtt_ms_out",f),volatility:at(this._reports,X.AUDIO,"delta_rtt_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=kt(this._reports,X.AUDIO,"total_packets_lost_out",f),S=kt(this._reports,X.AUDIO,"total_packets_out",f),A={lost:y,avg:Math.round((y/(y+S)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},R={emodel:{avg:ht(this._reports,X.AUDIO,"mos_emodel_out",!1,f),min:ot(this._reports,X.AUDIO,"mos_emodel_out",f),max:ut(this._reports,X.AUDIO,"mos_emodel_out",f),volatility:at(this._reports,X.AUDIO,"mos_emodel_out",f)},effective:{avg:ht(this._reports,X.AUDIO,"mos_out",!1,f),min:ot(this._reports,X.AUDIO,"mos_out",f),max:ut(this._reports,X.AUDIO,"mos_out",f),volatility:at(this._reports,X.AUDIO,"mos_out",f)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[f].jitter=d,s[f].rtt=T,s[f].traffic=v,s[f].bitrate=p,s[f].loss=A,s[f].mos=R}}),Object.keys(i[X.VIDEO]).forEach(f=>{const h=i[X.VIDEO][f];if(s[f]={type:X.VIDEO,direction:h.direction},h.direction===ze.INBOUND){const d={avg:ht(this._reports,X.VIDEO,"delta_jitter_ms_in",!1,f),min:ot(this._reports,X.VIDEO,"delta_jitter_ms_in",f),max:ut(this._reports,X.VIDEO,"delta_jitter_ms_in",f),volatility:at(this._reports,X.VIDEO,"delta_jitter_ms_in",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:ht(this._reports,X.VIDEO,"delta_kbs_in",!1,f),min:ot(this._reports,X.VIDEO,"delta_kbs_in",f),max:ut(this._reports,X.VIDEO,"delta_kbs_in",f),volatility:at(this._reports,X.VIDEO,"delta_kbs_in",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:ht(this._reports,X.VIDEO,"delta_KBytes_in",!1,f),min:ot(this._reports,X.VIDEO,"delta_KBytes_in",f),max:ut(this._reports,X.VIDEO,"delta_KBytes_in",f),volatility:at(this._reports,X.VIDEO,"delta_KBytes_in",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T=kt(this._reports,X.VIDEO,"total_packets_lost_in",f),y=kt(this._reports,X.VIDEO,"total_packets_in",f),S={lost:T,avg:Math.round((T/(T+y)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[f].jitter=d,s[f].traffic=v,s[f].bitrate=p,s[f].loss=S}else{const d={avg:ht(this._reports,X.VIDEO,"delta_jitter_ms_out",!1,f),min:ot(this._reports,X.VIDEO,"delta_jitter_ms_out",f),max:ut(this._reports,X.VIDEO,"delta_jitter_ms_out",f),volatility:at(this._reports,X.VIDEO,"delta_jitter_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:ht(this._reports,X.VIDEO,"delta_kbs_out",!1,f),min:ot(this._reports,X.VIDEO,"delta_kbs_out",f),max:ut(this._reports,X.VIDEO,"delta_kbs_out",f),volatility:at(this._reports,X.VIDEO,"delta_kbs_out",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:ht(this._reports,X.VIDEO,"delta_KBytes_out",!1,f),min:ot(this._reports,X.VIDEO,"delta_KBytes_out",f),max:ut(this._reports,X.VIDEO,"delta_KBytes_out",f),volatility:at(this._reports,X.VIDEO,"delta_KBytes_out",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T={avg:Ig(this._reports,X.VIDEO,f),min:ot(this._reports,X.VIDEO,"delta_rtt_ms_out",f),max:ut(this._reports,X.VIDEO,"delta_rtt_ms_out",f),volatility:at(this._reports,X.VIDEO,"delta_rtt_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=kt(this._reports,X.VIDEO,"total_packets_lost_out",f),S=kt(this._reports,X.VIDEO,"total_packets_out",f),A={lost:y,avg:Math.round((y/(y+S)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[f].jitter=d,s[f].rtt=T,s[f].traffic=v,s[f].bitrate=p,s[f].loss=A}})),{version:ob,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:ub(this._reports,"data"),min:ot(this._reports,"data","delta_rtt_connectivity_ms"),max:ut(this._reports,"data","delta_rtt_connectivity_ms"),volatility:at(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((e/(e+t)*100||0)*100)/100}},video:{in:{avg:Math.round((r/(r+l)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:ht(this._reports,"data","delta_kbs_in"),min:ot(this._reports,"data","delta_kbs_in"),max:ut(this._reports,"data","delta_kbs_in"),volatility:at(this._reports,"data","delta_kbs_in")},out:{avg:ht(this._reports,"data","delta_kbs_out"),min:ot(this._reports,"data","delta_kbs_out"),max:ut(this._reports,"data","delta_kbs_out"),volatility:at(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:ht(this._reports,"data","delta_KBytes_in"),min:ot(this._reports,"data","delta_KBytes_in"),max:ut(this._reports,"data","delta_KBytes_in"),volatility:at(this._reports,"data","delta_KBytes_in")},out:{avg:ht(this._reports,"data","delta_KBytes_out"),min:ot(this._reports,"data","delta_KBytes_out"),max:ut(this._reports,"data","delta_KBytes_out"),volatility:at(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:cb(this._reports),remoteConnection:hb(this._reports)}}}}updateConfig(e){this._cfg=e}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const e=this._reports.slice();return e.pop(),e.pop()||null}getReportsNumber(){return this._reports.length}}const Sn="extractor ",Og=(u,e,t,r)=>{let l=!1;const s=r[e].total_rtt_ms_out,i=r[e].total_rtt_measure_out,f=t?t[e].total_rtt_ms_out:0,h=t?t[e].total_rtt_measure_out:0,d={rtt:null,totalRTT:s,totalRTTMeasurements:i};if(u[te.TIMESTAMP]===r[e].timestamp_out||!Object.prototype.hasOwnProperty.call(u,te.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(u,te.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(l=!0,Number(u[te.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(u[te.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===i))return d;const p=1e3*Number(u[te.ROUND_TRIP_TIME]);let v=s+p,T=i+1;return l&&(v=1e3*Number(u[te.TOTAL_ROUND_TRIP_TIME])-f,T=Number(u[te.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:p,totalRTT:v,totalRTTMeasurements:T}},db=(u,e,t,r)=>{if(!Object.prototype.hasOwnProperty.call(u,te.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:r[e].total_rtt_connectivity_ms,totalRTTMeasurements:r[e].total_rtt_connectivity_measure};const l=1e3*Number(u[te.CURRENT_ROUND_TRIP_TIME]);let s=r[e].total_rtt_connectivity_ms+l,i=r[e].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(u,te.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(u[te.TOTAL_ROUND_TRIP_TIME])-(t?t[e].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(u,te.RESPONSES_RECEIVED)&&(i=Number(u[te.RESPONSES_RECEIVED])-(t?t[e].total_rtt_connectivity_measure:0)),{rtt:l,totalRTT:s,totalRTTMeasurements:i}},Ho=(u,e,t)=>u[te.TIMESTAMP]===t[e].timestamp_out||!Object.prototype.hasOwnProperty.call(u,te.JITTER)?null:1e3*(Number(u[te.JITTER])||0),_b=(u,e)=>{if(!Object.prototype.hasOwnProperty.call(u,te.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(u,te.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:e[X.VIDEO].delta_ms_decode_frame_in,frames_decoded:e[X.VIDEO].total_frames_decoded_in,total_decode_time:e[X.VIDEO].total_time_decoded_in};const t=u[te.FRAMES_DECODED],r=u[te.TOTAL_DECODE_TIME],l=r-e[X.VIDEO].total_time_decoded_in,s=t-e[X.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?l*1e3/s:0,frames_decoded:t,total_decode_time:r}},gb=(u,e)=>{if(!Object.prototype.hasOwnProperty.call(u,te.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(u,te.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:e[X.VIDEO].delta_ms_encode_frame_out,frames_encoded:e[X.VIDEO].total_frames_encoded_out,total_encode_time:e[X.VIDEO].total_time_encoded_out};const t=u[te.FRAMES_ENCODED],r=u[te.TOTAL_ENCODE_TIME],l=r-e[X.VIDEO].total_time_encoded_out,s=t-e[X.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&l?l*1e3/s:0,frames_encoded:t,total_encode_time:r}},Dg=(u,e,t,r)=>{if(!Object.prototype.hasOwnProperty.call(u,te.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(u,te.BYTES_SENT))return{packetsSent:t[e].total_packets_out,packetsLost:t[e].total_packets_lost_out,bytesSent:t[e].total_KBytes_out};const l=Number(u[te.PACKETS_SENT])||0-(r?r[e].total_packets_out:0),s=l-t[e].total_packets_out,i=Number(u[te.BYTES_SENT])/1024-(r?r[e].total_KBytes_out:0),f=i-t[e].total_KBytes_out,h=u[te.TIMESTAMP]||Date.now(),d=r?r.timestamp:null;let p=t.timestamp;!p&&d&&(p=d);const v=p?h-p:0,T=v>0?f*.008*1024/v*1e3:0;return{packetsSent:l,deltaPacketsSent:s,KBytesSent:i,deltaKBytesSent:f,kbsSent:T}},Ng=(u,e,t,r)=>{let l=t[e].total_packets_lost_out,s=0,i=0;return Object.prototype.hasOwnProperty.call(u,te.PACKETS_LOST)&&(l=Number(u[te.PACKETS_LOST])||0-(r?r[e].total_packets_lost_out:0),s=l-t[e].total_packets_lost_out),Object.prototype.hasOwnProperty.call(u,te.FRACTION_LOST)&&(i=Number(100*u[te.FRACTION_LOST])),{packetsLost:l,deltaPacketsLost:s,fractionLost:i}},Pg=(u,e,t,r)=>{if(!Object.prototype.hasOwnProperty.call(u,te.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(u,te.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(u,te.BYTES_RECEIVED))return{percent_packets_lost:t[e].percent_packets_lost_in,packetsReceived:t[e].total_packets_in,packetsLost:t[e].total_packets_lost_in,bytesReceived:t[e].total_KBytes_in};const l=Number(u[te.PACKETS_RECEIVED])||0-(r?r[e].total_packets_in:0),s=Number(u[te.PACKETS_LOST])||0-(r?r[e].total_packets_lost_in:0),i=s-t[e].total_packets_lost_in,f=l-t[e].total_packets_in,h=l!==t[e].total_packets_in?i*100/(i+f):0,d=Number(u[te.BYTES_RECEIVED])/1024-(r?r[e].total_KBytes_in:0),p=d-t[e].total_KBytes_in,v=u[te.TIMESTAMP]||Date.now(),T=r?r.timestamp:null;let y=t.timestamp;!y&&T&&(y=T);const S=y?v-y:0,A=S>0?p*.008*1024/S*1e3:0;return{percentPacketsLost:h,packetsReceived:l,deltaPacketsReceived:f,packetsLost:s,deltaPacketsLost:i,KBytesReceived:d,deltaKBytesReceived:p,kbsReceived:A}},pb=u=>u[te.CANDIDATE_TYPE]!=="relay"?"":u[te.RELAY_PROTOCOL]||"",mb=u=>{if(!Object.prototype.hasOwnProperty.call(u,te.NETWORK_TYPE))return oa.WIFI;switch(u[te.NETWORK_TYPE]){case Bh.ETHERNET:return oa.ETHERNET;case Bh.CELLULAR_4G:return oa.CELLULAR_4G;case Bh.WIFI:return oa.WIFI;default:return oa.CELLULAR}},xg=u=>!Object.prototype.hasOwnProperty.call(u,te.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(u,te.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:u[te.FRAME_WIDTH]||null,height:u[te.FRAME_HEIGHT]||null,framerate:u[te.FRAMES_PER_SECOND]},vb=u=>{const e=Object.prototype.hasOwnProperty.call(u,te.QUALITY_LIMITATION_REASON)?u[te.QUALITY_LIMITATION_REASON]:null,t=Object.prototype.hasOwnProperty.call(u,te.QUALITY_LIMITATION_RESOLUTION_CHANGES)?u[te.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,r=Object.prototype.hasOwnProperty.call(u,te.QUALITY_LIMITATION_DURATIONS)?u[te.QUALITY_LIMITATION_DURATIONS]:null;return r&&Object.keys(r).forEach(l=>{r[l]>1e3&&(r[l]=Number(r[l]/1e3))}),{reason:e,durations:r,resolutionChanges:t}},Tb=(u,e,t)=>{if(!Object.prototype.hasOwnProperty.call(u,te.PLI)||!Object.prototype.hasOwnProperty.call(u,te.NACK))return{pliCount:e.total_pli_sent_in,nackCount:e.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const r=(u[te.PLI]||0)-(t?t[X.VIDEO].total_pli_sent_in:0),l=(u[te.NACK]||0)-(t?t[X.VIDEO].total_nack_sent_in:0);return{pliCount:r,nackCount:l,deltaPliCount:r-e[X.VIDEO].total_pli_sent_in,deltaNackCount:l-e[X.VIDEO].total_nack_sent_in}},yb=(u,e,t)=>{if(!Object.prototype.hasOwnProperty.call(u,te.PLI)||!Object.prototype.hasOwnProperty.call(u,te.NACK))return{pliCount:e.total_pli_received_out,nackCount:e.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const r=(u[te.PLI]||0)-(t?t[X.VIDEO].total_pli_received_out:0),l=(u[te.NACK]||0)-(t?t[X.VIDEO].total_nack_received_out:0);return{pliCount:r,nackCount:l,deltaPliCount:r-e[X.VIDEO].total_pli_received_out,deltaNackCount:l-e[X.VIDEO].total_nack_received_out}},Sb=u=>({channels:u[te.CHANNELS]||null,clock_rate:u[te.CLOCK_RATE]||null,mime_type:u[te.MIME_TYPE]||null,sdp_fmtp_line:u[te.SDP_FMTP_LINE]||null}),Eb=u=>({clock_rate:u[te.CLOCK_RATE]||null,mime_type:u[te.MIME_TYPE]||null}),Cb=(u,e,t)=>{const r=(u[te.BYTES_RECEIVED]||0)/1024-(t?t.data.total_KBytes_in:0),l=(u[te.BYTES_SENT]||0)/1024-(t?t.data.total_KBytes_out:0),s=u[te.TIMESTAMP]||Date.now(),i=r-e.data.total_KBytes_in,f=l-e.data.total_KBytes_out,h=t?t.timestamp:null;let d=e.timestamp;!d&&h&&(d=h);const p=d?s-d:0,v=p>0?i*.008*1024/p*1e3:0,T=p>0?f*.008*1024/p*1e3:0;return{total_KBytes_received:r,total_KBytes_sent:l,delta_KBytes_received:i,delta_KBytes_sent:f,kbs_speed_received:v,kbs_speed_sent:T}},Ab=u=>{const e=u[te.AVAILABLE_INCOMING_BITRATE]/1024||0,t=u[te.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:e,kbs_outgoing_bandwidth:t}},bb=(u,e,t,r)=>{if(!u)return[];switch(u[te.TYPE]){case ps.CANDIDATE_PAIR:let l=!1;if(u[te.NOMINATED]&&u[te.STATE]===X.SUCCEEDED&&(l=!0,Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u),te.SELECTED in u&&!u[te.SELECTED]&&(l=!1)),l){const i=u[te.LOCAL_CANDIDATE_ID],f=u[te.REMOTE_CANDIDATE_ID],h=Cb(u,e,r),d=Ab(u),p=db(u,"data",r,e);return[{type:he.NETWORK,value:{local_candidate_id:i}},{type:he.NETWORK,value:{remote_candidate_id:f}},{type:he.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:he.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:he.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:he.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:he.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:he.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:he.DATA,value:{delta_kbs_bandwidth_in:d.kbs_incoming_bandwidth}},{type:he.DATA,value:{delta_kbs_bandwidth_out:d.kbs_outgoing_bandwidth}},{type:he.DATA,value:{delta_rtt_connectivity_ms:p.rtt}},{type:he.DATA,value:{total_rtt_connectivity_ms:p.totalRTT}},{type:he.DATA,value:{total_rtt_connectivity_measure:p.totalRTTMeasurements}}]}break;case ps.LOCAL_CANDIDATE:if(u[te.ID]===e.network.local_candidate_id)return[{type:he.NETWORK,value:{infrastructure:mb(u)}},{type:he.NETWORK,value:{local_candidate_type:u[te.CANDIDATE_TYPE]||""}},{type:he.NETWORK,value:{local_candidate_protocol:u[te.PROTOCOL]||""}},{type:he.NETWORK,value:{local_candidate_relay_protocol:pb(u)}}];break;case ps.REMOTE_CANDIDATE:if(u[te.ID]===e.network.remote_candidate_id)return[{type:he.NETWORK,value:{remote_candidate_type:u[te.CANDIDATE_TYPE]||""}},{type:he.NETWORK,value:{remote_candidate_protocol:u[te.PROTOCOL]||""}}];break;case ps.INBOUND_RTP:{Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=wt(i,e,ze.INBOUND);f&&(f.timestamp=e.timestamp);const h=wt(i,r,ze.INBOUND);if(h&&(h.timestamp=r.timestamp),u[te.MEDIA_TYPE]===X.AUDIO){const d=Pg(u,X.AUDIO,f,h),p=Ho(u,X.AUDIO,f),v=u[te.CODEC_ID]||"";return[{ssrc:i,type:he.AUDIO,value:{codec_id_in:v}},{ssrc:i,type:he.AUDIO,value:{total_packets_in:d.packetsReceived}},{ssrc:i,type:he.AUDIO,value:{delta_packets_in:d.deltaPacketsReceived}},{ssrc:i,type:he.AUDIO,value:{total_packets_lost_in:d.packetsLost}},{ssrc:i,type:he.AUDIO,value:{delta_packets_lost_in:d.deltaPacketsLost}},{ssrc:i,type:he.AUDIO,value:{percent_packets_lost_in:d.percentPacketsLost}},{ssrc:i,type:he.AUDIO,value:{total_KBytes_in:d.KBytesReceived}},{ssrc:i,type:he.AUDIO,value:{delta_KBytes_in:d.deltaKBytesReceived}},{ssrc:i,type:he.AUDIO,value:{delta_kbs_in:d.kbsReceived}},{ssrc:i,type:he.AUDIO,value:{delta_jitter_ms_in:p}}]}if(u[te.MEDIA_TYPE]===X.VIDEO){const d=_b(u,f),p=Pg(u,X.VIDEO,f,h),v=Ho(u,X.VIDEO,f),T=u[te.DECODER_IMPLEMENTATION]||null,y=u[te.CODEC_ID]||null,S=xg(u),A=Tb(u,f,h);return[{ssrc:i,type:he.VIDEO,value:{codec_id_in:y}},{ssrc:i,type:he.VIDEO,value:{total_packets_in:p.packetsReceived}},{ssrc:i,type:he.VIDEO,value:{delta_packets_in:p.deltaPacketsReceived}},{ssrc:i,type:he.VIDEO,value:{total_packets_lost_in:p.packetsLost}},{ssrc:i,type:he.VIDEO,value:{delta_packets_lost_in:p.deltaPacketsLost}},{ssrc:i,type:he.VIDEO,value:{percent_packets_lost_in:p.percentPacketsLost}},{ssrc:i,type:he.VIDEO,value:{total_KBytes_in:p.KBytesReceived}},{ssrc:i,type:he.VIDEO,value:{delta_KBytes_in:p.deltaKBytesReceived}},{ssrc:i,type:he.VIDEO,value:{delta_kbs_in:p.kbsReceived}},{ssrc:i,type:he.VIDEO,value:{delta_jitter_ms_in:v}},{ssrc:i,type:he.VIDEO,value:{decoder_in:T}},{ssrc:i,type:he.VIDEO,value:{delta_ms_decode_frame_in:d.delta_ms_decode_frame}},{ssrc:i,type:he.VIDEO,value:{total_frames_decoded_in:d.frames_decoded}},{ssrc:i,type:he.VIDEO,value:{total_time_decoded_in:d.total_decode_time}},{ssrc:i,type:he.VIDEO,value:{total_nack_sent_in:A.nackCount}},{ssrc:i,type:he.VIDEO,value:{delta_nack_sent_in:A.deltaNackCount}},{ssrc:i,type:he.VIDEO,value:{total_pli_sent_in:A.pliCount}},{ssrc:i,type:he.VIDEO,value:{delta_pli_sent_in:A.deltaPliCount}},{ssrc:i,type:he.VIDEO,value:{size_in:S}}]}break}case ps.OUTBOUND_RTP:{Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=wt(i,e,ze.OUTBOUND);f&&(f.timestamp=e.timestamp);const h=wt(i,r,ze.OUTBOUND);if(h&&(h.timestamp=r.timestamp),u[te.MEDIA_TYPE]===X.AUDIO){const d=u[te.CODEC_ID]||null,p=Dg(u,X.AUDIO,f,h);return[{ssrc:i,type:he.AUDIO,value:{codec_id_out:d}},{ssrc:i,type:he.AUDIO,value:{total_packets_out:p.packetsSent}},{ssrc:i,type:he.AUDIO,value:{delta_packets_out:p.deltaPacketsSent}},{ssrc:i,type:he.AUDIO,value:{total_KBytes_out:p.KBytesSent}},{ssrc:i,type:he.AUDIO,value:{delta_KBytes_out:p.deltaKBytesSent}},{ssrc:i,type:he.AUDIO,value:{delta_kbs_out:p.kbsSent}}]}if(u[te.MEDIA_TYPE]===X.VIDEO){const d=u[te.ENCODER_IMPLEMENTATION]||null,p=u[te.CODEC_ID]||null,v=gb(u,f),T=xg(u),y=vb(u),S=yb(u,f,h),A=Dg(u,X.VIDEO,f,h);return[{ssrc:i,type:he.VIDEO,value:{codec_id_out:p}},{ssrc:i,type:he.VIDEO,value:{total_packets_out:A.packetsSent}},{ssrc:i,type:he.VIDEO,value:{delta_packets_out:A.deltaPacketsSent}},{ssrc:i,type:he.VIDEO,value:{total_KBytes_out:A.KBytesSent}},{ssrc:i,type:he.VIDEO,value:{delta_KBytes_out:A.deltaKBytesSent}},{ssrc:i,type:he.VIDEO,value:{delta_kbs_out:A.kbsSent}},{ssrc:i,type:he.VIDEO,value:{encoder_out:d}},{ssrc:i,type:he.VIDEO,value:{delta_ms_encode_frame_out:v.delta_ms_encode_frame}},{ssrc:i,type:he.VIDEO,value:{total_frames_encoded_out:v.frames_encoded}},{ssrc:i,type:he.VIDEO,value:{total_time_encoded_out:v.total_encode_time}},{ssrc:i,type:he.VIDEO,value:{total_nack_received_out:S.nackCount}},{ssrc:i,type:he.VIDEO,value:{delta_nack_received_out:S.deltaNackCount}},{ssrc:i,type:he.VIDEO,value:{total_pli_received_out:S.pliCount}},{ssrc:i,type:he.VIDEO,value:{delta_pli_received_out:S.deltaPliCount}},{ssrc:i,type:he.VIDEO,value:{size_out:T}},{ssrc:i,type:he.VIDEO,value:{limitation_out:y}}]}break}case ps.MEDIA_SOURCE:{Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);break}case ps.TRACK:{Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);break}case ps.CODEC:const s=[];return Object.keys(e[X.AUDIO]).forEach(i=>{const f=e[X.AUDIO][i];if(f.codec_id_in===u[te.ID]||f.codec_id_out===u[te.ID]){Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const h=Sb(u);u[te.ID]===f.codec_id_in?s.push({ssrc:f.ssrc,type:he.AUDIO,value:{codec_in:h}}):s.push({ssrc:f.ssrc,type:he.AUDIO,value:{codec_out:h}})}}),Object.keys(e[X.VIDEO]).forEach(i=>{const f=e[X.VIDEO][i];if(f.codec_id_in===u[te.ID]||f.codec_id_out===u[te.ID]){Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const h=Eb(u);u[te.ID]===f.codec_id_in?s.push({ssrc:f.ssrc,type:he.VIDEO,value:{codec_in:h}}):s.push({ssrc:f.ssrc,type:he.VIDEO,value:{codec_out:h}})}}),s;case ps.REMOTE_INBOUND_RTP:{Be(Sn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=wt(i,e,ze.OUTBOUND),h=wt(i,r,ze.OUTBOUND);if(u[te.KIND]===X.AUDIO){const d=Og(u,X.AUDIO,h,f),p=Ho(u,X.AUDIO,f),v=Ng(u,X.AUDIO,f,h);return[{ssrc:i,type:he.AUDIO,value:{delta_rtt_ms_out:d.rtt}},{ssrc:i,type:he.AUDIO,value:{total_rtt_ms_out:d.totalRTT}},{ssrc:i,type:he.AUDIO,value:{total_rtt_measure_out:d.totalRTTMeasurements}},{ssrc:i,type:he.AUDIO,value:{delta_jitter_ms_out:p}},{ssrc:i,type:he.AUDIO,value:{timestamp_out:u[te.TIMESTAMP]}},{ssrc:i,type:he.AUDIO,value:{total_packets_lost_out:v.packetsLost}},{ssrc:i,type:he.AUDIO,value:{delta_packets_lost_out:v.deltaPacketsLost}},{ssrc:i,type:he.AUDIO,value:{percent_packets_lost_out:v.fractionLost}}]}if(u[te.KIND]===X.VIDEO){const d=Og(u,X.VIDEO,h,f),p=Ho(u,X.VIDEO,f),v=Ng(u,X.VIDEO,f,h);return[{ssrc:i,type:he.VIDEO,value:{delta_rtt_ms_out:d.rtt}},{ssrc:i,type:he.VIDEO,value:{total_rtt_ms_out:d.totalRTT}},{ssrc:i,type:he.VIDEO,value:{total_rtt_measure_out:d.totalRTTMeasurements}},{ssrc:i,type:he.VIDEO,value:{delta_jitter_ms_out:p}},{ssrc:i,type:he.VIDEO,value:{timestamp_out:u[te.TIMESTAMP]}},{ssrc:i,type:he.VIDEO,value:{total_packets_lost_out:v.packetsLost}},{ssrc:i,type:he.VIDEO,value:{delta_packets_lost_out:v.deltaPacketsLost}},{ssrc:i,type:he.VIDEO,value:{percent_packets_lost_out:v.fractionLost}}]}break}}return[]},Tc=u=>u<0?1:u>100?4.5:1+.035*u+7/1e6*u*(u-60)*(100-u),Rb=(u,e=X.AUDIO,t,r,l)=>{const s=wt(l,u,ze.INBOUND),i=wt(l,t,ze.INBOUND),f=wt(l,r,ze.INBOUND),h=[],d=[],p=s[e].percent_packets_lost_in,v=s[e].delta_jitter_ms_in,T=i&&i[e].delta_jitter_ms_in||null,y=f&&f[e].delta_jitter_ms_in||null,S=u.data.delta_rtt_connectivity_ms,A=t&&t.data.delta_rtt_connectivity_ms||null,R=r&&r.data.delta_rtt_connectivity_ms||null;S&&h.push(S),A&&h.push(A),R&&h.push(R),v&&d.push(v),t&&T&&d.push(T),r&&y&&d.push(y);const O=h.length>0?wn(h):100,N=d.length>0?wn(d):10,C=93.2-p,b=.18*C*C-27.9*C+1126.62,w=(O+N)/2,F=w-177.3<0?0:1,q=.024*w+.11*(w-177.3)*F,D=b-q;return Tc(D)},wb=(u,e=X.AUDIO,t,r,l)=>{const s=wt(l,u,ze.OUTBOUND),i=wt(l,t,ze.OUTBOUND),f=wt(l,r,ze.OUTBOUND),h=[],d=[],p=s[e].percent_packets_lost_out,v=s[e].delta_rtt_ms_out,T=i&&i[e].delta_rtt_ms_out||null,y=f&&f[e].delta_rtt_ms_out||null,S=s[e].delta_jitter_ms_out,A=i&&i[e].delta_jitter_ms_out||null,R=f&&f[e].delta_jitter_ms_out||null,O=u.data.delta_rtt_connectivity_ms,N=t&&t.data.delta_rtt_connectivity_ms||null,C=r&&r.data.delta_rtt_connectivity_ms||null;v?h.push(v):O&&h.push(O),T?h.push(T):N&&h.push(N),y?h.push(y):C&&h.push(C),S&&d.push(S),t&&A&&d.push(A),r&&R&&d.push(R);const b=h.length>0?wn(h):100,w=d.length>0?wn(d):10,F=93.2-p,q=.18*F*F-27.9*F+1126.62,D=(b+w)/2,P=D-177.3<0?0:1,I=.024*D+.11*(D-177.3)*P,x=q-I;return Tc(x)},Ib=(u,e=X.AUDIO,t,r,l)=>{const s=wt(l,u,ze.INBOUND),i=wt(l,t,ze.INBOUND),f=wt(l,r,ze.INBOUND),h=[],d=[],p=s[e].percent_packets_lost_in/100,v=s[e].delta_jitter_ms_in,T=i&&i[e].delta_jitter_ms_in||null,y=f&&f[e].delta_jitter_ms_in||null,S=u.data.delta_rtt_connectivity_ms,A=t&&t.data.delta_rtt_connectivity_ms||null,R=r&&r.data.delta_rtt_connectivity_ms||null;S&&h.push(S),A&&h.push(A),R&&h.push(R),v&&d.push(v),i&&T&&d.push(T),f&&y&&d.push(y);const O=h.length>0?wn(h):100,N=d.length>0?wn(d):10,C=0,b=19.8,w=29.7,F=30,q=(O+N)/2+F,D=q-177.3<0?0:1,P=.024*q+.11*(q-177.3)*D,x=93.2-(C+b*Math.log(1+w*p)+P);return Tc(x)},Ob=(u,e=X.AUDIO,t,r,l)=>{const s=wt(l,u,ze.OUTBOUND),i=wt(l,t,ze.OUTBOUND),f=wt(l,r,ze.OUTBOUND),h=[],d=[],p=s[e].percent_packets_lost_out/100,v=s[e].delta_rtt_ms_out,T=i&&i[e].delta_rtt_ms_out||null,y=f&&f[e].delta_rtt_ms_out||null,S=s[e].delta_jitter_ms_out,A=i&&i[e].delta_jitter_ms_out||null,R=f&&f[e].delta_jitter_ms_out||null,O=u.data.delta_rtt_connectivity_ms,N=t&&t.data.delta_rtt_connectivity_ms||null,C=r&&r.data.delta_rtt_connectivity_ms||null;v?h.push(v):O&&h.push(O),T?h.push(T):N&&h.push(N),y?h.push(y):C&&h.push(C),S&&d.push(S),i&&A&&d.push(A),f&&R&&d.push(R);const b=h.length>0?wn(h):100,w=d.length>0?wn(d):10,F=0,q=19.8,D=29.7,P=30,I=(b+w)/2+P,x=I-177.3<0?0:1,U=.024*I+.11*(I-177.3)*x,z=93.2-(F+q*Math.log(1+D*p)+U);return Tc(z)};class Db{constructor(e,t){this._callbacks={onreport:null,onticket:null},this._id=lb(),this._moduleName=this._id,this._probeId=t,this._config=e,this._exporter=new fb(e),this._state=js.IDLE,this.registerToPCEvents(),di(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(e,t,r,l){const s=(h,d)=>h===X.AUDIO?d===ps.INBOUND_RTP?{...l0}:{...a0}:d===ps.INBOUND_RTP?{...o0}:{...u0},i=tb(t);i.pname=this._config.pname,i.call_id=this._config.cid,i.user_id=this._config.uid,i.count=t?t.count+1:1;let f=null;return e.forEach(h=>{!f&&h.timestamp&&(f=h.timestamp),bb(h,i,i.pname,l).forEach(p=>{if(p.value&&p.type)if(p.ssrc){let v=i[p.type][p.ssrc];v||(v=s(p.type,h.type),v.ssrc=p.ssrc,i[p.type][p.ssrc]=v),Object.keys(p.value).forEach(T=>{v[T]=p.value[T]})}else Object.keys(p.value).forEach(v=>{i[p.type][v]=p.value[v]})})}),i.timestamp=f,Object.keys(i[X.AUDIO]).forEach(h=>{const d=i[X.AUDIO][h];d.direction===ze.INBOUND?(d.mos_emodel_in=Rb(i,X.AUDIO,t,r,d.ssrc),d.mos_in=Ib(i,X.AUDIO,t,r,d.ssrc)):(d.mos_emodel_out=wb(i,X.AUDIO,t,r,d.ssrc),d.mos_out=Ob(i,X.AUDIO,t,r,d.ssrc))}),i}async takeReferenceStats(){return new Promise((e,t)=>{const r=Date.now();setTimeout(async()=>{try{const l=Date.now()-r,s=Date.now(),i=await this._config.pc.getStats(),f=this.analyze(i,null,null,null),h=Date.now();f.experimental.time_to_measure_ms=h-s,f.experimental.time_to_wait_ms=l,this._exporter.saveReferenceReport(f),Be(this._moduleName,`got reference report for probe ${this._probeId}`),e()}catch(l){t(l)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==js.RUNNING||!this._config.pc)return Be(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const e=Date.now(),t=await this._config.pc.getStats(),r=this.analyze(t,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),l=Date.now();return r.experimental.time_to_measure_ms=l-e,this._exporter.addReport(r),Be(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(r),r}catch(e){return dr(this._moduleName,`got error ${e}`),null}}async start(){Be(this._moduleName,"starting"),this.state=js.RUNNING,this._startedTime=this._exporter.start(),Be(this._moduleName,"started")}async mute(){this.state=js.MUTED,Be(this._moduleName,"muted")}async unmute(){this.state=js.RUNNING,Be(this._moduleName,"unmuted")}async stop(e){if(Be(this._moduleName,`stopping${e?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=js.IDLE,this._config.ticket){const{ticket:t}=this._exporter;this.fireOnTicket(t)}this._exporter.reset(),Be(this._moduleName,"stopped")}registerCallback(e,t,r){e in this._callbacks?(this._callbacks[e]={callback:t,context:r},Be(this._moduleName,`registered callback '${e}'`)):dr(this._moduleName,`can't register callback for '${e}' - not found`)}unregisterCallback(e){e in this._callbacks?(this._callbacks[e]=null,delete this._callbacks[e],Be(this._moduleName,`unregistered callback '${e}'`)):dr(this._moduleName,`can't unregister callback for '${e}' - not found`)}fireOnReport(e){this._callbacks.onreport&&Cf(this._callbacks.onreport.callback,this._callbacks.onreport.context,e)}fireOnTicket(e){this._callbacks.onticket&&Cf(this._callbacks.onticket.callback,this._callbacks.onticket.context,e)}updateConfig(e){this._config=e,this._exporter.updateConfig(e)}get state(){return this._state}set state(e){this._state=e,Be(this._moduleName,`state changed to ${e}`)}addCustomEvent(e,t,r,l){this._exporter.addCustomEvent({at:typeof e=="object"?e.toJSON():e,category:t,name:r,description:l})}async registerToPCEvents(){const{pc:e}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const t=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${t.length} devices found`,"Media Devices state")}catch{dr(this._moduleName,"can't get devices")}},e){e.oniceconnectionstatechange=()=>{const r=e.iceConnectionState;r===aa.CONNECTED||r===aa.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",r,"ICE connection state"):r===aa.DISCONNECTED||r===aa.FAILED?this.addCustomEvent(new Date().toJSON(),"call",r,"ICE connection state"):r===aa.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},e.onicegatheringstatechange=()=>{const r=e.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",r,"ICE gathering state")},e.ontrack=r=>{this.addCustomEvent(new Date().toJSON(),"call",`${r.track.kind}track`,"MediaStreamTrack received")},e.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const t=e.getReceivers();if(t&&t.length>0){const r=t[0],{transport:l}=r;if(l){const{iceTransport:s}=l;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class Nb{constructor(e){this._id=e.pname&&e.pname.substr(0,12).padEnd(12," ")||rb(),this._moduleName=this._id,di(this._moduleName,"probe created"),this._config=e,this._collector=new Db(this._config,this._id)}set onreport(e){e?this._collector.registerCallback("onreport",e):this._collector.unregisterCallback("onreport")}set onticket(e){e?this._collector.registerCallback("onticket",e):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(e){this._collector.state=e}addCustomEvent(e,t,r,l=new Date().toJSON()){this._collector.addCustomEvent(l,t,e,r)}get isRunning(){return this._collector.state===js.RUNNING}get isIdle(){return this._collector.state===js.IDLE}updateUserId(e){this._config.uid=e,this._collector.updateConfig(this._config)}updateCallId(e){this._config.cid=e,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){nu(this._moduleName,"probe is already running");return}this._collector.start()}stop(e=!1){this.isRunning&&this._collector.stop(e)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const Vt="engine ";class Pb{constructor(e){this._config=e,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},di(Vt,`configured for probing every ${this._config.refreshEvery}ms`),di(Vt,`configured for starting after ${this._config.startAfter}ms`),di(Vt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Be(Vt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(e=>e.isRunning)}get isIdle(){return this._probes.every(e=>e.isIdle)}addNewProbe(e,t){if(!e)throw new Error("undefined peer connection");const r=nb(e,t,this._config),l=new Nb(r);return this._probes.push(l),Be(Vt,`${this._probes.length} probes registered`),l}removeExistingProbe(e){if(!e)throw new Error("undefined probe");e.state===js.RUNNING&&e.stop(),this._probes=this._probes.filter(t=>e.id!==t.id)}async start(){const e=()=>{this._probes.forEach(s=>s.start())},t=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),r=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,l=async()=>{const s=eb(),i=this._probes.filter(f=>f.isRunning);for(const f of i){const h=await f.collectStats();h&&s.probes.push(h),Be(Vt,`got probe ${f.id}`),await wg(0)}return s.delta_time_to_measure_probes_ms=ui(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=ui(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=ui(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=ui(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=ui(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=ui(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=ui(s.probes,"video","total_time_encoded_out"),s};for(Be(Vt,"starting to collect"),e(),Be(Vt,"generating reference reports..."),await t(),Be(Vt,"reference reports generated"),this._startedTime=Date.now();r();)if(Be(Vt,`wait ${this._config.refreshEvery}ms before collecting`),await wg(this._config.refreshEvery),r()){Be(Vt,"collecting...");const s=Date.now(),i=await l(),f=Date.now();i.delta_time_consumed_to_measure_ms=f-s,this.fireOnReports(i),Be(Vt,"collected")}Be(Vt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(e){const t=r=>{this._probes.forEach(l=>{l.stop(r)})};di(Vt,"stop collecting"),t(e)}registerCallback(e,t,r){e in this._callbacks?(this._callbacks[e]={callback:t,context:r},Be(Vt,`registered callback '${e}'`)):dr(Vt,`can't register callback for '${e}' - not found`)}unregisterCallback(e){e in this._callbacks?(this._callbacks[e]=null,delete this._callbacks[e],Be(this._moduleName,`unregistered callback '${e}'`)):dr(this._moduleName,`can't unregister callback for '${e}' - not found`)}fireOnReports(e){this._callbacks.onresult&&e.probes.length>0&&Cf(this._callbacks.onresult.callback,this._callbacks.onresult.context,e)}}const xb="interface ";class kb{constructor(e){this._config=ib(e),di(xb,`welcome to ${this._config.name} version ${this._config.version}`),WA(this._config.verbose||!1),this._engine=new Pb(this._config)}setupLogLevel(e){KA(e)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(e,t){return this._engine.addNewProbe(e,t)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(e){this._engine.removeExistingProbe(e)}set onresult(e){e?this._engine.registerCallback("onresult",e):this._engine.unregisterCallback("onresult")}}function Mb(u,e){return Object.keys(u).filter(t=>e.includes(t)).reduce((t,r)=>{const l=r;return{...t,[l]:u[l]}},{})}const Ub=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class Lb{constructor(e){this.intervals={},this.emitInterval=e.emitInterval||200,this.onChangeFunction=e.onChangeFunction}start(e,t){e&&e.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(e,t))}stop(e){this.clearVolumeInterval(e)}clearVolumeInterval(e){clearInterval(this.intervals[e]),delete this.intervals[e]}clearAllIntervals(){Object.keys(this.intervals).forEach(e=>{clearInterval(this.intervals[e])}),this.intervals={}}beginCalculation(e,t){this.clearVolumeInterval(t);const r=fi.createAnalyser(),l=fi.createMediaStreamSource(e),s=fi.createScriptProcessor(2048,1,1);r.smoothingTimeConstant=.8,r.fftSize=1024,l.connect(r),r.connect(s),s.connect(fi.destination),this.intervals[t]=setInterval(()=>{const i=new Uint8Array(r.frequencyBinCount);r.getByteFrequencyData(i);let f=0;const h=i.length;for(let p=0;p<h;p++)f+=i[p];const d=f/h;this.onChangeFunction(t,d)},this.emitInterval)}}const Go={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Fb=0;class $b{constructor(e){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=e,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new Lb({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(e){this.currentActiveRoomIdValue=e,this.context.emit("currentActiveRoomChanged",e)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(e){this.isCallAddingInProgress=e,this.context.emit("callAddingInProgressChanged",e)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get speakerVolume(){return this.speakerVolumeValue}get microphoneInputLevel(){return this.microphoneInputLevelValue}get getActiveCalls(){return this.activeCalls}get hasActiveCalls(){return Object.values(this.extendedCalls).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(e=>e.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(e=>e.kind==="audiooutput")}get getUserMediaConstraints(){return yp()?{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(e){this.availableMediaDevices=e,this.context.emit("changeAvailableDeviceList",e)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const e=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(e)}async initializeMediaDevices(){const e=localStorage.getItem(Go.SELECTED_INPUT_DEVICE)||"default",t=localStorage.getItem(Go.SELECTED_OUTPUT_DEVICE)||"default";try{const r=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),l=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(l),await this.setMicrophone(e),await this.setSpeaker(t),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),r.getTracks().forEach(s=>s.stop())}catch(r){console.error(r)}}setCallTime(e){const t={...e};delete t.callId,this.callTime={...this.callTime,[e.callId]:t},this.context.emit("changeCallTime",this.callTime)}removeCallTime(e){const t={...this.callTime};delete t[e],this.callTime={...t},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(e,t){this.timeIntervals={...this.timeIntervals,[e]:t}}removeTimeInterval(e){const t={...this.timeIntervals};t[e]&&(clearInterval(t[e]),delete t[e],this.timeIntervals={...t})}stopCallTimer(e){this.removeTimeInterval(e),this.removeCallTime(e)}emitVolumeChange(e,t){this.context.emit("changeCallVolume",{callId:e,volume:t})}setMetricsConfig(e){this.metricConfig={...this.metricConfig,...e}}sendDTMF(e,t){if(!/^[A-D0-9]+$/g.test(t))throw new Error("Not allowed character in DTMF input");this.extendedCalls[e].sendDTMF(t)}setIsMuted(e){this.muted=e,this.context.emit("changeIsMuted",e)}processMute(e){const t=this.currentActiveRoomId;this.setIsMuted(e),this.initialStreamValue.getTracks().forEach(r=>r.enabled=!e),this.roomReconfigure(t)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:e,toHold:t,automatic:r}){const l=this.extendedCalls[e];l._automaticHold=r??!1,await new Promise(f=>{const h=()=>{l.putOnHoldTimestamp=t?Date.now():void 0,f()};t?l.hold({},h):l.unhold({},h)}),this.updateCall(l);const i=Object.values(this.extendedCalls).filter(f=>f.roomId===this.currentActiveRoomId&&(t?e!==f._id:!0));i.length>1&&await this.doConference(i)}holdCall(e,t=!1){return this.processHold({callId:e,automatic:t,toHold:!0})}unholdCall(e){return this.processHold({callId:e,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(e=>e.direction==="outgoing"&&e.status===Fb).forEach(e=>this.terminateCall(e._id))}answerCall(e){const t=this.extendedCalls[e];this.cancelAllOutgoingUnanswered(),t.answer(this.sipOptions),this.updateCall(t),this.setActiveRoom(t.roomId),t.connection.addEventListener("track",r=>{this.triggerAddStream(r,t)})}async moveCall(e,t){this.updateCallStatus({callId:e,isMoving:!0}),await this.processRoomChange({callId:e,roomId:t}),this.updateCallStatus({callId:e,isMoving:!1})}updateCall(e){this.activeCalls[e._id]=G_(e),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(e){const r={...this.activeRooms[e.roomId],...e};this.activeRooms={...this.activeRooms,[e.roomId]:{...r}},this.context.emit("updateRoom",{room:r,roomList:this.activeRooms})}hasAutoAnswerHeaders(e){const t=/answer-after=0/,l=e.request.getHeader("Call-Info");return l&&t.test(l)}addCall(e,t=!0){this.activeCalls={...this.activeCalls,[e._id]:G_(e)},this.extendedCalls[e._id]=e,t&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(e){this.callStatus={...this.callStatus,[e]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(e){const r={...{...this.callStatus[e.callId]}};e.isMoving!==void 0&&(r.isMoving=e.isMoving),e.isTransferring!==void 0&&(r.isTransferring=e.isTransferring),e.isMerging!==void 0&&(r.isMerging=e.isMerging),this.callStatus={...this.callStatus,[e.callId]:{...r}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(e){const t={...this.callStatus};delete t[e],this.callStatus={...t},this.context.emit("changeCallStatus",this.callStatus)}addRoom(e){this.activeRooms={...this.activeRooms,[e.roomId]:e},this.context.emit("addRoom",{room:e,roomList:this.activeRooms})}getActiveStream(){const e=B_(this.initialStreamValue,this.microphoneInputLevel*2);return e.getTracks().forEach(t=>t.enabled=!this.isMuted),this.setActiveStream(e),e}async setMicrophone(e){if(!this.getInputDeviceList.find(({deviceId:r})=>r===e)||(this.setSelectedInputDevice(e),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const t=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId);t.length===1?Object.values(t).forEach(async r=>{const l=this.getActiveStream();r.connection.getSenders()[0].replaceTrack(l.getTracks()[0]),this.updateCall(r)}):await this.doConference(t)}setActiveStream(e){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(e,"origin"),this.activeStreamValue=e,this.context.emit("changeActiveStream",e)}async setSpeaker(e){if(!this.getOutputDeviceList.find(({deviceId:l})=>l===e))return;this.setSelectedOutputDevice(e);const t=Object.values(this.extendedCalls);if(t.length===0)return;const r=t.filter(l=>l.roomId===this.currentActiveRoomId);r.length===1?t.forEach(l=>{var s;(s=l.audioTag)==null||s.setSinkId(e),this.updateCall(l)}):await this.doConference(r)}removeRoom(e){const t={...this.activeRooms},r={...t[e]};delete t[e],this.activeRooms={...t},this.context.emit("removeRoom",{room:r,roomList:this.activeRooms})}deleteRoomIfEmpty(e){e!==void 0&&Object.values(this.extendedCalls).filter(t=>t.roomId===e).length===0&&(this.removeRoom(e),this.currentActiveRoomId===e&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(e){this.muted?e.mute({audio:!0}):e.unmute({audio:!0})}async roomReconfigure(e){var r;if(e===void 0)return;const t=Object.values(this.extendedCalls).filter(l=>l.roomId===e);if(this.currentActiveRoomId===e?t.forEach(l=>{l.audioTag&&(this.muteReconfigure(l),l.audioTag.muted=!1,this.updateCall(l))}):t.forEach(l=>{l.audioTag&&(l.audioTag.muted=!0,this.updateCall(l))}),t.length===0)this.deleteRoomIfEmpty(e);else if(t.length===1&&this.currentActiveRoomId!==e)t[0].isOnHold().local||await this.holdCall(t[0].id,!0);else if(t.length===1&&this.currentActiveRoomId===e){if(t[0].isOnHold().local&&t[0]._automaticHold&&await this.unholdCall(t[0].id),t[0].connection&&((r=t[0].connection)!=null&&r.getSenders()[0])){const l=this.getActiveStream();await t[0].connection.getSenders()[0].replaceTrack(l.getTracks()[0]),this.muteReconfigure(t[0])}}else t.length>1&&await this.doConference(t)}async doConference(e){const t=[];e.forEach(r=>{r!=null&&r.connection.getReceivers().forEach(l=>{t.push(l.track)})}),await jA.forEach(e,async r=>{var i;if(r==null)return;const l=new MediaStream,s=fi.createMediaStreamDestination();if(r.connection.getReceivers().forEach(f=>{t.forEach(h=>{l.addTrack(f.track),f.track.id!==h.id&&fi.createMediaStreamSource(new MediaStream([h])).connect(s)})}),e[0].roomId===this.currentActiveRoomId){const f=this.getActiveStream();fi.createMediaStreamSource(f).connect(s)}(i=r.connection)!=null&&i.getSenders()[0]&&(await r.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(r))})}processCallerMute(e,t){const r=this.extendedCalls[e];r&&r.connection.getReceivers().length&&(r.localMuted=t,r.connection.getReceivers().forEach(l=>{l.track.enabled=!t}),this.updateCall(r))}muteCaller(e){this.processCallerMute(e,!0)}unmuteCaller(e){this.processCallerMute(e,!1)}terminateCall(e){const t=this.extendedCalls[e];t._status!==8&&t.terminate()}transferCall(e,t){if(t.toString().length===0)return new Error("Target must be passed");const r=this.extendedCalls[e];if(!r._is_confirmed&&!r._is_canceled){const l=`sip:${t}@${this.context.sipDomain}`;r.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${l}`]});return}this.updateCallStatus({callId:e,isTransferring:!0}),r.refer(`sip:${t}@${this.context.sipDomain}`),this.updateCall(r)}mergeCall(e){const t=Object.values(this.extendedCalls).filter(s=>s.roomId===e);if(t.length!==2)return;const r=t[0],l=t[1];!r||!l||(this.updateCallStatus({callId:r._id,isMerging:!0}),this.updateCallStatus({callId:l._id,isMerging:!0}),r.refer(l.remote_identity.uri.toString(),{replaces:l}),this.updateCall(r))}mergeCallByIds(e,t){const r=Object.values(this.extendedCalls).find(s=>s._id===e),l=Object.values(this.extendedCalls).find(s=>s._id===t);if(!r||!l)throw new Error("Call ID is not provided");this.updateCallStatus({callId:e,isMerging:!0}),this.updateCallStatus({callId:t,isMerging:!0}),r.refer(l.remote_identity.uri.toString(),{replaces:l}),this.updateCall(r)}setDND(e){this.isDNDEnabled=e,this.context.emit("changeIsDND",e)}startCallTimer(e){this.removeTimeInterval(e);const t={callId:e,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(t);const r=setInterval(()=>{const l={...this.callTime[e]},s=GA(l);this.setCallTime({callId:e,...s})},1e3);this.setTimeInterval(e,r)}async setActiveRoom(e){const t=this.currentActiveRoomId;e!==t&&(this.currentActiveRoomId=e,await this.roomReconfigure(t),await this.roomReconfigure(e))}getNewRoomId(){const e=Object.keys(this.activeRooms);return e.length===0?1:parseInt(e.sort()[e.length-1])+1}async setupCall(e){var d,p;const t=e.session;if(this.getActiveCalls[t.id]!==void 0)return;const l=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:l};t.direction==="incoming"?(this.context.logger.log("New incoming call from",(p=(d=t._remote_identity)==null?void 0:d._uri)==null?void 0:p._user),s.incomingInProgress=!0,this.context.subscribe(ms.CALL_CONFIRMED,v=>{t.id===v.id&&(this.updateRoom({incomingInProgress:!1,roomId:l}),this.startCallTimer(t.id))}),this.context.subscribe(ms.CALL_FAILED,v=>{t.id===v.id&&(this.updateRoom({incomingInProgress:!1,roomId:l}),this.deleteRoomIfEmpty(l))})):t.direction==="outgoing"&&(t.once("confirmed",()=>{this.startCallTimer(t.id)}),this.startCallTimer(t.id));const i=t,f=this.hasAutoAnswerHeaders(e),h=i.direction==="incoming"&&!this.hasActiveCalls&&(f||this.autoAnswer);i.roomId=l,i.localMuted=!1,i.autoAnswer=h,h?this.addCall(i,!1):this.addCall(i),this.addCallStatus(t.id),this.addRoom(s),h&&this.answerCall(i._id)}removeCall(e){const t={...this.activeCalls};delete t[e],this.activeCalls={...t};const r={...this.extendedCalls};delete r[e],this.extendedCalls={...r},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(e){var l;const t=this.extendedCalls[e._id];this.stopVUMeter("origin"),(l=t.connection)==null||l.getSenders().forEach(s=>{s.track.stop()});const r=t.roomId;this.removeCall(e._id),this.roomReconfigure(r)}async newRTCSessionCallback(e){const t=e.session;if(this.isDND){t.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:ms.NEW_CALL,session:t,event:e}),t.on("ended",r=>{var s,i,f;this.stopVUMeter(t.id),this.context.logger.log("Session ended for",(i=(s=t._remote_identity)==null?void 0:s._uri)==null?void 0:i._user),this.context.triggerListener({listenerType:ms.CALL_ENDED,session:t,event:r});const l=this.getActiveCalls[t.id];l&&this.activeCallListRemove(l),this.stopCallTimer(t.id),this.removeCallStatus(t.id),this.removeCallMetrics(t.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(f=this.initialStreamValue)==null||f.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),t.on("progress",r=>{var l,s;this.context.logger.log("Session in progress for",(s=(l=t._remote_identity)==null?void 0:l._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:ms.CALL_PROGRESS,session:t,event:r})}),t.on("failed",r=>{var s,i,f;this.stopVUMeter(t.id),this.context.logger.log("Session failed for",(i=(s=t._remote_identity)==null?void 0:s._uri)==null?void 0:i._user),this.context.triggerListener({listenerType:ms.CALL_FAILED,session:t,event:r}),t.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const l=this.getActiveCalls[t.id];l&&this.activeCallListRemove(l),this.stopCallTimer(t.id),this.removeCallStatus(t.id),this.removeCallMetrics(t.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(f=this.initialStreamValue)==null||f.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),t.on("confirmed",r=>{var l,s;this.context.logger.log("Session confirmed for",(s=(l=t._remote_identity)==null?void 0:l._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:ms.CALL_CONFIRMED,session:t,event:r}),this.updateCall(t),t.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(e),t.direction==="outgoing"){const r=this.getActiveCalls[t.id].roomId;this.setActiveRoom(r)}}setMuteWhenJoin(e){this.muteWhenJoinEnabled=e,this.context.emit("changeMuteWhenJoin",e)}setMicrophoneSensitivity(e){if(e<0||e>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=e,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(e){this.speakerVolumeValue=e,Object.values(this.extendedCalls).forEach(t=>{t.audioTag&&(t.audioTag.volume=e,this.updateCall(t))})}setAutoAnswer(e){this.isAutoAnswer=e}setSelectedInputDevice(e){localStorage.setItem(Go.SELECTED_INPUT_DEVICE,e),this.selectedMediaDevices.input=e,this.context.emit("changeActiveInputMediaDevice",e)}setSelectedOutputDevice(e){localStorage.setItem(Go.SELECTED_OUTPUT_DEVICE,e),this.selectedMediaDevices.output=e,this.context.emit("changeActiveOutputMediaDevice",e)}setCallMetrics(e){const t={...e};delete t.callId,this.callMetrics={...this.callMetrics,[e.callId]:t},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(e){const t={...this.callMetrics};delete t[e],this.callMetrics={...t},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(e){const t=new kb(this.metricConfig),r=t.createProbe(e.connection,{cid:e._id}),l=[];let s;r.onreport=i=>{Object.entries(i.audio).forEach(([d,p])=>{p.direction==="inbound"&&!l.includes(d)&&(l.push(d),s=d)});const f=i.audio[s];if(!f)return;const h=Mb(f,Ub);h.callId=e._id,this.setCallMetrics(h)},this.context.subscribe(ms.CALL_ENDED,i=>{i._id===e._id&&t.stopAllProbes()}),t.startAllProbes()}setupVUMeter(e,t){this.VUMeter.start(e,t)}stopVUMeter(e){this.VUMeter.stop(e)}async setupStream(){const e=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(t=>t.stop()),this.initialStreamValue=null),this.initialStreamValue=e}async triggerAddStream(e,t){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const r=B_(this.initialStreamValue,this.microphoneInputLevel*2),l=this.isMuted||this.muteWhenJoin;r.getTracks().forEach(i=>i.enabled=!l),this.setActiveStream(r),await t.connection.getSenders()[0].replaceTrack(r.getTracks()[0]);const s=new MediaStream([e.track]);SS(s,t,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(s,t._id),this.getCallQuality(t),this.updateCall(t)}initCall(e,t,r=!1){if(e.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${e}@${this.context.sipDomain}...`);const l=this.context.call(`sip:${e}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=l.id,t&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:l.id,roomId:this.currentActiveRoomId}),r)){const s=Object.values(this.extendedCalls).filter(i=>i.roomId===this.currentActiveRoomId&&i._id!==l.id);for(const i of s)this.holdCall(i._id,!0)}l.connection.addEventListener("track",s=>{this.triggerAddStream(s,l)})}async processRoomChange({callId:e,roomId:t}){const r=this.extendedCalls[e].roomId;this.extendedCalls[e].roomId=t;const l=this.extendedCalls[e];return this.updateCall(l),await this.setActiveRoom(t),Promise.all([this.roomReconfigure(r),this.roomReconfigure(t)]).then(()=>{this.deleteRoomIfEmpty(r),this.deleteRoomIfEmpty(t)})}}class Hb{constructor(e){this.context=e}get sipOptions(){return{...this.context.options.sipOptions}}initCall(e,t){if(e.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${e}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${e}@${this.context.sipDomain}`,t,this.sipOptions)}stop(e={}){this.context.terminateJanusSessions(e)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(e){this.context.changeMediaConstraints(e)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class Gb{constructor(e){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=e,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(e){const t=this.extendedMessages[e];this.updateMSRPSession(t)}updateMSRPSession(e){this.activeMessages[e._id]=V_(e),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(e){this.activeMessages={...this.activeMessages,[e._id]:V_(e)},this.extendedMessages[e._id]=e,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(e,t){const r=this.msrpHistory[t.id]||[];r.push(e),this.msrpHistory={...this.msrpHistory,[t.id]:[...r]},this.context.emit("newMSRPMessage",{message:e,session:t})}messageTerminate(e){const t=this.extendedMessages[e];t._status!==8&&t.terminate()}addMessageSession(e){if(!e._id||this.getActiveMessages[e._id]!==void 0)return;const r=e;this.addMMSRPSession(r)}triggerMSRPListener({listenerType:e,session:t,event:r}){const l=this.context.listenersList[e];!l||!l.length||l.forEach(s=>{s(t,r)})}removeMMSRPSession(e){const t={...this.activeMessages};delete t[e],this.activeMessages={...t};const r={...this.extendedMessages};delete r[e],this.extendedMessages={...r},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(e){this.removeMMSRPSession(e._id)}newMSRPSessionCallback(e){const t=e.session;t.on("ended",r=>{this.triggerMSRPListener({listenerType:ms.CALL_ENDED,session:t,event:r});const l=this.getActiveMessages[t.id];this.activeMessageListRemove(l)}),t.on("failed",r=>{this.triggerMSRPListener({listenerType:ms.CALL_FAILED,session:t,event:r});const l=this.getActiveMessages[t.id];this.activeMessageListRemove(l)}),t.on("confirmed",r=>{this.triggerMSRPListener({listenerType:ms.CALL_CONFIRMED,session:t,event:r}),this.updateMSRPSession(t)}),t.on("newMessage",r=>{this.addMSRPMessage(r,t)}),this.addMessageSession(t)}setIsMSRPInitializing(e){this.isMSRPInitializingValue=e,this.context.emit("isMSRPInitializingChanged",e)}initMSRP(e,t,r){if(e.length===0)return console.error("Target must be a valid string");const l=this.context.startMSRP(e,r);l.on("active",()=>{this.addMessageSession(l),l.sendMSRP(t),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(e,t){const r=this.extendedMessages[e];if(!r)throw new Error(`MSRP session with id ${e} doesn't exist!`);r.sendMSRP(t)}}const qh={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class Vb extends _S{constructor(e,t){if(!e.modules.length)throw new Error("options.modules should include at least 1 module");const r={...e.configuration,sockets:e.socketInterfaces.map(l=>new HA.WebSocketInterface(l))};super(r),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.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],e.pnExtraHeaders&&Object.keys(e.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(e.pnExtraHeaders),this.options=e,this.modules=e.modules,t&&ES(t)&&(this.logger=t)}on(e,t){return super.on(e,t)}off(e,t){return super.off(e,t)}emit(e,t){return super.emit(e,t)}get sipDomain(){return this.options.sipDomain}use(e){if(this.newStreamPlugins.find(t=>t.name===e.name)||this.processStreamPlugins.find(t=>t.name===e.name))throw new Error(`Plugin with name ${e.name} already exists`);if(e instanceof Ru)e.setOpensips(this),this.newStreamPlugins.push(e);else if(e instanceof td)e.setOpensips(this),this.processStreamPlugins.push(e);else throw new Error("Wrong plugin instance")}getPlugin(e){return this.newStreamPlugins.find(t=>t.name===e)||this.processStreamPlugins.find(t=>t.name===e)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(qh.AUDIO)&&(this.audio=new $b(this)),this.modules.includes(qh.MSRP)&&(this.msrp=new Gb(this)),this.modules.includes(qh.VIDEO)&&(this.video=new Hb(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.isReconnecting=!1,this.activeConnection=!0}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.isReconnecting=!0,this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.stop(),this.setInitialized(!1),this.setConnected(!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(e,t){const l=!this.listenersList[e]||!this.listenersList[e].length?[t]:[...this.listenersList[e],t];this.listenersList={...this.listenersList,[e]:l}}removeIListener(e){const t={...this.listenersList};delete t[e],this.listenersList={...t}}triggerListener({listenerType:e,session:t,event:r}){const l=this.listenersList[e];!l||!l.length||l.forEach(s=>{s(t,r)})}setInitialized(e){this.initialized=e,this.emit("ready",e)}setConnected(e){this.connected=e,this.emit("connection",e)}}exports.BaseNewStreamPlugin=Ru;exports.BaseProcessStreamPlugin=td;exports.ScreenSharePlugin=CS;exports.ScreenShareWhiteBoardPlugin=CA;exports.WhiteBoardPlugin=RA;exports.default=Vb;
155
+ a=path:${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
156
+ `),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new sl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:s=>{this.onTransportError(),console.log(s)},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s),s.status_code===200&&(s.parseSDP(!0),this._status=Re.STATUS_CONFIRMED,this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Re.STATUS_INVITE_SENT}terminate(t={}){const n=t.cause||L.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Re.STATUS_TERMINATED)throw new qs.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Re.STATUS_NULL:case Re.STATUS_INVITE_SENT:case Re.STATUS_1XX_RECEIVED:if(r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Re.STATUS_NULL||this._status===Re.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Re.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Re.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case Re.STATUS_WAITING_FOR_ANSWER:case Re.STATUS_ANSWERED:if(r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case Re.STATUS_WAITING_FOR_ACK:case Re.STATUS_CONFIRMED:if(d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Re.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(L.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendRequest(t,n){return this._dialog.sendRequest(t,n)}authenticate(t){this.status="auth";let n=new cr("");n.method="AUTH",n.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),n.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),t&&n.addHeader("Authorization",t.toString());let a=n.toString(),o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));this._connection.send(n.toString())}onmessage(t){const n=new cr(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Km(this.credentials);o.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},a,ke.createRandomToken(12)),this.authenticate(o)}this.status==="auth"&&n.code===200&&this._direction==="outgoing"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.inviteParty(n)):this.status==="auth"&&n.code===200&&this._direction==="incoming"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.acceptParty(n),this.emit("confirmed")):n.method==="SEND"&&(this._sendOk(n),this._sendReport(n),n.direction="incoming",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)),n.code===480&&this._close()}onclose(){console.log("close")}onopen(){const t=new RTCPeerConnection({iceServers:[]});t.createDataChannel(""),t.createOffer().then(t.setLocalDescription.bind(t)),t.onicecandidate=n=>{if(!n||!n.candidate||!n.candidate.candidate)return;const a=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,o=n.candidate.candidate.match(a);this.my_ip=o&&o[1],t.onicecandidate=()=>{},this.authenticate(null)}}onerror(t){console.log(t)}_receiveInviteResponse(t){if(console.log("resp0000000000000",t),this._dialog&&t.status_code>=200&&t.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(L.ACK);return}else{const n=new ea(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Re.STATUS_INVITE_SENT&&this._status!==Re.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(t.status_code):this._status=Re.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){console.log("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Re.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(console.log("maybe here???"),this._status=Re.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n),new RTCSessionDescription({type:"answer",sdp:n.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(a=>this._connection.setLocalDescription(a)).catch(a=>{this._acceptAndTerminate(t,500,a.toString()),console.log("failed 4"),this._failed("local",t,L.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(L.ACK),this._confirmed("local",null)});break}default:{const n=ke.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new cr("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",ke.createRandomToken(10)),n.addHeader("Byte-Range","1-25/25"),n.addHeader("Content-Type","text/plain"),n.addHeader("Success-Report","yes"),n.addHeader("Failure-Report","yes"),n.body=t;let a=n.toString();console.log(a);let o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));console.log(o),this._connection.send(n.toString()),n.direction="outgoing",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new cr("");o.method="200 OK",o.addHeader("To-Path",`${this.my_addr[1]}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}_sendReport(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new cr("");o.method="REPORT",o.addHeader("To-Path",`${t.getHeader("From-Path")}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.addHeader("Byte-Range","1-25/25"),o.addHeader("Status","000 200 OK"),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}parseAuth(t){const n={},a=t.replace("Digest","").split(",");for(const o of a){const s=o.trim().split("=");n[s[0]]=s[1].match('^"(.+)"$')[1]}return n}init_incoming(t,n){let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Re.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=ke.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Re.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),console.log("failed 6"),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Re.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),console.log("failed 7"),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),t.parseSDP(!0),this.target_addr=t.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",t),this._status!==Re.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(t,n,a){this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),this.emit("failed",{originator:t,message:n||null,cause:a})}_close(){if(console.log("CLOSE SESSION"),this._status!==Re.STATUS_TERMINATED){if(this._status=Re.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){console.log("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyMSRPSession(this)}}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ea(this,t,n,ea.C.STATUS_EARLY),d.error?(console.log("failed 8"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ea(this,t,n);return h.error?(console.log("failed 9"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_newMSRPSession(t,n){this._ua.newMSRPSession(this,{originator:t,session:this,request:n})}_progress(t,n){this.emit("progress",{originator:t,response:n||null})}isEnded(){switch(this._status){case Re.STATUS_CANCELED:case Re.STATUS_TERMINATED:return!0;default:return!1}}_accepted(t,n){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===L.CANCEL)(this._status===Re.STATUS_WAITING_FOR_ANSWER||this._status===Re.STATUS_ANSWERED)&&(this._status=Re.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==Re.STATUS_WAITING_FOR_ACK)return;if(this._status=Re.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===Re.STATUS_CONFIRMED||this._status===Re.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===Re.STATUS_INVITE_RECEIVED||this._status===Re.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===Re.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:this._status===Re.STATUS_1XX_RECEIVED||this._status===Re.STATUS_WAITING_FOR_ANSWER||this._status===Re.STATUS_ANSWERED||this._status===Re.STATUS_WAITING_FOR_ACK||this._status===Re.STATUS_CONFIRMED?(t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new yu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===Re.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===Re.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===Re.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}}var MT=Zt();const Iu=ze(MT),fa=new Ga("Parser"),LT=(c,t)=>{let n,a,o=c.indexOf(`\r
157
+ `);if(o===-1){fa.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=Iu.parse(s,"Request_Response");if(r===-1){fa.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new pr.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new pr.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=$T(c,d),o===-2){a=d+2;break}else if(o===-1){fa.warn("parseMessage() | malformed message");return}if(r=HT(n,c,d,o),r!==!0){fa.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){const h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function $T(c,t){let n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
158
+ `,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function HT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Iu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Iu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof pr.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const FT={parseMessage:LT},Wi=new Ga("Registrator"),ha=10;class jT{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Ts.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const a=this._contact.indexOf(">");if(a!==-1){const o=this._contact.slice(0,a)+this._contact.slice(a+1,this._contact.length);this._contact=o}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Wi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),t.push(`Expires: ${this._expires}`);const n=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new sl(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Wi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Wi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<ha&&(d=ha);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<ha&&(this._expires=ha),this.register()):(Wi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=Ts.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Wi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const a=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new sl(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=Ts.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}}const tt=console,Vs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},qT=wT;class VT extends qT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new jT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){tt.debug("call()");const o=new $a(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){tt.debug("startScreenShare()");for(const t in this._janus_sessions)this._janus_sessions[t].connectScreenShare()}changeMediaConstraints(t){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(t)}startBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].connectBlur()}stopBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].stopBlur()}_loadConfig(t){try{rl.load(this._configuration,t)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Ts.newUUID());let n;typeof window<"u"&&typeof window.document<"u"?n=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(n=self.navigator.userAgent),n+=" "+De.USER_AGENT,this._configuration.user_agent=t.overrideUserAgent&&typeof t.overrideUserAgent=="function"?t.overrideUserAgent(n):n,this._configuration.jssip_id=Ts.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new eT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=BT.bind(this),this._transport.onconnect=GT.bind(this),this._transport.ondisconnect=WT.bind(this),this._transport.ondata=KT.bind(this)}catch(s){throw tt.warn(s),new qs.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new In("sip",Ts.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const r=s.anonymous||null,d=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),d&&(r?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(o.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));tt.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(rl.settings,s))switch(s){case"uri":case"registrar_server":tt.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":tt.debug(`- ${s}: NOT SHOWN`);break;default:tt.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",a=>{console.log(a)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(a=>{a.setSession(t)}),this.processStreamPlugins.forEach(a=>{a.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}receiveRequest(t){var s,r,d,h;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){tt.debug("Request-URI does not point to us"),t.method!==De.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===De.SIPS){t.reply_sl(416);return}if(Gt.checkTransaction(this,t))return;if(n===De.INVITE?new Gt.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new Gt.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new Qc.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new Qc.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)if(a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a)a.receiveRequest(t);else if(n===De.NOTIFY)if(o=this._findSession(t),o)o.receiveRequest(t);else{if(t.body)try{const _=JSON.parse(t.body)||{};(r=(s=_.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(_),(h=(d=_.plugindata)==null?void 0:d.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(_.plugindata.data.unpublished)}catch(_){console.error(_)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const _=t.replaces;a=this._findDialog(_.call_id,_.from_tag,_.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(o=new nu(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new $g(this),o.init_incoming(t));else tt.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):tt.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}startMSRP(t,n){tt.debug("startMSRP()",n);const a=new nu(this);return a.connect(t),a}startJanus(t,n){tt.debug("startJanus()",n);const a=new nu(this);return a.connect(t),a}terminateMSRPSessions(t){tt.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){tt.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){tt.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(t){tt.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}stop(){if(tt.debug("stop()"),this._dynConfiguration={},this._status===Vs.STATUS_USER_CLOSED){tt.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){tt.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,a)){tt.debug(`closing session ${a}`);try{this._msrp_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,a)){tt.debug(`closing session ${a}`);try{this._janus_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch(o){console.error(o)}this._status=Vs.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function BT(c){this.emit("connecting",c)}function GT(c){this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function WT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_NOT_READY,this._error=Vs.NETWORK_ERROR)}function KT(c){const t=c.transport;let n=c.message;if(n=FT.parseMessage(n,this),!!n&&!(this._status===Vs.STATUS_USER_CLOSED&&n instanceof pr.IncomingRequest)&&pT(n,this,t)){if(n instanceof pr.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof pr.IncomingResponse){let a;switch(n.method){case De.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case De.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const YT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],JT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Nf(c){const t={};return YT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Uf(c){const t={};return JT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function Pf(c,t){const n=new AudioContext,a=n.createMediaStreamSource(c),o=n.createMediaStreamDestination(),s=n.createGain();return a.connect(s),s.connect(o),s.gain.value=t,o.stream}function zT(c,t,n,a){const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,wh()||(o.setSinkId(n),o.volume=a),o.play(),t.audioTag=o}function XT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function wh(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}const QT=ut,ZT=Zt(),Dt=new QT("WebSocketInterface");var ev=class{constructor(t){Dt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=ZT.parse(t,"absoluteURI");if(n===-1)throw Dt.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Dt.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${n.host}${n.port?`:${n.port}`:""};transport=ws`,this._via_transport=n.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(t){this._via_transport=t.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Dt.debug("connect()"),this.isConnected()){Dt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Dt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Dt.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(t){this._onError(t)}}disconnect(){Dt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(t){return Dt.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Dt.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){Dt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:t,code:n,reason:a}){Dt.debug(`WebSocket ${this._url} closed`),t===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Dt.debug("received WebSocket message"),this.ondata(t)}_onError(t){Dt.warn(`WebSocket ${this._url} error: `,t)}};const bu=Ha,tv=De,sv=As,nv=At(),rv=bh,iv=ys(),lv=$u(),av=Zt(),ov=ev,uv=gr("JsSIP");uv("version %s",bu.version);var cv={C:tv,Exceptions:sv,Utils:nv,UA:rv,URI:iv,NameAddrHeader:lv,WebSocketInterface:ov,Grammar:av,debug:gr,get name(){return bu.title},get version(){return bu.version}};const fv=ze(cv);function ru(c){return c<10?`0${c}`:`${c}`}function hv(c){let t=c.hours||0,n=c.minutes||0,a=c.seconds||0;a++,a===60&&(a=0,n++,n===60&&(n=0,t++));const o=`${ru(t)}:${ru(n)}:${ru(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var Ct={};Ct.forEach=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)if(o in c){const s=Promise.resolve(c[o]).then(r=>t.call(n||globalThis,r,o,c));a.push(s)}await Promise.all(a)};Ct.forEachSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)};Ct.map=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=Promise.resolve(c[o]).then(s=>t.call(n||globalThis,s,o,c)));return Promise.all(a)};Ct.mapSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=await t.call(n||globalThis,await c[o],o,c));return a};Ct.find=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a();let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.findSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return c[a]};Ct.findIndex=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(-1);let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.findIndexSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return a};Ct.some=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.someSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&await t.call(n||globalThis,await c[a],a,c))return!0;return!1};Ct.every=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.everySeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&!await t.call(n||globalThis,await c[a],a,c))return!1;return!0};Ct.filter=(c,t,n)=>new Promise(async(a,o)=>{const s=[];for(let d=0;d<c.length;d++)d in c&&(s[d]=Promise.resolve(c[d]).then(h=>t.call(n||globalThis,h,d,c)).catch(o));const r=[];for(let d=0;d<s.length;d++)await s[d]&&r.push(await c[d]);a(r)});Ct.filterSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)&&a.push(await c[o]);return a};Ct.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let a,o;for(n!==void 0?(o=n,a=0):(o=c[0],a=1),a;a<c.length;a++)a in c&&(o=await t(await o,await c[a],a,c));return o};var Oh={};(function(c){const t=Ct;Object.keys(t).forEach(n=>{const a=n.charAt(0).toUpperCase()+n.slice(1);c[`async${a}`]=async function(...o){return t[n](this,...o)}})})(Oh);const dv=Ct,_v=Oh;var pv=Object.assign(dv,{instanceMethods:_v});const Cn=new AudioContext,Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var mv={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,W,G){ee[W]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=d.asyncIterator||"@@asyncIterator",g=d.toStringTag||"@@toStringTag";function T(ee,W,G){return Object.defineProperty(ee,W,{value:G,enumerable:!0,configurable:!0,writable:!0}),ee[W]}try{T({},"")}catch{T=function(W,G,re){return W[G]=re}}function E(ee,W,G,re){var ge=W&&W.prototype instanceof oe?W:oe,be=Object.create(ge.prototype),xe=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,xe)}),be}n.wrap=E;function y(ee,W,G){try{return{type:"normal",arg:ee.call(W,G)}}catch(re){return{type:"throw",arg:re}}}var A="suspendedStart",C="suspendedYield",I="executing",H="completed",$={};function oe(){}function N(){}function j(){}var Se={};T(Se,h,function(){return this});var ve=Object.getPrototypeOf,k=ve&&ve(ve(se([])));k&&k!==a&&o.call(k,h)&&(Se=k);var D=j.prototype=oe.prototype=Object.create(Se);N.prototype=j,s(D,"constructor",{value:j,configurable:!0}),s(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(W){T(ee,W,function(G){return this._invoke(W,G)})})}n.isGeneratorFunction=function(ee){var W=typeof ee=="function"&&ee.constructor;return W?W===N||(W.displayName||W.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function V(ee,W){function G(be,xe,Ce,le){var ye=y(ee[be],ee,xe);if(ye.type==="throw")le(ye.arg);else{var nt=ye.arg,at=nt.value;return at&&typeof at=="object"&&o.call(at,"__await")?W.resolve(at.__await).then(function(Ee){G("next",Ee,Ce,le)},function(Ee){G("throw",Ee,Ce,le)}):W.resolve(at).then(function(Ee){nt.value=Ee,Ce(nt)},function(Ee){return G("throw",Ee,Ce,le)})}}var re;function ge(be,xe){function Ce(){return new W(function(le,ye){G(be,xe,le,ye)})}return re=re?re.then(Ce,Ce):Ce()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,W,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,W,G,re),ge);return n.isGeneratorFunction(W)?be:be.next().then(function(xe){return xe.done?xe.value:be.next()})};function J(ee,W,G){var re=A;return function(be,xe){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw xe;return st()}for(G.method=be,G.arg=xe;;){var Ce=G.delegate;if(Ce){var le=F(Ce,G);if(le){if(le===$)continue;return le}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===A)throw re=H,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=I;var ye=y(ee,W,G);if(ye.type==="normal"){if(re=G.done?H:C,ye.arg===$)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,W){var G=W.method,re=ee.iterator[G];if(re===r)return W.delegate=null,G==="throw"&&ee.iterator.return&&(W.method="return",W.arg=r,F(ee,W),W.method==="throw")||G!=="return"&&(W.method="throw",W.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,W.arg);if(ge.type==="throw")return W.method="throw",W.arg=ge.arg,W.delegate=null,$;var be=ge.arg;if(!be)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,$;if(be.done)W[ee.resultName]=be.value,W.next=ee.nextLoc,W.method!=="return"&&(W.method="next",W.arg=r);else return be;return W.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,function(){return this}),T(D,"toString",function(){return"[object Generator]"});function X(ee){var W={tryLoc:ee[0]};1 in ee&&(W.catchLoc=ee[1]),2 in ee&&(W.finallyLoc=ee[2],W.afterLoc=ee[3]),this.tryEntries.push(W)}function U(ee){var W=ee.completion||{};W.type="normal",delete W.arg,ee.completion=W}function P(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(X,this),this.reset(!0)}n.keys=function(ee){var W=Object(ee),G=[];for(var re in W)G.push(re);return G.reverse(),function ge(){for(;G.length;){var be=G.pop();if(be in W)return ge.value=be,ge.done=!1,ge}return ge.done=!0,ge}};function se(ee){if(ee){var W=ee[h];if(W)return W.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var G=-1,re=function ge(){for(;++G<ee.length;)if(o.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=r,ge.done=!0,ge};return re.next=re}}return{next:st}}n.values=se;function st(){return{value:r,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(U),!ee)for(var W in this)W.charAt(0)==="t"&&o.call(this,W)&&!isNaN(+W.slice(1))&&(this[W]=r)},stop:function(){this.done=!0;var ee=this.tryEntries[0],W=ee.completion;if(W.type==="throw")throw W.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var W=this;function G(le,ye){return be.type="throw",be.arg=ee,W.next=le,ye&&(W.method="next",W.arg=r),!!ye}for(var re=this.tryEntries.length-1;re>=0;--re){var ge=this.tryEntries[re],be=ge.completion;if(ge.tryLoc==="root")return G("end");if(ge.tryLoc<=this.prev){var xe=o.call(ge,"catchLoc"),Ce=o.call(ge,"finallyLoc");if(xe&&Ce){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(xe){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0)}else if(Ce){if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,W){for(var G=this.tryEntries.length-1;G>=0;--G){var re=this.tryEntries[G];if(re.tryLoc<=this.prev&&o.call(re,"finallyLoc")&&this.prev<re.finallyLoc){var ge=re;break}}ge&&(ee==="break"||ee==="continue")&&ge.tryLoc<=W&&W<=ge.finallyLoc&&(ge=null);var be=ge?ge.completion:{};return be.type=ee,be.arg=W,ge?(this.method="next",this.next=ge.finallyLoc,$):this.complete(be)},complete:function(ee,W){if(ee.type==="throw")throw ee.arg;return ee.type==="break"||ee.type==="continue"?this.next=ee.arg:ee.type==="return"?(this.rval=this.arg=ee.arg,this.method="return",this.next="end"):ee.type==="normal"&&W&&(this.next=W),$},finish:function(ee){for(var W=this.tryEntries.length-1;W>=0;--W){var G=this.tryEntries[W];if(G.finallyLoc===ee)return this.complete(G.completion,G.afterLoc),U(G),$}},catch:function(ee){for(var W=this.tryEntries.length-1;W>=0;--W){var G=this.tryEntries[W];if(G.tryLoc===ee){var re=G.completion;if(re.type==="throw"){var ge=re.arg;U(G)}return ge}}throw new Error("illegal catch attempt")},delegateYield:function(ee,W,G){return this.delegate={iterator:se(ee),resultName:W,nextLoc:G},this.method==="next"&&(this.arg=r),$}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(mv);var Dh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(jh,function(){var t=function(){},n="undefined",a=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function s(C,I){var H=C[I];if(typeof H.bind=="function")return H.bind(C);try{return Function.prototype.bind.call(H,C)}catch{return function(){return Function.prototype.apply.apply(H,[C,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function d(C){return C==="debug"&&(C="log"),typeof console===n?!1:C==="trace"&&a?r:console[C]!==void 0?s(console,C):console.log!==void 0?s(console,"log"):t}function h(C,I){for(var H=0;H<o.length;H++){var $=o[H];this[$]=H<C?t:this.methodFactory($,C,I)}this.log=this.debug}function _(C,I,H){return function(){typeof console!==n&&(h.call(this,I,H),this[C].apply(this,arguments))}}function g(C,I,H){return d(C)||_.apply(this,arguments)}function T(C,I,H){var $=this,oe;I=I??"WARN";var N="loglevel";typeof C=="string"?N+=":"+C:typeof C=="symbol"&&(N=void 0);function j(D){var B=(o[D]||"silent").toUpperCase();if(!(typeof window===n||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return $.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===n||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}$.name=C,$.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},$.methodFactory=H||g,$.getLevel=function(){return oe},$.setLevel=function(D,B){if(typeof D=="string"&&$.levels[D.toUpperCase()]!==void 0&&(D=$.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=$.levels.SILENT){if(oe=D,B!==!1&&j(D),h.call($,D,C),typeof console===n&&D<$.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},$.setDefaultLevel=function(D){I=D,Se()||$.setLevel(D,!1)},$.resetLevel=function(){$.setLevel(I,!1),ve()},$.enableAll=function(D){$.setLevel($.levels.TRACE,D)},$.disableAll=function(D){$.setLevel($.levels.SILENT,D)};var k=Se();k==null&&(k=I),$.setLevel(k,!1)}var E=new T,y={};E.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var H=y[I];return H||(H=y[I]=new T(I,E.getLevel(),E.methodFactory)),H};var A=typeof window!==n?window.log:void 0;return E.noConflict=function(){return typeof window!==n&&window.log===E&&(window.log=A),E},E.getLoggers=function(){return y},E.default=E,E})})(Dh);var It=Dh.exports;const vs=()=>`${new Date().toISOString()} | metrics`,Es=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const gv=c=>{It.info(Es(vs(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},Tv=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Es(vs(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Es(vs(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Es(vs(),c,t),n):It.debug(Es(vs(),c,t))},iu=(c,t)=>{It.info(Es(vs(),c,t))},Rn=(c,t)=>{It.info(Es(vs(),c,t))},wa=(c,t)=>{It.warn(Es(vs(),c,t))},dr=(c,t)=>{It.error(Es(vs(),c,t))};function vv(c){return Math.floor(Math.random()*c).toString()}function xf(c,t){let n=t;return c.forEach(a=>{n=n.replace(a,"")}),n}function Ev(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[vv(c.length)];return n}function Sv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",d=[],h=[],_=[];return t&&(o.length&&(s=xf(o,s)),h=s.split("")),n&&(o.length&&(r=xf(o,r)),_=r.split("")),d=[...h,..._,...a],Ev(d,c)}var yv=Sv;const Qi=ze(yv),Av=()=>"WebRTCMetrics",Cv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},gs={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Ki={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Rv=()=>({...{delta_time_to_measure_probes_ms:0,delta_time_consumed_to_measure_ms:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,total_time_decoded_in:0,total_time_encoded_out:0,probes:[]}}),Nh={level_in:0,codec_id_in:"",codec_in:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,mos_in:0,mos_emodel_in:0,ssrc:"",direction:$e.INBOUND},Uh={level_out:0,codec_id_out:"",codec_out:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,timestamp_out:null,mos_out:0,mos_emodel_out:0,ssrc:"",direction:$e.OUTBOUND},Ph={codec_id_in:"",size_in:{width:null,height:null,framerate:null},codec_in:{mime_type:null,clock_rate:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,decoder_in:null,delta_ms_decode_frame_in:0,total_frames_decoded_in:0,total_time_decoded_in:0,delta_nack_sent_in:0,delta_pli_sent_in:0,total_nack_sent_in:0,total_pli_sent_in:0,ssrc:"",direction:$e.INBOUND},xh={codec_id_out:"",size_out:{width:null,height:null,framerate:null},codec_out:{mime_type:null,clock_rate:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,encoder_out:null,delta_ms_encode_frame_out:0,total_time_encoded_out:0,total_frames_encoded_out:0,delta_nack_received_out:0,delta_pli_received_out:0,total_nack_received_out:0,total_pli_received_out:0,limitation_out:{reason:null,durations:null,resolutionChanges:0},timestamp_out:null,ssrc:"",direction:$e.OUTBOUND},Iv=c=>{const t={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(c){const n={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(a=>{n.audio[a]={...c.audio[a]}}),Object.keys(c.video).forEach(a=>{n.video[a]={...c.video[a]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},bv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Qi()}`,cid:`c-${Qi()}`,uid:`u-${Qi()}`,record:!1,ticket:!0},zt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},x={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Yi={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},lu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},au="config ",wv=(c,t={},n)=>{const a={...n,...t};return t.pname||wa(au,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||wa(au,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||wa(au,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},Ov=(c={})=>{const t={...bv,...c};return t.name=Av(),t.version=Cv(),t},ml=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const d=r[t][o];return d?d[n]:null});return s=s.filter(r=>a?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Gs=c=>c.reduce((t,n)=>t+n,0)/c.length,Dv=()=>`probe-${Qi()}`,Nv=()=>`coltr-${Qi()}`,kf=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},Ke=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((_,g)=>_+g,0)/o.length;return s===0?null:o.map(_=>Math.abs(s-_)).reduce((_,g)=>_+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=ml(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},Sn=(c,t,n)=>ml(c,t,n).reduce((o,s)=>o+s,0),Ye=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Je=(c,t,n,a)=>{const o=ml(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},gt=(c,t,n,a)=>{const o=c.slice().pop();if(!o)return null;if(!n)return o[t];if(!a)return o[t][n];const s=o[t][a];return s?s[n]:null},Uv=c=>c.slice().pop(),ct=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Nh}:{...Uh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ph}:{...xh}),a[x.VIDEO]=s,a},Ji="exporter ",Pv="2.0",Mf=(c,t,n)=>{if(!c||c.length===0)return 0;const a=c[c.length-1];if(!a)return 0;const o=a[t][n];if(o){const s=o.total_rtt_ms_out,r=o.total_rtt_measure_out;return!r||!s?Xe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},xv=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const a=n[t].total_rtt_connectivity_ms,o=n[t].total_rtt_connectivity_measure;return!o||!a?Xe(c,t,"delta_rtt_connectivity_ms"):Number(a/o)},kv=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,Mv=c=>{const t=gt(c,"network","remote_candidate_type"),n=gt(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class Lv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){iu(Ji,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){iu(Ji,"stop() - stop exporter...");const t=new Date;return this._end=t.toJSON(),t}saveReferenceReport(t){this._referenceReport=t}getReferenceReport(){return this._referenceReport}addReport(t){this._cfg.ticket&&(Pe(Ji,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){iu(Ji,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(Ji,"ticket() - generate ticket");const t=gt(this._reports,"audio","total_packets_lost_in"),n=gt(this._reports,"audio","total_packets_in"),a=gt(this._reports,"video","total_packets_lost_in"),o=gt(this._reports,"video","total_packets_in"),s={},r=Uv(this._reports);return r&&(Object.keys(r[x.AUDIO]).forEach(d=>{const h=r[x.AUDIO][d];if(s[h.ssrc]={type:x.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_jitter_ms_in",d),max:Je(this._reports,x.AUDIO,"delta_jitter_ms_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_kbs_in",d),max:Je(this._reports,x.AUDIO,"delta_kbs_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_KBytes_in",d),max:Je(this._reports,x.AUDIO,"delta_KBytes_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_in",!1,d),min:Ye(this._reports,x.AUDIO,"mos_emodel_in",d),max:Je(this._reports,x.AUDIO,"mos_emodel_in",d),volatility:Ke(this._reports,x.AUDIO,"mos_emodel_in",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_in",!1,d),min:Ye(this._reports,x.AUDIO,"mos_in",d),max:Je(this._reports,x.AUDIO,"mos_in",d),volatility:Ke(this._reports,x.AUDIO,"mos_in",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=gt(this._reports,x.AUDIO,"total_packets_lost_in",d),A=gt(this._reports,x.AUDIO,"total_packets_in",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].mos=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}else{const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_jitter_ms_out",d),max:Je(this._reports,x.AUDIO,"delta_jitter_ms_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_kbs_out",d),max:Je(this._reports,x.AUDIO,"delta_kbs_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_KBytes_out",d),max:Je(this._reports,x.AUDIO,"delta_KBytes_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},E={avg:Mf(this._reports,x.AUDIO,d),min:Ye(this._reports,x.AUDIO,"delta_rtt_ms_out",d),max:Je(this._reports,x.AUDIO,"delta_rtt_ms_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=gt(this._reports,x.AUDIO,"total_packets_lost_out",d),A=gt(this._reports,x.AUDIO,"total_packets_out",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},I={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_out",!1,d),min:Ye(this._reports,x.AUDIO,"mos_emodel_out",d),max:Je(this._reports,x.AUDIO,"mos_emodel_out",d),volatility:Ke(this._reports,x.AUDIO,"mos_emodel_out",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_out",!1,d),min:Ye(this._reports,x.AUDIO,"mos_out",d),max:Je(this._reports,x.AUDIO,"mos_out",d),volatility:Ke(this._reports,x.AUDIO,"mos_out",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C,s[d].mos=I}}),Object.keys(r[x.VIDEO]).forEach(d=>{const h=r[x.VIDEO][d];if(s[d]={type:x.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_jitter_ms_in",d),max:Je(this._reports,x.VIDEO,"delta_jitter_ms_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_kbs_in",d),max:Je(this._reports,x.VIDEO,"delta_kbs_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_KBytes_in",d),max:Je(this._reports,x.VIDEO,"delta_KBytes_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E=gt(this._reports,x.VIDEO,"total_packets_lost_in",d),y=gt(this._reports,x.VIDEO,"total_packets_in",d),A={lost:E,avg:Math.round((E/(E+y)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}else{const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_jitter_ms_out",d),max:Je(this._reports,x.VIDEO,"delta_jitter_ms_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_kbs_out",d),max:Je(this._reports,x.VIDEO,"delta_kbs_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_KBytes_out",d),max:Je(this._reports,x.VIDEO,"delta_KBytes_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={avg:Mf(this._reports,x.VIDEO,d),min:Ye(this._reports,x.VIDEO,"delta_rtt_ms_out",d),max:Je(this._reports,x.VIDEO,"delta_rtt_ms_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=gt(this._reports,x.VIDEO,"total_packets_lost_out",d),A=gt(this._reports,x.VIDEO,"total_packets_out",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}})),{version:Pv,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:xv(this._reports,"data"),min:Ye(this._reports,"data","delta_rtt_connectivity_ms"),max:Je(this._reports,"data","delta_rtt_connectivity_ms"),volatility:Ke(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((t/(t+n)*100||0)*100)/100}},video:{in:{avg:Math.round((a/(a+o)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min:Ye(this._reports,"data","delta_kbs_in"),max:Je(this._reports,"data","delta_kbs_in"),volatility:Ke(this._reports,"data","delta_kbs_in")},out:{avg:Xe(this._reports,"data","delta_kbs_out"),min:Ye(this._reports,"data","delta_kbs_out"),max:Je(this._reports,"data","delta_kbs_out"),volatility:Ke(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:Xe(this._reports,"data","delta_KBytes_in"),min:Ye(this._reports,"data","delta_KBytes_in"),max:Je(this._reports,"data","delta_KBytes_in"),volatility:Ke(this._reports,"data","delta_KBytes_in")},out:{avg:Xe(this._reports,"data","delta_KBytes_out"),min:Ye(this._reports,"data","delta_KBytes_out"),max:Je(this._reports,"data","delta_KBytes_out"),volatility:Ke(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:kv(this._reports),remoteConnection:Mv(this._reports)}}}}updateConfig(t){this._cfg=t}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const t=this._reports.slice();return t.pop(),t.pop()||null}getReportsNumber(){return this._reports.length}}const js="extractor ",Lf=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,d=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,_={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[q.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return _;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=s+g,E=r+1;return o&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},$v=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:a[t].total_rtt_connectivity_ms,totalRTTMeasurements:a[t].total_rtt_connectivity_measure};const o=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let s=a[t].total_rtt_connectivity_ms+o,r=a[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(r=Number(c[q.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},da=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),Hv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[x.VIDEO].total_frames_decoded_in,total_decode_time:t[x.VIDEO].total_time_decoded_in};const n=c[q.FRAMES_DECODED],a=c[q.TOTAL_DECODE_TIME],o=a-t[x.VIDEO].total_time_decoded_in,s=n-t[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},Fv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[x.VIDEO].total_frames_encoded_out,total_encode_time:t[x.VIDEO].total_time_encoded_out};const n=c[q.FRAMES_ENCODED],a=c[q.TOTAL_ENCODE_TIME],o=a-t[x.VIDEO].total_time_encoded_out,s=n-t[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},$f=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const o=Number(c[q.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[q.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),d=r-n[t].total_KBytes_out,h=c[q.TIMESTAMP]||Date.now(),_=a?a.timestamp:null;let g=n.timestamp;!g&&_&&(g=_);const T=g?h-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:d,kbsSent:E}},Hf=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(o=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(r=Number(100*c[q.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Ff=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_RECEIVED))return{percent_packets_lost:n[t].percent_packets_lost_in,packetsReceived:n[t].total_packets_in,packetsLost:n[t].total_packets_lost_in,bytesReceived:n[t].total_KBytes_in};const o=Number(c[q.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,d=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+d):0,_=Number(c[q.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=_-n[t].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=a?a.timestamp:null;let y=n.timestamp;!y&&E&&(y=E);const A=y?T-y:0,C=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:d,packetsLost:s,deltaPacketsLost:r,KBytesReceived:_,deltaKBytesReceived:g,kbsReceived:C}},jv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",qv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return Yi.WIFI;switch(c[q.NETWORK_TYPE]){case lu.ETHERNET:return Yi.ETHERNET;case lu.CELLULAR_4G:return Yi.CELLULAR_4G;case lu.WIFI:return Yi.WIFI;default:return Yi.CELLULAR}},jf=c=>!Object.prototype.hasOwnProperty.call(c,q.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,q.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[q.FRAME_WIDTH]||null,height:c[q.FRAME_HEIGHT]||null,framerate:c[q.FRAMES_PER_SECOND]},Vv=c=>{const t=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return a&&Object.keys(a).forEach(o=>{a[o]>1e3&&(a[o]=Number(a[o]/1e3))}),{reason:t,durations:a,resolutionChanges:n}},Bv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_sent_in:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_sent_in,deltaNackCount:o-t[x.VIDEO].total_nack_sent_in}},Gv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_received_out:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_received_out,deltaNackCount:o-t[x.VIDEO].total_nack_received_out}},Wv=c=>({channels:c[q.CHANNELS]||null,clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null,sdp_fmtp_line:c[q.SDP_FMTP_LINE]||null}),Kv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),Yv=(c,t,n)=>{const a=(c[q.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[q.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[q.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,d=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let _=t.timestamp;!_&&h&&(_=h);const g=_?s-_:0,T=g>0?r*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Jv=c=>{const t=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},zv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case zt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(o=!1)),o){const r=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],h=Yv(c,t,a),_=Jv(c),g=$v(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:_.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:_.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case zt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:qv(c)}},{type:ne.NETWORK,value:{local_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{local_candidate_protocol:c[q.PROTOCOL]||""}},{type:ne.NETWORK,value:{local_candidate_relay_protocol:jv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[q.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[q.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ff(c,x.AUDIO,d,h),g=da(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:_.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:_.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:_.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:_.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:_.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:_.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:_.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:_.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=Hv(c,d),g=Ff(c,x.VIDEO,d,h),T=da(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,A=jf(c),C=Bv(c,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:r,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:r,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:_.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:_.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:_.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:C.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:C.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:C.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:C.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:A}}]}break}case zt.OUTBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=$f(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:_}},{ssrc:r,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=Fv(c,d),E=jf(c),y=Vv(c),A=Gv(c,d,h),C=$f(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:C.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:C.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:C.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:C.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:C.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:_}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_received_out:A.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_received_out:A.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_received_out:A.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_received_out:A.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_out:E}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:y}}]}break}case zt.MEDIA_SOURCE:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.TRACK:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.CODEC:const s=[];return Object.keys(t[x.AUDIO]).forEach(r=>{const d=t[x.AUDIO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Wv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[x.VIDEO]).forEach(r=>{const d=t[x.VIDEO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Kv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case zt.REMOTE_INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND),h=ct(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Lf(c,x.AUDIO,h,d),g=da(c,x.AUDIO,d),T=Hf(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const _=Lf(c,x.VIDEO,h,d),g=da(c,x.VIDEO,d),T=Hf(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ka=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Xv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),n&&E&&_.push(E),a&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=93.2-g,N=.18*oe*oe-27.9*oe+1126.62,j=(H+$)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,k=N-ve;return Ka(k)},Qv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),n&&C&&_.push(C),a&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,k=(N+j)/2,D=k-177.3<0?0:1,B=.024*k+.11*(k-177.3)*D,V=ve-B;return Ka(V)},Zv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),r&&E&&_.push(E),d&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=0,N=19.8,j=29.7,Se=30,ve=(H+$)/2+Se,k=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*k,V=93.2-(oe+N*Math.log(1+j*g)+D);return Ka(V)},eE=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),r&&C&&_.push(C),d&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=0,ve=19.8,k=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,X=93.2-(Se+ve*Math.log(1+k*g)+J);return Ka(X)};class tE{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=Nv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new Lv(t),this._state=gs.IDLE,this.registerToPCEvents(),Rn(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===zt.INBOUND_RTP?{...Nh}:{...Uh}:_===zt.INBOUND_RTP?{...Ph}:{...xh},r=Iv(n);r.pname=this._config.pname,r.call_id=this._config.cid,r.user_id=this._config.uid,r.count=n?n.count+1:1;let d=null;return t.forEach(h=>{!d&&h.timestamp&&(d=h.timestamp),zv(h,r,r.pname,o).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,h.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=d,Object.keys(r[x.AUDIO]).forEach(h=>{const _=r[x.AUDIO][h];_.direction===$e.INBOUND?(_.mos_emodel_in=Xv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Zv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Qv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=eE(r,x.AUDIO,n,a,_.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const a=Date.now();setTimeout(async()=>{try{const o=Date.now()-a,s=Date.now(),r=await this._config.pc.getStats(),d=this.analyze(r,null,null,null),h=Date.now();d.experimental.time_to_measure_ms=h-s,d.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(o){n(o)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==gs.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),a=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),o=Date.now();return a.experimental.time_to_measure_ms=o-t,this._exporter.addReport(a),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return dr(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=gs.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=gs.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=gs.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=gs.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(this._moduleName,`registered callback '${t}'`)):dr(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,t)}updateConfig(t){this._config=t,this._exporter.updateConfig(t)}get state(){return this._state}set state(t){this._state=t,Pe(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,a,o){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:a,description:o})}async registerToPCEvents(){const{pc:t}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const n=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch{dr(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===Ki.CONNECTED||a===Ki.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.DISCONNECTED||a===Ki.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const a=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",a,"ICE gathering state")},t.ontrack=a=>{this.addCustomEvent(new Date().toJSON(),"call",`${a.track.kind}track`,"MediaStreamTrack received")},t.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=t.getReceivers();if(n&&n.length>0){const a=n[0],{transport:o}=a;if(o){const{iceTransport:s}=o;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class sE{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||Dv(),this._moduleName=this._id,Rn(this._moduleName,"probe created"),this._config=t,this._collector=new tE(this._config,this._id)}set onreport(t){t?this._collector.registerCallback("onreport",t):this._collector.unregisterCallback("onreport")}set onticket(t){t?this._collector.registerCallback("onticket",t):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(t){this._collector.state=t}addCustomEvent(t,n,a,o=new Date().toJSON()){this._collector.addCustomEvent(o,n,t,a)}get isRunning(){return this._collector.state===gs.RUNNING}get isIdle(){return this._collector.state===gs.IDLE}updateUserId(t){this._config.uid=t,this._collector.updateConfig(this._config)}updateCallId(t){this._config.cid=t,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){wa(this._moduleName,"probe is already running");return}this._collector.start()}stop(t=!1){this.isRunning&&this._collector.stop(t)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const Rt="engine ";class nE{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},Rn(Rt,`configured for probing every ${this._config.refreshEvery}ms`),Rn(Rt,`configured for starting after ${this._config.startAfter}ms`),Rn(Rt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(Rt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(t=>t.isRunning)}get isIdle(){return this._probes.every(t=>t.isIdle)}addNewProbe(t,n){if(!t)throw new Error("undefined peer connection");const a=wv(t,n,this._config),o=new sE(a);return this._probes.push(o),Pe(Rt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===gs.RUNNING&&t.stop(),this._probes=this._probes.filter(n=>t.id!==n.id)}async start(){const t=()=>{this._probes.forEach(s=>s.start())},n=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),a=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,o=async()=>{const s=Rv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(Rt,`got probe ${d.id}`),await kf(0)}return s.delta_time_to_measure_probes_ms=Sn(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=Sn(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=Sn(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=Sn(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=Sn(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=Sn(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=Sn(s.probes,"video","total_time_encoded_out"),s};for(Pe(Rt,"starting to collect"),t(),Pe(Rt,"generating reference reports..."),await n(),Pe(Rt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(Rt,`wait ${this._config.refreshEvery}ms before collecting`),await kf(this._config.refreshEvery),a()){Pe(Rt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(Rt,"collected")}Pe(Rt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};Rn(Rt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(Rt,`registered callback '${t}'`)):dr(Rt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReports(t){this._callbacks.onresult&&t.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const rE="interface ";class iE{constructor(t){this._config=Ov(t),Rn(rE,`welcome to ${this._config.name} version ${this._config.version}`),gv(this._config.verbose||!1),this._engine=new nE(this._config)}setupLogLevel(t){Tv(t)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(t,n){return this._engine.addNewProbe(t,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(t){this._engine.removeExistingProbe(t)}set onresult(t){t?this._engine.registerCallback("onresult",t):this._engine.unregisterCallback("onresult")}}function lE(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const aE=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class oE{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=Cn.createAnalyser(),o=Cn.createMediaStreamSource(t),s=Cn.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(Cn.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const _a={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},uE=0;class cE{constructor(t){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new oE({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(t){this.currentActiveRoomIdValue=t,this.context.emit("currentActiveRoomChanged",t)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(t){this.isCallAddingInProgress=t,this.context.emit("callAddingInProgressChanged",t)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get speakerVolume(){return this.speakerVolumeValue}get microphoneInputLevel(){return this.microphoneInputLevelValue}get getActiveCalls(){return this.activeCalls}get hasActiveCalls(){return Object.values(this.extendedCalls).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audiooutput")}get getUserMediaConstraints(){return wh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(t){this.availableMediaDevices=t,this.context.emit("changeAvailableDeviceList",t)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}async initializeMediaDevices(){const t=localStorage.getItem(_a.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(_a.SELECTED_OUTPUT_DEVICE)||"default";try{const a=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),o=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(o),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),a.getTracks().forEach(s=>s.stop())}catch(a){console.error(a)}}setCallTime(t){const n={...t};delete n.callId,this.callTime={...this.callTime,[t.callId]:n},this.context.emit("changeCallTime",this.callTime)}removeCallTime(t){const n={...this.callTime};delete n[t],this.callTime={...n},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(t,n){this.timeIntervals={...this.timeIntervals,[t]:n}}removeTimeInterval(t){const n={...this.timeIntervals};n[t]&&(clearInterval(n[t]),delete n[t],this.timeIntervals={...n})}stopCallTimer(t){this.removeTimeInterval(t),this.removeCallTime(t)}emitVolumeChange(t,n){this.context.emit("changeCallVolume",{callId:t,volume:n})}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9]+$/g.test(n))throw new Error("Not allowed character in DTMF input");this.extendedCalls[t].sendDTMF(n)}setIsMuted(t){this.muted=t,this.context.emit("changeIsMuted",t)}processMute(t){const n=this.currentActiveRoomId;this.setIsMuted(t),this.initialStreamValue.getTracks().forEach(a=>a.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:a}){const o=this.extendedCalls[t];o._automaticHold=a??!1,await new Promise(d=>{const h=()=>{o.putOnHoldTimestamp=n?Date.now():void 0,d()};n?o.hold({},h):o.unhold({},h)}),this.updateCall(o);const r=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(n?t!==d._id:!0));r.length>1&&await this.doConference(r)}holdCall(t,n=!1){return this.processHold({callId:t,automatic:n,toHold:!0})}unholdCall(t){return this.processHold({callId:t,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(t=>t.direction==="outgoing"&&t.status===uE).forEach(t=>this.terminateCall(t._id))}answerCall(t){const n=this.extendedCalls[t];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",a=>{this.triggerAddStream(a,n)})}async moveCall(t,n){this.updateCallStatus({callId:t,isMoving:!0}),await this.processRoomChange({callId:t,roomId:n}),this.updateCallStatus({callId:t,isMoving:!1})}updateCall(t){this.activeCalls[t._id]=Nf(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const a={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...a}},this.context.emit("updateRoom",{room:a,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,o=t.request.getHeader("Call-Info");return o&&n.test(o)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:Nf(t)},this.extendedCalls[t._id]=t,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(t){this.callStatus={...this.callStatus,[t]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(t){const a={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(a.isMoving=t.isMoving),t.isTransferring!==void 0&&(a.isTransferring=t.isTransferring),t.isMerging!==void 0&&(a.isMerging=t.isMerging),this.callStatus={...this.callStatus,[t.callId]:{...a}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(t){const n={...this.callStatus};delete n[t],this.callStatus={...n},this.context.emit("changeCallStatus",this.callStatus)}addRoom(t){this.activeRooms={...this.activeRooms,[t.roomId]:t},this.context.emit("addRoom",{room:t,roomList:this.activeRooms})}getActiveStream(){const t=Pf(this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:a})=>a===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(a=>a.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async a=>{const o=this.getActiveStream();a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:o})=>o===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const a=n.filter(o=>o.roomId===this.currentActiveRoomId);a.length===1?n.forEach(o=>{var s;(s=o.audioTag)==null||s.setSinkId(t),this.updateCall(o)}):await this.doConference(a)}removeRoom(t){const n={...this.activeRooms},a={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:a,roomList:this.activeRooms})}deleteRoomIfEmpty(t){t!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===t).length===0&&(this.removeRoom(t),this.currentActiveRoomId===t&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(t){this.muted?t.mute({audio:!0}):t.unmute({audio:!0})}async roomReconfigure(t){var a;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(o=>o.roomId===t);if(this.currentActiveRoomId===t?n.forEach(o=>{o.audioTag&&(this.muteReconfigure(o),o.audioTag.muted=!1,this.updateCall(o))}):n.forEach(o=>{o.audioTag&&(o.audioTag.muted=!0,this.updateCall(o))}),n.length===0)this.deleteRoomIfEmpty(t);else if(n.length===1&&this.currentActiveRoomId!==t)n[0].isOnHold().local||await this.holdCall(n[0].id,!0);else if(n.length===1&&this.currentActiveRoomId===t){if(n[0].isOnHold().local&&n[0]._automaticHold&&await this.unholdCall(n[0].id),n[0].connection&&((a=n[0].connection)!=null&&a.getSenders()[0])){const o=this.getActiveStream();await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.muteReconfigure(n[0])}}else n.length>1&&await this.doConference(n)}async doConference(t){const n=[];t.forEach(a=>{a!=null&&a.connection.getReceivers().forEach(o=>{n.push(o.track)})}),await pv.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=Cn.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&Cn.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();Cn.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status!==8&&n.terminate()}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const a=this.extendedCalls[t];if(!a._is_confirmed&&!a._is_canceled){const o=`sip:${n}@${this.context.sipDomain}`;a.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${o}`]});return}this.updateCallStatus({callId:t,isTransferring:!0}),a.refer(`sip:${n}@${this.context.sipDomain}`),this.updateCall(a)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const a=n[0],o=n[1];!a||!o||(this.updateCallStatus({callId:a._id,isMerging:!0}),this.updateCallStatus({callId:o._id,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a))}mergeCallByIds(t,n){const a=Object.values(this.extendedCalls).find(s=>s._id===t),o=Object.values(this.extendedCalls).find(s=>s._id===n);if(!a||!o)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a)}setDND(t){this.isDNDEnabled=t,this.context.emit("changeIsDND",t)}startCallTimer(t){this.removeTimeInterval(t);const n={callId:t,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const a=setInterval(()=>{const o={...this.callTime[t]},s=hv(o);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,a)}async setActiveRoom(t){const n=this.currentActiveRoomId;t!==n&&(this.currentActiveRoomId=t,await this.roomReconfigure(n),await this.roomReconfigure(t))}getNewRoomId(){const t=Object.keys(this.activeRooms);return t.length===0?1:parseInt(t.sort()[t.length-1])+1}async setupCall(t){var _,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const o=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:o};n.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(_=n._remote_identity)==null?void 0:_._uri)==null?void 0:g._user),s.incomingInProgress=!0,this.context.subscribe(Xt.CALL_CONFIRMED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.startCallTimer(n.id))}),this.context.subscribe(Xt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.deleteRoomIfEmpty(o))})):n.direction==="outgoing"&&(n.once("confirmed",()=>{this.startCallTimer(n.id)}),this.startCallTimer(n.id));const r=n,d=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);r.roomId=o,r.localMuted=!1,r.autoAnswer=h,h?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),h&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const a={...this.extendedCalls};delete a[t],this.extendedCalls={...a},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){var o;const n=this.extendedCalls[t._id];this.stopVUMeter("origin"),(o=n.connection)==null||o.getSenders().forEach(s=>{s.track.stop()});const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a)}async newRTCSessionCallback(t){const n=t.session;if(this.isDND){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Xt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("progress",a=>{var o,s;this.context.logger.log("Session in progress for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:n,event:a}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("confirmed",a=>{var o,s;this.context.logger.log("Session confirmed for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;this.setActiveRoom(a)}}setMuteWhenJoin(t){this.muteWhenJoinEnabled=t,this.context.emit("changeMuteWhenJoin",t)}setMicrophoneSensitivity(t){if(t<0||t>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=t,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(t){this.speakerVolumeValue=t,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=t,this.updateCall(n))})}setAutoAnswer(t){this.isAutoAnswer=t}setSelectedInputDevice(t){localStorage.setItem(_a.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(_a.SELECTED_OUTPUT_DEVICE,t),this.selectedMediaDevices.output=t,this.context.emit("changeActiveOutputMediaDevice",t)}setCallMetrics(t){const n={...t};delete n.callId,this.callMetrics={...this.callMetrics,[t.callId]:n},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(t){const n={...this.callMetrics};delete n[t],this.callMetrics={...n},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(t){const n=new iE(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id}),o=[];let s;a.onreport=r=>{Object.entries(r.audio).forEach(([_,g])=>{g.direction==="inbound"&&!o.includes(_)&&(o.push(_),s=_)});const d=r.audio[s];if(!d)return;const h=lE(d,aE);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Xt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(t,n){this.VUMeter.start(t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){const t=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=t}async triggerAddStream(t,n){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const a=Pf(this.initialStreamValue,this.microphoneInputLevel*2),o=this.isMuted||this.muteWhenJoin;a.getTracks().forEach(r=>r.enabled=!o),this.setActiveStream(a),await n.connection.getSenders()[0].replaceTrack(a.getTracks()[0]);const s=new MediaStream([t.track]);zT(s,n,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(s,n._id),this.getCallQuality(n),this.updateCall(n)}initCall(t,n,a=!1){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=o.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),a)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==o.id);for(const r of s)this.holdCall(r._id,!0)}o.connection.addEventListener("track",s=>{this.triggerAddStream(s,o)})}async processRoomChange({callId:t,roomId:n}){const a=this.extendedCalls[t].roomId;this.extendedCalls[t].roomId=n;const o=this.extendedCalls[t];return this.updateCall(o),await this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})}}class fE{constructor(t){this.context=t}get sipOptions(){return{...this.context.options.sipOptions}}initCall(t,n){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${t}@${this.context.sipDomain}`,n,this.sipOptions)}stop(t={}){this.context.terminateJanusSessions(t)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(t){this.context.changeMediaConstraints(t)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class hE{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(t){const n=this.extendedMessages[t];this.updateMSRPSession(n)}updateMSRPSession(t){this.activeMessages[t._id]=Uf(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Uf(t)},this.extendedMessages[t._id]=t,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(t,n){const a=this.msrpHistory[n.id]||[];a.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...a]},this.context.emit("newMSRPMessage",{message:t,session:n})}messageTerminate(t){const n=this.extendedMessages[t];n._status!==8&&n.terminate()}addMessageSession(t){if(!t._id||this.getActiveMessages[t._id]!==void 0)return;const a=t;this.addMMSRPSession(a)}triggerMSRPListener({listenerType:t,session:n,event:a}){const o=this.context.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const a={...this.extendedMessages};delete a[t],this.extendedMessages={...a},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){const n=t.session;n.on("ended",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("failed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_FAILED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("confirmed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateMSRPSession(n)}),n.on("newMessage",a=>{this.addMSRPMessage(a,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,a){if(t.length===0)return console.error("Target must be a valid string");const o=this.context.startMSRP(t,a);o.on("active",()=>{this.addMessageSession(o),o.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const a=this.extendedMessages[t];if(!a)throw new Error(`MSRP session with id ${t} doesn't exist!`);a.sendMSRP(n)}}const ou={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class kh{constructor(t){this.opensips=null,this.session=null,this.name=null,this.name=t}setOpensips(t){this.opensips=t}setSession(t){this.session=t}kill(){this.opensips.kill(this.name)}}class Mh extends kh{constructor(t,n){super(t),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(t={}){this.opaqueId=this.session.generateOpaqueId();const n=ke.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new In("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(a.from_display_name=t.fromDisplayName),n.push(`Contact: ${this.session._contact}`),n.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&n.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,a,n),this._createRTCConnection(),this._sendInitialRequest()}getStream(){return this.stream}getConnection(){return this._connection}_createRTCConnection(){this._connection=new RTCPeerConnection({iceServers:[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}]});let t;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(t),t=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(t){t.forEach(n=>{this._connection.addTrack(n)})}async _sendInitialRequest(){const t=new sl(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(Pt.PUBLISHER)];this.session.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.session.receivePublishers(g)}catch(g){console.error(g)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handleId,session_id:this.session.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...t},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},s=["Content-Type: application/json",this.session.getPTypeHeader(Pt.ICE)];this.session.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
159
+ `),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendDetach(){const t={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},n=[this.session.getPTypeHeader(Pt.DETACH)];this.session.sendRequest(L.INFO,{extraHeaders:n,body:JSON.stringify(t)}),this.session._ua.emit("pluginDetach",this.name)}async stopMedia(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)}async stop(){await this.session.stopProcessPlugins(this.type);const t=this._connection.getSenders();t.forEach(n=>{const a=n.track;a&&a.stop()}),t.forEach(n=>{this._connection.removeTrack(n)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class Lh extends kh{constructor(t,n,a={}){super(t),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=a.immediate||!1,this.type=n}start(t){return t}stop(){throw new Error("stop method is not implemented")}async process(t){if(this.immediate){const n=await this.start(t);return this.running=!0,n}return t}async connect(){this.running=!0,await this.session.resyncPlugins(this.type)}terminate(){this.stop()}async kill(){this.stop(),this.running=!1,await this.session.resyncPlugins(this.type)}}class dE extends VT{constructor(t,n){if(!t.modules.length)throw new Error("options.modules should include at least 1 module");const a={...t.configuration,sockets:t.socketInterfaces.map(o=>new fv.WebSocketInterface(o))};super(a),this.initialized=!1,this.connected=!1,this.logger=console,this.newRTCSessionEventName="newRTCSession",this.registeredEventName="registered",this.unregisteredEventName="unregistered",this.disconnectedEventName="disconnected",this.connectedEventName="connected",this.newMSRPSessionEventName="newMSRPSession",this.isReconnecting=!1,this.activeConnection=!1,this.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],t.pnExtraHeaders&&Object.keys(t.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(t.pnExtraHeaders),this.options=t,this.modules=t.modules,n&&XT(n)&&(this.logger=n)}on(t,n){return super.on(t,n)}off(t,n){return super.off(t,n)}emit(t,n){return super.emit(t,n)}get sipDomain(){return this.options.sipDomain}use(t){if(this.newStreamPlugins.find(n=>n.name===t.name)||this.processStreamPlugins.find(n=>n.name===t.name))throw new Error(`Plugin with name ${t.name} already exists`);if(t instanceof Mh)t.setOpensips(this),this.newStreamPlugins.push(t);else if(t instanceof Lh)t.setOpensips(this),this.processStreamPlugins.push(t);else throw new Error("Wrong plugin instance")}getPlugin(t){return this.newStreamPlugins.find(n=>n.name===t)||this.processStreamPlugins.find(n=>n.name===t)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(ou.AUDIO)&&(this.audio=new cE(this)),this.modules.includes(ou.MSRP)&&(this.msrp=new hE(this)),this.modules.includes(ou.VIDEO)&&(this.video=new fE(this)),this.on(this.registeredEventName,()=>{this.logger.log("Successfully registered to",this.options.socketInterfaces[0]),this.setInitialized(!0)}),this.on(this.unregisteredEventName,()=>{this.logger.log("Unregistered from",this.options.socketInterfaces[0]),this.setInitialized(!1)}),this.on(this.connectedEventName,()=>{this.logger.log("Connected to",this.options.socketInterfaces[0]),this.setConnected(!0),this.isReconnecting=!1,this.activeConnection=!0}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.isReconnecting=!0,this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.stop(),this.setInitialized(!1),this.setConnected(!1),this.activeConnection&&setTimeout(this.start.bind(this),5e3))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(t,n){const o=!this.listenersList[t]||!this.listenersList[t].length?[n]:[...this.listenersList[t],n];this.listenersList={...this.listenersList,[t]:o}}removeIListener(t){const n={...this.listenersList};delete n[t],this.listenersList={...n}}triggerListener({listenerType:t,session:n,event:a}){const o=this.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}setInitialized(t){this.initialized=t,this.emit("ready",t)}setConnected(t){this.connected=t,this.emit("connection",t)}}exports.BaseNewStreamPlugin=Mh;exports.BaseProcessStreamPlugin=Lh;exports.default=dE;