@cognigy/click-to-call-sdk 0.0.7

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.
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WebRTCSDK={})}(this,function(e){"use strict";function t(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let s=0;s<8;s++)n+=t.charAt(Math.floor(62*Math.random()));return e?`${e}-${n}`:n}function n(){return"undefined"!=typeof window&&"undefined"!=typeof document&&!!(window.RTCPeerConnection&&window.navigator&&window.navigator.mediaDevices&&window.navigator.mediaDevices.getUserMedia)}function s(e){if(!e||"object"!=typeof e)return!1;return["organisationId","projectId","endpointSettings","endpointSettings.sipConnectivityInfo","endpointSettings.sipConnectivityInfo.username","endpointSettings.sipConnectivityInfo.password","endpointSettings.sipConnectivityInfo.wsUri","endpointSettings.sipConnectivityInfo.realm","endpointSettings.sipConnectivityInfo.applicationSid"].every(t=>{const n=function(e,t){return t.split(".").reduce((e,t)=>e&&void 0!==e[t]?e[t]:void 0,e)}(e,t);return null!=n&&""!==n})}function r(e,t){return Promise.race([e,new Promise((e,n)=>setTimeout(()=>n(new Error(`Operation timed out after ${t}ms`)),t))])}class i{constructor(e,t){this.config=null,this.endpointUrl=e,this.userId=t||"",this.userProvidedId=!!t}async fetchConfig(){if(this.config)return this.config;try{const e=await r(fetch(this.endpointUrl,{method:"GET",headers:{"Content-Type":"application/json"}}),1e4);if(!e.ok)throw new Error(`Failed to fetch config: ${e.status} ${e.statusText}`);const n=await e.json();if(!s(n))throw new Error("Invalid endpoint configuration received");if(this.config=n,!this.userProvidedId){const e=(n.endpointSettings?.endpointName||"").replace(/[^a-zA-Z0-9-]/g,"").toLowerCase()||"endpoint";this.userId=`webrtc-sdk-${e}-${t()}`}return n}catch(e){throw new Error(`Configuration fetch failed: ${e instanceof Error?e.message:"Unknown error"}`)}}getConfig(){return this.config}getSipCredentials(){if(!this.config)throw new Error("Configuration not loaded");const e=this.config.endpointSettings.sipConnectivityInfo;return{fullUsername:`${this.userId??""}@${e.realm}`,password:e.password,username:e.username,wsUri:e.wsUri,applicationSid:e.applicationSid,realm:e.realm}}getApplicationSid(){if(!this.config)throw new Error("Configuration not loaded");return this.config.endpointSettings.sipConnectivityInfo.applicationSid}isActive(){return this.config?.endpointSettings?.webrtcWidgetConfig?.active??!1}getPrivacySettings(){return this.config?.settings?.privacyNotice??{enabled:!1,text:"",cancelButtonText:"Cancel",submitButtonText:"Accept",urlText:"",url:""}}clearConfig(){this.config=null}isConfigValid(){return!!this.config&&s(this.config)}getPeerConnectionConfig(){}}const o={title:"JsSIP",version:"3.13.5"};var l,a,u,c;function h(){if(a)return l;a=1;return l={USER_AGENT:`${o.title} ${o.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,SUBSCRIBE",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 d(){if(c)return u;c=1;class e 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 t extends Error{constructor(e){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=e,this.message=`Invalid status: ${e}`}}class n extends Error{constructor(e){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=e}}class s extends Error{constructor(e){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=e}}return u={ConfigurationError:e,InvalidStateError:t,NotSupportedError:n,NotReadyError:s}}var _,p,f,m,g,T,E,S={};function C(){if(p)return _;p=1;const e=v(),t=A();return _=class n{static parse(e){return-1!==(e=t.parse(e,"Name_Addr_Header"))?e:void 0}constructor(t,n,s){if(!(t&&t instanceof e))throw new TypeError('missing or invalid "uri" parameter');this._uri=t,this._parameters={},this.display_name=n;for(const e in s)Object.prototype.hasOwnProperty.call(s,e)&&this.setParam(e,s[e])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(e){this._display_name=0===e?"0":e}setParam(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?null:t.toString())}getParam(e){if(e)return this._parameters[e.toLowerCase()]}hasParam(e){if(e)return!!this._parameters.hasOwnProperty(e.toLowerCase())}deleteParam(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){const t=this._parameters[e];return delete this._parameters[e],t}}clearParams(){this._parameters={}}clone(){return new n(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let e=this._display_name?`"${this._quote(this._display_name)}" `:"";e+=`<${this._uri.toString()}>`;for(const t in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=`;${t}`,null!==this._parameters[t]&&(e+=`=${this._parameters[t]}`));return e}}}function A(){return m?f:(m=1,f=function(){function e(e){return'"'+e.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(t,n){var s={CRLF:a,DIGIT:u,ALPHA:c,HEXDIG:h,WSP:d,OCTET:_,DQUOTE:p,SP:f,HTAB:m,alphanum:g,reserved:T,unreserved:E,mark:S,escaped:A,LWS:R,SWS:I,HCOLON:b,TEXT_UTF8_TRIM:w,TEXT_UTF8char:y,UTF8_NONASCII:N,UTF8_CONT:O,LHEX:function(){var e;null===(e=u())&&(/^[a-f]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[a-f]")));return e},token:D,token_nodot:U,separators:function(){var e;40===t.charCodeAt(r)?(e="(",r++):(e=null,l('"("'));null===e&&(41===t.charCodeAt(r)?(e=")",r++):(e=null,l('")"')),null===e&&(60===t.charCodeAt(r)?(e="<",r++):(e=null,l('"<"')),null===e&&(62===t.charCodeAt(r)?(e=">",r++):(e=null,l('">"')),null===e&&(64===t.charCodeAt(r)?(e="@",r++):(e=null,l('"@"')),null===e&&(44===t.charCodeAt(r)?(e=",",r++):(e=null,l('","')),null===e&&(59===t.charCodeAt(r)?(e=";",r++):(e=null,l('";"')),null===e&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(92===t.charCodeAt(r)?(e="\\",r++):(e=null,l('"\\\\"')),null===e&&null===(e=p())&&(47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"')),null===e&&(91===t.charCodeAt(r)?(e="[",r++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(r)?(e="]",r++):(e=null,l('"]"')),null===e&&(63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null===e&&(61===t.charCodeAt(r)?(e="=",r++):(e=null,l('"="')),null===e&&(123===t.charCodeAt(r)?(e="{",r++):(e=null,l('"{"')),null===e&&(125===t.charCodeAt(r)?(e="}",r++):(e=null,l('"}"')),null===e&&null===(e=f())&&(e=m()))))))))))))))));return e},word:x,STAR:M,SLASH:P,EQUAL:q,LPAREN:$,RPAREN:H,RAQUOT:F,LAQUOT:L,COMMA:k,SEMI:G,COLON:j,LDQUOT:B,RDQUOT:V,comment:function e(){var t,n,s,i;if(i=r,null!==(t=$())){for(n=[],null===(s=W())&&null===(s=X())&&(s=e());null!==s;)n.push(s),null===(s=W())&&null===(s=X())&&(s=e());null!==n&&null!==(s=H())?t=[t,n,s]:(t=null,r=i)}else t=null,r=i;return t},ctext:W,quoted_string:Y,quoted_string_clean:z,qdtext:K,quoted_pair:X,SIP_URI_noparams:Q,SIP_URI:J,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:se,user_unreserved:re,password:ie,hostport:oe,host:le,hostname:ae,domainlabel:ue,toplabel:ce,IPv6reference:he,IPv6address:de,h16:_e,ls32:pe,IPv4address:fe,dec_octet:me,port:ge,uri_parameters:Te,uri_parameter:Ee,transport_param:Se,user_param:Ce,method_param:Ae,ttl_param:ve,maddr_param:Re,lr_param:Ie,other_param:be,pname:we,pvalue:ye,paramchar:Ne,param_unreserved:Oe,headers:De,header:Ue,hname:xe,hvalue:Me,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=qe());return e},Request_Line:qe,Request_URI:$e,absoluteURI:He,hier_part:Fe,net_path:Le,abs_path:ke,opaque_part:Ge,uric:je,uric_no_slash:Be,path_segments:Ve,segment:We,param:Ye,pchar:ze,scheme:Ke,authority:Xe,srvr:Qe,reg_name:Je,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:st,BYEm:rt,CANCELm:it,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:at,REFERm:ut,Method:ct,Status_Line:ht,Status_Code:dt,extension_code:_t,Reason_Phrase:pt,Allow_Events:function(){var e,t,n,s,i,o;if(i=r,null!==(e=Ht())){for(t=[],o=r,null!==(n=k())&&null!==(s=Ht())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=Ht())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},Call_ID:function(){var e,n,s,i,o,a;i=r,o=r,null!==(e=x())?(a=r,64===t.charCodeAt(r)?(n="@",r++):(n=null,l('"@"')),null!==n&&null!==(s=x())?n=[n,s]:(n=null,r=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=o)):(e=null,r=o);null!==e&&(u=i,e=void(kn=t.substring(r,u)));var u;null===e&&(r=i);return e},Contact:function(){var e,t,n,s,i,o,l;if(i=r,null===(e=M()))if(o=r,null!==(e=ft())){for(t=[],l=r,null!==(n=k())&&null!==(s=ft())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=k())&&null!==(s=ft())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(e=function(){var e,t;for(t=kn.multi_header.length,e=0;e<t;e++)if(null===kn.multi_header[e].parsed){kn=null;break}kn=null!==kn?kn.multi_header:-1}());null===e&&(r=i);return e},contact_param:ft,name_addr:mt,display_name:gt,contact_params:Tt,c_p_q:Et,c_p_expires:St,delta_seconds:Ct,qvalue:At,generic_param:vt,gen_value:Rt,Content_Disposition:function(){var e,t,n,s,i,o;if(i=r,null!==(e=It())){for(t=[],o=r,null!==(n=G())&&null!==(s=bt())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=G())&&null!==(s=bt())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},disp_type:It,disp_param:bt,handling_param:wt,Content_Encoding:function(){var e,t,n,s,i,o;if(i=r,null!==(e=D())){for(t=[],o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},Content_Length:function(){var e,t,n;if(n=r,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(kn=parseInt(e.join(""))));null===e&&(r=n);return e},Content_Type:function(){var e,n;n=r,null!==(e=yt())&&(s=n,e=void(kn=t.substring(r,s)));var s;null===e&&(r=n);return e},media_type:yt,m_type:Nt,discrete_type:Ot,composite_type:Dt,extension_token:Ut,x_token:xt,m_subtype:Mt,m_parameter:Pt,m_value:qt,CSeq:function(){var e,t,n,s;s=r,null!==(e=$t())&&null!==(t=R())&&null!==(n=ct())?e=[e,t,n]:(e=null,r=s);return e},CSeq_value:$t,Expires:function(){var e,t;t=r,null!==(e=Ct())&&(e=void(kn=e));null===e&&(r=t);return e},Event:function(){var e,t,n,s,i,o,l;if(i=r,o=r,null!==(e=Ht())){for(t=[],l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(a=e[0],e=void(kn.event=a.join("").toLowerCase()));var a;null===e&&(r=i);return e},event_type:Ht,From:function(){var e,t,n,s,i,o,l;i=r,o=r,null===(e=Q())&&(e=mt());if(null!==e){for(t=[],l=r,null!==(n=G())&&null!==(s=Ft())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=Ft())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(e=function(){var e=kn.tag;try{kn=new Ln(kn.uri,kn.display_name,kn.params),e&&kn.setParam("tag",e)}catch(t){kn=-1}}());null===e&&(r=i);return e},from_param:Ft,tag_param:Lt,Max_Forwards:function(){var e,t,n;if(n=r,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(kn=parseInt(e.join(""))));null===e&&(r=n);return e},Min_Expires:function(){var e,t;t=r,null!==(e=Ct())&&(e=void(kn=e));null===e&&(r=t);return e},Name_Addr_Header:function(){var e,t,n,s,i,o,l,a,u,c;a=r,u=r,e=[],t=gt();for(;null!==t;)e.push(t),t=gt();if(null!==e)if(null!==(t=L()))if(null!==(n=J()))if(null!==(s=F())){for(i=[],c=r,null!==(o=G())&&null!==(l=vt())?o=[o,l]:(o=null,r=c);null!==o;)i.push(o),c=r,null!==(o=G())&&null!==(l=vt())?o=[o,l]:(o=null,r=c);null!==i?e=[e,t,n,s,i]:(e=null,r=u)}else e=null,r=u;else e=null,r=u;else e=null,r=u;else e=null,r=u;null!==e&&(e=function(){try{kn=new Ln(kn.uri,kn.display_name,kn.params)}catch(e){kn=-1}}());null===e&&(r=a);return e},Proxy_Authenticate:function(){return kt()},challenge:kt,other_challenge:Gt,auth_param:jt,digest_cln:Bt,realm:Vt,realm_value:Wt,domain:Yt,URI:zt,nonce:Kt,nonce_value:Xt,opaque:Qt,stale:Jt,algorithm:Zt,qop_options:en,qop_value:tn,Proxy_Require:function(){var e,t,n,s,i,o;if(i=r,null!==(e=D())){for(t=[],o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},Record_Route:function(){var e,t,n,s,i,o,l;if(i=r,o=r,null!==(e=nn())){for(t=[],l=r,null!==(n=k())&&null!==(s=nn())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=k())&&null!==(s=nn())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(e=function(){var e,t;for(t=kn.multi_header.length,e=0;e<t;e++)if(null===kn.multi_header[e].parsed){kn=null;break}kn=null!==kn?kn.multi_header:-1}());null===e&&(r=i);return e},rec_route:nn,Reason:function(){var e,n,s,i,o,a,u;o=r,a=r,"sip"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"SIP"'));null===e&&(e=D());if(null!==e){for(n=[],u=r,null!==(s=G())&&null!==(i=sn())?s=[s,i]:(s=null,r=u);null!==s;)n.push(s),u=r,null!==(s=G())&&null!==(i=sn())?s=[s,i]:(s=null,r=u);null!==n?e=[e,n]:(e=null,r=a)}else e=null,r=a;null!==e&&(e=function(e,t){if(kn.protocol=t.toLowerCase(),kn.params||(kn.params={}),kn.params.text&&'"'===kn.params.text[0]){var n=kn.params.text;kn.text=n.substring(1,n.length-1),delete kn.params.text}}(0,e[0]));null===e&&(r=o);return e},reason_param:sn,reason_cause:rn,Require:function(){var e,t,n,s,i,o;if(i=r,null!==(e=D())){for(t=[],o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},Route:function(){var e,t,n,s,i,o;if(i=r,null!==(e=on())){for(t=[],o=r,null!==(n=k())&&null!==(s=on())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=on())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},route_param:on,Subscription_State:function(){var e,t,n,s,i,o;if(i=r,null!==(e=ln())){for(t=[],o=r,null!==(n=G())&&null!==(s=an())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=G())&&null!==(s=an())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},substate_value:ln,subexp_params:an,event_reason_value:un,Subject:function(){var e;return e=null!==(e=w())?e:""},Supported:function(){var e,t,n,s,i,o;if(i=r,null!==(e=D())){for(t=[],o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=D())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e=null!==e?e:""},To:function(){var e,t,n,s,i,o,l;i=r,o=r,null===(e=Q())&&(e=mt());if(null!==e){for(t=[],l=r,null!==(n=G())&&null!==(s=cn())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=cn())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(e=function(){var e=kn.tag;try{kn=new Ln(kn.uri,kn.display_name,kn.params),e&&kn.setParam("tag",e)}catch(t){kn=-1}}());null===e&&(r=i);return e},to_param:cn,Via:function(){var e,t,n,s,i,o;if(i=r,null!==(e=hn())){for(t=[],o=r,null!==(n=k())&&null!==(s=hn())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=k())&&null!==(s=hn())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},via_param:hn,via_params:dn,via_ttl:_n,via_maddr:pn,via_received:fn,via_branch:mn,response_port:gn,rport:Tn,sent_protocol:En,protocol_name:Sn,transport:Cn,sent_by:An,via_host:vn,via_port:Rn,ttl:In,WWW_Authenticate:function(){return kt()},Session_Expires:function(){var e,t,n,s,i,o;if(i=r,null!==(e=bn())){for(t=[],o=r,null!==(n=G())&&null!==(s=wn())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=G())&&null!==(s=wn())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},s_e_expires:bn,s_e_params:wn,s_e_refresher:yn,extension_header:function(){var e,t,n,s;s=r,null!==(e=D())&&null!==(t=b())&&null!==(n=Nn())?e=[e,t,n]:(e=null,r=s);return e},header_value:Nn,message_body:function(){var e,t;e=[],t=_();for(;null!==t;)e.push(t),t=_();return e},uuid_URI:function(){var e,n,s;s=r,"uuid:"===t.substr(r,5)?(e="uuid:",r+=5):(e=null,l('"uuid:"'));null!==e&&null!==(n=On())?e=[e,n]:(e=null,r=s);return e},uuid:On,hex4:Dn,hex8:Un,hex12:xn,Refer_To:function(){var e,t,n,s,i,o,l;i=r,o=r,null===(e=Q())&&(e=mt());if(null!==e){for(t=[],l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;null!==e&&(e=function(){try{kn=new Ln(kn.uri,kn.display_name,kn.params)}catch(e){kn=-1}}());null===e&&(r=i);return e},Replaces:function(){var e,t,n,s,i,o;if(i=r,null!==(e=Mn())){for(t=[],o=r,null!==(n=G())&&null!==(s=Pn())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=G())&&null!==(s=Pn())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e},call_id:Mn,replaces_param:Pn,to_tag:qn,from_tag:$n,early_flag:Hn};if(void 0!==n){if(void 0===s[n])throw new Error("Invalid rule name: "+e(n)+".")}else n="CRLF";var r=0,i=0,o=[];function l(e){r<i||(r>i&&(i=r,o=[]),o.push(e))}function a(){var e;return"\r\n"===t.substr(r,2)?(e="\r\n",r+=2):(e=null,l('"\\r\\n"')),e}function u(){var e;return/^[0-9]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[0-9]")),e}function c(){var e;return/^[a-zA-Z]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[a-zA-Z]")),e}function h(){var e;return/^[0-9a-fA-F]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[0-9a-fA-F]")),e}function d(){var e;return null===(e=f())&&(e=m()),e}function _(){var e;return/^[\0-\xFF]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[\\0-\\xFF]")),e}function p(){var e;return/^["]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l('["]')),e}function f(){var e;return 32===t.charCodeAt(r)?(e=" ",r++):(e=null,l('" "')),e}function m(){var e;return 9===t.charCodeAt(r)?(e="\t",r++):(e=null,l('"\\t"')),e}function g(){var e;return/^[a-zA-Z0-9]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[a-zA-Z0-9]")),e}function T(){var e;return 59===t.charCodeAt(r)?(e=";",r++):(e=null,l('";"')),null===e&&(47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(r)?(e="@",r++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(r)?(e="&",r++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(r)?(e="=",r++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(r)?(e=",",r++):(e=null,l('","'))))))))))),e}function E(){var e;return null===(e=g())&&(e=S()),e}function S(){var e;return 45===t.charCodeAt(r)?(e="-",r++):(e=null,l('"-"')),null===e&&(95===t.charCodeAt(r)?(e="_",r++):(e=null,l('"_"')),null===e&&(46===t.charCodeAt(r)?(e=".",r++):(e=null,l('"."')),null===e&&(33===t.charCodeAt(r)?(e="!",r++):(e=null,l('"!"')),null===e&&(126===t.charCodeAt(r)?(e="~",r++):(e=null,l('"~"')),null===e&&(42===t.charCodeAt(r)?(e="*",r++):(e=null,l('"*"')),null===e&&(39===t.charCodeAt(r)?(e="'",r++):(e=null,l('"\'"')),null===e&&(40===t.charCodeAt(r)?(e="(",r++):(e=null,l('"("')),null===e&&(41===t.charCodeAt(r)?(e=")",r++):(e=null,l('")"')))))))))),e}function A(){var e,n,s,i,o;return i=r,o=r,37===t.charCodeAt(r)?(e="%",r++):(e=null,l('"%"')),null!==e&&null!==(n=h())&&null!==(s=h())?e=[e,n,s]:(e=null,r=o),null!==e&&(e=e.join("")),null===e&&(r=i),e}function R(){var e,t,n,s,i,o;for(s=r,i=r,o=r,e=[],t=d();null!==t;)e.push(t),t=d();if(null!==e&&null!==(t=a())?e=[e,t]:(e=null,r=o),null!==(e=null!==e?e:"")){if(null!==(n=d()))for(t=[];null!==n;)t.push(n),n=d();else t=null;null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return null!==e&&(e=function(){return" "}()),null===e&&(r=s),e}function I(){var e;return e=null!==(e=R())?e:""}function b(){var e,n,s,i,o;for(i=r,o=r,e=[],null===(n=f())&&(n=m());null!==n;)e.push(n),null===(n=f())&&(n=m());return null!==e?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return":"}()),null===e&&(r=i),e}function w(){var e,n,s,i,o,l,a,u;if(o=r,l=r,null!==(n=y()))for(e=[];null!==n;)e.push(n),n=y();else e=null;if(null!==e){for(n=[],a=r,s=[],i=R();null!==i;)s.push(i),i=R();for(null!==s&&null!==(i=y())?s=[s,i]:(s=null,r=a);null!==s;){for(n.push(s),a=r,s=[],i=R();null!==i;)s.push(i),i=R();null!==s&&null!==(i=y())?s=[s,i]:(s=null,r=a)}null!==n?e=[e,n]:(e=null,r=l)}else e=null,r=l;return null!==e&&(u=o,e=t.substring(r,u)),null===e&&(r=o),e}function y(){var e;return/^[!-~]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[!-~]")),null===e&&(e=N()),e}function N(){var e;return/^[\x80-\uFFFF]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[\\x80-\\uFFFF]")),e}function O(){var e;return/^[\x80-\xBF]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[\\x80-\\xBF]")),e}function D(){var e,n,s,i;if(s=r,null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"')))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"'))))))))))));else e=null;return null!==e&&(i=s,e=t.substring(r,i)),null===e&&(r=s),e}function U(){var e,n,s,i;if(s=r,null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"'))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"')))))))))));else e=null;return null!==e&&(i=s,e=t.substring(r,i)),null===e&&(r=s),e}function x(){var e,n,s,i;if(s=r,null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(r)?(n="(",r++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(r)?(n=")",r++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(r)?(n="<",r++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(r)?(n=">",r++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(r)?(n="\\",r++):(n=null,l('"\\\\"')),null===n&&null===(n=p())&&(47===t.charCodeAt(r)?(n="/",r++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(r)?(n="[",r++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(r)?(n="]",r++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(r)?(n="?",r++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(r)?(n="{",r++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(r)?(n="}",r++):(n=null,l('"}"')))))))))))))))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(r)?(n="!",r++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(r)?(n="%",r++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(r)?(n="_",r++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(r)?(n="`",r++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(r)?(n="'",r++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(r)?(n="~",r++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(r)?(n="(",r++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(r)?(n=")",r++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(r)?(n="<",r++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(r)?(n=">",r++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(r)?(n="\\",r++):(n=null,l('"\\\\"')),null===n&&null===(n=p())&&(47===t.charCodeAt(r)?(n="/",r++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(r)?(n="[",r++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(r)?(n="]",r++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(r)?(n="?",r++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(r)?(n="{",r++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(r)?(n="}",r++):(n=null,l('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(i=s,e=t.substring(r,i)),null===e&&(r=s),e}function M(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(42===t.charCodeAt(r)?(n="*",r++):(n=null,l('"*"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return"*"}()),null===e&&(r=i),e}function P(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(47===t.charCodeAt(r)?(n="/",r++):(n=null,l('"/"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return"/"}()),null===e&&(r=i),e}function q(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return"="}()),null===e&&(r=i),e}function $(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(40===t.charCodeAt(r)?(n="(",r++):(n=null,l('"("')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return"("}()),null===e&&(r=i),e}function H(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(41===t.charCodeAt(r)?(n=")",r++):(n=null,l('")"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return")"}()),null===e&&(r=i),e}function F(){var e,n,s,i;return s=r,i=r,62===t.charCodeAt(r)?(e=">",r++):(e=null,l('">"')),null!==e&&null!==(n=I())?e=[e,n]:(e=null,r=i),null!==e&&(e=function(){return">"}()),null===e&&(r=s),e}function L(){var e,n,s,i;return s=r,i=r,null!==(e=I())?(60===t.charCodeAt(r)?(n="<",r++):(n=null,l('"<"')),null!==n?e=[e,n]:(e=null,r=i)):(e=null,r=i),null!==e&&(e=function(){return"<"}()),null===e&&(r=s),e}function k(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(44===t.charCodeAt(r)?(n=",",r++):(n=null,l('","')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return","}()),null===e&&(r=i),e}function G(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(59===t.charCodeAt(r)?(n=";",r++):(n=null,l('";"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return";"}()),null===e&&(r=i),e}function j(){var e,n,s,i,o;return i=r,o=r,null!==(e=I())?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=I())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(e=function(){return":"}()),null===e&&(r=i),e}function B(){var e,t,n,s;return n=r,s=r,null!==(e=I())&&null!==(t=p())?e=[e,t]:(e=null,r=s),null!==e&&(e=function(){return'"'}()),null===e&&(r=n),e}function V(){var e,t,n,s;return n=r,s=r,null!==(e=p())&&null!==(t=I())?e=[e,t]:(e=null,r=s),null!==e&&(e=function(){return'"'}()),null===e&&(r=n),e}function W(){var e;return/^[!-']/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[!-']")),null===e&&(/^[*-[]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[*-[]")),null===e&&(/^[\]-~]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[\\]-~]")),null===e&&null===(e=N())&&(e=R()))),e}function Y(){var e,n,s,i,o,l,a;if(o=r,l=r,null!==(e=I()))if(null!==(n=p())){for(s=[],null===(i=K())&&(i=X());null!==i;)s.push(i),null===(i=K())&&(i=X());null!==s&&null!==(i=p())?e=[e,n,s,i]:(e=null,r=l)}else e=null,r=l;else e=null,r=l;return null!==e&&(a=o,e=t.substring(r,a)),null===e&&(r=o),e}function z(){var e,n,s,i,o,l,a,u;if(o=r,l=r,null!==(e=I()))if(null!==(n=p())){for(s=[],null===(i=K())&&(i=X());null!==i;)s.push(i),null===(i=K())&&(i=X());null!==s&&null!==(i=p())?e=[e,n,s,i]:(e=null,r=l)}else e=null,r=l;else e=null,r=l;return null!==e&&(a=o,e=(u=t.substring(r,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(r=o),e}function K(){var e;return null===(e=R())&&(33===t.charCodeAt(r)?(e="!",r++):(e=null,l('"!"')),null===e&&(/^[#-[]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[#-[]")),null===e&&(/^[\]-~]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[\\]-~]")),null===e&&(e=N())))),e}function X(){var e,n,s;return s=r,92===t.charCodeAt(r)?(e="\\",r++):(e=null,l('"\\\\"')),null!==e?(/^[\0-\t]/.test(t.charAt(r))?(n=t.charAt(r),r++):(n=null,l("[\\0-\\t]")),null===n&&(/^[\x0B-\f]/.test(t.charAt(r))?(n=t.charAt(r),r++):(n=null,l("[\\x0B-\\f]")),null===n&&(/^[\x0E-]/.test(t.charAt(r))?(n=t.charAt(r),r++):(n=null,l("[\\x0E-]")))),null!==n?e=[e,n]:(e=null,r=s)):(e=null,r=s),e}function Q(){var e,n,s,i,o,a;return o=r,a=r,null!==(e=Z())?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=null!==(s=ne())?s:"")&&null!==(i=oe())?e=[e,n,s,i]:(e=null,r=a)):(e=null,r=a),null!==e&&(e=function(){try{kn.uri=new Fn(kn.scheme,kn.user,kn.host,kn.port),delete kn.scheme,delete kn.user,delete kn.host,delete kn.host_type,delete kn.port}catch(e){kn=-1}}()),null===e&&(r=o),e}function J(){var e,s,i,o,a,u,c,h;return c=r,h=r,null!==(e=Z())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=null!==(i=ne())?i:"")&&null!==(o=oe())&&null!==(a=Te())&&null!==(u=null!==(u=De())?u:"")?e=[e,s,i,o,a,u]:(e=null,r=h)):(e=null,r=h),null!==e&&(e=function(){try{kn.uri=new Fn(kn.scheme,kn.user,kn.host,kn.port,kn.uri_params,kn.uri_headers),delete kn.scheme,delete kn.user,delete kn.host,delete kn.host_type,delete kn.port,delete kn.uri_params,"SIP_URI"===n&&(kn=kn.uri)}catch(e){kn=-1}}()),null===e&&(r=c),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,n,s;return n=r,"sips"===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"sips"')),null!==e&&(s=e,e=void(kn.scheme=s.toLowerCase())),null===e&&(r=n),e}function te(){var e,n,s;return n=r,"sip"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"sip"')),null!==e&&(s=e,e=void(kn.scheme=s.toLowerCase())),null===e&&(r=n),e}function ne(){var e,n,s,i,o,a,u;return i=r,o=r,null!==(e=se())?(a=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=ie())?n=[n,s]:(n=null,r=a),null!==(n=null!==n?n:"")?(64===t.charCodeAt(r)?(s="@",r++):(s=null,l('"@"')),null!==s?e=[e,n,s]:(e=null,r=o)):(e=null,r=o)):(e=null,r=o),null!==e&&(u=i,e=void(kn.user=decodeURIComponent(t.substring(r-1,u)))),null===e&&(r=i),e}function se(){var e,t;if(null===(t=E())&&null===(t=A())&&(t=re()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=E())&&null===(t=A())&&(t=re());else e=null;return e}function re(){var e;return 38===t.charCodeAt(r)?(e="&",r++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(r)?(e="=",r++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(r)?(e=",",r++):(e=null,l('","')),null===e&&(59===t.charCodeAt(r)?(e=";",r++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null===e&&(47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"'))))))))),e}function ie(){var e,n,s,i;for(s=r,e=[],null===(n=E())&&null===(n=A())&&(38===t.charCodeAt(r)?(n="&",r++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(r)?(n="$",r++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(r)?(n=",",r++):(n=null,l('","')))))));null!==n;)e.push(n),null===(n=E())&&null===(n=A())&&(38===t.charCodeAt(r)?(n="&",r++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(r)?(n="$",r++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(r)?(n=",",r++):(n=null,l('","')))))));return null!==e&&(i=s,e=void(kn.password=t.substring(r,i))),null===e&&(r=s),e}function oe(){var e,n,s,i,o;return i=r,null!==(e=le())?(o=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=ge())?n=[n,s]:(n=null,r=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=i)):(e=null,r=i),e}function le(){var e,n,s;return n=r,null===(e=ae())&&null===(e=fe())&&(e=he()),null!==e&&(s=n,kn.host=t.substring(r,s).toLowerCase(),e=kn.host),null===e&&(r=n),e}function ae(){var e,n,s,i,o,a,u;for(i=r,o=r,e=[],a=r,null!==(n=ue())?(46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')),null!==s?n=[n,s]:(n=null,r=a)):(n=null,r=a);null!==n;)e.push(n),a=r,null!==(n=ue())?(46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')),null!==s?n=[n,s]:(n=null,r=a)):(n=null,r=a);return null!==e&&null!==(n=ce())?(46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')),null!==(s=null!==s?s:"")?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(u=i,kn.host_type="domain",e=t.substring(r,u)),null===e&&(r=i),e}function ue(){var e,n,s,i;if(i=r,null!==(e=g())){for(n=[],null===(s=g())&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(95===t.charCodeAt(r)?(s="_",r++):(s=null,l('"_"'))));null!==s;)n.push(s),null===(s=g())&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(95===t.charCodeAt(r)?(s="_",r++):(s=null,l('"_"'))));null!==n?e=[e,n]:(e=null,r=i)}else e=null,r=i;return e}function ce(){var e,n,s,i;if(i=r,null!==(e=c())){for(n=[],null===(s=g())&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(95===t.charCodeAt(r)?(s="_",r++):(s=null,l('"_"'))));null!==s;)n.push(s),null===(s=g())&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(95===t.charCodeAt(r)?(s="_",r++):(s=null,l('"_"'))));null!==n?e=[e,n]:(e=null,r=i)}else e=null,r=i;return e}function he(){var e,n,s,i,o,a;return i=r,o=r,91===t.charCodeAt(r)?(e="[",r++):(e=null,l('"["')),null!==e&&null!==(n=de())?(93===t.charCodeAt(r)?(s="]",r++):(s=null,l('"]"')),null!==s?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(a=i,kn.host_type="IPv6",e=t.substring(r,a)),null===e&&(r=i),e}function de(){var e,n,s,i,o,a,u,c,h,d,_,p,f,m,g,T,E;return m=r,g=r,null!==(e=_e())?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?(58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?(58===t.charCodeAt(r)?(a=":",r++):(a=null,l('":"')),null!==a&&null!==(u=_e())?(58===t.charCodeAt(r)?(c=":",r++):(c=null,l('":"')),null!==c&&null!==(h=_e())?(58===t.charCodeAt(r)?(d=":",r++):(d=null,l('":"')),null!==d&&null!==(_=_e())?(58===t.charCodeAt(r)?(p=":",r++):(p=null,l('":"')),null!==p&&null!==(f=pe())?e=[e,n,s,i,o,a,u,c,h,d,_,p,f]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?(58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?(58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=_e())?(58===t.charCodeAt(r)?(h=":",r++):(h=null,l('":"')),null!==h&&null!==(d=_e())?(58===t.charCodeAt(r)?(_=":",r++):(_=null,l('":"')),null!==_&&null!==(p=pe())?e=[e,n,s,i,o,a,u,c,h,d,_,p]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?(58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?(58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=_e())?(58===t.charCodeAt(r)?(h=":",r++):(h=null,l('":"')),null!==h&&null!==(d=pe())?e=[e,n,s,i,o,a,u,c,h,d]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?(58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?(58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=pe())?e=[e,n,s,i,o,a,u,c]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?(58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=pe())?e=[e,n,s,i,o,a]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?(58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=pe())?e=[e,n,s,i]:(e=null,r=g)):(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=pe())?e=[e,n]:(e=null,r=g),null===e&&(g=r,"::"===t.substr(r,2)?(e="::",r+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?e=[e,n]:(e=null,r=g),null===e&&(g=r,null!==(e=_e())?("::"===t.substr(r,2)?(n="::",r+=2):(n=null,l('"::"')),null!==n&&null!==(s=_e())?(58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?(58===t.charCodeAt(r)?(a=":",r++):(a=null,l('":"')),null!==a&&null!==(u=_e())?(58===t.charCodeAt(r)?(c=":",r++):(c=null,l('":"')),null!==c&&null!==(h=_e())?(58===t.charCodeAt(r)?(d=":",r++):(d=null,l('":"')),null!==d&&null!==(_=pe())?e=[e,n,s,i,o,a,u,c,h,d,_]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?("::"===t.substr(r,2)?(s="::",r+=2):(s=null,l('"::"')),null!==s&&null!==(i=_e())?(58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?(58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=_e())?(58===t.charCodeAt(r)?(h=":",r++):(h=null,l('":"')),null!==h&&null!==(d=pe())?e=[e,n,s,i,o,a,u,c,h,d]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?(T=r,58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?s=[s,i]:(s=null,r=T),null!==(s=null!==s?s:"")?("::"===t.substr(r,2)?(i="::",r+=2):(i=null,l('"::"')),null!==i&&null!==(o=_e())?(58===t.charCodeAt(r)?(a=":",r++):(a=null,l('":"')),null!==a&&null!==(u=_e())?(58===t.charCodeAt(r)?(c=":",r++):(c=null,l('":"')),null!==c&&null!==(h=pe())?e=[e,n,s,i,o,a,u,c,h]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?(T=r,58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?s=[s,i]:(s=null,r=T),null!==(s=null!==s?s:"")?(T=r,58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?i=[i,o]:(i=null,r=T),null!==(i=null!==i?i:"")?("::"===t.substr(r,2)?(o="::",r+=2):(o=null,l('"::"')),null!==o&&null!==(a=_e())?(58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=pe())?e=[e,n,s,i,o,a,u,c]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?(T=r,58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?s=[s,i]:(s=null,r=T),null!==(s=null!==s?s:"")?(T=r,58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?i=[i,o]:(i=null,r=T),null!==(i=null!==i?i:"")?(T=r,58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?o=[o,a]:(o=null,r=T),null!==(o=null!==o?o:"")?("::"===t.substr(r,2)?(a="::",r+=2):(a=null,l('"::"')),null!==a&&null!==(u=pe())?e=[e,n,s,i,o,a,u]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?(T=r,58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?s=[s,i]:(s=null,r=T),null!==(s=null!==s?s:"")?(T=r,58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?i=[i,o]:(i=null,r=T),null!==(i=null!==i?i:"")?(T=r,58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?o=[o,a]:(o=null,r=T),null!==(o=null!==o?o:"")?(T=r,58===t.charCodeAt(r)?(a=":",r++):(a=null,l('":"')),null!==a&&null!==(u=_e())?a=[a,u]:(a=null,r=T),null!==(a=null!==a?a:"")?("::"===t.substr(r,2)?(u="::",r+=2):(u=null,l('"::"')),null!==u&&null!==(c=_e())?e=[e,n,s,i,o,a,u,c]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g),null===e&&(g=r,null!==(e=_e())?(T=r,58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?n=[n,s]:(n=null,r=T),null!==(n=null!==n?n:"")?(T=r,58===t.charCodeAt(r)?(s=":",r++):(s=null,l('":"')),null!==s&&null!==(i=_e())?s=[s,i]:(s=null,r=T),null!==(s=null!==s?s:"")?(T=r,58===t.charCodeAt(r)?(i=":",r++):(i=null,l('":"')),null!==i&&null!==(o=_e())?i=[i,o]:(i=null,r=T),null!==(i=null!==i?i:"")?(T=r,58===t.charCodeAt(r)?(o=":",r++):(o=null,l('":"')),null!==o&&null!==(a=_e())?o=[o,a]:(o=null,r=T),null!==(o=null!==o?o:"")?(T=r,58===t.charCodeAt(r)?(a=":",r++):(a=null,l('":"')),null!==a&&null!==(u=_e())?a=[a,u]:(a=null,r=T),null!==(a=null!==a?a:"")?(T=r,58===t.charCodeAt(r)?(u=":",r++):(u=null,l('":"')),null!==u&&null!==(c=_e())?u=[u,c]:(u=null,r=T),null!==(u=null!==u?u:"")?("::"===t.substr(r,2)?(c="::",r+=2):(c=null,l('"::"')),null!==c?e=[e,n,s,i,o,a,u,c]:(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g)):(e=null,r=g))))))))))))))),null!==e&&(E=m,kn.host_type="IPv6",e=t.substring(r,E)),null===e&&(r=m),e}function _e(){var e,t,n,s,i;return i=r,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,s]:(e=null,r=i),e}function pe(){var e,n,s,i;return i=r,null!==(e=_e())?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n&&null!==(s=_e())?e=[e,n,s]:(e=null,r=i)):(e=null,r=i),null===e&&(e=fe()),e}function fe(){var e,n,s,i,o,a,u,c,h,d;return c=r,h=r,null!==(e=me())?(46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null!==n&&null!==(s=me())?(46===t.charCodeAt(r)?(i=".",r++):(i=null,l('"."')),null!==i&&null!==(o=me())?(46===t.charCodeAt(r)?(a=".",r++):(a=null,l('"."')),null!==a&&null!==(u=me())?e=[e,n,s,i,o,a,u]:(e=null,r=h)):(e=null,r=h)):(e=null,r=h)):(e=null,r=h),null!==e&&(d=c,kn.host_type="IPv4",e=t.substring(r,d)),null===e&&(r=c),e}function me(){var e,n,s,i;return i=r,"25"===t.substr(r,2)?(e="25",r+=2):(e=null,l('"25"')),null!==e?(/^[0-5]/.test(t.charAt(r))?(n=t.charAt(r),r++):(n=null,l("[0-5]")),null!==n?e=[e,n]:(e=null,r=i)):(e=null,r=i),null===e&&(i=r,50===t.charCodeAt(r)?(e="2",r++):(e=null,l('"2"')),null!==e?(/^[0-4]/.test(t.charAt(r))?(n=t.charAt(r),r++):(n=null,l("[0-4]")),null!==n&&null!==(s=u())?e=[e,n,s]:(e=null,r=i)):(e=null,r=i),null===e&&(i=r,49===t.charCodeAt(r)?(e="1",r++):(e=null,l('"1"')),null!==e&&null!==(n=u())&&null!==(s=u())?e=[e,n,s]:(e=null,r=i),null===e&&(i=r,/^[1-9]/.test(t.charAt(r))?(e=t.charAt(r),r++):(e=null,l("[1-9]")),null!==e&&null!==(n=u())?e=[e,n]:(e=null,r=i),null===e&&(e=u())))),e}function ge(){var e,t,n,s,i,o,l,a;return o=r,l=r,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(s=null!==(s=u())?s:"")&&null!==(i=null!==(i=u())?i:"")?e=[e,t,n,s,i]:(e=null,r=l),null!==e&&(a=e,a=parseInt(a.join("")),kn.port=a,e=a),null===e&&(r=o),e}function Te(){var e,n,s,i;for(e=[],i=r,59===t.charCodeAt(r)?(n=";",r++):(n=null,l('";"')),null!==n&&null!==(s=Ee())?n=[n,s]:(n=null,r=i);null!==n;)e.push(n),i=r,59===t.charCodeAt(r)?(n=";",r++):(n=null,l('";"')),null!==n&&null!==(s=Ee())?n=[n,s]:(n=null,r=i);return e}function Ee(){var e;return null===(e=Se())&&null===(e=Ce())&&null===(e=Ae())&&null===(e=ve())&&null===(e=Re())&&null===(e=Ie())&&(e=be()),e}function Se(){var e,n,s,i,o;return s=r,i=r,"transport="===t.substr(r,10).toLowerCase()?(e=t.substr(r,10),r+=10):(e=null,l('"transport="')),null!==e?("udp"===t.substr(r,3).toLowerCase()?(n=t.substr(r,3),r+=3):(n=null,l('"udp"')),null===n&&("tcp"===t.substr(r,3).toLowerCase()?(n=t.substr(r,3),r+=3):(n=null,l('"tcp"')),null===n&&("sctp"===t.substr(r,4).toLowerCase()?(n=t.substr(r,4),r+=4):(n=null,l('"sctp"')),null===n&&("tls"===t.substr(r,3).toLowerCase()?(n=t.substr(r,3),r+=3):(n=null,l('"tls"')),null===n&&(n=D())))),null!==n?e=[e,n]:(e=null,r=i)):(e=null,r=i),null!==e&&(o=e[1],kn.uri_params||(kn.uri_params={}),e=void(kn.uri_params.transport=o.toLowerCase())),null===e&&(r=s),e}function Ce(){var e,n,s,i,o;return s=r,i=r,"user="===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"user="')),null!==e?("phone"===t.substr(r,5).toLowerCase()?(n=t.substr(r,5),r+=5):(n=null,l('"phone"')),null===n&&("ip"===t.substr(r,2).toLowerCase()?(n=t.substr(r,2),r+=2):(n=null,l('"ip"')),null===n&&(n=D())),null!==n?e=[e,n]:(e=null,r=i)):(e=null,r=i),null!==e&&(o=e[1],kn.uri_params||(kn.uri_params={}),e=void(kn.uri_params.user=o.toLowerCase())),null===e&&(r=s),e}function Ae(){var e,n,s,i,o;return s=r,i=r,"method="===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"method="')),null!==e&&null!==(n=ct())?e=[e,n]:(e=null,r=i),null!==e&&(o=e[1],kn.uri_params||(kn.uri_params={}),e=void(kn.uri_params.method=o)),null===e&&(r=s),e}function ve(){var e,n,s,i,o;return s=r,i=r,"ttl="===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"ttl="')),null!==e&&null!==(n=In())?e=[e,n]:(e=null,r=i),null!==e&&(o=e[1],kn.params||(kn.params={}),e=void(kn.params.ttl=o)),null===e&&(r=s),e}function Re(){var e,n,s,i,o;return s=r,i=r,"maddr="===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"maddr="')),null!==e&&null!==(n=le())?e=[e,n]:(e=null,r=i),null!==e&&(o=e[1],kn.uri_params||(kn.uri_params={}),e=void(kn.uri_params.maddr=o)),null===e&&(r=s),e}function Ie(){var e,n,s,i,o,a;return i=r,o=r,"lr"===t.substr(r,2).toLowerCase()?(e=t.substr(r,2),r+=2):(e=null,l('"lr"')),null!==e?(a=r,61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null!==n&&null!==(s=D())?n=[n,s]:(n=null,r=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=o)):(e=null,r=o),null!==e&&(kn.uri_params||(kn.uri_params={}),e=void(kn.uri_params.lr=void 0)),null===e&&(r=i),e}function be(){var e,n,s,i,o,a,u,c;return i=r,o=r,null!==(e=we())?(a=r,61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null!==n&&null!==(s=ye())?n=[n,s]:(n=null,r=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=o)):(e=null,r=o),null!==e&&(u=e[0],c=e[1],kn.uri_params||(kn.uri_params={}),c=void 0===c?void 0:c[1],e=void(kn.uri_params[u.toLowerCase()]=c)),null===e&&(r=i),e}function we(){var e,t,n;if(n=r,null!==(t=Ne()))for(e=[];null!==t;)e.push(t),t=Ne();else e=null;return null!==e&&(e=e.join("")),null===e&&(r=n),e}function ye(){var e,t,n;if(n=r,null!==(t=Ne()))for(e=[];null!==t;)e.push(t),t=Ne();else e=null;return null!==e&&(e=e.join("")),null===e&&(r=n),e}function Ne(){var e;return null===(e=Oe())&&null===(e=E())&&(e=A()),e}function Oe(){var e;return 91===t.charCodeAt(r)?(e="[",r++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(r)?(e="]",r++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"')),null===e&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(38===t.charCodeAt(r)?(e="&",r++):(e=null,l('"&"')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')))))))),e}function De(){var e,n,s,i,o,a,u;if(a=r,63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null!==e)if(null!==(n=Ue())){for(s=[],u=r,38===t.charCodeAt(r)?(i="&",r++):(i=null,l('"&"')),null!==i&&null!==(o=Ue())?i=[i,o]:(i=null,r=u);null!==i;)s.push(i),u=r,38===t.charCodeAt(r)?(i="&",r++):(i=null,l('"&"')),null!==i&&null!==(o=Ue())?i=[i,o]:(i=null,r=u);null!==s?e=[e,n,s]:(e=null,r=a)}else e=null,r=a;else e=null,r=a;return e}function Ue(){var e,n,s,i,o,a,u;return i=r,o=r,null!==(e=xe())?(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null!==n&&null!==(s=Me())?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(a=e[0],u=e[2],a=a.join("").toLowerCase(),u=u.join(""),kn.uri_headers||(kn.uri_headers={}),e=void(kn.uri_headers[a]?kn.uri_headers[a].push(u):kn.uri_headers[a]=[u])),null===e&&(r=i),e}function xe(){var e,t;if(null===(t=Pe())&&null===(t=E())&&(t=A()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=E())&&(t=A());else e=null;return e}function Me(){var e,t;for(e=[],null===(t=Pe())&&null===(t=E())&&(t=A());null!==t;)e.push(t),null===(t=Pe())&&null===(t=E())&&(t=A());return e}function Pe(){var e;return 91===t.charCodeAt(r)?(e="[",r++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(r)?(e="]",r++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')))))))),e}function qe(){var e,t,n,s,i,o;return o=r,null!==(e=ct())&&null!==(t=f())&&null!==(n=$e())&&null!==(s=f())&&null!==(i=et())?e=[e,t,n,s,i]:(e=null,r=o),e}function $e(){var e;return null===(e=J())&&(e=He()),e}function He(){var e,n,s,i;return i=r,null!==(e=Ke())?(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null!==n?(null===(s=Fe())&&(s=Ge()),null!==s?e=[e,n,s]:(e=null,r=i)):(e=null,r=i)):(e=null,r=i),e}function Fe(){var e,n,s,i,o;return i=r,null===(e=Le())&&(e=ke()),null!==e?(o=r,63===t.charCodeAt(r)?(n="?",r++):(n=null,l('"?"')),null!==n&&null!==(s=Ze())?n=[n,s]:(n=null,r=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=i)):(e=null,r=i),e}function Le(){var e,n,s,i;return i=r,"//"===t.substr(r,2)?(e="//",r+=2):(e=null,l('"//"')),null!==e&&null!==(n=Xe())&&null!==(s=null!==(s=ke())?s:"")?e=[e,n,s]:(e=null,r=i),e}function ke(){var e,n,s;return s=r,47===t.charCodeAt(r)?(e="/",r++):(e=null,l('"/"')),null!==e&&null!==(n=Ve())?e=[e,n]:(e=null,r=s),e}function Ge(){var e,t,n,s;if(s=r,null!==(e=Be())){for(t=[],n=je();null!==n;)t.push(n),n=je();null!==t?e=[e,t]:(e=null,r=s)}else e=null,r=s;return e}function je(){var e;return null===(e=T())&&null===(e=E())&&(e=A()),e}function Be(){var e;return null===(e=E())&&null===(e=A())&&(59===t.charCodeAt(r)?(e=";",r++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(r)?(e="?",r++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(r)?(e="@",r++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(r)?(e="&",r++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(r)?(e="=",r++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(r)?(e=",",r++):(e=null,l('","'))))))))))),e}function Ve(){var e,n,s,i,o,a;if(o=r,null!==(e=We())){for(n=[],a=r,47===t.charCodeAt(r)?(s="/",r++):(s=null,l('"/"')),null!==s&&null!==(i=We())?s=[s,i]:(s=null,r=a);null!==s;)n.push(s),a=r,47===t.charCodeAt(r)?(s="/",r++):(s=null,l('"/"')),null!==s&&null!==(i=We())?s=[s,i]:(s=null,r=a);null!==n?e=[e,n]:(e=null,r=o)}else e=null,r=o;return e}function We(){var e,n,s,i,o,a;for(o=r,e=[],n=ze();null!==n;)e.push(n),n=ze();if(null!==e){for(n=[],a=r,59===t.charCodeAt(r)?(s=";",r++):(s=null,l('";"')),null!==s&&null!==(i=Ye())?s=[s,i]:(s=null,r=a);null!==s;)n.push(s),a=r,59===t.charCodeAt(r)?(s=";",r++):(s=null,l('";"')),null!==s&&null!==(i=Ye())?s=[s,i]:(s=null,r=a);null!==n?e=[e,n]:(e=null,r=o)}else e=null,r=o;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=E())&&null===(e=A())&&(58===t.charCodeAt(r)?(e=":",r++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(r)?(e="@",r++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(r)?(e="&",r++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(r)?(e="=",r++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(r)?(e="+",r++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(r)?(e="$",r++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(r)?(e=",",r++):(e=null,l('","'))))))))),e}function Ke(){var e,n,s,i,o,a;if(i=r,o=r,null!==(e=c())){for(n=[],null===(s=c())&&null===(s=u())&&(43===t.charCodeAt(r)?(s="+",r++):(s=null,l('"+"')),null===s&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')))));null!==s;)n.push(s),null===(s=c())&&null===(s=u())&&(43===t.charCodeAt(r)?(s="+",r++):(s=null,l('"+"')),null===s&&(45===t.charCodeAt(r)?(s="-",r++):(s=null,l('"-"')),null===s&&(46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')))));null!==n?e=[e,n]:(e=null,r=o)}else e=null,r=o;return null!==e&&(a=i,e=void(kn.scheme=t.substring(r,a))),null===e&&(r=i),e}function Xe(){var e;return null===(e=Qe())&&(e=Je()),e}function Qe(){var e,n,s,i;return s=r,i=r,null!==(e=ne())?(64===t.charCodeAt(r)?(n="@",r++):(n=null,l('"@"')),null!==n?e=[e,n]:(e=null,r=i)):(e=null,r=i),null!==(e=null!==e?e:"")&&null!==(n=oe())?e=[e,n]:(e=null,r=s),e=null!==e?e:""}function Je(){var e,n;if(null===(n=E())&&null===(n=A())&&(36===t.charCodeAt(r)?(n="$",r++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(r)?(n=",",r++):(n=null,l('","')),null===n&&(59===t.charCodeAt(r)?(n=";",r++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(r)?(n="@",r++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(r)?(n="&",r++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"')))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=E())&&null===(n=A())&&(36===t.charCodeAt(r)?(n="$",r++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(r)?(n=",",r++):(n=null,l('","')),null===n&&(59===t.charCodeAt(r)?(n=";",r++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(r)?(n=":",r++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(r)?(n="@",r++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(r)?(n="&",r++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(r)?(n="=",r++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(r)?(n="+",r++):(n=null,l('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=je();null!==t;)e.push(t),t=je();return e}function et(){var e,n,s,i,o,a,c,h,d;if(c=r,h=r,"sip"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"SIP"')),null!==e)if(47===t.charCodeAt(r)?(n="/",r++):(n=null,l('"/"')),null!==n){if(null!==(i=u()))for(s=[];null!==i;)s.push(i),i=u();else s=null;if(null!==s)if(46===t.charCodeAt(r)?(i=".",r++):(i=null,l('"."')),null!==i){if(null!==(a=u()))for(o=[];null!==a;)o.push(a),a=u();else o=null;null!==o?e=[e,n,s,i,o]:(e=null,r=h)}else e=null,r=h;else e=null,r=h}else e=null,r=h;else e=null,r=h;return null!==e&&(d=c,e=void(kn.sip_version=t.substring(r,d))),null===e&&(r=c),e}function tt(){var e;return"INVITE"===t.substr(r,6)?(e="INVITE",r+=6):(e=null,l('"INVITE"')),e}function nt(){var e;return"ACK"===t.substr(r,3)?(e="ACK",r+=3):(e=null,l('"ACK"')),e}function st(){var e;return"OPTIONS"===t.substr(r,7)?(e="OPTIONS",r+=7):(e=null,l('"OPTIONS"')),e}function rt(){var e;return"BYE"===t.substr(r,3)?(e="BYE",r+=3):(e=null,l('"BYE"')),e}function it(){var e;return"CANCEL"===t.substr(r,6)?(e="CANCEL",r+=6):(e=null,l('"CANCEL"')),e}function ot(){var e;return"REGISTER"===t.substr(r,8)?(e="REGISTER",r+=8):(e=null,l('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===t.substr(r,9)?(e="SUBSCRIBE",r+=9):(e=null,l('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===t.substr(r,6)?(e="NOTIFY",r+=6):(e=null,l('"NOTIFY"')),e}function ut(){var e;return"REFER"===t.substr(r,5)?(e="REFER",r+=5):(e=null,l('"REFER"')),e}function ct(){var e,n,s;return n=r,null===(e=tt())&&null===(e=nt())&&null===(e=st())&&null===(e=rt())&&null===(e=it())&&null===(e=ot())&&null===(e=lt())&&null===(e=at())&&null===(e=ut())&&(e=D()),null!==e&&(s=n,kn.method=t.substring(r,s),e=kn.method),null===e&&(r=n),e}function ht(){var e,t,n,s,i,o;return o=r,null!==(e=et())&&null!==(t=f())&&null!==(n=dt())&&null!==(s=f())&&null!==(i=pt())?e=[e,t,n,s,i]:(e=null,r=o),e}function dt(){var e,t,n;return t=r,null!==(e=_t())&&(n=e,e=void(kn.status_code=parseInt(n.join("")))),null===e&&(r=t),e}function _t(){var e,t,n,s;return s=r,null!==(e=u())&&null!==(t=u())&&null!==(n=u())?e=[e,t,n]:(e=null,r=s),e}function pt(){var e,n,s,i;for(s=r,e=[],null===(n=T())&&null===(n=E())&&null===(n=A())&&null===(n=N())&&null===(n=O())&&null===(n=f())&&(n=m());null!==n;)e.push(n),null===(n=T())&&null===(n=E())&&null===(n=A())&&null===(n=N())&&null===(n=O())&&null===(n=f())&&(n=m());return null!==e&&(i=s,e=void(kn.reason_phrase=t.substring(r,i))),null===e&&(r=s),e}function ft(){var e,t,n,s,i,o,l;if(i=r,o=r,null===(e=Q())&&(e=mt()),null!==e){for(t=[],l=r,null!==(n=G())&&null!==(s=Tt())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=Tt())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;return null!==e&&(e=function(e){var t;kn.multi_header||(kn.multi_header=[]);try{t=new Ln(kn.uri,kn.display_name,kn.params),delete kn.uri,delete kn.display_name,delete kn.params}catch(n){t=null}kn.multi_header.push({possition:r,offset:e,parsed:t})}(i)),null===e&&(r=i),e}function mt(){var e,t,n,s,i;return i=r,null!==(e=null!==(e=gt())?e:"")&&null!==(t=L())&&null!==(n=J())&&null!==(s=F())?e=[e,t,n,s]:(e=null,r=i),e}function gt(){var e,t,n,s,i,o,l,a;if(i=r,o=r,null!==(e=D())){for(t=[],l=r,null!==(n=R())&&null!==(s=D())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=R())&&null!==(s=D())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;return null===e&&(e=z()),null!==e&&(a=e,e=void(kn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(r=i),e}function Tt(){var e;return null===(e=Et())&&null===(e=St())&&(e=vt()),e}function Et(){var e,n,s,i,o,a;return i=r,o=r,"q"===t.substr(r,1).toLowerCase()?(e=t.substr(r,1),r++):(e=null,l('"q"')),null!==e&&null!==(n=q())&&null!==(s=At())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],kn.params||(kn.params={}),e=void(kn.params.q=a)),null===e&&(r=i),e}function St(){var e,n,s,i,o,a;return i=r,o=r,"expires"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"expires"')),null!==e&&null!==(n=q())&&null!==(s=Ct())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],kn.params||(kn.params={}),e=void(kn.params.expires=a)),null===e&&(r=i),e}function Ct(){var e,t,n;if(n=r,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(r=n),e}function At(){var e,n,s,i,o,a,c,h,d;return a=r,c=r,48===t.charCodeAt(r)?(e="0",r++):(e=null,l('"0"')),null!==e?(h=r,46===t.charCodeAt(r)?(n=".",r++):(n=null,l('"."')),null!==n&&null!==(s=null!==(s=u())?s:"")&&null!==(i=null!==(i=u())?i:"")&&null!==(o=null!==(o=u())?o:"")?n=[n,s,i,o]:(n=null,r=h),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=c)):(e=null,r=c),null!==e&&(d=a,e=parseFloat(t.substring(r,d))),null===e&&(r=a),e}function vt(){var e,t,n,s,i,o,l,a;return s=r,i=r,null!==(e=D())?(o=r,null!==(t=q())&&null!==(n=Rt())?t=[t,n]:(t=null,r=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,r=i)):(e=null,r=i),null!==e&&(l=e[0],a=e[1],kn.params||(kn.params={}),a=void 0===a?void 0:a[1],e=void(kn.params[l.toLowerCase()]=a)),null===e&&(r=s),e}function Rt(){var e;return null===(e=D())&&null===(e=le())&&(e=Y()),e}function It(){var e;return"render"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"render"')),null===e&&("session"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"session"')),null===e&&("icon"===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"icon"')),null===e&&("alert"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"alert"')),null===e&&(e=D())))),e}function bt(){var e;return null===(e=wt())&&(e=vt()),e}function wt(){var e,n,s,i;return i=r,"handling"===t.substr(r,8).toLowerCase()?(e=t.substr(r,8),r+=8):(e=null,l('"handling"')),null!==e&&null!==(n=q())?("optional"===t.substr(r,8).toLowerCase()?(s=t.substr(r,8),r+=8):(s=null,l('"optional"')),null===s&&("required"===t.substr(r,8).toLowerCase()?(s=t.substr(r,8),r+=8):(s=null,l('"required"')),null===s&&(s=D())),null!==s?e=[e,n,s]:(e=null,r=i)):(e=null,r=i),e}function yt(){var e,t,n,s,i,o,l,a;if(l=r,null!==(e=Nt()))if(null!==(t=P()))if(null!==(n=Mt())){for(s=[],a=r,null!==(i=G())&&null!==(o=Pt())?i=[i,o]:(i=null,r=a);null!==i;)s.push(i),a=r,null!==(i=G())&&null!==(o=Pt())?i=[i,o]:(i=null,r=a);null!==s?e=[e,t,n,s]:(e=null,r=l)}else e=null,r=l;else e=null,r=l;else e=null,r=l;return e}function Nt(){var e;return null===(e=Ot())&&(e=Dt()),e}function Ot(){var e;return"text"===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"text"')),null===e&&("image"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"image"')),null===e&&("audio"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"audio"')),null===e&&("video"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"video"')),null===e&&("application"===t.substr(r,11).toLowerCase()?(e=t.substr(r,11),r+=11):(e=null,l('"application"')),null===e&&(e=Ut()))))),e}function Dt(){var e;return"message"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"message"')),null===e&&("multipart"===t.substr(r,9).toLowerCase()?(e=t.substr(r,9),r+=9):(e=null,l('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=D())&&(e=xt()),e}function xt(){var e,n,s;return s=r,"x-"===t.substr(r,2).toLowerCase()?(e=t.substr(r,2),r+=2):(e=null,l('"x-"')),null!==e&&null!==(n=D())?e=[e,n]:(e=null,r=s),e}function Mt(){var e;return null===(e=Ut())&&(e=D()),e}function Pt(){var e,t,n,s;return s=r,null!==(e=D())&&null!==(t=q())&&null!==(n=qt())?e=[e,t,n]:(e=null,r=s),e}function qt(){var e;return null===(e=D())&&(e=Y()),e}function $t(){var e,t,n,s;if(n=r,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(s=e,e=void(kn.value=parseInt(s.join("")))),null===e&&(r=n),e}function Ht(){var e,n,s,i,o,a;if(o=r,null!==(e=U())){for(n=[],a=r,46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')),null!==s&&null!==(i=U())?s=[s,i]:(s=null,r=a);null!==s;)n.push(s),a=r,46===t.charCodeAt(r)?(s=".",r++):(s=null,l('"."')),null!==s&&null!==(i=U())?s=[s,i]:(s=null,r=a);null!==n?e=[e,n]:(e=null,r=o)}else e=null,r=o;return e}function Ft(){var e;return null===(e=Lt())&&(e=vt()),e}function Lt(){var e,n,s,i,o,a;return i=r,o=r,"tag"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"tag"')),null!==e&&null!==(n=q())&&null!==(s=D())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.tag=a)),null===e&&(r=i),e}function kt(){var e,n,s,i,o,a,u,c;if(u=r,"digest"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"Digest"')),null!==e)if(null!==(n=R()))if(null!==(s=Bt())){for(i=[],c=r,null!==(o=k())&&null!==(a=Bt())?o=[o,a]:(o=null,r=c);null!==o;)i.push(o),c=r,null!==(o=k())&&null!==(a=Bt())?o=[o,a]:(o=null,r=c);null!==i?e=[e,n,s,i]:(e=null,r=u)}else e=null,r=u;else e=null,r=u;else e=null,r=u;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,s,i,o,l,a;if(l=r,null!==(e=D()))if(null!==(t=R()))if(null!==(n=jt())){for(s=[],a=r,null!==(i=k())&&null!==(o=jt())?i=[i,o]:(i=null,r=a);null!==i;)s.push(i),a=r,null!==(i=k())&&null!==(o=jt())?i=[i,o]:(i=null,r=a);null!==s?e=[e,t,n,s]:(e=null,r=l)}else e=null,r=l;else e=null,r=l;else e=null,r=l;return e}function jt(){var e,t,n,s;return s=r,null!==(e=D())&&null!==(t=q())?(null===(n=D())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,r=s)):(e=null,r=s),e}function Bt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Kt())&&null===(e=Qt())&&null===(e=Jt())&&null===(e=Zt())&&null===(e=en())&&(e=jt()),e}function Vt(){var e,n,s,i;return i=r,"realm"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"realm"')),null!==e&&null!==(n=q())&&null!==(s=Wt())?e=[e,n,s]:(e=null,r=i),e}function Wt(){var e,t,n;return t=r,null!==(e=z())&&(n=e,e=void(kn.realm=n)),null===e&&(r=t),e}function Yt(){var e,n,s,i,o,a,u,c,h;if(c=r,"domain"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"domain"')),null!==e)if(null!==(n=q()))if(null!==(s=B()))if(null!==(i=zt())){if(o=[],h=r,null!==(u=f()))for(a=[];null!==u;)a.push(u),u=f();else a=null;for(null!==a&&null!==(u=zt())?a=[a,u]:(a=null,r=h);null!==a;){if(o.push(a),h=r,null!==(u=f()))for(a=[];null!==u;)a.push(u),u=f();else a=null;null!==a&&null!==(u=zt())?a=[a,u]:(a=null,r=h)}null!==o&&null!==(a=V())?e=[e,n,s,i,o,a]:(e=null,r=c)}else e=null,r=c;else e=null,r=c;else e=null,r=c;else e=null,r=c;return e}function zt(){var e;return null===(e=He())&&(e=ke()),e}function Kt(){var e,n,s,i;return i=r,"nonce"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"nonce"')),null!==e&&null!==(n=q())&&null!==(s=Xt())?e=[e,n,s]:(e=null,r=i),e}function Xt(){var e,t,n;return t=r,null!==(e=z())&&(n=e,e=void(kn.nonce=n)),null===e&&(r=t),e}function Qt(){var e,n,s,i,o,a;return i=r,o=r,"opaque"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"opaque"')),null!==e&&null!==(n=q())&&null!==(s=z())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.opaque=a)),null===e&&(r=i),e}function Jt(){var e,n,s,i,o;return i=r,"stale"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"stale"')),null!==e&&null!==(n=q())?(o=r,"true"===t.substr(r,4).toLowerCase()?(s=t.substr(r,4),r+=4):(s=null,l('"true"')),null!==s&&(s=void(kn.stale=!0)),null===s&&(r=o),null===s&&(o=r,"false"===t.substr(r,5).toLowerCase()?(s=t.substr(r,5),r+=5):(s=null,l('"false"')),null!==s&&(s=void(kn.stale=!1)),null===s&&(r=o)),null!==s?e=[e,n,s]:(e=null,r=i)):(e=null,r=i),e}function Zt(){var e,n,s,i,o,a;return i=r,o=r,"algorithm"===t.substr(r,9).toLowerCase()?(e=t.substr(r,9),r+=9):(e=null,l('"algorithm"')),null!==e&&null!==(n=q())?("md5"===t.substr(r,3).toLowerCase()?(s=t.substr(r,3),r+=3):(s=null,l('"MD5"')),null===s&&("md5-sess"===t.substr(r,8).toLowerCase()?(s=t.substr(r,8),r+=8):(s=null,l('"MD5-sess"')),null===s&&(s=D())),null!==s?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(a=e[2],e=void(kn.algorithm=a.toUpperCase())),null===e&&(r=i),e}function en(){var e,n,s,i,o,a,u,c,h,d;if(c=r,"qop"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"qop"')),null!==e)if(null!==(n=q()))if(null!==(s=B())){if(h=r,null!==(i=tn())){for(o=[],d=r,44===t.charCodeAt(r)?(a=",",r++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,r=d);null!==a;)o.push(a),d=r,44===t.charCodeAt(r)?(a=",",r++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,r=d);null!==o?i=[i,o]:(i=null,r=h)}else i=null,r=h;null!==i&&null!==(o=V())?e=[e,n,s,i,o]:(e=null,r=c)}else e=null,r=c;else e=null,r=c;else e=null,r=c;return e}function tn(){var e,n,s;return n=r,"auth-int"===t.substr(r,8).toLowerCase()?(e=t.substr(r,8),r+=8):(e=null,l('"auth-int"')),null===e&&("auth"===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"auth"')),null===e&&(e=D())),null!==e&&(s=e,kn.qop||(kn.qop=[]),e=void kn.qop.push(s.toLowerCase())),null===e&&(r=n),e}function nn(){var e,t,n,s,i,o,l;if(i=r,o=r,null!==(e=mt())){for(t=[],l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==n;)t.push(n),l=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=l);null!==t?e=[e,t]:(e=null,r=o)}else e=null,r=o;return null!==e&&(e=function(e){var t;kn.multi_header||(kn.multi_header=[]);try{t=new Ln(kn.uri,kn.display_name,kn.params),delete kn.uri,delete kn.display_name,delete kn.params}catch(n){t=null}kn.multi_header.push({possition:r,offset:e,parsed:t})}(i)),null===e&&(r=i),e}function sn(){var e;return null===(e=rn())&&(e=vt()),e}function rn(){var e,n,s,i,o,a,c;if(o=r,a=r,"cause"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"cause"')),null!==e)if(null!==(n=q())){if(null!==(i=u()))for(s=[];null!==i;)s.push(i),i=u();else s=null;null!==s?e=[e,n,s]:(e=null,r=a)}else e=null,r=a;else e=null,r=a;return null!==e&&(c=e[2],e=void(kn.cause=parseInt(c.join("")))),null===e&&(r=o),e}function on(){var e,t,n,s,i,o;if(i=r,null!==(e=mt())){for(t=[],o=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=o);null!==n;)t.push(n),o=r,null!==(n=G())&&null!==(s=vt())?n=[n,s]:(n=null,r=o);null!==t?e=[e,t]:(e=null,r=i)}else e=null,r=i;return e}function ln(){var e,n,s;return n=r,"active"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"active"')),null===e&&("pending"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"pending"')),null===e&&("terminated"===t.substr(r,10).toLowerCase()?(e=t.substr(r,10),r+=10):(e=null,l('"terminated"')),null===e&&(e=D()))),null!==e&&(s=n,e=void(kn.state=t.substring(r,s))),null===e&&(r=n),e}function an(){var e,n,s,i,o,a,u,c;return i=r,o=r,"reason"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"reason"')),null!==e&&null!==(n=q())&&null!==(s=un())?e=[e,n,s]:(e=null,r=o),null!==e&&(e=void(void 0!==(a=e[2])&&(kn.reason=a))),null===e&&(r=i),null===e&&(i=r,o=r,"expires"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"expires"')),null!==e&&null!==(n=q())&&null!==(s=Ct())?e=[e,n,s]:(e=null,r=o),null!==e&&(e=void(void 0!==(c=e[2])&&(kn.expires=c))),null===e&&(r=i),null===e&&(i=r,o=r,"retry_after"===t.substr(r,11).toLowerCase()?(e=t.substr(r,11),r+=11):(e=null,l('"retry_after"')),null!==e&&null!==(n=q())&&null!==(s=Ct())?e=[e,n,s]:(e=null,r=o),null!==e&&(e=void(void 0!==(u=e[2])&&(kn.retry_after=u))),null===e&&(r=i),null===e&&(e=vt()))),e}function un(){var e;return"deactivated"===t.substr(r,11).toLowerCase()?(e=t.substr(r,11),r+=11):(e=null,l('"deactivated"')),null===e&&("probation"===t.substr(r,9).toLowerCase()?(e=t.substr(r,9),r+=9):(e=null,l('"probation"')),null===e&&("rejected"===t.substr(r,8).toLowerCase()?(e=t.substr(r,8),r+=8):(e=null,l('"rejected"')),null===e&&("timeout"===t.substr(r,7).toLowerCase()?(e=t.substr(r,7),r+=7):(e=null,l('"timeout"')),null===e&&("giveup"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"giveup"')),null===e&&("noresource"===t.substr(r,10).toLowerCase()?(e=t.substr(r,10),r+=10):(e=null,l('"noresource"')),null===e&&("invariant"===t.substr(r,9).toLowerCase()?(e=t.substr(r,9),r+=9):(e=null,l('"invariant"')),null===e&&(e=D()))))))),e}function cn(){var e;return null===(e=Lt())&&(e=vt()),e}function hn(){var e,t,n,s,i,o,l,a;if(l=r,null!==(e=En()))if(null!==(t=R()))if(null!==(n=An())){for(s=[],a=r,null!==(i=G())&&null!==(o=dn())?i=[i,o]:(i=null,r=a);null!==i;)s.push(i),a=r,null!==(i=G())&&null!==(o=dn())?i=[i,o]:(i=null,r=a);null!==s?e=[e,t,n,s]:(e=null,r=l)}else e=null,r=l;else e=null,r=l;else e=null,r=l;return e}function dn(){var e;return null===(e=_n())&&null===(e=pn())&&null===(e=fn())&&null===(e=mn())&&null===(e=gn())&&(e=vt()),e}function _n(){var e,n,s,i,o,a;return i=r,o=r,"ttl"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"ttl"')),null!==e&&null!==(n=q())&&null!==(s=In())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.ttl=a)),null===e&&(r=i),e}function pn(){var e,n,s,i,o,a;return i=r,o=r,"maddr"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"maddr"')),null!==e&&null!==(n=q())&&null!==(s=le())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.maddr=a)),null===e&&(r=i),e}function fn(){var e,n,s,i,o,a;return i=r,o=r,"received"===t.substr(r,8).toLowerCase()?(e=t.substr(r,8),r+=8):(e=null,l('"received"')),null!==e&&null!==(n=q())?(null===(s=fe())&&(s=de()),null!==s?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(a=e[2],e=void(kn.received=a)),null===e&&(r=i),e}function mn(){var e,n,s,i,o,a;return i=r,o=r,"branch"===t.substr(r,6).toLowerCase()?(e=t.substr(r,6),r+=6):(e=null,l('"branch"')),null!==e&&null!==(n=q())&&null!==(s=D())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.branch=a)),null===e&&(r=i),e}function gn(){var e,n,s,i,o;return i=r,"rport"===t.substr(r,5).toLowerCase()?(e=t.substr(r,5),r+=5):(e=null,l('"rport"')),null!==e?(o=r,null!==(n=q())&&null!==(s=Tn())?n=[n,s]:(n=null,r=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=i)):(e=null,r=i),e}function Tn(){var e,t,n,s,i,o,l,a;return o=r,l=r,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(s=null!==(s=u())?s:"")&&null!==(i=null!==(i=u())?i:"")?e=[e,t,n,s,i]:(e=null,r=l),null!==e&&(a=e,e=void(kn.rport=parseInt(a.join("")))),null===e&&(r=o),e}function En(){var e,t,n,s,i,o;return o=r,null!==(e=Sn())&&null!==(t=P())&&null!==(n=D())&&null!==(s=P())&&null!==(i=Cn())?e=[e,t,n,s,i]:(e=null,r=o),e}function Sn(){var e,n,s;return n=r,"sip"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"SIP"')),null===e&&(e=D()),null!==e&&(s=e,e=void(kn.protocol=s)),null===e&&(r=n),e}function Cn(){var e,n,s;return n=r,"udp"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"UDP"')),null===e&&("tcp"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"TCP"')),null===e&&("tls"===t.substr(r,3).toLowerCase()?(e=t.substr(r,3),r+=3):(e=null,l('"TLS"')),null===e&&("sctp"===t.substr(r,4).toLowerCase()?(e=t.substr(r,4),r+=4):(e=null,l('"SCTP"')),null===e&&(e=D())))),null!==e&&(s=e,e=void(kn.transport=s)),null===e&&(r=n),e}function An(){var e,t,n,s,i;return s=r,null!==(e=vn())?(i=r,null!==(t=j())&&null!==(n=Rn())?t=[t,n]:(t=null,r=i),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,r=s)):(e=null,r=s),e}function vn(){var e,n,s;return n=r,null===(e=fe())&&null===(e=he())&&(e=ae()),null!==e&&(s=n,e=void(kn.host=t.substring(r,s))),null===e&&(r=n),e}function Rn(){var e,t,n,s,i,o,l,a;return o=r,l=r,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(s=null!==(s=u())?s:"")&&null!==(i=null!==(i=u())?i:"")?e=[e,t,n,s,i]:(e=null,r=l),null!==e&&(a=e,e=void(kn.port=parseInt(a.join("")))),null===e&&(r=o),e}function In(){var e,t,n,s,i;return s=r,i=r,null!==(e=u())&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")?e=[e,t,n]:(e=null,r=i),null!==e&&(e=parseInt(e.join(""))),null===e&&(r=s),e}function bn(){var e,t,n;return t=r,null!==(e=Ct())&&(n=e,e=void(kn.expires=n)),null===e&&(r=t),e}function wn(){var e;return null===(e=yn())&&(e=vt()),e}function yn(){var e,n,s,i,o,a;return i=r,o=r,"refresher"===t.substr(r,9).toLowerCase()?(e=t.substr(r,9),r+=9):(e=null,l('"refresher"')),null!==e&&null!==(n=q())?("uac"===t.substr(r,3).toLowerCase()?(s=t.substr(r,3),r+=3):(s=null,l('"uac"')),null===s&&("uas"===t.substr(r,3).toLowerCase()?(s=t.substr(r,3),r+=3):(s=null,l('"uas"'))),null!==s?e=[e,n,s]:(e=null,r=o)):(e=null,r=o),null!==e&&(a=e[2],e=void(kn.refresher=a.toLowerCase())),null===e&&(r=i),e}function Nn(){var e,t;for(e=[],null===(t=y())&&null===(t=O())&&(t=R());null!==t;)e.push(t),null===(t=y())&&null===(t=O())&&(t=R());return e}function On(){var e,n,s,i,o,a,u,c,h,d,_,p;return d=r,_=r,null!==(e=Un())?(45===t.charCodeAt(r)?(n="-",r++):(n=null,l('"-"')),null!==n&&null!==(s=Dn())?(45===t.charCodeAt(r)?(i="-",r++):(i=null,l('"-"')),null!==i&&null!==(o=Dn())?(45===t.charCodeAt(r)?(a="-",r++):(a=null,l('"-"')),null!==a&&null!==(u=Dn())?(45===t.charCodeAt(r)?(c="-",r++):(c=null,l('"-"')),null!==c&&null!==(h=xn())?e=[e,n,s,i,o,a,u,c,h]:(e=null,r=_)):(e=null,r=_)):(e=null,r=_)):(e=null,r=_)):(e=null,r=_),null!==e&&(p=d,e[0],e=void(kn=t.substring(r+5,p))),null===e&&(r=d),e}function Dn(){var e,t,n,s,i;return i=r,null!==(e=h())&&null!==(t=h())&&null!==(n=h())&&null!==(s=h())?e=[e,t,n,s]:(e=null,r=i),e}function Un(){var e,t,n;return n=r,null!==(e=Dn())&&null!==(t=Dn())?e=[e,t]:(e=null,r=n),e}function xn(){var e,t,n,s;return s=r,null!==(e=Dn())&&null!==(t=Dn())&&null!==(n=Dn())?e=[e,t,n]:(e=null,r=s),e}function Mn(){var e,n,s,i,o,a,u;return i=r,o=r,null!==(e=x())?(a=r,64===t.charCodeAt(r)?(n="@",r++):(n=null,l('"@"')),null!==n&&null!==(s=x())?n=[n,s]:(n=null,r=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,r=o)):(e=null,r=o),null!==e&&(u=i,e=void(kn.call_id=t.substring(r,u))),null===e&&(r=i),e}function Pn(){var e;return null===(e=qn())&&null===(e=$n())&&null===(e=Hn())&&(e=vt()),e}function qn(){var e,n,s,i,o,a;return i=r,o=r,"to-tag"===t.substr(r,6)?(e="to-tag",r+=6):(e=null,l('"to-tag"')),null!==e&&null!==(n=q())&&null!==(s=D())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.to_tag=a)),null===e&&(r=i),e}function $n(){var e,n,s,i,o,a;return i=r,o=r,"from-tag"===t.substr(r,8)?(e="from-tag",r+=8):(e=null,l('"from-tag"')),null!==e&&null!==(n=q())&&null!==(s=D())?e=[e,n,s]:(e=null,r=o),null!==e&&(a=e[2],e=void(kn.from_tag=a)),null===e&&(r=i),e}function Hn(){var e,n;return n=r,"early-only"===t.substr(r,10)?(e="early-only",r+=10):(e=null,l('"early-only"')),null!==e&&(e=void(kn.early_only=!0)),null===e&&(r=n),e}var Fn=v(),Ln=C(),kn={};if(null===s[n]()||r!==t.length){var Gn=Math.max(r,i),jn=Gn<t.length?t.charAt(Gn):null,Bn=function(){for(var e=1,n=1,s=!1,o=0;o<Math.max(r,i);o++){var l=t.charAt(o);"\n"===l?(s||e++,n=1,s=!1):"\r"===l||"\u2028"===l||"\u2029"===l?(e++,n=1,s=!0):(n++,s=!1)}return{line:e,column:n}}();return new this.SyntaxError(function(e){e.sort();for(var t=null,n=[],s=0;s<e.length;s++)e[s]!==t&&(n.push(e[s]),t=e[s]);return n}(o),jn,Gn,Bn.line,Bn.column),-1}return kn},toSource:function(){return this._source},SyntaxError:function(t,n,s,r,i){this.name="SyntaxError",this.expected=t,this.found=n,this.message=function(t,n){var s;switch(t.length){case 0:s="end of input";break;case 1:s=t[0];break;default:s=t.slice(0,t.length-1).join(", ")+" or "+t[t.length-1]}return"Expected "+s+" but "+(n?e(n):"end of input")+" found."}(t,n),this.offset=s,this.line=r,this.column=i}};return t.SyntaxError.prototype=Error.prototype,t}())}function v(){if(T)return g;T=1;const e=h(),t=R(),n=A();return g=class s{static parse(e){return-1!==(e=n.parse(e,"SIP_URI"))?e:void 0}constructor(t,n,s,r,i={},o={}){if(!s)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=t||e.SIP,this._user=n,this._host=s,this._port=r;for(const e in i)Object.prototype.hasOwnProperty.call(i,e)&&this.setParam(e,i[e]);for(const e in o)Object.prototype.hasOwnProperty.call(o,e)&&this.setHeader(e,o[e])}get scheme(){return this._scheme}set scheme(e){this._scheme=e.toLowerCase()}get user(){return this._user}set user(e){this._user=e}get host(){return this._host}set host(e){this._host=e.toLowerCase()}get port(){return this._port}set port(e){this._port=0===e?e:parseInt(e,10)||null}setParam(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?null:t.toString())}getParam(e){if(e)return this._parameters[e.toLowerCase()]}hasParam(e){if(e)return!!this._parameters.hasOwnProperty(e.toLowerCase())}deleteParam(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){const t=this._parameters[e];return delete this._parameters[e],t}}clearParams(){this._parameters={}}setHeader(e,n){this._headers[t.headerize(e)]=Array.isArray(n)?n:[n]}getHeader(e){if(e)return this._headers[t.headerize(e)]}hasHeader(e){if(e)return!!this._headers.hasOwnProperty(t.headerize(e))}deleteHeader(e){if(e=t.headerize(e),this._headers.hasOwnProperty(e)){const t=this._headers[e];return delete this._headers[e],t}}clearHeaders(){this._headers={}}clone(){return new s(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const e=[];let n=`${this._scheme}:`;this._user&&(n+=`${t.escapeUser(this._user)}@`),n+=this._host,(this._port||0===this._port)&&(n+=`:${this._port}`);for(const t in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(n+=`;${t}`,null!==this._parameters[t]&&(n+=`=${this._parameters[t]}`));for(const t in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,t))for(const n of this._headers[t])e.push(`${t}=${n}`);return e.length>0&&(n+=`?${e.join("&")}`),n}toAor(e){let n=`${this._scheme}:`;return this._user&&(n+=`${t.escapeUser(this._user)}@`),n+=this._host,e&&(this._port||0===this._port)&&(n+=`:${this._port}`),n}}}function R(){if(E)return S;E=1;const e=h(),t=v(),n=A();S.str_utf8_length=e=>unescape(encodeURIComponent(e)).length;const s=S.isFunction=e=>void 0!==e&&"[object Function]"===Object.prototype.toString.call(e);S.isString=e=>void 0!==e&&"[object String]"===Object.prototype.toString.call(e),S.isDecimal=e=>!isNaN(e)&&parseFloat(e)===parseInt(e,10),S.isEmpty=e=>null===e||""===e||void 0===e||Array.isArray(e)&&0===e.length||"number"==typeof e&&isNaN(e),S.hasMethods=function(e,...t){for(const n of t)if(s(e[n]))return!1;return!0};const r=S.createRandomToken=(e,t=32)=>{let n,s,r="";for(n=0;n<e;n++)s=Math.random()*t|0,r+=s.toString(t);return r};S.newTag=()=>r(10),S.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),S.hostType=e=>{if(e)return-1!==(e=n.parse(e,"host"))?e.host_type:void 0};const i=S.escapeUser=e=>encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/");return S.normalizeTarget=(n,s)=>{if(n){if(n instanceof t)return n;if("string"==typeof n){const r=n.split("@");let o,l,a;switch(r.length){case 1:if(!s)return;o=n,l=s;break;case 2:o=r[0],l=r[1];break;default:o=r.slice(0,r.length-1).join("@"),l=r[r.length-1]}return o=o.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(o)&&(o=o.replace(/[-.()]/g,"")),n=`${e.SIP}:${i(o)}@${l}`,(a=t.parse(n))?a:void 0}}else;},S.headerize=e=>{const t={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-");let s="";const r=n.length;let i;for(i=0;i<r;i++)0!==i&&(s+="-"),s+=n[i].charAt(0).toUpperCase()+n[i].substring(1);return t[s]&&(s=t[s]),s},S.sipErrorCause=t=>{for(const n in e.SIP_ERROR_CAUSES)if(-1!==e.SIP_ERROR_CAUSES[n].indexOf(t))return e.causes[n];return e.causes.SIP_FAILURE_CODE},S.getRandomTestNetIP=()=>{return`192.0.2.${e=1,t=254,Math.floor(Math.random()*(t-e+1)+e)}`;var e,t},S.calculateMD5=e=>{function t(e,t){return e<<t|e>>>32-t}function n(e,t){const n=2147483648&e,s=2147483648&t,r=1073741824&e,i=1073741824&t,o=(1073741823&e)+(1073741823&t);return r&i?2147483648^o^n^s:r|i?1073741824&o?3221225472^o^n^s:1073741824^o^n^s:o^n^s}function s(e,s,r,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(s,r,i),o),a)),n(t(e,l),s)}function r(e,s,r,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(s,r,i),o),a)),n(t(e,l),s)}function i(e,s,r,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(s,r,i),o),a)),n(t(e,l),s)}function o(e,s,r,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(s,r,i),o),a)),n(t(e,l),s)}function l(e){let t,n,s="",r="";for(n=0;n<=3;n++)t=e>>>8*n&255,r=`0${t.toString(16)}`,s+=r.substr(r.length-2,2);return s}let a,u,c,h,d,_,p,f,m,g=[];for(g=function(e){let t;const n=e.length,s=n+8,r=16*((s-s%64)/64+1),i=new Array(r-1);let o=0,l=0;for(;l<n;)t=(l-l%4)/4,o=l%4*8,i[t]=i[t]|e.charCodeAt(l)<<o,l++;return t=(l-l%4)/4,o=l%4*8,i[t]=i[t]|128<<o,i[r-2]=n<<3,i[r-1]=n>>>29,i}(e=function(e){let t="";for(let n=0;n<e.length;n++){const s=e.charCodeAt(n);s<128?t+=String.fromCharCode(s):s>127&&s<2048?(t+=String.fromCharCode(s>>6|192),t+=String.fromCharCode(63&s|128)):(t+=String.fromCharCode(s>>12|224),t+=String.fromCharCode(s>>6&63|128),t+=String.fromCharCode(63&s|128))}return t}(e)),_=1732584193,p=4023233417,f=2562383102,m=271733878,a=0;a<g.length;a+=16)u=_,c=p,h=f,d=m,_=s(_,p,f,m,g[a+0],7,3614090360),m=s(m,_,p,f,g[a+1],12,3905402710),f=s(f,m,_,p,g[a+2],17,606105819),p=s(p,f,m,_,g[a+3],22,3250441966),_=s(_,p,f,m,g[a+4],7,4118548399),m=s(m,_,p,f,g[a+5],12,1200080426),f=s(f,m,_,p,g[a+6],17,2821735955),p=s(p,f,m,_,g[a+7],22,4249261313),_=s(_,p,f,m,g[a+8],7,1770035416),m=s(m,_,p,f,g[a+9],12,2336552879),f=s(f,m,_,p,g[a+10],17,4294925233),p=s(p,f,m,_,g[a+11],22,2304563134),_=s(_,p,f,m,g[a+12],7,1804603682),m=s(m,_,p,f,g[a+13],12,4254626195),f=s(f,m,_,p,g[a+14],17,2792965006),p=s(p,f,m,_,g[a+15],22,1236535329),_=r(_,p,f,m,g[a+1],5,4129170786),m=r(m,_,p,f,g[a+6],9,3225465664),f=r(f,m,_,p,g[a+11],14,643717713),p=r(p,f,m,_,g[a+0],20,3921069994),_=r(_,p,f,m,g[a+5],5,3593408605),m=r(m,_,p,f,g[a+10],9,38016083),f=r(f,m,_,p,g[a+15],14,3634488961),p=r(p,f,m,_,g[a+4],20,3889429448),_=r(_,p,f,m,g[a+9],5,568446438),m=r(m,_,p,f,g[a+14],9,3275163606),f=r(f,m,_,p,g[a+3],14,4107603335),p=r(p,f,m,_,g[a+8],20,1163531501),_=r(_,p,f,m,g[a+13],5,2850285829),m=r(m,_,p,f,g[a+2],9,4243563512),f=r(f,m,_,p,g[a+7],14,1735328473),p=r(p,f,m,_,g[a+12],20,2368359562),_=i(_,p,f,m,g[a+5],4,4294588738),m=i(m,_,p,f,g[a+8],11,2272392833),f=i(f,m,_,p,g[a+11],16,1839030562),p=i(p,f,m,_,g[a+14],23,4259657740),_=i(_,p,f,m,g[a+1],4,2763975236),m=i(m,_,p,f,g[a+4],11,1272893353),f=i(f,m,_,p,g[a+7],16,4139469664),p=i(p,f,m,_,g[a+10],23,3200236656),_=i(_,p,f,m,g[a+13],4,681279174),m=i(m,_,p,f,g[a+0],11,3936430074),f=i(f,m,_,p,g[a+3],16,3572445317),p=i(p,f,m,_,g[a+6],23,76029189),_=i(_,p,f,m,g[a+9],4,3654602809),m=i(m,_,p,f,g[a+12],11,3873151461),f=i(f,m,_,p,g[a+15],16,530742520),p=i(p,f,m,_,g[a+2],23,3299628645),_=o(_,p,f,m,g[a+0],6,4096336452),m=o(m,_,p,f,g[a+7],10,1126891415),f=o(f,m,_,p,g[a+14],15,2878612391),p=o(p,f,m,_,g[a+5],21,4237533241),_=o(_,p,f,m,g[a+12],6,1700485571),m=o(m,_,p,f,g[a+3],10,2399980690),f=o(f,m,_,p,g[a+10],15,4293915773),p=o(p,f,m,_,g[a+1],21,2240044497),_=o(_,p,f,m,g[a+8],6,1873313359),m=o(m,_,p,f,g[a+15],10,4264355552),f=o(f,m,_,p,g[a+6],15,2734768916),p=o(p,f,m,_,g[a+13],21,1309151649),_=o(_,p,f,m,g[a+4],6,4149444226),m=o(m,_,p,f,g[a+11],10,3174756917),f=o(f,m,_,p,g[a+2],15,718787259),p=o(p,f,m,_,g[a+9],21,3951481745),_=n(_,u),p=n(p,c),f=n(f,h),m=n(m,d);return(l(_)+l(p)+l(f)+l(m)).toLowerCase()},S.closeMediaStream=e=>{if(e)try{let t;if(e.getTracks){t=e.getTracks();for(const e of t)e.stop()}else{t=e.getAudioTracks();for(const e of t)e.stop();t=e.getVideoTracks();for(const e of t)e.stop()}}catch(t){"function"!=typeof e.stop&&"object"!=typeof e.stop||e.stop()}},S.cloneArray=e=>e&&e.slice()||[],S.cloneObject=(e,t={})=>e&&Object.assign({},e)||t,S}var I,b={exports:{}};function w(){if(I)return b.exports;I=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function r(){r.init.call(this)}b.exports=r,b.exports.once=function(e,t){return new Promise(function(n,s){function r(n){e.removeListener(t,i),s(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",r),n([].slice.call(arguments))}p(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,n)}(e,r,{once:!0})})},r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var i=10;function o(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?r.defaultMaxListeners:e._maxListeners}function a(e,t,n,s){var r,i,a,u;if(o(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),a=i[t]),void 0===a)a=i[t]=n,++e._eventsCount;else if("function"==typeof a?a=i[t]=s?[n,a]:[a,n]:s?a.unshift(n):a.push(n),(r=l(e))>0&&a.length>r&&!a.warned){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,u=c,console&&console.warn&&console.warn(u)}return e}function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function c(e,t,n){var s={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=u.bind(s);return r.listener=n,s.wrapFn=r,r}function h(e,t,n){var s=e._events;if(void 0===s)return[];var r=s[t];return void 0===r?[]:"function"==typeof r?n?[r.listener||r]:[r]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(r):_(r,r.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function _(e,t){for(var n=new Array(t),s=0;s<t;++s)n[s]=e[s];return n}function p(e,t,n,s){if("function"==typeof e.on)s.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function r(i){s.once&&e.removeEventListener(t,r),n(i)})}}return Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");i=e}}),r.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},r.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(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},r.prototype.getMaxListeners=function(){return l(this)},r.prototype.emit=function(e){for(var t=[],s=1;s<arguments.length;s++)t.push(arguments[s]);var r="error"===e,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var l=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw l.context=o,l}var a=i[e];if(void 0===a)return!1;if("function"==typeof a)n(a,this,t);else{var u=a.length,c=_(a,u);for(s=0;s<u;++s)n(c[s],this,t)}return!0},r.prototype.addListener=function(e,t){return a(this,e,t,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(e,t){return a(this,e,t,!0)},r.prototype.once=function(e,t){return o(t),this.on(e,c(this,e,t)),this},r.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,c(this,e,t)),this},r.prototype.removeListener=function(e,t){var n,s,r,i,l;if(o(t),void 0===(s=this._events))return this;if(void 0===(n=s[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(r=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){l=n[i].listener,r=i;break}if(r<0)return this;0===r?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,r),1===n.length&&(s[e]=n[0]),void 0!==s.removeListener&&this.emit("removeListener",e,l||t)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(e){var t,n,s;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var r,i=Object.keys(n);for(s=0;s<i.length;++s)"removeListener"!==(r=i[s])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this},r.prototype.listeners=function(e){return h(this,e,!0)},r.prototype.rawListeners=function(e){return h(this,e,!1)},r.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},r.prototype.listenerCount=d,r.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},b.exports}var y,N,O,D,U,x,M,P={exports:{}};function q(){if(N)return y;N=1;var e=1e3,t=60*e,n=60*t,s=24*n,r=7*s,i=365.25*s;function o(e,t,n,s){var r=t>=1.5*n;return Math.round(e/n)+" "+s+(r?"s":"")}return y=function(l,a){a=a||{};var u=typeof l;if("string"===u&&l.length>0)return function(o){if((o=String(o)).length>100)return;var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!l)return;var a=parseFloat(l[1]);switch((l[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*i;case"weeks":case"week":case"w":return a*r;case"days":case"day":case"d":return a*s;case"hours":case"hour":case"hrs":case"hr":case"h":return a*n;case"minutes":case"minute":case"mins":case"min":case"m":return a*t;case"seconds":case"second":case"secs":case"sec":case"s":return a*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(l);if("number"===u&&isFinite(l))return a.long?function(r){var i=Math.abs(r);if(i>=s)return o(r,i,s,"day");if(i>=n)return o(r,i,n,"hour");if(i>=t)return o(r,i,t,"minute");if(i>=e)return o(r,i,e,"second");return r+" ms"}(l):function(r){var i=Math.abs(r);if(i>=s)return Math.round(r/s)+"d";if(i>=n)return Math.round(r/n)+"h";if(i>=t)return Math.round(r/t)+"m";if(i>=e)return Math.round(r/e)+"s";return r+"ms"}(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))}}function $(){return U||(U=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let s=0,r=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(s++,"%c"===e&&(r=s))}),t.splice(r,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(n){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(n){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!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"],t.log=console.debug||console.log||(()=>{}),e.exports=(D?O:(D=1,O=function(e){function t(e){let s,r,i,o=null;function l(...e){if(!l.enabled)return;const n=l,r=Number(new Date),i=r-(s||r);n.diff=i,n.prev=s,n.curr=r,s=r,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(s,r)=>{if("%%"===s)return"%";o++;const i=t.formatters[r];if("function"==typeof i){const t=e[o];s=i.call(n,t),e.splice(o,1),o--}return s}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return l.namespace=e,l.useColors=t.useColors(),l.color=t.selectColor(e),l.extend=n,l.destroy=t.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(r!==t.namespaces&&(r=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(l),l}function n(e,n){const s=t(this.namespace+(void 0===n?":":n)+e);return s.log=this.log,s}function s(e,t){let n=0,s=0,r=-1,i=0;for(;n<e.length;)if(s<t.length&&(t[s]===e[n]||"*"===t[s]))"*"===t[s]?(r=s,i=n,s++):(n++,s++);else{if(-1===r)return!1;s=r+1,i++,n=i}for(;s<t.length&&"*"===t[s];)s++;return s===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const s of n)"-"===s[0]?t.skips.push(s.slice(1)):t.names.push(s)},t.enabled=function(e){for(const n of t.skips)if(s(e,n))return!1;for(const n of t.names)if(s(e,n))return!0;return!1},t.humanize=q(),t.destroy=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`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}))(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}(P,P.exports)),P.exports}function H(){if(M)return x;M=1;const e=$(),t="JsSIP";return x=class{constructor(n){n?(this._debug=e.default(`${t}:${n}`),this._warn=e.default(`${t}:WARN:${n}`),this._error=e.default(`${t}:ERROR:${n}`)):(this._debug=e.default(t),this._warn=e.default(`${t}:WARN`),this._error=e.default(`${t}: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}}}var F,L,k,G,j,B,V,W,Y,z,K,X,Q,J,Z,ee,te,ne,se,re,ie,oe={},le={},ae={exports:{}};function ue(){if(F)return ae.exports;F=1;var e=ae.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(e){return e.encoding?"rtpmap:%d %s/%s/%s":e.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(e){return null!=e.address?"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(e){return null!=e.subtype?"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(e){return"extmap:%d"+(e.direction?"/%s":"%v")+(e["encrypt-uri"]?" %s":"%v")+" %s"+(e.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(e){return null!=e.sessionConfig?"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(e){var t="candidate:%s %d %s %d %s %d typ %s";return t+=null!=e.raddr?" raddr %s rport %d":"%v%v",t+=null!=e.tcptype?" tcptype %s":"%v",null!=e.generation&&(t+=" generation %d"),t+=null!=e["network-id"]?" network-id %d":"%v",t+=null!=e["network-cost"]?" network-cost %d":"%v"}},{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(e){var t="ssrc:%d";return null!=e.attribute&&(t+=" %s",null!=e.value&&(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(e){return null!=e.maxMessageSize?"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(e){return e.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(e){return"imageattr:%s %s %s"+(e.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(e){return"simulcast:%s %s"+(e.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(e){return"ts-refclk:%s"+(null!=e.clksrcExt?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(e){var t="mediaclk:";return t+=null!=e.id?"id=%s %s":"%v%s",t+=null!=e.mediaClockValue?"=%s":"",t+=null!=e.rateNumerator?" rate=%s":"",t+=null!=e.rateDenominator?"/%s":""}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};return Object.keys(e).forEach(function(t){e[t].forEach(function(e){e.reg||(e.reg=/(.*)/),e.format||(e.format="%s")})}),ae.exports}function ce(){return L||(L=1,function(e){var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,s){var r=e.name&&e.names;e.push&&!n[e.push]?n[e.push]=[]:r&&!n[e.name]&&(n[e.name]={});var i=e.push?{}:r?n[e.name]:n;!function(e,n,s,r){if(r&&!s)n[r]=t(e[1]);else for(var i=0;i<s.length;i+=1)null!=e[i+1]&&(n[s[i]]=t(e[i+1]))}(s.match(e.reg),i,e.names,e.name),e.push&&n[e.push].push(i)},s=ue(),r=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},i=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(r).forEach(function(e){var t=e[0],r=e.slice(2);"m"===t&&(i.push({rtp:[],fmtp:[]}),o=i[i.length-1]);for(var l=0;l<(s[t]||[]).length;l+=1){var a=s[t][l];if(a.reg.test(r))return n(a,o,r)}}),t.media=i,t};var i=function(e,n){var s=n.split(/=(.+)/,2);return 2===s.length?e[s[0]]=t(s[1]):1===s.length&&n.length>1&&(e[s[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(i,{})},e.parseFmtpConfig=e.parseParams,e.parsePayloads=function(e){return e.toString().split(" ").map(Number)},e.parseRemoteCandidates=function(e){for(var n=[],s=e.split(" ").map(t),r=0;r<s.length;r+=3)n.push({component:s[r],ip:s[r+1],port:s[r+2]});return n},e.parseImageAttributes=function(e){return e.split(" ").map(function(e){return e.substring(1,e.length-1).split(",").reduce(i,{})})},e.parseSimulcastStreamList=function(e){return e.split(";").map(function(e){return e.split(",").map(function(e){var n,s=!1;return"~"!==e[0]?n=t(e):(n=t(e.substring(1,e.length)),s=!0),{scid:n,paused:s}})})}}(le)),le}function he(){if(G)return k;G=1;var e=ue(),t=/%[sdv%]/g,n=function(e){var n=1,s=arguments,r=s.length;return e.replace(t,function(e){if(n>=r)return e;var t=s[n];switch(n+=1,e){case"%%":return"%";case"%s":return String(t);case"%d":return Number(t);case"%v":return""}})},s=function(e,t,s){var r=[e+"="+(t.format instanceof Function?t.format(t.push?s:s[t.name]):t.format)];if(t.names)for(var i=0;i<t.names.length;i+=1){var o=t.names[i];t.name?r.push(s[t.name][o]):r.push(s[t.names[i]])}else r.push(s[t.name]);return n.apply(null,r)},r=["v","o","s","i","u","e","p","c","b","t","r","z","a"],i=["i","c","b","a"];return k=function(t,n){n=n||{},null==t.version&&(t.version=0),null==t.name&&(t.name=" "),t.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var o=n.outerOrder||r,l=n.innerOrder||i,a=[];return o.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(s(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(s(n,e,t))})})}),t.media.forEach(function(t){a.push(s("m",e.m[0],t)),l.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(s(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(s(n,e,t))})})})}),a.join("\r\n")+"\r\n"}}function de(){if(j)return oe;j=1;var e=ce(),t=he(),n=ue();return oe.grammar=n,oe.write=t,oe.parse=e.parse,oe.parseParams=e.parseParams,oe.parseFmtpConfig=e.parseFmtpConfig,oe.parsePayloads=e.parsePayloads,oe.parseRemoteCandidates=e.parseRemoteCandidates,oe.parseImageAttributes=e.parseImageAttributes,oe.parseSimulcastStreamList=e.parseSimulcastStreamList,oe}function _e(){if(V)return B;V=1;const e=de(),t=H(),n=h(),s=R(),r=C(),i=A(),o=new t("SIPMessage");class l{constructor(e,t,i,o,l,a){if(!e||!t||!i)return null;o=o||{},this.ua=i,this.headers={},this.method=e,this.ruri=t,this.body=a,this.extraHeaders=s.cloneArray(l),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):i.configuration.use_preloaded_route&&this.setHeader("route",`<${i.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",n.MAX_FORWARDS);const u=o.to_uri||t,c=o.to_tag?{tag:o.to_tag}:null,h=void 0!==o.to_display_name?o.to_display_name:null;this.to=new r(u,h,c),this.setHeader("to",this.to.toString());const d=o.from_uri||i.configuration.uri,_={tag:o.from_tag||s.newTag()};let p;p=void 0!==o.from_display_name?o.from_display_name:i.configuration.display_name?i.configuration.display_name:null,this.from=new r(d,p,_),this.setHeader("from",this.from.toString());const f=o.call_id||i.configuration.jssip_id+s.createRandomToken(15);this.call_id=f,this.setHeader("call-id",f);const m=o.cseq||Math.floor(1e4*Math.random());this.cseq=m,this.setHeader("cseq",`${m} ${e}`)}setHeader(e,t){const n=new RegExp(`^\\s*${e}\\s*:`,"i");for(let s=0;s<this.extraHeaders.length;s++)n.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[s.headerize(e)]=Array.isArray(t)?t:[t]}getHeader(e){const t=this.headers[s.headerize(e)];if(t){if(t[0])return t[0]}else{const t=new RegExp(`^\\s*${e}\\s*:`,"i");for(const e of this.extraHeaders)if(t.test(e))return e.substring(e.indexOf(":")+1).trim()}}getHeaders(e){const t=this.headers[s.headerize(e)],n=[];if(t){for(const e of t)n.push(e);return n}{const t=new RegExp(`^\\s*${e}\\s*:`,"i");for(const e of this.extraHeaders)t.test(e)&&n.push(e.substring(e.indexOf(":")+1).trim());return n}}hasHeader(e){if(this.headers[s.headerize(e)])return!0;{const t=new RegExp(`^\\s*${e}\\s*:`,"i");for(const e of this.extraHeaders)if(t.test(e))return!0}return!1}parseSDP(t){return!t&&this.sdp||(this.sdp=e.parse(this.body||"")),this.sdp}toString(){let e=`${this.method} ${this.ruri} SIP/2.0\r\n`;for(const n in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,n))for(const t of this.headers[n])e+=`${n}: ${t}\r\n`;for(const n of this.extraHeaders)e+=`${n.trim()}\r\n`;const t=[];switch(this.method){case n.REGISTER:t.push("path","gruu");break;case n.INVITE:this.ua.configuration.session_timers&&t.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&t.push("gruu"),t.push("ice","replaces");break;case n.UPDATE:this.ua.configuration.session_timers&&t.push("timer"),t.push("ice")}t.push("outbound");const r=this.ua.configuration.user_agent||n.USER_AGENT;if(e+=`Allow: ${n.ALLOWED_METHODS}\r\n`,e+=`Supported: ${t}\r\n`,e+=`User-Agent: ${r}\r\n`,this.body){e+=`Content-Length: ${s.str_utf8_length(this.body)}\r\n\r\n`,e+=this.body}else e+="Content-Length: 0\r\n\r\n";return e}clone(){const e=new l(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=s.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e}}class a extends l{constructor(e,t,s,r,i){super(n.INVITE,e,t,s,r,i),this.transaction=null}cancel(e){this.transaction.cancel(e)}clone(){const e=new a(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=s.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e.transaction=this.transaction,e}}class u{constructor(){this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}addHeader(e,t){const n={raw:t};e=s.headerize(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}getHeader(e){const t=this.headers[s.headerize(e)];if(t)return t[0]?t[0].raw:void 0}getHeaders(e){const t=this.headers[s.headerize(e)],n=[];if(!t)return[];for(const s of t)n.push(s.raw);return n}hasHeader(e){return!!this.headers[s.headerize(e)]}parseHeader(e,t=0){if(e=s.headerize(e),!this.headers[e])return void o.debug(`header "${e}" not present`);if(t>=this.headers[e].length)return void o.debug(`not so many "${e}" headers present`);const n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;const l=i.parse(r,e.replace(/-/g,"_"));return-1===l?(this.headers[e].splice(t,1),void o.debug(`error parsing "${e}" header field with value "${r}"`)):(n.parsed=l,l)}s(e,t){return this.parseHeader(e,t)}setHeader(e,t){const n={raw:t};this.headers[s.headerize(e)]=[n]}parseSDP(t){return!t&&this.sdp||(this.sdp=e.parse(this.body||"")),this.sdp}toString(){return this.data}}return B={OutgoingRequest:l,InitialOutgoingInviteRequest:a,IncomingRequest:class extends u{constructor(e){super(),this.ua=e,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(e,t,r,i,o,l){const a=[];let u=this.getHeader("To");if(t=t||null,!(e=e||null)||e<100||e>699)throw new TypeError(`Invalid status_code: ${e}`);if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError(`Invalid reason_phrase: ${t}`);t=t||n.REASON_PHRASE[e]||"",r=s.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));let c=`SIP/2.0 ${e} ${t}\r\n`;if(this.method===n.INVITE&&e>100&&e<=200){const e=this.getHeaders("record-route");for(const t of e)c+=`Record-Route: ${t}\r\n`}const h=this.getHeaders("via");for(const n of h)c+=`Via: ${n}\r\n`;!this.to_tag&&e>100?u+=`;tag=${s.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(u+=`;tag=${this.to_tag}`),c+=`To: ${u}\r\n`,c+=`From: ${this.getHeader("From")}\r\n`,c+=`Call-ID: ${this.call_id}\r\n`,c+=`CSeq: ${this.cseq} ${this.method}\r\n`;for(const n of r)c+=`${n.trim()}\r\n`;switch(this.method){case n.INVITE:this.ua.configuration.session_timers&&a.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&a.push("gruu"),a.push("ice","replaces");break;case n.UPDATE:this.ua.configuration.session_timers&&a.push("timer"),i&&a.push("ice"),a.push("replaces")}if(a.push("outbound"),this.method===n.OPTIONS?(c+=`Allow: ${n.ALLOWED_METHODS}\r\n`,c+=`Accept: ${n.ACCEPTED_BODY_TYPES}\r\n`):405===e?c+=`Allow: ${n.ALLOWED_METHODS}\r\n`:415===e&&(c+=`Accept: ${n.ACCEPTED_BODY_TYPES}\r\n`),c+=`Supported: ${a}\r\n`,i){c+="Content-Type: application/sdp\r\n",c+=`Content-Length: ${s.str_utf8_length(i)}\r\n\r\n`,c+=i}else c+="Content-Length: 0\r\n\r\n";this.server_transaction.receiveResponse(e,c,o,l)}reply_sl(e=null,t=null){const r=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError(`Invalid status_code: ${e}`);if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError(`Invalid reason_phrase: ${t}`);let i=`SIP/2.0 ${e} ${t=t||n.REASON_PHRASE[e]||""}\r\n`;for(const n of r)i+=`Via: ${n}\r\n`;let o=this.getHeader("To");if(!this.to_tag&&e>100?o+=`;tag=${s.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(o+=`;tag=${this.to_tag}`),i+=`To: ${o}\r\n`,i+=`From: ${this.getHeader("From")}\r\n`,i+=`Call-ID: ${this.call_id}\r\n`,i+=`CSeq: ${this.cseq} ${this.method}\r\n`,this.ua.configuration.extra_headers)for(const n of this.ua.configuration.extra_headers)i+=`${n.trim()}\r\n`;i+="Content-Length: 0\r\n\r\n",this.transport.send(i)}},IncomingResponse:class extends u{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}}}function pe(){if(K)return z;K=1;const e=500;return z={T1:e,T2:4e3,T4:5e3,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4}}function fe(){if(Q)return X;Q=1;const e=w().EventEmitter,t=H(),n=h(),s=_e(),r=pe(),i=new t("NonInviteClientTransaction"),o=new t("InviteClientTransaction"),l=new t("AckClientTransaction"),a=new t("NonInviteServerTransaction"),u=new t("InviteServerTransaction"),c={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"};return X={C:c,NonInviteClientTransaction:class extends e{constructor(e,t,n,s){super(),this.type=c.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(1e7*Math.random())}`,this.ua=e,this.transport=t,this.request=n,this.eventHandlers=s;let r=`SIP/2.0/${t.via_transport}`;r+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",r),this.ua.newTransaction(this)}get C(){return c}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(c.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},r.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){i.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){i.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(e){const t=e.status_code;if(t<200)switch(this.state){case c.STATUS_TRYING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e)}else switch(this.state){case c.STATUS_TRYING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_COMPLETED),clearTimeout(this.F),408===t?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(()=>{this.timer_K()},r.TIMER_K)}}},InviteClientTransaction:class extends e{constructor(e,t,n,s){super(),this.type=c.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(1e7*Math.random())}`,this.ua=e,this.transport=t,this.request=n,this.eventHandlers=s,n.transaction=this;let r=`SIP/2.0/${t.via_transport}`;r+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",r),this.ua.newTransaction(this)}get C(){return c}stateChanged(e){this.state=e,this.emit("stateChanged")}send(){this.stateChanged(c.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},r.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==c.STATUS_ACCEPTED&&(o.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){o.debug(`Timer M expired for transaction ${this.id}`),this.state===c.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){o.debug(`Timer B expired for transaction ${this.id}`),this.state===c.STATUS_CALLING&&(this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){o.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(e){const t=new s.OutgoingRequest(n.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()},r.TIMER_D),this.transport.send(t)}cancel(e){if(this.state!==c.STATUS_PROCEEDING)return;const t=new s.OutgoingRequest(n.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 c.STATUS_CALLING:this.stateChanged(c.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case c.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(t>=200&&t<=299)switch(this.state){case c.STATUS_CALLING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},r.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case c.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(t>=300&&t<=699)switch(this.state){case c.STATUS_CALLING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case c.STATUS_COMPLETED:this.sendACK(e)}}},AckClientTransaction:class extends e{constructor(e,t,n,s){super(),this.id=`z9hG4bK${Math.floor(1e7*Math.random())}`,this.transport=t,this.request=n,this.eventHandlers=s;let r=`SIP/2.0/${t.via_transport}`;r+=` ${e.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",r)}get C(){return c}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){l.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}},NonInviteServerTransaction:class extends e{constructor(e,t,n){super(),this.type=c.NON_INVITE_SERVER,this.id=n.via_branch,this.ua=e,this.transport=t,this.request=n,this.last_response="",n.server_transaction=this,this.state=c.STATUS_TRYING,e.newTransaction(this)}get C(){return c}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_J(){a.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,a.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(e,t,n,s){if(100===e)switch(this.state){case c.STATUS_TRYING:this.stateChanged(c.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case c.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?n&&n():(this.onTransportError(),s&&s())}else if(e>=200&&e<=699)switch(this.state){case c.STATUS_TRYING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(()=>{this.timer_J()},r.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),s&&s())}}},InviteServerTransaction:class extends e{constructor(e,t,n){super(),this.type=c.INVITE_SERVER,this.id=n.via_branch,this.ua=e,this.transport=t,this.request=n,this.last_response="",n.server_transaction=this,this.state=c.STATUS_PROCEEDING,e.newTransaction(this),this.resendProvisionalTimer=null,n.reply(100)}get C(){return c}stateChanged(e){this.state=e,this.emit("stateChanged")}timer_H(){u.debug(`Timer H expired for transaction ${this.id}`),this.state===c.STATUS_COMPLETED&&u.debug("ACK not received, dialog will be terminated"),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){u.debug(`Timer L expired for transaction ${this.id}`),this.state===c.STATUS_ACCEPTED&&(this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,u.debug(`transport error occurred, deleting transaction ${this.id}`),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(c.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(e,t,n,s){if(e>=100&&e<=199&&this.state===c.STATUS_PROCEEDING)this.transport.send(t)||this.onTransportError(),this.last_response=t;if(e>100&&e<=199&&this.state===c.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},r.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(()=>{this.timer_L()},r.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case c.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),s&&s())}else if(e>=300&&e<=699&&this.state===c.STATUS_PROCEEDING)null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(c.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},r.TIMER_H),n&&n()):(this.onTransportError(),s&&s())}},checkTransaction:function({_transactions:e},t){let s;switch(t.method){case n.INVITE:if(s=e.ist[t.via_branch],s){if(s.state===c.STATUS_PROCEEDING)s.transport.send(s.last_response);return!0}break;case n.ACK:if(s=e.ist[t.via_branch],!s)return!1;if(s.state===c.STATUS_ACCEPTED)return!1;if(s.state===c.STATUS_COMPLETED)return s.state=c.STATUS_CONFIRMED,s.I=setTimeout(()=>{s.timer_I()},r.TIMER_I),!0;break;case n.CANCEL:return s=e.ist[t.via_branch],s?(t.reply_sl(200),s.state!==c.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(s=e.nist[t.via_branch],s){switch(s.state){case c.STATUS_TRYING:break;case c.STATUS_PROCEEDING:case c.STATUS_COMPLETED:s.transport.send(s.last_response)}return!0}}}}}function me(){if(Z)return J;Z=1;const e=H(),t=h(),n=function(){if(Y)return W;Y=1;const e=H(),t=R(),n=new e("DigestAuthentication");return W=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:return void n.warn('get() | cannot get "%s" parameter',e)}}authenticate({method:e,ruri:s,body:r},i,o=null){if(this._algorithm=i.algorithm,this._realm=i.realm,this._nonce=i.nonce,this._opaque=i.opaque,this._stale=i.stale,this._algorithm){if("MD5"!==this._algorithm)return n.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return n.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return n.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return n.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return n.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(i.qop)if(i.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(i.qop.indexOf("auth")>-1))return n.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=e,this._uri=s,this._cnonce=o||t.createRandomToken(12),this._nc+=1;const l=Number(this._nc).toString(16);let a,u;return this._ncHex="00000000".substr(0,8-l.length)+l,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=t.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1,"auth"===this._qop?(a=`${this._method}:${this._uri}`,u=t.calculateMD5(a),n.debug('authenticate() | using qop=auth [a2:"%s"]',a),this._response=t.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${u}`)):"auth-int"===this._qop?(a=`${this._method}:${this._uri}:${t.calculateMD5(r||"")}`,u=t.calculateMD5(a),n.debug('authenticate() | using qop=auth-int [a2:"%s"]',a),this._response=t.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${u}`)):null===this._qop&&(a=`${this._method}:${this._uri}`,u=t.calculateMD5(a),n.debug('authenticate() | using qop=null [a2:"%s"]',a),this._response=t.calculateMD5(`${this._ha1}:${this._nonce}:${u}`)),n.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(", ")}`}}}(),s=fe(),r=new e("RequestSender"),i={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};return J=class{constructor(e,n,s){this._ua=e,this._eventHandlers=s,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const t in i)Object.prototype.hasOwnProperty.call(i,t)&&(this._eventHandlers[t]||(this._eventHandlers[t]=i[t]));e.status!==e.C.STATUS_USER_CLOSED||this._method===t.BYE&&this._method===t.ACK||this._eventHandlers.onTransportError()}send(){const e={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:e=>{this._receiveResponse(e)}};switch(this._method){case"INVITE":this.clientTransaction=new s.InviteClientTransaction(this._ua,this._ua.transport,this._request,e);break;case"ACK":this.clientTransaction=new s.AckClientTransaction(this._ua,this._ua.transport,this._request,e);break;default:this.clientTransaction=new s.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,s;const i=e.status_code;if(401!==i&&407!==i||null===this._ua.configuration.password&&null===this._ua.configuration.ha1)this._eventHandlers.onReceiveResponse(e);else{if(401===e.status_code?(t=e.parseHeader("www-authenticate"),s="authorization"):(t=e.parseHeader("proxy-authenticate"),s="proxy-authorization"),!t)return r.debug(`${e.status_code} with wrong or missing challenge, cannot authenticate`),void this._eventHandlers.onReceiveResponse(e);if(!this._challenged||!this._staled&&!0===t.stale){if(this._auth||(this._auth=new n({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))return void this._eventHandlers.onReceiveResponse(e);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(s,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}}}}function ge(){if(ie)return re;ie=1;const e=H(),t=_e(),n=h(),s=fe(),r=function(){if(se)return ne;se=1;const e=h(),t=fe(),n=me(),s={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};return ne=class{constructor(e,t,n){this._dialog=e,this._ua=e._ua,this._request=t,this._eventHandlers=n,this._reattempt=!1,this._reattemptTimer=null;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&(this._eventHandlers[r]||(this._eventHandlers[r]=s[r]))}get request(){return this._request}send(){const s=new n(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:e=>{this._eventHandlers.onAuthenticated(e)},onReceiveResponse:e=>{this._receiveResponse(e)}});if(s.send(),(this._request.method===e.INVITE||this._request.method===e.UPDATE&&this._request.body)&&s.clientTransaction.state!==t.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const e=()=>{s.clientTransaction.state!==t.C.STATUS_ACCEPTED&&s.clientTransaction.state!==t.C.STATUS_COMPLETED&&s.clientTransaction.state!==t.C.STATUS_TERMINATED||(s.clientTransaction.removeListener("stateChanged",e),this._dialog.uac_pending_reply=!1)};s.clientTransaction.on("stateChanged",e)}}_receiveResponse(t){408===t.status_code||481===t.status_code?this._eventHandlers.onDialogError(t):t.method===e.INVITE&&491===t.status_code?this._reattempt?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)}}}(),i=R(),o=new e("Dialog"),l={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};return re=class{static get C(){return l}constructor(e,n,s,r=l.STATUS_CONFIRMED){if(this._owner=e,this._ua=e._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 t.IncomingResponse&&(r=n.status_code<200?l.STATUS_EARLY:l.STATUS_CONFIRMED);const i=n.parseHeader("contact");"UAS"===s?(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=r,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=i.uri,this._route_set=n.getHeaders("record-route"),this.incoming_ack_seqnum=n.cseq,this.outgoing_ack_seqnum=null):"UAC"===s&&(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=r,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this.incoming_ack_seqnum=null,this.outgoing_ack_seqnum=this._local_seqnum),this._ua.newDialog(this),o.debug(`new ${s} dialog created with status ${this._state===l.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===l.STATUS_TERMINATED}update(e,t){this._state=l.STATUS_CONFIRMED,o.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}terminate(){o.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=l.STATUS_TERMINATED}sendRequest(e,t={}){const s=i.cloneArray(t.extraHeaders),o=i.cloneObject(t.eventHandlers),l=t.body||null,a=this._createRequest(e,s,l),u=o.onAuthenticated||(()=>{});o.onAuthenticated=e=>{this._local_seqnum+=1,a.method===n.INVITE&&(this._outgoing_ack_seqnum=this._local_seqnum),u(e)};return new r(this,a,o).send(),a}receiveRequest(e){this._checkInDialogRequest(e)&&(e.method===n.ACK&&null!==this.incoming_ack_seqnum?this.incoming_ack_seqnum=null:e.method===n.INVITE&&(this.incoming_ack_seqnum=e.cseq),this._owner.receiveRequest(e))}_createRequest(e,s,r){s=i.cloneArray(s),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));const o=e===n.CANCEL||e===n.ACK?this.outgoing_ack_seqnum:this._local_seqnum+=1;e===n.INVITE&&(this.outgoing_ack_seqnum=o);return new t.OutgoingRequest(e,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},s,r)}_checkInDialogRequest(e){if(this._remote_seqnum)if(e.cseq<this._remote_seqnum){if(e.method!==n.ACK)return e.reply(500),!1;if(null===this.incoming_ack_seqnum||e.cseq!==this.incoming_ack_seqnum)return!1}else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===n.INVITE||e.method===n.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){const t=1+(10*Math.random()|0);return e.reply(500,null,[`Retry-After:${t}`]),!1}{this._uas_pending_reply=!0;const t=()=>{e.server_transaction.state!==s.C.STATUS_ACCEPTED&&e.server_transaction.state!==s.C.STATUS_COMPLETED&&e.server_transaction.state!==s.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===s.C.STATUS_ACCEPTED&&(this._remote_target=e.parseHeader("contact").uri)})}else e.method===n.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",()=>{e.server_transaction.state===s.C.STATUS_COMPLETED&&(this._remote_target=e.parseHeader("contact").uri)});return!0}}}var Te,Ee,Se,Ce,Ae,ve,Re,Ie,be,we,ye,Ne,Oe,De,Ue,xe,Me,Pe={exports:{}};function qe(){if(be)return Ie;be=1;const e=w().EventEmitter,t=de(),n=H(),s=h(),r=d(),i=fe(),o=R(),l=pe(),a=_e(),u=ge(),c=me(),_=function(){if(Te)return Pe.exports;Te=1;const e=w().EventEmitter,t=H(),n=h(),s=d(),r=R(),i=new t("RTCSession:DTMF"),o={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};return Pe.exports=class extends e{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(void 0===e)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&&this._session.status!==this._session.C.STATUS_1XX_RECEIVED)throw new s.InvalidStateError(this._session.status);const i=r.cloneArray(t.extraHeaders);if(this.eventHandlers=r.cloneObject(t.eventHandlers),"string"==typeof e)e=e.toUpperCase();else{if("number"!=typeof e)throw new TypeError(`Invalid tone: ${e}`);e=e.toString()}if(!e.match(/^[0-9A-DR#*]$/))throw new TypeError(`Invalid tone: ${e}`);this._tone=e,this._duration=t.duration,i.push("Content-Type: application/dtmf-relay");let o=`Signal=${this._tone}\r\n`;o+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(n.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:e=>{this.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:e=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:e})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:o})}init_incoming(e){const t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=e,e.reply(200),e.body){const s=e.body.split("\n");s.length>=1&&t.test(s[0])&&(this._tone=s[0].replace(t,"$2")),s.length>=2&&n.test(s[1])&&(this._duration=parseInt(s[1].replace(n,"$2"),10))}this._duration||(this._duration=o.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):i.debug("invalid INFO DTMF received, discarded")}},Pe.exports.C=o,Pe.exports}(),p=function(){if(Se)return Ee;Se=1;const e=w().EventEmitter,t=h(),n=d(),s=R();return Ee=class extends e{constructor(e){super(),this._session=e,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(e,r,i={}){if(this._direction="outgoing",void 0===e)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 n.InvalidStateError(this._session.status);this._contentType=e,this._body=r;const o=s.cloneArray(i.extraHeaders);o.push(`Content-Type: ${e}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(t.INFO,{extraHeaders:o,eventHandlers:{onSuccessResponse:e=>{this.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:e=>{this.emit("failed",{originator:"remote",response:e})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:r})}init_incoming(e){this._direction="incoming",this.request=e,e.reply(200),this._contentType=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,this._body=e.body,this._session.newInfo({originator:"remote",info:this,request:e})}}}(),f=function(){if(Ae)return Ce;Ae=1;const e=H(),t=h(),n=new e("RTCSession:ReferNotifier"),s="refer",r="message/sipfrag;version=2.0",i=300;return Ce=class{constructor(e,t,n){this._session=e,this._id=t,this._expires=n||i,this._active=!0,this.notify(100)}notify(e,i){if(n.debug("notify()"),!1===this._active)return;let o;i=i||t.REASON_PHRASE[e]||"",o=e>=200?"terminated;reason=noresource":`active;expires=${this._expires}`,this._session.sendRequest(t.NOTIFY,{extraHeaders:[`Event: ${s};id=${this._id}`,`Subscription-State: ${o}`,`Content-Type: ${r}`],body:`SIP/2.0 ${e} ${i}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}}}(),m=function(){if(Re)return ve;Re=1;const e=w().EventEmitter,t=H(),n=h(),s=A(),r=R(),i=new t("RTCSession:ReferSubscriber");return ve=class extends e{constructor(e){super(),this._id=null,this._session=e}get id(){return this._id}sendRefer(e,t={}){i.debug("sendRefer()");const s=r.cloneArray(t.extraHeaders),o=r.cloneObject(t.eventHandlers);for(const n in o)Object.prototype.hasOwnProperty.call(o,n)&&this.on(n,o[n]);let l=null;t.replaces&&(l=t.replaces._request.call_id,l+=`;to-tag=${t.replaces._to_tag}`,l+=`;from-tag=${t.replaces._from_tag}`,l=encodeURIComponent(l));const a=`Refer-To: <${e}${l?`?Replaces=${l}`:""}>`;if(s.push(a),!s.some(e=>e.toLowerCase().startsWith("referred-by:"))){const e=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;s.push(e)}s.push(`Contact: ${this._session.contact}`);const u=this._session.sendRequest(n.REFER,{extraHeaders:s,eventHandlers:{onSuccessResponse:e=>{this._requestSucceeded(e)},onErrorResponse:e=>{this._requestFailed(e,n.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,n.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,n.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,n.causes.DIALOG_ERROR)},onAuthenticated:e=>{this._id=e.cseq,this.emit("authenticated")}}});this._id=u.cseq}receiveNotify(e){if(i.debug("receiveNotify()"),!e.body)return;const t=s.parse(e.body.trim().split("\r\n",1)[0],"Status_Line");if(-1!==t)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})}else i.debug(`receiveNotify() | error parsing NOTIFY body: "${e.body}"`)}_requestSucceeded(e){i.debug("REFER succeeded"),i.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}_requestFailed(e,t){i.debug("REFER failed"),i.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}}}(),g=v(),T=new n("RTCSession"),E={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},S=["audio","video"];return Ie=class n extends e{static get C(){return E}constructor(e){T.debug("new"),super(),this._id=null,this._ua=e,this._status=E.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:s.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return E}get causes(){return s.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 E.STATUS_NULL:case E.STATUS_INVITE_SENT:case E.STATUS_1XX_RECEIVED:case E.STATUS_INVITE_RECEIVED:case E.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case E.STATUS_ANSWERED:case E.STATUS_WAITING_FOR_ACK:case E.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case E.STATUS_CANCELED:case E.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={},n){T.debug("connect()");const i=e,l=o.cloneObject(t.eventHandlers),u=o.cloneArray(t.extraHeaders),c=o.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),h=t.mediaStream||null,d=o.cloneObject(t.pcConfig,{iceServers:[]}),_=t.rtcConstraints||null,p=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=p,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==E.STATUS_NULL)throw new r.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new r.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError(`Invalid target: ${i}`);this._sessionTimers.enabled&&o.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=s.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=s.SESSION_EXPIRES);for(const s in l)Object.prototype.hasOwnProperty.call(l,s)&&this.on(s,l[s]);this._from_tag=o.newTag();const f=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:f,outbound:!0}),f?(m.from_display_name="Anonymous",m.from_uri=new g("sip","anonymous","anonymous.invalid"),u.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),u.push("Privacy: id")):t.fromUserName&&(m.from_uri=new g("sip",t.fromUserName,this._ua.configuration.uri.host),u.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),u.push(`Contact: ${this._contact}`),u.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&u.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new a.InitialOutgoingInviteRequest(e,this._ua,m,u),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(d,_),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(c,p,h)}init_incoming(e,t){let n;T.debug("init_incoming()");const r=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==r?e.reply(415):(this._status=E.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")&&(n=1e3*e.getHeader("expires")),e.to_tag=o.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=E.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{e.reply(408),this._failed("local",null,s.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(()=>{this._status===E.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),this._failed("system",null,s.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==E.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}answer(e={}){T.debug("answer()");const t=this._request,n=o.cloneArray(e.extraHeaders),i=o.cloneObject(e.mediaConstraints),l=e.mediaStream||null,a=o.cloneObject(e.pcConfig,{iceServers:[]}),u=e.rtcConstraints||null,c=e.rtcAnswerConstraints||null,h=o.cloneObject(e.rtcOfferConstraints);let d,_=!1,p=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=c,this._rtcOfferConstraints=e.rtcOfferConstraints||null,this._data=e.data||this._data,"incoming"!==this._direction)throw new r.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==E.STATUS_WAITING_FOR_ANSWER)throw new r.InvalidStateError(this._status);if(this._sessionTimers.enabled&&o.isDecimal(e.sessionTimersExpires)&&(e.sessionTimersExpires>=s.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=e.sessionTimersExpires:this._sessionTimers.defaultExpires=s.SESSION_EXPIRES),this._status=E.STATUS_ANSWERED,!this._createDialog(t,"UAS"))return void t.reply(500,"Error creating dialog");clearTimeout(this._timers.userNoAnswerTimer),n.unshift(`Contact: ${this._contact}`);const g=t.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);for(const s of g.media)"audio"===s.type&&(_=!0,s.direction&&"sendrecv"!==s.direction||(f=!0)),"video"===s.type&&(p=!0,s.direction&&"sendrecv"!==s.direction||(m=!0));if(l&&!1===i.audio){d=l.getAudioTracks();for(const e of d)l.removeTrack(e)}if(l&&!1===i.video){d=l.getVideoTracks();for(const e of d)l.removeTrack(e)}l||void 0!==i.audio||(i.audio=f),l||void 0!==i.video||(i.video=m),l||_||h.offerToReceiveAudio||(i.audio=!1),l||p||h.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(a,u),Promise.resolve().then(()=>l||(i.audio||i.video?(this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(e=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");throw t.reply(480),this._failed("local",null,s.causes.USER_DENIED_MEDIA_ACCESS),T.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),new Error("getUserMedia() failed")})):void 0)).then(e=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=e,e&&e.getTracks().forEach(t=>{this._connection.addTrack(t,e)})}).then(()=>{if(this._late_sdp)return;const e={originator:"remote",type:"offer",sdp:t.body};T.debug('emit "sdp"'),this.emit("sdp",e);const n=new RTCSessionDescription({type:"offer",sdp:e.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(n)).catch(e=>{throw t.reply(488),this._failed("system",null,s.causes.WEBRTC_ERROR),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===E.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",c).catch(()=>{throw t.reply(500),new Error("_createLocalDescription() failed")})}).then(e=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(t,n),t.reply(200,null,n,e,()=>{this._status=E.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,e),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,s.causes.CONNECTION_ERROR)})}).catch(e=>{this._status!==E.STATUS_TERMINATED&&(T.warn(`answer() failed: ${e.message}`),this._failed("system",e.message,s.causes.INTERNAL_ERROR))})}terminate(e={}){T.debug("terminate()");const t=e.cause||s.causes.BYE,n=o.cloneArray(e.extraHeaders),l=e.body;let a,u=e.status_code,c=e.reason_phrase;if(this._status===E.STATUS_TERMINATED)throw new r.InvalidStateError(this._status);switch(this._status){case E.STATUS_NULL:case E.STATUS_INVITE_SENT:case E.STATUS_1XX_RECEIVED:if(T.debug("canceling session"),u&&(u<200||u>=700))throw new TypeError(`Invalid status_code: ${u}`);u&&(c=c||s.REASON_PHRASE[u]||"",a=`SIP ;cause=${u} ;text="${c}"`),this._status===E.STATUS_NULL||this._status===E.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=a):this._status===E.STATUS_1XX_RECEIVED&&this._request.cancel(a),this._status=E.STATUS_CANCELED,this._failed("local",null,s.causes.CANCELED);break;case E.STATUS_WAITING_FOR_ANSWER:case E.STATUS_ANSWERED:if(T.debug("rejecting session"),u=u||480,u<300||u>=700)throw new TypeError(`Invalid status_code: ${u}`);this._request.reply(u,c,n,l),this._failed("local",null,s.causes.REJECTED);break;case E.STATUS_WAITING_FOR_ACK:case E.STATUS_CONFIRMED:if(T.debug("terminating session"),c=e.reason_phrase||s.REASON_PHRASE[u]||"",u&&(u<200||u>=700))throw new TypeError(`Invalid status_code: ${u}`);if(u&&n.push(`Reason: SIP ;cause=${u}; text="${c}"`),this._status===E.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==i.C.STATUS_TERMINATED){const e=this._dialog;this.receiveRequest=({method:t})=>{t===s.ACK&&(this.sendRequest(s.BYE,{extraHeaders:n,body:l}),e.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===i.C.STATUS_TERMINATED&&(this.sendRequest(s.BYE,{extraHeaders:n,body:l}),e.terminate())}),this._ended("local",null,t),this._dialog=e,this._ua.newDialog(e)}else this.sendRequest(s.BYE,{extraHeaders:n,body:l}),this._ended("local",null,t)}}sendDTMF(e,t={}){T.debug("sendDTMF() | tones: %s",e);let n=t.duration||null,i=t.interToneGap||null;const l=t.transportType||s.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==E.STATUS_CONFIRMED&&this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_1XX_RECEIVED)throw new r.InvalidStateError(this._status);if(l!==s.DTMF_TRANSPORT.INFO&&l!==s.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${l}`);if("number"==typeof e&&(e=e.toString()),!e||"string"!=typeof e||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${e}`);if(n&&!o.isDecimal(n))throw new TypeError(`Invalid tone duration: ${n}`);if(n?n<_.C.MIN_DURATION?(T.debug(`"duration" value is lower than the minimum allowed, setting it to ${_.C.MIN_DURATION} milliseconds`),n=_.C.MIN_DURATION):n>_.C.MAX_DURATION?(T.debug(`"duration" value is greater than the maximum allowed, setting it to ${_.C.MAX_DURATION} milliseconds`),n=_.C.MAX_DURATION):n=Math.abs(n):n=_.C.DEFAULT_DURATION,t.duration=n,i&&!o.isDecimal(i))throw new TypeError(`Invalid interToneGap: ${i}`);if(i?i<_.C.MIN_INTER_TONE_GAP?(T.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${_.C.MIN_INTER_TONE_GAP} milliseconds`),i=_.C.MIN_INTER_TONE_GAP):i=Math.abs(i):i=_.C.DEFAULT_INTER_TONE_GAP,l===s.DTMF_TRANSPORT.RFC2833){const t=this._getDTMFRTPSender();return void(t&&(e=t.toneBuffer+e,t.insertDTMF(e,n,i)))}this._tones?this._tones+=e:(this._tones=e,function e(){let s;if(this._status===E.STATUS_TERMINATED||!this._tones)return void(this._tones=null);const r=this._tones[0];if(this._tones=this._tones.substring(1),","===r)s=2e3;else{const e=new _(this);t.eventHandlers={onFailed:()=>{this._tones=null}},e.send(r,t),s=n+i}setTimeout(e.bind(this),s)}.call(this))}sendInfo(e,t,n={}){if(T.debug("sendInfo()"),this._status!==E.STATUS_CONFIRMED&&this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_1XX_RECEIVED)throw new r.InvalidStateError(this._status);new p(this).send(e,t,n)}mute(e={audio:!0,video:!1}){T.debug("mute()");let t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}unmute(e={audio:!0,video:!0}){T.debug("unmute()");let t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}hold(e={},t){if(T.debug("hold()"),this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this.isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const n={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:s.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:n,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:n,extraHeaders:e.extraHeaders}),!0}unhold(e={},t){if(T.debug("unhold()"),this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this.isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const n={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:s.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:n,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:n,extraHeaders:e.extraHeaders}),!0}renegotiate(e={},t){T.debug("renegotiate()");const n=e.rtcOfferConstraints||null;if(this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;if(!this.isReadyToReOffer())return!1;const r={succeeded:()=>{t&&t()},failed:()=>{this.terminate({cause:s.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),e.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,rtcOfferConstraints:n,extraHeaders:e.extraHeaders}):this._sendReinvite({eventHandlers:r,rtcOfferConstraints:n,extraHeaders:e.extraHeaders}),!0}refer(e,t){T.debug("refer()");const n=e;if(this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError(`Invalid target: ${n}`);const s=new m(this);s.sendRefer(e,t);let r=s.id;return this._referSubscribers[r]=s,s.on("requestFailed",()=>{delete this._referSubscribers[r]}),s.on("accepted",()=>{delete this._referSubscribers[r]}),s.on("failed",()=>{delete this._referSubscribers[r]}),s.on("authenticated",()=>{delete this._referSubscribers[r],r=s.id,this._referSubscribers[r]=s}),s}sendRequest(e,t){if(T.debug("sendRequest()"),this._dialog)return this._dialog.sendRequest(e,t);{const n=Object.values(this._earlyDialogs);return n.length>0?n[0].sendRequest(e,t):void T.warn("sendRequest() | no valid early dialog found")}}receiveRequest(e){if(T.debug("receiveRequest()"),e.method===s.CANCEL)this._status!==E.STATUS_WAITING_FOR_ANSWER&&this._status!==E.STATUS_ANSWERED||(this._status=E.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,s.causes.CANCELED));else switch(e.method){case s.ACK:if(this._status!==E.STATUS_WAITING_FOR_ACK)return;if(this._status=E.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:s.causes.MISSING_SDP,status_code:400});break}const t={originator:"remote",type:"answer",sdp:e.body};T.debug('emit "sdp"'),this.emit("sdp",t);const n=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(n)).then(()=>{this._is_confirmed||this._confirmed("remote",e)}).catch(e=>{this.terminate({cause:s.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case s.BYE:this._status===E.STATUS_CONFIRMED||this._status===E.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,s.causes.BYE)):this._status===E.STATUS_INVITE_RECEIVED||this._status===E.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,s.causes.BYE)):e.reply(403,"Wrong Status");break;case s.INVITE:this._status===E.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case s.INFO:if(this._status===E.STATUS_1XX_RECEIVED||this._status===E.STATUS_WAITING_FOR_ANSWER||this._status===E.STATUS_ANSWERED||this._status===E.STATUS_WAITING_FOR_ACK||this._status===E.STATUS_CONFIRMED){const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;t&&t.match(/^application\/dtmf-relay/i)?new _(this).init_incoming(e):void 0!==t?new p(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case s.UPDATE:this._status===E.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case s.REFER:this._status===E.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case s.NOTIFY:this._status===E.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}onTransportError(){T.warn("onTransportError()"),this._status!==E.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:s.causes.CONNECTION_ERROR,cause:s.causes.CONNECTION_ERROR})}onRequestTimeout(){T.warn("onRequestTimeout()"),this._status!==E.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:s.causes.REQUEST_TIMEOUT,cause:s.causes.REQUEST_TIMEOUT})}onDialogError(){T.warn("onDialogError()"),this._status!==E.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:s.causes.DIALOG_ERROR,cause:s.causes.DIALOG_ERROR})}newDTMF(e){T.debug("newDTMF()"),this.emit("newDTMF",e)}newInfo(e){T.debug("newInfo()"),this.emit("newInfo",e)}isReadyToReOffer(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(T.debug("isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(T.debug("isReadyToReOffer() | session not established yet"),!1):(T.debug("isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(T.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(T.debug("close() | closing local MediaStream"),o.closeMediaStream(this._localMediaStream)),this._status!==E.STATUS_TERMINATED){if(this._status=E.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){T.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 n=l.T1;this._timers.invite2xxTimer=setTimeout(function s(){this._status===E.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),n<l.T2&&(n*=2,n>l.T2&&(n=l.T2)),this._timers.invite2xxTimer=setTimeout(s.bind(this),n))}.bind(this),n)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===E.STATUS_WAITING_FOR_ACK&&(T.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(s.BYE),this._ended("remote",null,s.causes.NO_ACK))},l.TIMER_H)}_createRTCConnection(e,t){this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",()=>{"failed"===this._connection.iceConnectionState&&this.terminate({cause:s.causes.RTP_TIMEOUT,status_code:408,reason_phrase:s.causes.RTP_TIMEOUT})}),T.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(e,t){if(T.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error(`createLocalDescription() | invalid type "${e}"`);const n=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>"offer"===e?n.createOffer(t).catch(e=>(T.warn('emit "peerconnection:createofferfailed" [error:%o]',e),this.emit("peerconnection:createofferfailed",e),Promise.reject(e))):n.createAnswer(t).catch(e=>(T.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),this.emit("peerconnection:createanswerfailed",e),Promise.reject(e)))).then(e=>n.setLocalDescription(e).catch(e=>(this._rtcReady=!0,T.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),this.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)))).then(()=>{const s=t&&t.iceRestart;if("complete"===n.iceGatheringState&&!s||"gathering"===n.iceGatheringState&&this._iceReady){this._rtcReady=!0;const t={originator:"local",type:e,sdp:n.localDescription.sdp};return T.debug('emit "sdp"'),this.emit("sdp",t),Promise.resolve(t.sdp)}return new Promise(t=>{let s,r,i=!1;this._iceReady=!1;const o=()=>{if(i)return;n.removeEventListener("icecandidate",s),n.removeEventListener("icegatheringstatechange",r),i=!0,this._rtcReady=!0,this._iceReady=!0;const o={originator:"local",type:e,sdp:n.localDescription.sdp};T.debug('emit "sdp"'),this.emit("sdp",o),t(o.sdp)};n.addEventListener("icecandidate",s=e=>{const t=e.candidate;t?this.emit("icecandidate",{candidate:t,ready:o}):o()}),n.addEventListener("icegatheringstatechange",r=()=>{"complete"===n.iceGatheringState&&o()})})})}_createDialog(e,t,n){const r="UAS"===t?e.to_tag:e.from_tag,i="UAS"===t?e.from_tag:e.to_tag,o=e.call_id+r+i;let l=this._earlyDialogs[o];if(n)return!!l||(l=new u(this,e,t,u.C.STATUS_EARLY),l.error?(T.debug(l.error),this._failed("remote",e,s.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[o]=l,!0));{if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,l)return l.update(e,t),this._dialog=l,delete this._earlyDialogs[o],!0;const n=new u(this,e,t);return n.error?(T.debug(n.error),this._failed("remote",e,s.causes.INTERNAL_ERROR),!1):(this._dialog=n,!0)}}_receiveReinvite(e){T.debug("receiveReinvite()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,n={request:e,callback:void 0,reject:function(t={}){s=!0;const n=t.status_code||403,r=t.reason_phrase||"",i=o.cloneArray(t.extraHeaders);if(this._status!==E.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);e.reply(n,r,i)}.bind(this)};let s=!1;if(this.emit("reinvite",n),!s){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(e=>{r.call(this,e)}).catch(()=>{e.reply(500)}));if("application/sdp"!==t)return T.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(e=>{this._status!==E.STATUS_TERMINATED&&r.call(this,e)}).catch(e=>{T.warn(e)})}function r(t){const s=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,s),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,s,t,()=>{this._status=E.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(e,t),this._setACKTimer()}),"function"==typeof n.callback&&n.callback()}}_receiveUpdate(e){T.debug("receiveUpdate()");const t=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,n={request:e,callback:void 0,reject:function(t={}){s=!0;const n=t.status_code||403,r=t.reason_phrase||"",i=o.cloneArray(t.extraHeaders);if(this._status!==E.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);e.reply(n,r,i)}.bind(this)};let s=!1;if(this.emit("update",n),!s)if(e.body){if("application/sdp"!==t)return T.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(e=>{this._status!==E.STATUS_TERMINATED&&r.call(this,e)}).catch(e=>{T.warn(e)})}else r.call(this,null);function r(t){const s=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,s),e.reply(200,null,s,t),"function"==typeof n.callback&&n.callback()}}_processInDialogSdpOffer(e){T.debug("_processInDialogSdpOffer()");const t=e.parseSDP();let n=!1;for(const i of t.media){if(-1===S.indexOf(i.type))continue;const e=i.direction||t.direction||"sendrecv";if("sendonly"!==e&&"inactive"!==e){n=!1;break}n=!0}const s={originator:"remote",type:"offer",sdp:e.body};T.debug('emit "sdp"'),this.emit("sdp",s);const r=new RTCSessionDescription({type:"offer",sdp:s.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(r).catch(t=>{throw e.reply(488),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),this.emit("peerconnection:setremotedescriptionfailed",t),t})}).then(()=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");!0===this._remoteHold&&!1===n?(this._remoteHold=!1,this._onunhold("remote")):!1===this._remoteHold&&!0===n&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(t=>{throw e.reply(500),T.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(e=>{T.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}_receiveRefer(e){if(T.debug("receiveRefer()"),!e.refer_to)return T.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==s.SIP)return T.debug("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);const t=new f(this,e.cseq);function r(s,r={}){if(s="function"==typeof s?s:null,this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;const i=new n(this._ua);if(i.on("progress",({response:e})=>{t.notify(e.status_code,e.reason_phrase)}),i.on("accepted",({response:e})=>{t.notify(e.status_code,e.reason_phrase)}),i.on("_failed",({message:e,cause:n})=>{e?t.notify(e.status_code,e.reason_phrase):t.notify(487,n)}),e.refer_to.uri.hasHeader("replaces")){const t=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=o.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${t}`)}i.connect(e.refer_to.uri,r,s)}function i(){t.notify(603)}T.debug('emit "refer"'),this.emit("refer",{request:e,accept:(e,t)=>{r.call(this,e,t)},reject:()=>{i.call(this)}})}_receiveNotify(e){switch(T.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":{let t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200);break}default:e.reply(489)}}_receiveReplaces(e){function t(t){if(this._status!==E.STATUS_WAITING_FOR_ACK&&this._status!==E.STATUS_CONFIRMED)return!1;const s=new n(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(e,t)}function s(){T.debug("Replaced INVITE rejected by the user"),e.reply(486)}T.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:e=>{t.call(this,e)},reject:()=>{s.call(this)}})}_sendInitialRequest(e,t,n){const r=new c(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:e=>{this._request=e},onReceiveResponse:e=>{this._receiveInviteResponse(e)}});Promise.resolve().then(()=>n||(e.audio||e.video?(this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(e=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");throw this._failed("local",null,s.causes.USER_DENIED_MEDIA_ACCESS),T.warn('emit "getusermediafailed" [error:%o]',e),this.emit("getusermediafailed",e),e})):void 0)).then(e=>{if(this._status===E.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=e,e&&e.getTracks().forEach(t=>{this._connection.addTrack(t,e)}),this._connecting(this._request),this._createLocalDescription("offer",t).catch(e=>{throw this._failed("local",null,s.causes.WEBRTC_ERROR),e})}).then(e=>{if(this._is_canceled||this._status===E.STATUS_TERMINATED)throw new Error("terminated");this._request.body=e,this._status=E.STATUS_INVITE_SENT,T.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),r.send()}).catch(e=>{this._status!==E.STATUS_TERMINATED&&T.warn(e)})}_getDTMFRTPSender(){const e=this._connection.getSenders().find(e=>e.track&&"audio"===e.track.kind);if(e&&e.dtmf)return e.dtmf;T.warn("sendDTMF() | no local audio track to send DTMF with")}_receiveInviteResponse(e){if(T.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)return void this.sendRequest(s.ACK);{const t=new u(this,e,"UAC");return void 0!==t.error?void T.debug(t.error):(this.sendRequest(s.ACK),void this.sendRequest(s.BYE))}}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);else if(this._status===E.STATUS_INVITE_SENT||this._status===E.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=E.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):{if(!e.to_tag){T.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=E.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}const t={originator:"remote",type:"answer",sdp:e.body};T.debug('emit "sdp"'),this.emit("sdp",t);const n=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(n)).then(()=>this._progress("remote",e)).catch(e=>{T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e)});break}case/^2[0-9]{2}$/.test(e.status_code):{if(this._status=E.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,s.causes.MISSING_SDP),this._failed("remote",e,s.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;const t={originator:"remote",type:"answer",sdp:e.body};T.debug('emit "sdp"'),this.emit("sdp",t);const n=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if("stable"===this._connection.signalingState)return this._connection.createOffer(this._rtcOfferConstraints).then(e=>this._connection.setLocalDescription(e)).catch(t=>{this._acceptAndTerminate(e,500,t.toString()),this._failed("local",e,s.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(n).then(()=>{this._handleSessionTimersInIncomingResponse(e),this._accepted("remote",e),this.sendRequest(s.ACK),this._confirmed("local",null)}).catch(t=>{this._acceptAndTerminate(e,488,"Not Acceptable Here"),this._failed("remote",e,s.causes.BAD_MEDIA_DESCRIPTION),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),this.emit("peerconnection:setremotedescriptionfailed",t)})});break}default:{const t=o.sipErrorCause(e.status_code);this._failed("remote",e,t)}}}_sendReinvite(e={}){T.debug("sendReinvite()");const t=o.cloneArray(e.extraHeaders),n=o.cloneObject(e.eventHandlers),r=e.rtcOfferConstraints||this._rtcOfferConstraints||null;let i=!1;function l(e){if(this._status===E.STATUS_TERMINATED)return;if(this.sendRequest(s.ACK),i)return;if(this._handleSessionTimersInIncomingResponse(e),!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);const t={originator:"remote",type:"answer",sdp:e.body};T.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(()=>{n.succeeded&&n.succeeded(e)}).catch(e=>{a.call(this),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e)})}function a(e){n.failed&&n.failed(e)}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",r)).then(e=>{const n={originator:"local",type:"offer",sdp:e=this._mangleOffer(e)};T.debug('emit "sdp"'),this.emit("sdp",n),this.sendRequest(s.INVITE,{extraHeaders:t,body:e,eventHandlers:{onSuccessResponse:e=>{l.call(this,e),i=!0},onErrorResponse:e=>{a.call(this,e)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{a()})}_sendUpdate(e={}){T.debug("sendUpdate()");const t=o.cloneArray(e.extraHeaders),n=o.cloneObject(e.eventHandlers),r=e.rtcOfferConstraints||this._rtcOfferConstraints||null,i=e.sdpOffer||!1;let l=!1;function a(e){if(this._status!==E.STATUS_TERMINATED&&!l)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void u.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void u.call(this);const t={originator:"remote",type:"answer",sdp:e.body};T.debug('emit "sdp"'),this.emit("sdp",t);const s=new RTCSessionDescription({type:"answer",sdp:t.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(s)).then(()=>{n.succeeded&&n.succeeded(e)}).catch(e=>{u.call(this),T.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e)})}else n.succeeded&&n.succeeded(e)}function u(e){n.failed&&n.failed(e)}t.push(`Contact: ${this._contact}`),this._sessionTimers.running&&t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),i?(t.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",r)).then(e=>{const n={originator:"local",type:"offer",sdp:e=this._mangleOffer(e)};T.debug('emit "sdp"'),this.emit("sdp",n),this.sendRequest(s.UPDATE,{extraHeaders:t,body:e,eventHandlers:{onSuccessResponse:e=>{a.call(this,e),l=!0},onErrorResponse:e=>{u.call(this,e)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{u.call(this)})):this.sendRequest(s.UPDATE,{extraHeaders:t,eventHandlers:{onSuccessResponse:e=>{a.call(this,e)},onErrorResponse:e=>{u.call(this,e)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}_acceptAndTerminate(e,t,n){T.debug("acceptAndTerminate()");const r=[];t&&(n=n||s.REASON_PHRASE[t]||"",r.push(`Reason: SIP ;cause=${t}; text="${n}"`)),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(s.ACK),this.sendRequest(s.BYE,{extraHeaders:r})),this._status=E.STATUS_TERMINATED}_mangleOffer(e){if(!this._localHold&&!this._remoteHold)return e;if(e=t.parse(e),this._localHold&&!this._remoteHold){T.debug("mangleOffer() | me on hold, mangling offer");for(const t of e.media)-1!==S.indexOf(t.type)&&(t.direction?"sendrecv"===t.direction?t.direction="sendonly":"recvonly"===t.direction&&(t.direction="inactive"):t.direction="sendonly")}else if(this._localHold&&this._remoteHold){T.debug("mangleOffer() | both on hold, mangling offer");for(const t of e.media)-1!==S.indexOf(t.type)&&(t.direction="inactive")}else if(this._remoteHold){T.debug("mangleOffer() | remote on hold, mangling offer");for(const t of e.media)-1!==S.indexOf(t.type)&&(t.direction?"sendrecv"===t.direction?t.direction="recvonly":"recvonly"===t.direction&&(t.direction="inactive"):t.direction="recvonly")}return t.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 n;e.session_expires&&e.session_expires>=s.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,n=e.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uas"),t.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${n}`),this._sessionTimers.refresher="uas"===n,this._runSessionTimer()}_handleSessionTimersInIncomingResponse(e){if(!this._sessionTimers.enabled)return;let t;e.session_expires&&e.session_expires>=s.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="uac"===t,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!==E.STATUS_TERMINATED&&this.isReadyToReOffer()&&(T.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===s.UPDATE?this._sendUpdate():this._sendReinvite())},500*e):this._sessionTimers.timer=setTimeout(()=>{this._status!==E.STATUS_TERMINATED&&(T.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:s.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},1100*e)}_toggleMuteAudio(e){const t=this._connection.getSenders().filter(e=>e.track&&"audio"===e.track.kind);for(const n of t)n.track.enabled=!e}_toggleMuteVideo(e){const t=this._connection.getSenders().filter(e=>e.track&&"video"===e.track.kind);for(const n of t)n.track.enabled=!e}_newRTCSession(e,t){T.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}_connecting(e){T.debug("session connecting"),T.debug('emit "connecting"'),this.emit("connecting",{request:e})}_progress(e,t){T.debug("session progress"),T.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}_accepted(e,t){T.debug("session accepted"),this._start_time=new Date,T.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}_confirmed(e,t){T.debug("session confirmed"),this._is_confirmed=!0,T.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}_ended(e,t,n){T.debug("session ended"),this._end_time=new Date,this._close(),T.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}_failed(e,t,n){T.debug("session failed"),T.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),T.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}_onhold(e){T.debug("session onhold"),this._setLocalMediaStatus(),T.debug('emit "hold"'),this.emit("hold",{originator:e})}_onunhold(e){T.debug("session onunhold"),this._setLocalMediaStatus(),T.debug('emit "unhold"'),this.emit("unhold",{originator:e})}_onmute({audio:e,video:t}){T.debug("session onmute"),this._setLocalMediaStatus(),T.debug('emit "muted"'),this.emit("muted",{audio:e,video:t})}_onunmute({audio:e,video:t}){T.debug("session onunmute"),this._setLocalMediaStatus(),T.debug('emit "unmuted"'),this.emit("unmuted",{audio:e,video:t})}}}var $e,He,Fe,Le={};function ke(){if($e)return Le;$e=1;const e=H(),t=R(),n=A(),s=new e("Socket");return Le.isSocket=e=>{if(Array.isArray(e))return!1;if(void 0===e)return s.warn("undefined JsSIP.Socket instance"),!1;try{if(!t.isString(e.url))throw s.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!t.isString(e.via_transport))throw s.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===n.parse(e.sip_uri,"SIP_URI"))throw s.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(r){return!1}try{["connect","disconnect","send"].forEach(n=>{if(!t.isFunction(e[n]))throw s.warn(`missing or invalid JsSIP.Socket method: ${n}`),new Error(`Missing or invalid JsSIP.Socket method: ${n}`)})}catch(r){return!1}return!0},Le}var Ge,je,Be,Ve={};var We,Ye,ze,Ke,Xe,Qe,Je,Ze={};function et(){if(ze)return Ye;ze=1;const e=w().EventEmitter,t=H(),n=h(),s=function(){if(te)return ee;te=1;const e=H(),t=R(),n=h(),s=_e(),r=me(),i=new e("Registrator");return ee=class{constructor(e,n){this._reg_id=1,this._ua=e,this._transport=n,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=t.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 n=e[t];this._extraContactParams+=`;${t}`,n&&(this._extraContactParams+=`=${n}`)}}register(){if(this._registering)return void i.debug("Register request in progress...");const e=t.cloneArray(this._extraHeaders);let o;this._expires?(o=`${this._contact};expires=${this._expires}${this._extraContactParams}`,e.push(`Expires: ${this._expires}`)):o=`${this._contact}${this._extraContactParams}`,e.push(`Contact: ${o}`);let l=t.newTag();this._ua.configuration.register_from_tag_trail&&("function"==typeof this._ua.configuration.register_from_tag_trail?l+=this._ua.configuration.register_from_tag_trail():l+=this._ua.configuration.register_from_tag_trail);const a=new s.OutgoingRequest(n.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1,from_tag:l},e),u=new r(this._ua,a,{onRequestTimeout:()=>{this._registrationFailure(null,n.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,n.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:e=>{if(e.cseq===this._cseq)switch(null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):{if(this._registering=!1,!e.hasHeader("Contact")){i.debug("no Contact header in response to REGISTER, response ignored");break}const t=e.headers.Contact.reduce((e,t)=>e.concat(t.parsed),[]);let n=t.find(e=>this._sipInstance===e.getParam("+sip.instance")&&this._reg_id===parseInt(e.getParam("reg-id")));if(n||(n=t.find(e=>e.uri.user===this._ua.contact.uri.user)),!n){i.debug("no Contact header pointing to us, response ignored");break}let s=n.getParam("expires");!s&&e.hasHeader("expires")&&(s=e.getHeader("expires")),s||(s=this._expires),s=Number(s),s<10&&(s=10);const r=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,0===this._ua.listeners("registrationExpiring").length?this.register():this._ua.emit("registrationExpiring")},r),n.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:e}));break}case/^423$/.test(e.status_code):e.hasHeader("min-expires")?(this._expires=Number(e.getHeader("min-expires")),this._expires<10&&(this._expires=10),this._registering=!1,this.register()):(i.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(e,n.causes.SIP_FAILURE_CODE));break;default:{const n=t.sipErrorCause(e.status_code);this._registrationFailure(e,n)}}}});this._registering=!0,u.send()}unregister(e={}){if(!this._registered)return void i.debug("already unregistered");this._registered=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const o=t.cloneArray(this._extraHeaders);e.all?o.push(`Contact: *${this._extraContactParams}`):o.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),o.push("Expires: 0");const l=new s.OutgoingRequest(n.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o);new r(this._ua,l,{onRequestTimeout:()=>{this._unregistered(null,n.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,n.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:e=>{switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._unregistered(e);break;default:{const n=t.sipErrorCause(e.status_code);this._unregistered(e,n)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,null!==this._registrationTimer&&(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})}}}(),r=qe(),i=function(){if(ye)return we;ye=1;const e=w().EventEmitter,t=d(),n=H(),s=h(),r=R(),i=A(),o=_e(),l=me(),a=ge(),u=new n("Subscriber"),c={SUBSCRIBE_RESPONSE_TIMEOUT:0,SUBSCRIBE_TRANSPORT_ERROR:1,SUBSCRIBE_NON_OK_RESPONSE:2,SUBSCRIBE_WRONG_OK_RESPONSE:3,SUBSCRIBE_AUTHENTICATION_FAILED:4,UNSUBSCRIBE_TIMEOUT:5,FINAL_NOTIFY_RECEIVED:6,WRONG_NOTIFY_RECEIVED:7,STATE_PENDING:0,STATE_ACTIVE:1,STATE_TERMINATED:2,STATE_INIT:3,STATE_WAITING_NOTIFY:4,DEFAULT_EXPIRES_SEC:900};return we=class extends e{static get C(){return c}constructor(e,t,n,s,{expires:o,contentType:l,allowEvents:a,params:h,extraHeaders:d}){if(u.debug("new"),super(),!t)throw new TypeError("Not enough arguments: Missing target");if(!n)throw new TypeError("Not enough arguments: Missing eventName");if(!s)throw new TypeError("Not enough arguments: Missing accept");const _=i.parse(n,"Event");if(-1===_)throw new TypeError("Missing Event header field");this._ua=e,this._target=t,(!r.isDecimal(o)||o<=0)&&(o=c.DEFAULT_EXPIRES_SEC),this._expires=o,this._content_type=l,this._params=r.cloneObject(h),this._params.from_uri||(this._params.from_uri=this._ua.configuration.uri),this._params.from_tag=r.newTag(),this._params.to_tag=null,this._params.call_id=r.createRandomToken(20),void 0===this._params.cseq&&(this._params.cseq=Math.floor(1e4*Math.random()+1)),this._state=c.STATE_INIT,this._dialog=null,this._expires_timer=null,this._expires_timestamp=null,this._terminated=!1,this._event_name=_.event,this._event_id=_.params&&_.params.id;let p=this._event_name;if(this._event_id&&(p+=`;id=${this._event_id}`),this._headers=r.cloneArray(d),this._headers=this._headers.concat([`Event: ${p}`,`Expires: ${this._expires}`,`Accept: ${s}`]),!this._headers.find(e=>e.startsWith("Contact"))){const e=`Contact: ${this._ua._contact.toString()}`;this._headers.push(e)}a&&this._headers.push(`Allow-Events: ${a}`),this._queue=[],this._data={}}get C(){return c}get state(){return this._state}get id(){return this._dialog?this._dialog.id:null}get data(){return this._data}set data(e){this._data=e}onRequestTimeout(){this._terminateDialog(c.SUBSCRIBE_RESPONSE_TIMEOUT)}onTransportError(){this._terminateDialog(c.SUBSCRIBE_TRANSPORT_ERROR)}receiveRequest(e){if(e.method!==s.NOTIFY)return u.warn("received non-NOTIFY request"),void e.reply(405);const t=e.parseHeader("Event");if(!t)return u.warn("missing Event header"),e.reply(400),void this._terminateDialog(c.WRONG_NOTIFY_RECEIVED);const n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return u.warn("Event header does not match the one in SUBSCRIBE request"),e.reply(489),void this._terminateDialog(c.WRONG_NOTIFY_RECEIVED);const i=e.parseHeader("subscription-state");if(!i)return u.warn("missing Subscription-State header"),e.reply(400),void this._terminateDialog(c.WRONG_NOTIFY_RECEIVED);const o=this._parseSubscriptionState(i.state);if(void 0===o)return u.warn(`Invalid Subscription-State header value: ${i.state}`),e.reply(400),void this._terminateDialog(c.WRONG_NOTIFY_RECEIVED);e.reply(200);const l=this._state;if(l!==c.STATE_TERMINATED&&o!==c.STATE_TERMINATED&&(this._state=o,void 0!==i.expires)){const e=i.expires,t=(new Date).getTime()+1e3*e,n=2e3;this._expires_timestamp-t>n&&(u.debug("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(e))}l!==c.STATE_PENDING&&o===c.STATE_PENDING?(u.debug('emit "pending"'),this.emit("pending")):l!==c.STATE_ACTIVE&&o===c.STATE_ACTIVE&&(u.debug('emit "active"'),this.emit("active"));const a=e.body,h=o===c.STATE_TERMINATED;if(a){const t=e.getHeader("content-type");u.debug('emit "notify"'),this.emit("notify",h,e,a,t)}if(h){const e=i.reason;let t;i.params&&void 0!==i.params["retry-after"]&&(t=parseInt(i.params["retry-after"])),this._terminateDialog(c.FINAL_NOTIFY_RECEIVED,e,t)}}subscribe(e=null){u.debug("subscribe()"),this._state===c.STATE_INIT?this._sendInitialSubscribe(e,this._headers):this._sendSubsequentSubscribe(e,this._headers)}terminate(e=null){if(u.debug("terminate()"),this._state===c.STATE_INIT)throw new t.InvalidStateError(this._state);if(this._terminated)return;this._terminated=!0;const n=this._headers.map(e=>e.startsWith("Expires")?"Expires: 0":e);this._sendSubsequentSubscribe(e,n)}_terminateDialog(e,t=void 0,n=void 0){this._state!==c.STATE_TERMINATED&&(this._state=c.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null),u.debug(`emit "terminated" code=${e}`),this.emit("terminated",e,t,n))}_sendInitialSubscribe(e,t){if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=r.cloneArray(t)).push(`Content-Type: ${this._content_type}`)}this._state=c.STATE_WAITING_NOTIFY;const n=new o.OutgoingRequest(s.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new l(this._ua,n,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onReceiveResponse:e=>{this._receiveSubscribeResponse(e)}}).send()}_sendSubsequentSubscribe(e,t){if(this._state!==c.STATE_TERMINATED){if(!this._dialog)return u.debug("enqueue subscribe"),void this._queue.push({body:e,headers:r.cloneArray(t)});if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=r.cloneArray(t)).push(`Content-Type: ${this._content_type}`)}this._dialog.sendRequest(s.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onSuccessResponse:e=>{this._receiveSubscribeResponse(e)},onErrorResponse:e=>{this._receiveSubscribeResponse(e)},onDialogError:e=>{this._receiveSubscribeResponse(e)}}})}}_receiveSubscribeResponse(e){if(this._state!==c.STATE_TERMINATED)if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){const t=new a(this,e,"UAC");if(t.error)return u.warn(t.error),void this._terminateDialog(c.SUBSCRIBE_WRONG_OK_RESPONSE);this._dialog=t,u.debug('emit "accepted"'),this.emit("accepted");for(const e of this._queue)u.debug("dequeue subscribe"),this._sendSubsequentSubscribe(e.body,e.headers)}const t=e.getHeader("expires");let n=parseInt(t);(!r.isDecimal(n)||n<=0)&&(u.warn(`response without Expires header, setting a default value of ${c.DEFAULT_EXPIRES_SEC}`),n=c.DEFAULT_EXPIRES_SEC),n>0&&this._scheduleSubscribe(n)}else 401===e.status_code||407===e.status_code?this._terminateDialog(c.SUBSCRIBE_AUTHENTICATION_FAILED):e.status_code>=300&&this._terminateDialog(c.SUBSCRIBE_NON_OK_RESPONSE)}_scheduleSubscribe(e){const t=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,u.debug(`next SUBSCRIBE will be sent in ${Math.floor(t/1e3)} sec`),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(()=>{this._expires_timer=null,this._sendSubsequentSubscribe(null,this._headers)},t)}_parseSubscriptionState(e){switch(e){case"pending":return c.STATE_PENDING;case"active":return c.STATE_ACTIVE;case"terminated":return c.STATE_TERMINATED;case"init":return c.STATE_INIT;case"notify_wait":return c.STATE_WAITING_NOTIFY;default:return}}}}(),o=function(){if(Oe)return Ne;Oe=1;const e=w().EventEmitter,t=d(),n=H(),s=h(),r=R(),i=ge(),o=new n("Notifier"),l={NOTIFY_RESPONSE_TIMEOUT:0,NOTIFY_TRANSPORT_ERROR:1,NOTIFY_NON_OK_RESPONSE:2,NOTIFY_AUTHENTICATION_FAILED:3,FINAL_NOTIFY_SENT:4,UNSUBSCRIBE_RECEIVED:5,SUBSCRIPTION_EXPIRED:6,STATE_PENDING:0,STATE_ACTIVE:1,STATE_TERMINATED:2,DEFAULT_EXPIRES_SEC:900};return Ne=class n extends e{static get C(){return l}static init_incoming(e,t){try{n.checkSubscribe(e)}catch(s){return o.warn("Notifier.init_incoming: invalid request. Error: ",s.message),void e.reply(405)}t()}static checkSubscribe(e){if(!e)throw new TypeError("Not enough arguments. Missing subscribe request");if(e.method!==s.SUBSCRIBE)throw new TypeError("Invalid method for Subscribe request");if(!e.hasHeader("contact"))throw new TypeError("Missing Contact header in subscribe request");if(!e.hasHeader("event"))throw new TypeError("Missing Event header in subscribe request");const t=e.getHeader("expires");if(t){const e=parseInt(t);if(!r.isDecimal(e)||e<0)throw new TypeError("Invalid Expires header field in subscribe request")}}constructor(e,t,s,{extraHeaders:i,allowEvents:a,pending:u,defaultExpires:c}){if(o.debug("new"),super(),!s)throw new TypeError("Not enough arguments. Missing contentType");n.checkSubscribe(t);const h=t.getHeader("event");this._ua=e,this._initial_subscribe=t,this._expires_timestamp=null,this._expires_timer=null,this._defaultExpires=c||l.DEFAULT_EXPIRES_SEC,this._state=u?l.STATE_PENDING:l.STATE_ACTIVE,this._content_type=s,this._headers=r.cloneArray(i),this._headers.push(`Event: ${h}`),this._contact=this._headers.find(e=>e.startsWith("Contact")),this._contact||(this._contact=`Contact: ${this._ua._contact.toString()}`,this._headers.push(this._contact)),a&&this._headers.push(`Allow-Events: ${a}`),this._target=t.from.uri.user,t.to_tag=r.newTag(),this._data={}}get C(){return l}get state(){return this._state}get id(){return this._dialog?this._dialog.id:null}get data(){return this._data}set data(e){this._data=e}receiveRequest(e){if(e.method!==s.SUBSCRIBE)return void e.reply(405);this._setExpires(e),this._dialog||(this._dialog=new i(this,e,"UAS")),e.reply(200,null,[`Expires: ${this._expires}`,`${this._contact}`]);const t=e.body,n=e.getHeader("content-type"),r=0===this._expires;r||this._setExpiresTimer(),o.debug('emit "subscribe"'),this.emit("subscribe",r,e,t,n),r&&this._terminateDialog(l.UNSUBSCRIBE_RECEIVED)}start(){if(o.debug("start()"),this._state===l.STATE_TERMINATED)throw new t.InvalidStateError(this._state);this.receiveRequest(this._initial_subscribe)}setActiveState(){if(o.debug("setActiveState()"),this._state===l.STATE_TERMINATED)throw new t.InvalidStateError(this._state);this._state===l.STATE_PENDING&&(this._state=l.STATE_ACTIVE)}notify(e=null){if(o.debug("notify()"),this._state===l.STATE_TERMINATED)throw new t.InvalidStateError(this._state);const n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<=0?(this._expires_timer||o.error("expires timer is not set"),clearTimeout(this._expires_timer),this.terminate(e,"timeout")):this._sendNotify([`;expires=${n}`],e)}terminate(e=null,t=null,n=null){if(o.debug("terminate()"),this._state===l.STATE_TERMINATED)return;const s=[];t&&s.push(`;reason=${t}`),null!==n&&s.push(`;retry-after=${n}`),this._sendNotify(s,e,null,"terminated"),this._terminateDialog("timeout"===t?l.SUBSCRIPTION_EXPIRED:l.FINAL_NOTIFY_SENT)}_terminateDialog(e){this._state!==l.STATE_TERMINATED&&(this._state=l.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null),o.debug(`emit "terminated" code=${e}`),this.emit("terminated",e))}_setExpires(e){e.hasHeader("expires")?this._expires=parseInt(e.getHeader("expires")):(this._expires=this._defaultExpires,o.debug(`missing Expires header field, default value set: ${this._expires}`))}_sendNotify(e,t=null,n=null,i=null){if(this._state===l.STATE_TERMINATED)return void o.warn("final notify already sent");let a=`Subscription-State: ${i||this._parseState()}`;for(const s of e)a+=s;let u=r.cloneArray(this._headers);u.push(a),n&&(u=u.concat(n)),t&&u.push(`Content-Type: ${this._content_type}`),this._dialog.sendRequest(s.NOTIFY,{body:t,extraHeaders:u,eventHandlers:{onRequestTimeout:()=>{this._terminateDialog(l.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:()=>{this._terminateDialog(l.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:e=>{401===e.status_code||407===e.status_code?this._terminateDialog(l.NOTIFY_AUTHENTICATION_FAILED):this._terminateDialog(l.NOTIFY_NON_OK_RESPONSE)},onDialogError:()=>{this._terminateDialog(l.NOTIFY_NON_OK_RESPONSE)}}})}_setExpiresTimer(){this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(()=>{this._state!==l.STATE_TERMINATED&&(o.debug('emit "expired"'),this.emit("expired"),this.terminate(null,"timeout"))},1e3*this._expires)}_parseState(){switch(this._state){case l.STATE_PENDING:return"pending";case l.STATE_ACTIVE:return"active";case l.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}}(),l=function(){if(Ue)return De;Ue=1;const e=w().EventEmitter,t=H(),n=h(),s=_e(),r=R(),i=me(),o=d(),l=v(),a=new t("Message");return De=class extends e{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,o={}){const a=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError(`Invalid target: ${a}`);const u=r.cloneArray(o.extraHeaders),c=r.cloneObject(o.eventHandlers),h=o.contentType||"text/plain",d={};o.fromUserName&&(d.from_uri=new l("sip",o.fromUserName,this._ua.configuration.uri.host),u.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),o.fromDisplayName&&(d.from_display_name=o.fromDisplayName);for(const n in c)Object.prototype.hasOwnProperty.call(c,n)&&this.on(n,c[n]);u.push(`Content-Type: ${h}`),this._request=new s.OutgoingRequest(n.MESSAGE,e,this._ua,d,u),t&&(this._request.body=t);const _=new i(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:e=>{this._receiveResponse(e)}});this._newMessage("local",this._request),_.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=r.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new o.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,n)}reject(e={}){const t=e.status_code||480,n=e.reason_phrase,s=r.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new o.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,n,s,i)}_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=r.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,n.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,n.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(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,n){a.debug("MESSAGE failed"),this._close(),a.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}_succeeded(e,t){a.debug("MESSAGE succeeded"),this._close(),a.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}}(),a=function(){if(Me)return xe;Me=1;const e=w().EventEmitter,t=H(),n=h(),s=_e(),r=R(),i=me(),o=d(),l=new t("Options");return xe=class extends e{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,o={}){const l=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError(`Invalid target: ${l}`);const a=r.cloneArray(o.extraHeaders),u=r.cloneObject(o.eventHandlers),c=o.contentType||"application/sdp";for(const n in u)Object.prototype.hasOwnProperty.call(u,n)&&this.on(n,u[n]);a.push(`Content-Type: ${c}`),this._request=new s.OutgoingRequest(n.OPTIONS,e,this._ua,null,a),t&&(this._request.body=t);const h=new i(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:e=>{this._receiveResponse(e)}});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=r.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new o.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,n)}reject(e={}){const t=e.status_code||480,n=e.reason_phrase,s=r.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new o.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,n,s,i)}_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=r.sipErrorCause(e.status_code);this._failed("remote",e,t);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,n.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,n.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(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,n){l.debug("OPTIONS failed"),this._close(),l.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}_succeeded(e,t){l.debug("OPTIONS succeeded"),this._close(),l.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}}(),u=fe(),c=function(){if(Fe)return He;Fe=1;const e=H(),t=ke(),n=h(),s=new e("Transport"),r=0,i=1,o=2,l=0,a=1,u={min_interval:n.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:n.CONNECTION_RECOVERY_MAX_INTERVAL};return He=class{constructor(e,n=u){s.debug("new()"),this.status=o,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(r){s.warn(`cannot use TextDecoder: ${r}`)}if(void 0===e)throw new TypeError("Invalid argument. undefined 'sockets' argument");e instanceof Array||(e=[e]),e.forEach(function(e){if(!t.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:l})},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(){s.debug("connect()"),this.isConnected()?s.debug("Transport is already connected"):this.isConnecting()?s.debug("Transport is connecting"):(this.close_requested=!1,this.status=i,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(){s.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=o,null!==this.recovery_timer&&(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(s.debug("send()"),!this.isConnected())return s.warn("unable to send message, transport is not connected"),!1;const t=e.toString();return s.debug(`sending message:\n\n${t}\n`),this.socket.send(t)}isConnected(){return this.status===r}isConnecting(){return this.status===i}_reconnect(){this.recover_attempts+=1;let e=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);e<this.recovery_options.min_interval?e=this.recovery_options.min_interval:e>this.recovery_options.max_interval&&(e=this.recovery_options.max_interval),s.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${e} seconds`),this.recovery_timer=setTimeout(()=>{this.close_requested||this.isConnected()||this.isConnecting()||(this._getSocket(),this.connect())},1e3*e)}_getSocket(){let e=[];if(this.sockets.forEach(t=>{t.status!==a&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(e=>{e.status=l}),void this._getSocket();const t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}_onConnect(){this.recover_attempts=0,this.status=r,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(e,t,n){this.status=o,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a)},this),this._reconnect(e))}_onData(e){if("\r\n\r\n"!==e)if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(t){return void s.debug(`received binary message failed to be converted into string: ${t}`)}s.debug(`received binary message:\n\n${e}\n`)}else s.debug(`received text message:\n\n${e}\n`);this.ondata({transport:this,message:e})}else s.debug("received message with CRLF Keep Alive response");else{s.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(t){s.warn(`error sending Keep Alive response: ${t}`)}}}}}(),_=R(),p=d(),f=v(),m=function(){if(Ge)return Ve;Ge=1;const e=H(),t=A(),n=_e(),s=new e("Parser");function r(e,t){let n=t,s=0,r=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===s;){if(r=e.indexOf("\r\n",n),-1===r)return r;!e.substring(r+2,r+4).match(/(^\r\n)/)&&e.charAt(r+2).match(/(^\s+)/)?n=r+2:s=r}return s}function i(e,s,r,i){let o;const l=s.indexOf(":",r),a=s.substring(r,l).trim(),u=s.substring(l+1,i).trim();switch(a.toLowerCase()){case"via":case"v":e.addHeader("via",u),1===e.getHeaders("via").length?(o=e.parseHeader("Via"),o&&(e.via=o,e.via_branch=o.branch)):o=0;break;case"from":case"f":e.setHeader("from",u),o=e.parseHeader("from"),o&&(e.from=o,e.from_tag=o.getParam("tag"));break;case"to":case"t":e.setHeader("to",u),o=e.parseHeader("to"),o&&(e.to=o,e.to_tag=o.getParam("tag"));break;case"record-route":if(o=t.parse(u,"Record_Route"),-1===o)o=void 0;else for(const t of o)e.addHeader("record-route",u.substring(t.possition,t.offset)),e.headers["Record-Route"][e.getHeaders("record-route").length-1].parsed=t.parsed;break;case"call-id":case"i":e.setHeader("call-id",u),o=e.parseHeader("call-id"),o&&(e.call_id=u);break;case"contact":case"m":if(o=t.parse(u,"Contact"),-1===o)o=void 0;else for(const t of o)e.addHeader("contact",u.substring(t.possition,t.offset)),e.headers.Contact[e.getHeaders("contact").length-1].parsed=t.parsed;break;case"content-length":case"l":e.setHeader("content-length",u),o=e.parseHeader("content-length");break;case"content-type":case"c":e.setHeader("content-type",u),o=e.parseHeader("content-type");break;case"cseq":e.setHeader("cseq",u),o=e.parseHeader("cseq"),o&&(e.cseq=o.value),e instanceof n.IncomingResponse&&(e.method=o.method);break;case"max-forwards":e.setHeader("max-forwards",u),o=e.parseHeader("max-forwards");break;case"www-authenticate":e.setHeader("www-authenticate",u),o=e.parseHeader("www-authenticate");break;case"proxy-authenticate":e.setHeader("proxy-authenticate",u),o=e.parseHeader("proxy-authenticate");break;case"session-expires":case"x":e.setHeader("session-expires",u),o=e.parseHeader("session-expires"),o&&(e.session_expires=o.expires,e.session_expires_refresher=o.refresher);break;case"refer-to":case"r":e.setHeader("refer-to",u),o=e.parseHeader("refer-to"),o&&(e.refer_to=o);break;case"replaces":e.setHeader("replaces",u),o=e.parseHeader("replaces"),o&&(e.replaces=o);break;case"event":case"o":e.setHeader("event",u),o=e.parseHeader("event"),o&&(e.event=o);break;default:e.addHeader(a,u),o=0}return void 0!==o||{error:`error parsing header "${a}"`}}return Ve.parseMessage=(e,o)=>{let l,a,u=e.indexOf("\r\n");if(-1===u)return void s.warn("parseMessage() | no CRLF found, not a SIP message");const c=e.substring(0,u);let h=t.parse(c,"Request_Response");if(-1===h)return void s.warn(`parseMessage() | error parsing first line of SIP message: "${c}"`);h.status_code?(l=new n.IncomingResponse,l.status_code=h.status_code,l.reason_phrase=h.reason_phrase):(l=new n.IncomingRequest(o),l.method=h.method,l.ruri=h.uri),l.data=e;let d=u+2;for(;;){if(u=r(e,d),-2===u){a=d+2;break}if(-1===u)return void s.warn("parseMessage() | malformed message");if(h=i(l,e,d,u),!0!==h)return void s.warn("parseMessage() |",h.error);d=u+2}if(l.hasHeader("content-length")){const t=l.getHeader("content-length");l.body=e.substr(a,t)}else l.body=e.substring(a);return l},Ve}(),g=_e(),T=function(){if(Be)return je;Be=1;const e=H(),t=h(),n=_e(),s=R(),r=new e("sanityCheck"),i=[function(){const e=["from","to","call_id","cseq","via"];for(const t of e)if(!a.hasHeader(t))return r.debug(`missing mandatory header field : ${t}, dropping the response`),!1}],o=[function(){if("sip"!==a.s("to").uri.scheme)return d(416),!1},function(){if(!a.to_tag&&a.call_id.substr(0,5)===u.configuration.jssip_id)return d(482),!1},function(){if(s.str_utf8_length(a.body)<a.getHeader("content-length"))return d(400),!1},function(){const e=a.from_tag,n=a.call_id,s=a.cseq;let r;if(!a.to_tag)if(a.method===t.INVITE){if(u._transactions.ist[a.via_branch])return!1;for(const t in u._transactions.ist)if(Object.prototype.hasOwnProperty.call(u._transactions.ist,t)&&(r=u._transactions.ist[t],r.request.from_tag===e&&r.request.call_id===n&&r.request.cseq===s))return d(482),!1}else{if(u._transactions.nist[a.via_branch])return!1;for(const t in u._transactions.nist)if(Object.prototype.hasOwnProperty.call(u._transactions.nist,t)&&(r=u._transactions.nist[t],r.request.from_tag===e&&r.request.call_id===n&&r.request.cseq===s))return d(482),!1}}],l=[function(){if(a.getHeaders("via").length>1)return r.debug("more than one Via header field present in the response, dropping the response"),!1},function(){if(s.str_utf8_length(a.body)<a.getHeader("content-length"))return r.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}];let a,u,c;function d(e){const n=a.getHeaders("via");let r,i=`SIP/2.0 ${e} ${t.REASON_PHRASE[e]}\r\n`;for(const t of n)i+=`Via: ${t}\r\n`;r=a.getHeader("To"),a.to_tag||(r+=`;tag=${s.newTag()}`),i+=`To: ${r}\r\n`,i+=`From: ${a.getHeader("From")}\r\n`,i+=`Call-ID: ${a.call_id}\r\n`,i+=`CSeq: ${a.cseq} ${a.method}\r\n`,i+="\r\n",c.send(i)}return je=(e,t,s)=>{a=e,u=t,c=s;for(const n of i)if(!1===n())return!1;if(a instanceof n.IncomingRequest){for(const n of o)if(!1===n())return!1}else if(a instanceof n.IncomingResponse)for(const n of l)if(!1===n())return!1;return!0}}(),E=function(){if(We)return Ze;We=1;const e=R(),t=h(),n=A(),s=v(),r=ke(),i=d();Ze.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:t.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,register_from_tag_trail:"",registrar_server:null,sockets:null,connection_recovery_max_interval:t.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:t.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${e.createRandomToken(12)}.invalid`};const o={mandatory:{sockets(e){const t=[];if(r.isSocket(e))t.push({socket:e});else{if(!Array.isArray(e)||!e.length)return;for(const n of e)Object.prototype.hasOwnProperty.call(n,"socket")&&r.isSocket(n.socket)?t.push(n):r.isSocket(n)&&t.push({socket:n})}return t},uri(e){/^sip:/i.test(e)||(e=`${t.SIP}:${e}`);const n=s.parse(e);return n&&n.user?n:void 0}},optional:{authorization_user:e=>-1===n.parse(`"${e}"`,"quoted_string")?void 0:e,authorization_jwt(e){if("string"==typeof e)return e},user_agent(e){if("string"==typeof e)return e},connection_recovery_max_interval(t){if(e.isDecimal(t)){const e=Number(t);if(e>0)return e}},connection_recovery_min_interval(t){if(e.isDecimal(t)){const e=Number(t);if(e>0)return e}},contact_uri(e){if("string"==typeof e){const t=n.parse(e,"SIP_URI");if(-1!==t)return t}},display_name:e=>e,instance_id:e=>(/^uuid:/i.test(e)&&(e=e.substr(5)),-1===n.parse(e,"uuid")?void 0:e),no_answer_timeout(t){if(e.isDecimal(t)){const e=Number(t);if(e>0)return e}},session_timers(e){if("boolean"==typeof e)return e},session_timers_refresh_method(e){if("string"==typeof e&&((e=e.toUpperCase())===t.INVITE||e===t.UPDATE))return e},session_timers_force_refresher(e){if("boolean"==typeof e)return e},password:e=>String(e),realm:e=>String(e),ha1:e=>String(e),register(e){if("boolean"==typeof e)return e},register_expires(t){if(e.isDecimal(t)){const e=Number(t);if(e>=0)return e}},register_from_tag_trail:e=>"function"==typeof e?e:String(e),registrar_server(e){/^sip:/i.test(e)||(e=`${t.SIP}:${e}`);const n=s.parse(e);return n?n.user?void 0:n:void 0},use_preloaded_route(e){if("boolean"==typeof e)return e},extra_headers(e){const t=[];if(Array.isArray(e)&&e.length){for(const n of e)"string"==typeof n&&t.push(n);return t}}}};return Ze.load=(t,n)=>{for(const e in o.mandatory){if(!n.hasOwnProperty(e))throw new i.ConfigurationError(e);{const s=n[e],r=o.mandatory[e](s);if(void 0===r)throw new i.ConfigurationError(e,s);t[e]=r}}for(const s in o.optional)if(n.hasOwnProperty(s)){const r=n[s];if(e.isEmpty(r))continue;const l=o.optional[s](r);if(void 0===l)throw new i.ConfigurationError(s,r);t[s]=l}},Ze}(),S=new t("UA"),C={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};function I(e){this.emit("connecting",e)}function b(e){this._status!==C.STATUS_USER_CLOSED&&(this._status=C.STATUS_READY,this._error=null,this.emit("connected",e),this._dynConfiguration.register&&this._registrator.register())}function y(e){const t=["nict","ict","nist","ist"];for(const n of t)for(const e in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],e)&&this._transactions[n][e].onTransportError();this.emit("disconnected",e),this._registrator.onTransportClosed(),this._status!==C.STATUS_USER_CLOSED&&(this._status=C.STATUS_NOT_READY,this._error=C.NETWORK_ERROR)}function N(e){const t=e.transport;let s=e.message;if(s=m.parseMessage(s,this),s&&!(this._status===C.STATUS_USER_CLOSED&&s instanceof g.IncomingRequest)&&T(s,this,t))if(s instanceof g.IncomingRequest)s.transport=t,this.receiveRequest(s);else if(s instanceof g.IncomingResponse){let e;switch(s.method){case n.INVITE:e=this._transactions.ict[s.via_branch],e&&e.receiveResponse(s);break;case n.ACK:break;default:e=this._transactions.nict[s.via_branch],e&&e.receiveResponse(s)}}}return Ye=class extends e{static get C(){return C}constructor(e){if(!e)throw new TypeError("Not enough arguments");const t=["password","ha1","authorization_jwt"];S.debug("new() [configuration:%o]",Object.entries(e).filter(([e])=>!t.includes(e))),super(),this._cache={credentials:{}},this._configuration=Object.assign({},E.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=C.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null;try{this._loadConfig(e)}catch(n){throw this._status=C.STATUS_NOT_READY,this._error=C.CONFIGURATION_ERROR,n}this._registrator=new s(this)}get C(){return C}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){S.debug("start()"),this._status===C.STATUS_INIT?this._transport.connect():this._status===C.STATUS_USER_CLOSED?(S.debug("restarting UA"),null!==this._closeTimer&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=C.STATUS_INIT,this._transport.connect()):this._status===C.STATUS_READY?S.debug("UA is in READY status, not restarted"):S.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){S.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(e){S.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){S.debug("call()");const n=new r(this);return n.connect(e,t),n}sendMessage(e,t,n){S.debug("sendMessage()");const s=new l(this);return s.send(e,t,n),s}subscribe(e,t,n,s){return S.debug("subscribe()"),new i(this,e,t,n,s)}notify(e,t,n){return S.debug("notify()"),new o(this,e,t,n)}sendOptions(e,t,n){S.debug("sendOptions()");const s=new a(this);return s.send(e,t,n),s}terminateSessions(e){S.debug("terminateSessions()");for(const t in this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}stop(){if(S.debug("stop()"),this._dynConfiguration={},this._status===C.STATUS_USER_CLOSED)return void S.debug("UA already closed");this._registrator.close();const e=Object.keys(this._sessions).length;for(const n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){S.debug(`closing session ${n}`);try{this._sessions[n].terminate()}catch(t){}}for(const n in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,n))try{this._applicants[n].close()}catch(t){}this._status=C.STATUS_USER_CLOSED;0===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?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(e){return _.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:return void S.warn('get() | cannot get "%s" parameter in runtime',e)}}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;case"extra_headers":this._configuration.extra_headers=t;break;default:return S.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)return S.debug("Request-URI does not point to us"),void(e.method!==n.ACK&&e.reply_sl(404));if(e.ruri.scheme===n.SIPS)return void e.reply_sl(416);if(u.checkTransaction(this,e))return;if(t===n.INVITE?new u.InviteServerTransaction(this,this._transport,e):t!==n.ACK&&t!==n.CANCEL&&new u.NonInviteServerTransaction(this,this._transport,e),t===n.OPTIONS){if(0===this.listeners("newOptions").length)return void e.reply(200);new a(this).init_incoming(e)}else if(t===n.MESSAGE){if(0===this.listeners("newMessage").length)return void e.reply(405);new l(this).init_incoming(e)}else if(t===n.SUBSCRIBE){if(0===this.listeners("newSubscribe").length)return void e.reply(405)}else if(t===n.INVITE&&!e.to_tag&&0===this.listeners("newRTCSession").length)return void e.reply(405);let s,i;if(e.to_tag)s=this._findDialog(e.call_id,e.from_tag,e.to_tag),s?s.receiveRequest(e):t===n.NOTIFY?(i=this._findSession(e),i?i.receiveRequest(e):(S.debug("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist"))):t!==n.ACK&&e.reply(481);else switch(t){case n.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){const t=e.replaces;s=this._findDialog(t.call_id,t.from_tag,t.to_tag),s?(i=s.owner,i.isEnded()?e.reply(603):i.receiveRequest(e)):e.reply(481)}else i=new r(this),i.init_incoming(e);else S.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case n.BYE:e.reply(481);break;case n.CANCEL:i=this._findSession(e),i?i.receiveRequest(e):S.debug("received CANCEL request for a non existent session");break;case n.ACK:break;case n.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;case n.SUBSCRIBE:o.init_incoming(e,()=>{this.emit("newSubscribe",{event:e.event,request:e})});break;default:e.reply(405)}}_findSession({call_id:e,from_tag:t,to_tag:n}){const s=e+t,r=this._sessions[s],i=e+n,o=this._sessions[i];return r||(o||null)}_findDialog(e,t,n){let s=e+t+n,r=this._dialogs[s];return r||(s=e+n+t,r=this._dialogs[s],r||null)}_loadConfig(e){E.load(this._configuration,e),0===this._configuration.display_name&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=_.newUUID()),this._configuration.jssip_id=_.createRandomToken(5);const t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new c(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=I.bind(this),this._transport.onconnect=b.bind(this),this._transport.ondisconnect=y.bind(this),this._transport.ondata=N.bind(this)}catch(s){throw S.warn(s),new p.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new f("sip",_.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(e={}){const t=e.anonymous||null,n=e.outbound||null;let s="<";return s+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(s+=";ob"),s+=">",s}};const n=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register","extra_headers"];for(const r in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,r)&&(-1!==n.indexOf(r)?Object.defineProperty(this._configuration,r,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,r,{writable:!1,configurable:!1}));S.debug("configuration parameters after validation:");for(const r in this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,r))switch(r){case"uri":case"registrar_server":S.debug(`- ${r}: ${this._configuration[r]}`);break;case"password":case"ha1":case"authorization_jwt":S.debug(`- ${r}: NOT SHOWN`);break;default:S.debug(`- ${r}: ${JSON.stringify(this._configuration[r])}`)}}}}var tt=function(){if(Je)return Qe;Je=1;const e=o,t=h(),n=d(),s=R(),r=et(),i=v(),l=C(),a=A(),u=function(){if(Xe)return Ke;Xe=1;const e=H(),t=A(),n=new e("WebSocketInterface");return Ke=class{constructor(e){n.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;const s=t.parse(e,"absoluteURI");if(-1===s)throw n.warn(`invalid WebSocket URI: ${e}`),new TypeError(`Invalid argument: ${e}`);if("wss"!==s.scheme&&"ws"!==s.scheme)throw n.warn(`invalid WebSocket URI scheme: ${s.scheme}`),new TypeError(`Invalid argument: ${e}`);this._sip_uri=`sip:${s.host}${s.port?`:${s.port}`:""};transport=ws`,this._via_transport=s.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(e){this._via_transport=e.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(n.debug("connect()"),this.isConnected())n.debug(`WebSocket ${this._url} is already connected`);else if(this.isConnecting())n.debug(`WebSocket ${this._url} is connecting`);else{this._ws&&this.disconnect(),n.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(){n.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 n.debug("send()"),this.isConnected()?(this._ws.send(e),!0):(n.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(){n.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:e,code:t,reason:s}){n.debug(`WebSocket ${this._url} closed`),!1===e&&n.debug("WebSocket abrupt disconnection"),this.ondisconnect(!e,t,s)}_onMessage({data:e}){n.debug("received WebSocket message"),this.ondata(e)}_onError(e){n.warn(`WebSocket ${this._url} error: `,e)}}}(),c=$()("JsSIP"),_=qe();return c("version %s",e.version),Qe={C:t,Exceptions:n,Utils:s,UA:r,URI:i,NameAddrHeader:l,WebSocketInterface:u,Grammar:a,RTCSession:_,debug:$(),get name(){return e.title},get version(){return e.version}}}(),nt=w();class st extends nt.EventEmitter{constructor(){super(),this.setMaxListeners(50)}on(e,t){return super.on(e,t),this}off(e,t){return super.off(e,t),this}emit(e,...t){return super.emit(e,...t)}removeAllListeners(e){return super.removeAllListeners(e)}once(e,t){return super.once(e,t)}listenerCount(e){return super.listenerCount(e)}listeners(e){return super.listeners(e)}}const rt={CONNECTING:"connecting",CONNECTED:"connected",DISCONNECTED:"disconnected",REGISTERED:"registered",UNREGISTERED:"unregistered",RINGING:"ringing",ANSWERED:"answered",ENDED:"ended",FAILED:"failed",MUTED:"muted",UNMUTED:"unmuted",AUDIO_ENDED:"audioEnded",INFO_SENT:"infoSent",ERROR:"error",SESSION_CREATED:"sessionCreated",SESSION_UPDATED:"sessionUpdated",SESSION_DESTROYED:"sessionDestroyed",INFO_RECEIVED:"infoReceived",TRANSCRIPTION:"transcription",CAPTURE_AUDIO:"captureAudio"};class it extends st{constructor(){super(...arguments),this.ua=null,this.state={ua:null,connected:!1,registered:!1,connecting:!1}}initialize(e,t){this.ua&&this.stop(),this.pcConfig=t.pcConfig,console.log("Creating SIP client with config:",{client:e,settings:t},t.pcConfig);const n=new tt.WebSocketInterface(t.wsUri),s={uri:`sip:${e.fullUsername}`,password:e.password,authorization_user:e.username,sockets:[n],register:!0};this.ua=new tt.UA(s),this.state.ua=this.ua,this.setupEventHandlers()}setupEventHandlers(){this.ua&&(["connecting","connected","disconnected"].forEach(e=>{this.ua?.on(e,t=>{console.log(`SIP ${e}:`,t),"connected"===e?(this.state.connected=!0,this.state.connecting=!1):"disconnected"===e?(this.state.connected=!1,this.state.registered=!1,this.state.connecting=!1):"connecting"===e&&(this.state.connecting=!0),this.emit(rt[e.toUpperCase()],t)})}),this.ua.on("registered",e=>{console.log("SIP registered:",e),this.state.registered=!0,this.emit(rt.REGISTERED,e)}),this.ua.on("unregistered",e=>{console.log("SIP unregistered:",e),this.state.registered=!1,this.emit(rt.UNREGISTERED,e)}),this.ua.on("newRTCSession",e=>{const t=e.session;this.handleNewSession(t),this.emit("newRTCSession",t)}),this.ua.on("registrationFailed",e=>{console.error("SIP registration failed:",e),this.emit(rt.ERROR,new Error(`Registration failed: ${e.cause}`))}))}handleNewSession(e){e.data||(e.data={}),e.data.sessionId||(e.data.sessionId=t("session"));const n=e.sendInfo;e.sendInfo=(t,s)=>{try{n.call(e,"application/json",JSON.stringify({text:t,data:s})),this.emit(rt.INFO_SENT,t,s)}catch(r){console.error("Failed to send info:",r),this.emit(rt.ERROR,new Error(`Failed to send info: ${r}`))}},this.emit(rt.SESSION_CREATED,e)}start(){if(!this.ua)throw new Error("SIP manager not initialized");console.log("Starting SIP user agent"),this.state.connecting=!0,this.ua.start()}stop(){this.ua&&(console.log("Stopping SIP user agent"),this.ua.stop(),this.ua=null,this.state={ua:null,connected:!1,registered:!1,connecting:!1})}call(e,n){if(!this.ua)throw new Error("SIP manager not initialized");if(!this.state.registered)throw new Error("SIP client not registered");console.log(`Making call to: ${e}`);try{this.ua.call(e,{data:{originalNumber:n||e,sessionId:t("call")},mediaConstraints:{audio:!0,video:!1},pcConfig:this.pcConfig,extraHeaders:["X-Source: webrtc"]})}catch(s){throw console.error("Failed to make call:",s),this.emit(rt.ERROR,new Error(`Failed to make call: ${s}`)),s}}getState(){return{...this.state}}isConnected(){return this.state.connected}isRegistered(){return this.state.registered}isConnecting(){return this.state.connecting}getUserAgent(){return this.ua}destroy(){this.stop(),this.removeAllListeners()}}class ot extends st{constructor(e){super(),this.sessions=new Map,this.activeSessionId=null}setAudioManager(e){this.audioManager=e}createSession(e){const n=e.data?.sessionId||t("session"),s={id:n,startTime:new Date,status:"init",active:!1,endInfo:{originator:null,cause:null,description:null},muted:!1,localHold:!1,remoteHold:!1,doingAttendedTransfer:!1,autoMerge:!1,rtcSession:e};return this.sessions.set(n,s),this.setupSessionEventHandlers(s),this.emit(rt.SESSION_CREATED,this.getPublicSession(s)),n}setupSessionEventHandlers(e){const{rtcSession:t}=e;t.on("connecting",()=>{this.updateSession(e),this.emit(rt.CONNECTING,this.getPublicSession(e))}),t.on("progress",()=>{e.status="ringing",this.updateSession(e),this.emit(rt.RINGING,this.getPublicSession(e))}),t.on("accepted",()=>{e.status="answered",this.setActiveSession(e.id),this.updateSession(e),this.emit(rt.ANSWERED,this.getPublicSession(e))}),t.on("failed",t=>{this.handleSessionEnd(e,t,"failed")}),t.on("ended",t=>{this.handleSessionEnd(e,t,"ended")}),t.on("muted",()=>{e.muted=!0,this.updateSession(e),this.emit(rt.MUTED,this.getPublicSession(e))}),t.on("unmuted",()=>{e.muted=!1,this.updateSession(e),this.emit(rt.UNMUTED,this.getPublicSession(e))}),t.on("hold",t=>{"local"===t.originator?e.localHold=!0:"remote"===t.originator&&(e.remoteHold=!0),this.updateSession(e)}),t.on("unhold",t=>{"local"===t.originator?e.localHold=!1:"remote"===t.originator&&(e.remoteHold=!1),this.updateSession(e)}),t.on("sdp",e=>{e.sdp.includes("opus")&&e.sdp.includes("stereo=1")&&(e.sdp=e.sdp.replace("stereo=1","stereo=0"))}),t.on("newInfo",this.handleNewInfo.bind(this)),this.setupPeerConnectionHandlers(e)}handleNewInfo(e){const{originator:t,info:n}=e;try{if("remote"===t){const e=JSON.parse(n.body);if(Object.hasOwn(e,"_transcription"))return void this.emit(rt.TRANSCRIPTION,e._transcription)}this.emit(rt.INFO_RECEIVED,e)}catch(s){this.emit(rt.INFO_RECEIVED,e)}}setupPeerConnectionHandlers(e){const{rtcSession:t}=e,n=e=>{e.addEventListener("track",e=>{const t=e.track,n=new MediaStream;n.addTrack(t),this.audioManager&&this.audioManager.handleRemoteStream(n)})};t._connection?n(t._connection):t.on("peerconnection",e=>{const t=e.peerconnection;n(t)})}handleSessionEnd(e,t,n){const{originator:s,cause:r,message:i}=t;let o=null;if(i&&"remote"===s)if("failed"===n&&i.status_code)o=`${i.status_code}`.trim();else if("ended"===n&&i.hasHeader&&i.hasHeader("Reason")){const e=tt.Grammar.parse(i.getHeader("Reason"),"Reason");e&&(o=`${e.cause}`.trim())}e.endInfo={originator:s,cause:r,description:o},e.status=n,e.active=!1,this.activeSessionId===e.id&&(this.activeSessionId=null),this.updateSession(e);const l=this.getPublicSession(e);"failed"===n?this.emit(rt.FAILED,l,e.endInfo):this.emit(rt.ENDED,l,e.endInfo),this.emit(rt.AUDIO_ENDED),setTimeout(()=>{this.removeSession(e.id)},5e3)}updateSession(e){this.sessions.set(e.id,e),this.emit(rt.SESSION_UPDATED,this.getPublicSession(e))}getPublicSession(e){return{id:e.id,status:e.status,direction:"outgoing"===e.rtcSession.direction?"outgoing":"incoming",startTime:e.startTime,answerTime:e.rtcSession.start_time||void 0,duration:this.calculateDuration(e),muted:e.muted,localHold:e.localHold,remoteHold:e.remoteHold}}calculateDuration(e){if(!e.rtcSession.start_time)return 0;const t=new Date;return Math.floor((t.getTime()-e.rtcSession.start_time.getTime())/1e3)}setActiveSession(e){const t=this.sessions.get(e);if(!t)throw new Error(`Session not found: ${e}`);if(this.activeSessionId&&this.activeSessionId!==e){const e=this.sessions.get(this.activeSessionId);e&&(e.active=!1,e.rtcSession.isEstablished()&&!e.localHold&&e.rtcSession.hold())}t.active=!0,this.activeSessionId=e,t.rtcSession.isEstablished()&&t.localHold&&t.rtcSession.unhold(),this.updateSession(t)}getActiveSession(){if(!this.activeSessionId)return null;const e=this.sessions.get(this.activeSessionId);return e?this.getPublicSession(e):null}getSession(e){const t=this.sessions.get(e);return t?this.getPublicSession(t):null}getAllSessions(){return Array.from(this.sessions.values()).map(e=>this.getPublicSession(e))}mute(){const e=this.getActiveSessionState();if(!e)throw new Error("No active session to mute");if(!e.rtcSession.isEstablished())throw new Error("Session not established");e.rtcSession.mute({audio:!0,video:!0})}unmute(){const e=this.getActiveSessionState();e?.rtcSession?.isEstablished()&&e.rtcSession.unmute({audio:!0,video:!0})}sendInfo(e,t={}){const n=this.getActiveSessionState();if(!n?.rtcSession?.isEstablished())throw new Error("No active session to send info");n.rtcSession.sendInfo(e,t),this.emit(rt.INFO_SENT,e,t)}terminate(e=480,t="Ended by user"){const n=this.getActiveSessionState();if(!n)throw new Error("No active session to terminate");n.rtcSession.terminate({status_code:e,reason_phrase:t})}getActiveSessionState(){return this.activeSessionId&&this.sessions.get(this.activeSessionId)||null}removeSession(e){this.sessions.delete(e),this.activeSessionId===e&&(this.activeSessionId=null),this.emit(rt.SESSION_DESTROYED,e)}destroy(){for(const e of this.sessions.values())e.rtcSession&&!e.rtcSession.isEnded()&&e.rtcSession.terminate();this.sessions.clear(),this.activeSessionId=null,this.removeAllListeners()}}class lt extends st{constructor(){super(),this.state={remoteAudio:null,currentStream:null,captureAudio:!1},this.initializeDefaultAudio()}initializeDefaultAudio(){"undefined"!=typeof window?(this.state.remoteAudio=new Audio,this.state.remoteAudio.autoplay=!0,this.state.remoteAudio.volume=1,this.state.remoteAudio.onplaying=()=>{console.log("Default audio started playing"),this.emit("audioStarted")},this.state.remoteAudio.onpause=()=>{console.log("Default audio paused"),this.emit("audioPaused")},this.state.remoteAudio.onerror=e=>{console.error("Default audio error:",e),this.emit(rt.ERROR,new Error("Audio playback error"))},this.state.remoteAudio.onended=()=>{console.log("Default audio ended"),this.emit("audioEnded")}):console.warn("AudioManager: Window not available, skipping default audio initialization")}handleRemoteStream(e){console.log("AudioManager: Handling remote stream",e),this.state.currentStream=e,this.playDefaultAudio(e),this.state.captureAudio&&this.emit(rt.CAPTURE_AUDIO,e)}playDefaultAudio(e){if(!this.state.remoteAudio)return void console.warn("AudioManager: Default audio element not initialized");if(0!==e.getAudioTracks().length)try{this.state.remoteAudio.srcObject=e;const t=this.state.remoteAudio.play();t instanceof Promise&&t.then(()=>{console.log("AudioManager: Default audio started successfully")}).catch(e=>{console.error("AudioManager: Failed to start default audio:",e),this.emit(rt.ERROR,new Error(`Audio playback failed: ${e.message}`))})}catch(t){console.error("AudioManager: Error setting up default audio:",t),this.emit(rt.ERROR,new Error(`Audio setup failed: ${t}`))}else console.warn("AudioManager: Stream has no audio tracks, skipping audio setup")}stopAudio(){console.log("AudioManager: Stopping audio"),this.state.remoteAudio&&"function"==typeof this.state.remoteAudio.pause&&(this.state.remoteAudio.pause(),this.state.remoteAudio.srcObject=null),this.state.currentStream&&(this.state.currentStream.getTracks().forEach(e=>{e.stop()}),this.state.currentStream=null),this.emit(rt.AUDIO_ENDED)}setVolume(e){if(e<0||e>1||Number.isNaN(e))throw new Error("Volume must be between 0 and 1");this.state.remoteAudio&&void 0!==this.state.remoteAudio.volume&&(this.state.remoteAudio.volume=e)}getVolume(){return this.state.remoteAudio&&void 0!==this.state.remoteAudio.volume?this.state.remoteAudio.volume:1}setMuted(e){this.state.remoteAudio&&void 0!==this.state.remoteAudio.muted&&(this.state.remoteAudio.muted=e)}isMuted(){return!(!this.state.remoteAudio||void 0===this.state.remoteAudio.muted)&&this.state.remoteAudio.muted}getCurrentStream(){return this.state.currentStream}setCaptureAudio(e){this.state.captureAudio=e}getState(){return{hasRemoteAudio:!!this.state.remoteAudio,hasCurrentStream:!!this.state.currentStream,volume:this.getVolume(),muted:this.isMuted()}}destroy(){this.stopAudio(),this.state.remoteAudio&&(this.state.remoteAudio.onplaying=null,this.state.remoteAudio.onpause=null,this.state.remoteAudio.onerror=null,this.state.remoteAudio.onended=null,this.state.remoteAudio=null),this.removeAllListeners(rt.AUDIO_ENDED),this.removeAllListeners(rt.ERROR),this.removeAllListeners()}}class at extends st{constructor(e){if(super(),this.isInitialized=!1,this.isDestroyed=!1,!n())throw new Error("WebRTC is not supported in this environment");this.configManager=new i(e.endpointUrl,e?.userId||void 0),this.sipManager=new it,this.sessionManager=new ot(e.pcConfig),this.audioManager=new lt,this.sessionManager.setAudioManager(this.audioManager),e.captureAudio&&this.audioManager.setCaptureAudio(!0),this.setupEventHandlers()}setupEventHandlers(){this.sipManager.on(rt.CONNECTING,()=>{this.emit(rt.CONNECTING)}),this.sipManager.on(rt.CONNECTED,()=>{this.emit(rt.CONNECTED)}),this.sipManager.on(rt.DISCONNECTED,()=>{this.emit(rt.DISCONNECTED)}),this.sipManager.on(rt.REGISTERED,()=>{this.emit(rt.REGISTERED)}),this.sipManager.on(rt.UNREGISTERED,()=>{this.emit(rt.UNREGISTERED)}),this.sipManager.on("newRTCSession",e=>{this.sessionManager.createSession(e)}),this.sipManager.on(rt.ERROR,e=>{this.emit(rt.ERROR,e)}),this.sessionManager.on(rt.RINGING,e=>{this.emit(rt.RINGING,e)}),this.sessionManager.on(rt.ANSWERED,e=>{this.emit(rt.ANSWERED,e)}),this.sessionManager.on(rt.ENDED,(e,t)=>{this.audioManager.stopAudio(),this.emit(rt.ENDED,e,t)}),this.sessionManager.on(rt.FAILED,(e,t)=>{this.audioManager.stopAudio(),this.emit(rt.FAILED,e,t)}),this.sessionManager.on(rt.MUTED,e=>{this.emit(rt.MUTED,e)}),this.sessionManager.on(rt.UNMUTED,e=>{this.emit(rt.UNMUTED,e)}),this.sessionManager.on(rt.INFO_SENT,(e,t)=>{this.emit(rt.INFO_SENT,e,t)}),this.sessionManager.on(rt.INFO_RECEIVED,e=>{this.emit(rt.INFO_RECEIVED,e)}),this.sessionManager.on(rt.TRANSCRIPTION,e=>{this.emit(rt.TRANSCRIPTION,e)}),this.audioManager.on(rt.AUDIO_ENDED,()=>{this.emit(rt.AUDIO_ENDED)}),this.audioManager.on(rt.ERROR,e=>{this.emit(rt.ERROR,e)}),this.audioManager.on(rt.CAPTURE_AUDIO,e=>{this.emit(rt.CAPTURE_AUDIO,e)})}async connect(){if(this.isDestroyed)throw new Error("Client has been destroyed");try{await this.configManager.fetchConfig();if(!this.configManager.isActive())throw new Error("WebRTC widget is not active in the configuration");const e=this.configManager.getSipCredentials();this.sipManager.initialize({fullUsername:e.fullUsername,password:e.password,username:e.username},{wsUri:e.wsUri,pcConfig:this.configManager.getPeerConnectionConfig()}),this.sipManager.start(),await r(new Promise((e,t)=>{let n=!1,s=!1;const r=()=>{n=!0,s&&(this.sipManager.off(rt.CONNECTED,r),this.sipManager.off(rt.REGISTERED,i),this.sipManager.off(rt.ERROR,o),this.isInitialized=!0,e())},i=()=>{s=!0,n&&(this.sipManager.off(rt.CONNECTED,r),this.sipManager.off(rt.REGISTERED,i),this.sipManager.off(rt.ERROR,o),this.isInitialized=!0,e())},o=e=>{this.sipManager.off(rt.CONNECTED,r),this.sipManager.off(rt.REGISTERED,i),this.sipManager.off(rt.ERROR,o),t(e)};this.sipManager.on(rt.CONNECTED,r),this.sipManager.on(rt.REGISTERED,i),this.sipManager.on(rt.ERROR,o)}),15e3)}catch(e){throw new Error(`Failed to connect: ${e instanceof Error?e.message:"Unknown error"}`)}}async disconnect(){if(this.isInitialized)try{this.audioManager.stopAudio(),this.sessionManager.destroy(),this.sipManager.stop(),this.isInitialized=!1}catch(e){throw console.error("Error during disconnect:",e),new Error(`Failed to disconnect: ${e instanceof Error?e.message:"Unknown error"}`)}}async startCall(){if(!this.isInitialized)throw new Error("Client not connected. Call connect() first.");if(!this.sipManager.isRegistered())throw new Error("SIP client not registered");try{const e=`app-${this.configManager.getApplicationSid()}`;this.sipManager.call(e)}catch(e){throw new Error(`Failed to start call: ${e instanceof Error?e.message:"Unknown error"}`)}}async endCall(){try{this.sessionManager.terminate()}catch(e){throw new Error(`Failed to end call: ${e instanceof Error?e.message:"Unknown error"}`)}}async mute(){try{this.sessionManager.mute()}catch(e){throw new Error(`Failed to mute call: ${e instanceof Error?e.message:"Unknown error"}`)}}async unmute(){try{this.sessionManager.unmute()}catch(e){throw new Error(`Failed to unmute call: ${e instanceof Error?e.message:"Unknown error"}`)}}async connectAndCall(){await this.connect(),await this.startCall()}async sendInfo(e,t={}){try{this.sessionManager.sendInfo(e,t)}catch(n){throw new Error(`Failed to send info: ${n instanceof Error?n.message:"Unknown error"}`)}}on(e,t){return super.on(e,t),this}off(e,t){return super.off(e,t),this}isConnected(){return this.isInitialized&&this.sipManager.isRegistered()}getCurrentSession(){return this.sessionManager.getActiveSession()}async destroy(){if(!this.isDestroyed)try{await this.disconnect(),this.audioManager.destroy(),this.sessionManager.destroy(),this.sipManager.destroy(),this.configManager.clearConfig(),this.removeAllListeners(),this.isDestroyed=!0}catch(e){throw console.error("Error during destroy:",e),new Error(`Failed to destroy client: ${e instanceof Error?e.message:"Unknown error"}`)}}getStatus(){return{connected:this.sipManager.isConnected(),registered:this.sipManager.isRegistered(),activeSession:this.getCurrentSession(),audioState:this.audioManager.getState()}}}e.SDK_NAME="@cognigy/webrtc-sdk",e.VERSION="1.0.0",e.WebRTCClient=at,e.checkWebRTCSupport=function(){const e=[];return"undefined"==typeof window?e.push("window"):(window.RTCPeerConnection||e.push("RTCPeerConnection"),window.navigator?window.navigator.mediaDevices?window.navigator.mediaDevices.getUserMedia||e.push("navigator.mediaDevices.getUserMedia"):e.push("navigator.mediaDevices"):e.push("navigator")),{supported:0===e.length,missing:e}},e.createWebRTCClient=async function(e){if(!e.endpointUrl)throw new Error("endpointUrl is required");if(!n())throw new Error("WebRTC is not supported in this environment");return new at(e)},e.isWebRTCSupported=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
+ //# sourceMappingURL=webRTCSDK.js.map