@voicenter-team/opensips-js 1.0.130 → 1.0.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -91
- package/dist/opensips-js.cjs.js +131 -132
- package/dist/opensips-js.es.js +13160 -20844
- package/dist/opensips-js.iife.js +131 -132
- package/dist/opensips-js.umd.js +131 -132
- package/package.json +2 -1
- package/src/types/listeners.d.ts +2 -0
package/dist/opensips-js.iife.js
CHANGED
@@ -1,160 +1,159 @@
|
|
1
|
-
var OpensipsJS=function(zt){"use strict";var Ab=Object.defineProperty;var bb=(zt,fs,We)=>fs in zt?Ab(zt,fs,{enumerable:!0,configurable:!0,writable:!0,value:We}):zt[fs]=We;var Cs=(zt,fs,We)=>(bb(zt,typeof fs!="symbol"?fs+"":fs,We),We);var fs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function We(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}const Ha={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.0",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@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"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};var nd=Ha,Tt={USER_AGENT:"".concat(nd.title," ").concat(nd.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 Ga(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ga=function(t){return typeof t}:Ga=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ga(u)}function Va(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Ba(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&&Pr(u,e)}function ja(u){var e=id();return function(){var r=xr(u),l;if(e){var s=xr(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return h0(this,l)}}function h0(u,e){return e&&(Ga(e)==="object"||typeof e=="function")?e:f0(u)}function f0(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function Ri(u){var e=typeof Map=="function"?new Map:void 0;return Ri=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 qa(r,arguments,xr(this).constructor)}return l.prototype=Object.create(r.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}}),Pr(l,r)},Ri(u)}function qa(u,e,t){return id()?qa=Reflect.construct:qa=function(l,s,i){var f=[null];f.push.apply(f,s);var h=Function.bind.apply(l,f),d=new h;return i&&Pr(d,i.prototype),d},qa.apply(null,arguments)}function id(){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 Pr(u,e){return Pr=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Pr(u,e)}function xr(u){return xr=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},xr(u)}var _0=function(u){Ba(t,u);var e=ja(t);function t(r,l){var s;return Va(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}(Ri(Error)),g0=function(u){Ba(t,u);var e=ja(t);function t(r){var l;return Va(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}(Ri(Error)),p0=function(u){Ba(t,u);var e=ja(t);function t(r){var l;return Va(this,t),l=e.call(this),l.code=3,l.name="NOT_SUPPORTED_ERROR",l.message=r,l}return t}(Ri(Error)),m0=function(u){Ba(t,u);var e=ja(t);function t(r){var l;return Va(this,t),l=e.call(this),l.code=4,l.name="NOT_READY_ERROR",l.message=r,l}return t}(Ri(Error)),rn={ConfigurationError:_0,InvalidStateError:g0,NotSupportedError:p0,NotReadyError:m0},_t={},Ec,rd;function Cc(){if(rd)return Ec;rd=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=ln(),l=As();return Ec=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}(),Ec}var Ac,ld;function As(){return ld||(ld=1,Ac=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:He,uri_scheme:vt,uri_scheme_sips:Je,uri_scheme_sip:as,userinfo:Gt,user:er,user_unreserved:tr,password:li,hostport:Ps,host:tn,hostname:ai,domainlabel:sr,toplabel:nr,IPv6reference:oi,IPv6address:Ae,h16:me,ls32:Rt,IPv4address:Es,dec_octet:Rn,port:Dl,uri_parameters:ir,uri_parameter:rr,transport_param:Nl,user_param:Pl,method_param:xl,ttl_param:kl,maddr_param:Ml,lr_param:Ul,other_param:Ll,pname:Fl,pvalue:wn,paramchar:In,param_unreserved:$l,headers:ui,header:ci,hname:Hl,hvalue:On,hnv_unreserved:hi,Request_Response:ec,Request_Line:Gl,Request_URI:lr,absoluteURI:ar,hier_part:Vl,net_path:fi,abs_path:di,opaque_part:Dn,uric:Nn,uric_no_slash:Bl,path_segments:_i,segment:Pn,param:sn,pchar:xn,scheme:jl,authority:ql,srvr:Wl,reg_name:Kl,query:or,SIP_Version:ur,INVITEm:Yl,ACKm:zl,OPTIONSm:Xl,BYEm:Jl,CANCELm:Ql,REGISTERm:Zl,SUBSCRIBEm:ea,NOTIFYm:ta,REFERm:gi,Method:pi,Status_Line:sa,Status_Code:na,extension_code:ia,Reason_Phrase:tc,Allow_Events:Hf,Call_ID:Gf,Contact:cr,contact_param:os,name_addr:us,display_name:kn,contact_params:hr,c_p_q:ra,c_p_expires:xs,delta_seconds:ks,qvalue:ut,generic_param:ct,gen_value:sc,Content_Disposition:nc,disp_type:fr,disp_param:dr,handling_param:ic,Content_Encoding:Vf,Content_Length:Bf,Content_Type:rc,media_type:la,m_type:aa,discrete_type:oa,composite_type:mi,extension_token:vi,x_token:ua,m_subtype:_r,m_parameter:gr,m_value:lc,CSeq:ac,CSeq_value:oc,Expires:jf,Event:Ti,event_type:yi,From:ca,from_param:Si,tag_param:ha,Max_Forwards:qf,Min_Expires:Wf,Name_Addr_Header:Kf,Proxy_Authenticate:fa,challenge:pr,other_challenge:Mn,auth_param:Ms,digest_cln:Ei,realm:da,realm_value:_a,domain:Ci,URI:Ai,nonce:ga,nonce_value:pa,opaque:ma,stale:va,algorithm:Ta,qop_options:bi,qop_value:mr,Proxy_Require:Yf,Record_Route:vr,rec_route:Tr,Reason:ya,reason_param:yr,reason_cause:uc,Require:zf,Route:Sr,route_param:Er,Subscription_State:cc,substate_value:Cr,subexp_params:Ar,event_reason_value:hc,Subject:Xf,Supported:Jf,To:Sa,to_param:Ea,Via:br,via_param:Un,via_params:Rr,via_ttl:Ca,via_maddr:Aa,via_received:ba,via_branch:Ra,response_port:wa,rport:Ia,sent_protocol:Oa,protocol_name:Da,transport:Na,sent_by:Pa,via_host:xa,via_port:wr,ttl:ka,WWW_Authenticate:Qf,Session_Expires:fc,s_e_expires:Ir,s_e_params:Or,s_e_refresher:dc,extension_header:_c,header_value:gc,message_body:Zf,uuid_URI:pc,uuid:cs,hex4:hs,hex8:Ma,hex12:mc,Refer_To:ed,Replaces:vc,call_id:Dr,replaces_param:Nr,to_tag:Ua,from_tag:La,early_flag:Tc};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
|
-
`?(
|
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=vt(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Gt(),c=c!==null?c:"",c!==null?(_=Ps(),_!==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 nn(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 He(){var n,o,c,_,g,m,E,k;return E=i,k=i,n=vt(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Gt(),c=c!==null?c:"",c!==null?(_=Ps(),_!==null?(g=ir(),g!==null?(m=ui(),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 nn(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 vt(){var n;return n=Je(),n===null&&(n=as()),n}function Je(){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 as(){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 Gt(){var n,o,c,_,g,m;return _=i,g=i,n=er(),n!==null?(m=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=li(),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 er(){var n,o;if(o=w(),o===null&&(o=q(),o===null&&(o=tr())),o!==null)for(n=[];o!==null;)n.push(o),o=w(),o===null&&(o=q(),o===null&&(o=tr()));else n=null;return n}function tr(){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 li(){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 Ps(){var n,o,c,_,g;return _=i,n=tn(),n!==null?(g=i,r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Dl(),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 tn(){var n,o;return o=i,n=ai(),n===null&&(n=Es(),n===null&&(n=oi())),n!==null&&(n=function(c){return G.host=r.substring(i,c).toLowerCase(),G.host}(o)),n===null&&(i=o),n}function ai(){var n,o,c,_,g,m;for(_=i,g=i,n=[],m=i,o=sr(),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=sr(),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=nr(),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 sr(){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 nr(){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 oi(){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,Ge,Yt,Ln,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?(Ge=me(),Ge!==null?(r.charCodeAt(i)===58?(Yt=":",i++):(Yt=null,d('":"')),Yt!==null?(Ln=Rt(),Ln!==null?n=[n,o,c,_,g,m,E,k,W,pe,Ge,Yt,Ln]:(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?(Ge=":",i++):(Ge=null,d('":"')),Ge!==null?(Yt=Rt(),Yt!==null?n=[n,o,c,_,g,m,E,k,W,pe,Ge,Yt]:(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=Rt(),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=Rt(),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=Rt(),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?(_=Rt(),_!==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=Rt(),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?(Ge=Rt(),Ge!==null?n=[n,o,c,_,g,m,E,k,W,pe,Ge]:(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=Rt(),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=Rt(),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=Rt(),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=Rt(),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(Cb){return G.host_type="IPv6",r.substring(i,Cb)}(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 Rt(){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=Es()),n}function Es(){var n,o,c,_,g,m,E,k,W;return k=i,W=i,n=Rn(),n!==null?(r.charCodeAt(i)===46?(o=".",i++):(o=null,d('"."')),o!==null?(c=Rn(),c!==null?(r.charCodeAt(i)===46?(_=".",i++):(_=null,d('"."')),_!==null?(g=Rn(),g!==null?(r.charCodeAt(i)===46?(m=".",i++):(m=null,d('"."')),m!==null?(E=Rn(),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 Rn(){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 Dl(){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 ir(){var n,o,c,_;for(n=[],_=i,r.charCodeAt(i)===59?(o=";",i++):(o=null,d('";"')),o!==null?(c=rr(),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=rr(),c!==null?o=[o,c]:(o=null,i=_)):(o=null,i=_);return n}function rr(){var n;return n=Nl(),n===null&&(n=Pl(),n===null&&(n=xl(),n===null&&(n=kl(),n===null&&(n=Ml(),n===null&&(n=Ul(),n===null&&(n=Ll())))))),n}function Nl(){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 Pl(){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 xl(){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=pi(),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 kl(){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=ka(),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 Ml(){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=tn(),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 Ul(){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 Ll(){var n,o,c,_,g,m;return _=i,g=i,n=Fl(),n!==null?(m=i,r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=wn(),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 Fl(){var n,o,c;if(c=i,o=In(),o!==null)for(n=[];o!==null;)n.push(o),o=In();else n=null;return n!==null&&(n=function(_,g){return g.join("")}(c,n)),n===null&&(i=c),n}function wn(){var n,o,c;if(c=i,o=In(),o!==null)for(n=[];o!==null;)n.push(o),o=In();else n=null;return n!==null&&(n=function(_,g){return g.join("")}(c,n)),n===null&&(i=c),n}function In(){var n;return n=$l(),n===null&&(n=w(),n===null&&(n=q())),n}function $l(){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 ui(){var n,o,c,_,g,m,E;if(m=i,r.charCodeAt(i)===63?(n="?",i++):(n=null,d('"?"')),n!==null)if(o=ci(),o!==null){for(c=[],E=i,r.charCodeAt(i)===38?(_="&",i++):(_=null,d('"&"')),_!==null?(g=ci(),g!==null?_=[_,g]:(_=null,i=E)):(_=null,i=E);_!==null;)c.push(_),E=i,r.charCodeAt(i)===38?(_="&",i++):(_=null,d('"&"')),_!==null?(g=ci(),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 ci(){var n,o,c,_,g;return _=i,g=i,n=Hl(),n!==null?(r.charCodeAt(i)===61?(o="=",i++):(o=null,d('"="')),o!==null?(c=On(),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 Hl(){var n,o;if(o=hi(),o===null&&(o=w(),o===null&&(o=q())),o!==null)for(n=[];o!==null;)n.push(o),o=hi(),o===null&&(o=w(),o===null&&(o=q()));else n=null;return n}function On(){var n,o;for(n=[],o=hi(),o===null&&(o=w(),o===null&&(o=q()));o!==null;)n.push(o),o=hi(),o===null&&(o=w(),o===null&&(o=q()));return n}function hi(){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 ec(){var n;return n=sa(),n===null&&(n=Gl()),n}function Gl(){var n,o,c,_,g,m;return m=i,n=pi(),n!==null?(o=O(),o!==null?(c=lr(),c!==null?(_=O(),_!==null?(g=ur(),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 lr(){var n;return n=He(),n===null&&(n=ar()),n}function ar(){var n,o,c,_;return _=i,n=jl(),n!==null?(r.charCodeAt(i)===58?(o=":",i++):(o=null,d('":"')),o!==null?(c=Vl(),c===null&&(c=Dn()),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function Vl(){var n,o,c,_,g;return _=i,n=fi(),n===null&&(n=di()),n!==null?(g=i,r.charCodeAt(i)===63?(o="?",i++):(o=null,d('"?"')),o!==null?(c=or(),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 fi(){var n,o,c,_;return _=i,r.substr(i,2)==="//"?(n="//",i+=2):(n=null,d('"//"')),n!==null?(o=ql(),o!==null?(c=di(),c=c!==null?c:"",c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function di(){var n,o,c;return c=i,r.charCodeAt(i)===47?(n="/",i++):(n=null,d('"/"')),n!==null?(o=_i(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function Dn(){var n,o,c,_;if(_=i,n=Bl(),n!==null){for(o=[],c=Nn();c!==null;)o.push(c),c=Nn();o!==null?n=[n,o]:(n=null,i=_)}else n=null,i=_;return n}function Nn(){var n;return n=b(),n===null&&(n=w(),n===null&&(n=q())),n}function Bl(){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 _i(){var n,o,c,_,g,m;if(g=i,n=Pn(),n!==null){for(o=[],m=i,r.charCodeAt(i)===47?(c="/",i++):(c=null,d('"/"')),c!==null?(_=Pn(),_!==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?(_=Pn(),_!==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 Pn(){var n,o,c,_,g,m;for(g=i,n=[],o=xn();o!==null;)n.push(o),o=xn();if(n!==null){for(o=[],m=i,r.charCodeAt(i)===59?(c=";",i++):(c=null,d('";"')),c!==null?(_=sn(),_!==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?(_=sn(),_!==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 sn(){var n,o;for(n=[],o=xn();o!==null;)n.push(o),o=xn();return n}function xn(){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 jl(){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 ql(){var n;return n=Wl(),n===null&&(n=Kl()),n}function Wl(){var n,o,c,_;return c=i,_=i,n=Gt(),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=Ps(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n=n!==null?n:"",n}function Kl(){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 or(){var n,o;for(n=[],o=Nn();o!==null;)n.push(o),o=Nn();return n}function ur(){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 Yl(){var n;return r.substr(i,6)==="INVITE"?(n="INVITE",i+=6):(n=null,d('"INVITE"')),n}function zl(){var n;return r.substr(i,3)==="ACK"?(n="ACK",i+=3):(n=null,d('"ACK"')),n}function Xl(){var n;return r.substr(i,7)==="OPTIONS"?(n="OPTIONS",i+=7):(n=null,d('"OPTIONS"')),n}function Jl(){var n;return r.substr(i,3)==="BYE"?(n="BYE",i+=3):(n=null,d('"BYE"')),n}function Ql(){var n;return r.substr(i,6)==="CANCEL"?(n="CANCEL",i+=6):(n=null,d('"CANCEL"')),n}function Zl(){var n;return r.substr(i,8)==="REGISTER"?(n="REGISTER",i+=8):(n=null,d('"REGISTER"')),n}function ea(){var n;return r.substr(i,9)==="SUBSCRIBE"?(n="SUBSCRIBE",i+=9):(n=null,d('"SUBSCRIBE"')),n}function ta(){var n;return r.substr(i,6)==="NOTIFY"?(n="NOTIFY",i+=6):(n=null,d('"NOTIFY"')),n}function gi(){var n;return r.substr(i,5)==="REFER"?(n="REFER",i+=5):(n=null,d('"REFER"')),n}function pi(){var n,o;return o=i,n=Yl(),n===null&&(n=zl(),n===null&&(n=Xl(),n===null&&(n=Jl(),n===null&&(n=Ql(),n===null&&(n=Zl(),n===null&&(n=ea(),n===null&&(n=ta(),n===null&&(n=gi(),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 sa(){var n,o,c,_,g,m;return m=i,n=ur(),n!==null?(o=O(),o!==null?(c=na(),c!==null?(_=O(),_!==null?(g=tc(),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 na(){var n,o;return o=i,n=ia(),n!==null&&(n=function(c,_){G.status_code=parseInt(_.join(""))}(o,n)),n===null&&(i=o),n}function ia(){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 tc(){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 Hf(){var n,o,c,_,g,m;if(g=i,n=yi(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=yi(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),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 Gf(){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 cr(){var n,o,c,_,g,m,E;if(g=i,n=j(),n===null)if(m=i,n=os(),n!==null){for(o=[],E=i,c=M(),c!==null?(_=os(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=M(),c!==null?(_=os(),_!==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 os(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=us()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=hr(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=hr(),_!==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 us(){var n,o,c,_,g;return g=i,n=kn(),n=n!==null?n:"",n!==null?(o=be(),o!==null?(c=He(),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 kn(){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,Ge){return pe+Ge[0]+Ge[1]},W[0])}(g,n)),n===null&&(i=g),n}function hr(){var n;return n=ra(),n===null&&(n=xs(),n===null&&(n=ct())),n}function ra(){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=ut(),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 xs(){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=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.params||(G.params={}),G.params.expires=E}(_,n[2])),n===null&&(i=_),n}function ks(){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 ut(){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 ct(){var n,o,c,_,g,m;return _=i,g=i,n=V(),n!==null?(m=i,o=ie(),o!==null?(c=sc(),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 sc(){var n;return n=V(),n===null&&(n=tn(),n===null&&(n=De())),n}function nc(){var n,o,c,_,g,m;if(g=i,n=fr(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=dr(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=dr(),_!==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 fr(){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 dr(){var n;return n=ic(),n===null&&(n=ct()),n}function ic(){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 Vf(){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 Bf(){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=la(),n!==null&&(n=function(c){G=r.substring(i,c)}(o)),n===null&&(i=o),n}function la(){var n,o,c,_,g,m,E,k;if(E=i,n=aa(),n!==null)if(o=K(),o!==null)if(c=_r(),c!==null){for(_=[],k=i,g=Y(),g!==null?(m=gr(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=Y(),g!==null?(m=gr(),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 aa(){var n;return n=oa(),n===null&&(n=mi()),n}function oa(){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=vi()))))),n}function mi(){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=vi())),n}function vi(){var n;return n=V(),n===null&&(n=ua()),n}function ua(){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 _r(){var n;return n=vi(),n===null&&(n=V()),n}function gr(){var n,o,c,_;return _=i,n=V(),n!==null?(o=ie(),o!==null?(c=lc(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function lc(){var n;return n=V(),n===null&&(n=De()),n}function ac(){var n,o,c,_;return _=i,n=oc(),n!==null?(o=D(),o!==null?(c=pi(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function oc(){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 jf(){var n,o;return o=i,n=ks(),n!==null&&(n=function(c,_){G=_}(o,n)),n===null&&(i=o),n}function Ti(){var n,o,c,_,g,m,E;if(g=i,m=i,n=yi(),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=ct(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=ct(),_!==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 yi(){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 ca(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=us()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=Si(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=Si(),_!==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 Si(){var n;return n=ha(),n===null&&(n=ct()),n}function ha(){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 qf(){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 Wf(){var n,o;return o=i,n=ks(),n!==null&&(n=function(c,_){G=_}(o,n)),n===null&&(i=o),n}function Kf(){var n,o,c,_,g,m,E,k,W,pe;for(k=i,W=i,n=[],o=kn();o!==null;)n.push(o),o=kn();if(n!==null)if(o=be(),o!==null)if(c=He(),c!==null)if(_=ke(),_!==null){for(g=[],pe=i,m=Y(),m!==null?(E=ct(),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=ct(),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(Ge){try{G=new H(G.uri,G.display_name,G.params)}catch{G=-1}}()),n===null&&(i=k),n}function fa(){var n;return n=pr(),n}function pr(){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=Ei(),c!==null){for(_=[],k=i,g=M(),g!==null?(m=Ei(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=M(),g!==null?(m=Ei(),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=Mn()),n}function Mn(){var n,o,c,_,g,m,E,k;if(E=i,n=V(),n!==null)if(o=D(),o!==null)if(c=Ms(),c!==null){for(_=[],k=i,g=M(),g!==null?(m=Ms(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=M(),g!==null?(m=Ms(),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 Ms(){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 Ei(){var n;return n=da(),n===null&&(n=Ci(),n===null&&(n=ga(),n===null&&(n=ma(),n===null&&(n=va(),n===null&&(n=Ta(),n===null&&(n=bi(),n===null&&(n=Ms()))))))),n}function da(){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=_a(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function _a(){var n,o;return o=i,n=ce(),n!==null&&(n=function(c,_){G.realm=_}(o,n)),n===null&&(i=o),n}function Ci(){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(_=Ai(),_!==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=Ai(),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=Ai(),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 Ai(){var n;return n=ar(),n===null&&(n=di()),n}function ga(){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=pa(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function pa(){var n,o;return o=i,n=ce(),n!==null&&(n=function(c,_){G.nonce=_}(o,n)),n===null&&(i=o),n}function ma(){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 va(){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 Ta(){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 bi(){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,_=mr(),_!==null){for(g=[],pe=i,r.charCodeAt(i)===44?(m=",",i++):(m=null,d('","')),m!==null?(E=mr(),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=mr(),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 mr(){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 Yf(){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 vr(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Tr(),n!==null){for(o=[],E=i,c=M(),c!==null?(_=Tr(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=M(),c!==null?(_=Tr(),_!==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 Tr(){var n,o,c,_,g,m,E;if(g=i,m=i,n=us(),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=ct(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=ct(),_!==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 ya(){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?(_=yr(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=yr(),_!==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 yr(){var n;return n=uc(),n===null&&(n=ct()),n}function uc(){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 zf(){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 Sr(){var n,o,c,_,g,m;if(g=i,n=Er(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=Er(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),c!==null?(_=Er(),_!==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;if(g=i,n=us(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=ct(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=ct(),_!==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,_,g,m;if(g=i,n=Cr(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Ar(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Ar(),_!==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 Cr(){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 Ar(){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=hc(),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=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){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=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){typeof E<"u"&&(G.retry_after=E)}(_,n[2])),n===null&&(i=_),n===null&&(n=ct()))),n}function hc(){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 Xf(){var n;return n=x(),n=n!==null?n:"",n}function Jf(){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 Sa(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=us()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=Ea(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=Ea(),_!==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 Ea(){var n;return n=ha(),n===null&&(n=ct()),n}function br(){var n,o,c,_,g,m;if(g=i,n=Un(),n!==null){for(o=[],m=i,c=M(),c!==null?(_=Un(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=M(),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,E,k;if(E=i,n=Oa(),n!==null)if(o=D(),o!==null)if(c=Pa(),c!==null){for(_=[],k=i,g=Y(),g!==null?(m=Rr(),m!==null?g=[g,m]:(g=null,i=k)):(g=null,i=k);g!==null;)_.push(g),k=i,g=Y(),g!==null?(m=Rr(),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 Rr(){var n;return n=Ca(),n===null&&(n=Aa(),n===null&&(n=ba(),n===null&&(n=Ra(),n===null&&(n=wa(),n===null&&(n=ct()))))),n}function Ca(){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=ka(),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 Aa(){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=tn(),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 ba(){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=Es(),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 Ra(){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 wa(){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=Ia(),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 Ia(){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 Oa(){var n,o,c,_,g,m;return m=i,n=Da(),n!==null?(o=K(),o!==null?(c=V(),c!==null?(_=K(),_!==null?(g=Na(),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 Da(){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 Na(){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 Pa(){var n,o,c,_,g;return _=i,n=xa(),n!==null?(g=i,o=Ee(),o!==null?(c=wr(),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 xa(){var n,o;return o=i,n=Es(),n===null&&(n=oi(),n===null&&(n=ai())),n!==null&&(n=function(c){G.host=r.substring(i,c)}(o)),n===null&&(i=o),n}function wr(){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 ka(){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 Qf(){var n;return n=pr(),n}function fc(){var n,o,c,_,g,m;if(g=i,n=Ir(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Or(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Or(),_!==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 Ir(){var n,o;return o=i,n=ks(),n!==null&&(n=function(c,_){G.expires=_}(o,n)),n===null&&(i=o),n}function Or(){var n;return n=dc(),n===null&&(n=ct()),n}function dc(){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 _c(){var n,o,c,_;return _=i,n=V(),n!==null?(o=I(),o!==null?(c=gc(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function gc(){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 Zf(){var n,o;for(n=[],o=A();o!==null;)n.push(o),o=A();return n}function pc(){var n,o,c;return c=i,r.substr(i,5)==="uuid:"?(n="uuid:",i+=5):(n=null,d('"uuid:"')),n!==null?(o=cs(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function cs(){var n,o,c,_,g,m,E,k,W,pe,Ge;return pe=i,Ge=i,n=Ma(),n!==null?(r.charCodeAt(i)===45?(o="-",i++):(o=null,d('"-"')),o!==null?(c=hs(),c!==null?(r.charCodeAt(i)===45?(_="-",i++):(_=null,d('"-"')),_!==null?(g=hs(),g!==null?(r.charCodeAt(i)===45?(m="-",i++):(m=null,d('"-"')),m!==null?(E=hs(),E!==null?(r.charCodeAt(i)===45?(k="-",i++):(k=null,d('"-"')),k!==null?(W=mc(),W!==null?n=[n,o,c,_,g,m,E,k,W]:(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge)):(n=null,i=Ge),n!==null&&(n=function(Yt,Ln){G=r.substring(i+5,Yt)}(pe,n[0])),n===null&&(i=pe),n}function hs(){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 Ma(){var n,o,c;return c=i,n=hs(),n!==null?(o=hs(),o!==null?n=[n,o]:(n=null,i=c)):(n=null,i=c),n}function mc(){var n,o,c,_;return _=i,n=hs(),n!==null?(o=hs(),o!==null?(c=hs(),c!==null?n=[n,o,c]:(n=null,i=_)):(n=null,i=_)):(n=null,i=_),n}function ed(){var n,o,c,_,g,m,E;if(g=i,m=i,n=Oe(),n===null&&(n=us()),n!==null){for(o=[],E=i,c=Y(),c!==null?(_=ct(),_!==null?c=[c,_]:(c=null,i=E)):(c=null,i=E);c!==null;)o.push(c),E=i,c=Y(),c!==null?(_=ct(),_!==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 vc(){var n,o,c,_,g,m;if(g=i,n=Dr(),n!==null){for(o=[],m=i,c=Y(),c!==null?(_=Nr(),_!==null?c=[c,_]:(c=null,i=m)):(c=null,i=m);c!==null;)o.push(c),m=i,c=Y(),c!==null?(_=Nr(),_!==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 Dr(){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 Nr(){var n;return n=Ua(),n===null&&(n=La(),n===null&&(n=Tc(),n===null&&(n=ct()))),n}function Ua(){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 La(){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 Tc(){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 td(n){n.sort();for(var o=null,c=[],_=0;_<n.length;_++)n[_]!==o&&(c.push(n[_]),o=n[_]);return c}function yc(){for(var n=1,o=1,c=!1,_=0;_<Math.max(i,f);_++){var g=r.charAt(_);g===`
|
4
|
-
`?(
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var 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=Tt,s=ln(),i=As();_t.str_utf8_length=function(p){return unescape(encodeURIComponent(p)).length};var f=_t.isFunction=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object Function]":!1};_t.isString=function(p){return p!==void 0?Object.prototype.toString.call(p)==="[object String]":!1},_t.isDecimal=function(p){return!isNaN(p)&&parseFloat(p)===parseInt(p,10)},_t.isEmpty=function(p){return p===null||p===""||p===void 0||Array.isArray(p)&&p.length===0||typeof p=="number"&&isNaN(p)},_t.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=_t.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};_t.newTag=function(){return h(10)},_t.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},_t.hostType=function(p){if(p){if(p=i.parse(p,"host"),p!==-1)return p.host_type}else return};var d=_t.escapeUser=function(p){return encodeURIComponent(decodeURIComponent(p)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return _t.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},_t.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},_t.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},_t.getRandomTestNetIP=function(){function p(v,T){return Math.floor(Math.random()*(T-v+1)+v)}return"192.0.2.".concat(p(1,254))},_t.calculateMD5=function(p){function v(ce,de){return ce<<de|ce>>>32-de}function T(ce,de){var ge=ce&2147483648,Oe=de&2147483648,He=ce&1073741824,vt=de&1073741824,Je=(ce&1073741823)+(de&1073741823);return He&vt?Je^2147483648^ge^Oe:He|vt?Je&1073741824?Je^3221225472^ge^Oe:Je^1073741824^ge^Oe:Je^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,He,vt,Je){return ce=T(ce,T(T(y(de,ge,Oe),He),Je)),T(v(ce,vt),de)}function N(ce,de,ge,Oe,He,vt,Je){return ce=T(ce,T(T(S(de,ge,Oe),He),Je)),T(v(ce,vt),de)}function C(ce,de,ge,Oe,He,vt,Je){return ce=T(ce,T(T(A(de,ge,Oe),He),Je)),T(v(ce,vt),de)}function b(ce,de,ge,Oe,He,vt,Je){return ce=T(ce,T(T(R(de,ge,Oe),He),Je)),T(v(ce,vt),de)}function w(ce){for(var de,ge=ce.length,Oe=ge+8,He=(Oe-Oe%64)/64,vt=(He+1)*16,Je=new Array(vt-1),as=0,Gt=0;Gt<ge;)de=(Gt-Gt%4)/4,as=Gt%4*8,Je[de]=Je[de]|ce.charCodeAt(Gt)<<as,Gt++;return de=(Gt-Gt%4)/4,as=Gt%4*8,Je[de]=Je[de]|128<<as,Je[vt-2]=ge<<3,Je[vt-1]=ge>>>29,Je}function F(ce){var de="",ge="",Oe,He;for(He=0;He<=3;He++)Oe=ce>>>He*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()},_t.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()}},_t.cloneArray=function(p){return p&&p.slice()||[]},_t.cloneObject=function(p){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return p&&Object.assign({},p)||v},_t}var Rc={exports:{}},wi=typeof Reflect=="object"?Reflect:null,ud=wi&&typeof wi.apply=="function"?wi.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)},Wa;wi&&typeof wi.ownKeys=="function"?Wa=wi.ownKeys:Object.getOwnPropertySymbols?Wa=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Wa=function(e){return Object.getOwnPropertyNames(e)};function v0(u){console&&console.warn&&console.warn(u)}var cd=Number.isNaN||function(e){return e!==e};function Ke(){Ke.init.call(this)}Rc.exports=Ke,Rc.exports.once=E0,Ke.EventEmitter=Ke,Ke.prototype._events=void 0,Ke.prototype._eventsCount=0,Ke.prototype._maxListeners=void 0;var hd=10;function Ka(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 hd},set:function(u){if(typeof u!="number"||u<0||cd(u))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+u+".");hd=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||cd(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 fd(u){return u._maxListeners===void 0?Ke.defaultMaxListeners:u._maxListeners}Ke.prototype.getMaxListeners=function(){return fd(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")ud(h,this,t);else for(var d=h.length,p=md(h,d),r=0;r<d;++r)ud(p[r],this,t);return!0};function dd(u,e,t,r){var l,s,i;if(Ka(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=fd(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,v0(f)}return u}Ke.prototype.addListener=function(e,t){return dd(this,e,t,!1)},Ke.prototype.on=Ke.prototype.addListener,Ke.prototype.prependListener=function(e,t){return dd(this,e,t,!0)};function T0(){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 _d(u,e,t){var r={fired:!1,wrapFn:void 0,target:u,type:e,listener:t},l=T0.bind(r);return l.listener=t,r.wrapFn=l,l}Ke.prototype.once=function(e,t){return Ka(t),this.on(e,_d(this,e,t)),this},Ke.prototype.prependOnceListener=function(e,t){return Ka(t),this.prependListener(e,_d(this,e,t)),this},Ke.prototype.removeListener=function(e,t){var r,l,s,i,f;if(Ka(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():y0(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 gd(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?S0(l):md(l,l.length)}Ke.prototype.listeners=function(e){return gd(this,e,!0)},Ke.prototype.rawListeners=function(e){return gd(this,e,!1)},Ke.listenerCount=function(u,e){return typeof u.listenerCount=="function"?u.listenerCount(e):pd.call(u,e)},Ke.prototype.listenerCount=pd;function pd(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?Wa(this._events):[]};function md(u,e){for(var t=new Array(e),r=0;r<e;++r)t[r]=u[r];return t}function y0(u,e){for(;e+1<u.length;e++)u[e]=u[e+1];u.pop()}function S0(u){for(var e=new Array(u.length),t=0;t<e.length;++t)e[t]=u[t].listener||u[t];return e}function E0(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))}vd(u,e,s,{once:!0}),e!=="error"&&C0(u,l,{once:!0})})}function C0(u,e,t){typeof u.on=="function"&&vd(u,"error",e,t)}function vd(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 wt=Rc.exports,wc={exports:{}},Ic,Td;function A0(){if(Td)return Ic;Td=1;var u=1e3,e=u*60,t=e*60,r=t*24,l=r*7,s=r*365.25;Ic=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 Ic}function b0(u){t.debug=t,t.default=t,t.coerce=h,t.disable=s,t.enable=l,t.enabled=i,t.humanize=A0(),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 R0=b0;(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=R0(e);const{formatters:f}=u.exports;f.j=function(h){try{return JSON.stringify(h)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}})(wc,wc.exports);var Ii=wc.exports;function w0(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 I0(u,e,t){return e&&yd(u.prototype,e),t&&yd(u,t),u}var Oi=Ii,Di="JsSIP",It=function(){function u(e){w0(this,u),e?(this._debug=Oi.default("".concat(Di,":").concat(e)),this._warn=Oi.default("".concat(Di,":WARN:").concat(e)),this._error=Oi.default("".concat(Di,":ERROR:").concat(e))):(this._debug=Oi.default(Di),this._warn=Oi.default("".concat(Di,":WARN")),this._error=Oi.default("".concat(Di,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return I0(u,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),u}(),Xt={},Sd={},Ed={exports:{}},Cd=Ed.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(Cd).forEach(function(u){var e=Cd[u];e.forEach(function(t){t.reg||(t.reg=/(.*)/),t.format||(t.format="%s")})});var Ad=Ed.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=Ad,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}})})}})(Sd);var Oc=Ad,O0=/%[sdv%]/g,D0=function(u){var e=1,t=arguments,r=t.length;return u.replace(O0,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""}})},kr=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 D0.apply(null,l)},N0=["v","o","s","i","u","e","p","c","b","t","r","z","a"],P0=["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||N0,r=e.innerOrder||P0,l=[];return t.forEach(function(s){Oc[s].forEach(function(i){i.name in u&&u[i.name]!=null?l.push(kr(s,i,u)):i.push in u&&u[i.push]!=null&&u[i.push].forEach(function(f){l.push(kr(s,i,f))})})}),u.media.forEach(function(s){l.push(kr("m",Oc.m[0],s)),r.forEach(function(i){Oc[i].forEach(function(f){f.name in s&&s[f.name]!=null?l.push(kr(i,f,s)):f.push in s&&s[f.push]!=null&&s[f.push].forEach(function(h){l.push(kr(i,f,h))})})})}),l.join(`\r
|
1
|
+
var OpensipsJS=function(Wt){"use strict";var Jv=Object.defineProperty;var zv=(Wt,cs,Me)=>cs in Wt?Jv(Wt,cs,{enumerable:!0,configurable:!0,writable:!0,value:Me}):Wt[cs]=Me;var es=(Wt,cs,Me)=>(zv(Wt,typeof cs!="symbol"?cs+"":cs,Me),Me);var cs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Me(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const vl={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.0",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@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"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};var Ku=vl,st={USER_AGENT:"".concat(Ku.title," ").concat(Ku.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 El(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?El=function(n){return typeof n}:El=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},El(c)}function Sl(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function yl(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&&yr(c,t)}function Al(c){var t=Yu();return function(){var a=Ar(c),o;if(t){var s=Ar(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Fh(this,o)}}function Fh(c,t){return t&&(El(t)==="object"||typeof t=="function")?t:jh(c)}function jh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Dn(c){var t=typeof Map=="function"?new Map:void 0;return Dn=function(a){if(a===null||!qh(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 Cl(a,arguments,Ar(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),yr(o,a)},Dn(c)}function Cl(c,t,n){return Yu()?Cl=Reflect.construct:Cl=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&yr(_,r.prototype),_},Cl.apply(null,arguments)}function Yu(){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 qh(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function yr(c,t){return yr=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yr(c,t)}function Ar(c){return Ar=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ar(c)}var Vh=function(c){yl(n,c);var t=Al(n);function n(a,o){var s;return Sl(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}(Dn(Error)),Bh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(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}(Dn(Error)),Gh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(Dn(Error)),Wh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(Dn(Error)),Is={ConfigurationError:Vh,InvalidStateError:Bh,NotSupportedError:Gh,NotReadyError:Wh},Qe={},za,Ju;function Xa(){if(Ju)return za;Ju=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=bs(),o=ts();return za=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}(),za}var Qa,zu;function ts(){return zu||(zu=1,Qa=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:Z,LHEX:U,token:P,token_nodot:se,separators:it,word:ee,STAR:Y,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:ke,LAQUOT:Re,COMMA:le,SEMI:ye,COLON:lt,LDQUOT:ot,RDQUOT:Ee,comment:Ae,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:de,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:tt,uri_scheme_sips:He,uri_scheme_sip:jt,userinfo:Ct,user:Bn,user_unreserved:Gn,password:cn,hostport:ls,host:As,hostname:fn,domainlabel:Wn,toplabel:Kn,IPv6reference:hn,IPv6address:me,h16:ae,ls32:ut,IPv4address:Zt,dec_octet:$s,port:ui,uri_parameters:Yn,uri_parameter:Jn,transport_param:ci,user_param:fi,method_param:hi,ttl_param:di,maddr_param:_i,lr_param:pi,other_param:mi,pname:gi,pvalue:Hs,paramchar:Fs,param_unreserved:Ti,headers:dn,header:_n,hname:vi,hvalue:js,hnv_unreserved:pn,Request_Response:wa,Request_Line:Ei,Request_URI:zn,absoluteURI:Xn,hier_part:Si,net_path:mn,abs_path:gn,opaque_part:qs,uric:Vs,uric_no_slash:yi,path_segments:Tn,segment:Bs,param:Cs,pchar:Gs,scheme:Ai,authority:Ci,srvr:Ri,reg_name:Ii,query:Qn,SIP_Version:Zn,INVITEm:bi,ACKm:wi,OPTIONSm:Oi,BYEm:Di,CANCELm:Ni,REGISTERm:Ui,SUBSCRIBEm:Pi,NOTIFYm:xi,REFERm:vn,Method:En,Status_Line:ki,Status_Code:Mi,extension_code:Li,Reason_Phrase:Oa,Allow_Events:Du,Call_ID:Nu,Contact:er,contact_param:qt,name_addr:Vt,display_name:Ws,contact_params:tr,c_p_q:$i,c_p_expires:as,delta_seconds:os,qvalue:Je,generic_param:ze,gen_value:Da,Content_Disposition:Na,disp_type:sr,disp_param:nr,handling_param:Ua,Content_Encoding:Uu,Content_Length:Pu,Content_Type:Pa,media_type:Hi,m_type:Fi,discrete_type:ji,composite_type:Sn,extension_token:yn,x_token:qi,m_subtype:rr,m_parameter:ir,m_value:xa,CSeq:ka,CSeq_value:Ma,Expires:xu,Event:An,event_type:Cn,From:Vi,from_param:Rn,tag_param:Bi,Max_Forwards:ku,Min_Expires:Mu,Name_Addr_Header:Lu,Proxy_Authenticate:Gi,challenge:lr,other_challenge:Ks,auth_param:us,digest_cln:In,realm:Wi,realm_value:Ki,domain:bn,URI:wn,nonce:Yi,nonce_value:Ji,opaque:zi,stale:Xi,algorithm:Qi,qop_options:On,qop_value:ar,Proxy_Require:$u,Record_Route:or,rec_route:ur,Reason:Zi,reason_param:cr,reason_cause:La,Require:Hu,Route:fr,route_param:hr,Subscription_State:$a,substate_value:dr,subexp_params:_r,event_reason_value:Ha,Subject:Fu,Supported:ju,To:el,to_param:tl,Via:pr,via_param:Ys,via_params:mr,via_ttl:sl,via_maddr:nl,via_received:rl,via_branch:il,response_port:ll,rport:al,sent_protocol:ol,protocol_name:ul,transport:cl,sent_by:fl,via_host:hl,via_port:gr,ttl:dl,WWW_Authenticate:qu,Session_Expires:Fa,s_e_expires:Tr,s_e_params:vr,s_e_refresher:ja,extension_header:qa,header_value:Va,message_body:Vu,uuid_URI:Ba,uuid:Bt,hex4:Gt,hex8:_l,hex12:Ga,Refer_To:Bu,Replaces:Wa,call_id:Er,replaces_param:Sr,to_tag:pl,from_tag:ml,early_flag:Ka};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 Z(){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 it(){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 Y(){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 ke(){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 Re(){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 lt(){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 ot(){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=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),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=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),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 de(){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=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ct(),u=u!==null?u:"",u!==null?(f=ls(),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 Rs(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=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ct(),u=u!==null?u:"",u!==null?(f=ls(),f!==null?(p=Yn(),p!==null?(m=dn(),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 Rs(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 tt(){var e;return e=He(),e===null&&(e=jt()),e}function He(){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 jt(){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 Ct(){var e,l,u,f,p,m;return f=r,p=r,e=Bn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=cn(),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 Bn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=Gn())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=Gn()));else e=null;return e}function Gn(){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 cn(){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 ls(){var e,l,u,f,p;return f=r,e=As(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ui(),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 As(){var e,l;return l=r,e=fn(),e===null&&(e=Zt(),e===null&&(e=hn())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function fn(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Wn(),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=Wn(),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=Kn(),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 Wn(){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 Kn(){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 hn(){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,Dt,Js,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?(Dt=":",r++):(Dt=null,_('":"')),Dt!==null?(Js=ut(),Js!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js]:(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?(Dt=ut(),Dt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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=ut(),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(Yv){return w.host_type="IPv6",a.substring(r,Yv)}(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 ut(){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=Zt()),e}function Zt(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=$s(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=$s(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=$s(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=$s(),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 $s(){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 ui(){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 Yn(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Jn(),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=Jn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Jn(){var e;return e=ci(),e===null&&(e=fi(),e===null&&(e=hi(),e===null&&(e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi())))))),e}function ci(){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 fi(){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 hi(){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=En(),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 di(){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=dl(),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 _i(){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=As(),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 pi(){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 mi(){var e,l,u,f,p,m;return f=r,p=r,e=gi(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Hs(),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 gi(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Hs(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Fs(){var e;return e=Ti(),e===null&&(e=j(),e===null&&(e=ve())),e}function Ti(){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 dn(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=_n(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=_n(),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=_n(),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 _n(){var e,l,u,f,p;return f=r,p=r,e=vi(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=js(),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 vi(){var e,l;if(l=pn(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function js(){var e,l;for(e=[],l=pn(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));return e}function pn(){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 wa(){var e;return e=ki(),e===null&&(e=Ei()),e}function Ei(){var e,l,u,f,p,m;return m=r,e=En(),e!==null?(l=H(),l!==null?(u=zn(),u!==null?(f=H(),f!==null?(p=Zn(),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 zn(){var e;return e=Ne(),e===null&&(e=Xn()),e}function Xn(){var e,l,u,f;return f=r,e=Ai(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Si(),u===null&&(u=qs()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Si(){var e,l,u,f,p;return f=r,e=mn(),e===null&&(e=gn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Qn(),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 mn(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=Ci(),l!==null?(u=gn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function gn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=Tn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qs(){var e,l,u,f;if(f=r,e=yi(),e!==null){for(l=[],u=Vs();u!==null;)l.push(u),u=Vs();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Vs(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function yi(){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 Tn(){var e,l,u,f,p,m;if(p=r,e=Bs(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Bs(),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=Bs(),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 Bs(){var e,l,u,f,p,m;for(p=r,e=[],l=Gs();l!==null;)e.push(l),l=Gs();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=Gs();l!==null;)e.push(l),l=Gs();return e}function Gs(){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 Ai(){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 Ci(){var e;return e=Ri(),e===null&&(e=Ii()),e}function Ri(){var e,l,u,f;return u=r,f=r,e=Ct(),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=ls(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Ii(){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 Qn(){var e,l;for(e=[],l=Vs();l!==null;)e.push(l),l=Vs();return e}function Zn(){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 bi(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function wi(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Oi(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function Di(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function Ni(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Ui(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Pi(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function xi(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function vn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function En(){var e,l;return l=r,e=bi(),e===null&&(e=wi(),e===null&&(e=Oi(),e===null&&(e=Di(),e===null&&(e=Ni(),e===null&&(e=Ui(),e===null&&(e=Pi(),e===null&&(e=xi(),e===null&&(e=vn(),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 ki(){var e,l,u,f,p,m;return m=r,e=Zn(),e!==null?(l=H(),l!==null?(u=Mi(),u!==null?(f=H(),f!==null?(p=Oa(),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 Mi(){var e,l;return l=r,e=Li(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Li(){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 Oa(){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=Z(),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=Z(),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 Du(){var e,l,u,f,p,m;if(p=r,e=Cn(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=Cn(),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=Cn(),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 Nu(){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 er(){var e,l,u,f,p,m,v;if(p=r,e=Y(),e===null)if(m=r,e=qt(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=qt(),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=qt(),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 qt(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Vt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tr(),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=tr(),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 Vt(){var e,l,u,f,p;return p=r,e=Ws(),e=e!==null?e:"",e!==null?(l=Re(),l!==null?(u=Ne(),u!==null?(f=ke(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ws(){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 tr(){var e;return e=$i(),e===null&&(e=as(),e===null&&(e=ze())),e}function $i(){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=Je(),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 as(){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=os(),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 os(){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 Je(){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 ze(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=Da(),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 Da(){var e;return e=P(),e===null&&(e=As(),e===null&&(e=Oe())),e}function Na(){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;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 nr(){var e;return e=Ua(),e===null&&(e=ze()),e}function Ua(){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 Uu(){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 Pu(){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 Pa(){var e,l;return l=r,e=Hi(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function Hi(){var e,l,u,f,p,m,v,S;if(v=r,e=Fi(),e!==null)if(l=G(),l!==null)if(u=rr(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=ir(),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=ir(),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 Fi(){var e;return e=ji(),e===null&&(e=Sn()),e}function ji(){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=yn()))))),e}function Sn(){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=yn())),e}function yn(){var e;return e=P(),e===null&&(e=qi()),e}function qi(){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 rr(){var e;return e=yn(),e===null&&(e=P()),e}function ir(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=xa(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function xa(){var e;return e=P(),e===null&&(e=Oe()),e}function ka(){var e,l,u,f;return f=r,e=Ma(),e!==null?(l=k(),l!==null?(u=En(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ma(){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 xu(){var e,l;return l=r,e=os(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function An(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Cn(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),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=ze(),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 Cn(){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 Vi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Vt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Rn(),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=Rn(),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 Rn(){var e;return e=Bi(),e===null&&(e=ze()),e}function Bi(){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 ku(){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 Mu(){var e,l;return l=r,e=os(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function Lu(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Ws();l!==null;)e.push(l),l=Ws();if(e!==null)if(l=Re(),l!==null)if(u=Ne(),u!==null)if(f=ke(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=ze(),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=ze(),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 Gi(){var e;return e=lr(),e}function lr(){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=In(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=In(),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=In(),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=Ks()),e}function Ks(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=us(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=us(),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=us(),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 us(){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 In(){var e;return e=Wi(),e===null&&(e=bn(),e===null&&(e=Yi(),e===null&&(e=zi(),e===null&&(e=Xi(),e===null&&(e=Qi(),e===null&&(e=On(),e===null&&(e=us()))))))),e}function Wi(){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=Ki(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ki(){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 bn(){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=ot(),u!==null)if(f=wn(),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=wn(),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=wn(),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 wn(){var e;return e=Xn(),e===null&&(e=gn()),e}function Yi(){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=Ji(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ji(){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 zi(){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 Xi(){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 Qi(){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 On(){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=ot(),u!==null){if(O=r,f=ar(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=ar(),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=ar(),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 ar(){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 $u(){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 or(){var e,l,u,f,p,m,v;if(p=r,m=r,e=ur(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=ur(),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=ur(),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 ur(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Vt(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),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=ze(),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 Zi(){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=cr(),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=cr(),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 cr(){var e;return e=La(),e===null&&(e=ze()),e}function La(){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 Hu(){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 fr(){var e,l,u,f,p,m;if(p=r,e=hr(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=hr(),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=hr(),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 hr(){var e,l,u,f,p,m;if(p=r,e=Vt(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ze(),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=ze(),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 $a(){var e,l,u,f,p,m;if(p=r,e=dr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=_r(),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=_r(),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 dr(){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 _r(){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=Ha(),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=os(),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=os(),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=ze()))),e}function Ha(){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 Fu(){var e;return e=V(),e=e!==null?e:"",e}function ju(){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 el(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Vt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tl(),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=tl(),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 tl(){var e;return e=Bi(),e===null&&(e=ze()),e}function pr(){var e,l,u,f,p,m;if(p=r,e=Ys(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=Ys(),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=Ys(),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 Ys(){var e,l,u,f,p,m,v,S;if(v=r,e=ol(),e!==null)if(l=k(),l!==null)if(u=fl(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=mr(),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=mr(),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 mr(){var e;return e=sl(),e===null&&(e=nl(),e===null&&(e=rl(),e===null&&(e=il(),e===null&&(e=ll(),e===null&&(e=ze()))))),e}function sl(){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=dl(),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 nl(){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=As(),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 rl(){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=Zt(),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 il(){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 ll(){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=al(),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 al(){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 ol(){var e,l,u,f,p,m;return m=r,e=ul(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=cl(),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 ul(){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 cl(){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 fl(){var e,l,u,f,p;return f=r,e=hl(),e!==null?(p=r,l=lt(),l!==null?(u=gr(),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 hl(){var e,l;return l=r,e=Zt(),e===null&&(e=hn(),e===null&&(e=fn())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function gr(){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 dl(){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 qu(){var e;return e=lr(),e}function Fa(){var e,l,u,f,p,m;if(p=r,e=Tr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=vr(),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=vr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Tr(){var e,l;return l=r,e=os(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function vr(){var e;return e=ja(),e===null&&(e=ze()),e}function ja(){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 qa(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Va(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Va(){var e,l;for(e=[],l=J(),l===null&&(l=Z(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=Z(),l===null&&(l=k()));return e}function Vu(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Ba(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Bt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Bt(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=_l(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=Gt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=Gt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=Gt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=Ga(),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(Dt,Js){w=a.substring(r+5,Dt)}(ie,e[0])),e===null&&(r=ie),e}function Gt(){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 _l(){var e,l,u;return u=r,e=Gt(),e!==null?(l=Gt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ga(){var e,l,u,f;return f=r,e=Gt(),e!==null?(l=Gt(),l!==null?(u=Gt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Bu(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Vt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),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=ze(),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 Wa(){var e,l,u,f,p,m;if(p=r,e=Er(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Er(){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 Sr(){var e;return e=pl(),e===null&&(e=ml(),e===null&&(e=Ka(),e===null&&(e=ze()))),e}function pl(){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 ml(){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 Ka(){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 Gu(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 Ya(){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 Rs=bs(),b=Xa(),w={},gl=s[o]();if(gl===null||r!==a.length){var Tl=Math.max(r,d),Ja=Tl<a.length?a.charAt(Tl):null,i=Ya();return new this.SyntaxError(Gu(h),Ja,Tl,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}()),Qa}var Za,Xu;function bs(){if(Xu)return Za;Xu=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=st,d=Rt(),h=ts();return Za=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}}]),_}(),Za}var Qu;function Rt(){if(Qu)return Qe;Qu=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=st,s=bs(),r=ts();Qe.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var d=Qe.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};Qe.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},Qe.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},Qe.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},Qe.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=Qe.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};Qe.newTag=function(){return h(10)},Qe.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},Qe.hostType=function(g){if(g){if(g=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=Qe.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Qe.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},Qe.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},Qe.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},Qe.getRandomTestNetIP=function(){function g(T,E){return Math.floor(Math.random()*(E-T+1)+T)}return"192.0.2.".concat(g(1,254))},Qe.calculateMD5=function(g){function T(pe,de){return pe<<de|pe>>>32-de}function E(pe,de){var _e=pe&2147483648,we=de&2147483648,Ne=pe&1073741824,tt=de&1073741824,He=(pe&1073741823)+(de&1073741823);return Ne&tt?He^2147483648^_e^we:Ne|tt?He&1073741824?He^3221225472^_e^we:He^1073741824^_e^we:He^_e^we}function y(pe,de,_e){return pe&de|~pe&_e}function A(pe,de,_e){return pe&_e|de&~_e}function C(pe,de,_e){return pe^de^_e}function I(pe,de,_e){return de^(pe|~_e)}function H(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(y(de,_e,we),Ne),He)),E(T(pe,tt),de)}function $(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(A(de,_e,we),Ne),He)),E(T(pe,tt),de)}function oe(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(C(de,_e,we),Ne),He)),E(T(pe,tt),de)}function N(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(I(de,_e,we),Ne),He)),E(T(pe,tt),de)}function j(pe){for(var de,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,tt=(Ne+1)*16,He=new Array(tt-1),jt=0,Ct=0;Ct<_e;)de=(Ct-Ct%4)/4,jt=Ct%4*8,He[de]=He[de]|pe.charCodeAt(Ct)<<jt,Ct++;return de=(Ct-Ct%4)/4,jt=Ct%4*8,He[de]=He[de]|128<<jt,He[tt-2]=_e<<3,He[tt-1]=_e>>>29,He}function Se(pe){var de="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),de=de+_e.substr(_e.length-2,2);return de}function ve(pe){for(var de="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);we<128?de+=String.fromCharCode(we):we>127&&we<2048?(de+=String.fromCharCode(we>>6|192),de+=String.fromCharCode(we&63|128)):(de+=String.fromCharCode(we>>12|224),de+=String.fromCharCode(we>>6&63|128),de+=String.fromCharCode(we&63|128))}return de}var k=[],D,B,V,J,F,Z,U,P,se,it=7,ee=12,Y=17,G=22,re=5,ge=9,be=14,ke=20,Re=4,le=11,ye=16,lt=23,ot=6,Ee=10,Ae=15,Ie=21;for(g=ve(g),k=j(g),Z=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=Z,V=U,J=P,F=se,Z=H(Z,U,P,se,k[D+0],it,3614090360),se=H(se,Z,U,P,k[D+1],ee,3905402710),P=H(P,se,Z,U,k[D+2],Y,606105819),U=H(U,P,se,Z,k[D+3],G,3250441966),Z=H(Z,U,P,se,k[D+4],it,4118548399),se=H(se,Z,U,P,k[D+5],ee,1200080426),P=H(P,se,Z,U,k[D+6],Y,2821735955),U=H(U,P,se,Z,k[D+7],G,4249261313),Z=H(Z,U,P,se,k[D+8],it,1770035416),se=H(se,Z,U,P,k[D+9],ee,2336552879),P=H(P,se,Z,U,k[D+10],Y,4294925233),U=H(U,P,se,Z,k[D+11],G,2304563134),Z=H(Z,U,P,se,k[D+12],it,1804603682),se=H(se,Z,U,P,k[D+13],ee,4254626195),P=H(P,se,Z,U,k[D+14],Y,2792965006),U=H(U,P,se,Z,k[D+15],G,1236535329),Z=$(Z,U,P,se,k[D+1],re,4129170786),se=$(se,Z,U,P,k[D+6],ge,3225465664),P=$(P,se,Z,U,k[D+11],be,643717713),U=$(U,P,se,Z,k[D+0],ke,3921069994),Z=$(Z,U,P,se,k[D+5],re,3593408605),se=$(se,Z,U,P,k[D+10],ge,38016083),P=$(P,se,Z,U,k[D+15],be,3634488961),U=$(U,P,se,Z,k[D+4],ke,3889429448),Z=$(Z,U,P,se,k[D+9],re,568446438),se=$(se,Z,U,P,k[D+14],ge,3275163606),P=$(P,se,Z,U,k[D+3],be,4107603335),U=$(U,P,se,Z,k[D+8],ke,1163531501),Z=$(Z,U,P,se,k[D+13],re,2850285829),se=$(se,Z,U,P,k[D+2],ge,4243563512),P=$(P,se,Z,U,k[D+7],be,1735328473),U=$(U,P,se,Z,k[D+12],ke,2368359562),Z=oe(Z,U,P,se,k[D+5],Re,4294588738),se=oe(se,Z,U,P,k[D+8],le,2272392833),P=oe(P,se,Z,U,k[D+11],ye,1839030562),U=oe(U,P,se,Z,k[D+14],lt,4259657740),Z=oe(Z,U,P,se,k[D+1],Re,2763975236),se=oe(se,Z,U,P,k[D+4],le,1272893353),P=oe(P,se,Z,U,k[D+7],ye,4139469664),U=oe(U,P,se,Z,k[D+10],lt,3200236656),Z=oe(Z,U,P,se,k[D+13],Re,681279174),se=oe(se,Z,U,P,k[D+0],le,3936430074),P=oe(P,se,Z,U,k[D+3],ye,3572445317),U=oe(U,P,se,Z,k[D+6],lt,76029189),Z=oe(Z,U,P,se,k[D+9],Re,3654602809),se=oe(se,Z,U,P,k[D+12],le,3873151461),P=oe(P,se,Z,U,k[D+15],ye,530742520),U=oe(U,P,se,Z,k[D+2],lt,3299628645),Z=N(Z,U,P,se,k[D+0],ot,4096336452),se=N(se,Z,U,P,k[D+7],Ee,1126891415),P=N(P,se,Z,U,k[D+14],Ae,2878612391),U=N(U,P,se,Z,k[D+5],Ie,4237533241),Z=N(Z,U,P,se,k[D+12],ot,1700485571),se=N(se,Z,U,P,k[D+3],Ee,2399980690),P=N(P,se,Z,U,k[D+10],Ae,4293915773),U=N(U,P,se,Z,k[D+1],Ie,2240044497),Z=N(Z,U,P,se,k[D+8],ot,1873313359),se=N(se,Z,U,P,k[D+15],Ee,4264355552),P=N(P,se,Z,U,k[D+6],Ae,2734768916),U=N(U,P,se,Z,k[D+13],Ie,1309151649),Z=N(Z,U,P,se,k[D+4],ot,4149444226),se=N(se,Z,U,P,k[D+11],Ee,3174756917),P=N(P,se,Z,U,k[D+2],Ae,718787259),U=N(U,P,se,Z,k[D+9],Ie,3951481745),Z=E(Z,B),U=E(U,V),P=E(P,J),se=E(se,F);var Oe=Se(Z)+Se(U)+Se(P)+Se(se);return Oe.toLowerCase()},Qe.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()}},Qe.cloneArray=function(g){return g&&g.slice()||[]},Qe.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},Qe}var eo={exports:{}},Nn=typeof Reflect=="object"?Reflect:null,Zu=Nn&&typeof Nn.apply=="function"?Nn.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},Rl;Nn&&typeof Nn.ownKeys=="function"?Rl=Nn.ownKeys:Object.getOwnPropertySymbols?Rl=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Rl=function(t){return Object.getOwnPropertyNames(t)};function Kh(c){console&&console.warn&&console.warn(c)}var ec=Number.isNaN||function(t){return t!==t};function Le(){Le.init.call(this)}eo.exports=Le,eo.exports.once=Xh,Le.EventEmitter=Le,Le.prototype._events=void 0,Le.prototype._eventsCount=0,Le.prototype._maxListeners=void 0;var tc=10;function Il(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Le,"defaultMaxListeners",{enumerable:!0,get:function(){return tc},set:function(c){if(typeof c!="number"||c<0||ec(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");tc=c}}),Le.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},Le.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ec(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 sc(c){return c._maxListeners===void 0?Le.defaultMaxListeners:c._maxListeners}Le.prototype.getMaxListeners=function(){return sc(this)},Le.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=ac(h,_),a=0;a<_;++a)Zu(g[a],this,n);return!0};function nc(c,t,n,a){var o,s,r;if(Il(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=sc(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,Kh(d)}return c}Le.prototype.addListener=function(t,n){return nc(this,t,n,!1)},Le.prototype.on=Le.prototype.addListener,Le.prototype.prependListener=function(t,n){return nc(this,t,n,!0)};function Yh(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rc(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=Yh.bind(a);return o.listener=n,a.wrapFn=o,o}Le.prototype.once=function(t,n){return Il(n),this.on(t,rc(this,t,n)),this},Le.prototype.prependOnceListener=function(t,n){return Il(n),this.prependListener(t,rc(this,t,n)),this},Le.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Il(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():Jh(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this},Le.prototype.off=Le.prototype.removeListener,Le.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 ic(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?zh(o):ac(o,o.length)}Le.prototype.listeners=function(t){return ic(this,t,!0)},Le.prototype.rawListeners=function(t){return ic(this,t,!1)},Le.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):lc.call(c,t)},Le.prototype.listenerCount=lc;function lc(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}Le.prototype.eventNames=function(){return this._eventsCount>0?Rl(this._events):[]};function ac(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function Jh(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function zh(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function Xh(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))}oc(c,t,s,{once:!0}),t!=="error"&&Qh(c,o,{once:!0})})}function Qh(c,t,n){typeof c.on=="function"&&oc(c,"error",t,n)}function oc(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 ct=eo.exports,to={exports:{}},so,uc;function Zh(){if(uc)return so;uc=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;so=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 so}function ed(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=Zh(),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=ed;(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}}})(to,to.exports);var Un=to.exports;function sd(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 nd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Pn=Un,xn="JsSIP",ft=function(){function c(t){sd(this,c),t?(this._debug=Pn.default("".concat(xn,":").concat(t)),this._warn=Pn.default("".concat(xn,":WARN:").concat(t)),this._error=Pn.default("".concat(xn,":ERROR:").concat(t))):(this._debug=Pn.default(xn),this._warn=Pn.default("".concat(xn,":WARN")),this._error=Pn.default("".concat(xn,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return nd(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),Nt={},fc={},hc={exports:{}},dc=hc.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(dc).forEach(function(c){var t=dc[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var _c=hc.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=_c,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}})})}})(fc);var no=_c,rd=/%[sdv%]/g,id=function(c){var t=1,n=arguments,a=n.length;return c.replace(rd,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""}})},Cr=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 id.apply(null,o)},ld=["v","o","s","i","u","e","p","c","b","t","r","z","a"],ad=["i","c","b","a"],od=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||ld,a=t.innerOrder||ad,o=[];return n.forEach(function(s){no[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Cr(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Cr(s,r,d))})})}),c.media.forEach(function(s){o.push(Cr("m",no.m[0],s)),a.forEach(function(r){no[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Cr(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Cr(r,d,h))})})})}),o.join(`\r
|
7
7
|
`)+`\r
|
8
|
-
`},
|
9
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,
|
10
|
-
`);for(var
|
11
|
-
`)}}catch(y){
|
12
|
-
`)}}catch(y){
|
13
|
-
`),
|
14
|
-
`),
|
15
|
-
`),this.body){var
|
8
|
+
`},zs=fc,ud=od;Nt.write=ud,Nt.parse=zs.parse,Nt.parseParams=zs.parseParams,Nt.parseFmtpConfig=zs.parseFmtpConfig,Nt.parsePayloads=zs.parsePayloads,Nt.parseRemoteCandidates=zs.parseRemoteCandidates,Nt.parseImageAttributes=zs.parseImageAttributes,Nt.parseSimulcastStreamList=zs.parseSimulcastStreamList;function bl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?bl=function(n){return typeof n}:bl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bl(c)}function ro(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&&io(c,t)}function io(c,t){return io=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},io(c,t)}function lo(c){var t=hd();return function(){var a=wl(c),o;if(t){var s=wl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return cd(this,o)}}function cd(c,t){return t&&(bl(t)==="object"||typeof t=="function")?t:fd(c)}function fd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function hd(){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 wl(c){return wl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},wl(c)}function Lt(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 pc(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 pc(c,t)}}function pc(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 Rr(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 Ol(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var gc=Nt,_d=ft,dt=st,nt=Rt(),Tc=Xa(),pd=ts(),ao=new _d("SIPMessage"),vc=function(){function c(t,n,a,o,s,r){if(Rr(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=nt.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",dt.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 Tc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||nt.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 Tc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+nt.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 Ol(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[nt.headerize(n)]=Array.isArray(a)?a:[a]}},{key:"getHeader",value:function(n){var a=this.headers[nt.headerize(n)];if(a){if(a[0])return a[0]}else{var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=Lt(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[nt.headerize(n)],o=[];if(a){var s=Lt(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"),_=Lt(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[nt.headerize(n)])return!0;var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),o=Lt(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=gc.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=Lt(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=Lt(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 dt.REGISTER:g.push("path","gruu");break;case dt.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case dt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var T=this.ua.configuration.user_agent||dt.USER_AGENT;if(n+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
|
13
|
+
`),n+="Supported: ".concat(g,`\r
|
14
|
+
`),n+="User-Agent: ".concat(T,`\r
|
15
|
+
`),this.body){var E=nt.str_utf8_length(this.body);n+="Content-Length: ".concat(E,`\r
|
16
16
|
\r
|
17
|
-
`),
|
17
|
+
`),n+=this.body}else n+=`Content-Length: 0\r
|
18
18
|
\r
|
19
|
-
`;return
|
20
|
-
`);if(this.method===
|
21
|
-
`)}}catch(
|
22
|
-
`)}}catch(
|
23
|
-
`),
|
24
|
-
`),
|
25
|
-
`),
|
26
|
-
`);var
|
27
|
-
`)}}catch(
|
28
|
-
`),
|
29
|
-
`)):
|
30
|
-
`):
|
31
|
-
`)),
|
32
|
-
`),
|
33
|
-
`,
|
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=nt.cloneArray(this.extraHeaders),n.to=this.to,n.from=this.from,n.call_id=this.call_id,n.cseq=this.cseq,n}}]),c}(),md=function(c){ro(n,c);var t=lo(n);function n(a,o,s,r,d){var h;return Rr(this,n),h=t.call(this,dt.INVITE,a,o,s,r,d),h.transaction=null,h}return Ol(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=nt.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}(vc),Ec=function(){function c(){Rr(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 Ol(c,[{key:"addHeader",value:function(n,a){var o={raw:a};n=nt.headerize(n),this.headers[n]?this.headers[n].push(o):this.headers[n]=[o]}},{key:"getHeader",value:function(n){var a=this.headers[nt.headerize(n)];if(a){if(a[0])return a[0].raw}else return}},{key:"getHeaders",value:function(n){var a=this.headers[nt.headerize(n)],o=[];if(!a)return[];var s=Lt(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[nt.headerize(n)]}},{key:"parseHeader",value:function(n){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=nt.headerize(n),this.headers[n]){if(a>=this.headers[n].length){ao.debug('not so many "'.concat(n,'" headers present'));return}}else{ao.debug('header "'.concat(n,'" not present'));return}var o=this.headers[n][a],s=o.raw;if(o.parsed)return o.parsed;var r=pd.parse(s,n.replace(/-/g,"_"));if(r===-1){this.headers[n].splice(a,1),ao.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[nt.headerize(n)]=[o]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=gc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),gd=function(c){ro(n,c);var t=lo(n);function n(a){var o;return Rr(this,n),o=t.call(this),o.ua=a,o.headers={},o.ruri=null,o.transport=null,o.server_transaction=null,o}return Ol(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||dt.REASON_PHRASE[o]||"",r=nt.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===dt.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),A=Lt(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"),$=Lt(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(nt.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=Lt(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 dt.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case dt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),d&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===dt.OPTIONS?(E+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
|
28
|
+
`),E+="Accept: ".concat(dt.ACCEPTED_BODY_TYPES,`\r
|
29
|
+
`)):o===405?E+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
|
30
|
+
`):o===415&&(E+="Accept: ".concat(dt.ACCEPTED_BODY_TYPES,`\r
|
31
|
+
`)),E+="Supported: ".concat(g,`\r
|
32
|
+
`),d){var k=nt.str_utf8_length(d);E+=`Content-Type: application/sdp\r
|
33
|
+
`,E+="Content-Length: ".concat(k,`\r
|
34
34
|
\r
|
35
|
-
`),
|
35
|
+
`),E+=d}else E+="Content-Length: ".concat(0,`\r
|
36
36
|
\r
|
37
|
-
`);this.server_transaction.receiveResponse(
|
38
|
-
`),h=
|
39
|
-
`)}}catch(
|
40
|
-
`),
|
41
|
-
`),
|
42
|
-
`),
|
43
|
-
`),this.ua.configuration.extra_headers){var
|
44
|
-
`)}}catch(
|
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||dt.REASON_PHRASE[o]||"";var d="SIP/2.0 ".concat(o," ").concat(s,`\r
|
38
|
+
`),h=Lt(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(nt.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=Lt(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}(Dd),B0=function(u){Dc(t,u);var e=Pc(t);function t(){var r;return Mr(this,t),r=e.call(this),r.headers={},r.status_code=null,r.reason_phrase=null,r}return t}(Dd),Us={OutgoingRequest:Od,InitialOutgoingInviteRequest:G0,IncomingRequest:V0,IncomingResponse:B0};function j0(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Nd(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&&Nd(u.prototype,e),t&&Nd(u,t),u}var W0=It,Ls=Vt(),ds=new W0("DigestAuthentication"),K0=function(){function u(e){j0(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 q0(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,Y0=4e3,Pd=5e3,xd={T1:Fs,T2:Y0,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 Ja(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ja=function(t){return typeof t}:Ja=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ja(u)}function Ur(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function kd(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 Lr(u,e,t){return e&&kd(u.prototype,e),t&&kd(u,t),u}function Fr(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&&kc(u,e)}function kc(u,e){return kc=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},kc(u,e)}function $r(u){var e=X0();return function(){var r=Qa(u),l;if(e){var s=Qa(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return z0(this,l)}}function z0(u,e){return e&&(Ja(e)==="object"||typeof e=="function")?e:an(u)}function an(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function X0(){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 Qa(u){return Qa=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Qa(u)}var Hr=wt.EventEmitter,Gr=It,Vr=Tt,Md=Us,bs=xd,Ud=new Gr("NonInviteClientTransaction"),Za=new Gr("InviteClientTransaction"),J0=new Gr("AckClientTransaction"),Ld=new Gr("NonInviteServerTransaction"),eo=new Gr("InviteServerTransaction"),ve={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"},Q0=function(u){Fr(t,u);var e=$r(t);function t(r,l,s,i){var f;Ur(this,t),f=e.call(this),f.type=ve.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(an(f)),f}return Lr(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"send",value:function(){var l=this;this.stateChanged(ve.STATUS_TRYING),this.F=setTimeout(function(){l.timer_F()},bs.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Ud.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Ud.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ve.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 ve.STATUS_TRYING:case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(l);break}else switch(this.state){case ve.STATUS_TRYING:case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_COMPLETED),clearTimeout(this.F),i===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(l),this.K=setTimeout(function(){s.timer_K()},bs.TIMER_K);break;case ve.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ve}}]),t}(Hr),Z0=function(u){Fr(t,u);var e=$r(t);function t(r,l,s,i){var f;Ur(this,t),f=e.call(this),f.type=ve.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=an(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(an(f)),f}return Lr(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"send",value:function(){var l=this;this.stateChanged(ve.STATUS_CALLING),this.B=setTimeout(function(){l.timer_B()},bs.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ve.STATUS_ACCEPTED&&(Za.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Za.debug("Timer M expired for transaction ".concat(this.id)),this.state===ve.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Za.debug("Timer B expired for transaction ".concat(this.id)),this.state===ve.STATUS_CALLING&&(this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Za.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(l){var s=this,i=new Md.OutgoingRequest(Vr.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});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()},bs.TIMER_D),this.transport.send(i)}},{key:"cancel",value:function(l){if(this.state===ve.STATUS_PROCEEDING){var s=new Md.OutgoingRequest(Vr.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),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 ve.STATUS_CALLING:this.stateChanged(ve.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(l);break;case ve.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(l);break}else if(i>=200&&i<=299)switch(this.state){case ve.STATUS_CALLING:case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},bs.TIMER_M),this.eventHandlers.onReceiveResponse(l);break;case ve.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(l);break}else if(i>=300&&i<=699)switch(this.state){case ve.STATUS_CALLING:case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_COMPLETED),this.sendACK(l),this.eventHandlers.onReceiveResponse(l);break;case ve.STATUS_COMPLETED:this.sendACK(l);break}}},{key:"C",get:function(){return ve}}]),t}(Hr),em=function(u){Fr(t,u);var e=$r(t);function t(r,l,s,i){var f;Ur(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 Lr(t,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){J0.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ve}}]),t}(Hr),tm=function(u){Fr(t,u);var e=$r(t);function t(r,l,s){var i;return Ur(this,t),i=e.call(this),i.type=ve.NON_INVITE_SERVER,i.id=s.via_branch,i.ua=r,i.transport=l,i.request=s,i.last_response="",s.server_transaction=an(i),i.state=ve.STATUS_TRYING,r.newTransaction(an(i)),i}return Lr(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"timer_J",value:function(){Ld.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Ld.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(l,s,i,f){var h=this;if(l===100)switch(this.state){case ve.STATUS_TRYING:this.stateChanged(ve.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ve.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 ve.STATUS_TRYING:case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},bs.TIMER_J),this.transport.send(s)?i&&i():(this.onTransportError(),f&&f());break;case ve.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ve}}]),t}(Hr),sm=function(u){Fr(t,u);var e=$r(t);function t(r,l,s){var i;return Ur(this,t),i=e.call(this),i.type=ve.INVITE_SERVER,i.id=s.via_branch,i.ua=r,i.transport=l,i.request=s,i.last_response="",s.server_transaction=an(i),i.state=ve.STATUS_PROCEEDING,r.newTransaction(an(i)),i.resendProvisionalTimer=null,s.reply(100),i}return Lr(t,[{key:"stateChanged",value:function(l){this.state=l,this.emit("stateChanged")}},{key:"timer_H",value:function(){eo.debug("Timer H expired for transaction ".concat(this.id)),this.state===ve.STATUS_COMPLETED&&eo.debug("ACK not received, dialog will be terminated"),this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){eo.debug("Timer L expired for transaction ".concat(this.id)),this.state===ve.STATUS_ACCEPTED&&(this.stateChanged(ve.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,eo.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(ve.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 ve.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(l>100&&l<=199&&this.state===ve.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},bs.PROVISIONAL_RESPONSE_INTERVAL));else if(l>=200&&l<=299)switch(this.state){case ve.STATUS_PROCEEDING:this.stateChanged(ve.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},bs.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ve.STATUS_ACCEPTED:this.transport.send(s)?i&&i():(this.onTransportError(),f&&f());break}else if(l>=300&&l<=699)switch(this.state){case ve.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ve.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},bs.TIMER_H),i&&i()):(this.onTransportError(),f&&f());break}}},{key:"C",get:function(){return ve}}]),t}(Hr);function nm(u,e){var t=u._transactions,r;switch(e.method){case Vr.INVITE:if(r=t.ist[e.via_branch],r){switch(r.state){case ve.STATUS_PROCEEDING:r.transport.send(r.last_response);break;case ve.STATUS_ACCEPTED:break}return!0}break;case Vr.ACK:if(r=t.ist[e.via_branch],r){if(r.state===ve.STATUS_ACCEPTED)return!1;if(r.state===ve.STATUS_COMPLETED)return r.state=ve.STATUS_CONFIRMED,r.I=setTimeout(function(){r.timer_I()},bs.TIMER_I),!0}else return!1;break;case Vr.CANCEL:return r=t.ist[e.via_branch],r?(e.reply_sl(200),r.state!==ve.STATUS_PROCEEDING):(e.reply_sl(481),!0);default:if(r=t.nist[e.via_branch],r){switch(r.state){case ve.STATUS_TRYING:break;case ve.STATUS_PROCEEDING:case ve.STATUS_COMPLETED:r.transport.send(r.last_response);break}return!0}break}}var Br={C:ve,NonInviteClientTransaction:Q0,InviteClientTransaction:Z0,AckClientTransaction:em,NonInviteServerTransaction:tm,InviteServerTransaction:sm,checkTransaction:nm};function im(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 rm(u,e,t){return e&&Fd(u.prototype,e),t&&Fd(u,t),u}var lm=It,$d=Tt,am=K0,Mc=Br,om=new lm("RequestSender"),Uc={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},jr=function(){function u(e,t,r){im(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 Uc)Object.prototype.hasOwnProperty.call(Uc,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=Uc[l]));e.status===e.C.STATUS_USER_CLOSED&&(this._method!==$d.BYE||this._method!==$d.ACK)&&this._eventHandlers.onTransportError()}return rm(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 Mc.InviteClientTransaction(this._ua,this._ua.transport,this._request,r);break;case"ACK":this.clientTransaction=new Mc.AckClientTransaction(this._ua,this._ua.transport,this._request,r);break;default:this.clientTransaction=new Mc.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){om.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 um(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Hd(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 cm(u,e,t){return e&&Hd(u.prototype,e),t&&Hd(u,t),u}var hm=It,Lc=Vt(),$n=Tt,Gd=Us,Vd=jr,qr=new hm("Registrator"),to=10,fm=function(){function u(e,t){um(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=Lc.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 cm(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){qr.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 Gd.OutgoingRequest($n.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},r),s=new Vd(this._ua,l,{onRequestTimeout:function(){t._registrationFailure(null,$n.causes.REQUEST_TIMEOUT)},onTransportError:function(){t._registrationFailure(null,$n.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")){qr.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){qr.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<to&&(p=to);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<to&&(t._expires=to),t.register()):(qr.debug("423 response received for REGISTER without Min-Expires"),t._registrationFailure(f,$n.causes.SIP_FAILURE_CODE));break}default:{var T=Lc.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){qr.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 Gd.OutgoingRequest($n.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l),i=new Vd(this._ua,s,{onRequestTimeout:function(){t._unregistered(null,$n.causes.REQUEST_TIMEOUT)},onTransportError:function(){t._unregistered(null,$n.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=Lc.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 Bd(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&&Bd(u.prototype,e),t&&Bd(u,t),u}var Fc=Tt,so=Br,gm=jr,$c={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},pm=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 $c)Object.prototype.hasOwnProperty.call($c,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=$c[l]))}return _m(u,[{key:"send",value:function(){var t=this,r=new gm(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===Fc.INVITE||this._request.method===Fc.UPDATE&&this._request.body)&&r.clientTransaction.state!==so.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var l=function s(){(r.clientTransaction.state===so.C.STATUS_ACCEPTED||r.clientTransaction.state===so.C.STATUS_COMPLETED||r.clientTransaction.state===so.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===Fc.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 mm(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 qd(u,e,t){return e&&jd(u.prototype,e),t&&jd(u,t),u}var vm=It,Wd=Us,on=Tt,Wr=Br,Tm=pm,Hc=Vt(),Gc=new vm("Dialog"),un={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},ym=function(){qd(u,null,[{key:"C",get:function(){return un}}]);function u(e,t,r){var l=arguments.length>3&&arguments[3]!==void 0?arguments[3]:un.STATUS_CONFIRMED;if(mm(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 Wd.IncomingResponse&&(l=t.status_code<200?un.STATUS_EARLY:un.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),Gc.debug("new ".concat(r," dialog created with status ").concat(this._state===un.STATUS_EARLY?"EARLY":"CONFIRMED"))}return qd(u,[{key:"isTerminated",value:function(){return this._status===un.STATUS_TERMINATED}},{key:"update",value:function(t,r){this._state=un.STATUS_CONFIRMED,Gc.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),r==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Gc.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=un.STATUS_TERMINATED}},{key:"sendRequest",value:function(t){var r=this,l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=Hc.cloneArray(l.extraHeaders),i=Hc.cloneObject(l.eventHandlers),f=l.body||null,h=this._createRequest(t,s,f);i.onAuthenticated=function(){r._local_seqnum+=1};var d=new Tm(this,h,i);return d.send(),h}},{key:"receiveRequest",value:function(t){this._checkInDialogRequest(t)&&(t.method===on.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===on.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}},{key:"_createRequest",value:function(t,r,l){r=Hc.cloneArray(r),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=t===on.CANCEL||t===on.ACK?this._local_seqnum:this._local_seqnum+=1,i=new Wd.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===on.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===on.INVITE||t.method===on.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===Wr.C.STATUS_ACCEPTED||t.server_transaction.state===Wr.C.STATUS_COMPLETED||t.server_transaction.state===Wr.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===Wr.C.STATUS_ACCEPTED&&(r._remote_target=t.parseHeader("contact").uri)})}else t.method===on.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",function(){t.server_transaction.state===Wr.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}(),Vc={exports:{}};function no(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?no=function(t){return typeof t}:no=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},no(u)}function Sm(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function Kd(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&&Kd(u.prototype,e),t&&Kd(u,t),u}function Cm(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&&Bc(u,e)}function Bc(u,e){return Bc=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Bc(u,e)}function Am(u){var e=wm();return function(){var r=io(u),l;if(e){var s=io(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return bm(this,l)}}function bm(u,e){return e&&(no(e)==="object"||typeof e=="function")?e:Rm(u)}function Rm(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function wm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function io(u){return io=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},io(u)}var Im=wt.EventEmitter,Om=It,Dm=Tt,Nm=rn,Yd=Vt(),Pm=new Om("RTCSession:DTMF"),zd={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Vc.exports=function(u){Cm(t,u);var e=Am(t);function t(r){var l;return Sm(this,t),l=e.call(this),l._session=r,l._direction=null,l._tone=null,l._duration=null,l._request=null,l}return Em(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 Nm.InvalidStateError(this._session.status);var f=Yd.cloneArray(i.extraHeaders);if(this.eventHandlers=Yd.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(
|
48
|
-
`);
|
49
|
-
`,1)[0],"Status_Line");if(s===-1){
|
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 ov(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}function uv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function s_(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 n_(u,e,t){return e&&s_(u.prototype,e),t&&s_(u,t),u}function cv(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&&Kc(u,e)}function Kc(u,e){return Kc=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Kc(u,e)}function hv(u){var e=_v();return function(){var r=co(u),l;if(e){var s=co(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return fv(this,l)}}function fv(u,e){return e&&(uo(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 _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 co(u){return co=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},co(u)}var gv=wt.EventEmitter,i_=Xt,pv=It,Te=Tt,Gn=rn,r_=Br,st=Vt(),Yr=xd,mv=Us,ho=ym,vv=jr,es=xm,l_=qm,Tv=Xm,yv=av,a_=ln(),se=new pv("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},fo=["audio","video"],Sv=function(u){cv(t,u);var e=hv(t);n_(t,null,[{key:"C",get:function(){return le}}]);function t(r){var l;return uv(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:Te.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},l._referSubscribers={},l._data={},l}return n_(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=st.cloneObject(s.eventHandlers),d=st.cloneArray(s.extraHeaders),p=st.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),v=s.mediaStream||null,T=st.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 Gn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Gn.NotSupportedError("WebRTC not supported");if(l=this._ua.normalizeTarget(l),!l)throw new TypeError("Invalid target: ".concat(f));this._sessionTimers.enabled&&st.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=Te.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=Te.SESSION_EXPIRES);for(var A in h)Object.prototype.hasOwnProperty.call(h,A)&&this.on(A,h[A]);this._from_tag=st.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 a_("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 a_("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 mv.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=st.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,Te.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,Te.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=st.cloneArray(s.extraHeaders),h=st.cloneObject(s.mediaConstraints),d=s.mediaStream||null,p=st.cloneObject(s.pcConfig,{iceServers:[]}),v=s.rtcConstraints||null,T=s.rtcAnswerConstraints||null,y=st.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 Gn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==le.STATUS_WAITING_FOR_ANSWER)throw new Gn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&st.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=Te.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=Te.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,Te.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,Te.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,Te.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||Te.causes.BYE,f=st.cloneArray(s.extraHeaders),h=s.body,d,p=s.status_code,v=s.reason_phrase;if(this._status===le.STATUS_TERMINATED)throw new Gn.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||Te.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,Te.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,Te.causes.REJECTED);break;case le.STATUS_WAITING_FOR_ACK:case le.STATUS_CONFIRMED:if(se.debug("terminating session"),v=s.reason_phrase||Te.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!==r_.C.STATUS_TERMINATED){var T=this._dialog;this.receiveRequest=function(y){var S=y.method;S===Te.ACK&&(l.sendRequest(Te.BYE,{extraHeaders:f,body:h}),T.terminate())},this._request.server_transaction.on("stateChanged",function(){l._request.server_transaction.state===r_.C.STATUS_TERMINATED&&(l.sendRequest(Te.BYE,{extraHeaders:f,body:h}),T.terminate())}),this._ended("local",null,i),this._dialog=T,this._ua.newDialog(T)}else this.sendRequest(Te.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||Te.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 Gn.InvalidStateError(this._status);if(d!==Te.DTMF_TRANSPORT.INFO&&d!==Te.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&&!st.isDecimal(f))throw new TypeError("Invalid tone duration: ".concat(f));if(f?f<es.C.MIN_DURATION?(se.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(es.C.MIN_DURATION," milliseconds")),f=es.C.MIN_DURATION):f>es.C.MAX_DURATION?(se.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(es.C.MAX_DURATION," milliseconds")),f=es.C.MAX_DURATION):f=Math.abs(f):f=es.C.DEFAULT_DURATION,s.duration=f,h&&!st.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<es.C.MIN_INTER_TONE_GAP?(se.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(es.C.MIN_INTER_TONE_GAP," milliseconds")),h=es.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=es.C.DEFAULT_INTER_TONE_GAP,d===Te.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 es(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 Gn.InvalidStateError(this._status);var f=new l_(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:Te.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:Te.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:Te.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 yv(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===Te.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,Te.causes.CANCELED));else switch(l.method){case Te.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:Te.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:Te.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 Te.BYE:this._status===le.STATUS_CONFIRMED||this._status===le.STATUS_WAITING_FOR_ACK?(l.reply(200),this._ended("remote",l,Te.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,Te.causes.BYE)):l.reply(403,"Wrong Status");break;case Te.INVITE:this._status===le.STATUS_CONFIRMED?l.hasHeader("replaces")?this._receiveReplaces(l):this._receiveReinvite(l):l.reply(403,"Wrong Status");break;case Te.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 es(this).init_incoming(l):h!==void 0?new l_(this).init_incoming(l):l.reply(415)}else l.reply(403,"Wrong Status");break;case Te.UPDATE:this._status===le.STATUS_CONFIRMED?this._receiveUpdate(l):l.reply(403,"Wrong Status");break;case Te.REFER:this._status===le.STATUS_CONFIRMED?this._receiveRefer(l):l.reply(403,"Wrong Status");break;case Te.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:Te.causes.CONNECTION_ERROR,cause:Te.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){se.warn("onRequestTimeout()"),this._status!==le.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:Te.causes.REQUEST_TIMEOUT,cause:Te.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){se.warn("onDialogError()"),this._status!==le.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Te.causes.DIALOG_ERROR,cause:Te.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"),st.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=Yr.T1;function f(){this._status===le.STATUS_WAITING_FOR_ACK&&(l.reply(200,null,["Contact: ".concat(this._contact)],s),i<Yr.T2&&(i=i*2,i>Yr.T2&&(i=Yr.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(Te.BYE),l._ended("remote",null,Te.causes.NO_ACK))},Yr.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:Te.causes.RTP_TIMEOUT,status_code:408,reason_phrase:Te.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 ho(this,l,s,ho.C.STATUS_EARLY),p.error?(se.debug(p.error),this._failed("remote",l,Te.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 ho(this,l,s);return v.error?(se.debug(v.error),this._failed("remote",l,Te.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=st.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=st.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(fo.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!==Te.SIP){se.debug("Refer-To header field points to a non-SIP URI scheme"),l.reply(416);return}l.reply(202);var i=new Tv(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=st.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 vv(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,Te.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,Te.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(Te.ACK);return}else{var i=new ho(this,l,"UAC");if(i.error!==void 0){se.debug(i.error);return}this.sendRequest(Te.ACK),this.sendRequest(Te.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,Te.causes.MISSING_SDP),this._failed("remote",l,Te.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,Te.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(p).then(function(){s._handleSessionTimersInIncomingResponse(l),s._accepted("remote",l),s.sendRequest(Te.ACK),s._confirmed("local",null)}).catch(function(T){s._acceptAndTerminate(l,488,"Not Acceptable Here"),s._failed("remote",l,Te.causes.BAD_MEDIA_DESCRIPTION),se.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),s.emit("peerconnection:setremotedescriptionfailed",T)})});break}default:{var v=st.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=st.cloneArray(s.extraHeaders),f=st.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(Te.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(Te.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=st.cloneArray(s.extraHeaders),f=st.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(Te.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(Te.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||Te.REASON_PHRASE[s]||"",f.push("Reason: SIP ;cause=".concat(s,'; text="').concat(i,'"'))),(this._dialog||this._createDialog(l,"UAC"))&&(this.sendRequest(Te.ACK),this.sendRequest(Te.BYE,{extraHeaders:f})),this._status=le.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(l){if(!this._localHold&&!this._remoteHold)return l;if(l=i_.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;fo.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;fo.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;fo.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 i_.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>=Te.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>=Te.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===Te.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:Te.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 Te.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}(gv);function _o(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?_o=function(t){return typeof t}:_o=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_o(u)}function Ev(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 Cv(u,e,t){return e&&o_(u.prototype,e),t&&o_(u,t),u}function Av(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&&Yc(u,e)}function Yc(u,e){return Yc=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Yc(u,e)}function bv(u){var e=Iv();return function(){var r=go(u),l;if(e){var s=go(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return Rv(this,l)}}function Rv(u,e){return e&&(_o(e)==="object"||typeof e=="function")?e:wv(u)}function wv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function Iv(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function go(u){return go=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},go(u)}var Ov=wt.EventEmitter,Dv=It,zc=Tt,Nv=Us,zr=Vt(),Pv=jr,u_=rn,xv=ln(),po=new Dv("Message"),kv=function(u){Av(t,u);var e=bv(t);function t(r){var l;return Ev(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 Cv(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=zr.cloneArray(f.extraHeaders),p=zr.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 Nv.OutgoingRequest(zc.MESSAGE,l,this._ua,T,d),s&&(this._request.body=s);var S=new Pv(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=zr.cloneArray(l.extraHeaders),i=l.body;if(this._direction!=="incoming")throw new u_.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=zr.cloneArray(l.extraHeaders),h=l.body;if(this._direction!=="incoming")throw new u_.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=zr.sipErrorCause(l.status_code);this._failed("remote",l,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,zc.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,zc.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){po.debug("MESSAGE failed"),this._close(),po.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:i})}},{key:"_succeeded",value:function(l,s){po.debug("MESSAGE succeeded"),this._close(),po.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}(Ov);function mo(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?mo=function(t){return typeof t}:mo=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},mo(u)}function Mv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function c_(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 Uv(u,e,t){return e&&c_(u.prototype,e),t&&c_(u,t),u}function Lv(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&&Xc(u,e)}function Xc(u,e){return Xc=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},Xc(u,e)}function Fv(u){var e=Gv();return function(){var r=vo(u),l;if(e){var s=vo(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return $v(this,l)}}function $v(u,e){return e&&(mo(e)==="object"||typeof e=="function")?e:Hv(u)}function Hv(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function Gv(){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 vo(u){return vo=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},vo(u)}var Vv=wt.EventEmitter,Bv=It,Jc=Tt,jv=Us,Xr=Vt(),qv=jr,h_=rn,To=new Bv("Options"),Wv=function(u){Lv(t,u);var e=Fv(t);function t(r){var l;return Mv(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 Uv(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=Xr.cloneArray(f.extraHeaders),p=Xr.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 jv.OutgoingRequest(Jc.OPTIONS,l,this._ua,null,d),s&&(this._request.body=s);var y=new qv(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=Xr.cloneArray(l.extraHeaders),i=l.body;if(this._direction!=="incoming")throw new h_.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=Xr.cloneArray(l.extraHeaders),h=l.body;if(this._direction!=="incoming")throw new h_.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=Xr.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){To.debug("OPTIONS failed"),this._close(),To.debug('emit "failed"'),this.emit("failed",{originator:l,response:s||null,cause:i})}},{key:"_succeeded",value:function(l,s){To.debug("OPTIONS succeeded"),this._close(),To.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}(Vv),Qc={},Kv=It,Zc=Vt(),Yv=As(),Jr=new Kv("Socket");Qc.isSocket=function(u){if(Array.isArray(u))return!1;if(typeof u>"u")return Jr.warn("undefined JsSIP.Socket instance"),!1;try{if(!Zc.isString(u.url))throw Jr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Zc.isString(u.via_transport))throw Jr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Yv.parse(u.sip_uri,"SIP_URI")===-1)throw Jr.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(!Zc.isFunction(u[e]))throw Jr.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 zv(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function f_(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 Xv(u,e,t){return e&&f_(u.prototype,e),t&&f_(u,t),u}var Jv=It,Qv=Qc,d_=Tt,Jt=new Jv("Transport"),ns={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:d_.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:d_.CONNECTION_RECOVERY_MAX_INTERVAL}},Zv=function(){function u(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ns.recovery_options;zv(this,u),Jt.debug("new()"),this.status=ns.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){Jt.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(!Qv.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:ns.SOCKET_STATUS_READY})},this),this._getSocket()}return Xv(u,[{key:"connect",value:function(){if(Jt.debug("connect()"),this.isConnected()){Jt.debug("Transport is already connected");return}else if(this.isConnecting()){Jt.debug("Transport is connecting");return}this.close_requested=!1,this.status=ns.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(){Jt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=ns.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(Jt.debug("send()"),!this.isConnected())return Jt.warn("unable to send message, transport is not connected"),!1;var r=t.toString();return Jt.debug(`sending message:
|
46
|
+
`),this.transport.send(d)}}]),n}(Ec),Td=function(c){ro(n,c);var t=lo(n);function n(){var a;return Rr(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(Ec),fs={OutgoingRequest:vc,InitialOutgoingInviteRequest:md,IncomingRequest:gd,IncomingResponse:Td};function vd(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 Ed(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(c,n),c}var Sd=ft,hs=Rt(),Kt=new Sd("DigestAuthentication"),yd=function(){function c(t){vd(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 Ed(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Kt.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 Kt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Kt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Kt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Kt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Kt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(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 Kt.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(_),Kt.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(_),Kt.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(_),Kt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Kt.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,Ad=4e3,yc=5e3,Ac={T1:ds,T2:Ad,T4:yc,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*yc,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Dl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Dl=function(n){return typeof n}:Dl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Dl(c)}function Ir(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 br(c,t,n){return t&&Cc(c.prototype,t),n&&Cc(c,n),c}function wr(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&&oo(c,t)}function oo(c,t){return oo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},oo(c,t)}function Or(c){var t=Rd();return function(){var a=Nl(c),o;if(t){var s=Nl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Cd(this,o)}}function Cd(c,t){return t&&(Dl(t)==="object"||typeof t=="function")?t:ws(c)}function ws(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Rd(){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 Nl(c){return Nl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Nl(c)}var Dr=ct.EventEmitter,Nr=ft,Ur=st,Rc=fs,ss=Ac,Ic=new Nr("NonInviteClientTransaction"),Ul=new Nr("InviteClientTransaction"),Id=new Nr("AckClientTransaction"),bc=new Nr("NonInviteServerTransaction"),Pl=new Nr("InviteServerTransaction"),ue={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},bd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.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(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ss.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Ic.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Ic.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break}else switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(o),this.K=setTimeout(function(){s.timer_K()},ss.TIMER_K);break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),wd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.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=ws(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(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ss.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ue.STATUS_ACCEPTED&&(Ul.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Ul.debug("Timer M expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Ul.debug("Timer B expired for transaction ".concat(this.id)),this.state===ue.STATUS_CALLING&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Ul.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new Rc.OutgoingRequest(Ur.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()},ss.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===ue.STATUS_PROCEEDING){var s=new Rc.OutgoingRequest(Ur.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 ue.STATUS_CALLING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);break}else if(r>=200&&r<=299)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},ss.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);break}else if(r>=300&&r<=699)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.sendACK(o),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Od=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(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 br(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Id.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ue}}]),n}(Dr),Dd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_TRYING,a.newTransaction(ws(r)),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){bc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,bc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case ue.STATUS_TRYING:this.stateChanged(ue.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ue.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 ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ss.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Nd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_PROCEEDING,a.newTransaction(ws(r)),r.resendProvisionalTimer=null,s.reply(100),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Pl.debug("Timer H expired for transaction ".concat(this.id)),this.state===ue.STATUS_COMPLETED&&Pl.debug("ACK not received, dialog will be terminated"),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Pl.debug("Timer L expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Pl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case ue.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===ue.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ss.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ss.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ue.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case ue.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ue.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ss.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return ue}}]),n}(Dr);function Ud(c,t){var n=c._transactions,a;switch(t.method){case Ur.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case ue.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case ue.STATUS_ACCEPTED:break}return!0}break;case Ur.ACK:if(a=n.ist[t.via_branch],a){if(a.state===ue.STATUS_ACCEPTED)return!1;if(a.state===ue.STATUS_COMPLETED)return a.state=ue.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ss.TIMER_I),!0}else return!1;break;case Ur.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==ue.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case ue.STATUS_TRYING:break;case ue.STATUS_PROCEEDING:case ue.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var Pr={C:ue,NonInviteClientTransaction:bd,InviteClientTransaction:wd,AckClientTransaction:Od,NonInviteServerTransaction:Dd,InviteServerTransaction:Nd,checkTransaction:Ud};function Pd(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 xd(c,t,n){return t&&wc(c.prototype,t),n&&wc(c,n),c}var kd=ft,Oc=st,Md=yd,uo=Pr,Ld=new kd("RequestSender"),co={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},xr=function(){function c(t,n,a){Pd(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 co)Object.prototype.hasOwnProperty.call(co,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=co[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==Oc.BYE||this._method!==Oc.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 uo.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new uo.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new uo.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){Ld.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 Md({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 $d(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Dc(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 Hd(c,t,n){return t&&Dc(c.prototype,t),n&&Dc(c,n),c}var Fd=ft,fo=Rt(),Xs=st,Nc=fs,Uc=xr,kr=new Fd("Registrator"),xl=10,jd=function(){function c(t,n){$d(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=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:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return Hd(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){kr.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 Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new Uc(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,Xs.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")){kr.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})),!_){kr.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<xl&&(g=xl);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<xl&&(n._expires=xl),n.register()):(kr.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,Xs.causes.SIP_FAILURE_CODE));break}default:{var E=fo.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){kr.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 Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new Uc(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,Xs.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 _=fo.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 qd(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 Vd(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}var ho=st,kl=Pr,Bd=xr,_o={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},Gd=function(){function c(t,n,a){qd(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 _o)Object.prototype.hasOwnProperty.call(_o,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=_o[o]))}return Vd(c,[{key:"send",value:function(){var n=this,a=new Bd(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===ho.INVITE||this._request.method===ho.UPDATE&&this._request.body)&&a.clientTransaction.state!==kl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===kl.C.STATUS_ACCEPTED||a.clientTransaction.state===kl.C.STATUS_COMPLETED||a.clientTransaction.state===kl.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===ho.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 Wd(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 kc(c,t,n){return t&&xc(c.prototype,t),n&&xc(c,n),c}var Kd=ft,Mc=fs,Os=st,Mr=Pr,Yd=Gd,po=Rt(),mo=new Kd("Dialog"),Ds={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Jd=function(){kc(c,null,[{key:"C",get:function(){return Ds}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ds.STATUS_CONFIRMED;if(Wd(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 Mc.IncomingResponse&&(o=n.status_code<200?Ds.STATUS_EARLY:Ds.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),mo.debug("new ".concat(a," dialog created with status ").concat(this._state===Ds.STATUS_EARLY?"EARLY":"CONFIRMED"))}return kc(c,[{key:"isTerminated",value:function(){return this._status===Ds.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ds.STATUS_CONFIRMED,mo.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){mo.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ds.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=po.cloneArray(o.extraHeaders),r=po.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new Yd(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Os.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Os.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=po.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Os.CANCEL||n===Os.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Mc.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===Os.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===Os.INVITE||n.method===Os.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===Mr.C.STATUS_ACCEPTED||n.server_transaction.state===Mr.C.STATUS_COMPLETED||n.server_transaction.state===Mr.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===Mr.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Os.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Mr.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}(),go={exports:{}};function Ml(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ml=function(n){return typeof n}:Ml=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ml(c)}function zd(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 Xd(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}function Qd(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&&To(c,t)}function To(c,t){return To=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},To(c,t)}function Zd(c){var t=s_();return function(){var a=Ll(c),o;if(t){var s=Ll(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return e_(this,o)}}function e_(c,t){return t&&(Ml(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 s_(){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 Ll(c){return Ll=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ll(c)}var n_=ct.EventEmitter,r_=ft,i_=st,l_=Is,$c=Rt(),a_=new r_("RTCSession:DTMF"),Hc={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};go.exports=function(c){Qd(n,c);var t=Zd(n);function n(a){var o;return zd(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return Xd(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 l_.InvalidStateError(this._session.status);var d=$c.cloneArray(r.extraHeaders);if(this.eventHandlers=$c.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(i_.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=Hc.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):a_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(n_),go.exports.C=Hc;var o_=go.exports;function $l(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?$l=function(n){return typeof n}:$l=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},$l(c)}function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Fc(c,t){for(var n=0;n<t.length;n++){var 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_(c,t,n){return t&&Fc(c.prototype,t),n&&Fc(c,n),c}function f_(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&&vo(c,t)}function vo(c,t){return vo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},vo(c,t)}function h_(c){var t=p_();return function(){var a=Hl(c),o;if(t){var s=Hl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return d_(this,o)}}function d_(c,t){return t&&($l(t)==="object"||typeof t=="function")?t:__(c)}function __(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function p_(){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 Hl(c){return Hl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Hl(c)}var m_=ct.EventEmitter,g_=st,T_=Is,v_=Rt(),E_=function(c){f_(n,c);var t=h_(n);function n(a){var o;return u_(this,n),o=t.call(this),o._session=a,o._direction=null,o._contentType=null,o._body=null,o}return c_(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 T_.InvalidStateError(this._session.status);this._contentType=o,this._body=s;var h=v_.cloneArray(d.extraHeaders);h.push("Content-Type: ".concat(o)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(g_.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}(m_);function S_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function jc(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 y_(c,t,n){return t&&jc(c.prototype,t),n&&jc(c,n),c}var A_=ft,qc=st,C_=new A_("RTCSession:ReferNotifier"),Eo={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},R_=function(){function c(t,n,a){S_(this,c),this._session=t,this._id=n,this._expires=a||Eo.expires,this._active=!0,this.notify(100)}return y_(c,[{key:"notify",value:function(n,a){if(C_.debug("notify()"),this._active!==!1){a=a||qc.REASON_PHRASE[n]||"";var o;n>=200?o="terminated;reason=noresource":o="active;expires=".concat(this._expires),this._session.sendRequest(qc.NOTIFY,{extraHeaders:["Event: ".concat(Eo.event_type,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(Eo.body_type)],body:"SIP/2.0 ".concat(n," ").concat(a),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function Fl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fl=function(n){return typeof n}:Fl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Fl(c)}function I_(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 b_(c,t,n){return t&&Vc(c.prototype,t),n&&Vc(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&&So(c,t)}function So(c,t){return So=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},So(c,t)}function O_(c){var t=U_();return function(){var a=jl(c),o;if(t){var s=jl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return D_(this,o)}}function D_(c,t){return t&&(Fl(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 jl(c){return jl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},jl(c)}var P_=ct.EventEmitter,x_=ft,Lr=st,k_=ts(),Bc=Rt(),Qs=new x_("RTCSession:ReferSubscriber"),M_=function(c){w_(n,c);var t=O_(n);function n(a){var o;return I_(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]:{};Qs.debug("sendRefer()");var d=Bc.cloneArray(r.extraHeaders),h=Bc.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(Lr.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(C){s._requestSucceeded(C)},onErrorResponse:function(C){s._requestFailed(C,Lr.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,Lr.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,Lr.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,Lr.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(o){if(Qs.debug("receiveNotify()"),!!o.body){var s=k_.parse(o.body.trim().split(`\r
|
49
|
+
`,1)[0],"Status_Line");if(s===-1){Qs.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){Qs.debug("REFER succeeded"),Qs.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}},{key:"_requestFailed",value:function(o,s){Qs.debug("REFER failed"),Qs.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(P_);function ql(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ql=function(n){return typeof n}:ql=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ql(c)}function _s(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=L_(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 L_(c,t){if(c){if(typeof c=="string")return Gc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Gc(c,t)}}function Gc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function $_(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 H_(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&&yo(c,t)}function yo(c,t){return yo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yo(c,t)}function F_(c){var t=V_();return function(){var a=Vl(c),o;if(t){var s=Vl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return j_(this,o)}}function j_(c,t){return t&&(ql(t)==="object"||typeof t=="function")?t:q_(c)}function q_(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 Vl(c){return Vl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Vl(c)}var B_=ct.EventEmitter,Yc=Nt,G_=ft,ce=st,Zs=Is,Jc=Pr,Be=Rt(),$r=Ac,W_=fs,Bl=Jd,K_=xr,kt=o_,zc=E_,Y_=R_,J_=M_,Xc=bs(),W=new G_("RTCSession"),X={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Gl=["audio","video"],z_=function(c){H_(n,c);var t=F_(n);Kc(n,null,[{key:"C",get:function(){return X}}]);function n(a){var o;return $_(this,n),W.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=X.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 Kc(n,[{key:"isInProgress",value:function(){switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:case X.STATUS_INVITE_RECEIVED:case X.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case X.STATUS_ANSWERED:case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case X.STATUS_CANCELED:case X.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;W.debug("connect()");var d=o,h=Be.cloneObject(s.eventHandlers),_=Be.cloneArray(s.extraHeaders),g=Be.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Be.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!==X.STATUS_NULL)throw new Zs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Zs.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var C in h)Object.prototype.hasOwnProperty.call(h,C)&&this.on(C,h[C]);this._from_tag=Be.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 Xc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Xc("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 W_.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;W.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=X.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=Be.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=X.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===X.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!==X.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]:{};W.debug("answer()");var r=this._request,d=Be.cloneArray(s.extraHeaders),h=Be.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Be.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Be.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 Zs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==X.STATUS_WAITING_FOR_ANSWER)throw new Zs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=X.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===X.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(Z){o._connection.addTrack(Z,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};W.debug('emit "sdp"'),o.emit("sdp",F);var Z=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(Z)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===X.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===X.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=X.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!==X.STATUS_TERMINATED&&W.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Be.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===X.STATUS_TERMINATED)throw new Zs.InvalidStateError(this._status);switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:if(W.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===X.STATUS_NULL||this._status===X.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===X.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=X.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case X.STATUS_WAITING_FOR_ANSWER:case X.STATUS_ANSWERED:if(W.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 X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:if(W.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===X.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Jc.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===Jc.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]:{};W.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!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.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&&!Be.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<kt.C.MIN_DURATION?(W.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?(W.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&&!Be.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<kt.C.MIN_INTER_TONE_GAP?(W.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===X.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(W.debug("sendInfo()"),this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.InvalidStateError(this._status);var d=new zc(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};W.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};W.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(W.debug("hold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var d={succeeded:function(){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(W.debug("unhold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var d={succeeded:function(){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;W.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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;W.debug("refer()");var d=o;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new J_(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 W.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(W.debug("receiveRequest()"),o.method===ce.CANCEL)(this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED)&&(this._status=X.STATUS_CANCELED,this._request.reply(487),this._failed("remote",o,ce.causes.CANCELED));else switch(o.method){case ce.ACK:if(this._status!==X.STATUS_WAITING_FOR_ACK)return;if(this._status=X.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};W.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}),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===X.STATUS_CONFIRMED||this._status===X.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===X.STATUS_INVITE_RECEIVED||this._status===X.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===X.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===X.STATUS_1XX_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED||this._status===X.STATUS_WAITING_FOR_ACK||this._status===X.STATUS_CONFIRMED){var 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 zc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===X.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===X.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===X.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.reply(501)}}},{key:"onTransportError",value:function(){W.warn("onTransportError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){W.warn("onRequestTimeout()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){W.warn("onDialogError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(o){W.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){W.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?(W.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(W.debug("_isReadyToReOffer() | session not established yet"),!1):(W.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(W.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(W.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==X.STATUS_TERMINATED){if(this._status=X.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){W.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=$r.T1;function d(){this._status===X.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<$r.T2&&(r=r*2,r>$r.T2&&(r=$r.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===X.STATUS_WAITING_FOR_ACK&&(W.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},$r.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})}),W.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(W.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 W.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return W.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,W.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 W.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};W.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 Bl(this,o,s,Bl.C.STATUS_EARLY),g.error?(W.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 Bl(this,o,s);return T.error?(W.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;W.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=Be.cloneArray(T.extraHeaders);if(this._status!==X.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"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.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=X.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;W.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=Be.cloneArray(T.extraHeaders);if(this._status!==X.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"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.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;W.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Gl.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};W.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===X.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(A){throw o.reply(488),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),s.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(s._status===X.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===X.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(A){throw o.reply(500),W.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){W.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(o){var s=this;if(W.debug("receiveRefer()"),!o.refer_to){W.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){W.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new Y_(this,o.cseq);W.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!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.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=Be.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(W.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;W.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){W.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 K_(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===X.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===X.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===X.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=X.STATUS_INVITE_SENT,W.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==X.STATUS_TERMINATED&&W.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){W.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(W.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 Bl(this,o,"UAC");if(r.error!==void 0){W.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!==X.STATUS_INVITE_SENT&&this._status!==X.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=X.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){W.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=X.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};W.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){W.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=X.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};W.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),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Be.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]:{};W.debug("sendReinvite()");var r=Be.cloneArray(s.extraHeaders),d=Be.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};W.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!==X.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};W.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),W.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]:{};W.debug("sendUpdate()");var r=Be.cloneArray(s.extraHeaders),d=Be.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};W.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!==X.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};W.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),W.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){W.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=X.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Yc.parse(o),this._localHold&&!this._remoteHold){W.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;Gl.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){W.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Gl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){h.e(A)}finally{h.f()}}else if(this._remoteHold){W.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;Gl.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 Yc.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!==X.STATUS_TERMINATED&&o._isReadyToReOffer()&&(W.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==X.STATUS_TERMINATED&&(W.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){W.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){W.debug("session connecting"),W.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){W.debug("session progress"),W.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){W.debug("session accepted"),this._start_time=new Date,W.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){W.debug("session confirmed"),this._is_confirmed=!0,W.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){W.debug("session ended"),this._end_time=new Date,this._close(),W.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){W.debug("session failed"),W.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),W.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){W.debug("session onhold"),this._setLocalMediaStatus(),W.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){W.debug("session onunhold"),this._setLocalMediaStatus(),W.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onmute"),this._setLocalMediaStatus(),W.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onunmute"),this._setLocalMediaStatus(),W.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{key:"C",get:function(){return X}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(B_);function Wl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Wl=function(n){return typeof n}:Wl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Wl(c)}function X_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Qc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Q_(c,t,n){return t&&Qc(c.prototype,t),n&&Qc(c,n),c}function Z_(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&&Ao(c,t)}function Ao(c,t){return Ao=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Ao(c,t)}function ep(c){var t=np();return function(){var a=Kl(c),o;if(t){var s=Kl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return tp(this,o)}}function tp(c,t){return t&&(Wl(t)==="object"||typeof t=="function")?t:sp(c)}function sp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function np(){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 Kl(c){return Kl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Kl(c)}var rp=ct.EventEmitter,ip=ft,Co=st,lp=fs,Hr=Rt(),ap=xr,Zc=Is,op=bs(),Yl=new ip("Message"),up=function(c){Z_(n,c);var t=ep(n);function n(a){var o;return X_(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 Q_(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 _=Hr.cloneArray(d.extraHeaders),g=Hr.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new op("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 lp.OutgoingRequest(Co.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var A=new ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),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=Hr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Zc.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=Hr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Zc.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=Hr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Co.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Co.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){Yl.debug("MESSAGE failed"),this._close(),Yl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Yl.debug("MESSAGE succeeded"),this._close(),Yl.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}(rp);function Jl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Jl=function(n){return typeof n}:Jl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Jl(c)}function cp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ef(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 fp(c,t,n){return t&&ef(c.prototype,t),n&&ef(c,n),c}function hp(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&&Ro(c,t)}function Ro(c,t){return Ro=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Ro(c,t)}function dp(c){var t=mp();return function(){var a=zl(c),o;if(t){var s=zl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return _p(this,o)}}function _p(c,t){return t&&(Jl(t)==="object"||typeof t=="function")?t:pp(c)}function pp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mp(){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 zl(c){return zl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},zl(c)}var gp=ct.EventEmitter,Tp=ft,Io=st,vp=fs,Fr=Rt(),Ep=xr,tf=Is,Xl=new Tp("Options"),Sp=function(c){hp(n,c);var t=dp(n);function n(a){var o;return cp(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 fp(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 _=Fr.cloneArray(d.extraHeaders),g=Fr.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 vp.OutgoingRequest(Io.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Ep(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=Fr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new tf.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=Fr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new tf.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=Fr.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){Xl.debug("OPTIONS failed"),this._close(),Xl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Xl.debug("OPTIONS succeeded"),this._close(),Xl.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}(gp),bo={},yp=ft,wo=Rt(),Ap=ts(),jr=new yp("Socket");bo.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return jr.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw jr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw jr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Ap.parse(c.sip_uri,"SIP_URI")===-1)throw jr.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!wo.isFunction(c[t]))throw jr.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 Cp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sf(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 Rp(c,t,n){return t&&sf(c.prototype,t),n&&sf(c,n),c}var Ip=ft,bp=bo,nf=st,Ut=new Ip("Transport"),$t={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nf.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nf.CONNECTION_RECOVERY_MAX_INTERVAL}},wp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:$t.recovery_options;Cp(this,c),Ut.debug("new()"),this.status=$t.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Ut.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:$t.SOCKET_STATUS_READY})},this),this._getSocket()}return Rp(c,[{key:"connect",value:function(){if(Ut.debug("connect()"),this.isConnected()){Ut.debug("Transport is already connected");return}else if(this.isConnecting()){Ut.debug("Transport is connecting");return}this.close_requested=!1,this.status=$t.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Ut.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=$t.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=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(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Ut.debug(`sending message:
|
51
51
|
|
52
|
-
`.concat(
|
53
|
-
`)),this.socket.send(
|
54
|
-
`){
|
52
|
+
`.concat(a,`
|
53
|
+
`)),this.socket.send(a)}},{key:"isConnected",value:function(){return this.status===$t.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===$t.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),Ut.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!==$t.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=$t.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=$t.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=$t.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=$t.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
|
54
|
+
`){Ut.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{Ut.debug("received binary message failed to be converted into string, message discarded");return}Ut.debug(`received binary message:
|
55
55
|
|
56
|
-
`.concat(
|
57
|
-
`))}else
|
56
|
+
`.concat(n,`
|
57
|
+
`))}else Ut.debug(`received text message:
|
58
58
|
|
59
|
-
`.concat(
|
60
|
-
`));this.ondata({transport:this,message:
|
61
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,
|
62
|
-
`);if(
|
63
|
-
`,
|
64
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,
|
65
|
-
`),
|
66
|
-
`)}}catch(
|
67
|
-
`),
|
68
|
-
`),
|
69
|
-
`),
|
70
|
-
`),
|
71
|
-
`,
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,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 E_(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 E_(u,e)}}function E_(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 Ni=Vt(),Vn=Tt,rh=As(),C_=ln(),lh=Qc,ah=rn;ih.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:Vn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:Vn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:Vn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(Ni.createRandomToken(12),".invalid")};var Eo={mandatory:{sockets:function(e){var t=[];if(lh.isSocket(e))t.push({socket:e});else if(Array.isArray(e)&&e.length){var r=S_(e),l;try{for(r.s();!(l=r.n()).done;){var s=l.value;Object.prototype.hasOwnProperty.call(s,"socket")&&lh.isSocket(s.socket)?t.push(s):lh.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(Vn.SIP,":").concat(e));var t=C_.parse(e);if(t)return t.user?t:void 0}},optional:{authorization_user:function(e){if(rh.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(Ni.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(Ni.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if(typeof e=="string"){var t=rh.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)),rh.parse(e,"uuid")!==-1)return e},no_answer_timeout:function(e){if(Ni.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===Vn.INVITE||e===Vn.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(Ni.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(Vn.SIP,":").concat(e));var t=C_.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=S_(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}}};ih.load=function(u,e){for(var t in Eo.mandatory)if(e.hasOwnProperty(t)){var r=e[t],l=Eo.mandatory[t](r);if(l!==void 0)u[t]=l;else throw new ah.ConfigurationError(t,r)}else throw new ah.ConfigurationError(t);for(var s in Eo.optional)if(e.hasOwnProperty(s)){var i=e[s];if(Ni.isEmpty(i))continue;var f=Eo.optional[s](i);if(f!==void 0)u[s]=f;else throw new ah.ConfigurationError(s,i)}};function Co(u){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Co=function(t){return typeof t}:Co=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Co(u)}function v1(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function A_(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 b_(u,e,t){return e&&A_(u.prototype,e),t&&A_(u,t),u}function T1(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&&oh(u,e)}function oh(u,e){return oh=Object.setPrototypeOf||function(r,l){return r.__proto__=l,r},oh(u,e)}function y1(u){var e=E1();return function(){var r=Ao(u),l;if(e){var s=Ao(this).constructor;l=Reflect.construct(r,arguments,s)}else l=r.apply(this,arguments);return S1(this,l)}}function S1(u,e){return e&&(Co(e)==="object"||typeof e=="function")?e:R_(u)}function R_(u){if(u===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return u}function E1(){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 Ao(u){return Ao=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Ao(u)}var C1=wt.EventEmitter,A1=It,Nt=Tt,b1=fm,w_=Sv,I_=kv,O_=Wv,uh=Br,R1=Zv,bo=Vt(),w1=rn,I1=ln(),O1=__,ch=Us,D1=u1,hh=ih,et=new A1("UA"),Pt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},N1=function(u){T1(t,u);var e=y1(t);b_(t,null,[{key:"C",get:function(){return Pt}}]);function t(r){var l;if(v1(this,t),et.debug("new() [configuration:%o]",r),l=e.call(this),l._cache={credentials:{}},l._configuration=Object.assign({},hh.settings),l._dynConfiguration={},l._dialogs={},l._applicants={},l._sessions={},l._transport=null,l._contact=null,l._status=Pt.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=Pt.STATUS_NOT_READY,l._error=Pt.CONFIGURATION_ERROR,s}return l._registrator=new b1(R_(l)),l}return b_(t,[{key:"start",value:function(){et.debug("start()"),this._status===Pt.STATUS_INIT?this._transport.connect():this._status===Pt.STATUS_USER_CLOSED?(et.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Pt.STATUS_INIT,this._transport.connect()):this._status===Pt.STATUS_READY?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}},{key:"register",value:function(){et.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(l){et.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){et.debug("call()");var i=new w_(this);return i.connect(l,s),i}},{key:"sendMessage",value:function(l,s,i){et.debug("sendMessage()");var f=new I_(this);return f.send(l,s,i),f}},{key:"sendOptions",value:function(l,s,i){et.debug("sendOptions()");var f=new O_(this);return f.send(l,s,i),f}},{key:"terminateSessions",value:function(l){et.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(et.debug("stop()"),this._dynConfiguration={},this._status===Pt.STATUS_USER_CLOSED){et.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)){et.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=Pt.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 bo.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:et.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 et.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){et.debug("Request-URI does not point to us"),l.method!==Nt.ACK&&l.reply_sl(404);return}if(l.ruri.scheme===Nt.SIPS){l.reply_sl(416);return}if(!uh.checkTransaction(this,l)){if(s===Nt.INVITE?new uh.InviteServerTransaction(this,this._transport,l):s!==Nt.ACK&&s!==Nt.CANCEL&&new uh.NonInviteServerTransaction(this,this._transport,l),s===Nt.OPTIONS){if(this.listeners("newOptions").length===0){l.reply(200);return}var i=new O_(this);i.init_incoming(l)}else if(s===Nt.MESSAGE){if(this.listeners("newMessage").length===0){l.reply(405);return}var f=new I_(this);f.init_incoming(l)}else if(s===Nt.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===Nt.NOTIFY?(d=this._findSession(l),d?d.receiveRequest(l):(et.debug("received NOTIFY request for a non existent subscription"),l.reply(481,"Subscription does not exist"))):s!==Nt.ACK&&l.reply(481);else switch(s){case Nt.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 w_(this),d.init_incoming(l);else et.warn("INVITE received but WebRTC is not supported"),l.reply(488);break;case Nt.BYE:l.reply(481);break;case Nt.CANCEL:d=this._findSession(l),d?d.receiveRequest(l):et.debug("received CANCEL request for a non existent session");break;case Nt.ACK:break;case Nt.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{hh.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=bo.newUUID()),this._configuration.jssip_id=bo.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new R1(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=P1.bind(this),this._transport.onconnect=x1.bind(this),this._transport.ondisconnect=k1.bind(this),this._transport.ondata=M1.bind(this)}catch(p){throw et.warn(p),new w1.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 I1("sip",bo.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}));et.debug("configuration parameters after validation:");for(var d in this._configuration)if(Object.prototype.hasOwnProperty.call(hh.settings,d))switch(d){case"uri":case"registrar_server":et.debug("- ".concat(d,": ").concat(this._configuration[d]));break;case"password":case"ha1":case"authorization_jwt":et.debug("- ".concat(d,": NOT SHOWN"));break;default:et.debug("- ".concat(d,": ").concat(JSON.stringify(this._configuration[d])))}}},{key:"C",get:function(){return Pt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),t}(C1);function P1(u){this.emit("connecting",u)}function x1(u){this._status!==Pt.STATUS_USER_CLOSED&&(this._status=Pt.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function k1(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!==Pt.STATUS_USER_CLOSED&&(this._status=Pt.STATUS_NOT_READY,this._error=Pt.NETWORK_ERROR)}function M1(u){var e=u.transport,t=u.message;if(t=O1.parseMessage(t,this),!!t&&!(this._status===Pt.STATUS_USER_CLOSED&&t instanceof ch.IncomingRequest)&&D1(t,this,e)){if(t instanceof ch.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof ch.IncomingResponse){var r;switch(t.method){case Nt.INVITE:r=this._transactions.ict[t.via_branch],r&&r.receiveResponse(t);break;case Nt.ACK:break;default:r=this._transactions.nict[t.via_branch],r&&r.receiveResponse(t);break}}}}function U1(u,e){if(!(u instanceof e))throw new TypeError("Cannot call a class as a function")}function D_(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 L1(u,e,t){return e&&D_(u.prototype,e),t&&D_(u,t),u}var F1=It,$1=As(),Wt=new F1("WebSocketInterface"),H1=function(){function u(e){U1(this,u),Wt.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;var t=$1.parse(e,"absoluteURI");if(t===-1)throw Wt.warn("invalid WebSocket URI: ".concat(e)),new TypeError("Invalid argument: ".concat(e));if(t.scheme!=="wss"&&t.scheme!=="ws")throw Wt.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 L1(u,[{key:"connect",value:function(){if(Wt.debug("connect()"),this.isConnected()){Wt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Wt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Wt.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(){Wt.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 Wt.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Wt.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(){Wt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(t){var r=t.wasClean,l=t.code,s=t.reason;Wt.debug("WebSocket ".concat(this._url," closed")),r===!1&&Wt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!r,l,s)}},{key:"_onMessage",value:function(t){var r=t.data;Wt.debug("received WebSocket message"),this.ondata(r)}},{key:"_onError",value:function(t){Wt.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}(),fh=Ha,G1=Tt,V1=rn,B1=Vt(),j1=N1,q1=ln(),W1=Cc(),K1=As(),Y1=H1,z1=Ii("JsSIP");z1("version %s",fh.version);var N_={C:G1,Exceptions:V1,Utils:B1,UA:j1,URI:q1,NameAddrHeader:W1,WebSocketInterface:Y1,Grammar:K1,debug:Ii,get name(){return fh.title},get version(){return fh.version}};const Pi=Ii,xi="JsSIP";var Et=class{constructor(e){e?(this._debug=Pi.default(`${xi}:${e}`),this._warn=Pi.default(`${xi}:WARN:${e}`),this._error=Pi.default(`${xi}:ERROR:${e}`)):(this._debug=Pi.default(xi),this._warn=Pi.default(`${xi}:WARN`),this._error=Pi.default(`${xi}: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 Ro=We(Et),P_=Ha;var Ue={USER_AGENT:`${P_.title} ${P_.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=We(Ue);var gt={},dh,x_;function _h(){if(x_)return dh;x_=1;const u=Hs(),e=_s();return dh=class o0{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 o0(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}},dh}var gh,k_;function _s(){return k_||(k_=1,gh=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:He,uri_scheme_sips:vt,uri_scheme_sip:Je,userinfo:as,user:Gt,user_unreserved:er,password:tr,hostport:li,host:Ps,hostname:tn,domainlabel:ai,toplabel:sr,IPv6reference:nr,IPv6address:oi,h16:Ae,ls32:me,IPv4address:Rt,dec_octet:Es,port:Rn,uri_parameters:Dl,uri_parameter:ir,transport_param:rr,user_param:Nl,method_param:Pl,ttl_param:xl,maddr_param:kl,lr_param:Ml,other_param:Ul,pname:Ll,pvalue:Fl,paramchar:wn,param_unreserved:In,headers:$l,header:ui,hname:ci,hvalue:Hl,hnv_unreserved:On,Request_Response:hi,Request_Line:ec,Request_URI:Gl,absoluteURI:lr,hier_part:ar,net_path:Vl,abs_path:fi,opaque_part:di,uric:Dn,uric_no_slash:Nn,path_segments:Bl,segment:_i,param:Pn,pchar:sn,scheme:xn,authority:jl,srvr:ql,reg_name:Wl,query:Kl,SIP_Version:or,INVITEm:ur,ACKm:Yl,OPTIONSm:zl,BYEm:Xl,CANCELm:Jl,REGISTERm:Ql,SUBSCRIBEm:Zl,NOTIFYm:ea,REFERm:ta,Method:gi,Status_Line:pi,Status_Code:sa,extension_code:na,Reason_Phrase:ia,Allow_Events:tc,Call_ID:Hf,Contact:Gf,contact_param:cr,name_addr:os,display_name:us,contact_params:kn,c_p_q:hr,c_p_expires:ra,delta_seconds:xs,qvalue:ks,generic_param:ut,gen_value:ct,Content_Disposition:sc,disp_type:nc,disp_param:fr,handling_param:dr,Content_Encoding:ic,Content_Length:Vf,Content_Type:Bf,media_type:rc,m_type:la,discrete_type:aa,composite_type:oa,extension_token:mi,x_token:vi,m_subtype:ua,m_parameter:_r,m_value:gr,CSeq:lc,CSeq_value:ac,Expires:oc,Event:jf,event_type:Ti,From:yi,from_param:ca,tag_param:Si,Max_Forwards:ha,Min_Expires:qf,Name_Addr_Header:Wf,Proxy_Authenticate:Kf,challenge:fa,other_challenge:pr,auth_param:Mn,digest_cln:Ms,realm:Ei,realm_value:da,domain:_a,URI:Ci,nonce:Ai,nonce_value:ga,opaque:pa,stale:ma,algorithm:va,qop_options:Ta,qop_value:bi,Proxy_Require:mr,Record_Route:Yf,rec_route:vr,Reason:Tr,reason_param:ya,reason_cause:yr,Require:uc,Route:zf,route_param:Sr,Subscription_State:Er,substate_value:cc,subexp_params:Cr,event_reason_value:Ar,Subject:hc,Supported:Xf,To:Jf,to_param:Sa,Via:Ea,via_param:br,via_params:Un,via_ttl:Rr,via_maddr:Ca,via_received:Aa,via_branch:ba,response_port:Ra,rport:wa,sent_protocol:Ia,protocol_name:Oa,transport:Da,sent_by:Na,via_host:Pa,via_port:xa,ttl:wr,WWW_Authenticate:ka,Session_Expires:Qf,s_e_expires:fc,s_e_params:Ir,s_e_refresher:Or,extension_header:dc,header_value:_c,message_body:gc,uuid_URI:Zf,uuid:pc,hex4:cs,hex8:hs,hex12:Ma,Refer_To:mc,Replaces:ed,call_id:vc,replaces_param:Dr,to_tag:Nr,from_tag:Ua,early_flag:La};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
|
-
`?(
|
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=He(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=as(),o=o!==null?o:"",o!==null?(c=li(),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 yc(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=He(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=as(),o=o!==null?o:"",o!==null?(c=li(),c!==null?(_=Dl(),_!==null?(g=$l(),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 yc(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 He(){var a;return a=vt(),a===null&&(a=Je()),a}function vt(){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 Je(){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 as(){var a,n,o,c,_,g;return c=s,_=s,a=Gt(),a!==null?(g=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=tr(),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 Gt(){var a,n;if(n=b(),n===null&&(n=F(),n===null&&(n=er())),n!==null)for(a=[];n!==null;)a.push(n),n=b(),n===null&&(n=F(),n===null&&(n=er()));else a=null;return a}function er(){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 tr(){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 li(){var a,n,o,c,_;return c=s,a=Ps(),a!==null?(_=s,t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=Rn(),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 Ps(){var a,n;return n=s,a=tn(),a===null&&(a=Rt(),a===null&&(a=nr())),a!==null&&(a=function(o){return H.host=t.substring(s,o).toLowerCase(),H.host}(n)),a===null&&(s=n),a}function tn(){var a,n,o,c,_,g;for(c=s,_=s,a=[],g=s,n=ai(),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=ai(),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=sr(),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 ai(){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 sr(){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 nr(){var a,n,o,c,_;return c=s,_=s,t.charCodeAt(s)===91?(a="[",s++):(a=null,h('"["')),a!==null?(n=oi(),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 oi(){var a,n,o,c,_,g,m,E,k,W,pe,Ge,Yt,Ln,Q,$;return Ln=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?(Ge=":",s++):(Ge=null,h('":"')),Ge!==null?(Yt=me(),Yt!==null?a=[a,n,o,c,_,g,m,E,k,W,pe,Ge,Yt]:(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?(Ge=me(),Ge!==null?a=[a,n,o,c,_,g,m,E,k,W,pe,Ge]:(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)}(Ln)),a===null&&(s=Ln),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=Rt()),a}function Rt(){var a,n,o,c,_,g,m,E,k;return E=s,k=s,a=Es(),a!==null?(t.charCodeAt(s)===46?(n=".",s++):(n=null,h('"."')),n!==null?(o=Es(),o!==null?(t.charCodeAt(s)===46?(c=".",s++):(c=null,h('"."')),c!==null?(_=Es(),_!==null?(t.charCodeAt(s)===46?(g=".",s++):(g=null,h('"."')),g!==null?(m=Es(),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 Es(){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 Rn(){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 Dl(){var a,n,o,c;for(a=[],c=s,t.charCodeAt(s)===59?(n=";",s++):(n=null,h('";"')),n!==null?(o=ir(),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=ir(),o!==null?n=[n,o]:(n=null,s=c)):(n=null,s=c);return a}function ir(){var a;return a=rr(),a===null&&(a=Nl(),a===null&&(a=Pl(),a===null&&(a=xl(),a===null&&(a=kl(),a===null&&(a=Ml(),a===null&&(a=Ul())))))),a}function rr(){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 Nl(){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 Pl(){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=gi(),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 xl(){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=wr(),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 kl(){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=Ps(),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 Ml(){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 Ul(){var a,n,o,c,_,g;return c=s,_=s,a=Ll(),a!==null?(g=s,t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=Fl(),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 Ll(){var a,n,o;if(o=s,n=wn(),n!==null)for(a=[];n!==null;)a.push(n),n=wn();else a=null;return a!==null&&(a=function(c,_){return _.join("")}(o,a)),a===null&&(s=o),a}function Fl(){var a,n,o;if(o=s,n=wn(),n!==null)for(a=[];n!==null;)a.push(n),n=wn();else a=null;return a!==null&&(a=function(c,_){return _.join("")}(o,a)),a===null&&(s=o),a}function wn(){var a;return a=In(),a===null&&(a=b(),a===null&&(a=F())),a}function In(){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 $l(){var a,n,o,c,_,g,m;if(g=s,t.charCodeAt(s)===63?(a="?",s++):(a=null,h('"?"')),a!==null)if(n=ui(),n!==null){for(o=[],m=s,t.charCodeAt(s)===38?(c="&",s++):(c=null,h('"&"')),c!==null?(_=ui(),_!==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?(_=ui(),_!==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 ui(){var a,n,o,c,_;return c=s,_=s,a=ci(),a!==null?(t.charCodeAt(s)===61?(n="=",s++):(n=null,h('"="')),n!==null?(o=Hl(),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 ci(){var a,n;if(n=On(),n===null&&(n=b(),n===null&&(n=F())),n!==null)for(a=[];n!==null;)a.push(n),n=On(),n===null&&(n=b(),n===null&&(n=F()));else a=null;return a}function Hl(){var a,n;for(a=[],n=On(),n===null&&(n=b(),n===null&&(n=F()));n!==null;)a.push(n),n=On(),n===null&&(n=b(),n===null&&(n=F()));return a}function On(){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 hi(){var a;return a=pi(),a===null&&(a=ec()),a}function ec(){var a,n,o,c,_,g;return g=s,a=gi(),a!==null?(n=R(),n!==null?(o=Gl(),o!==null?(c=R(),c!==null?(_=or(),_!==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 Gl(){var a;return a=Oe(),a===null&&(a=lr()),a}function lr(){var a,n,o,c;return c=s,a=xn(),a!==null?(t.charCodeAt(s)===58?(n=":",s++):(n=null,h('":"')),n!==null?(o=ar(),o===null&&(o=di()),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function ar(){var a,n,o,c,_;return c=s,a=Vl(),a===null&&(a=fi()),a!==null?(_=s,t.charCodeAt(s)===63?(n="?",s++):(n=null,h('"?"')),n!==null?(o=Kl(),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 Vl(){var a,n,o,c;return c=s,t.substr(s,2)==="//"?(a="//",s+=2):(a=null,h('"//"')),a!==null?(n=jl(),n!==null?(o=fi(),o=o!==null?o:"",o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function fi(){var a,n,o;return o=s,t.charCodeAt(s)===47?(a="/",s++):(a=null,h('"/"')),a!==null?(n=Bl(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function di(){var a,n,o,c;if(c=s,a=Nn(),a!==null){for(n=[],o=Dn();o!==null;)n.push(o),o=Dn();n!==null?a=[a,n]:(a=null,s=c)}else a=null,s=c;return a}function Dn(){var a;return a=C(),a===null&&(a=b(),a===null&&(a=F())),a}function Nn(){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 Bl(){var a,n,o,c,_,g;if(_=s,a=_i(),a!==null){for(n=[],g=s,t.charCodeAt(s)===47?(o="/",s++):(o=null,h('"/"')),o!==null?(c=_i(),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=_i(),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 _i(){var a,n,o,c,_,g;for(_=s,a=[],n=sn();n!==null;)a.push(n),n=sn();if(a!==null){for(n=[],g=s,t.charCodeAt(s)===59?(o=";",s++):(o=null,h('";"')),o!==null?(c=Pn(),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=Pn(),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 Pn(){var a,n;for(a=[],n=sn();n!==null;)a.push(n),n=sn();return a}function sn(){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 xn(){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 jl(){var a;return a=ql(),a===null&&(a=Wl()),a}function ql(){var a,n,o,c;return o=s,c=s,a=as(),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=li(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a=a!==null?a:"",a}function Wl(){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 Kl(){var a,n;for(a=[],n=Dn();n!==null;)a.push(n),n=Dn();return a}function or(){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 ur(){var a;return t.substr(s,6)==="INVITE"?(a="INVITE",s+=6):(a=null,h('"INVITE"')),a}function Yl(){var a;return t.substr(s,3)==="ACK"?(a="ACK",s+=3):(a=null,h('"ACK"')),a}function zl(){var a;return t.substr(s,7)==="OPTIONS"?(a="OPTIONS",s+=7):(a=null,h('"OPTIONS"')),a}function Xl(){var a;return t.substr(s,3)==="BYE"?(a="BYE",s+=3):(a=null,h('"BYE"')),a}function Jl(){var a;return t.substr(s,6)==="CANCEL"?(a="CANCEL",s+=6):(a=null,h('"CANCEL"')),a}function Ql(){var a;return t.substr(s,8)==="REGISTER"?(a="REGISTER",s+=8):(a=null,h('"REGISTER"')),a}function Zl(){var a;return t.substr(s,9)==="SUBSCRIBE"?(a="SUBSCRIBE",s+=9):(a=null,h('"SUBSCRIBE"')),a}function ea(){var a;return t.substr(s,6)==="NOTIFY"?(a="NOTIFY",s+=6):(a=null,h('"NOTIFY"')),a}function ta(){var a;return t.substr(s,5)==="REFER"?(a="REFER",s+=5):(a=null,h('"REFER"')),a}function gi(){var a,n;return n=s,a=ur(),a===null&&(a=Yl(),a===null&&(a=zl(),a===null&&(a=Xl(),a===null&&(a=Jl(),a===null&&(a=Ql(),a===null&&(a=Zl(),a===null&&(a=ea(),a===null&&(a=ta(),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 pi(){var a,n,o,c,_,g;return g=s,a=or(),a!==null?(n=R(),n!==null?(o=sa(),o!==null?(c=R(),c!==null?(_=ia(),_!==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 sa(){var a,n;return n=s,a=na(),a!==null&&(a=function(o,c){H.status_code=parseInt(c.join(""))}(n,a)),a===null&&(s=n),a}function na(){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 ia(){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 tc(){var a,n,o,c,_,g;if(_=s,a=Ti(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=Ti(),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=Ti(),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 Hf(){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 Gf(){var a,n,o,c,_,g,m;if(_=s,a=ee(),a===null)if(g=s,a=cr(),a!==null){for(n=[],m=s,o=be(),o!==null?(c=cr(),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=cr(),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 cr(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=os()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=kn(),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=kn(),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 nn(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 os(){var a,n,o,c,_;return _=s,a=us(),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 us(){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 kn(){var a;return a=hr(),a===null&&(a=ra(),a===null&&(a=ut())),a}function hr(){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=ks(),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 ra(){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=xs(),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 xs(){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 ks(){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 ut(){var a,n,o,c,_,g;return c=s,_=s,a=L(),a!==null?(g=s,n=K(),n!==null?(o=ct(),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 ct(){var a;return a=L(),a===null&&(a=Ps(),a===null&&(a=we())),a}function sc(){var a,n,o,c,_,g;if(_=s,a=nc(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=fr(),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=fr(),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 nc(){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 fr(){var a;return a=dr(),a===null&&(a=ut()),a}function dr(){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 ic(){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 Vf(){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 Bf(){var a,n;return n=s,a=rc(),a!==null&&(a=function(o){H=t.substring(s,o)}(n)),a===null&&(s=n),a}function rc(){var a,n,o,c,_,g,m,E;if(m=s,a=la(),a!==null)if(n=j(),n!==null)if(o=ua(),o!==null){for(c=[],E=s,_=M(),_!==null?(g=_r(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=M(),_!==null?(g=_r(),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 la(){var a;return a=aa(),a===null&&(a=oa()),a}function aa(){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=mi()))))),a}function oa(){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=mi())),a}function mi(){var a;return a=L(),a===null&&(a=vi()),a}function vi(){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 ua(){var a;return a=mi(),a===null&&(a=L()),a}function _r(){var a,n,o,c;return c=s,a=L(),a!==null?(n=K(),n!==null?(o=gr(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function gr(){var a;return a=L(),a===null&&(a=we()),a}function lc(){var a,n,o,c;return c=s,a=ac(),a!==null?(n=q(),n!==null?(o=gi(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function ac(){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 oc(){var a,n;return n=s,a=xs(),a!==null&&(a=function(o,c){H=c}(n,a)),a===null&&(s=n),a}function jf(){var a,n,o,c,_,g,m;if(_=s,g=s,a=Ti(),a!==null){for(n=[],m=s,o=M(),o!==null?(c=ut(),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=ut(),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 Ti(){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 yi(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=os()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=ca(),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=ca(),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 nn(H.uri,H.display_name,H.params),k&&H.setParam("tag",k)}catch{H=-1}}()),a===null&&(s=_),a}function ca(){var a;return a=Si(),a===null&&(a=ut()),a}function Si(){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 ha(){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 qf(){var a,n;return n=s,a=xs(),a!==null&&(a=function(o,c){H=c}(n,a)),a===null&&(s=n),a}function Wf(){var a,n,o,c,_,g,m,E,k,W;for(E=s,k=s,a=[],n=us();n!==null;)a.push(n),n=us();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=ut(),m!==null?g=[g,m]:(g=null,s=W)):(g=null,s=W);g!==null;)_.push(g),W=s,g=M(),g!==null?(m=ut(),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 nn(H.uri,H.display_name,H.params)}catch{H=-1}}()),a===null&&(s=E),a}function Kf(){var a;return a=fa(),a}function fa(){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=Ms(),o!==null){for(c=[],E=s,_=be(),_!==null?(g=Ms(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=be(),_!==null?(g=Ms(),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=pr()),a}function pr(){var a,n,o,c,_,g,m,E;if(m=s,a=L(),a!==null)if(n=q(),n!==null)if(o=Mn(),o!==null){for(c=[],E=s,_=be(),_!==null?(g=Mn(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=be(),_!==null?(g=Mn(),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 Mn(){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 Ms(){var a;return a=Ei(),a===null&&(a=_a(),a===null&&(a=Ai(),a===null&&(a=pa(),a===null&&(a=ma(),a===null&&(a=va(),a===null&&(a=Ta(),a===null&&(a=Mn()))))))),a}function Ei(){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=da(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function da(){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 _a(){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=Ci(),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=Ci(),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=Ci(),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 Ci(){var a;return a=lr(),a===null&&(a=fi()),a}function Ai(){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=ga(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function ga(){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 pa(){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 ma(){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 va(){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 Ta(){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=bi(),c!==null){for(_=[],W=s,t.charCodeAt(s)===44?(g=",",s++):(g=null,h('","')),g!==null?(m=bi(),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=bi(),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 bi(){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 mr(){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 Yf(){var a,n,o,c,_,g,m;if(_=s,g=s,a=vr(),a!==null){for(n=[],m=s,o=be(),o!==null?(c=vr(),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=vr(),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 vr(){var a,n,o,c,_,g,m;if(_=s,g=s,a=os(),a!==null){for(n=[],m=s,o=M(),o!==null?(c=ut(),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=ut(),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 nn(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 Tr(){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=ya(),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=ya(),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 ya(){var a;return a=yr(),a===null&&(a=ut()),a}function yr(){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 uc(){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 zf(){var a,n,o,c,_,g;if(_=s,a=Sr(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=Sr(),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=Sr(),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 Sr(){var a,n,o,c,_,g;if(_=s,a=os(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=ut(),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=ut(),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 Er(){var a,n,o,c,_,g;if(_=s,a=cc(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Cr(),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=Cr(),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 cc(){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 Cr(){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=Ar(),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=xs(),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=xs(),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=ut()))),a}function Ar(){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 hc(){var a;return a=I(),a=a!==null?a:"",a}function Xf(){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 Jf(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=os()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=Sa(),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=Sa(),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 nn(H.uri,H.display_name,H.params),k&&H.setParam("tag",k)}catch{H=-1}}()),a===null&&(s=_),a}function Sa(){var a;return a=Si(),a===null&&(a=ut()),a}function Ea(){var a,n,o,c,_,g;if(_=s,a=br(),a!==null){for(n=[],g=s,o=be(),o!==null?(c=br(),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=br(),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 br(){var a,n,o,c,_,g,m,E;if(m=s,a=Ia(),a!==null)if(n=q(),n!==null)if(o=Na(),o!==null){for(c=[],E=s,_=M(),_!==null?(g=Un(),g!==null?_=[_,g]:(_=null,s=E)):(_=null,s=E);_!==null;)c.push(_),E=s,_=M(),_!==null?(g=Un(),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 Un(){var a;return a=Rr(),a===null&&(a=Ca(),a===null&&(a=Aa(),a===null&&(a=ba(),a===null&&(a=Ra(),a===null&&(a=ut()))))),a}function Rr(){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=wr(),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 Ca(){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=Ps(),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 Aa(){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=Rt(),o===null&&(o=oi()),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 ba(){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 Ra(){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=wa(),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 wa(){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 Ia(){var a,n,o,c,_,g;return g=s,a=Oa(),a!==null?(n=j(),n!==null?(o=L(),o!==null?(c=j(),c!==null?(_=Da(),_!==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 Oa(){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 Da(){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 Na(){var a,n,o,c,_;return c=s,a=Pa(),a!==null?(_=s,n=Y(),n!==null?(o=xa(),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 Pa(){var a,n;return n=s,a=Rt(),a===null&&(a=nr(),a===null&&(a=tn())),a!==null&&(a=function(o){H.host=t.substring(s,o)}(n)),a===null&&(s=n),a}function xa(){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 wr(){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 ka(){var a;return a=fa(),a}function Qf(){var a,n,o,c,_,g;if(_=s,a=fc(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Ir(),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=Ir(),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 fc(){var a,n;return n=s,a=xs(),a!==null&&(a=function(o,c){H.expires=c}(n,a)),a===null&&(s=n),a}function Ir(){var a;return a=Or(),a===null&&(a=ut()),a}function Or(){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 dc(){var a,n,o,c;return c=s,a=L(),a!==null?(n=P(),n!==null?(o=_c(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function _c(){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 gc(){var a,n;for(a=[],n=S();n!==null;)a.push(n),n=S();return a}function Zf(){var a,n,o;return o=s,t.substr(s,5)==="uuid:"?(a="uuid:",s+=5):(a=null,h('"uuid:"')),a!==null?(n=pc(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function pc(){var a,n,o,c,_,g,m,E,k,W,pe;return W=s,pe=s,a=hs(),a!==null?(t.charCodeAt(s)===45?(n="-",s++):(n=null,h('"-"')),n!==null?(o=cs(),o!==null?(t.charCodeAt(s)===45?(c="-",s++):(c=null,h('"-"')),c!==null?(_=cs(),_!==null?(t.charCodeAt(s)===45?(g="-",s++):(g=null,h('"-"')),g!==null?(m=cs(),m!==null?(t.charCodeAt(s)===45?(E="-",s++):(E=null,h('"-"')),E!==null?(k=Ma(),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(Ge,Yt){H=t.substring(s+5,Ge)}(W,a[0])),a===null&&(s=W),a}function cs(){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 hs(){var a,n,o;return o=s,a=cs(),a!==null?(n=cs(),n!==null?a=[a,n]:(a=null,s=o)):(a=null,s=o),a}function Ma(){var a,n,o,c;return c=s,a=cs(),a!==null?(n=cs(),n!==null?(o=cs(),o!==null?a=[a,n,o]:(a=null,s=c)):(a=null,s=c)):(a=null,s=c),a}function mc(){var a,n,o,c,_,g,m;if(_=s,g=s,a=ge(),a===null&&(a=os()),a!==null){for(n=[],m=s,o=M(),o!==null?(c=ut(),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=ut(),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 nn(H.uri,H.display_name,H.params)}catch{H=-1}}()),a===null&&(s=_),a}function ed(){var a,n,o,c,_,g;if(_=s,a=vc(),a!==null){for(n=[],g=s,o=M(),o!==null?(c=Dr(),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=Dr(),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 vc(){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 Dr(){var a;return a=Nr(),a===null&&(a=Ua(),a===null&&(a=La(),a===null&&(a=ut()))),a}function Nr(){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 Ua(){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 La(){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 Tc(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 td(){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 yc=Hs(),nn=_h(),H={},G=l[r]();if(G===null||s!==t.length){var Fa=Math.max(s,i),$a=Fa<t.length?t.charAt(Fa):null,Sc=td();return new this.SyntaxError(Tc(f),$a,Fa,Sc.line,Sc.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}()),gh}var ph,M_;function Hs(){if(M_)return ph;M_=1;const u=Ue,e=xt(),t=_s();return ph=class u0{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 u0(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}},ph}var U_;function xt(){if(U_)return gt;U_=1;const u=Ue,e=Hs(),t=_s();gt.str_utf8_length=i=>unescape(encodeURIComponent(i)).length;const r=gt.isFunction=i=>i!==void 0?Object.prototype.toString.call(i)==="[object Function]":!1;gt.isString=i=>i!==void 0?Object.prototype.toString.call(i)==="[object String]":!1,gt.isDecimal=i=>!isNaN(i)&&parseFloat(i)===parseInt(i,10),gt.isEmpty=i=>i===null||i===""||i===void 0||Array.isArray(i)&&i.length===0||typeof i=="number"&&isNaN(i),gt.hasMethods=function(i,...f){for(const h of f)if(r(i[h]))return!1;return!0};const l=gt.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};gt.newTag=()=>l(10),gt.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)}),gt.hostType=i=>{if(i){if(i=t.parse(i,"host"),i!==-1)return i.host_type}else return};const s=gt.escapeUser=i=>encodeURIComponent(decodeURIComponent(i)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return gt.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},gt.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},gt.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},gt.getRandomTestNetIP=()=>{function i(f,h){return Math.floor(Math.random()*(h-f+1)+f)}return`192.0.2.${i(1,254)}`},gt.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,He=0;for(;He<we;)_e=(He-He%4)/4,Oe=He%4*8,ge[_e]=ge[_e]|fe.charCodeAt(He)<<Oe,He++;return _e=(He-He%4)/4,Oe=He%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()},gt.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()}},gt.cloneArray=i=>i&&i.slice()||[],gt.cloneObject=(i,f={})=>i&&Object.assign({},i)||f,gt}const L_=Xt,X1=Et,kt=Ue,St=xt(),F_=_h(),J1=_s(),mh=new X1("SIPMessage");class wo{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=St.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",kt.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 F_(f,d,h),this.setHeader("to",this.to.toString());const p=l.from_uri||r.configuration.uri,v={tag:l.from_tag||St.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 F_(p,T,v),this.setHeader("from",this.from.toString());const y=l.call_id||r.configuration.jssip_id+St.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[St.headerize(e)]=Array.isArray(t)?t:[t]}getHeader(e){const t=this.headers[St.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[St.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[St.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=L_.parse(this.body||""),this.sdp)}toString(){let e=`${this.method} ${this.ruri} SIP/2.0\r
|
76
|
-
`;for(const
|
77
|
-
`;for(const
|
78
|
-
`;const
|
79
|
-
`,
|
80
|
-
`,
|
81
|
-
`,this.body){const
|
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}(),rf={};function lf(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Op(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 Op(c,t){if(c){if(typeof c=="string")return af(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 af(c,t)}}function af(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 Dp=ft,Oo=ts(),Do=fs,Ql=new Dp("Parser");rf.parseMessage=function(c,t){var n,a,o=c.indexOf(`\r
|
62
|
+
`);if(o===-1){Ql.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=c.substring(0,o),r=Oo.parse(s,"Request_Response");if(r===-1){Ql.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else r.status_code?(n=new Do.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new Do.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;for(var d=o+2;;){if(o=Np(c,d),o===-2){a=d+2;break}else if(o===-1){Ql.warn("parseMessage() | malformed message");return}if(r=Up(n,c,d,o),r!==!0){Ql.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 Np(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 Up(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=Oo.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=lf(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=Oo.parse(d,"Contact"),o===-1)o=void 0;else{var T=lf(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 Do.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 Zl(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Pp(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 Pp(c,t){if(c){if(typeof c=="string")return of(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 of(c,t)}}function of(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=ft,uf=st,cf=fs,No=Rt(),Uo=new xp("sanityCheck"),kp=[Gp],Mp=[Hp,Fp,jp,qp],Lp=[Vp,Bp],Fe,ns,ff,$p=function(c,t,n){Fe=c,ns=t,ff=n;var a=Zl(kp),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(Fe instanceof cf.IncomingRequest){var r=Zl(Mp),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(Fe instanceof cf.IncomingResponse){var _=Zl(Lp),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 Hp(){if(Fe.s("to").uri.scheme!=="sip")return qr(416),!1}function Fp(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===ns.configuration.jssip_id)return qr(482),!1}function jp(){var c=No.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return qr(400),!1}function qp(){var c=Fe.from_tag,t=Fe.call_id,n=Fe.cseq,a;if(!Fe.to_tag)if(Fe.method===uf.INVITE){if(ns._transactions.ist[Fe.via_branch])return!1;for(var o in ns._transactions.ist)if(Object.prototype.hasOwnProperty.call(ns._transactions.ist,o)&&(a=ns._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return qr(482),!1}else{if(ns._transactions.nist[Fe.via_branch])return!1;for(var s in ns._transactions.nist)if(Object.prototype.hasOwnProperty.call(ns._transactions.nist,s)&&(a=ns._transactions.nist[s],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return qr(482),!1}}function Vp(){if(Fe.getHeaders("via").length>1)return Uo.debug("more than one Via header field present in the response, dropping the response"),!1}function Bp(){var c=No.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return Uo.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function Gp(){for(var c=["from","to","call_id","cseq","via"],t=0,n=c;t<n.length;t++){var a=n[t];if(!Fe.hasHeader(a))return Uo.debug("missing mandatory header field : ".concat(a,", dropping the response")),!1}}function qr(c){var t=Fe.getHeaders("via"),n,a="SIP/2.0 ".concat(c," ").concat(uf.REASON_PHRASE[c],`\r
|
65
|
+
`),o=Zl(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=Fe.getHeader("To"),Fe.to_tag||(n+=";tag=".concat(No.newTag())),a+="To: ".concat(n,`\r
|
67
|
+
`),a+="From: ".concat(Fe.getHeader("From"),`\r
|
68
|
+
`),a+="Call-ID: ".concat(Fe.call_id,`\r
|
69
|
+
`),a+="CSeq: ".concat(Fe.cseq," ").concat(Fe.method,`\r
|
70
|
+
`),a+=`\r
|
71
|
+
`,ff.send(a)}var Po={};function hf(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.
|
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 Wp(c,t){if(c){if(typeof c=="string")return df(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 df(c,t)}}function df(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 kn=Rt(),en=st,xo=ts(),_f=bs(),ko=bo,Mo=Is;Po.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:en.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:en.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:en.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(kn.createRandomToken(12),".invalid")};var ea={mandatory:{sockets:function(t){var n=[];if(ko.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=hf(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&ko.isSocket(s.socket)?n.push(s):ko.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(en.SIP,":").concat(t));var n=_f.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(xo.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(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=xo.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)),xo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(kn.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===en.INVITE||t===en.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(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(en.SIP,":").concat(t));var n=_f.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=hf(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}}};Po.load=function(c,t){for(var n in ea.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=ea.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Mo.ConfigurationError(n,a)}else throw new Mo.ConfigurationError(n);for(var s in ea.optional)if(t.hasOwnProperty(s)){var r=t[s];if(kn.isEmpty(r))continue;var d=ea.optional[s](r);if(d!==void 0)c[s]=d;else throw new Mo.ConfigurationError(s,r)}};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 Kp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pf(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 mf(c,t,n){return t&&pf(c.prototype,t),n&&pf(c,n),c}function Yp(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&&Lo(c,t)}function Lo(c,t){return Lo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Lo(c,t)}function Jp(c){var t=Xp();return function(){var a=sa(c),o;if(t){var s=sa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return zp(this,o)}}function zp(c,t){return t&&(ta(t)==="object"||typeof t=="function")?t:gf(c)}function gf(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Xp(){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 sa(c){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},sa(c)}var Qp=ct.EventEmitter,Zp=ft,_t=st,em=jd,Tf=z_,vf=up,Ef=Sp,$o=Pr,tm=wp,na=Rt(),sm=Is,nm=bs(),rm=rf,Ho=fs,im=$p,Fo=Po,qe=new Zp("UA"),pt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},lm=function(c){Yp(n,c);var t=Jp(n);mf(n,null,[{key:"C",get:function(){return pt}}]);function n(a){var o;if(Kp(this,n),qe.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},Fo.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=pt.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=pt.STATUS_NOT_READY,o._error=pt.CONFIGURATION_ERROR,s}return o._registrator=new em(gf(o)),o}return mf(n,[{key:"start",value:function(){qe.debug("start()"),this._status===pt.STATUS_INIT?this._transport.connect():this._status===pt.STATUS_USER_CLOSED?(qe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=pt.STATUS_INIT,this._transport.connect()):this._status===pt.STATUS_READY?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}},{key:"register",value:function(){qe.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(o){qe.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){qe.debug("call()");var r=new Tf(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){qe.debug("sendMessage()");var d=new vf(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){qe.debug("sendOptions()");var d=new Ef(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){qe.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(qe.debug("stop()"),this._dynConfiguration={},this._status===pt.STATUS_USER_CLOSED){qe.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)){qe.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=pt.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 na.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:qe.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 qe.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){qe.debug("Request-URI does not point to us"),o.method!==_t.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===_t.SIPS){o.reply_sl(416);return}if(!$o.checkTransaction(this,o)){if(s===_t.INVITE?new $o.InviteServerTransaction(this,this._transport,o):s!==_t.ACK&&s!==_t.CANCEL&&new $o.NonInviteServerTransaction(this,this._transport,o),s===_t.OPTIONS){if(this.listeners("newOptions").length===0){o.reply(200);return}var r=new Ef(this);r.init_incoming(o)}else if(s===_t.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new vf(this);d.init_incoming(o)}else if(s===_t.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===_t.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(qe.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==_t.ACK&&o.reply(481);else switch(s){case _t.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 Tf(this),_.init_incoming(o);else qe.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case _t.BYE:o.reply(481);break;case _t.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):qe.debug("received CANCEL request for a non existent session");break;case _t.ACK:break;case _t.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{Fo.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=na.newUUID()),this._configuration.jssip_id=na.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=am.bind(this),this._transport.onconnect=om.bind(this),this._transport.ondisconnect=um.bind(this),this._transport.ondata=cm.bind(this)}catch(g){throw qe.warn(g),new sm.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 nm("sip",na.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}));qe.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(Fo.settings,_))switch(_){case"uri":case"registrar_server":qe.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":qe.debug("- ".concat(_,": NOT SHOWN"));break;default:qe.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{key:"C",get:function(){return pt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}(Qp);function am(c){this.emit("connecting",c)}function om(c){this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function um(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!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_NOT_READY,this._error=pt.NETWORK_ERROR)}function cm(c){var t=c.transport,n=c.message;if(n=rm.parseMessage(n,this),!!n&&!(this._status===pt.STATUS_USER_CLOSED&&n instanceof Ho.IncomingRequest)&&im(n,this,t)){if(n instanceof Ho.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Ho.IncomingResponse){var a;switch(n.method){case _t.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case _t.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function fm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sf(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 hm(c,t,n){return t&&Sf(c.prototype,t),n&&Sf(c,n),c}var dm=ft,_m=ts(),wt=new dm("WebSocketInterface"),pm=function(){function c(t){fm(this,c),wt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=_m.parse(t,"absoluteURI");if(n===-1)throw wt.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw wt.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 hm(c,[{key:"connect",value:function(){if(wt.debug("connect()"),this.isConnected()){wt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){wt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),wt.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(){wt.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 wt.debug("send()"),this.isConnected()?(this._ws.send(n),!0):(wt.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(){wt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(n){var a=n.wasClean,o=n.code,s=n.reason;wt.debug("WebSocket ".concat(this._url," closed")),a===!1&&wt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;wt.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){wt.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}(),jo=vl,mm=st,gm=Is,Tm=Rt(),vm=lm,Em=bs(),Sm=Xa(),ym=ts(),Am=pm,Cm=Un("JsSIP");Cm("version %s",jo.version);var yf={C:mm,Exceptions:gm,Utils:Tm,UA:vm,URI:Em,NameAddrHeader:Sm,WebSocketInterface:Am,Grammar:ym,debug:Un,get name(){return jo.title},get version(){return jo.version}};const Mn=Un,Ln="JsSIP";var at=class{constructor(t){t?(this._debug=Mn.default(`${Ln}:${t}`),this._warn=Mn.default(`${Ln}:WARN:${t}`),this._error=Mn.default(`${Ln}:ERROR:${t}`)):(this._debug=Mn.default(Ln),this._warn=Mn.default(`${Ln}:WARN`),this._error=Mn.default(`${Ln}: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 ra=Me(at),Af=vl;var De={USER_AGENT:`${Af.title} ${Af.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=Me(De);var Ze={},qo,Cf;function Vo(){if(Cf)return qo;Cf=1;const c=ps(),t=Yt();return qo=class $h{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 $h(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}},qo}var Bo,Rf;function Yt(){return Rf||(Rf=1,Bo=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:Z,token:U,token_nodot:P,separators:se,word:it,STAR:ee,SLASH:Y,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:ke,COMMA:Re,SEMI:le,COLON:ye,LDQUOT:lt,RDQUOT:ot,comment:Ee,ctext:Ae,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:de,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:tt,uri_scheme_sip:He,userinfo:jt,user:Ct,user_unreserved:Bn,password:Gn,hostport:cn,host:ls,hostname:As,domainlabel:fn,toplabel:Wn,IPv6reference:Kn,IPv6address:hn,h16:me,ls32:ae,IPv4address:ut,dec_octet:Zt,port:$s,uri_parameters:ui,uri_parameter:Yn,transport_param:Jn,user_param:ci,method_param:fi,ttl_param:hi,maddr_param:di,lr_param:_i,other_param:pi,pname:mi,pvalue:gi,paramchar:Hs,param_unreserved:Fs,headers:Ti,header:dn,hname:_n,hvalue:vi,hnv_unreserved:js,Request_Response:pn,Request_Line:wa,Request_URI:Ei,absoluteURI:zn,hier_part:Xn,net_path:Si,abs_path:mn,opaque_part:gn,uric:qs,uric_no_slash:Vs,path_segments:yi,segment:Tn,param:Bs,pchar:Cs,scheme:Gs,authority:Ai,srvr:Ci,reg_name:Ri,query:Ii,SIP_Version:Qn,INVITEm:Zn,ACKm:bi,OPTIONSm:wi,BYEm:Oi,CANCELm:Di,REGISTERm:Ni,SUBSCRIBEm:Ui,NOTIFYm:Pi,REFERm:xi,Method:vn,Status_Line:En,Status_Code:ki,extension_code:Mi,Reason_Phrase:Li,Allow_Events:Oa,Call_ID:Du,Contact:Nu,contact_param:er,name_addr:qt,display_name:Vt,contact_params:Ws,c_p_q:tr,c_p_expires:$i,delta_seconds:as,qvalue:os,generic_param:Je,gen_value:ze,Content_Disposition:Da,disp_type:Na,disp_param:sr,handling_param:nr,Content_Encoding:Ua,Content_Length:Uu,Content_Type:Pu,media_type:Pa,m_type:Hi,discrete_type:Fi,composite_type:ji,extension_token:Sn,x_token:yn,m_subtype:qi,m_parameter:rr,m_value:ir,CSeq:xa,CSeq_value:ka,Expires:Ma,Event:xu,event_type:An,From:Cn,from_param:Vi,tag_param:Rn,Max_Forwards:Bi,Min_Expires:ku,Name_Addr_Header:Mu,Proxy_Authenticate:Lu,challenge:Gi,other_challenge:lr,auth_param:Ks,digest_cln:us,realm:In,realm_value:Wi,domain:Ki,URI:bn,nonce:wn,nonce_value:Yi,opaque:Ji,stale:zi,algorithm:Xi,qop_options:Qi,qop_value:On,Proxy_Require:ar,Record_Route:$u,rec_route:or,Reason:ur,reason_param:Zi,reason_cause:cr,Require:La,Route:Hu,route_param:fr,Subscription_State:hr,substate_value:$a,subexp_params:dr,event_reason_value:_r,Subject:Ha,Supported:Fu,To:ju,to_param:el,Via:tl,via_param:pr,via_params:Ys,via_ttl:mr,via_maddr:sl,via_received:nl,via_branch:rl,response_port:il,rport:ll,sent_protocol:al,protocol_name:ol,transport:ul,sent_by:cl,via_host:fl,via_port:hl,ttl:gr,WWW_Authenticate:dl,Session_Expires:qu,s_e_expires:Fa,s_e_params:Tr,s_e_refresher:vr,extension_header:ja,header_value:qa,message_body:Va,uuid_URI:Vu,uuid:Ba,hex4:Bt,hex8:Gt,hex12:_l,Refer_To:Ga,Replaces:Bu,call_id:Wa,replaces_param:Er,to_tag:Sr,from_tag:pl,early_flag:ml};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 Z(){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 it(){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 Y(){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 ke(){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 Re(){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 lt(){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 ot(){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=de(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ae(),l===null&&(l=de(),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=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());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=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());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 de(){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=jt(),l=l!==null?l:"",l!==null?(u=cn(),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 Ya(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=jt(),l=l!==null?l:"",l!==null?(u=cn(),u!==null?(f=ui(),f!==null?(p=Ti(),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 Ya(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=tt(),i===null&&(i=He()),i}function tt(){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 He(){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 jt(){var i,e,l,u,f,p;return u=s,f=s,i=Ct(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Gn(),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 Ct(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=Bn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=Bn()));else i=null;return i}function Bn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function Gn(){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 cn(){var i,e,l,u,f;return u=s,i=ls(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=$s(),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 ls(){var i,e;return e=s,i=As(),i===null&&(i=ut(),i===null&&(i=Kn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function As(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=fn(),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=fn(),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=Wn(),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 fn(){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 Wn(){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 Kn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=hn(),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 hn(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js,M,R;return Js=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?(Dt=ae(),Dt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(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)}(Js)),i===null&&(s=Js),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=ut()),i}function ut(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=Zt(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=Zt(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=Zt(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=Zt(),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 Zt(){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 $s(){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 ui(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Yn(),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=Yn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Yn(){var i;return i=Jn(),i===null&&(i=ci(),i===null&&(i=fi(),i===null&&(i=hi(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi())))))),i}function Jn(){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 ci(){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 fi(){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=vn(),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 hi(){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=gr(),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 di(){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=ls(),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 _i(){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 pi(){var i,e,l,u,f,p;return u=s,f=s,i=mi(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=gi(),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 mi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function gi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Hs(){var i;return i=Fs(),i===null&&(i=N(),i===null&&(i=Se())),i}function Fs(){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 Ti(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=dn(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=dn(),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=dn(),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 dn(){var i,e,l,u,f;return u=s,f=s,i=_n(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=vi(),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 _n(){var i,e;if(e=js(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function vi(){var i,e;for(i=[],e=js(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));return i}function js(){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 pn(){var i;return i=En(),i===null&&(i=wa()),i}function wa(){var i,e,l,u,f,p;return p=s,i=vn(),i!==null?(e=I(),e!==null?(l=Ei(),l!==null?(u=I(),u!==null?(f=Qn(),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 Ei(){var i;return i=we(),i===null&&(i=zn()),i}function zn(){var i,e,l,u;return u=s,i=Gs(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Xn(),l===null&&(l=gn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Xn(){var i,e,l,u,f;return u=s,i=Si(),i===null&&(i=mn()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Ii(),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 Si(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=Ai(),e!==null?(l=mn(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function mn(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=yi(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function gn(){var i,e,l,u;if(u=s,i=Vs(),i!==null){for(e=[],l=qs();l!==null;)e.push(l),l=qs();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function qs(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Vs(){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 yi(){var i,e,l,u,f,p;if(f=s,i=Tn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=Tn(),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=Tn(),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 Tn(){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=Bs(),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=Bs(),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 Bs(){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 Gs(){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 Ai(){var i;return i=Ci(),i===null&&(i=Ri()),i}function Ci(){var i,e,l,u;return l=s,u=s,i=jt(),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=cn(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Ri(){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 Ii(){var i,e;for(i=[],e=qs();e!==null;)i.push(e),e=qs();return i}function Qn(){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 Zn(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function bi(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function wi(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Oi(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function Di(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function Ni(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Ui(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Pi(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function xi(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function vn(){var i,e;return e=s,i=Zn(),i===null&&(i=bi(),i===null&&(i=wi(),i===null&&(i=Oi(),i===null&&(i=Di(),i===null&&(i=Ni(),i===null&&(i=Ui(),i===null&&(i=Pi(),i===null&&(i=xi(),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 En(){var i,e,l,u,f,p;return p=s,i=Qn(),i!==null?(e=I(),e!==null?(l=ki(),l!==null?(u=I(),u!==null?(f=Li(),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 ki(){var i,e;return e=s,i=Mi(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Mi(){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 Li(){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 Oa(){var i,e,l,u,f,p;if(f=s,i=An(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=An(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=An(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Du(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),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 Nu(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=er(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=er(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=er(),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 er(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=qt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ws(),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=Ws(),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 Rs(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 qt(){var i,e,l,u,f;return f=s,i=Vt(),i=i!==null?i:"",i!==null?(e=ke(),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 Vt(){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 Ws(){var i;return i=tr(),i===null&&(i=$i(),i===null&&(i=Je())),i}function tr(){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=os(),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 $i(){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=as(),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 as(){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 os(){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 Je(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=ze(),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 ze(){var i;return i=U(),i===null&&(i=ls(),i===null&&(i=Ie())),i}function Da(){var i,e,l,u,f,p;if(f=s,i=Na(),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 Na(){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 sr(){var i;return i=nr(),i===null&&(i=Je()),i}function nr(){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 Ua(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),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=Re(),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 Uu(){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 Pu(){var i,e;return e=s,i=Pa(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function Pa(){var i,e,l,u,f,p,m,v;if(m=s,i=Hi(),i!==null)if(e=Y(),e!==null)if(l=qi(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=rr(),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=rr(),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 Hi(){var i;return i=Fi(),i===null&&(i=ji()),i}function Fi(){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=Sn()))))),i}function ji(){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=Sn())),i}function Sn(){var i;return i=U(),i===null&&(i=yn()),i}function yn(){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 qi(){var i;return i=Sn(),i===null&&(i=U()),i}function rr(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=ir(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ir(){var i;return i=U(),i===null&&(i=Ie()),i}function xa(){var i,e,l,u;return u=s,i=ka(),i!==null?(e=ve(),e!==null?(l=vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ka(){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 Ma(){var i,e;return e=s,i=as(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function xu(){var i,e,l,u,f,p,m;if(f=s,p=s,i=An(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),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=Je(),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 An(){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 Cn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=qt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Vi(),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=Vi(),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 Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function Vi(){var i;return i=Rn(),i===null&&(i=Je()),i}function Rn(){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 Bi(){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 ku(){var i,e;return e=s,i=as(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Mu(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Vt();e!==null;)i.push(e),e=Vt();if(i!==null)if(e=ke(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Je(),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=Je(),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 Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function Lu(){var i;return i=Gi(),i}function Gi(){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=us(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=us(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=us(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=lr()),i}function lr(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ks(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ks(){var i,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 us(){var i;return i=In(),i===null&&(i=Ki(),i===null&&(i=wn(),i===null&&(i=Ji(),i===null&&(i=zi(),i===null&&(i=Xi(),i===null&&(i=Qi(),i===null&&(i=Ks()))))))),i}function In(){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=Wi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Wi(){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 Ki(){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=lt(),l!==null)if(u=bn(),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=bn(),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=bn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=ot(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function bn(){var i;return i=zn(),i===null&&(i=mn()),i}function wn(){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=Yi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yi(){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 Ji(){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 zi(){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 Xi(){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 Qi(){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=lt(),l!==null){if(S=s,u=On(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=On(),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=On(),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=ot(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function On(){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 ar(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),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=Re(),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 $u(){var i,e,l,u,f,p,m;if(f=s,p=s,i=or(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=or(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=or(),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 or(){var i,e,l,u,f,p,m;if(f=s,p=s,i=qt(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),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=Je(),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 Rs(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 ur(){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=Zi(),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=Zi(),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 Zi(){var i;return i=cr(),i===null&&(i=Je()),i}function cr(){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 La(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),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=Re(),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 Hu(){var i,e,l,u,f,p;if(f=s,i=fr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=fr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=fr(),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 fr(){var i,e,l,u,f,p;if(f=s,i=qt(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Je(),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=Je(),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 hr(){var i,e,l,u,f,p;if(f=s,i=$a(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=dr(),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=dr(),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 $a(){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 dr(){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=_r(),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=as(),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=as(),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=Je()))),i}function _r(){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 Ha(){var i;return i=B(),i=i!==null?i:"",i}function Fu(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),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=Re(),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 ju(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=qt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=el(),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=el(),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 Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function el(){var i;return i=Rn(),i===null&&(i=Je()),i}function tl(){var i,e,l,u,f,p;if(f=s,i=pr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=pr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=pr(),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 pr(){var i,e,l,u,f,p,m,v;if(m=s,i=al(),i!==null)if(e=ve(),e!==null)if(l=cl(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=Ys(),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=Ys(),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 Ys(){var i;return i=mr(),i===null&&(i=sl(),i===null&&(i=nl(),i===null&&(i=rl(),i===null&&(i=il(),i===null&&(i=Je()))))),i}function mr(){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=gr(),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 sl(){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=ls(),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 nl(){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=ut(),l===null&&(l=hn()),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 rl(){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 il(){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=ll(),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 ll(){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 al(){var i,e,l,u,f,p;return p=s,i=ol(),i!==null?(e=Y(),e!==null?(l=U(),l!==null?(u=Y(),u!==null?(f=ul(),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 ol(){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 ul(){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 cl(){var i,e,l,u,f;return u=s,i=fl(),i!==null?(f=s,e=ye(),e!==null?(l=hl(),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 fl(){var i,e;return e=s,i=ut(),i===null&&(i=Kn(),i===null&&(i=As())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function hl(){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 gr(){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 dl(){var i;return i=Gi(),i}function qu(){var i,e,l,u,f,p;if(f=s,i=Fa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Fa(){var i,e;return e=s,i=as(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function Tr(){var i;return i=vr(),i===null&&(i=Je()),i}function vr(){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 ja(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=qa(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function qa(){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 Va(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function Vu(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Ba(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ba(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=Gt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Bt(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Bt(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Bt(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=_l(),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,Dt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Bt(){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 Gt(){var i,e,l;return l=s,i=Bt(),i!==null?(e=Bt(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _l(){var i,e,l,u;return u=s,i=Bt(),i!==null?(e=Bt(),e!==null?(l=Bt(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Ga(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=qt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),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=Je(),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 Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function Bu(){var i,e,l,u,f,p;if(f=s,i=Wa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Er(),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=Er(),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 Wa(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),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 Er(){var i;return i=Sr(),i===null&&(i=pl(),i===null&&(i=ml(),i===null&&(i=Je()))),i}function Sr(){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 pl(){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 ml(){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 Ka(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 Gu(){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 Ya=ps(),Rs=Vo(),b={},w=o[a]();if(w===null||s!==n.length){var gl=Math.max(s,r),Tl=gl<n.length?n.charAt(gl):null,Ja=Gu();return new this.SyntaxError(Ka(d),Tl,gl,Ja.line,Ja.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}()),Bo}var Go,If;function ps(){if(If)return Go;If=1;const c=De,t=mt(),n=Yt();return Go=class Hh{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 Hh(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}},Go}var bf;function mt(){if(bf)return Ze;bf=1;const c=De,t=ps(),n=Yt();Ze.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=Ze.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;Ze.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,Ze.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),Ze.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),Ze.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=Ze.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};Ze.newTag=()=>o(10),Ze.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)}),Ze.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=Ze.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return Ze.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},Ze.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[_]),_},Ze.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},Ze.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},Ze.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,de=Ae&1073741824,_e=(Ee&1073741823)+(Ae&1073741823);return pe&de?_e^2147483648^Ie^Oe:pe|de?_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,de,_e){return Ee=h(Ee,h(h(_(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function A(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(g(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function C(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(T(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function I(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(E(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function H(Ee){let Ae;const Ie=Ee.length,Oe=Ie+8,de=((Oe-Oe%64)/64+1)*16,_e=new Array(de-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[de-2]=Ie<<3,_e[de-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 Z=7,U=12,P=17,se=22,it=5,ee=9,Y=14,G=20,re=4,ge=11,be=16,ke=23,Re=6,le=10,ye=15,lt=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],Z,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],Z,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],Z,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],Z,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],it,4129170786),F=A(F,B,V,J,N[j+6],ee,3225465664),J=A(J,F,B,V,N[j+11],Y,643717713),V=A(V,J,F,B,N[j+0],G,3921069994),B=A(B,V,J,F,N[j+5],it,3593408605),F=A(F,B,V,J,N[j+10],ee,38016083),J=A(J,F,B,V,N[j+15],Y,3634488961),V=A(V,J,F,B,N[j+4],G,3889429448),B=A(B,V,J,F,N[j+9],it,568446438),F=A(F,B,V,J,N[j+14],ee,3275163606),J=A(J,F,B,V,N[j+3],Y,4107603335),V=A(V,J,F,B,N[j+8],G,1163531501),B=A(B,V,J,F,N[j+13],it,2850285829),F=A(F,B,V,J,N[j+2],ee,4243563512),J=A(J,F,B,V,N[j+7],Y,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],ke,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],ke,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],ke,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],ke,3299628645),B=I(B,V,J,F,N[j+0],Re,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],lt,4237533241),B=I(B,V,J,F,N[j+12],Re,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],lt,2240044497),B=I(B,V,J,F,N[j+8],Re,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],lt,1309151649),B=I(B,V,J,F,N[j+4],Re,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],lt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},Ze.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()}},Ze.cloneArray=r=>r&&r.slice()||[],Ze.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,Ze}const wf=Nt,Rm=at,gt=De,rt=mt(),Of=Vo(),Im=Yt(),Wo=new Rm("SIPMessage");class ia{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=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",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",gt.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 Of(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.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 Of(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+rt.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[rt.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[rt.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[rt.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[rt.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=wf.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 gt.REGISTER:n.push("path","gruu");break;case gt.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 gt.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const a=this.ua.configuration.user_agent||gt.USER_AGENT;if(t+=`Allow: ${gt.ALLOWED_METHODS}\r
|
79
|
+
`,t+=`Supported: ${n}\r
|
80
|
+
`,t+=`User-Agent: ${a}\r
|
81
|
+
`,this.body){const o=rt.str_utf8_length(this.body);t+=`Content-Length: ${o}\r
|
82
82
|
\r
|
83
|
-
`,
|
83
|
+
`,t+=this.body}else t+=`Content-Length: 0\r
|
84
84
|
\r
|
85
|
-
`;return
|
86
|
-
`;if(this.method===
|
87
|
-
`}const
|
88
|
-
`;!this.to_tag&&
|
89
|
-
`,
|
90
|
-
`,
|
91
|
-
`,
|
92
|
-
`;for(const
|
93
|
-
`;switch(this.method){case
|
94
|
-
`,
|
95
|
-
`):
|
96
|
-
`:
|
97
|
-
`),
|
98
|
-
`,
|
99
|
-
`,
|
85
|
+
`;return t}clone(){const t=new ia(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=rt.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}class Ko extends ia{constructor(t,n,a,o,s){super(gt.INVITE,t,n,a,o,s),this.transaction=null}cancel(t){this.transaction.cancel(t)}clone(){const t=new Ko(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=rt.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 Df{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=rt.headerize(t),this.headers[t]?this.headers[t].push(a):this.headers[t]=[a]}getHeader(t){const n=this.headers[rt.headerize(t)];if(n){if(n[0])return n[0].raw}else return}getHeaders(t){const n=this.headers[rt.headerize(t)],a=[];if(!n)return[];for(const o of n)a.push(o.raw);return a}hasHeader(t){return!!this.headers[rt.headerize(t)]}parseHeader(t,n=0){if(t=rt.headerize(t),this.headers[t]){if(n>=this.headers[t].length){Wo.debug(`not so many "${t}" headers present`);return}}else{Wo.debug(`header "${t}" not present`);return}const a=this.headers[t][n],o=a.raw;if(a.parsed)return a.parsed;const s=Im.parse(o,t.replace(/-/g,"_"));if(s===-1){this.headers[t].splice(n,1),Wo.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[rt.headerize(t)]=[a]}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=wf.parse(this.body||""),this.sdp)}toString(){return this.data}}class bm extends Df{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||gt.REASON_PHRASE[t]||"",a=rt.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===gt.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=${rt.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 gt.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 gt.UPDATE:this.ua.configuration.session_timers&&d.push("timer"),o&&d.push("ice"),d.push("replaces")}if(d.push("outbound"),this.method===gt.OPTIONS?(_+=`Allow: ${gt.ALLOWED_METHODS}\r
|
94
|
+
`,_+=`Accept: ${gt.ACCEPTED_BODY_TYPES}\r
|
95
|
+
`):t===405?_+=`Allow: ${gt.ALLOWED_METHODS}\r
|
96
|
+
`:t===415&&(_+=`Accept: ${gt.ACCEPTED_BODY_TYPES}\r
|
97
|
+
`),_+=`Supported: ${d}\r
|
98
|
+
`,o){const T=rt.str_utf8_length(o);_+=`Content-Type: application/sdp\r
|
99
|
+
`,_+=`Content-Length: ${T}\r
|
100
100
|
\r
|
101
|
-
`,
|
101
|
+
`,_+=o}else _+=`Content-Length: 0\r
|
102
102
|
\r
|
103
|
-
`;this.server_transaction.receiveResponse(
|
104
|
-
`;for(const
|
105
|
-
`;let s=this.getHeader("To");if(!this.to_tag&&
|
106
|
-
`,
|
107
|
-
`,
|
108
|
-
`,
|
109
|
-
`,this.ua.configuration.extra_headers)for(const
|
110
|
-
`;
|
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||gt.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=${rt.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 Z1 extends $_{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var Mt={OutgoingRequest:wo,InitialOutgoingInviteRequest:vh,IncomingRequest:Q1,IncomingResponse:Z1};const ki=We(Mt),eT=Et,Gs=xt(),gs=new eT("DigestAuthentication");var H_=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:gs.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 gs.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return gs.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return gs.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return gs.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return gs.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 gs.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||Gs.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=Gs.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=Gs.calculateMD5(f),gs.debug('authenticate() | using qop=auth [a2:"%s"]',f),this._response=Gs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(f=`${this._method}:${this._uri}:${Gs.calculateMD5(r||"")}`,h=Gs.calculateMD5(f),gs.debug('authenticate() | using qop=auth-int [a2:"%s"]',f),this._response=Gs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(f=`${this._method}:${this._uri}`,h=Gs.calculateMD5(f),gs.debug('authenticate() | using qop=null [a2:"%s"]',f),this._response=Gs.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),gs.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 tT=We(H_),Vs=500,sT=4e3,G_=5e3;var Th={T1:Vs,T2:sT,T4:G_,TIMER_B:64*Vs,TIMER_D:0*Vs,TIMER_F:64*Vs,TIMER_H:64*Vs,TIMER_I:0*Vs,TIMER_J:0*Vs,TIMER_K:0*G_,TIMER_L:64*Vs,TIMER_M:64*Vs,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Zr=We(Th),el=wt.EventEmitter,tl=Et,sl=Ue,V_=Mt,ws=Th,B_=new tl("NonInviteClientTransaction"),Io=new tl("InviteClientTransaction"),nT=new tl("AckClientTransaction"),j_=new tl("NonInviteServerTransaction"),Oo=new tl("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"};class iT extends el{constructor(e,t,r,l){super(),this.type=ye.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 ye}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(ye.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},ws.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){B_.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){B_.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(e){const t=e.status_code;if(t<200)switch(this.state){case ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break}else switch(this.state){case ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),clearTimeout(this.F),t===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(()=>{this.timer_K()},ws.TIMER_K);break;case ye.STATUS_COMPLETED:break}}}class rT extends el{constructor(e,t,r,l){super(),this.type=ye.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 ye}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(ye.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},ws.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ye.STATUS_ACCEPTED&&(Io.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){Io.debug(`Timer M expired for transaction ${this.id}`),this.state===ye.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){Io.debug(`Timer B expired for transaction ${this.id}`),this.state===ye.STATUS_CALLING&&(this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){Io.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(e){const t=new V_.OutgoingRequest(sl.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()},ws.TIMER_D),this.transport.send(t)}cancel(e){if(this.state!==ye.STATUS_PROCEEDING)return;const t=new V_.OutgoingRequest(sl.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 ye.STATUS_CALLING:this.stateChanged(ye.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case ye.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e);break}else if(t>=200&&t<=299)switch(this.state){case ye.STATUS_CALLING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},ws.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case ye.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e);break}else if(t>=300&&t<=699)switch(this.state){case ye.STATUS_CALLING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case ye.STATUS_COMPLETED:this.sendACK(e);break}}}class lT extends el{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 ye}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){nT.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class aT extends el{constructor(e,t,r){super(),this.type=ye.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=ye.STATUS_TRYING,e.newTransaction(this)}get C(){return ye}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_J(){j_.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,j_.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(e,t,r,l){if(e===100)switch(this.state){case ye.STATUS_TRYING:this.stateChanged(ye.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case ye.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 ye.STATUS_TRYING:case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(()=>{this.timer_J()},ws.TIMER_J),this.transport.send(t)?r&&r():(this.onTransportError(),l&&l());break;case ye.STATUS_COMPLETED:break}}}class oT extends el{constructor(e,t,r){super(),this.type=ye.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=ye.STATUS_PROCEEDING,e.newTransaction(this),this.resendProvisionalTimer=null,r.reply(100)}get C(){return ye}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_H(){Oo.debug(`Timer H expired for transaction ${this.id}`),this.state===ye.STATUS_COMPLETED&&Oo.debug("ACK not received, dialog will be terminated"),this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){Oo.debug(`Timer L expired for transaction ${this.id}`),this.state===ye.STATUS_ACCEPTED&&(this.stateChanged(ye.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,Oo.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(ye.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 ye.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t;break}if(e>100&&e<=199&&this.state===ye.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},ws.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case ye.STATUS_PROCEEDING:this.stateChanged(ye.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(()=>{this.timer_L()},ws.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ye.STATUS_ACCEPTED:this.transport.send(t)?r&&r():(this.onTransportError(),l&&l());break}else if(e>=300&&e<=699)switch(this.state){case ye.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(ye.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},ws.TIMER_H),r&&r()):(this.onTransportError(),l&&l());break}}}function uT({_transactions:u},e){let t;switch(e.method){case sl.INVITE:if(t=u.ist[e.via_branch],t){switch(t.state){case ye.STATUS_PROCEEDING:t.transport.send(t.last_response);break;case ye.STATUS_ACCEPTED:break}return!0}break;case sl.ACK:if(t=u.ist[e.via_branch],t){if(t.state===ye.STATUS_ACCEPTED)return!1;if(t.state===ye.STATUS_COMPLETED)return t.state=ye.STATUS_CONFIRMED,t.I=setTimeout(()=>{t.timer_I()},ws.TIMER_I),!0}else return!1;break;case sl.CANCEL:return t=u.ist[e.via_branch],t?(e.reply_sl(200),t.state!==ye.STATUS_PROCEEDING):(e.reply_sl(481),!0);default:if(t=u.nist[e.via_branch],t){switch(t.state){case ye.STATUS_TRYING:break;case ye.STATUS_PROCEEDING:case ye.STATUS_COMPLETED:t.transport.send(t.last_response);break}return!0}break}}var Mi={C:ye,NonInviteClientTransaction:iT,InviteClientTransaction:rT,AckClientTransaction:lT,NonInviteServerTransaction:aT,InviteServerTransaction:oT,checkTransaction:uT};const is=We(Mi),cT=Et,q_=Ue,hT=H_,yh=Mi,fT=new cT("RequestSender"),Sh={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Ui=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 Sh)Object.prototype.hasOwnProperty.call(Sh,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=Sh[l]));e.status===e.C.STATUS_USER_CLOSED&&(this._method!==q_.BYE||this._method!==q_.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 yh.InviteClientTransaction(this._ua,this._ua.transport,this._request,e);break;case"ACK":this.clientTransaction=new yh.AckClientTransaction(this._ua,this._ua.transport,this._request,e);break;default:this.clientTransaction=new yh.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){fT.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 hT({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 nl=We(Ui),dT=Et,Eh=xt(),Bn=Ue,W_=Mt,K_=Ui,il=new dT("Registrator"),Do=10;var _T=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=Eh.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){il.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 W_.OutgoingRequest(Bn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},e),r=new K_(this._ua,t,{onRequestTimeout:()=>{this._registrationFailure(null,Bn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Bn.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")){il.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){il.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<Do&&(f=Do);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<Do&&(this._expires=Do),this.register()):(il.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(l,Bn.causes.SIP_FAILURE_CODE));break}default:{const s=Eh.sipErrorCause(l.status_code);this._registrationFailure(l,s)}}}});this._registering=!0,r.send()}unregister(e={}){if(!this._registered){il.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 W_.OutgoingRequest(Bn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t);new K_(this._ua,r,{onRequestTimeout:()=>{this._unregistered(null,Bn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Bn.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=Eh.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 gT 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 pT extends Error{constructor(e){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=e,this.message=`Invalid status: ${e}`}}class mT extends Error{constructor(e){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=e}}class vT extends Error{constructor(e){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=e}}var Bs={ConfigurationError:gT,InvalidStateError:pT,NotSupportedError:mT,NotReadyError:vT};const cn=We(Bs),Ch=Ue,No=Mi,TT=Ui,Ah={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var Y_=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 Ah)Object.prototype.hasOwnProperty.call(Ah,l)&&(this._eventHandlers[l]||(this._eventHandlers[l]=Ah[l]))}get request(){return this._request}send(){const e=new TT(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===Ch.INVITE||this._request.method===Ch.UPDATE&&this._request.body)&&e.clientTransaction.state!==No.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const t=()=>{(e.clientTransaction.state===No.C.STATUS_ACCEPTED||e.clientTransaction.state===No.C.STATUS_COMPLETED||e.clientTransaction.state===No.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===Ch.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 yT=We(Y_),ST=Et,z_=Mt,hn=Ue,rl=Mi,ET=Y_,bh=xt(),Rh=new ST("Dialog"),fn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var X_=class{static get C(){return fn}constructor(e,t,r,l=fn.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 z_.IncomingResponse&&(l=t.status_code<200?fn.STATUS_EARLY:fn.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),Rh.debug(`new ${r} dialog created with status ${this._state===fn.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===fn.STATUS_TERMINATED}update(e,t){this._state=fn.STATUS_CONFIRMED,Rh.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t==="UAC"&&(this._route_set=e.getHeaders("record-route").reverse())}terminate(){Rh.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=fn.STATUS_TERMINATED}sendRequest(e,t={}){const r=bh.cloneArray(t.extraHeaders),l=bh.cloneObject(t.eventHandlers),s=t.body||null,i=this._createRequest(e,r,s);return l.onAuthenticated=()=>{this._local_seqnum+=1},new ET(this,i,l).send(),i}receiveRequest(e){this._checkInDialogRequest(e)&&(e.method===hn.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:e.method===hn.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}_createRequest(e,t,r){t=bh.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const l=e===hn.CANCEL||e===hn.ACK?this._local_seqnum:this._local_seqnum+=1;return new z_.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===hn.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===hn.INVITE||e.method===hn.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===rl.C.STATUS_ACCEPTED||e.server_transaction.state===rl.C.STATUS_COMPLETED||e.server_transaction.state===rl.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===rl.C.STATUS_ACCEPTED&&(this._remote_target=e.parseHeader("contact").uri)})}else e.method===hn.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===rl.C.STATUS_COMPLETED&&(this._remote_target=e.parseHeader("contact").uri)});return!0}};const Po=We(X_);var wh={exports:{}};const CT=wt.EventEmitter,AT=Et,bT=Ue,RT=Bs,J_=xt(),wT=new AT("RTCSession:DTMF"),Q_={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};wh.exports=class extends CT{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 RT.InvalidStateError(this._session.status);const r=J_.cloneArray(t.extraHeaders);if(this.eventHandlers=J_.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
|
-
`;
|
114
|
-
`);
|
115
|
-
`,1)[0],"Status_Line");if(t===-1){jn.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){jn.debug("REFER succeeded"),jn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}_requestFailed(e,t){jn.debug("REFER failed"),jn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}};const $T=We(ig),HT=wt.EventEmitter,rg=Xt,GT=Et,Se=Ue,qn=Bs,lg=Mi,nt=xt(),al=Th,VT=Mt,xo=X_,BT=Ui,ts=Z_,ag=eg,jT=sg,qT=ig,og=Hs(),ne=new GT("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},ko=["audio","video"];var ug=class sd extends HT{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:Se.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return ae}get causes(){return Se.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=nt.cloneObject(t.eventHandlers),i=nt.cloneArray(t.extraHeaders),f=nt.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),h=t.mediaStream||null,d=nt.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 qn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new qn.NotSupportedError("WebRTC not supported");if(e=this._ua.normalizeTarget(e),!e)throw new TypeError(`Invalid target: ${l}`);this._sessionTimers.enabled&&nt.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=Se.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=Se.SESSION_EXPIRES);for(const S in s)Object.prototype.hasOwnProperty.call(s,S)&&this.on(S,s[S]);this._from_tag=nt.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 og("sip","anonymous","anonymous.invalid"),i.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),i.push("Privacy: id")):t.fromUserName&&(y.from_uri=new og("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 VT.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=nt.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,Se.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,Se.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=nt.cloneArray(e.extraHeaders),l=nt.cloneObject(e.mediaConstraints),s=e.mediaStream||null,i=nt.cloneObject(e.pcConfig,{iceServers:[]}),f=e.rtcConstraints||null,h=e.rtcAnswerConstraints||null,d=nt.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 qn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==ae.STATUS_WAITING_FOR_ANSWER)throw new qn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&nt.isDecimal(e.sessionTimersExpires)&&(e.sessionTimersExpires>=Se.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=e.sessionTimersExpires:this._sessionTimers.defaultExpires=Se.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,Se.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,Se.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,Se.causes.CONNECTION_ERROR)})}).catch(R=>{this._status!==ae.STATUS_TERMINATED&&ne.warn(R)})}terminate(e={}){ne.debug("terminate()");const t=e.cause||Se.causes.BYE,r=nt.cloneArray(e.extraHeaders),l=e.body;let s,i=e.status_code,f=e.reason_phrase;if(this._status===ae.STATUS_TERMINATED)throw new qn.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||Se.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,Se.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,Se.causes.REJECTED);break;case ae.STATUS_WAITING_FOR_ACK:case ae.STATUS_CONFIRMED:if(ne.debug("terminating session"),f=e.reason_phrase||Se.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!==lg.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:d})=>{d===Se.ACK&&(this.sendRequest(Se.BYE,{extraHeaders:r,body:l}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===lg.C.STATUS_TERMINATED&&(this.sendRequest(Se.BYE,{extraHeaders:r,body:l}),h.terminate())}),this._ended("local",null,t),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(Se.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||Se.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 qn.InvalidStateError(this._status);if(i!==Se.DTMF_TRANSPORT.INFO&&i!==Se.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&&!nt.isDecimal(l))throw new TypeError(`Invalid tone duration: ${l}`);if(l?l<ts.C.MIN_DURATION?(ne.debug(`"duration" value is lower than the minimum allowed, setting it to ${ts.C.MIN_DURATION} milliseconds`),l=ts.C.MIN_DURATION):l>ts.C.MAX_DURATION?(ne.debug(`"duration" value is greater than the maximum allowed, setting it to ${ts.C.MAX_DURATION} milliseconds`),l=ts.C.MAX_DURATION):l=Math.abs(l):l=ts.C.DEFAULT_DURATION,t.duration=l,s&&!nt.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<ts.C.MIN_INTER_TONE_GAP?(ne.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${ts.C.MIN_INTER_TONE_GAP} milliseconds`),s=ts.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=ts.C.DEFAULT_INTER_TONE_GAP,i===Se.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 ts(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 qn.InvalidStateError(this._status);new ag(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:Se.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:Se.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:Se.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 qT(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===Se.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,Se.causes.CANCELED));else switch(e.method){case Se.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:Se.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:Se.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 Se.BYE:this._status===ae.STATUS_CONFIRMED||this._status===ae.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,Se.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,Se.causes.BYE)):e.reply(403,"Wrong Status");break;case Se.INVITE:this._status===ae.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case Se.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 ts(this).init_incoming(e):t!==void 0?new ag(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case Se.UPDATE:this._status===ae.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case Se.REFER:this._status===ae.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case Se.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:Se.causes.CONNECTION_ERROR,cause:Se.causes.CONNECTION_ERROR})}onRequestTimeout(){ne.warn("onRequestTimeout()"),this._status!==ae.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:Se.causes.REQUEST_TIMEOUT,cause:Se.causes.REQUEST_TIMEOUT})}onDialogError(){ne.warn("onDialogError()"),this._status!==ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:Se.causes.DIALOG_ERROR,cause:Se.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"),nt.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=al.T1;function l(){this._status===ae.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),r<al.T2&&(r=r*2,r>al.T2&&(r=al.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(Se.BYE),this._ended("remote",null,Se.causes.NO_ACK))},al.TIMER_H)}_createRTCConnection(e,t){this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:Se.causes.RTP_TIMEOUT,status_code:408,reason_phrase:Se.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 xo(this,e,t,xo.C.STATUS_EARLY),f.error?(ne.debug(f.error),this._failed("remote",e,Se.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 xo(this,e,t);return h.error?(ne.debug(h.error),this._failed("remote",e,Se.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=nt.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=nt.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(ko.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!==Se.SIP){ne.debug("Refer-To header field points to a non-SIP URI scheme"),e.reply(416);return}e.reply(202);const t=new jT(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 sd(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=nt.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 sd(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 BT(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,Se.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,Se.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(Se.ACK);return}else{const t=new xo(this,e,"UAC");if(t.error!==void 0){ne.debug(t.error);return}this.sendRequest(Se.ACK),this.sendRequest(Se.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,Se.causes.MISSING_SDP),this._failed("remote",e,Se.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,Se.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(r).then(()=>{this._handleSessionTimersInIncomingResponse(e),this._accepted("remote",e),this.sendRequest(Se.ACK),this._confirmed("local",null)}).catch(l=>{this._acceptAndTerminate(e,488,"Not Acceptable Here"),this._failed("remote",e,Se.causes.BAD_MEDIA_DESCRIPTION),ne.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',l),this.emit("peerconnection:setremotedescriptionfailed",l)})});break}default:{const t=nt.sipErrorCause(e.status_code);this._failed("remote",e,t)}}}_sendReinvite(e={}){ne.debug("sendReinvite()");const t=nt.cloneArray(e.extraHeaders),r=nt.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(Se.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(Se.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=nt.cloneArray(e.extraHeaders),r=nt.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(Se.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(Se.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||Se.REASON_PHRASE[t]||"",l.push(`Reason: SIP ;cause=${t}; text="${r}"`)),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(Se.ACK),this.sendRequest(Se.BYE,{extraHeaders:l})),this._status=ae.STATUS_TERMINATED}_mangleOffer(e){if(!this._localHold&&!this._remoteHold)return e;if(e=rg.parse(e),this._localHold&&!this._remoteHold){ne.debug("mangleOffer() | me on hold, mangling offer");for(const t of e.media)ko.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)ko.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)ko.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="recvonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="recvonly")}return rg.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>=Se.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>=Se.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===Se.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:Se.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 WT=We(ug),KT=wt.EventEmitter,YT=Et,Dh=Ue,zT=Mt,ol=xt(),XT=Ui,cg=Bs,JT=Hs(),Mo=new YT("Message");var QT=class extends KT{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=ol.cloneArray(r.extraHeaders),i=ol.cloneObject(r.eventHandlers),f=r.contentType||"text/plain",h={};r.fromUserName&&(h.from_uri=new JT("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 zT.OutgoingRequest(Dh.MESSAGE,e,this._ua,h,s),t&&(this._request.body=t);const d=new XT(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=ol.cloneArray(e.extraHeaders),r=e.body;if(this._direction!=="incoming")throw new cg.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=ol.cloneArray(e.extraHeaders),s=e.body;if(this._direction!=="incoming")throw new cg.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=ol.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Dh.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Dh.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){Mo.debug("MESSAGE failed"),this._close(),Mo.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:r})}_succeeded(e,t){Mo.debug("MESSAGE succeeded"),this._close(),Mo.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}};const ZT=wt.EventEmitter,ey=Et,Nh=Ue,ty=Mt,ul=xt(),sy=Ui,hg=Bs,Uo=new ey("Options");var ny=class extends ZT{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=ul.cloneArray(r.extraHeaders),i=ul.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 ty.OutgoingRequest(Nh.OPTIONS,e,this._ua,null,s),t&&(this._request.body=t);const h=new sy(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=ul.cloneArray(e.extraHeaders),r=e.body;if(this._direction!=="incoming")throw new hg.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=ul.cloneArray(e.extraHeaders),s=e.body;if(this._direction!=="incoming")throw new hg.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=ul.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Nh.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Nh.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){Uo.debug("OPTIONS failed"),this._close(),Uo.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:r})}_succeeded(e,t){Uo.debug("OPTIONS succeeded"),this._close(),Uo.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},Ph={};const iy=Et,xh=xt(),ry=_s(),cl=new iy("Socket");Ph.isSocket=u=>{if(Array.isArray(u))return!1;if(typeof u>"u")return cl.warn("undefined JsSIP.Socket instance"),!1;try{if(!xh.isString(u.url))throw cl.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!xh.isString(u.via_transport))throw cl.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(ry.parse(u.sip_uri,"SIP_URI")===-1)throw cl.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(!xh.isFunction(u[e]))throw cl.warn(`missing or invalid JsSIP.Socket method: ${e}`),new Error(`Missing or invalid JsSIP.Socket method: ${e}`)})}catch{return!1}return!0};const ly=Et,ay=Ph,fg=Ue,Qt=new ly("Transport"),rs={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:fg.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:fg.CONNECTION_RECOVERY_MAX_INTERVAL}};var dg=class{constructor(e,t=rs.recovery_options){Qt.debug("new()"),this.status=rs.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){Qt.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:rs.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(Qt.debug("connect()"),this.isConnected()){Qt.debug("Transport is already connected");return}else if(this.isConnecting()){Qt.debug("Transport is connecting");return}this.close_requested=!1,this.status=rs.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(){Qt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=rs.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(Qt.debug("send()"),!this.isConnected())return Qt.warn("unable to send message, transport is not connected"),!1;const t=e.toString();return Qt.debug(`sending message:
|
112
|
+
`,this.transport.send(o)}}class wm extends Df{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var Tt={OutgoingRequest:ia,InitialOutgoingInviteRequest:Ko,IncomingRequest:bm,IncomingResponse:wm};const $n=Me(Tt),Om=at,ms=mt(),Jt=new Om("DigestAuthentication");var Nf=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||ms.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=ms.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=ms.calculateMD5(d),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=ms.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${ms.calculateMD5(a||"")}`,h=ms.calculateMD5(d),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=ms.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,h=ms.calculateMD5(d),Jt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=ms.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 Dm=Me(Nf),gs=500,Nm=4e3,Uf=5e3;var Yo={T1:gs,T2:Nm,T4:Uf,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*Uf,TIMER_L:64*gs,TIMER_M:64*gs,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Vr=Me(Yo),Br=ct.EventEmitter,Gr=at,Wr=De,Pf=Tt,rs=Yo,xf=new Gr("NonInviteClientTransaction"),la=new Gr("InviteClientTransaction"),Um=new Gr("AckClientTransaction"),kf=new Gr("NonInviteServerTransaction"),aa=new Gr("InviteServerTransaction"),fe={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 Pm extends Br{constructor(t,n,a,o){super(),this.type=fe.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 fe}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(fe.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},rs.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){xf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){xf.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},rs.TIMER_K);break;case fe.STATUS_COMPLETED:break}}}class xm extends Br{constructor(t,n,a,o){super(),this.type=fe.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 fe}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(fe.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},rs.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==fe.STATUS_ACCEPTED&&(la.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){la.debug(`Timer M expired for transaction ${this.id}`),this.state===fe.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){la.debug(`Timer B expired for transaction ${this.id}`),this.state===fe.STATUS_CALLING&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){la.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new Pf.OutgoingRequest(Wr.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()},rs.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==fe.STATUS_PROCEEDING)return;const n=new Pf.OutgoingRequest(Wr.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 fe.STATUS_CALLING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},rs.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_COMPLETED:this.sendACK(t);break}}}class km extends Br{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 fe}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Um.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Mm extends Br{constructor(t,n,a){super(),this.type=fe.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=fe.STATUS_TRYING,t.newTransaction(this)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){kf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,kf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,a,o){if(t===100)switch(this.state){case fe.STATUS_TRYING:this.stateChanged(fe.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case fe.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 fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},rs.TIMER_J),this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break;case fe.STATUS_COMPLETED:break}}}class Lm extends Br{constructor(t,n,a){super(),this.type=fe.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=fe.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,a.reply(100)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){aa.debug(`Timer H expired for transaction ${this.id}`),this.state===fe.STATUS_COMPLETED&&aa.debug("ACK not received, dialog will be terminated"),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){aa.debug(`Timer L expired for transaction ${this.id}`),this.state===fe.STATUS_ACCEPTED&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,aa.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(fe.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 fe.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===fe.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},rs.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},rs.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case fe.STATUS_ACCEPTED:this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=300&&t<=699)switch(this.state){case fe.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(fe.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},rs.TIMER_H),a&&a()):(this.onTransportError(),o&&o());break}}}function $m({_transactions:c},t){let n;switch(t.method){case Wr.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case fe.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case fe.STATUS_ACCEPTED:break}return!0}break;case Wr.ACK:if(n=c.ist[t.via_branch],n){if(n.state===fe.STATUS_ACCEPTED)return!1;if(n.state===fe.STATUS_COMPLETED)return n.state=fe.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},rs.TIMER_I),!0}else return!1;break;case Wr.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==fe.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case fe.STATUS_TRYING:break;case fe.STATUS_PROCEEDING:case fe.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var Hn={C:fe,NonInviteClientTransaction:Pm,InviteClientTransaction:xm,AckClientTransaction:km,NonInviteServerTransaction:Mm,InviteServerTransaction:Lm,checkTransaction:$m};const Ht=Me(Hn),Hm=at,Mf=De,Fm=Nf,Jo=Hn,jm=new Hm("RequestSender"),zo={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Fn=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 zo)Object.prototype.hasOwnProperty.call(zo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=zo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==Mf.BYE||this._method!==Mf.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 Jo.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new Jo.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new Jo.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){jm.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 Fm({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 Kr=Me(Fn),qm=at,Xo=mt(),tn=De,Lf=Tt,$f=Fn,Yr=new qm("Registrator"),oa=10;var Vm=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=Xo.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){Yr.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 Lf.OutgoingRequest(tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new $f(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")){Yr.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){Yr.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<oa&&(d=oa);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<oa&&(this._expires=oa),this.register()):(Yr.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,tn.causes.SIP_FAILURE_CODE));break}default:{const s=Xo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Yr.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 Lf.OutgoingRequest(tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new $f(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=Xo.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 Bm 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 Gm extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class Wm extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class Km extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var Ts={ConfigurationError:Bm,InvalidStateError:Gm,NotSupportedError:Wm,NotReadyError:Km};const Ns=Me(Ts),Qo=De,ua=Hn,Ym=Fn,Zo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var Hf=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 Zo)Object.prototype.hasOwnProperty.call(Zo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Zo[o]))}get request(){return this._request}send(){const t=new Ym(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(t.send(),(this._request.method===Qo.INVITE||this._request.method===Qo.UPDATE&&this._request.body)&&t.clientTransaction.state!==ua.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===ua.C.STATUS_ACCEPTED||t.clientTransaction.state===ua.C.STATUS_COMPLETED||t.clientTransaction.state===ua.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};t.clientTransaction.on("stateChanged",n)}}_receiveResponse(t){t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===Qo.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}};const Jm=Me(Hf),zm=at,Ff=Tt,Us=De,Jr=Hn,Xm=Hf,eu=mt(),tu=new zm("Dialog"),Ps={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var jf=class{static get C(){return Ps}constructor(t,n,a,o=Ps.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 Ff.IncomingResponse&&(o=n.status_code<200?Ps.STATUS_EARLY:Ps.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),tu.debug(`new ${a} dialog created with status ${this._state===Ps.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===Ps.STATUS_TERMINATED}update(t,n){this._state=Ps.STATUS_CONFIRMED,tu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){tu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Ps.STATUS_TERMINATED}sendRequest(t,n={}){const a=eu.cloneArray(n.extraHeaders),o=eu.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new Xm(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===Us.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===Us.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=eu.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===Us.CANCEL||t===Us.ACK?this._local_seqnum:this._local_seqnum+=1;return new Ff.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===Us.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===Us.INVITE||t.method===Us.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===Jr.C.STATUS_ACCEPTED||t.server_transaction.state===Jr.C.STATUS_COMPLETED||t.server_transaction.state===Jr.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===Jr.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===Us.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Jr.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const ca=Me(jf);var su={exports:{}};const Qm=ct.EventEmitter,Zm=at,eg=De,tg=Ts,qf=mt(),sg=new Zm("RTCSession:DTMF"),Vf={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};su.exports=class extends Qm{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=qf.cloneArray(n.extraHeaders);if(this.eventHandlers=qf.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(eg.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=Vf.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):sg.debug("invalid INFO DTMF received, discarded")}},su.exports.C=Vf;var Bf=su.exports;const ng=Me(Bf),rg=ct.EventEmitter,ig=De,lg=Ts,ag=mt();var Gf=class extends rg{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 lg.InvalidStateError(this._session.status);this._contentType=t,this._body=n;const o=ag.cloneArray(a.extraHeaders);o.push(`Content-Type: ${t}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(ig.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 nu=Me(Gf),og=at,Wf=De,ug=new og("RTCSession:ReferNotifier"),ru={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var Kf=class{constructor(t,n,a){this._session=t,this._id=n,this._expires=a||ru.expires,this._active=!0,this.notify(100)}notify(t,n){if(ug.debug("notify()"),this._active===!1)return;n=n||Wf.REASON_PHRASE[t]||"";let a;t>=200?a="terminated;reason=noresource":a=`active;expires=${this._expires}`,this._session.sendRequest(Wf.NOTIFY,{extraHeaders:[`Event: ${ru.event_type};id=${this._id}`,`Subscription-State: ${a}`,`Content-Type: ${ru.body_type}`],body:`SIP/2.0 ${t} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const cg=Me(Kf),fg=ct.EventEmitter,hg=at,zr=De,dg=Yt(),Yf=mt(),sn=new hg("RTCSession:ReferSubscriber");var Jf=class extends fg{constructor(t){super(),this._id=null,this._session=t}get id(){return this._id}sendRefer(t,n={}){sn.debug("sendRefer()");const a=Yf.cloneArray(n.extraHeaders),o=Yf.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(zr.REFER,{extraHeaders:a,eventHandlers:{onSuccessResponse:h=>{this._requestSucceeded(h)},onErrorResponse:h=>{this._requestFailed(h,zr.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,zr.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,zr.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,zr.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(t){if(sn.debug("receiveNotify()"),!t.body)return;const n=dg.parse(t.body.trim().split(`\r
|
115
|
+
`,1)[0],"Status_Line");if(n===-1){sn.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){sn.debug("REFER succeeded"),sn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){sn.debug("REFER failed"),sn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const _g=Me(Jf),pg=ct.EventEmitter,zf=Nt,mg=at,he=De,nn=Ts,Xf=Hn,Ge=mt(),Xr=Yo,gg=Tt,fa=jf,Tg=Fn,Mt=Bf,Qf=Gf,vg=Kf,Eg=Jf,Zf=ps(),K=new mg("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},ha=["audio","video"];var eh=class Wu extends pg{static get C(){return Q}constructor(t){K.debug("new"),super(),this._id=null,this._ua=t,this._status=Q.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:he.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Q}get causes(){return he.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 Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:case Q.STATUS_INVITE_RECEIVED:case Q.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Q.STATUS_CANCELED:case Q.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(t,n={},a){K.debug("connect()");const o=t,s=Ge.cloneObject(n.eventHandlers),r=Ge.cloneArray(n.extraHeaders),d=Ge.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Ge.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new nn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new nn.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Ge.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES);for(const A in s)Object.prototype.hasOwnProperty.call(s,A)&&this.on(A,s[A]);this._from_tag=Ge.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 Zf("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Zf("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 gg.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){K.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=Q.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=Ge.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,he.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,he.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!==Q.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){K.debug("answer()");const n=this._request,a=Ge.cloneArray(t.extraHeaders),o=Ge.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Ge.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Ge.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 nn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new nn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ge.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES),this._status=Q.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===Q.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===Q.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};K.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,he.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,he.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==Q.STATUS_TERMINATED&&K.warn(I)})}terminate(t={}){K.debug("terminate()");const n=t.cause||he.causes.BYE,a=Ge.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new nn.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"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||he.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Q.STATUS_CANCELED,this._failed("local",null,he.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.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,he.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),d=t.reason_phrase||he.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===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Xf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===he.ACK&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Xf.C.STATUS_TERMINATED&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(he.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendDTMF(t,n={}){K.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||he.DTMF_TRANSPORT.INFO;if(t===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 nn.InvalidStateError(this._status);if(r!==he.DTMF_TRANSPORT.INFO&&r!==he.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&&!Ge.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<Mt.C.MIN_DURATION?(K.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?(K.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&&!Ge.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<Mt.C.MIN_INTER_TONE_GAP?(K.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===he.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===Q.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(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new nn.InvalidStateError(this._status);new Qf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){K.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}){K.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(K.debug("hold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.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(K.debug("unhold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.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){K.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.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){K.debug("refer()");const a=t;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Eg(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 K.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(K.debug("receiveRequest()"),t.method===he.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",t,he.causes.CANCELED));else switch(t.method){case he.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(!t.body){this.terminate({cause:he.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};K.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:he.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case he.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,he.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,he.causes.BYE)):t.reply(403,"Wrong Status");break;case he.INVITE:this._status===Q.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case he.INFO:if(this._status===Q.STATUS_1XX_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED||this._status===Q.STATUS_WAITING_FOR_ACK||this._status===Q.STATUS_CONFIRMED){const n=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 Qf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case he.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case he.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case he.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.CONNECTION_ERROR,cause:he.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:he.causes.REQUEST_TIMEOUT,cause:he.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.DIALOG_ERROR,cause:he.causes.DIALOG_ERROR})}newDTMF(t){K.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){K.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Ge.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){K.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=Xr.T1;function o(){this._status===Q.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Xr.T2&&(a=a*2,a>Xr.T2&&(a=Xr.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(he.BYE),this._ended("remote",null,he.causes.NO_ACK))},Xr.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:he.causes.RTP_TIMEOUT,status_code:408,reason_phrase:he.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(K.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=>(K.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(K.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,K.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 K.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};K.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 fa(this,t,n,fa.C.STATUS_EARLY),d.error?(K.debug(d.error),this._failed("remote",t,he.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 fa(this,t,n);return h.error?(K.debug(h.error),this._failed("remote",t,he.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){K.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=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.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"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.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=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){K.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=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.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"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.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){K.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ha.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};K.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===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Q.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===Q.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{K.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(K.debug("receiveRefer()"),!t.refer_to){K.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==he.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new vg(this,t.cseq);K.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!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const d=new Wu(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=Ge.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(K.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){K.debug("receiveReplaces()");function n(o){if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const s=new Wu(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){K.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 Tg(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===Q.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Q.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,he.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Q.STATUS_TERMINATED&&K.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(K.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(he.ACK);return}else{const n=new fa(this,t,"UAC");if(n.error!==void 0){K.debug(n.error);return}this.sendRequest(he.ACK),this.sendRequest(he.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!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){K.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};K.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=>{K.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=Q.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,he.causes.MISSING_SDP),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};K.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,he.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(he.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Ge.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){K.debug("sendReinvite()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.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};K.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(he.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===Q.STATUS_TERMINATED||(this.sendRequest(he.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};K.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),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){K.debug("sendUpdate()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.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:_};K.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(he.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(he.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!==Q.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};K.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),K.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){K.debug("acceptAndTerminate()");const o=[];n&&(a=a||he.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(he.ACK),this.sendRequest(he.BYE,{extraHeaders:o})),this._status=Q.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=zf.parse(t),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return zf.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>=he.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>=he.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!==Q.STATUS_TERMINATED&&this._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===he.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:he.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){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const Sg=Me(eh),yg=ct.EventEmitter,Ag=at,iu=De,Cg=Tt,Qr=mt(),Rg=Fn,th=Ts,Ig=ps(),da=new Ag("Message");var bg=class extends yg{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=Qr.cloneArray(a.extraHeaders),r=Qr.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Ig("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 Cg.OutgoingRequest(iu.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new Rg(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=Qr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new th.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=Qr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new th.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=Qr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,iu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,iu.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){da.debug("MESSAGE failed"),this._close(),da.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){da.debug("MESSAGE succeeded"),this._close(),da.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const wg=ct.EventEmitter,Og=at,lu=De,Dg=Tt,Zr=mt(),Ng=Fn,sh=Ts,_a=new Og("Options");var Ug=class extends wg{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=Zr.cloneArray(a.extraHeaders),r=Zr.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 Dg.OutgoingRequest(lu.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Ng(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=Zr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new sh.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=Zr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new sh.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=Zr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,lu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,lu.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){_a.debug("OPTIONS failed"),this._close(),_a.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){_a.debug("OPTIONS succeeded"),this._close(),_a.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},au={};const Pg=at,ou=mt(),xg=Yt(),ei=new Pg("Socket");au.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return ei.warn("undefined JsSIP.Socket instance"),!1;try{if(!ou.isString(c.url))throw ei.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!ou.isString(c.via_transport))throw ei.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 ei.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(!ou.isFunction(c[t]))throw ei.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const kg=at,Mg=au,nh=De,Pt=new kg("Transport"),Ft={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nh.CONNECTION_RECOVERY_MAX_INTERVAL}};var rh=class{constructor(t,n=Ft.recovery_options){Pt.debug("new()"),this.status=Ft.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){Pt.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(!Mg.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:Ft.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(Pt.debug("connect()"),this.isConnected()){Pt.debug("Transport is already connected");return}else if(this.isConnecting()){Pt.debug("Transport is connecting");return}this.close_requested=!1,this.status=Ft.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){Pt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Ft.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(Pt.debug("send()"),!this.isConnected())return Pt.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return Pt.debug(`sending message:
|
116
116
|
|
117
|
-
${
|
118
|
-
`),this.socket.send(
|
119
|
-
`){
|
117
|
+
${n}
|
118
|
+
`),this.socket.send(n)}isConnected(){return this.status===Ft.STATUS_CONNECTED}isConnecting(){return this.status===Ft.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),Pt.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!==Ft.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=Ft.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=Ft.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(t,n,a){this.status=Ft.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=Ft.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}_onData(t){if(t===`\r
|
119
|
+
`){Pt.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{Pt.debug("received binary message failed to be converted into string, message discarded");return}Pt.debug(`received binary message:
|
120
120
|
|
121
|
-
${
|
122
|
-
`)}else
|
121
|
+
${t}
|
122
|
+
`)}else Pt.debug(`received text message:
|
123
123
|
|
124
|
-
${
|
125
|
-
`);this.ondata({transport:this,message:
|
126
|
-
`);if(
|
127
|
-
`,
|
128
|
-
`;for(const
|
129
|
-
`;
|
130
|
-
`,
|
131
|
-
`,
|
132
|
-
`,
|
133
|
-
`,
|
134
|
-
`,mg.send(r)}const Cy=We(vg);var fl={};const Li=xt(),Wn=Ue,Fh=_s(),Tg=Hs(),$h=Ph,Hh=Bs;fl.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:Wn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:Wn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:Wn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${Li.createRandomToken(12)}.invalid`};const Fo={mandatory:{sockets(u){const e=[];if($h.isSocket(u))e.push({socket:u});else if(Array.isArray(u)&&u.length)for(const t of u)Object.prototype.hasOwnProperty.call(t,"socket")&&$h.isSocket(t.socket)?e.push(t):$h.isSocket(t)&&e.push({socket:t});else return;return e},uri(u){/^sip:/i.test(u)||(u=`${Wn.SIP}:${u}`);const e=Tg.parse(u);if(e)return e.user?e:void 0}},optional:{authorization_user(u){if(Fh.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(Li.isDecimal(u)){const e=Number(u);if(e>0)return e}},connection_recovery_min_interval(u){if(Li.isDecimal(u)){const e=Number(u);if(e>0)return e}},contact_uri(u){if(typeof u=="string"){const e=Fh.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)),Fh.parse(u,"uuid")!==-1)return u},no_answer_timeout(u){if(Li.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===Wn.INVITE||u===Wn.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(Li.isDecimal(u)){const e=Number(u);if(e>0)return e}},registrar_server(u){/^sip:/i.test(u)||(u=`${Wn.SIP}:${u}`);const e=Tg.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}}};fl.load=(u,e)=>{for(const t in Fo.mandatory)if(e.hasOwnProperty(t)){const r=e[t],l=Fo.mandatory[t](r);if(l!==void 0)u[t]=l;else throw new Hh.ConfigurationError(t,r)}else throw new Hh.ConfigurationError(t);for(const t in Fo.optional)if(e.hasOwnProperty(t)){const r=e[t];if(Li.isEmpty(r))continue;const l=Fo.optional[t](r);if(l!==void 0)u[t]=l;else throw new Hh.ConfigurationError(t,r)}};const Ay=wt.EventEmitter,by=Et,Ut=Ue,Ry=_T,yg=ug,Sg=QT,Eg=ny,Gh=Mi,wy=dg,$o=xt(),Iy=Bs,Oy=Hs(),Dy=_g,Vh=Mt,Ny=vg,Bh=fl,tt=new by("UA"),Lt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var Cg=class extends Ay{static get C(){return Lt}constructor(e){if(tt.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=Lt.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=Lt.STATUS_NOT_READY,this._error=Lt.CONFIGURATION_ERROR,t}this._registrator=new Ry(this)}get C(){return Lt}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){tt.debug("start()"),this._status===Lt.STATUS_INIT?this._transport.connect():this._status===Lt.STATUS_USER_CLOSED?(tt.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Lt.STATUS_INIT,this._transport.connect()):this._status===Lt.STATUS_READY?tt.debug("UA is in READY status, not restarted"):tt.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){tt.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(e){tt.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){tt.debug("call()");const r=new yg(this);return r.connect(e,t),r}sendMessage(e,t,r){tt.debug("sendMessage()");const l=new Sg(this);return l.send(e,t,r),l}sendOptions(e,t,r){tt.debug("sendOptions()");const l=new Eg(this);return l.send(e,t,r),l}terminateSessions(e){tt.debug("terminateSessions()");for(const t in this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}stop(){if(tt.debug("stop()"),this._dynConfiguration={},this._status===Lt.STATUS_USER_CLOSED){tt.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)){tt.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=Lt.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 $o.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:tt.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 tt.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){tt.debug("Request-URI does not point to us"),e.method!==Ut.ACK&&e.reply_sl(404);return}if(e.ruri.scheme===Ut.SIPS){e.reply_sl(416);return}if(Gh.checkTransaction(this,e))return;if(t===Ut.INVITE?new Gh.InviteServerTransaction(this,this._transport,e):t!==Ut.ACK&&t!==Ut.CANCEL&&new Gh.NonInviteServerTransaction(this,this._transport,e),t===Ut.OPTIONS){if(this.listeners("newOptions").length===0){e.reply(200);return}new Eg(this).init_incoming(e)}else if(t===Ut.MESSAGE){if(this.listeners("newMessage").length===0){e.reply(405);return}new Sg(this).init_incoming(e)}else if(t===Ut.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===Ut.NOTIFY?(l=this._findSession(e),l?l.receiveRequest(e):(tt.debug("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist"))):t!==Ut.ACK&&e.reply(481);else switch(t){case Ut.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 yg(this),l.init_incoming(e);else tt.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case Ut.BYE:e.reply(481);break;case Ut.CANCEL:l=this._findSession(e),l?l.receiveRequest(e):tt.debug("received CANCEL request for a non existent session");break;case Ut.ACK:break;case Ut.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=$o.newUUID()),this._configuration.jssip_id=$o.createRandomToken(5);const t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new wy(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Py.bind(this),this._transport.onconnect=xy.bind(this),this._transport.ondisconnect=ky.bind(this),this._transport.ondata=My.bind(this)}catch(l){throw tt.warn(l),new Iy.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 Oy("sip",$o.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}));tt.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":tt.debug(`- ${l}: ${this._configuration[l]}`);break;case"password":case"ha1":case"authorization_jwt":tt.debug(`- ${l}: NOT SHOWN`);break;default:tt.debug(`- ${l}: ${JSON.stringify(this._configuration[l])}`)}}};function Py(u){this.emit("connecting",u)}function xy(u){this._status!==Lt.STATUS_USER_CLOSED&&(this._status=Lt.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function ky(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!==Lt.STATUS_USER_CLOSED&&(this._status=Lt.STATUS_NOT_READY,this._error=Lt.NETWORK_ERROR)}function My(u){const e=u.transport;let t=u.message;if(t=Dy.parseMessage(t,this),!!t&&!(this._status===Lt.STATUS_USER_CLOSED&&t instanceof Vh.IncomingRequest)&&Ny(t,this,e)){if(t instanceof Vh.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof Vh.IncomingResponse){let r;switch(t.method){case Ut.INVITE:r=this._transactions.ict[t.via_branch],r&&r.receiveResponse(t);break;case Ut.ACK:break;default:r=this._transactions.nict[t.via_branch],r&&r.receiveResponse(t);break}}}}const Uy=We(Cg);for(var Ft=[],jh=0;jh<256;++jh)Ft.push((jh+256).toString(16).slice(1));function Ly(u,e=0){return(Ft[u[e+0]]+Ft[u[e+1]]+Ft[u[e+2]]+Ft[u[e+3]]+"-"+Ft[u[e+4]]+Ft[u[e+5]]+"-"+Ft[u[e+6]]+Ft[u[e+7]]+"-"+Ft[u[e+8]]+Ft[u[e+9]]+"-"+Ft[u[e+10]]+Ft[u[e+11]]+Ft[u[e+12]]+Ft[u[e+13]]+Ft[u[e+14]]+Ft[u[e+15]]).toLowerCase()}var Ho,Fy=new Uint8Array(16);function $y(){if(!Ho&&(Ho=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ho))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ho(Fy)}var Hy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ag={randomUUID:Hy};function bg(u,e,t){if(Ag.randomUUID&&!e&&!u)return Ag.randomUUID();u=u||{};var r=u.random||(u.rng||$y)();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 Ly(r)}var je=xt();const js=We(je),qh=new Ro("Dialog"),dn={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class Go{static get C(){return dn}constructor(e,t,r,l=dn.STATUS_CONFIRMED){if(this._owner=e,this._ua=e._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,t instanceof Mt.IncomingResponse&&(l=t.status_code<200?dn.STATUS_EARLY:dn.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),qh.debug(`new ${r} dialog created with status ${this._state===dn.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===dn.STATUS_TERMINATED}update(e,t){this._state=dn.STATUS_CONFIRMED,qh.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t==="UAC"&&(this._route_set=e.getHeaders("record-route").reverse())}terminate(){qh.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=dn.STATUS_TERMINATED}sendRequest(e,t={}){const r=js.cloneArray(t.extraHeaders),l=js.cloneObject(t.eventHandlers),s=t.body||null,i=this._createRequest(e,r,s);return l.onAuthenticated=()=>{this._local_seqnum+=1},new yT(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=js.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 Mt.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===is.C.STATUS_ACCEPTED||e.server_transaction.state===is.C.STATUS_COMPLETED||e.server_transaction.state===is.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===is.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===is.C.STATUS_COMPLETED&&(this._remote_target=e.parseHeader("contact").uri)});return!0}}class Gy{constructor(e,t){Cs(this,"plugin",null);Cs(this,"rtcpPeer",null);Cs(this,"handleId",0);Cs(this,"info",null);Cs(this,"joinResult",null);Cs(this,"state",{});Cs(this,"stream",null);Cs(this,"loaded",!1);Cs(this,"aTracks",[]);Cs(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 ps{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(e){return ps.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(r=>r.kind===e):[]}static async getMicrophoneList(){return(await ps.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 ps.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 ps.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 ps.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 Vy=Hs();const Kn=We(Vy),Zt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},re=new Ro("JanusSession"),By="/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},Vo=["audio","video"];class Bo extends wt.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-${bg().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 Kn("sip","anonymous","anonymous.invalid"),f.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),f.push("Privacy: id")):r.fromUserName&&(S.from_uri=new Kn("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 Mt.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!==is.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===is.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(Zt.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(Zt.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(){ps.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){ps.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(Zt.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(){ps.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){ps.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(Zt.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 Ih(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 $T(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 IT(this).init_incoming(e):t!==void 0?new Ih(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=Zr.T1;function l(){this._status===oe.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),r<Zr.T2&&(r=r*2,r>Zr.T2&&(r=Zr.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))},Zr.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 Go(this,e,t,Go.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 Go(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(Vo.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 MT(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 Bo(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 Bo(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 nl(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 By+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(Zt.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(Zt.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(Zt.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(Zt.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(Zt.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(Zt.SUBSCRIBER)];this.sendRequest(Z.INFO,{extraHeaders:r,body:JSON.stringify(t)}),ps.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 Gy(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 Go(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=bg();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(Zt.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=Xt.parse(e),this._localHold&&!this._remoteHold){re.debug("mangleOffer() | me on hold, mangling offer");for(const t of e.media)Vo.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)Vo.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)Vo.indexOf(t.type)!==-1&&(t.direction?t.direction==="sendrecv"?t.direction="recvonly":t.direction==="recvonly"&&(t.direction="inactive"):t.direction="recvonly")}return Xt.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 Fi{constructor(e){if(this.headers={},e.length>0){let t=!1;const r=e.split(`\r
|
136
|
-
`),
|
137
|
-
`;else{const
|
138
|
-
`;for(const
|
139
|
-
`;return this.body&&(
|
124
|
+
${t}
|
125
|
+
`);this.ondata({transport:this,message:t})}};const Lg=Me(rh);var ih={};const $g=at,uu=Yt(),cu=Tt,pa=new $g("Parser");ih.parseMessage=(c,t)=>{let n,a,o=c.indexOf(`\r
|
126
|
+
`);if(o===-1){pa.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=uu.parse(s,"Request_Response");if(r===-1){pa.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new cu.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new cu.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=Hg(c,d),o===-2){a=d+2;break}else if(o===-1){pa.warn("parseMessage() | malformed message");return}if(r=Fg(n,c,d,o),r!==!0){pa.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 Hg(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 Fg(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=uu.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=uu.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 cu.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 jg=at,lh=De,ah=Tt,fu=mt(),hu=new jg("sanityCheck"),qg=[Xg],Vg=[Gg,Wg,Kg,Yg],Bg=[Jg,zg];let je,is,oh;var uh=(c,t,n)=>{je=c,is=t,oh=n;for(const a of qg)if(a()===!1)return!1;if(je instanceof ah.IncomingRequest){for(const a of Vg)if(a()===!1)return!1}else if(je instanceof ah.IncomingResponse){for(const a of Bg)if(a()===!1)return!1}return!0};function Gg(){if(je.s("to").uri.scheme!=="sip")return ti(416),!1}function Wg(){if(!je.to_tag&&je.call_id.substr(0,5)===is.configuration.jssip_id)return ti(482),!1}function Kg(){const c=fu.str_utf8_length(je.body),t=je.getHeader("content-length");if(c<t)return ti(400),!1}function Yg(){const c=je.from_tag,t=je.call_id,n=je.cseq;let a;if(!je.to_tag)if(je.method===lh.INVITE){if(is._transactions.ist[je.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 ti(482),!1}else{if(is._transactions.nist[je.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 ti(482),!1}}function Jg(){if(je.getHeaders("via").length>1)return hu.debug("more than one Via header field present in the response, dropping the response"),!1}function zg(){const c=fu.str_utf8_length(je.body),t=je.getHeader("content-length");if(c<t)return hu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function Xg(){const c=["from","to","call_id","cseq","via"];for(const t of c)if(!je.hasHeader(t))return hu.debug(`missing mandatory header field : ${t}, dropping the response`),!1}function ti(c){const t=je.getHeaders("via");let n,a=`SIP/2.0 ${c} ${lh.REASON_PHRASE[c]}\r
|
128
|
+
`;for(const o of t)a+=`Via: ${o}\r
|
129
|
+
`;n=je.getHeader("To"),je.to_tag||(n+=`;tag=${fu.newTag()}`),a+=`To: ${n}\r
|
130
|
+
`,a+=`From: ${je.getHeader("From")}\r
|
131
|
+
`,a+=`Call-ID: ${je.call_id}\r
|
132
|
+
`,a+=`CSeq: ${je.cseq} ${je.method}\r
|
133
|
+
`,a+=`\r
|
134
|
+
`,oh.send(a)}const Qg=Me(uh);var si={};const jn=mt(),rn=De,du=Yt(),ch=ps(),_u=au,pu=Ts;si.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:rn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:rn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:rn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${jn.createRandomToken(12)}.invalid`};const ma={mandatory:{sockets(c){const t=[];if(_u.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&_u.isSocket(n.socket)?t.push(n):_u.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(du.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(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=du.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)),du.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(jn.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===rn.INVITE||c===rn.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(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.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}}};si.load=(c,t)=>{for(const n in ma.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=ma.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}else throw new pu.ConfigurationError(n);for(const n in ma.optional)if(t.hasOwnProperty(n)){const a=t[n];if(jn.isEmpty(a))continue;const o=ma.optional[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}};const Zg=ct.EventEmitter,eT=at,vt=De,tT=Vm,fh=eh,hh=bg,dh=Ug,mu=Hn,sT=rh,ga=mt(),nT=Ts,rT=ps(),iT=ih,gu=Tt,lT=uh,Tu=si,Ve=new eT("UA"),Et={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var _h=class extends Zg{static get C(){return Et}constructor(t){if(Ve.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},Tu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=Et.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=Et.STATUS_NOT_READY,this._error=Et.CONFIGURATION_ERROR,n}this._registrator=new tT(this)}get C(){return Et}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){Ve.debug("start()"),this._status===Et.STATUS_INIT?this._transport.connect():this._status===Et.STATUS_USER_CLOSED?(Ve.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Et.STATUS_INIT,this._transport.connect()):this._status===Et.STATUS_READY?Ve.debug("UA is in READY status, not restarted"):Ve.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){Ve.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(t){Ve.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){Ve.debug("call()");const a=new fh(this);return a.connect(t,n),a}sendMessage(t,n,a){Ve.debug("sendMessage()");const o=new hh(this);return o.send(t,n,a),o}sendOptions(t,n,a){Ve.debug("sendOptions()");const o=new dh(this);return o.send(t,n,a),o}terminateSessions(t){Ve.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(Ve.debug("stop()"),this._dynConfiguration={},this._status===Et.STATUS_USER_CLOSED){Ve.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)){Ve.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=Et.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 ga.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:Ve.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 Ve.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){Ve.debug("Request-URI does not point to us"),t.method!==vt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===vt.SIPS){t.reply_sl(416);return}if(mu.checkTransaction(this,t))return;if(n===vt.INVITE?new mu.InviteServerTransaction(this,this._transport,t):n!==vt.ACK&&n!==vt.CANCEL&&new mu.NonInviteServerTransaction(this,this._transport,t),n===vt.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new dh(this).init_incoming(t)}else if(n===vt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new hh(this).init_incoming(t)}else if(n===vt.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===vt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(Ve.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==vt.ACK&&t.reply(481);else switch(n){case vt.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 fh(this),o.init_incoming(t);else Ve.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case vt.BYE:t.reply(481);break;case vt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):Ve.debug("received CANCEL request for a non existent session");break;case vt.ACK:break;case vt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){try{Tu.load(this._configuration,t)}catch(o){throw o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ga.newUUID()),this._configuration.jssip_id=ga.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new sT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=aT.bind(this),this._transport.onconnect=oT.bind(this),this._transport.ondisconnect=uT.bind(this),this._transport.ondata=cT.bind(this)}catch(o){throw Ve.warn(o),new nT.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 rT("sip",ga.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}));Ve.debug("configuration parameters after validation:");for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(Tu.settings,o))switch(o){case"uri":case"registrar_server":Ve.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":Ve.debug(`- ${o}: NOT SHOWN`);break;default:Ve.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}}};function aT(c){this.emit("connecting",c)}function oT(c){this._status!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function uT(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!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_NOT_READY,this._error=Et.NETWORK_ERROR)}function cT(c){const t=c.transport;let n=c.message;if(n=iT.parseMessage(n,this),!!n&&!(this._status===Et.STATUS_USER_CLOSED&&n instanceof gu.IncomingRequest)&&lT(n,this,t)){if(n instanceof gu.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof gu.IncomingResponse){let a;switch(n.method){case vt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case vt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const fT=Me(_h);for(var St=[],vu=0;vu<256;++vu)St.push((vu+256).toString(16).slice(1));function hT(c,t=0){return(St[c[t+0]]+St[c[t+1]]+St[c[t+2]]+St[c[t+3]]+"-"+St[c[t+4]]+St[c[t+5]]+"-"+St[c[t+6]]+St[c[t+7]]+"-"+St[c[t+8]]+St[c[t+9]]+"-"+St[c[t+10]]+St[c[t+11]]+St[c[t+12]]+St[c[t+13]]+St[c[t+14]]+St[c[t+15]]).toLowerCase()}var Ta,dT=new Uint8Array(16);function _T(){if(!Ta&&(Ta=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ta))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ta(dT)}var pT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ph={randomUUID:pT};function mh(c,t,n){if(ph.randomUUID&&!t&&!c)return ph.randomUUID();c=c||{};var a=c.random||(c.rng||_T)();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 hT(a)}var xe=mt();const vs=Me(xe),Eu=new ra("Dialog"),xs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class va{static get C(){return xs}constructor(t,n,a,o=xs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof Tt.IncomingResponse&&(o=n.status_code<200?xs.STATUS_EARLY:xs.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),Eu.debug(`new ${a} dialog created with status ${this._state===xs.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===xs.STATUS_TERMINATED}update(t,n){this._state=xs.STATUS_CONFIRMED,Eu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Eu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=xs.STATUS_TERMINATED}sendRequest(t,n={}){const a=vs.cloneArray(n.extraHeaders),o=vs.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new Jm(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=vs.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 Tt.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===Ht.C.STATUS_ACCEPTED||t.server_transaction.state===Ht.C.STATUS_COMPLETED||t.server_transaction.state===Ht.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===Ht.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===Ht.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class mT{constructor(t,n){es(this,"plugin",null);es(this,"rtcpPeer",null);es(this,"handleId",0);es(this,"info",null);es(this,"joinResult",null);es(this,"state",{});es(this,"stream",null);es(this,"loaded",!1);es(this,"aTracks",[]);es(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 zt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return zt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await zt.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 zt.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 zt.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 zt.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 gT=ps();const ln=Me(gT),xt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new ra("JanusSession"),TT="/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},Ea=["audio","video"];class Sa extends ct.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-${mh().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=xe.cloneObject(a.eventHandlers),d=xe.cloneArray(a.extraHeaders),h=xe.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=xe.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 Ns.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Ns.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&&xe.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=xe.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 ln("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(A.from_uri=new ln("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 Tt.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=xe.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=xe.cloneArray(t.extraHeaders),o=xe.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=xe.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=xe.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 Ns.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new Ns.InvalidStateError(this._status);if(this._sessionTimers.enabled&&xe.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=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new Ns.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!==Ht.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===Ht.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(xt.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(xt.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(){zt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){zt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(xt.VIDEO_CHANGE)];this.sendRequest(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(){zt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){zt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(xt.STATE)];this.sendRequest(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 Ns.InvalidStateError(this._status);new nu(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 _g(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 ng(this).init_incoming(t):n!==void 0?new nu(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"),xe.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=Vr.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Vr.T2&&(a=a*2,a>Vr.T2&&(a=Vr.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))},Vr.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 va(this,t,n,va.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 va(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=xe.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=xe.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(Ea.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 cg(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 Sa(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=xe.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 Sa(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 Kr(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 TT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(xt.ICE)];this.sendRequest(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(xt.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(xt.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(xt.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(xt.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(xt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),zt.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 mT(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 va(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=mh();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(xt.PUBLISHER)];this.sendRequest(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=xe.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=xe.cloneArray(t.extraHeaders),a=xe.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=xe.cloneArray(t.extraHeaders),a=xe.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=Nt.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)Ea.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)Ea.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)Ea.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Nt.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 qn{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=xe.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
|
-
`),
|
142
|
-
`,
|
141
|
+
`),t+=`-------${this.ident}$\r
|
142
|
+
`,t}}const Ce={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class Su extends ct.EventEmitter{constructor(t){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=t,this.auth_id=xe.createRandomToken(10),this._status=Ce.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username: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 Ce}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 qn("");t.method="SEND",t.addHeader("To-Path",`${this.my_addr[1]}`),t.addHeader("From-Path",`${this.my_addr[0]}`),t.addHeader("Message-ID",xe.createRandomToken(10)),this._connection.send(t.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Ce.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(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: ${
|
149
|
-
`)}inviteParty(
|
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 ln("sip",this.target,this._ua._configuration.realm),n.from_uri=new ln("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 Tt.InitialOutgoingInviteRequest(new ln("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:${
|
156
|
-
`),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new nl(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!==is.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===is.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 Fi("");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 Fi(e.data);if(this.status==="auth"&&t.code===401){const r=this.parseAuth(t.getHeader("WWW-Authenticate")),l=new tT(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 Po(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 Fi("");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 Fi("");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 Fi("");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 Po(this,e,t,Po.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 Po(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 Ih(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 jy=_s();const Kh=We(jy),jo=new Ro("Parser"),qy=(u,e)=>{let t,r,l=u.indexOf(`\r
|
157
|
-
`);if(
|
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 Ky(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=Kh.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=Kh.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 ki.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 Yy={parseMessage:qy},dl=new Ro("Registrator"),qo=10;class zy{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=js.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){dl.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 Mt.OutgoingRequest(Z.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},e),r=new nl(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")){dl.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){dl.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<qo&&(f=qo);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<qo&&(this._expires=qo),this.register()):(dl.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(l,Z.causes.SIP_FAILURE_CODE));break}default:{const s=js.sipErrorCause(l.status_code);this._registrationFailure(l,s)}}}});this._registering=!0,r.send()}unregister(e={}){if(!this._registered){dl.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 Mt.OutgoingRequest(Z.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t);new nl(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=js.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 pt=console,_n={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Xy=Uy;class Jy extends Xy{constructor(e){super(e),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new zy(this)}call(e,t){return super.call(e,t)}joinVideoCall(e,t,r){pt.debug("call()");const l=new Bo(this);return l.configureMedia({audio:!0,video:!0}),l.connect(e,t,r),l}startScreenShare(){pt.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{fl.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=js.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=js.createRandomToken(5);const r=this._configuration.uri.clone();r.user=null,this._configuration.hostport_params=r.toString().replace(/^sip:/i,"");try{this._transport=new oy(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Qy.bind(this),this._transport.onconnect=Zy.bind(this),this._transport.ondisconnect=eS.bind(this),this._transport.ondata=tS.bind(this)}catch(s){throw pt.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 Kn("sip",js.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}));pt.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(fl.settings,s))switch(s){case"uri":case"registrar_server":pt.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":pt.debug(`- ${s}: NOT SHOWN`);break;default:pt.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){pt.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(is.checkTransaction(this,e))return;if(t===Ue.INVITE?new is.InviteServerTransaction(this,this._transport,e):t!==Ue.ACK&&t!==Ue.CANCEL&&new is.NonInviteServerTransaction(this,this._transport,e),t===Ue.OPTIONS){if(this.listeners("newOptions").length===0){e.reply(200);return}new N_.Options(this).init_incoming(e)}else if(t===Ue.MESSAGE){if(this.listeners("newMessage").length===0){e.reply(405);return}new N_.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 Wh(this),l.init_incoming(e)):e.body.search(/JANUS/ig)>-1||(l=new WT(this),l.init_incoming(e));else pt.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):pt.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){pt.debug("startMSRP()",t);const r=new Wh(this);return r.connect(e),r}startJanus(e,t){pt.debug("startJanus()",t);const r=new Wh(this);return r.connect(e),r}terminateMSRPSessions(e){pt.debug("terminateSessions()");for(const t in this._msrp_sessions)this._msrp_sessions[t].isEnded()||this._msrp_sessions[t].terminate(e)}terminateJanusSessions(e){pt.debug("terminateSessions()");for(const t in this._janus_sessions)this._janus_sessions[t].isEnded()||this._janus_sessions[t].terminate(e)}enableJanusAudio(e){pt.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){pt.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(pt.debug("stop()"),this._dynConfiguration={},this._status===_n.STATUS_USER_CLOSED){pt.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)){pt.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)){pt.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)){pt.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=_n.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 Qy(u){this.emit("connecting",u)}function Zy(u){this._status!==_n.STATUS_USER_CLOSED&&(this._status=_n.STATUS_READY,this._error=null,this.emit("connected",u),this._dynConfiguration.register&&this._registrator.register())}function eS(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!==_n.STATUS_USER_CLOSED&&(this._status=_n.STATUS_NOT_READY,this._error=_n.NETWORK_ERROR)}function tS(u){const e=u.transport;let t=u.message;if(t=Yy.parseMessage(t,this),!!t&&!(this._status===_n.STATUS_USER_CLOSED&&t instanceof ki.IncomingRequest)&&Cy(t,this,e)){if(t instanceof ki.IncomingRequest)t.transport=e,this.receiveRequest(t);else if(t instanceof ki.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 sS=["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"],nS=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Rg(u){const e={};return sS.forEach(t=>{u[t]!==void 0&&(e[t]=u[t])}),e.localHold=u._localHold,e}function wg(u){const e={};return nS.forEach(t=>{u[t]!==void 0&&(e[t]=u[t])}),e}function Ig(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 iS(u,e,t,r){const l=document.createElement("audio");l.id=e._id,l.className="audioTag",l.srcObject=u,Og()||(l.setSinkId(t),l.volume=r),l.play(),e.audioTag=l}function rS(u){if(u&&typeof u.log=="function"&&typeof u.warn=="function"&&typeof u.error=="function")return!0}function Og(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}class Dg{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 Wo extends Dg{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 Kn("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 Mt.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 nl(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(Zt.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(Zt.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(Zt.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 lS extends Wo{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 Yh={exports:{}},Ko={},Ng={},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 fs<"u"?fs: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 rt={};(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(16777216+(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+.3333333333333333*-(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)*(.6666666666666666-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)}}})(rt);var it={},Fe={},Ne={};Object.defineProperty(Ne,"__esModule",{value:!0}),Ne.RGBComponent=aS,Ne.alphaComponent=oS,Ne.getNumberValidator=uS,Ne.getNumberOrArrayOfNumbersValidator=cS,Ne.getNumberOrAutoValidator=hS,Ne.getStringValidator=fS,Ne.getStringOrGradientValidator=dS,Ne.getFunctionValidator=_S,Ne.getNumberArrayValidator=gS,Ne.getBooleanValidator=pS,Ne.getComponentValidator=mS;const qs=Le,ht=rt;function Ws(u){return ht.Util._isString(u)?'"'+u+'"':Object.prototype.toString.call(u)==="[object Number]"||ht.Util._isBoolean(u)?u:Object.prototype.toString.call(u)}function aS(u){return u>255?255:u<0?0:Math.round(u)}function oS(u){return u>1?1:u<1e-4?1e-4:u}function uS(){if(qs.Konva.isUnminified)return function(u,e){return ht.Util._isNumber(u)||ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),u}}function cS(u){if(qs.Konva.isUnminified)return function(e,t){const r=ht.Util._isNumber(e),l=ht.Util._isArray(e)&&e.length==u;return!r&&!l&&ht.Util.warn(Ws(e)+' is a not valid value for "'+t+'" attribute. The value should be a number or Array<number>('+u+")"),e}}function hS(){if(qs.Konva.isUnminified)return function(u,e){return ht.Util._isNumber(u)||u==="auto"||ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),u}}function fS(){if(qs.Konva.isUnminified)return function(u,e){return ht.Util._isString(u)||ht.Util.warn(Ws(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=ht.Util._isString(u),r=Object.prototype.toString.call(u)==="[object CanvasGradient]"||u&&u.addColorStop;return t||r||ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),u}}function _S(){if(qs.Konva.isUnminified)return function(u,e){return ht.Util._isFunction(u)||ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a function.'),u}}function gS(){if(qs.Konva.isUnminified)return function(u,e){const t=Int8Array?Object.getPrototypeOf(Int8Array):null;return t&&u instanceof t||(ht.Util._isArray(u)?u.forEach(function(r){ht.Util._isNumber(r)||ht.Util.warn('"'+e+'" attribute has non numeric element '+r+". Make sure that all elements are numbers.")}):ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),u}}function pS(){if(qs.Konva.isUnminified)return function(u,e){return u===!0||u===!1||ht.Util.warn(Ws(u)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),u}}function mS(u){if(qs.Konva.isUnminified)return function(e,t){return e==null||ht.Util.isObject(e)||ht.Util.warn(Ws(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=rt,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 ms={},Ks={};Object.defineProperty(Ks,"__esModule",{value:!0}),Ks.HitContext=Ks.SceneContext=Ks.Context=void 0;const Pg=rt,vS=Le;function TS(u){let e=[],t=u.length,r=Pg.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 xg=",",yS="(",SS=")",ES="([",CS="])",AS=";",bS="()",RS="=",kg=["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"],wS=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled"],IS=100;class Yo{constructor(e){this.canvas=e,vS.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+=bS:Pg.Util._isArray(d[0])?s+=ES+d.join(xg)+CS:(t&&(d=d.map(p=>typeof p=="number"?Math.floor(p):p)),s+=yS+d.join(xg)+SS)):(s+=f.property,e||(s+=RS+f.val)),s+=AS;return s}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,r;t.push(e),r=t.length,r>=IS&&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=kg.length,r=this.setAttr,l,s;const i=function(f){let h=e[f],d;e[f]=function(){return s=TS(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(kg[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)}}Ks.Context=Yo,wS.forEach(function(u){Object.defineProperty(Yo.prototype,u,{get(){return this._context[u]},set(e){this._context[u]=e}})});class OS extends Yo{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)}}Ks.SceneContext=OS;class DS extends Yo{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()}}}Ks.HitContext=DS,Object.defineProperty(ms,"__esModule",{value:!0}),ms.HitCanvas=ms.SceneCanvas=ms.Canvas=void 0;const zo=rt,Mg=Ks,Ug=Le,NS=Fe,PS=Ne;let Xo;function xS(){if(Xo)return Xo;const u=zo.Util.createCanvasElement(),e=u.getContext("2d");return Xo=function(){const t=Ug.Konva._global.devicePixelRatio||1,r=e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return t/r}(),zo.Util.releaseCanvas(u),Xo}class Jo{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const r=(e||{}).pixelRatio||Ug.Konva.pixelRatio||xS();this.pixelRatio=r,this._canvas=zo.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 zo.Util.error("Unable to get data URL. "+l.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}ms.Canvas=Jo,NS.Factory.addGetterSetter(Jo,"pixelRatio",void 0,(0,PS.getNumberValidator)());class kS extends Jo{constructor(e={width:0,height:0,willReadFrequently:!1}){super(e),this.context=new Mg.SceneContext(this,{willReadFrequently:e.willReadFrequently}),this.setSize(e.width,e.height)}}ms.SceneCanvas=kS;class MS extends Jo{constructor(e={width:0,height:0}){super(e),this.hitCanvas=!0,this.context=new Mg.HitContext(this),this.setSize(e.width,e.height)}}ms.HitCanvas=MS;var Qo={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.DD=void 0;const e=Le,t=rt;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))})(Qo),Object.defineProperty(it,"__esModule",{value:!0}),it.Node=void 0;const $e=rt,_l=Fe,gl=ms,gn=Le,ls=Qo,mt=Ne,Zo="absoluteOpacity",eu="allEventListeners",Ys="absoluteTransform",Lg="absoluteScale",Yn="canvas",US="Change",LS="children",FS="konva",zh="listening",Fg="mouseenter",$g="mouseleave",Hg="set",Gg="Shape",tu=" ",Vg="stage",pn="transform",$S="Stage",Xh="visible",HS=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(tu);let GS=1;class xe{constructor(e){this._id=GS++,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===pn||e===Ys)&&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===pn||e===Ys)&&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(tu);this.on(l,()=>{this._clearCache(e)}),this._attachedDepsListeners.set(e,!0)}return this._getCache(e,r)}_getCanvasCache(){return this._cache.get(Yn)}_clearSelfAndDescendantCache(e){this._clearCache(e),e===Ys&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(Yn)){const{scene:e,filter:t,hit:r}=this._cache.get(Yn);$e.Util.releaseCanvas(e,t,r),this._cache.delete(Yn)}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){$e.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 gl.SceneCanvas({pixelRatio:i,width:l,height:s}),A=new gl.SceneCanvas({pixelRatio:i,width:0,height:0,willReadFrequently:!0}),R=new gl.HitCanvas({pixelRatio:v,width:l,height:s}),O=S.getContext(),N=R.getContext();return R.isCache=!0,S.isCache=!0,this._cache.delete(Yn),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(Zo),this._clearSelfAndDescendantCache(Lg),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(Yn,{scene:S,filter:A,hit:R,x:f,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(Yn)}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"){$e.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){$e.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(eu),arguments.length===3)return this._delegate.apply(this,arguments);let r=e.split(tu),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(tu),l=r.length,s,i,f,h,d,p;if(this._cache&&this._cache.delete(eu),!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=$e.Util.cloneObject(s),s.currentTarget=i[f],r.call(i[f],s)})}remove(){return this.isDragging()&&this.stopDrag(),ls.DD._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(Ys),this._clearSelfAndDescendantCache(Zo),this._clearSelfAndDescendantCache(Lg),this._clearSelfAndDescendantCache(Vg),this._clearSelfAndDescendantCache(Xh),this._clearSelfAndDescendantCache(zh)}_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"+$e.Util._capitalize(e);return $e.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!==LS&&(r=Hg+$e.Util._capitalize(t),$e.Util._isFunction(this[r])?this[r](e[t]):this._setAttr(t,e[t]))}),this}isListening(){return this._getCache(zh,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(Xh,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;ls.DD._dragElements.forEach(i=>{i.dragStatus==="dragging"&&(i.node.nodeType==="Stage"||i.node.getLayer()===r)&&(l=!0)});const s=!t&&!gn.Konva.hitOnDragEnabled&&(l||gn.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!==Gg&&(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!==$S&&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(pn),this._clearSelfAndDescendantCache(Ys)),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 $e.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(pn);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(pn),this._clearSelfAndDescendantCache(Ys),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 $e.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 $e.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 $e.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 $e.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 $e.Util.warn("Node has no parent. zIndex parameter is ignored."),this;(e<0||e>=this.parent.children.length)&&$e.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(Zo,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=$e.Util.isObject(r)&&!$e.Util._isPlainObject(r)&&!$e.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 $e.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],$e.Util.isValidSelector(s)||($e.Util.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),$e.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),$e.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(Vg,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(Ys,this._getAbsoluteTransform)}_getAbsoluteTransform(e){let t;if(e)return t=new $e.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(Ys)||new $e.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(pn,this._getTransform)}_getTransform(){var e,t;const r=this._cache.get(pn)||new $e.Transform;r.reset();const l=this.x(),s=this.y(),i=gn.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=$e.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(FS)<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 gl.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 gl.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,$e.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():gn.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+US,{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[Hg+$e.Util._capitalize(e)];return $e.Util._isFunction(r)?r.call(this,t):this._setAttr(e,t),this}_requestDraw(){if(gn.Konva.autoDrawEnabled){const e=this.getLayer()||this.getStage();e==null||e.batchDraw()}}_setAttr(e,t){const r=this.attrs[e];r===t&&!$e.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===Gg&&(t.target=this),!((e===Fg||e===$g)&&(r&&(this===r||this.isAncestorOf&&this.isAncestorOf(r))||this.nodeType==="Stage"&&!r))){this._fire(e,t);const s=(e===Fg||e===$g)&&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(eu))!==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(eu,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;ls.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){ls.DD._dragElements.has(this._id)||this._createDragElement(e);const r=ls.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:$e.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=ls.DD._dragElements.get(this._id);t&&(t.dragStatus="stopped"),ls.DD._endDragBefore(e),ls.DD._endDragAfter(e)}setDraggable(e){this._setAttr("draggable",e),this._dragChange()}isDragging(){const e=ls.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)||gn.Konva.dragButtons.indexOf(e.evt.button)>=0)||this.isDragging())return;let l=!1;ls.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=ls.DD._dragElements.get(this._id),r=t&&t.dragStatus==="dragging",l=t&&t.dragStatus==="ready";r?this.stopDrag():l&&ls.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 $e.Util.haveIntersection(r,this.getClientRect())}static create(e,t){return $e.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),gn.Konva[r]||($e.Util.warn('Can not find a node with class name "'+r+'". Fallback to "Shape".'),r="Shape");const h=gn.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,HS,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(pn),this._clearSelfAndDescendantCache(Ys)}),xe.prototype.on.call(xe.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(Xh)}),xe.prototype.on.call(xe.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(zh)}),xe.prototype.on.call(xe.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(Zo)});const ze=_l.Factory.addGetterSetter;ze(xe,"zIndex"),ze(xe,"absolutePosition"),ze(xe,"position"),ze(xe,"x",0,(0,mt.getNumberValidator)()),ze(xe,"y",0,(0,mt.getNumberValidator)()),ze(xe,"globalCompositeOperation","source-over",(0,mt.getStringValidator)()),ze(xe,"opacity",1,(0,mt.getNumberValidator)()),ze(xe,"name","",(0,mt.getStringValidator)()),ze(xe,"id","",(0,mt.getStringValidator)()),ze(xe,"rotation",0,(0,mt.getNumberValidator)()),_l.Factory.addComponentsGetterSetter(xe,"scale",["x","y"]),ze(xe,"scaleX",1,(0,mt.getNumberValidator)()),ze(xe,"scaleY",1,(0,mt.getNumberValidator)()),_l.Factory.addComponentsGetterSetter(xe,"skew",["x","y"]),ze(xe,"skewX",0,(0,mt.getNumberValidator)()),ze(xe,"skewY",0,(0,mt.getNumberValidator)()),_l.Factory.addComponentsGetterSetter(xe,"offset",["x","y"]),ze(xe,"offsetX",0,(0,mt.getNumberValidator)()),ze(xe,"offsetY",0,(0,mt.getNumberValidator)()),ze(xe,"dragDistance",null,(0,mt.getNumberValidator)()),ze(xe,"width",0,(0,mt.getNumberValidator)()),ze(xe,"height",0,(0,mt.getNumberValidator)()),ze(xe,"listening",!0,(0,mt.getBooleanValidator)()),ze(xe,"preventDefault",!0,(0,mt.getBooleanValidator)()),ze(xe,"filters",null,function(u){return this._filterUpToDate=!1,u}),ze(xe,"visible",!0,(0,mt.getBooleanValidator)()),ze(xe,"transformsEnabled","all",(0,mt.getStringValidator)()),ze(xe,"size"),ze(xe,"dragBoundFunc"),ze(xe,"draggable",!1,(0,mt.getBooleanValidator)()),_l.Factory.backCompat(xe,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var zn={};Object.defineProperty(zn,"__esModule",{value:!0}),zn.Container=void 0;const $i=Fe,Jh=it,su=Ne;class Xn extends Jh.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=Jh.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=Jh.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)}}zn.Container=Xn,$i.Factory.addComponentsGetterSetter(Xn,"clip",["x","y","width","height"]),$i.Factory.addGetterSetter(Xn,"clipX",void 0,(0,su.getNumberValidator)()),$i.Factory.addGetterSetter(Xn,"clipY",void 0,(0,su.getNumberValidator)()),$i.Factory.addGetterSetter(Xn,"clipWidth",void 0,(0,su.getNumberValidator)()),$i.Factory.addGetterSetter(Xn,"clipHeight",void 0,(0,su.getNumberValidator)()),$i.Factory.addGetterSetter(Xn,"clipFunc");var Bg={},mn={};Object.defineProperty(mn,"__esModule",{value:!0}),mn.getCapturedShape=BS,mn.createEvent=Qh,mn.hasPointerCapture=jS,mn.setPointerCapture=qS,mn.releaseCapture=qg;const VS=Le,pl=new Map,jg=VS.Konva._global.PointerEvent!==void 0;function BS(u){return pl.get(u)}function Qh(u){return{evt:u,pointerId:u.pointerId}}function jS(u,e){return pl.get(u)===e}function qS(u,e){qg(u),e.getStage()&&(pl.set(u,e),jg&&e._fire("gotpointercapture",Qh(new PointerEvent("gotpointercapture"))))}function qg(u,e){const t=pl.get(u);if(!t)return;const r=t.getStage();r&&r.content,pl.delete(u),jg&&t._fire("lostpointercapture",Qh(new PointerEvent("lostpointercapture")))}(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Stage=u.stages=void 0;const e=rt,t=Fe,r=zn,l=Le,s=ms,i=Qo,f=Le,h=mn,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()})})})(Bg);var ml={},Ct={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Shape=u.shapes=void 0;const e=Le,t=rt,r=Fe,l=it,s=Ne,i=Le,f=mn,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"})})(Ct),Object.defineProperty(ml,"__esModule",{value:!0}),ml.Layer=void 0;const zs=rt,Zh=zn,Hi=it,ef=Fe,Wg=ms,WS=Ne,KS=Ct,YS=Le,zS="#",XS="beforeDraw",JS="draw",Kg=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],QS=Kg.length;class Gi extends Zh.Container{constructor(e){super(e),this.canvas=new Wg.SceneCanvas,this.hitCanvas=new Wg.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(){Hi.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(!Hi.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(Hi.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(Hi.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 Hi.Node.prototype.remove.call(this),e&&e.parentNode&&zs.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"&&zs.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(),Hi.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(){zs.Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){zs.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,zs.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<QS;l++){const s=Kg[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=zs.Util._rgbToHex(r[0],r[1],r[2]),i=KS.shapes[zS+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(XS,{node:this}),this.clearBeforeDraw()&&l.getContext().clear(),Zh.Container.prototype.drawScene.call(this,l,t),this._fire(JS,{node:this}),this}drawHit(e,t){const r=this.getLayer(),l=e||r&&r.hitCanvas;return r&&r.clearBeforeDraw()&&r.getHitCanvas().getContext().clear(),Zh.Container.prototype.drawHit.call(this,l,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){zs.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(e)}getHitGraphEnabled(e){return zs.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 zs.Util.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}ml.Layer=Gi,Gi.prototype.nodeType="Layer",(0,YS._registerNode)(Gi),ef.Factory.addGetterSetter(Gi,"imageSmoothingEnabled",!0),ef.Factory.addGetterSetter(Gi,"clearBeforeDraw",!0),ef.Factory.addGetterSetter(Gi,"hitGraphEnabled",!0,(0,WS.getBooleanValidator)());var nu={};Object.defineProperty(nu,"__esModule",{value:!0}),nu.FastLayer=void 0;const ZS=rt,e2=ml,t2=Le;class tf extends e2.Layer{constructor(e){super(e),this.listening(!1),ZS.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}nu.FastLayer=tf,tf.prototype.nodeType="FastLayer",(0,t2._registerNode)(tf);var Vi={};Object.defineProperty(Vi,"__esModule",{value:!0}),Vi.Group=void 0;const s2=rt,n2=zn,i2=Le;class sf extends n2.Container{_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&s2.Util.throw("You may only add groups and shapes to groups.")}}Vi.Group=sf,sf.prototype.nodeType="Group",(0,i2._registerNode)(sf);var Bi={};Object.defineProperty(Bi,"__esModule",{value:!0}),Bi.Animation=void 0;const nf=Le,Yg=rt,rf=function(){return nf.glob.performance&&nf.glob.performance.now?function(){return nf.glob.performance.now()}:function(){return new Date().getTime()}}();class Os{constructor(e,t){this.id=Os.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:rf(),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=Os.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=rf(),Os._addAnimation(this),this}stop(){return Os._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(rf());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=Os;e.animations.length?(e._runFrames(),Yg.Util.requestAnimFrame(e._animationLoop)):e.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Yg.Util.requestAnimFrame(this._animationLoop))}}Bi.Animation=Os,Os.animations=[],Os.animIdCounter=0,Os.animRunning=!1;var zg={};(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Easings=u.Tween=void 0;const e=rt,t=Bi,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*(2.70158*y-1.70158)+S},BackEaseOut(y,S,A,R){return A*((y=y/R-1)*y*(2.70158*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*.44999999999999996),!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)<.36363636363636365?A*(7.5625*y*y)+S:y<.7272727272727273?A*(7.5625*(y-=.5454545454545454)*y+.75)+S:y<.9090909090909091?A*(7.5625*(y-=.8181818181818182)*y+.9375)+S:A*(7.5625*(y-=.9545454545454546)*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}}})(zg),function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Konva=void 0;const e=Le,t=rt,r=it,l=zn,s=Bg,i=ml,f=nu,h=Vi,d=Qo,p=Ct,v=Bi,T=zg,y=Ks,S=ms;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}(Ng);var iu={};Object.defineProperty(iu,"__esModule",{value:!0}),iu.Arc=void 0;const ru=Fe,r2=Ct,Xg=Le,lu=Ne,l2=Le;class Xs extends r2.Shape{_sceneFunc(e){const t=Xg.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=Xg.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}}}iu.Arc=Xs,Xs.prototype._centroid=!0,Xs.prototype.className="Arc",Xs.prototype._attrsAffectingSize=["innerRadius","outerRadius"],(0,l2._registerNode)(Xs),ru.Factory.addGetterSetter(Xs,"innerRadius",0,(0,lu.getNumberValidator)()),ru.Factory.addGetterSetter(Xs,"outerRadius",0,(0,lu.getNumberValidator)()),ru.Factory.addGetterSetter(Xs,"angle",0,(0,lu.getNumberValidator)()),ru.Factory.addGetterSetter(Xs,"clockwise",!1,(0,lu.getBooleanValidator)());var au={},vl={};Object.defineProperty(vl,"__esModule",{value:!0}),vl.Line=void 0;const ou=Fe,a2=Le,o2=Ct,Jg=Ne;function lf(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 Qg(u,e){const t=u.length,r=[];for(let l=2;l<t-2;l+=2){const s=lf(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 vn extends o2.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():Qg(this.points(),this.tension())}_getTensionPointsClosed(){const e=this.points(),t=e.length,r=this.tension(),l=lf(e[t-2],e[t-1],e[0],e[1],e[2],e[3],r),s=lf(e[t-4],e[t-3],e[t-2],e[t-1],e[0],e[1],r),i=Qg(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}}}vl.Line=vn,vn.prototype.className="Line",vn.prototype._attrsAffectingSize=["points","bezier","tension"],(0,a2._registerNode)(vn),ou.Factory.addGetterSetter(vn,"closed",!1),ou.Factory.addGetterSetter(vn,"bezier",!1),ou.Factory.addGetterSetter(vn,"tension",0,(0,Jg.getNumberValidator)()),ou.Factory.addGetterSetter(vn,"points",[],(0,Jg.getNumberArrayValidator)());var ji={},Zg={};(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})(Zg),Object.defineProperty(ji,"__esModule",{value:!0}),ji.Path=void 0;const u2=Fe,c2=Ct,h2=Le,qi=Zg;class At extends c2.Shape{constructor(e){super(e),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=At.parsePathData(this.data()),this.pathLength=At.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=At.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=At.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=At.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 At.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 At.getPointOnLine(e,i.start.x,i.start.y,f[0],f[1]);case"C":return At.getPointOnCubicBezier((0,qi.t2length)(e,At.getPathLength(t),A=>(0,qi.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 At.getPointOnQuadraticBezier((0,qi.t2length)(e,At.getPathLength(t),A=>(0,qi.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,At.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=At;switch(r){case"L":return d.getLineLength(e,t,l[0],l[1]);case"C":return(0,qi.getCubicArcLength)([e,l[0],l[2],l[4]],[t,l[1],l[3],l[5]],1);case"Q":return(0,qi.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]}}ji.Path=At,At.prototype.className="Path",At.prototype._attrsAffectingSize=["data"],(0,h2._registerNode)(At),u2.Factory.addGetterSetter(At,"data"),Object.defineProperty(au,"__esModule",{value:!0}),au.Arrow=void 0;const uu=Fe,f2=vl,ep=Ne,d2=Le,tp=ji;class Jn extends f2.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=tp.Path.calcLength(l[l.length-4],l[l.length-3],"C",T),S=tp.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}}}au.Arrow=Jn,Jn.prototype.className="Arrow",(0,d2._registerNode)(Jn),uu.Factory.addGetterSetter(Jn,"pointerLength",10,(0,ep.getNumberValidator)()),uu.Factory.addGetterSetter(Jn,"pointerWidth",10,(0,ep.getNumberValidator)()),uu.Factory.addGetterSetter(Jn,"pointerAtBeginning",!1),uu.Factory.addGetterSetter(Jn,"pointerAtEnding",!0);var cu={};Object.defineProperty(cu,"__esModule",{value:!0}),cu.Circle=void 0;const _2=Fe,g2=Ct,p2=Ne,m2=Le;class Wi extends g2.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)}}cu.Circle=Wi,Wi.prototype._centroid=!0,Wi.prototype.className="Circle",Wi.prototype._attrsAffectingSize=["radius"],(0,m2._registerNode)(Wi),_2.Factory.addGetterSetter(Wi,"radius",0,(0,p2.getNumberValidator)());var hu={};Object.defineProperty(hu,"__esModule",{value:!0}),hu.Ellipse=void 0;const af=Fe,v2=Ct,sp=Ne,T2=Le;class Tn extends v2.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=Tn,Tn.prototype.className="Ellipse",Tn.prototype._centroid=!0,Tn.prototype._attrsAffectingSize=["radiusX","radiusY"],(0,T2._registerNode)(Tn),af.Factory.addComponentsGetterSetter(Tn,"radius",["x","y"]),af.Factory.addGetterSetter(Tn,"radiusX",0,(0,sp.getNumberValidator)()),af.Factory.addGetterSetter(Tn,"radiusY",0,(0,sp.getNumberValidator)());var fu={};Object.defineProperty(fu,"__esModule",{value:!0}),fu.Image=void 0;const of=rt,Qn=Fe,y2=Ct,S2=Le,Tl=Ne;let Ds=class c0 extends y2.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?of.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?of.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=of.Util.createImageElement();l.onload=function(){const s=new c0({image:l});t(s)},l.onerror=r,l.crossOrigin="Anonymous",l.src=e}};fu.Image=Ds,Ds.prototype.className="Image",(0,S2._registerNode)(Ds),Qn.Factory.addGetterSetter(Ds,"cornerRadius",0,(0,Tl.getNumberOrArrayOfNumbersValidator)(4)),Qn.Factory.addGetterSetter(Ds,"image"),Qn.Factory.addComponentsGetterSetter(Ds,"crop",["x","y","width","height"]),Qn.Factory.addGetterSetter(Ds,"cropX",0,(0,Tl.getNumberValidator)()),Qn.Factory.addGetterSetter(Ds,"cropY",0,(0,Tl.getNumberValidator)()),Qn.Factory.addGetterSetter(Ds,"cropWidth",0,(0,Tl.getNumberValidator)()),Qn.Factory.addGetterSetter(Ds,"cropHeight",0,(0,Tl.getNumberValidator)());var Ki={};Object.defineProperty(Ki,"__esModule",{value:!0}),Ki.Tag=Ki.Label=void 0;const du=Fe,E2=Ct,C2=Vi,uf=Ne,np=Le,ip=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],A2="Change.konva",b2="none",cf="up",hf="right",ff="down",df="left",R2=ip.length;class _f extends C2.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<R2;r++)e.on(ip[r]+A2,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 cf:f=r/2,h=-1*d;break;case hf:f=r+i,h=l/2;break;case ff:f=r/2,h=l+d;break;case df: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})}}}Ki.Label=_f,_f.prototype.className="Label",(0,np._registerNode)(_f);class Zn extends E2.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===cf&&(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===hf&&(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===ff&&(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===df&&(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===cf?(t-=l,f+=l):s===ff?f+=l:s===df?(e-=r*1.5,i+=r):s===hf&&(i+=r*1.5),{x:e,y:t,width:i,height:f}}}Ki.Tag=Zn,Zn.prototype.className="Tag",(0,np._registerNode)(Zn),du.Factory.addGetterSetter(Zn,"pointerDirection",b2),du.Factory.addGetterSetter(Zn,"pointerWidth",0,(0,uf.getNumberValidator)()),du.Factory.addGetterSetter(Zn,"pointerHeight",0,(0,uf.getNumberValidator)()),du.Factory.addGetterSetter(Zn,"cornerRadius",0,(0,uf.getNumberOrArrayOfNumbersValidator)(4));var yl={};Object.defineProperty(yl,"__esModule",{value:!0}),yl.Rect=void 0;const w2=Fe,I2=Ct,O2=Le,D2=rt,N2=Ne;class _u extends I2.Shape{_sceneFunc(e){const t=this.cornerRadius(),r=this.width(),l=this.height();e.beginPath(),t?D2.Util.drawRoundedRectPath(e,r,l,t):e.rect(0,0,r,l),e.closePath(),e.fillStrokeShape(this)}}yl.Rect=_u,_u.prototype.className="Rect",(0,O2._registerNode)(_u),w2.Factory.addGetterSetter(_u,"cornerRadius",0,(0,N2.getNumberOrArrayOfNumbersValidator)(4));var gu={};Object.defineProperty(gu,"__esModule",{value:!0}),gu.RegularPolygon=void 0;const rp=Fe,P2=Ct,lp=Ne,x2=Le;class ei extends P2.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)}}gu.RegularPolygon=ei,ei.prototype.className="RegularPolygon",ei.prototype._centroid=!0,ei.prototype._attrsAffectingSize=["radius"],(0,x2._registerNode)(ei),rp.Factory.addGetterSetter(ei,"radius",0,(0,lp.getNumberValidator)()),rp.Factory.addGetterSetter(ei,"sides",0,(0,lp.getNumberValidator)());var pu={};Object.defineProperty(pu,"__esModule",{value:!0}),pu.Ring=void 0;const ap=Fe,k2=Ct,op=Ne,M2=Le,up=Math.PI*2;class ti extends k2.Shape{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,up,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),up,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)}}pu.Ring=ti,ti.prototype.className="Ring",ti.prototype._centroid=!0,ti.prototype._attrsAffectingSize=["innerRadius","outerRadius"],(0,M2._registerNode)(ti),ap.Factory.addGetterSetter(ti,"innerRadius",0,(0,op.getNumberValidator)()),ap.Factory.addGetterSetter(ti,"outerRadius",0,(0,op.getNumberValidator)());var mu={};Object.defineProperty(mu,"__esModule",{value:!0}),mu.Sprite=void 0;const si=Fe,U2=Ct,L2=Bi,cp=Ne,F2=Le;class Ns extends U2.Shape{constructor(e){super(e),this._updated=!0,this.anim=new L2.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)}}mu.Sprite=Ns,Ns.prototype.className="Sprite",(0,F2._registerNode)(Ns),si.Factory.addGetterSetter(Ns,"animation"),si.Factory.addGetterSetter(Ns,"animations"),si.Factory.addGetterSetter(Ns,"frameOffsets"),si.Factory.addGetterSetter(Ns,"image"),si.Factory.addGetterSetter(Ns,"frameIndex",0,(0,cp.getNumberValidator)()),si.Factory.addGetterSetter(Ns,"frameRate",17,(0,cp.getNumberValidator)()),si.Factory.backCompat(Ns,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});var vu={};Object.defineProperty(vu,"__esModule",{value:!0}),vu.Star=void 0;const gf=Fe,$2=Ct,pf=Ne,H2=Le;class yn extends $2.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)}}vu.Star=yn,yn.prototype.className="Star",yn.prototype._centroid=!0,yn.prototype._attrsAffectingSize=["innerRadius","outerRadius"],(0,H2._registerNode)(yn),gf.Factory.addGetterSetter(yn,"numPoints",5,(0,pf.getNumberValidator)()),gf.Factory.addGetterSetter(yn,"innerRadius",0,(0,pf.getNumberValidator)()),gf.Factory.addGetterSetter(yn,"outerRadius",0,(0,pf.getNumberValidator)());var Yi={};Object.defineProperty(Yi,"__esModule",{value:!0}),Yi.Text=void 0,Yi.stringToArray=hp;const mf=rt,Bt=Fe,G2=Ct,vf=Le,Sn=Ne,V2=Le;function hp(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 zi="auto",B2="center",fp="inherit",Sl="justify",j2="Change.konva",q2="2d",dp="-",_p="left",W2="text",K2="Text",Y2="top",z2="bottom",gp="middle",pp="normal",X2="px ",Tu=" ",J2="right",mp="rtl",Q2="word",Z2="char",vp="none",Tf="…",Tp=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],eE=Tp.length;function tE(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 yu;function yf(){return yu||(yu=mf.Util.createCanvasElement().getContext(q2),yu)}function sE(u){u.fillText(this._partialText,this._partialTextX,this._partialTextY)}function nE(u){u.setAttr("miterLimit",2),u.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function iE(u){return u=u||{},!u.fillLinearGradientColorStops&&!u.fillRadialGradientColorStops&&!u.fillPatternImage&&(u.fill=u.fill||"black"),u}class ft extends G2.Shape{constructor(e){super(iE(e)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<eE;t++)this.on(Tp[t]+j2,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===fp?e.direction:h;let N=i/2,C=gp;if(vf.Konva._fixTextRendering){const B=this.measureSize("M");C="alphabetic",N=(B.fontBoundingBoxAscent-B.fontBoundingBoxDescent)/2+i/2}var b=0,w=0;for(h===mp&&e.setAttr("direction",h),e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",C),e.setAttr("textAlign",_p),f===gp?d=(this.getHeight()-r*i-l*2)/2:f===z2&&(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===J2?b+=v-D-l*2:p===B2&&(b+=(v-D-l*2)/2),A){e.save(),e.beginPath();const L=vf.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===Sl&&!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=vf.Konva._fixTextRendering?-Math.round(s/4):0;e.moveTo(b,N+w+L),I=q.split(" ").length-1,x=I===0,U=p===Sl&&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!==mp&&(T!==0||p===Sl)){I=q.split(" ").length-1;const L=hp(q);for(let V=0;V<L.length;V++){const J=L[V];J===" "&&!P&&p===Sl&&(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=mf.Util._isString(e)?e:e==null?"":e+"";return this._setAttr(W2,t),this}getWidth(){return this.attrs.width===zi||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===zi||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return mf.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=yf(),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()+Tu+this.fontVariant()+Tu+(this.fontSize()+X2)+tE(this.fontFamily())}_addTextLine(e){this.align()===Sl&&(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 yf().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!==zi&&s!==void 0,h=i!==zi&&i!==void 0,d=this.padding(),p=s-d*2,v=i-d*2,T=0,y=this.wrap(),S=y!==vp,A=y!==Z2&&S,R=this.ellipsis();this.textArr=[],yf().font=this._getContextFont();const O=R?this._getTextWidth(Tf):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===Tu||U===dp)&&I<=p?N=P.length:N=Math.max(P.lastIndexOf(Tu),P.lastIndexOf(dp))+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!==zi&&l!==void 0,i=this.padding(),f=l-i*2;return!(this.wrap()!==vp)||s&&e+r>f}_tryToAddEllipsisToLastLine(){const e=this.attrs.width,t=e!==zi&&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+Tf)<l||(i.text=i.text.slice(0,i.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(i.text+Tf))}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()}}Yi.Text=ft,ft.prototype._fillFunc=sE,ft.prototype._strokeFunc=nE,ft.prototype.className=K2,ft.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],(0,V2._registerNode)(ft),Bt.Factory.overWriteSetter(ft,"width",(0,Sn.getNumberOrAutoValidator)()),Bt.Factory.overWriteSetter(ft,"height",(0,Sn.getNumberOrAutoValidator)()),Bt.Factory.addGetterSetter(ft,"direction",fp),Bt.Factory.addGetterSetter(ft,"fontFamily","Arial"),Bt.Factory.addGetterSetter(ft,"fontSize",12,(0,Sn.getNumberValidator)()),Bt.Factory.addGetterSetter(ft,"fontStyle",pp),Bt.Factory.addGetterSetter(ft,"fontVariant",pp),Bt.Factory.addGetterSetter(ft,"padding",0,(0,Sn.getNumberValidator)()),Bt.Factory.addGetterSetter(ft,"align",_p),Bt.Factory.addGetterSetter(ft,"verticalAlign",Y2),Bt.Factory.addGetterSetter(ft,"lineHeight",1,(0,Sn.getNumberValidator)()),Bt.Factory.addGetterSetter(ft,"wrap",Q2),Bt.Factory.addGetterSetter(ft,"ellipsis",!1,(0,Sn.getBooleanValidator)()),Bt.Factory.addGetterSetter(ft,"letterSpacing",0,(0,Sn.getNumberValidator)()),Bt.Factory.addGetterSetter(ft,"text","",(0,Sn.getStringValidator)()),Bt.Factory.addGetterSetter(ft,"textDecoration","");var Su={};Object.defineProperty(Su,"__esModule",{value:!0}),Su.TextPath=void 0;const Sf=rt,vs=Fe,rE=Ct,El=ji,Ef=Yi,yp=Ne,lE=Le,aE="",Sp="normal";function Ep(u){u.fillText(this.partialText,0,0)}function Cp(u){u.strokeText(this.partialText,0,0)}class bt extends rE.Shape{constructor(e){super(e),this.dummyCanvas=Sf.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 El.Path.getPathLength(this.dataArray)}_getPointAtLength(e){if(!this.attrs.data)return null;const t=this.pathLength;return e-1>t?null:El.Path.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=El.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 Sf.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 Ef.Text.prototype.setText.call(this,e)}_getContextFont(){return Ef.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,Ef.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=El.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=El.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 Sf.Util.releaseCanvas(this.dummyCanvas),super.destroy()}}Su.TextPath=bt,bt.prototype._fillFunc=Ep,bt.prototype._strokeFunc=Cp,bt.prototype._fillFuncHit=Ep,bt.prototype._strokeFuncHit=Cp,bt.prototype.className="TextPath",bt.prototype._attrsAffectingSize=["text","fontSize","data"],(0,lE._registerNode)(bt),vs.Factory.addGetterSetter(bt,"data"),vs.Factory.addGetterSetter(bt,"fontFamily","Arial"),vs.Factory.addGetterSetter(bt,"fontSize",12,(0,yp.getNumberValidator)()),vs.Factory.addGetterSetter(bt,"fontStyle",Sp),vs.Factory.addGetterSetter(bt,"align","left"),vs.Factory.addGetterSetter(bt,"letterSpacing",0,(0,yp.getNumberValidator)()),vs.Factory.addGetterSetter(bt,"textBaseline","middle"),vs.Factory.addGetterSetter(bt,"fontVariant",Sp),vs.Factory.addGetterSetter(bt,"text",aE),vs.Factory.addGetterSetter(bt,"textDecoration",null),vs.Factory.addGetterSetter(bt,"kerningFunc",null);var Eu={};Object.defineProperty(Eu,"__esModule",{value:!0}),Eu.Transformer=void 0;const Ye=rt,qe=Fe,Ap=it,oE=Ct,uE=yl,bp=Vi,Ts=Le,En=Ne,cE=Le,Rp="tr-konva",hE=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(u=>u+`.${Rp}`).join(" "),wp="nodesRect",fE=["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},_E="ontouchstart"in Ts.Konva._global;function gE(u,e,t){if(u==="rotater")return t;e+=Ye.Util.degToRad(dE[u]||0);const r=(Ye.Util.radToDeg(e)%360+360)%360;return Ye.Util._inRange(r,337.5,360)||Ye.Util._inRange(r,0,22.5)?"ns-resize":Ye.Util._inRange(r,22.5,67.5)?"nesw-resize":Ye.Util._inRange(r,67.5,112.5)?"ew-resize":Ye.Util._inRange(r,112.5,157.5)?"nwse-resize":Ye.Util._inRange(r,157.5,202.5)?"ns-resize":Ye.Util._inRange(r,202.5,247.5)?"nesw-resize":Ye.Util._inRange(r,247.5,292.5)?"ew-resize":Ye.Util._inRange(r,292.5,337.5)?"nwse-resize":(Ye.Util.error("Transformer has unknown angle for cursor detection: "+r),"pointer")}const Cu=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"],Ip=1e8;function pE(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 Op(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 mE(u,e){const t=pE(u);return Op(u,e,t)}function vE(u,e,t){let r=e;for(let l=0;l<u.length;l++){const s=Ts.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 Cf=0;class Ve extends bp.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(hE,this.update),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return Ye.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 Rp+this._id}setNodes(e=[]){this._nodes&&this._nodes.length&&this.detach();const t=e.filter(l=>l.isAncestorOf(this)?(Ye.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(fE.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(wp),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(wp,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=(Ts.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 Op(p,-Ts.Konva.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-Ip,y:-Ip,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 Ye.Transform;r.rotate(-Ts.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:Ts.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(),Cu.forEach(e=>{this._createAnchor(e)}),this._createAnchor("rotater")}_createAnchor(e){const t=new uE.Rect({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:e+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:_E?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=Ts.Konva.getAngle(this.rotation()),s=this.rotateAnchorCursor(),i=gE(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 oE.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()*Ye.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},Cf++,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=Ts.Konva.getAngle(this.rotation())+F,P=Ts.Konva.getAngle(this.rotationSnapTolerance()),x=vE(this.rotationSnaps(),D,P)-w.rotation,U=mE(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:Ts.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();Cf--,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(Ye.Util._inRange(e.width,-this.padding()*2-l,l)){this.update();return}if(Ye.Util._inRange(e.height,-this.padding()*2-l,l)){this.update();return}const s=new Ye.Transform;if(s.rotate(Ts.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:Ye.Util.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const i=1e7,f=new Ye.Transform;f.translate(r.x,r.y),f.rotate(r.rotation),f.scale(r.width/i,r.height/i);const h=new Ye.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 Ye.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(Ye.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(Ye.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()*Ye.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=""),bp.Group.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return Ap.Node.prototype.toObject.call(this)}clone(e){return Ap.Node.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}Eu.Transformer=Ve,Ve.isTransforming=()=>Cf>0;function TE(u){return u instanceof Array||Ye.Util.warn("enabledAnchors value should be an array"),u instanceof Array&&u.forEach(function(e){Cu.indexOf(e)===-1&&Ye.Util.warn("Unknown anchor name: "+e+". Available names are: "+Cu.join(", "))}),u||[]}Ve.prototype.className="Transformer",(0,cE._registerNode)(Ve),qe.Factory.addGetterSetter(Ve,"enabledAnchors",Cu,TE),qe.Factory.addGetterSetter(Ve,"flipEnabled",!0,(0,En.getBooleanValidator)()),qe.Factory.addGetterSetter(Ve,"resizeEnabled",!0),qe.Factory.addGetterSetter(Ve,"anchorSize",10,(0,En.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,En.getNumberValidator)()),qe.Factory.addGetterSetter(Ve,"rotateAnchorCursor","crosshair"),qe.Factory.addGetterSetter(Ve,"rotationSnapTolerance",5,(0,En.getNumberValidator)()),qe.Factory.addGetterSetter(Ve,"borderEnabled",!0),qe.Factory.addGetterSetter(Ve,"anchorStroke","rgb(0, 161, 255)"),qe.Factory.addGetterSetter(Ve,"anchorStrokeWidth",1,(0,En.getNumberValidator)()),qe.Factory.addGetterSetter(Ve,"anchorFill","white"),qe.Factory.addGetterSetter(Ve,"anchorCornerRadius",0,(0,En.getNumberValidator)()),qe.Factory.addGetterSetter(Ve,"borderStroke","rgb(0, 161, 255)"),qe.Factory.addGetterSetter(Ve,"borderStrokeWidth",1,(0,En.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,En.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 Au={};Object.defineProperty(Au,"__esModule",{value:!0}),Au.Wedge=void 0;const bu=Fe,yE=Ct,SE=Le,Dp=Ne,EE=Le;class Js extends yE.Shape{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,SE.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)}}Au.Wedge=Js,Js.prototype.className="Wedge",Js.prototype._centroid=!0,Js.prototype._attrsAffectingSize=["radius"],(0,EE._registerNode)(Js),bu.Factory.addGetterSetter(Js,"radius",0,(0,Dp.getNumberValidator)()),bu.Factory.addGetterSetter(Js,"angle",0,(0,Dp.getNumberValidator)()),bu.Factory.addGetterSetter(Js,"clockwise",!1),bu.Factory.backCompat(Js,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});var Ru={};Object.defineProperty(Ru,"__esModule",{value:!0}),Ru.Blur=void 0;const Np=Fe,CE=it,AE=Ne;function Pp(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}const bE=[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],RE=[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 wE(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 Pp,ee=null,j=Pe,K=null,ie=null,ue=bE[e],Ce=RE[e];for(f=1;f<B;f++)j=j.next=new Pp,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 IE=function(e){const t=Math.round(this.blurRadius());t>0&&wE(e,t)};Ru.Blur=IE,Np.Factory.addGetterSetter(CE.Node,"blurRadius",0,(0,AE.getNumberValidator)(),Np.Factory.afterSetFilter);var wu={};Object.defineProperty(wu,"__esModule",{value:!0}),wu.Brighten=void 0;const xp=Fe,OE=it,DE=Ne,NE=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};wu.Brighten=NE,xp.Factory.addGetterSetter(OE.Node,"brightness",0,(0,DE.getNumberValidator)(),xp.Factory.afterSetFilter);var Iu={};Object.defineProperty(Iu,"__esModule",{value:!0}),Iu.Contrast=void 0;const kp=Fe,PE=it,xE=Ne,kE=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};Iu.Contrast=kE,kp.Factory.addGetterSetter(PE.Node,"contrast",0,(0,xE.getNumberValidator)(),kp.Factory.afterSetFilter);var Ou={};Object.defineProperty(Ou,"__esModule",{value:!0}),Ou.Emboss=void 0;const Cn=Fe,Du=it,ME=rt,Mp=Ne,UE=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:ME.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)};Ou.Emboss=UE,Cn.Factory.addGetterSetter(Du.Node,"embossStrength",.5,(0,Mp.getNumberValidator)(),Cn.Factory.afterSetFilter),Cn.Factory.addGetterSetter(Du.Node,"embossWhiteLevel",.5,(0,Mp.getNumberValidator)(),Cn.Factory.afterSetFilter),Cn.Factory.addGetterSetter(Du.Node,"embossDirection","top-left",null,Cn.Factory.afterSetFilter),Cn.Factory.addGetterSetter(Du.Node,"embossBlend",!1,null,Cn.Factory.afterSetFilter);var Nu={};Object.defineProperty(Nu,"__esModule",{value:!0}),Nu.Enhance=void 0;const Up=Fe,LE=it,FE=Ne;function Af(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 $E=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]=Af(e[T+0],r,l,R,A),e[T+1]=Af(e[T+1],i,f,C,N),e[T+2]=Af(e[T+2],d,p,F,w)};Nu.Enhance=$E,Up.Factory.addGetterSetter(LE.Node,"enhance",0,(0,FE.getNumberValidator)(),Up.Factory.afterSetFilter);var Pu={};Object.defineProperty(Pu,"__esModule",{value:!0}),Pu.Grayscale=void 0;const HE=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};Pu.Grayscale=HE;var xu={};Object.defineProperty(xu,"__esModule",{value:!0}),xu.HSL=void 0;const Xi=Fe,bf=it,Rf=Ne;Xi.Factory.addGetterSetter(bf.Node,"hue",0,(0,Rf.getNumberValidator)(),Xi.Factory.afterSetFilter),Xi.Factory.addGetterSetter(bf.Node,"saturation",0,(0,Rf.getNumberValidator)(),Xi.Factory.afterSetFilter),Xi.Factory.addGetterSetter(bf.Node,"luminance",0,(0,Rf.getNumberValidator)(),Xi.Factory.afterSetFilter);const GE=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};xu.HSL=GE;var ku={};Object.defineProperty(ku,"__esModule",{value:!0}),ku.HSV=void 0;const Ji=Fe,wf=it,If=Ne,VE=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};ku.HSV=VE,Ji.Factory.addGetterSetter(wf.Node,"hue",0,(0,If.getNumberValidator)(),Ji.Factory.afterSetFilter),Ji.Factory.addGetterSetter(wf.Node,"saturation",0,(0,If.getNumberValidator)(),Ji.Factory.afterSetFilter),Ji.Factory.addGetterSetter(wf.Node,"value",0,(0,If.getNumberValidator)(),Ji.Factory.afterSetFilter);var Mu={};Object.defineProperty(Mu,"__esModule",{value:!0}),Mu.Invert=void 0;const BE=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]};Mu.Invert=BE;var Uu={};Object.defineProperty(Uu,"__esModule",{value:!0}),Uu.Kaleidoscope=void 0;const Lu=Fe,Lp=it,Fp=rt,$p=Ne,jE=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},qE=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},WE=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=Fp.Util.createCanvasElement();R.width=e,R.height=t;const O=R.getContext("2d").getImageData(0,0,e,t);Fp.Util.releaseCanvas(R),jE(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}qE(O,u,{polarRotation:0})};Uu.Kaleidoscope=WE,Lu.Factory.addGetterSetter(Lp.Node,"kaleidoscopePower",2,(0,$p.getNumberValidator)(),Lu.Factory.afterSetFilter),Lu.Factory.addGetterSetter(Lp.Node,"kaleidoscopeAngle",0,(0,$p.getNumberValidator)(),Lu.Factory.afterSetFilter);var Fu={};Object.defineProperty(Fu,"__esModule",{value:!0}),Fu.Mask=void 0;const Hp=Fe,KE=it,YE=Ne;function $u(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 Cl(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 zE(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 XE(u,e){const t=$u(u,0,0),r=$u(u,u.width-1,0),l=$u(u,0,u.height-1),s=$u(u,u.width-1,u.height-1),i=e||10;if(Cl(t,r)<i&&Cl(r,s)<i&&Cl(s,l)<i&&Cl(l,t)<i){const f=zE([r,t,s,l]),h=[];for(let d=0;d<u.width*u.height;d++){const p=Cl(f,[u.data[d*4],u.data[d*4+1],u.data[d*4+2]]);h[d]=p<i?0:255}return h}}function JE(u,e){for(let t=0;t<u.width*u.height;t++)u.data[4*t+3]=e[t]}function QE(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===2040?255:0}return i}function ZE(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>=1020?255:0}return i}function eC(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 tC=function(u){let e=this.threshold(),t=XE(u,e);return t&&(t=QE(t,u.width,u.height),t=ZE(t,u.width,u.height),t=eC(t,u.width,u.height),JE(u,t)),u};Fu.Mask=tC,Hp.Factory.addGetterSetter(KE.Node,"threshold",0,(0,YE.getNumberValidator)(),Hp.Factory.afterSetFilter);var Hu={};Object.defineProperty(Hu,"__esModule",{value:!0}),Hu.Noise=void 0;const Gp=Fe,sC=it,nC=Ne,iC=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()};Hu.Noise=iC,Gp.Factory.addGetterSetter(sC.Node,"noise",.2,(0,nC.getNumberValidator)(),Gp.Factory.afterSetFilter);var Gu={};Object.defineProperty(Gu,"__esModule",{value:!0}),Gu.Pixelate=void 0;const Vp=Fe,rC=rt,lC=it,aC=Ne,oC=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){rC.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)}};Gu.Pixelate=oC,Vp.Factory.addGetterSetter(lC.Node,"pixelSize",8,(0,aC.getNumberValidator)(),Vp.Factory.afterSetFilter);var Vu={};Object.defineProperty(Vu,"__esModule",{value:!0}),Vu.Posterize=void 0;const Bp=Fe,uC=it,cC=Ne,hC=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};Vu.Posterize=hC,Bp.Factory.addGetterSetter(uC.Node,"levels",.5,(0,cC.getNumberValidator)(),Bp.Factory.afterSetFilter);var Bu={};Object.defineProperty(Bu,"__esModule",{value:!0}),Bu.RGB=void 0;const ju=Fe,Of=it,fC=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]};Bu.RGB=dC,ju.Factory.addGetterSetter(Of.Node,"red",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)}),ju.Factory.addGetterSetter(Of.Node,"green",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)}),ju.Factory.addGetterSetter(Of.Node,"blue",0,fC.RGBComponent,ju.Factory.afterSetFilter);var qu={};Object.defineProperty(qu,"__esModule",{value:!0}),qu.RGBA=void 0;const Al=Fe,Wu=it,_C=Ne,gC=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}};qu.RGBA=gC,Al.Factory.addGetterSetter(Wu.Node,"red",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)}),Al.Factory.addGetterSetter(Wu.Node,"green",0,function(u){return this._filterUpToDate=!1,u>255?255:u<0?0:Math.round(u)}),Al.Factory.addGetterSetter(Wu.Node,"blue",0,_C.RGBComponent,Al.Factory.afterSetFilter),Al.Factory.addGetterSetter(Wu.Node,"alpha",1,function(u){return this._filterUpToDate=!1,u>1?1:u<0?0:u});var Ku={};Object.defineProperty(Ku,"__esModule",{value:!0}),Ku.Sepia=void 0;const pC=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)};Ku.Sepia=pC;var Yu={};Object.defineProperty(Yu,"__esModule",{value:!0}),Yu.Solarize=void 0;const mC=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)};Yu.Solarize=mC;var zu={};Object.defineProperty(zu,"__esModule",{value:!0}),zu.Threshold=void 0;const jp=Fe,vC=it,TC=Ne,yC=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};zu.Threshold=yC,jp.Factory.addGetterSetter(vC.Node,"threshold",.5,(0,TC.getNumberValidator)(),jp.Factory.afterSetFilter),Object.defineProperty(Ko,"__esModule",{value:!0}),Ko.Konva=void 0;const qp=Ng,SC=iu,EC=au,CC=cu,AC=hu,bC=fu,Wp=Ki,RC=vl,wC=ji,IC=yl,OC=gu,DC=pu,NC=mu,PC=vu,xC=Yi,kC=Su,MC=Eu,UC=Au,LC=Ru,FC=wu,$C=Iu,HC=Ou,GC=Nu,VC=Pu,BC=xu,jC=ku,qC=Mu,WC=Uu,KC=Fu,YC=Hu,zC=Gu,XC=Vu,JC=Bu,QC=qu,ZC=Ku,eA=Yu,tA=zu;Ko.Konva=qp.Konva.Util._assign(qp.Konva,{Arc:SC.Arc,Arrow:EC.Arrow,Circle:CC.Circle,Ellipse:AC.Ellipse,Image:bC.Image,Label:Wp.Label,Tag:Wp.Tag,Line:RC.Line,Path:wC.Path,Rect:IC.Rect,RegularPolygon:OC.RegularPolygon,Ring:DC.Ring,Sprite:NC.Sprite,Star:PC.Star,Text:xC.Text,TextPath:kC.TextPath,Transformer:MC.Transformer,Wedge:UC.Wedge,Filters:{Blur:LC.Blur,Brighten:FC.Brighten,Contrast:$C.Contrast,Emboss:HC.Emboss,Enhance:GC.Enhance,Grayscale:VC.Grayscale,HSL:BC.HSL,HSV:jC.HSV,Invert:qC.Invert,Kaleidoscope:WC.Kaleidoscope,Mask:KC.Mask,Noise:YC.Noise,Pixelate:zC.Pixelate,Posterize:XC.Posterize,RGB:JC.RGB,RGBA:QC.RGBA,Sepia:ZC.Sepia,Solarize:eA.Solarize,Threshold:tA.Threshold}});var sA=Yh.exports;Object.defineProperty(sA,"__esModule",{value:!0});const nA=Ko;Yh.exports=nA.Konva;var iA=Yh.exports;const Qi=We(iA),Df={STROKE_WIDTH:5,STROKE_COLOR:"#f32",EMPTY_DRAWER_RECT_COLOR:"#fff"};class Nf{constructor(e){this.stage=null,this.strokeWidth=Df.STROKE_WIDTH,this.strokeColor=Df.STROKE_COLOR,this.emptyDrawerRectColor=Df.EMPTY_DRAWER_RECT_COLOR,this.emptyDrawerRect=null;const{container:t,width:r,height:l}=e,s=new Qi.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 Qi.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 Qi.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 Qi.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 Qi.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 Qi.Line({stroke:"#ffffff",strokeWidth:1,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[0,0,0,0]});e.add(t)}}class Pf extends Dg{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 rA={container:"screen-share-video-container",compositeCanvasContainer:"composite-canvas-container",compositeCanvas:"composite-canvas",drawerContainer:"container",videoElement:"whiteboard-source-video",videoElementContainer:"whiteboard-wrapper"};class lA extends Pf{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={...rA,...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 Nf({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&&window.addEventListener&&typeof window.addEventListener=="function"&&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 Kp={WHITEBOARD:"whiteboard",IMAGE_WHITEBOARD:"imageWhiteboard"},oA={container:"presentation-video-container",drawerContainer:"presentationCanvasWrapper"};class uA extends Wo{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={...oA,...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 Nf({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 Nf({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===Kp.WHITEBOARD)this.drawEmptyWhiteboard();else if(this.mode===Kp.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 cA=Et,hA=_s(),Kt=new cA("WebSocketInterface");var fA=class{constructor(e){Kt.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;const t=hA.parse(e,"absoluteURI");if(t===-1)throw Kt.warn(`invalid WebSocket URI: ${e}`),new TypeError(`Invalid argument: ${e}`);if(t.scheme!=="wss"&&t.scheme!=="ws")throw Kt.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(Kt.debug("connect()"),this.isConnected()){Kt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Kt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Kt.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(e){this._onError(e)}}disconnect(){Kt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(e){return Kt.debug("send()"),this.isConnected()?(this._ws.send(e),!0):(Kt.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){Kt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:e,code:t,reason:r}){Kt.debug(`WebSocket ${this._url} closed`),e===!1&&Kt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!e,t,r)}_onMessage({data:e}){Kt.debug("received WebSocket message"),this.ondata(e)}_onError(e){Kt.warn(`WebSocket ${this._url} error: `,e)}};const xf=Ha,dA=Ue,_A=Bs,gA=xt(),pA=Cg,mA=Hs(),vA=_h(),TA=_s(),yA=fA;Ii("JsSIP")("version %s",xf.version);var SA={C:dA,Exceptions:_A,Utils:gA,UA:pA,URI:mA,NameAddrHeader:vA,WebSocketInterface:yA,Grammar:TA,debug:Ii,get name(){return xf.title},get version(){return xf.version}};const EA=We(SA);function kf(u){return u<10?`0${u}`:`${u}`}function CA(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=`${kf(e)}:${kf(t)}:${kf(r)}`;return{seconds:r,minutes:t,hours:e,formatted:l}}var $t={};$t.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)},$t.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)},$t.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)},$t.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},$t.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)}}),$t.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]},$t.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)}}),$t.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},$t.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)}}),$t.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},$t.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)}}),$t.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},$t.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)}),$t.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},$t.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 Yp={};(function(u){const e=$t;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)}})})(Yp);var AA=Object.assign($t,{instanceMethods:Yp});const ni=new AudioContext,ys={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var bA={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)}})(bA);var zp={exports:{}};(function(u){(function(e,t){u.exports?u.exports=t():e.log=t()})(fs,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})})(zp);var jt=zp.exports;const Qs=()=>`${new Date().toISOString()} | metrics`,Zs=(u,e,t)=>`${u} | ${e} | ${t}`;jt.setDefaultLevel(jt.levels.TRACE);const RA=u=>{jt.info(Zs(Qs(),"log ",`set log level to ${u?"verbose":"info"}`)),jt.setLevel(u?jt.levels.TRACE:jt.levels.INFO)},wA=u=>{const e=[...Object.keys(jt.levels)];e.includes(u)?(jt.info(Zs(Qs(),"log ",`update log level to ${u.toLowerCase()}`)),jt.setLevel(u)):jt.warn(Zs(Qs(),"log ","Incorrect log level please choose one of "),e)},Be=(u,e,t)=>{t?jt.debug(Zs(Qs(),u,e),t):jt.debug(Zs(Qs(),u,e))},Mf=(u,e)=>{jt.info(Zs(Qs(),u,e))},ii=(u,e)=>{jt.info(Zs(Qs(),u,e))},Xu=(u,e)=>{jt.warn(Zs(Qs(),u,e))},Zi=(u,e)=>{jt.error(Zs(Qs(),u,e))};function IA(u){return Math.floor(Math.random()*u).toString()}function Xp(u,e){let t=e;return u.forEach(r=>{t=t.replace(r,"")}),t}function OA(u,e){let t="";for(let r=0;r<e;r+=1)t+=u[IA(u.length)];return t}function DA({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=Xp(l,s)),h=s.split("")),t&&(l.length&&(i=Xp(l,i)),d=i.split("")),f=[...h,...d,...r],OA(f,u)}var NA=DA;const bl=We(NA),PA=()=>"WebRTCMetrics",xA=()=>"5.0.3",Xe={INBOUND:"inbound",OUTBOUND:"outbound"},en={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Rl={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},kA=()=>({...{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:[]}}),Jp={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:Xe.INBOUND},Qp={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:Xe.OUTBOUND},Zp={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:Xe.INBOUND},e0={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:Xe.OUTBOUND},MA=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}}},UA={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${bl()}`,cid:`c-${bl()}`,uid:`u-${bl()}`,record:!1,ticket:!0},Ss={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"},wl={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},Uf={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},he={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},Lf="config ",LA=(u,e={},t)=>{const r={...t,...e};return e.pname||Xu(Lf,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${t.pname}'`),e.cid||Xu(Lf,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${t.cid}'`),e.uid||Xu(Lf,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${t.uid}'`),r.pc=u,r},FA=(u={})=>{const e={...UA,...u};return e.name=PA(),e.version=xA(),e},Il=(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},An=u=>u.reduce((e,t)=>e+t,0)/u.length,$A=()=>`probe-${bl()}`,HA=()=>`coltr-${bl()}`,t0=u=>new Promise(e=>setTimeout(e,u)),Ff=(u,e,t)=>{e?u.call(e,t):u(t)},lt=(u,e,t,r)=>{const l=Il(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},dt=(u,e,t,r=!1,l)=>{const s=Il(u,e,t,r,l);return s.length===0?null:s.reduce((i,f)=>i+f,0)/s.length},ri=(u,e,t)=>Il(u,e,t).reduce((l,s)=>l+s,0),at=(u,e,t,r)=>{const l=Il(u,e,t,!0,r);return l.length===0?null:Math.min(...l)},ot=(u,e,t,r)=>{const l=Il(u,e,t,!1,r);return l.length===0?null:Math.max(...l)},Ht=(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},GA=u=>u.slice().pop(),Ot=(u,e,t)=>{if(!e)return null;const r={};let l=e[X.AUDIO][u];l||(l=t===Xe.INBOUND?{...Jp}:{...Qp}),r[X.AUDIO]=l;let s=e[X.VIDEO][u];return s||(s=t===Xe.INBOUND?{...Zp}:{...e0}),r[X.VIDEO]=s,r},Ol="exporter ",VA="2.0",s0=(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?dt(u,e,"delta_rtt_ms_out",!1,t):Number(s/i)}return null},BA=(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?dt(u,e,"delta_rtt_connectivity_ms"):Number(r/l)},jA=u=>Ht(u,"network","local_candidate_type")!=="relay"?`direct/${Ht(u,"network","local_candidate_protocol")}`:`turn/${Ht(u,"network","local_candidate_relay_protocol")}`,qA=u=>{const e=Ht(u,"network","remote_candidate_type"),t=Ht(u,"network","remote_candidate_protocol");return e!=="relay"?`direct/${t}`:`turn/${t}`};class WA{constructor(e){this._start=null,this._end=null,this._cfg=e,this._referenceReport=null,this._reports=[],this._events=[]}start(){Mf(Ol,"start() - start exporter...");const e=new Date;return this._start=e.toJSON(),e}stop(){Mf(Ol,"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(Ol,`addReport() - add report to exporter at ${e.timestamp}`),this._reports.push(e))}addCustomEvent(e){this._events.push(e)}reset(){Mf(Ol,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Be(Ol,"ticket() - generate ticket");const e=Ht(this._reports,"audio","total_packets_lost_in"),t=Ht(this._reports,"audio","total_packets_in"),r=Ht(this._reports,"video","total_packets_lost_in"),l=Ht(this._reports,"video","total_packets_in"),s={},i=GA(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===Xe.INBOUND){const d={avg:dt(this._reports,X.AUDIO,"delta_jitter_ms_in",!1,f),min:at(this._reports,X.AUDIO,"delta_jitter_ms_in",f),max:ot(this._reports,X.AUDIO,"delta_jitter_ms_in",f),volatility:lt(this._reports,X.AUDIO,"delta_jitter_ms_in",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:dt(this._reports,X.AUDIO,"delta_kbs_in",!1,f),min:at(this._reports,X.AUDIO,"delta_kbs_in",f),max:ot(this._reports,X.AUDIO,"delta_kbs_in",f),volatility:lt(this._reports,X.AUDIO,"delta_kbs_in",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:dt(this._reports,X.AUDIO,"delta_KBytes_in",!1,f),min:at(this._reports,X.AUDIO,"delta_KBytes_in",f),max:ot(this._reports,X.AUDIO,"delta_KBytes_in",f),volatility:lt(this._reports,X.AUDIO,"delta_KBytes_in",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T={emodel:{avg:dt(this._reports,X.AUDIO,"mos_emodel_in",!1,f),min:at(this._reports,X.AUDIO,"mos_emodel_in",f),max:ot(this._reports,X.AUDIO,"mos_emodel_in",f),volatility:lt(this._reports,X.AUDIO,"mos_emodel_in",f)},effective:{avg:dt(this._reports,X.AUDIO,"mos_in",!1,f),min:at(this._reports,X.AUDIO,"mos_in",f),max:ot(this._reports,X.AUDIO,"mos_in",f),volatility:lt(this._reports,X.AUDIO,"mos_in",f)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=Ht(this._reports,X.AUDIO,"total_packets_lost_in",f),S=Ht(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:dt(this._reports,X.AUDIO,"delta_jitter_ms_out",!1,f),min:at(this._reports,X.AUDIO,"delta_jitter_ms_out",f),max:ot(this._reports,X.AUDIO,"delta_jitter_ms_out",f),volatility:lt(this._reports,X.AUDIO,"delta_jitter_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:dt(this._reports,X.AUDIO,"delta_kbs_out",!1,f),min:at(this._reports,X.AUDIO,"delta_kbs_out",f),max:ot(this._reports,X.AUDIO,"delta_kbs_out",f),volatility:lt(this._reports,X.AUDIO,"delta_kbs_out",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:dt(this._reports,X.AUDIO,"delta_KBytes_out",!1,f),min:at(this._reports,X.AUDIO,"delta_KBytes_out",f),max:ot(this._reports,X.AUDIO,"delta_KBytes_out",f),volatility:lt(this._reports,X.AUDIO,"delta_KBytes_out",f),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},T={avg:s0(this._reports,X.AUDIO,f),min:at(this._reports,X.AUDIO,"delta_rtt_ms_out",f),max:ot(this._reports,X.AUDIO,"delta_rtt_ms_out",f),volatility:lt(this._reports,X.AUDIO,"delta_rtt_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=Ht(this._reports,X.AUDIO,"total_packets_lost_out",f),S=Ht(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:dt(this._reports,X.AUDIO,"mos_emodel_out",!1,f),min:at(this._reports,X.AUDIO,"mos_emodel_out",f),max:ot(this._reports,X.AUDIO,"mos_emodel_out",f),volatility:lt(this._reports,X.AUDIO,"mos_emodel_out",f)},effective:{avg:dt(this._reports,X.AUDIO,"mos_out",!1,f),min:at(this._reports,X.AUDIO,"mos_out",f),max:ot(this._reports,X.AUDIO,"mos_out",f),volatility:lt(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===Xe.INBOUND){const d={avg:dt(this._reports,X.VIDEO,"delta_jitter_ms_in",!1,f),min:at(this._reports,X.VIDEO,"delta_jitter_ms_in",f),max:ot(this._reports,X.VIDEO,"delta_jitter_ms_in",f),volatility:lt(this._reports,X.VIDEO,"delta_jitter_ms_in",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:dt(this._reports,X.VIDEO,"delta_kbs_in",!1,f),min:at(this._reports,X.VIDEO,"delta_kbs_in",f),max:ot(this._reports,X.VIDEO,"delta_kbs_in",f),volatility:lt(this._reports,X.VIDEO,"delta_kbs_in",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:dt(this._reports,X.VIDEO,"delta_KBytes_in",!1,f),min:at(this._reports,X.VIDEO,"delta_KBytes_in",f),max:ot(this._reports,X.VIDEO,"delta_KBytes_in",f),volatility:lt(this._reports,X.VIDEO,"delta_KBytes_in",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T=Ht(this._reports,X.VIDEO,"total_packets_lost_in",f),y=Ht(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:dt(this._reports,X.VIDEO,"delta_jitter_ms_out",!1,f),min:at(this._reports,X.VIDEO,"delta_jitter_ms_out",f),max:ot(this._reports,X.VIDEO,"delta_jitter_ms_out",f),volatility:lt(this._reports,X.VIDEO,"delta_jitter_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},p={avg:dt(this._reports,X.VIDEO,"delta_kbs_out",!1,f),min:at(this._reports,X.VIDEO,"delta_kbs_out",f),max:ot(this._reports,X.VIDEO,"delta_kbs_out",f),volatility:lt(this._reports,X.VIDEO,"delta_kbs_out",f),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},v={avg:dt(this._reports,X.VIDEO,"delta_KBytes_out",!1,f),min:at(this._reports,X.VIDEO,"delta_KBytes_out",f),max:ot(this._reports,X.VIDEO,"delta_KBytes_out",f),volatility:lt(this._reports,X.VIDEO,"delta_KBytes_out",f),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},T={avg:s0(this._reports,X.VIDEO,f),min:at(this._reports,X.VIDEO,"delta_rtt_ms_out",f),max:ot(this._reports,X.VIDEO,"delta_rtt_ms_out",f),volatility:lt(this._reports,X.VIDEO,"delta_rtt_ms_out",f),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=Ht(this._reports,X.VIDEO,"total_packets_lost_out",f),S=Ht(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:VA,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:BA(this._reports,"data"),min:at(this._reports,"data","delta_rtt_connectivity_ms"),max:ot(this._reports,"data","delta_rtt_connectivity_ms"),volatility:lt(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:dt(this._reports,"data","delta_kbs_in"),min:at(this._reports,"data","delta_kbs_in"),max:ot(this._reports,"data","delta_kbs_in"),volatility:lt(this._reports,"data","delta_kbs_in")},out:{avg:dt(this._reports,"data","delta_kbs_out"),min:at(this._reports,"data","delta_kbs_out"),max:ot(this._reports,"data","delta_kbs_out"),volatility:lt(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:dt(this._reports,"data","delta_KBytes_in"),min:at(this._reports,"data","delta_KBytes_in"),max:ot(this._reports,"data","delta_KBytes_in"),volatility:lt(this._reports,"data","delta_KBytes_in")},out:{avg:dt(this._reports,"data","delta_KBytes_out"),min:at(this._reports,"data","delta_KBytes_out"),max:ot(this._reports,"data","delta_KBytes_out"),volatility:lt(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:jA(this._reports),remoteConnection:qA(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 bn="extractor ",n0=(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}},KA=(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}},Ju=(u,e,t)=>u[te.TIMESTAMP]===t[e].timestamp_out||!Object.prototype.hasOwnProperty.call(u,te.JITTER)?null:1e3*(Number(u[te.JITTER])||0),YA=(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}},zA=(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}},i0=(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}},r0=(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}},l0=(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}},XA=u=>u[te.CANDIDATE_TYPE]!=="relay"?"":u[te.RELAY_PROTOCOL]||"",JA=u=>{if(!Object.prototype.hasOwnProperty.call(u,te.NETWORK_TYPE))return wl.WIFI;switch(u[te.NETWORK_TYPE]){case Uf.ETHERNET:return wl.ETHERNET;case Uf.CELLULAR_4G:return wl.CELLULAR_4G;case Uf.WIFI:return wl.WIFI;default:return wl.CELLULAR}},a0=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]},QA=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}},ZA=(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}},eb=(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}},tb=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}),sb=u=>({clock_rate:u[te.CLOCK_RATE]||null,mime_type:u[te.MIME_TYPE]||null}),nb=(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}},ib=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}},rb=(u,e,t,r)=>{if(!u)return[];switch(u[te.TYPE]){case Ss.CANDIDATE_PAIR:let l=!1;if(u[te.NOMINATED]&&u[te.STATE]===X.SUCCEEDED&&(l=!0,Be(bn,`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=nb(u,e,r),d=ib(u),p=KA(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 Ss.LOCAL_CANDIDATE:if(u[te.ID]===e.network.local_candidate_id)return[{type:he.NETWORK,value:{infrastructure:JA(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:XA(u)}}];break;case Ss.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 Ss.INBOUND_RTP:{Be(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=Ot(i,e,Xe.INBOUND);f&&(f.timestamp=e.timestamp);const h=Ot(i,r,Xe.INBOUND);if(h&&(h.timestamp=r.timestamp),u[te.MEDIA_TYPE]===X.AUDIO){const d=l0(u,X.AUDIO,f,h),p=Ju(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=YA(u,f),p=l0(u,X.VIDEO,f,h),v=Ju(u,X.VIDEO,f),T=u[te.DECODER_IMPLEMENTATION]||null,y=u[te.CODEC_ID]||null,S=a0(u),A=ZA(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 Ss.OUTBOUND_RTP:{Be(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=Ot(i,e,Xe.OUTBOUND);f&&(f.timestamp=e.timestamp);const h=Ot(i,r,Xe.OUTBOUND);if(h&&(h.timestamp=r.timestamp),u[te.MEDIA_TYPE]===X.AUDIO){const d=u[te.CODEC_ID]||null,p=i0(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=zA(u,f),T=a0(u),y=QA(u),S=eb(u,f,h),A=i0(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 Ss.MEDIA_SOURCE:{Be(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);break}case Ss.TRACK:{Be(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);break}case Ss.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(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const h=tb(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(bn,`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.VIDEO,value:{codec_in:h}}):s.push({ssrc:f.ssrc,type:he.VIDEO,value:{codec_out:h}})}}),s;case Ss.REMOTE_INBOUND_RTP:{Be(bn,`analyze() - got stats ${u[te.TYPE]} for ${t}`,u);const i=u[te.SSRC],f=Ot(i,e,Xe.OUTBOUND),h=Ot(i,r,Xe.OUTBOUND);if(u[te.KIND]===X.AUDIO){const d=n0(u,X.AUDIO,h,f),p=Ju(u,X.AUDIO,f),v=r0(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=n0(u,X.VIDEO,h,f),p=Ju(u,X.VIDEO,f),v=r0(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[]},Qu=u=>u<0?1:u>100?4.5:1+.035*u+7/1e6*u*(u-60)*(100-u),lb=(u,e=X.AUDIO,t,r,l)=>{const s=Ot(l,u,Xe.INBOUND),i=Ot(l,t,Xe.INBOUND),f=Ot(l,r,Xe.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?An(h):100,N=d.length>0?An(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 Qu(D)},ab=(u,e=X.AUDIO,t,r,l)=>{const s=Ot(l,u,Xe.OUTBOUND),i=Ot(l,t,Xe.OUTBOUND),f=Ot(l,r,Xe.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?An(h):100,w=d.length>0?An(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 Qu(x)},ob=(u,e=X.AUDIO,t,r,l)=>{const s=Ot(l,u,Xe.INBOUND),i=Ot(l,t,Xe.INBOUND),f=Ot(l,r,Xe.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?An(h):100,N=d.length>0?An(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 Qu(x)},ub=(u,e=X.AUDIO,t,r,l)=>{const s=Ot(l,u,Xe.OUTBOUND),i=Ot(l,t,Xe.OUTBOUND),f=Ot(l,r,Xe.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?An(h):100,w=d.length>0?An(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 Qu(z)};class cb{constructor(e,t){this._callbacks={onreport:null,onticket:null},this._id=HA(),this._moduleName=this._id,this._probeId=t,this._config=e,this._exporter=new WA(e),this._state=en.IDLE,this.registerToPCEvents(),ii(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(e,t,r,l){const s=(h,d)=>h===X.AUDIO?d===Ss.INBOUND_RTP?{...Jp}:{...Qp}:d===Ss.INBOUND_RTP?{...Zp}:{...e0},i=MA(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),rb(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===Xe.INBOUND?(d.mos_emodel_in=lb(i,X.AUDIO,t,r,d.ssrc),d.mos_in=ob(i,X.AUDIO,t,r,d.ssrc)):(d.mos_emodel_out=ab(i,X.AUDIO,t,r,d.ssrc),d.mos_out=ub(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!==en.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 Zi(this._moduleName,`got error ${e}`),null}}async start(){Be(this._moduleName,"starting"),this.state=en.RUNNING,this._startedTime=this._exporter.start(),Be(this._moduleName,"started")}async mute(){this.state=en.MUTED,Be(this._moduleName,"muted")}async unmute(){this.state=en.RUNNING,Be(this._moduleName,"unmuted")}async stop(e){if(Be(this._moduleName,`stopping${e?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=en.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}'`)):Zi(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}'`)):Zi(this._moduleName,`can't unregister callback for '${e}' - not found`)}fireOnReport(e){this._callbacks.onreport&&Ff(this._callbacks.onreport.callback,this._callbacks.onreport.context,e)}fireOnTicket(e){this._callbacks.onticket&&Ff(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{Zi(this._moduleName,"can't get devices")}},e){e.oniceconnectionstatechange=()=>{const r=e.iceConnectionState;r===Rl.CONNECTED||r===Rl.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",r,"ICE connection state"):r===Rl.DISCONNECTED||r===Rl.FAILED?this.addCustomEvent(new Date().toJSON(),"call",r,"ICE connection state"):r===Rl.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 hb{constructor(e){this._id=e.pname&&e.pname.substr(0,12).padEnd(12," ")||$A(),this._moduleName=this._id,ii(this._moduleName,"probe created"),this._config=e,this._collector=new cb(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===en.RUNNING}get isIdle(){return this._collector.state===en.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){Xu(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 qt="engine ";class fb{constructor(e){this._config=e,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},ii(qt,`configured for probing every ${this._config.refreshEvery}ms`),ii(qt,`configured for starting after ${this._config.startAfter}ms`),ii(qt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Be(qt,"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=LA(e,t,this._config),l=new hb(r);return this._probes.push(l),Be(qt,`${this._probes.length} probes registered`),l}removeExistingProbe(e){if(!e)throw new Error("undefined probe");e.state===en.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=kA(),i=this._probes.filter(f=>f.isRunning);for(const f of i){const h=await f.collectStats();h&&s.probes.push(h),Be(qt,`got probe ${f.id}`),await t0(0)}return s.delta_time_to_measure_probes_ms=ri(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=ri(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=ri(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=ri(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=ri(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=ri(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=ri(s.probes,"video","total_time_encoded_out"),s};for(Be(qt,"starting to collect"),e(),Be(qt,"generating reference reports..."),await t(),Be(qt,"reference reports generated"),this._startedTime=Date.now();r();)if(Be(qt,`wait ${this._config.refreshEvery}ms before collecting`),await t0(this._config.refreshEvery),r()){Be(qt,"collecting...");const s=Date.now(),i=await l(),f=Date.now();i.delta_time_consumed_to_measure_ms=f-s,this.fireOnReports(i),Be(qt,"collected")}Be(qt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(e){const t=r=>{this._probes.forEach(l=>{l.stop(r)})};ii(qt,"stop collecting"),t(e)}registerCallback(e,t,r){e in this._callbacks?(this._callbacks[e]={callback:t,context:r},Be(qt,`registered callback '${e}'`)):Zi(qt,`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}'`)):Zi(this._moduleName,`can't unregister callback for '${e}' - not found`)}fireOnReports(e){this._callbacks.onresult&&e.probes.length>0&&Ff(this._callbacks.onresult.callback,this._callbacks.onresult.context,e)}}const db="interface ";class _b{constructor(e){this._config=FA(e),ii(db,`welcome to ${this._config.name} version ${this._config.version}`),RA(this._config.verbose||!1),this._engine=new fb(this._config)}setupLogLevel(e){wA(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 gb(u,e){return Object.keys(u).filter(t=>e.includes(t)).reduce((t,r)=>{const l=r;return{...t,[l]:u[l]}},{})}const pb=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class mb{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=ni.createAnalyser(),l=ni.createMediaStreamSource(e),s=ni.createScriptProcessor(2048,1,1);r.smoothingTimeConstant=.8,r.fftSize=1024,l.connect(r),r.connect(s),s.connect(ni.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 Zu={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},vb=0;class Tb{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 mb({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 Og()?{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(Zu.SELECTED_INPUT_DEVICE)||"default",t=localStorage.getItem(Zu.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===vb).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]=Rg(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]:Rg(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=Ig(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 AA.forEach(e,async r=>{var i;if(r==null)return;const l=new MediaStream,s=ni.createMediaStreamDestination();if(r.connection.getReceivers().forEach(f=>{t.forEach(h=>{l.addTrack(f.track),f.track.id!==h.id&&ni.createMediaStreamSource(new MediaStream([h])).connect(s)})}),e[0].roomId===this.currentActiveRoomId){const f=this.getActiveStream();ni.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=CA(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(ys.CALL_CONFIRMED,v=>{t.id===v.id&&(this.updateRoom({incomingInProgress:!1,roomId:l}),this.startCallTimer(t.id))}),this.context.subscribe(ys.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:ys.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:ys.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:ys.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:ys.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:ys.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(Zu.SELECTED_INPUT_DEVICE,e),this.selectedMediaDevices.input=e,this.context.emit("changeActiveInputMediaDevice",e)}setSelectedOutputDevice(e){localStorage.setItem(Zu.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 _b(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=gb(f,pb);h.callId=e._id,this.setCallMetrics(h)},this.context.subscribe(ys.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=Ig(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]);iS(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 yb{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 Sb{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]=wg(e),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(e){this.activeMessages={...this.activeMessages,[e._id]:wg(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:ys.CALL_ENDED,session:t,event:r});const l=this.getActiveMessages[t.id];this.activeMessageListRemove(l)}),t.on("failed",r=>{this.triggerMSRPListener({listenerType:ys.CALL_FAILED,session:t,event:r});const l=this.getActiveMessages[t.id];this.activeMessageListRemove(l)}),t.on("confirmed",r=>{this.triggerMSRPListener({listenerType:ys.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 $f={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class Eb extends Jy{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 EA.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&&rS(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 Wo)e.setOpensips(this),this.newStreamPlugins.push(e);else if(e instanceof Pf)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($f.AUDIO)&&(this.audio=new Tb(this)),this.modules.includes($f.MSRP)&&(this.msrp=new Sb(this)),this.modules.includes($f.VIDEO)&&(this.video=new yb(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)}}return zt.BaseNewStreamPlugin=Wo,zt.BaseProcessStreamPlugin=Pf,zt.ScreenSharePlugin=lS,zt.ScreenShareWhiteBoardPlugin=lA,zt.WhiteBoardPlugin=uA,zt.default=Eb,Object.defineProperties(zt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),zt}({});
|
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 Kr(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=Ce.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=Ce.STATUS_INVITE_SENT}terminate(t={}){const n=t.cause||L.causes.BYE,a=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Ce.STATUS_TERMINATED)throw new Ns.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ce.STATUS_NULL:case Ce.STATUS_INVITE_SENT:case Ce.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===Ce.STATUS_NULL||this._status===Ce.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Ce.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Ce.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case Ce.STATUS_WAITING_FOR_ANSWER:case Ce.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 Ce.STATUS_WAITING_FOR_ACK:case Ce.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===Ce.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Ht.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===Ht.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 qn("");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 qn(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Dm(this.credentials);o.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},a,xe.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 ca(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!==Ce.STATUS_INVITE_SENT&&this._status!==Ce.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(t.status_code):this._status=Ce.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=Ce.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=Ce.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=xe.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new qn("");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",xe.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 qn("");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 qn("");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=Ce.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=xe.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=Ce.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===Ce.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!==Ce.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!==Ce.STATUS_TERMINATED){if(this._status=Ce.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 ca(this,t,n,ca.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 ca(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 Ce.STATUS_CANCELED:case Ce.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===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED)&&(this._status=Ce.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==Ce.STATUS_WAITING_FOR_ACK)return;if(this._status=Ce.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!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===Ce.STATUS_CONFIRMED||this._status===Ce.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===Ce.STATUS_INVITE_RECEIVED||this._status===Ce.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===Ce.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:this._status===Ce.STATUS_1XX_RECEIVED||this._status===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED||this._status===Ce.STATUS_WAITING_FOR_ACK||this._status===Ce.STATUS_CONFIRMED?(t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new nu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===Ce.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===Ce.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===Ce.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}}var vT=Yt();const yu=Me(vT),ya=new ra("Parser"),ET=(c,t)=>{let n,a,o=c.indexOf(`\r
|
157
|
+
`);if(o===-1){ya.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=yu.parse(s,"Request_Response");if(r===-1){ya.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new $n.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new $n.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){ya.warn("parseMessage() | malformed message");return}if(r=yT(n,c,d,o),r!==!0){ya.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
|
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 yT(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=yu.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=yu.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 $n.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 AT={parseMessage:ET},ni=new ra("Registrator"),Aa=10;class CT{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=vs.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){ni.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 Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new Kr(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")){ni.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){ni.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<Aa&&(d=Aa);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<Aa&&(this._expires=Aa),this.register()):(ni.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=vs.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){ni.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 Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new Kr(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=vs.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 et=console,ks={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},RT=fT;class IT extends RT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new CT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){et.debug("call()");const o=new Sa(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){et.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{si.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=vs.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=vs.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Lg(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=wT.bind(this),this._transport.ondisconnect=OT.bind(this),this._transport.ondata=DT.bind(this)}catch(s){throw et.warn(s),new Ns.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 ln("sip",vs.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}));et.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(si.settings,s))switch(s){case"uri":case"registrar_server":et.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":et.debug(`- ${s}: NOT SHOWN`);break;default:et.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){et.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(Ht.checkTransaction(this,t))return;if(n===De.INVITE?new Ht.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new Ht.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new yf.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new yf.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 Su(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new Sg(this),o.init_incoming(t));else et.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):et.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){et.debug("startMSRP()",n);const a=new Su(this);return a.connect(t),a}startJanus(t,n){et.debug("startJanus()",n);const a=new Su(this);return a.connect(t),a}terminateMSRPSessions(t){et.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){et.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){et.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){et.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(et.debug("stop()"),this._dynConfiguration={},this._status===ks.STATUS_USER_CLOSED){et.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)){et.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)){et.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)){et.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=ks.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 wT(c){this._status!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function OT(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!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_NOT_READY,this._error=ks.NETWORK_ERROR)}function DT(c){const t=c.transport;let n=c.message;if(n=AT.parseMessage(n,this),!!n&&!(this._status===ks.STATUS_USER_CLOSED&&n instanceof $n.IncomingRequest)&&Qg(n,this,t)){if(n instanceof $n.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof $n.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 NT=["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"],UT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function gh(c){const t={};return NT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Th(c){const t={};return UT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function vh(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 PT(c,t,n,a){const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,Eh()||(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 Eh(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}const kT=at,MT=Yt(),Ot=new kT("WebSocketInterface");var LT=class{constructor(t){Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=MT.parse(t,"absoluteURI");if(n===-1)throw Ot.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.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(Ot.debug("connect()"),this.isConnected()){Ot.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Ot.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Ot.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(){Ot.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 Ot.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Ot.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(){Ot.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:t,code:n,reason:a}){Ot.debug(`WebSocket ${this._url} closed`),t===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Ot.debug("received WebSocket message"),this.ondata(t)}_onError(t){Ot.warn(`WebSocket ${this._url} error: `,t)}};const Au=vl,$T=De,HT=Ts,FT=mt(),jT=_h,qT=ps(),VT=Vo(),BT=Yt(),GT=LT;Un("JsSIP")("version %s",Au.version);var WT={C:$T,Exceptions:HT,Utils:FT,UA:jT,URI:qT,NameAddrHeader:VT,WebSocketInterface:GT,Grammar:BT,debug:Un,get name(){return Au.title},get version(){return Au.version}};const KT=Me(WT);function Cu(c){return c<10?`0${c}`:`${c}`}function YT(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=`${Cu(t)}:${Cu(n)}:${Cu(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var yt={};yt.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)},yt.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)},yt.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)},yt.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},yt.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)}}),yt.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]},yt.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)}}),yt.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},yt.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)}}),yt.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},yt.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)}}),yt.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},yt.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)}),yt.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},yt.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 Sh={};(function(c){const t=yt;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)}})})(Sh);var JT=Object.assign(yt,{instanceMethods:Sh});const an=new AudioContext,Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var zT={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,Y,G){ee[Y]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=d.asyncIterator||"@@asyncIterator",g=d.toStringTag||"@@toStringTag";function T(ee,Y,G){return Object.defineProperty(ee,Y,{value:G,enumerable:!0,configurable:!0,writable:!0}),ee[Y]}try{T({},"")}catch{T=function(Y,G,re){return Y[G]=re}}function E(ee,Y,G,re){var ge=Y&&Y.prototype instanceof oe?Y:oe,be=Object.create(ge.prototype),ke=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,ke)}),be}n.wrap=E;function y(ee,Y,G){try{return{type:"normal",arg:ee.call(Y,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(Y){T(ee,Y,function(G){return this._invoke(Y,G)})})}n.isGeneratorFunction=function(ee){var Y=typeof ee=="function"&&ee.constructor;return Y?Y===N||(Y.displayName||Y.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,Y){function G(be,ke,Re,le){var ye=y(ee[be],ee,ke);if(ye.type==="throw")le(ye.arg);else{var lt=ye.arg,ot=lt.value;return ot&&typeof ot=="object"&&o.call(ot,"__await")?Y.resolve(ot.__await).then(function(Ee){G("next",Ee,Re,le)},function(Ee){G("throw",Ee,Re,le)}):Y.resolve(ot).then(function(Ee){lt.value=Ee,Re(lt)},function(Ee){return G("throw",Ee,Re,le)})}}var re;function ge(be,ke){function Re(){return new Y(function(le,ye){G(be,ke,le,ye)})}return re=re?re.then(Re,Re):Re()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,Y,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,Y,G,re),ge);return n.isGeneratorFunction(Y)?be:be.next().then(function(ke){return ke.done?ke.value:be.next()})};function J(ee,Y,G){var re=A;return function(be,ke){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw ke;return it()}for(G.method=be,G.arg=ke;;){var Re=G.delegate;if(Re){var le=F(Re,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,Y,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,Y){var G=Y.method,re=ee.iterator[G];if(re===r)return Y.delegate=null,G==="throw"&&ee.iterator.return&&(Y.method="return",Y.arg=r,F(ee,Y),Y.method==="throw")||G!=="return"&&(Y.method="throw",Y.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,Y.arg);if(ge.type==="throw")return Y.method="throw",Y.arg=ge.arg,Y.delegate=null,$;var be=ge.arg;if(!be)return Y.method="throw",Y.arg=new TypeError("iterator result is not an object"),Y.delegate=null,$;if(be.done)Y[ee.resultName]=be.value,Y.next=ee.nextLoc,Y.method!=="return"&&(Y.method="next",Y.arg=r);else return be;return Y.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,function(){return this}),T(D,"toString",function(){return"[object Generator]"});function Z(ee){var Y={tryLoc:ee[0]};1 in ee&&(Y.catchLoc=ee[1]),2 in ee&&(Y.finallyLoc=ee[2],Y.afterLoc=ee[3]),this.tryEntries.push(Y)}function U(ee){var Y=ee.completion||{};Y.type="normal",delete Y.arg,ee.completion=Y}function P(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(Z,this),this.reset(!0)}n.keys=function(ee){var Y=Object(ee),G=[];for(var re in Y)G.push(re);return G.reverse(),function ge(){for(;G.length;){var be=G.pop();if(be in Y)return ge.value=be,ge.done=!1,ge}return ge.done=!0,ge}};function se(ee){if(ee){var Y=ee[h];if(Y)return Y.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:it}}n.values=se;function it(){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 Y in this)Y.charAt(0)==="t"&&o.call(this,Y)&&!isNaN(+Y.slice(1))&&(this[Y]=r)},stop:function(){this.done=!0;var ee=this.tryEntries[0],Y=ee.completion;if(Y.type==="throw")throw Y.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var Y=this;function G(le,ye){return be.type="throw",be.arg=ee,Y.next=le,ye&&(Y.method="next",Y.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 ke=o.call(ge,"catchLoc"),Re=o.call(ge,"finallyLoc");if(ke&&Re){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(ke){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0)}else if(Re){if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,Y){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<=Y&&Y<=ge.finallyLoc&&(ge=null);var be=ge?ge.completion:{};return be.type=ee,be.arg=Y,ge?(this.method="next",this.next=ge.finallyLoc,$):this.complete(be)},complete:function(ee,Y){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"&&Y&&(this.next=Y),$},finish:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];if(G.finallyLoc===ee)return this.complete(G.completion,G.afterLoc),U(G),$}},catch:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];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,Y,G){return this.delegate={iterator:se(ee),resultName:Y,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)}})(zT);var yh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(cs,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})})(yh);var It=yh.exports;const Es=()=>`${new Date().toISOString()} | metrics`,Ss=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const XT=c=>{It.info(Ss(Es(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},QT=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Ss(Es(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Ss(Es(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Ss(Es(),c,t),n):It.debug(Ss(Es(),c,t))},Ru=(c,t)=>{It.info(Ss(Es(),c,t))},on=(c,t)=>{It.info(Ss(Es(),c,t))},Ca=(c,t)=>{It.warn(Ss(Es(),c,t))},Vn=(c,t)=>{It.error(Ss(Es(),c,t))};function ZT(c){return Math.floor(Math.random()*c).toString()}function Ah(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[ZT(c.length)];return n}function tv({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=Ah(o,s)),h=s.split("")),n&&(o.length&&(r=Ah(o,r)),_=r.split("")),d=[...h,..._,...a],ev(d,c)}var sv=tv;const ri=Me(sv),nv=()=>"WebRTCMetrics",rv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},ys={IDLE:"idle",RUNNING:"running",MUTED:"muted"},ii={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},iv=()=>({...{delta_time_to_measure_probes_ms:0,delta_time_consumed_to_measure_ms:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,total_time_decoded_in:0,total_time_encoded_out:0,probes:[]}}),Ch={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},Rh={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},Ih={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},bh={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},lv=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}}},av={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${ri()}`,cid:`c-${ri()}`,uid:`u-${ri()}`,record:!1,ticket:!0},Qt={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"},li={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},Iu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},bu="config ",ov=(c,t={},n)=>{const a={...n,...t};return t.pname||Ca(bu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Ca(bu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Ca(bu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},uv=(c={})=>{const t={...av,...c};return t.name=nv(),t.version=rv(),t},ai=(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},Ms=c=>c.reduce((t,n)=>t+n,0)/c.length,cv=()=>`probe-${ri()}`,fv=()=>`coltr-${ri()}`,wh=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},We=(c,t,n,a)=>{const o=ai(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=ai(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},un=(c,t,n)=>ai(c,t,n).reduce((o,s)=>o+s,0),Ke=(c,t,n,a)=>{const o=ai(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Ye=(c,t,n,a)=>{const o=ai(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},At=(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},hv=c=>c.slice().pop(),ht=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Ch}:{...Rh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ih}:{...bh}),a[x.VIDEO]=s,a},oi="exporter ",dv="2.0",Oh=(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},_v=(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)},pv=c=>At(c,"network","local_candidate_type")!=="relay"?`direct/${At(c,"network","local_candidate_protocol")}`:`turn/${At(c,"network","local_candidate_relay_protocol")}`,mv=c=>{const t=At(c,"network","remote_candidate_type"),n=At(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class gv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){Ru(oi,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){Ru(oi,"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(oi,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){Ru(oi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(oi,"ticket() - generate ticket");const t=At(this._reports,"audio","total_packets_lost_in"),n=At(this._reports,"audio","total_packets_in"),a=At(this._reports,"video","total_packets_lost_in"),o=At(this._reports,"video","total_packets_in"),s={},r=hv(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:Ke(this._reports,x.AUDIO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_in",d),volatility:We(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:Ke(this._reports,x.AUDIO,"delta_kbs_in",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_in",d),volatility:We(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:Ke(this._reports,x.AUDIO,"delta_KBytes_in",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_in",d),volatility:We(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:Ke(this._reports,x.AUDIO,"mos_emodel_in",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_in",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_in",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_in",!1,d),min:Ke(this._reports,x.AUDIO,"mos_in",d),max:Ye(this._reports,x.AUDIO,"mos_in",d),volatility:We(this._reports,x.AUDIO,"mos_in",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=At(this._reports,x.AUDIO,"total_packets_lost_in",d),A=At(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:Ke(this._reports,x.AUDIO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_out",d),volatility:We(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:Ke(this._reports,x.AUDIO,"delta_kbs_out",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_out",d),volatility:We(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:Ke(this._reports,x.AUDIO,"delta_KBytes_out",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_out",d),volatility:We(this._reports,x.AUDIO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},E={avg:Oh(this._reports,x.AUDIO,d),min:Ke(this._reports,x.AUDIO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.AUDIO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=At(this._reports,x.AUDIO,"total_packets_lost_out",d),A=At(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:Ke(this._reports,x.AUDIO,"mos_emodel_out",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_out",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_out",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_out",!1,d),min:Ke(this._reports,x.AUDIO,"mos_out",d),max:Ye(this._reports,x.AUDIO,"mos_out",d),volatility:We(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:Ke(this._reports,x.VIDEO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_in",d),volatility:We(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:Ke(this._reports,x.VIDEO,"delta_kbs_in",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_in",d),volatility:We(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:Ke(this._reports,x.VIDEO,"delta_KBytes_in",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_in",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E=At(this._reports,x.VIDEO,"total_packets_lost_in",d),y=At(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:Ke(this._reports,x.VIDEO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_out",d),volatility:We(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:Ke(this._reports,x.VIDEO,"delta_kbs_out",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_out",d),volatility:We(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:Ke(this._reports,x.VIDEO,"delta_KBytes_out",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_out",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={avg:Oh(this._reports,x.VIDEO,d),min:Ke(this._reports,x.VIDEO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.VIDEO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=At(this._reports,x.VIDEO,"total_packets_lost_out",d),A=At(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:dv,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:_v(this._reports,"data"),min:Ke(this._reports,"data","delta_rtt_connectivity_ms"),max:Ye(this._reports,"data","delta_rtt_connectivity_ms"),volatility:We(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:Ke(this._reports,"data","delta_kbs_in"),max:Ye(this._reports,"data","delta_kbs_in"),volatility:We(this._reports,"data","delta_kbs_in")},out:{avg:Xe(this._reports,"data","delta_kbs_out"),min:Ke(this._reports,"data","delta_kbs_out"),max:Ye(this._reports,"data","delta_kbs_out"),volatility:We(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:Ke(this._reports,"data","delta_KBytes_in"),max:Ye(this._reports,"data","delta_KBytes_in"),volatility:We(this._reports,"data","delta_KBytes_in")},out:{avg:Xe(this._reports,"data","delta_KBytes_out"),min:Ke(this._reports,"data","delta_KBytes_out"),max:Ye(this._reports,"data","delta_KBytes_out"),volatility:We(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:pv(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 Ls="extractor ",Dh=(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}},Tv=(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}},Ra=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),vv=(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}},Ev=(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}},Nh=(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}},Uh=(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}},Ph=(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}},Sv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",yv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return li.WIFI;switch(c[q.NETWORK_TYPE]){case Iu.ETHERNET:return li.ETHERNET;case Iu.CELLULAR_4G:return li.CELLULAR_4G;case Iu.WIFI:return li.WIFI;default:return li.CELLULAR}},xh=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]},Av=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}},Cv=(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}},Rv=(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}},Iv=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}),bv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),wv=(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}},Ov=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}},Dv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case Qt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(Ls,`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=wv(c,t,a),_=Ov(c),g=Tv(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 Qt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:yv(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:Sv(c)}}];break;case Qt.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 Qt.INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ph(c,x.AUDIO,d,h),g=Ra(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 _=vv(c,d),g=Ph(c,x.VIDEO,d,h),T=Ra(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,A=xh(c),C=Cv(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 Qt.OUTBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=Nh(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=Ev(c,d),E=xh(c),y=Av(c),A=Rv(c,d,h),C=Nh(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 Qt.MEDIA_SOURCE:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Qt.TRACK:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Qt.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(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Iv(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(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=bv(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 Qt.REMOTE_INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND),h=ht(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Dh(c,x.AUDIO,h,d),g=Ra(c,x.AUDIO,d),T=Uh(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 _=Dh(c,x.VIDEO,h,d),g=Ra(c,x.VIDEO,d),T=Uh(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[]},Ia=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Nv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(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?Ms(h):100,$=_.length>0?Ms(_):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 Ia(k)},Uv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(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?Ms(h):100,j=_.length>0?Ms(_):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 Ia(V)},Pv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(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?Ms(h):100,$=_.length>0?Ms(_):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 Ia(V)},xv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(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?Ms(h):100,j=_.length>0?Ms(_):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,Z=93.2-(Se+ve*Math.log(1+k*g)+J);return Ia(Z)};class kv{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=fv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new gv(t),this._state=ys.IDLE,this.registerToPCEvents(),on(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===Qt.INBOUND_RTP?{...Ch}:{...Rh}:_===Qt.INBOUND_RTP?{...Ih}:{...bh},r=lv(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),Dv(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=Nv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Pv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Uv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=xv(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!==ys.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 Vn(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=ys.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=ys.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=ys.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=ys.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}'`)):Vn(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}'`)):Vn(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{Vn(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===ii.CONNECTED||a===ii.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.DISCONNECTED||a===ii.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.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 Mv{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||cv(),this._moduleName=this._id,on(this._moduleName,"probe created"),this._config=t,this._collector=new kv(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===ys.RUNNING}get isIdle(){return this._collector.state===ys.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){Ca(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 bt="engine ";class Lv{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},on(bt,`configured for probing every ${this._config.refreshEvery}ms`),on(bt,`configured for starting after ${this._config.startAfter}ms`),on(bt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(bt,"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=ov(t,n,this._config),o=new Mv(a);return this._probes.push(o),Pe(bt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===ys.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=iv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(bt,`got probe ${d.id}`),await wh(0)}return s.delta_time_to_measure_probes_ms=un(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=un(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=un(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=un(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=un(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=un(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=un(s.probes,"video","total_time_encoded_out"),s};for(Pe(bt,"starting to collect"),t(),Pe(bt,"generating reference reports..."),await n(),Pe(bt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(bt,`wait ${this._config.refreshEvery}ms before collecting`),await wh(this._config.refreshEvery),a()){Pe(bt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(bt,"collected")}Pe(bt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};on(bt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(bt,`registered callback '${t}'`)):Vn(bt,`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}'`)):Vn(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 $v="interface ";class Hv{constructor(t){this._config=uv(t),on($v,`welcome to ${this._config.name} version ${this._config.version}`),XT(this._config.verbose||!1),this._engine=new Lv(this._config)}setupLogLevel(t){QT(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 Fv(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const jv=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class qv{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=an.createAnalyser(),o=an.createMediaStreamSource(t),s=an.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(an.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const ba={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Vv=0;class Bv{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 qv({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 Eh()?{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(ba.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(ba.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===Vv).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]=gh(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]:gh(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=vh(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 JT.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=an.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&an.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();an.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status!==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=YT(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(ba.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(ba.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 Hv(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=Fv(d,jv);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=vh(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]);PT(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 Gv{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 Wv{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]=Th(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Th(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=xe.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new ln("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 Tt.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 Kr(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(xt.PUBLISHER)];this.session.sendRequest(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(xt.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(xt.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 Kv extends IT{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 KT.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 Bv(this)),this.modules.includes(Ou.MSRP)&&(this.msrp=new Wv(this)),this.modules.includes(Ou.VIDEO)&&(this.video=new Gv(this)),this.on(this.registeredEventName,()=>{this.logger.log("Successfully registered to",this.options.socketInterfaces[0]),this.setInitialized(!0)}),this.on(this.unregisteredEventName,()=>{this.logger.log("Unregistered from",this.options.socketInterfaces[0]),this.setInitialized(!1)}),this.on(this.connectedEventName,()=>{this.logger.log("Connected to",this.options.socketInterfaces[0]),this.setConnected(!0),this.setReconnecting(!1),this.activeConnection=!0}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.setReconnecting(!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)}setReconnecting(t){this.isReconnecting=t,this.emit("reconnecting",t)}}return Wt.BaseNewStreamPlugin=Mh,Wt.BaseProcessStreamPlugin=Lh,Wt.default=Kv,Object.defineProperties(Wt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Wt}({});
|