@16x/webphone-sdk 3.1.8 → 3.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,12 +1,12 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CCBarSDK={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},u=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},d=(e,r,i)=>(i=e==null?{}:t(a(e)),u(r||!e||!e.__esModule||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e)),f=e=>o.call(e,`module.exports`)?e[`module.exports`]:u(n({},`__esModule`,{value:!0}),e),p,m=s((()=>{p=class extends Error{code;category;retryable;requestId;callId;cause;serverCode;status;constructor(e,t,n,r={}){super(e),this.name=`CCBarError`,this.code=e,this.category=t,this.retryable=n,this.requestId=r.requestId,this.callId=r.callId,this.cause=r.cause,this.serverCode=r.serverCode,this.status=r.status}}}));m();var h=class{handlers=new Map;on(e,t){let n=this.handlers.get(e)??new Set;n.add(t),this.handlers.set(e,n);let r=!0;return()=>{r&&(r=!1,n.delete(t))}}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){[...this.handlers.get(e)??[]].forEach(e=>{try{e(t)}catch{}})}listenerCount(){return[...this.handlers.values()].reduce((e,t)=>e+t.size,0)}clear(){this.handlers.clear()}},g={new:new Set([`dialing`,`ringing`,`failed`]),dialing:new Set([`ringing`,`connecting`,`ended`,`failed`]),ringing:new Set([`connecting`,`ended`,`failed`]),connecting:new Set([`active`,`ended`,`failed`]),active:new Set([`held`,`ended`,`failed`]),held:new Set([`active`,`ended`,`failed`]),ended:new Set,failed:new Set},_=(e,t)=>g[e].has(t);function v(e,t){if(!_(e,t))throw new y(e,t);return t}var y=class extends p{constructor(e,t){super(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:{from:e,to:t}})}},b=v,x=60,S=class{tokenProvider;cachedToken;cachedRequestKey=``;refreshing;generation=0;constructor(e){this.tokenProvider=e}getValidToken(e){let t=e?.extension?.trim()??``;if(this.cachedToken&&this.cachedRequestKey===t&&!this.needsRefresh(this.cachedToken))return Promise.resolve(this.cachedToken.accessToken);if(!this.refreshing){let n=this.generation,r=this.refresh(e,t,n);this.refreshing=r,r.then(()=>this.clearRefresh(r),()=>this.clearRefresh(r))}return this.refreshing}invalidate(){this.generation+=1,this.cachedToken=void 0,this.cachedRequestKey=``,this.refreshing=void 0}needsRefresh(e){return e.expiresAt!==void 0&&e.expiresAt<=Math.floor(Date.now()/1e3)+x}async refresh(e,t,n){let r=await this.tokenProvider(e),i=typeof r==`string`?{accessToken:r}:r;return n===this.generation&&(this.cachedToken=i,this.cachedRequestKey=t),i.accessToken}clearRefresh(e){this.refreshing===e&&(this.refreshing=void 0)}};function C(e){if(e.code!==`OK`)throw TypeError(`Unexpected session response code: ${e.code}`);if(e.data===void 0||e.data===null)throw TypeError(`Unexpected session response: missing data`);return e.data}m();var w={ORIGIN_NOT_ALLOWED:{code:`CONFIG_ORIGIN_NOT_ALLOWED`,category:`configuration`,retryable:!1},CAPABILITY_DENIED:{code:`CAPABILITY_NOT_SUPPORTED`,category:`capability`,retryable:!1},TOKEN_INVALID:{code:`AUTH_TOKEN_UNAVAILABLE`,category:`auth`,retryable:!1},TOKEN_EXPIRED:{code:`AUTH_TOKEN_EXPIRED`,category:`auth`,retryable:!1},INVALID_ARGUMENT:{code:`CONFIG_INVALID`,category:`configuration`,retryable:!1},INVALID_EXTENSION:{code:`CONFIG_INVALID`,category:`configuration`,retryable:!1},SEAT_NOT_FOUND:{code:`AUTH_PERMISSION_DENIED`,category:`auth`,retryable:!1},SESSION_NOT_FOUND:{code:`CALL_NOT_CONNECTED`,category:`call`,retryable:!1},SESSION_EXPIRED:{code:`CALL_NOT_CONNECTED`,category:`call`,retryable:!1},SEAT_IN_USE:{code:`CALL_ALREADY_EXISTS`,category:`call`,retryable:!1},SESSION_CONFLICT:{code:`CALL_ALREADY_EXISTS`,category:`call`,retryable:!1},SEAT_NOT_ASSIGNED:{code:`AUTH_PERMISSION_DENIED`,category:`auth`,retryable:!1},QUEUE_NOT_ASSIGNED:{code:`CAPABILITY_NOT_SUPPORTED`,category:`capability`,retryable:!1},RATE_LIMITED:{code:`NETWORK_OFFLINE`,category:`network`,retryable:!0},SIP_GATEWAY_UNAVAILABLE:{code:`SIP_WS_UNAVAILABLE`,category:`registration`,retryable:!0},SERVICE_UNAVAILABLE:{code:`NETWORK_OFFLINE`,category:`network`,retryable:!0},INTERNAL_ERROR:{code:`SDK_INTERNAL_ERROR`,category:`internal`,retryable:!0}},T=class{tokenManager;fetcher;baseUrl;timeoutMs;constructor(e){this.tokenManager=new S(e.tokenProvider),this.fetcher=e.fetcher??fetch.bind(globalThis),this.baseUrl=e.baseUrl.replace(/\/$/,``),this.timeoutMs=e.timeoutMs??1e4}invalidateToken(){this.tokenManager.invalidate()}createSession(e){return this.request(`POST`,`/webphone/v1/sessions`,e).then(e=>this.requireData(e))}refreshSession(e,t={refresh:[`sip_register_ticket`,`wss_ticket`,`turn_credentials`]}){return this.request(`POST`,`/webphone/v1/sessions/${encodeURIComponent(e)}/refresh`,t).then(e=>this.requireData(e))}deleteSession(e){return this.request(`DELETE`,`/webphone/v1/sessions/${encodeURIComponent(e)}`).then(()=>void 0)}setAgentStatus(e){return this.request(`PUT`,`/webphone/v1/agents/me/status`,e).then(()=>void 0)}getCapabilities(){return this.request(`GET`,`/webphone/v1/capabilities`).then(e=>this.requireData(e))}async request(e,t,n){let r=new AbortController,i=setTimeout(()=>r.abort(),this.timeoutMs);try{let i=await this.tokenManager.getValidToken(),a=await this.fetcher(`${this.baseUrl}${t}`,{method:e,credentials:`omit`,headers:{Authorization:`Bearer ${i}`,...n===void 0?{}:{"Content-Type":`application/json`}},...n===void 0?{}:{body:JSON.stringify(n)},signal:r.signal}),o=await this.parseResponse(a);if(!a.ok||o.code!==`OK`)throw this.toCCBarError(a.status,o);return{data:o.data,requestId:o.requestId}}catch(e){throw e instanceof p?e:e instanceof DOMException&&e.name===`AbortError`?new p(`NETWORK_TIMEOUT`,`network`,!0,{cause:e}):new p(`NETWORK_OFFLINE`,`network`,!0,{cause:e})}finally{clearTimeout(i)}}requireData(e){if(e.data===void 0||e.data===null)throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{requestId:e.requestId});return e.data}async parseResponse(e){try{return await e.json()}catch(t){throw new p(`SDK_INTERNAL_ERROR`,`internal`,e.status>=500,{cause:t})}}toCCBarError(e,t){let n=w[t.code??``]??this.mapStatus(e);return new p(n.code,n.category,n.retryable,{requestId:t.requestId,serverCode:t.code,status:e})}mapStatus(e){return e===401?{code:`AUTH_TOKEN_EXPIRED`,category:`auth`,retryable:!1}:e===403?{code:`AUTH_PERMISSION_DENIED`,category:`auth`,retryable:!1}:e>=500?{code:`SDK_INTERNAL_ERROR`,category:`internal`,retryable:!0}:{code:`SDK_INTERNAL_ERROR`,category:`internal`,retryable:!1}}};m();var E=[`progress`,`accepted`,`confirmed`,`ended`,`failed`,`hold`,`unhold`,`mediaConnected`],D=3e4,O=class{options;currentState=`new`;sessionUnsubscribers=[];capabilities;disposed=!1;pendingOperation;incomingOperation;ownerTabId;ownerLost=!1;id;destination;platform;constructor(e){this.options=e,this.id=e.id,this.destination=e.destination,this.platform=e.platform,this.capabilities=e.capabilities??new Set;try{E.forEach(t=>{this.sessionUnsubscribers.push(e.session.on(t,e=>this.handleSessionEvent(t,e)))})}catch(t){this.cleanupSessionListeners();try{e.session.terminate()}catch{}throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:this.id,cause:t})}}get state(){return this.currentState}getResourceCounts(){return{timers:this.pendingOperation?.timer===void 0?0:1,listeners:this.sessionUnsubscribers.length}}async mute(e){this.assertNotDisposed(),this.assertOwner(e),this.assertMediaControlAllowed(),this.assertCapability(`mute`),this.invoke(()=>this.options.session.mute())}async unmute(e){this.assertNotDisposed(),this.assertOwner(e),this.assertMediaControlAllowed(),this.assertCapability(`mute`),this.invoke(()=>this.options.session.unmute())}async answer(e,t){this.assertNotDisposed(),this.assertOwner(t),this.assertIncomingCall(),this.assertCapability(`inbound`),this.assertIncomingOperationAvailable(),this.incomingOperation=`answer`;try{this.options.session.answer(e)}catch(e){throw this.incomingOperation=void 0,this.finishFailedIncomingOperation(e),this.operationError(e)}this.transitionIfAllowed(`connecting`,void 0,`accepted`)}async reject(e={},t){this.assertNotDisposed(),this.assertOwner(t),this.assertIncomingCall(),this.assertIncomingOperationAvailable(),this.incomingOperation=`reject`;let n;try{this.options.session.terminate()}catch(e){n=e}finally{this.incomingOperation=void 0,this.transitionIfStillRinging(`ended`,{reason:e.reason?.trim()||`rejected`})}if(n!==void 0)throw this.operationError(n)}async hold(e){this.assertNotDisposed(),this.assertOwner(e),this.assertHoldCapability(),this.assertState(`active`),this.assertCapability(`hold`),await this.startPendingOperation(`hold`,`held`,()=>this.options.session.hold())}async resume(e){this.assertNotDisposed(),this.assertOwner(e),this.assertHoldCapability(),this.assertState(`held`),this.assertCapability(`hold`),await this.startPendingOperation(`resume`,`active`,()=>this.options.session.unhold())}async sendDtmf(e,t){if(this.assertNotDisposed(),this.assertOwner(t),!/^[0-9A-D*#]$/.test(e))throw this.operationError();this.assertState(`active`),this.assertCapability(`dtmf`),this.invoke(()=>this.options.session.sendDtmf(e))}async transfer(e,t){if(this.assertNotDisposed(),this.assertOwner(t),this.assertTransferCapability(),this.assertState(`active`),this.assertCapability(`blind_transfer`),!A(e)||e.target.trim()===``)throw this.operationError();this.invoke(()=>this.options.session.refer(e.target.trim()))}async hangup(e){if(this.assertNotDisposed(),this.assertOwner(e),k(this.currentState))throw this.operationError();try{this.options.session.terminate(),k(this.currentState)||this.transitionTo(`ended`)}catch(e){throw this.operationError(e)}}beginOutbound(){this.assertNotDisposed(),this.assertCapability(`outbound`),this.transitionTo(`dialing`)}beginIncoming(){this.assertNotDisposed(),this.transitionTo(`ringing`)}setOwnerTabId(e){this.ownerTabId=e,this.ownerLost=!1}clearOwnerTabId(e={}){this.ownerTabId=void 0,this.ownerLost=e.lost===!0}getOwnerTabId(){return this.ownerTabId}assertOwnerForManager(e){this.assertOwner(e)}canBeReclaimed(){return this.currentState===`new`||this.currentState===`dialing`||this.currentState===`ringing`}dispose(){if(!this.disposed){if(this.rejectPendingOperation(),this.incomingOperation=void 0,this.disposed=!0,!k(this.currentState))try{this.options.session.terminate()}catch(e){this.reportOperationError(e)}this.cleanupSessionListeners();try{this.options.onDisposed?.()}catch{}}}handleSessionEvent(e,t){if((e===`accepted`||e===`confirmed`||e===`ended`||e===`failed`)&&(this.incomingOperation=void 0),!(this.disposed||k(this.currentState)))switch(e){case`progress`:this.transitionIfAllowed(`ringing`,t,e);break;case`accepted`:this.transitionIfAllowed(`connecting`,t,e);break;case`confirmed`:this.transitionToActive(t);break;case`mediaConnected`:this.currentState===`connecting`&&this.transitionTo(`active`,t);break;case`hold`:this.transitionIfAllowed(`held`,t,e);break;case`unhold`:this.transitionIfAllowed(`active`,t,e);break;case`ended`:this.transitionIfAllowed(`ended`,t,e);break;case`failed`:this.transitionIfAllowed(`failed`,t,e)}}transitionToActive(e){this.currentState!==`active`&&((this.currentState===`dialing`||this.currentState===`ringing`)&&this.transitionTo(`connecting`,e),this.transitionIfAllowed(`active`,e,`confirmed`))}transitionIfAllowed(e,t,n){this.currentState!==e&&(_(this.currentState,e)?this.transitionTo(e,t):this.reportIllegalTransition(e,n))}transitionIfStillRinging(e,t){this.currentState===`ringing`&&this.transitionTo(e,t)}transitionTo(e,t){if(this.currentState===e)return;if(!_(this.currentState,e))throw this.operationError();let n=this.currentState;this.currentState=e,k(e)&&this.rejectPendingOperation();try{this.options.onStateChanged?.({callId:this.id,from:n,to:e},t)}catch{}finally{k(e)&&this.dispose()}}startPendingOperation(e,t,n){if(this.pendingOperation!==void 0)throw this.operationError();return new Promise((r,i)=>{let a={kind:e,nextState:t,resolve:r,reject:i};this.pendingOperation=a,a.timer=setTimeout(()=>this.timeoutPendingOperation(a),D);let o;try{o=n()}catch(e){this.rejectPendingOperation(e);return}o.then(()=>this.resolvePendingOperation(a),e=>this.rejectPendingOperation(e,a))})}resolvePendingOperation(e){if(this.pendingOperation===e){if(this.clearPendingTimer(e),this.pendingOperation=void 0,this.disposed||k(this.currentState)){e.reject(this.operationError());return}try{this.transitionTo(e.nextState),e.resolve()}catch(t){e.reject(this.operationError(t))}}}rejectPendingOperation(e,t){let n=this.pendingOperation;n===void 0||t!==void 0&&n!==t||(this.clearPendingTimer(n),this.pendingOperation=void 0,n.reject(this.operationError(e)))}timeoutPendingOperation(e){this.pendingOperation===e&&(this.rejectPendingOperation(Error(`${e.kind} operation timed out`),e),this.dispose())}clearPendingTimer(e){e.timer!==void 0&&(clearTimeout(e.timer),e.timer=void 0)}reportIllegalTransition(e,t){this.reportOperationError({event:t,from:this.currentState,to:e})}reportOperationError(e){let t=e instanceof p&&e.callId===this.id?e:this.operationError(e);try{this.options.onError?.(t)}catch{}}finishFailedIncomingOperation(e){this.reportOperationError(e);try{this.options.session.terminate()}catch(t){e={operation:e,cleanup:t}}this.transitionIfStillRinging(`ended`,{reason:`incoming_operation_failed`,cause:e})}cleanupSessionListeners(){this.sessionUnsubscribers.splice(0).forEach(e=>{try{e()}catch{}})}assertState(e){if(this.currentState!==e)throw this.operationError()}assertMediaControlAllowed(){if(this.currentState!==`active`&&this.currentState!==`held`)throw this.operationError()}assertHoldCapability(){if(this.platform===`mobile-web`)throw this.capabilityError()}assertTransferCapability(){if(this.platform===`mobile-web`)throw this.capabilityError()}assertIncomingCall(){if(this.options.incoming!==!0||this.currentState!==`ringing`)throw this.operationError()}assertIncomingOperationAvailable(){if(this.incomingOperation!==void 0)throw this.operationError()}assertCapability(e){if(!this.capabilities.has(e))throw this.capabilityError()}invoke(e){try{e()}catch(e){throw this.operationError(e)}}assertNotDisposed(){if(this.disposed)throw this.operationError()}assertOwner(e){if(e!==void 0&&(this.ownerLost||this.ownerTabId!==void 0&&this.ownerTabId!==e))throw this.operationError()}capabilityError(){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:this.id})}operationError(e){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:this.id,cause:e})}};function k(e){return e===`ended`||e===`failed`}function A(e){return typeof e==`object`&&!!e&&e.type===`blind`&&typeof e.target==`string`}var j=0;function M(){return j+=1,`call_${Date.now().toString(36)}_${j.toString(36)}`}m();var N=`X-User-Data`,P=/[^\x20-\x7E]/,ee=`userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来`;function F(e){if(typeof e!=`string`)return[];let t=e.trim();if(t===``)return[];if(P.test(t))throw new p(`CALL_INVALID_USERDATA`,`call`,!1,{cause:ee});return[`${N}: ${t}`]}m();var I=class{events=new te;calls=new Map;options;incomingUnsubscribe;activeCallId=null;incomingSessionSnapshot;callSessions=new Map;callOwners=new Map;ownerLostCalls=new Set;pendingDialCount=0;pendingDestinations=new Set;activeOperationPromise=Promise.resolve();operationGeneration=0;automaticActiveTransition;disposed=!1;terminalNotified=new Set;terminalOperations=new Map;disposeOperation;constructor(e){this.options=e,this.incomingSessionSnapshot=e.session;try{this.incomingUnsubscribe=e.sip.onIncoming(e=>this.handleIncoming(e))}catch(e){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}}on(e,t){return this.disposed?()=>void 0:this.events.on(e,t)}async dial(e,t){this.assertNotDisposed();let n=this.operationGeneration,r=e.destination.trim();if(r===``)throw new p(`CALL_INVALID_DESTINATION`,`call`,!1);let i=F(e.userdata);this.requireCapability(t,`outbound`);let a=this.callLimit(t);if(this.options.platform===`mobile-web`&&this.calls.size+this.pendingDialCount>=a)throw this.capabilityError();if(this.calls.size+this.pendingDialCount>=a||this.pendingDestinations.has(r)||[...this.calls.values()].some(e=>e.destination===r))throw new p(`CALL_ALREADY_EXISTS`,`call`,!1);this.pendingDialCount+=1,this.pendingDestinations.add(r);let o=M(),s;try{s=await this.holdActiveCallForNewCall(),this.assertGeneration(n,o);let a;try{a=this.options.sip.dial(r,this.dialOptions(o,t,e.type,i))}catch(e){throw this.dialError(e,o)}this.assertGeneration(n,o);let c;try{c=new O({id:o,destination:r,platform:this.options.platform,capabilities:this.effectiveCapabilities(t),session:a,onStateChanged:(e,t)=>this.handleStateChanged(c,e,t),onError:e=>this.events.emit(`error`,{error:e}),onDisposed:()=>this.handleDisposed(c)})}catch(e){throw this.dialError(e,o)}if(!this.isCurrentGeneration(n))throw c.dispose(),this.callOperationError(c.id);this.calls.set(c.id,c),this.callSessions.set(c.id,a),this.options.onCallCreated?.(c.id,a);try{c.beginOutbound()}catch(e){throw c.dispose(),this.calls.delete(c.id),this.callSessions.delete(c.id),this.dialError(e,c.id)}if(!this.isCurrentGeneration(n))throw c.dispose(),this.calls.delete(c.id),this.callSessions.delete(c.id),this.callOperationError(c.id);return this.events.emit(`call.created`,{callId:c.id,state:c.state}),c}catch(e){if(this.isCurrentGeneration(n)&&s!==void 0&&this.isManagedCall(s)&&s.state===`held`)try{await s.resume()}catch(t){throw this.compensationError(s.id,void 0,e,t)}throw e}finally{--this.pendingDialCount,this.pendingDestinations.delete(r)}}async answer(e,t,n,r){this.assertNotDisposed();let i=this.requireCall(e);if(this.options.platform===`mobile-web`&&t.policy.mobileIncomingEnabled!==!0)throw this.capabilityError(e);let a={iceServers:t.iceServers,pcConfig:{iceServers:t.iceServers},...n===void 0?{}:{mediaConstraints:n}};await i.answer(a,r)}async reject(e,t,n){this.assertNotDisposed(),await this.requireCall(e).reject(t,n)}getCalls(){return[...this.calls.values()]}hasNonTerminalCalls(){return this.calls.size>0}getResourceCounts(){let e=[...this.calls.values()].map(e=>e.getResourceCounts());return{timers:e.reduce((e,t)=>e+t.timers,0),listeners:this.events.listenerCount()+e.reduce((e,t)=>e+t.listeners,0),terminalRecords:this.terminalNotified.size+this.terminalOperations.size}}getActiveCall(){return this.activeCallId===null?void 0:this.calls.get(this.activeCallId)}async setActiveCall(e,t){this.assertNotDisposed(),this.requireCall(e).assertOwnerForManager(t),await this.enqueueActiveOperation(t=>this.switchActiveCall(e,t))}async claimCall(e,t){this.assertNotDisposed();let n=t.trim();if(n===``)throw this.callOperationError(e);let r=this.requireCall(e),i=this.callOwners.get(e);if(i!==n){if(i!==void 0||this.ownerLostCalls.has(e)&&!r.canBeReclaimed())throw this.callOperationError(e);this.ownerLostCalls.delete(e),this.callOwners.set(e,n),r.setOwnerTabId(n),this.emitOwnershipChanged({callId:e,state:`owned`,ownerTabId:n})}}async releaseCall(e,t){this.assertNotDisposed();let n=this.requireCall(e);if(this.callOwners.get(e)!==t)throw this.callOperationError(e);this.callOwners.delete(e);let r=!n.canBeReclaimed();r?this.ownerLostCalls.add(e):this.ownerLostCalls.delete(e),n.clearOwnerTabId({lost:r}),this.emitOwnershipChanged({callId:e,state:r?`owner-lost`:`released`})}getCallOwner(e){return this.callOwners.get(e)}releaseOwnedCalls(e){for(let[t,n]of[...this.callOwners.entries()]){if(n!==e)continue;let r=this.calls.get(t);if(r===void 0){this.callOwners.delete(t),this.ownerLostCalls.delete(t);continue}this.callOwners.delete(t);let i=!r.canBeReclaimed();i?this.ownerLostCalls.add(t):this.ownerLostCalls.delete(t),r.clearOwnerTabId({lost:i}),this.emitOwnershipChanged({callId:t,state:i?`owner-lost`:`released`})}}dispose(e={}){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposed=!0,this.operationGeneration+=1,this.automaticActiveTransition=void 0,this.activeOperationPromise=Promise.resolve(),this.events.clear();try{this.incomingUnsubscribe()}catch{}this.activeCallId=null;let t=[...this.calls.values()];this.calls.clear(),this.callSessions.clear(),this.callOwners.clear(),this.ownerLostCalls.clear();let n=Promise.all(t.map(async t=>{let n;try{e.terminateCalls===!0&&t.state!==`ended`&&t.state!==`failed`?await t.hangup():t.dispose()}catch(e){n=e,t.dispose()}try{await this.notifyCallTerminal(t.id)}catch(e){n??=e}if(n!==void 0)throw n})).finally(()=>{this.terminalNotified.clear(),this.terminalOperations.clear()}).then(()=>void 0);return this.disposeOperation=n,n}updateSession(e){this.disposed||(this.incomingSessionSnapshot=e)}async switchActiveCall(e,t){this.assertGeneration(t,e);let n=this.requireCall(e),r=this.getActiveCall();if(r?.id===n.id)return;if(n.state!==`held`&&n.state!==`active`)throw this.callOperationError(e);let i=n.state===`held`;try{if(r!==void 0&&await r.hold(),this.assertGeneration(t,n.id),n.state===`held`&&await n.resume(),this.assertGeneration(t,n.id),!this.isManagedCall(n)||n.state!==`active`)throw this.callOperationError(n.id);this.commitActive(n,t)}catch(a){if(!this.isCurrentGeneration(t))throw this.callOperationError(n.id,a);if(r===void 0)throw this.callOperationError(e,a);try{let e=n.state===`active`;i&&e&&this.isManagedCall(n)&&await n.hold(),this.assertGeneration(t,n.id),r.state===`held`&&this.isManagedCall(r)&&await r.resume(),this.assertGeneration(t,r.id),r.state===`active`&&this.isManagedCall(r)&&this.commitActive(r,t)}catch(e){throw this.compensationError(r.id,n.id,a,e)}throw this.isManagedCall(r)&&r.state===`active`&&this.commitActive(r,t),this.callOperationError(n.id,{operation:a,restoredCallId:r.id})}}handleStateChanged(e,t,n){if(this.disposed)return;let r=this.callSessions.get(e.id);if(r!==void 0&&this.options.onCallStateChanged?.(e.id,r),this.events.emit(`call.stateChanged`,t),t.to===`active`&&this.activeCallId!==e.id){let t=this.getActiveCall();if(this.options.autoHoldPreviousCall===!0&&t!==void 0&&t.id!==e.id&&t.state===`active`){let n=this.operationGeneration;this.enqueueActiveOperation(n=>this.switchAutomaticActiveCall(t,e,n)).catch(e=>{this.isCurrentGeneration(n)&&this.events.emit(`error`,{error:e})})}else this.commitActive(e)}t.to===`held`&&this.activeCallId===e.id&&this.automaticActiveTransition?.previous.id!==e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})),(t.to===`ended`||t.to===`failed`)&&(this.calls.delete(e.id),this.callSessions.delete(e.id),this.callOwners.delete(e.id),this.ownerLostCalls.delete(e.id),this.activeCallId===e.id&&this.automaticActiveTransition?.previous.id!==e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})),this.notifyCallTerminal(e.id),t.to===`ended`?this.events.emit(`call.ended`,{callId:e.id,reason:ne(n)}):this.events.emit(`call.failed`,{callId:e.id,error:re(n,e.id)}))}async switchAutomaticActiveCall(e,t,n){this.automaticActiveTransition={previous:e,target:t};let r;try{if(this.assertGeneration(n,t.id),!this.isManagedCall(t)||t.state!==`active`)return;if(!this.isManagedCall(e)||e.state!==`active`){this.commitActive(t,n);return}if(await e.hold(),this.assertGeneration(n,t.id),!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}if(!this.isManagedCall(t)||t.state!==`active`)r=Error(`target call is no longer active`);else{this.commitActive(t,n);return}}catch(e){r=e}finally{this.automaticActiveTransition?.target.id===t.id&&(this.automaticActiveTransition=void 0)}if(!this.isCurrentGeneration(n))return;if(!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}let i=await this.restoreAutomaticActiveCall(e,t,r,n);if(this.isCurrentGeneration(n)){if(i.error!==void 0)throw i.error;if(!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}throw this.callOperationError(t.id,{operation:r,restoredCallId:e.id})}}async restoreAutomaticActiveCall(e,t,n,r){if(!this.isCurrentGeneration(r))return{};if(!this.isManagedCall(e))return this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,r),{};let i;try{this.isManagedCall(t)&&t.state===`active`&&await t.hold(),this.assertGeneration(r,t.id),this.isManagedCall(e)&&e.state===`held`&&await e.resume(),this.assertGeneration(r,e.id)}catch(e){i=e}return this.isCurrentGeneration(r)?this.isManagedCall(e)?i===void 0?(e.state===`active`&&this.commitActive(e,r),{}):{error:this.compensationError(e.id,t.id,n,i)}:(this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,r),{}):{}}handleDisposed(e){this.disposed||(this.calls.delete(e.id),this.callSessions.delete(e.id),this.callOwners.delete(e.id),this.ownerLostCalls.delete(e.id),this.notifyCallTerminal(e.id),this.activeCallId===e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})))}commitActive(e,t=this.operationGeneration){this.isCurrentGeneration(t)&&this.isManagedCall(e)&&e.state===`active`&&this.activeCallId!==e.id&&(this.activeCallId=e.id,this.events.emit(`call.activeChanged`,{callId:e.id}))}handleIncoming(e){if(this.disposed)return;let t=M(),n=this.incomingSessionSnapshot;if(n===void 0||!n.policy.incomingEnabled||!this.effectiveCapabilities(n).has(`inbound`)){this.terminateUnsupportedIncoming(e),this.events.emit(`error`,{error:this.capabilityError(t)});return}let r=e.from??e.id;if(this.calls.size+this.pendingDialCount>=this.callLimit(n)){this.terminateUnsupportedIncoming(e),this.events.emit(`error`,{error:new p(`CALL_ALREADY_EXISTS`,`call`,!1,{callId:t})});return}let i;try{i=new O({id:t,destination:r,platform:this.options.platform,incoming:!0,capabilities:this.effectiveCapabilities(n),session:e,onStateChanged:(e,t)=>this.handleStateChanged(i,e,t),onError:e=>this.events.emit(`error`,{error:e}),onDisposed:()=>this.handleDisposed(i)})}catch(e){this.events.emit(`error`,{error:this.callOperationError(t,e)});return}this.calls.set(i.id,i),this.callSessions.set(i.id,e),this.options.onCallCreated?.(i.id,e);try{i.beginIncoming(),this.events.emit(`call.incoming`,{callId:i.id,from:r})}catch(e){i.dispose(),this.events.emit(`error`,{error:this.callOperationError(i.id,e)})}}terminateUnsupportedIncoming(e){try{e.terminate()}catch{}}async holdActiveCallForNewCall(){if(this.options.autoHoldPreviousCall!==!0)return;let e=this.getActiveCall();if(e!==void 0&&e.state===`active`)return await e.hold(),e}enqueueActiveOperation(e){let t=this.operationGeneration,n=()=>this.isCurrentGeneration(t)?e(t):Promise.reject(this.callOperationError(``)),r=this.activeOperationPromise.then(n,n);return this.activeOperationPromise=r.catch(()=>void 0),r}isManagedCall(e){return!this.disposed&&this.calls.get(e.id)===e&&e.state!==`ended`&&e.state!==`failed`}isCurrentGeneration(e){return!this.disposed&&this.operationGeneration===e}assertGeneration(e,t){if(!this.isCurrentGeneration(e))throw this.callOperationError(t??``)}effectiveCapabilities(e){let t=new Set(e.capabilities);return this.options.platform===`mobile-web`&&(t.delete(`hold`),t.delete(`blind_transfer`),e.policy.mobileIncomingEnabled!==!0&&t.delete(`inbound`)),t}requireCapability(e,t,n){if(!this.effectiveCapabilities(e).has(t))throw this.capabilityError(n)}requireCall(e){let t=this.calls.get(e);if(t===void 0)throw this.callOperationError(e);return t}emitOwnershipChanged(e){this.events.emit(`call.ownershipChanged`,e)}notifyCallTerminal(e){let t=this.terminalOperations.get(e);if(t!==void 0)return t;if(this.terminalNotified.has(e))return Promise.resolve();this.terminalNotified.add(e);let n;try{n=this.options.onCallTerminal?.(e)}catch(t){this.events.emit(`error`,{error:this.callOperationError(e,t)});let n=Promise.reject(this.callOperationError(e,t));return this.terminalOperations.set(e,n),n.catch(()=>void 0).finally(()=>this.pruneTerminalRecord(e,n)),n}let r=Promise.resolve(n).catch(t=>{throw this.events.emit(`error`,{error:this.callOperationError(e,t)}),t});return this.terminalOperations.set(e,r),r.catch(()=>void 0).finally(()=>this.pruneTerminalRecord(e,r)),r}pruneTerminalRecord(e,t){this.terminalOperations.get(e)===t&&this.terminalOperations.delete(e),this.calls.has(e)||this.terminalNotified.delete(e)}assertNotDisposed(){if(this.disposed)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}callOperationError(e,t){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e,cause:t})}capabilityError(e){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e})}compensationError(e,t,n,r){return this.callOperationError(e,{operation:n,rollback:r,originalCallId:e,targetCallId:t})}callLimit(e){let t=this.options.platform===`mobile-web`?1:2,n=this.options.maxConcurrentCalls??t;return Math.min(t,Math.max(1,n),Math.max(1,e.policy.maxConcurrentCalls))}dialOptions(e,t,n,r=[]){return{iceServers:t.iceServers,extraHeaders:[`X-XCall-Call-ID: ${e}`,`X-XCall-Session-ID: ${t.sessionId}`,...r],...n===void 0?{}:{type:n}}}dialError(e,t){return e instanceof p?new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:t,cause:e.cause??e}):new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:e})}},te=class{handlers=new Map;on(e,t){let n=this.handlers.get(e)??new Set,r=t;n.add(r),this.handlers.set(e,n);let i=!0;return()=>{i&&(i=!1,n.delete(r))}}emit(e,t){let n=this.handlers.get(e);n!==void 0&&[...n].forEach(e=>{try{e(t)}catch{}})}listenerCount(){return[...this.handlers.values()].reduce((e,t)=>e+t.size,0)}clear(){this.handlers.clear()}};function ne(e){if(typeof e!=`object`||!e||!(`reason`in e))return`ended`;let t=e.reason;return typeof t==`string`&&t!==``?t:`ended`}function re(e,t){if(e instanceof p)return new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:t,cause:e.cause??e});if(typeof e==`object`&&e&&`error`in e){let n=e.error;if(n instanceof p)return new p(n.code,n.category,n.retryable,{requestId:n.requestId,callId:t,cause:n.cause??n});if(n instanceof Error)return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:n})}return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:e})}var ie=`3.1.8`,L=`[REDACTED]`,R=/\bBearer\s+[^\s,;"'}]+/gi,ae=/(\bAuthorization\s*[:=]\s*)Digest\s+[^\r\n]*/gi,oe=/(\bAuthorization\s*[:=]\s*)(?:(Bearer|Basic|Digest|Token)\s+)?[^\s,;"'}]+/gi,se=/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,ce=/\b((?:sip|sips|turn|turns|ws|wss):(?:\/\/)?)[^/?#@\s:]+:[^/?#@\s]+@/gi,le=/(\b(?:sip(?:Register)?Ticket|registerTicket|wssTicket|turnCredential|credential|accessToken|refreshToken|appSecret|password|jwt|ticket)\b\s*[:=]\s*)(["']?)([^\s,;&}"']+)(["']?)/gi,ue=/(?<!\d)(1[3-9]\d)\d{4}(\d{4})(?!\d)/g,de=/(?:authorization|token|ticket|credential|password|secret)$/i;function fe(e,t={}){let n=e.replace(R,`Bearer ${L}`).replace(ae,(e,t)=>`${t}Digest ${L}`).replace(oe,(e,t,n)=>`${t}${n===void 0?``:`${n} `}${L}`).replace(se,L).replace(ce,(e,t)=>`${t}${L}@`).replace(le,(e,t)=>`${t}${L}`);return t.maskPhoneNumbers!==!1&&(n=n.replace(ue,`$1****$2`)),n}function z(e,t={}){return pe(e,t,new WeakSet)}function pe(e,t,n){if(typeof e==`string`)return fe(e,t);if(typeof e!=`object`||!e)return e;if(n.has(e))return`[Circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>pe(e,t,n));let r={};return Object.entries(e).forEach(([e,i])=>{r[e]=de.test(e)?L:pe(i,t,n)}),r}m();function me(e){if(!ge(e))throw B(`Invalid worker message`);if(e.version!==1)throw B(`Unsupported worker protocol version`);if(e.type===`attach`||e.type===`detach`)return he(e),e;if(e.type===`command`){if(he(e),typeof e.command!=`string`||e.payload!==void 0&&!ge(e.payload))throw B(`Invalid worker command`);return e}if(e.type===`response`){if(typeof e.requestId!=`string`||typeof e.ok!=`boolean`)throw B(`Invalid worker response`);return e}if(e.type===`event`){if(typeof e.event!=`string`||!(`payload`in e))throw B(`Invalid worker event`);return e}throw B(`Unknown worker message type`)}function he(e){if(typeof e.requestId!=`string`||typeof e.tabId!=`string`)throw B(`Worker request requires requestId and tabId`)}function ge(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function B(e){return new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}m();var _e=class{port;timeoutMs;pending=new Map;eventHandlers=new Set;closed=!1;lifecycleState=`connected`;constructor(e,t={}){this.port=e,this.timeoutMs=t.timeoutMs??15e3,this.port.onmessage=e=>this.handleMessage(e.data),this.port.start()}request(e){return this.closed?Promise.reject(new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)):this.pending.has(e.requestId)?Promise.reject(new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{requestId:e.requestId})):this.lifecycleState===`reconnecting`&&e.type===`command`&&(e.command===`dial`||e.command===`answer`)?Promise.reject(new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0,{callId:e.payload?.callId})):new Promise((t,n)=>{let r=setTimeout(()=>{this.pending.delete(e.requestId),n(new p(`NETWORK_TIMEOUT`,`network`,!0,{requestId:e.requestId}))},this.timeoutMs);this.pending.set(e.requestId,{resolve:e=>t(e),reject:n,timer:r}),this.port.postMessage(e)})}onEvent(e){return this.closed?()=>void 0:(this.eventHandlers.add(e),()=>this.eventHandlers.delete(e))}getLifecycleState(){return this.lifecycleState}close(){this.closed||(this.closed=!0,this.pending.forEach(e=>{clearTimeout(e.timer),e.reject(new p(`SDK_ALREADY_DISPOSED`,`internal`,!1))}),this.pending.clear(),this.eventHandlers.clear(),this.port.close())}handleMessage(e){try{let t=me(e);if(t.type===`event`){t.event===`connection.stateChanged`&&ve(t.payload)&&(this.lifecycleState=t.payload.state),this.eventHandlers.forEach(e=>e(t));return}if(t.type!==`response`)return;let n=this.pending.get(t.requestId);if(n===void 0)return;this.pending.delete(t.requestId),clearTimeout(n.timer),t.ok?n.resolve(t.result):n.reject(ye(t))}catch(e){this.pending.forEach(t=>{clearTimeout(t.timer),t.reject(e)}),this.pending.clear()}}};function ve(e){return typeof e==`object`&&!!e&&`state`in e&&(e.state===`connected`||e.state===`reconnecting`)}function ye(e){let t=e.error;return new p(t?.code??`SDK_INTERNAL_ERROR`,t?.category??`internal`,t?.retryable??!1,{requestId:e.requestId,...t?.message===void 0?{}:{cause:t.message},...t?.serverCode===void 0?{}:{serverCode:t.serverCode},...t?.status===void 0?{}:{status:t.status}})}m();function be(e={}){if((e.enabled??`auto`)===!1)return{mode:`single-tab`,reason:`disabled`};let t=e.locationHref??Se(),n=xe(e.url,t),r=t=>{if(e.fallback===`error`)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:t});return{mode:`single-tab`,reason:t}};if(n===void 0)return r(`SharedWorker URL is unavailable`);if(!we(n,t))return r(`SharedWorker URL must be same-origin`);let i=e.workerCtor??Ce();if(i===void 0)return r(`SharedWorker is not supported`);let a;try{a=new i(n,e.name===void 0?void 0:{name:e.name})}catch(e){return r(`SharedWorker construction failed: ${e instanceof Error?e.message:String(e)}`)}let o=e.tabId??Te(),s=new _e(a.port),c={version:1,type:`attach`,requestId:Ee(),tabId:o},l=s.request(c).then(()=>void 0).catch(e=>{throw s.close(),e});return{mode:`shared`,worker:a,client:s,tabId:o,workerUrl:n,ready:l}}function xe(e,t=Se()){try{return t===void 0?void 0:new URL(e??`./shared-worker.js`,t).toString()}catch{return}}function Se(){return typeof location>`u`?void 0:location.href}function Ce(){if(typeof SharedWorker==`function`)return SharedWorker}function we(e,t){if(t===void 0)return!0;try{return new URL(e,t).origin===new URL(t).origin}catch{return!1}}function Te(){return`tab-${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Ee(){return`attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}m();var De=class{mediaDevices;createAudioElement;outputCapability;outputDeviceId;outputGeneration=0;outputTail;constructor(e={}){this.mediaDevices=e.mediaDevices===null?void 0:e.mediaDevices??V(),this.createAudioElement=e.createAudioElement}async requestPermission(e={}){let t=this.requireMediaDevices(),n;try{n=await t.getUserMedia({audio:e})}catch(e){throw ke(e)}H(n)}async getDevices(){if(this.mediaDevices===void 0)return[];try{return(await this.mediaDevices.enumerateDevices()).filter(e=>e.kind===`audioinput`||e.kind===`audiooutput`&&this.supportsOutputSelection())}catch(e){throw Ae(e)}}getCapabilities(){return{input:this.mediaDevices!==void 0,output:this.supportsOutputSelection()}}supportsOutputSelection(){if(this.outputCapability!==void 0)return this.outputCapability;let e=this.createAudioElementSafely();return this.outputCapability=e!==void 0&&typeof e.setSinkId==`function`,this.outputCapability}async setOutputDevice(e,t){if(!this.supportsOutputSelection())throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);this.outputDeviceId=e;let n=++this.outputGeneration;t!==void 0&&await this.enqueueOutput(async()=>{n===this.outputGeneration&&await this.applyOutputDevice(e,t)})}async applyConfiguredOutputDevice(e){if(this.outputDeviceId===void 0||e===void 0)return;let t=this.outputDeviceId,n=this.outputGeneration;await this.enqueueOutput(async()=>{n===this.outputGeneration&&await this.applyOutputDevice(t,e)})}getOutputDeviceId(){return this.outputDeviceId}async applyOutputDevice(e,t){let n=t;if(typeof n.setSinkId!=`function`)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);try{await n.setSinkId(e)}catch(e){throw je(e)}}enqueueOutput(e){let t=this.outputTail,n=t===void 0?e():t.then(e,e),r=n.catch(()=>void 0);return this.outputTail=r,r.then(()=>{this.outputTail===r&&(this.outputTail=void 0)}),n}async openInputStream(e){let t=this.requireMediaDevices();try{return await t.getUserMedia({audio:{deviceId:{exact:e}}})}catch(e){throw Oe(e)}}requireMediaDevices(){if(this.mediaDevices===void 0)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);return this.mediaDevices}createAudioElementSafely(){if(this.createAudioElement!==void 0)try{return this.createAudioElement()}catch{return}if(typeof document<`u`)try{return document.createElement(`audio`)}catch{return}}};function V(){return globalThis.navigator?.mediaDevices}function H(e){let t;try{t=e.getTracks()}catch{return}t.forEach(e=>{try{e.stop()}catch{}})}function Oe(e){let t=Me(e);return t===`NotFoundError`||t===`OverconstrainedError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotReadableError`||t===`AbortError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function ke(e){let t=Me(e);return t===`NotFoundError`||t===`OverconstrainedError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotReadableError`||t===`AbortError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function Ae(e){let t=Me(e);return t===`NotFoundError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):t===`AbortError`||t===`NotReadableError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function je(e){let t=Me(e);return t===`NotFoundError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):t===`AbortError`||t===`NotReadableError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function Me(e){if(typeof e!=`object`||!e||!(`name`in e))return;let t=e.name;return typeof t==`string`?t:void 0}m();var Ne=class{createAudioElement;bindings=new Map;audioOwners=new Map;trackOwners=new Map;generations=new Map;pendingPlays=new Map;constructor(e=Pe){this.createAudioElement=e}async bind(e,t){let n=this.bindings.get(e);if(n?.stream===t)return;let r=Fe(e,t),i;try{i=this.createAudioElement()}catch(t){throw Ie(r,this.trackOwners),new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e,cause:t})}let a=this.audioOwners.get(i);if(a!==void 0&&a!==e)throw Ie(r,this.trackOwners),new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e});try{i.autoplay=!0,i.playsInline=!0}catch(t){throw Ie(r,this.trackOwners),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:t})}try{i.srcObject=t}catch(t){throw Ie(r,this.trackOwners),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:t})}this.acquireTracks(r),n!==void 0&&this.releaseBinding(n,n.audio!==i);let o=this.nextGeneration(e);this.audioOwners.set(i,e);let s={callId:e,audio:i,stream:t,tracks:r,generation:o};this.bindings.set(e,s),this.beginPlay(e);try{await i.play()}catch(t){if(!this.isCurrent(e,o))return;throw new p(`MEDIA_PLAYBACK_BLOCKED`,`media`,!1,{callId:e,cause:t})}finally{this.finishPlay(e)}this.isCurrent(e,o)}async play(e){let t=this.bindings.get(e);if(t===void 0)throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e});let n=t.generation;this.beginPlay(e);try{await t.audio.play()}catch(t){if(!this.isCurrent(e,n))return;throw new p(`MEDIA_PLAYBACK_BLOCKED`,`media`,!1,{callId:e,cause:t})}finally{this.finishPlay(e)}this.isCurrent(e,n)}getAudioElement(e){return this.bindings.get(e)?.audio}getResourceCounts(){return{tracks:this.trackOwners.size,audioElements:this.audioOwners.size}}release(e){this.nextGeneration(e);let t=this.bindings.get(e);t!==void 0&&this.releaseBinding(t),this.cleanupGeneration(e)}releaseAll(){[...this.bindings.keys()].forEach(e=>this.release(e))}releaseBinding(e,t=!0){if(this.bindings.get(e.callId)===e&&this.bindings.delete(e.callId),this.audioOwners.get(e.audio)===e.callId&&this.audioOwners.delete(e.audio),t)try{e.audio.srcObject=null}catch{}e.tracks.forEach(e=>this.releaseTrack(e))}acquireTracks(e){e.forEach(e=>this.trackOwners.set(e,(this.trackOwners.get(e)??0)+1))}releaseTrack(e){let t=this.trackOwners.get(e);if(t===void 0||t<=1){this.trackOwners.delete(e),Re(e);return}this.trackOwners.set(e,t-1)}beginPlay(e){this.pendingPlays.set(e,(this.pendingPlays.get(e)??0)+1)}finishPlay(e){let t=this.pendingPlays.get(e)??0;t<=1?this.pendingPlays.delete(e):this.pendingPlays.set(e,t-1),this.cleanupGeneration(e)}nextGeneration(e){let t=(this.generations.get(e)??0)+1;return this.generations.set(e,t),t}cleanupGeneration(e){!this.bindings.has(e)&&!this.pendingPlays.has(e)&&this.generations.delete(e)}isCurrent(e,t){return this.generations.get(e)===t&&this.bindings.get(e)?.generation===t}};function Pe(){if(typeof document>`u`)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);return document.createElement(`audio`)}function Fe(e,t){try{return[...new Set(t.getAudioTracks())].filter(e=>e.kind===`audio`)}catch(n){try{return[...new Set(t.getTracks())].filter(e=>e.kind===`audio`)}catch(r){throw Le(t),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:n??r})}}}function Ie(e,t){e.forEach(e=>{(t.get(e)??0)===0&&Re(e)})}function Le(e){try{[...new Set(e.getTracks())].filter(e=>e.kind===`audio`).forEach(Re)}catch{}}function Re(e){try{e.stop()}catch{}}m();var ze=class{deviceManager;remoteAudio;getActiveCall;createRemoteStream;calls=new Map;resources=new Set;inputOperations=new Map;senderQueues=new Map;releaseOperations=new Map;callReleaseOperations=new Map;releaseErrors=new WeakMap;releaseAllOperation;disposeOperation;disposing=!1;disposed=!1;constructor(e={}){let t={mediaDevices:e.mediaDevices,createAudioElement:e.createAudioElement};this.deviceManager=new De(t),this.remoteAudio=new Ne(e.createAudioElement),this.getActiveCall=e.getActiveCall,this.createRemoteStream=e.createRemoteStream??Ge}requestPermission(e){return this.assertNotDisposed(),this.deviceManager.requestPermission(e)}getDevices(){return this.assertNotDisposed(),this.deviceManager.getDevices()}getCapabilities(){return this.assertNotDisposed(),this.deviceManager.getCapabilities()}supportsOutputSelection(){return this.assertNotDisposed(),this.deviceManager.supportsOutputSelection()}registerCallMedia(e,t){this.assertNotDisposed();let n=this.calls.get(e);n!==void 0&&this.releaseResource(n).catch(e=>{this.releaseErrors.set(n,e)});let r=Be(t)?t:{peerConnection:t},i={callId:e,peerConnection:r.peerConnection,senders:new Map,localTracks:new Set,pendingTracks:new Set,generation:1,released:!1,peerClosed:!1};if(this.captureSenders(i,r.getSenderKind),this.resources.add(i),r.localTracks?.forEach(e=>{e.kind===`audio`&&i.localTracks.add(e)}),this.calls.set(e,i),r.trackSource!==void 0)try{i.trackSourceUnsubscribe=r.trackSource.onTrack(e=>this.handleTrackEvent(i,e))}catch{}return async()=>{let e=this.releaseOperations.get(i);if(e!==void 0)await e;else if(this.releaseErrors.has(i))throw this.releaseErrors.get(i);else await this.releaseResource(i);let t=this.releaseErrors.get(i);if(t!==void 0)throw t}}async setInputDevice(e,t){this.assertNotDisposed();let n=t??this.getActiveCall?.();this.assertActiveCall(n),this.assertDeviceSelectionCapability(n);let r=this.ensureCallMedia(n),i=(this.inputOperations.get(n.callId)??Promise.resolve()).then(()=>this.performInputSwitch(e,n,r),()=>this.performInputSwitch(e,n,r));this.inputOperations.set(n.callId,i);try{await i}finally{this.inputOperations.get(n.callId)===i&&this.inputOperations.delete(n.callId)}}setOutputDevice(e,t){this.assertNotDisposed();let n=t??this.getActiveCall?.()?.callId,r=n===void 0?void 0:this.remoteAudio.getAudioElement(n);return this.deviceManager.setOutputDevice(e,r)}async bindRemoteTrack(e,t){this.assertNotDisposed();let n;try{await this.remoteAudio.bind(e,t)}catch(e){n=e}let r;try{await this.deviceManager.applyConfiguredOutputDevice(this.remoteAudio.getAudioElement(e))}catch(e){r=e}if(n!==void 0)throw n;if(r!==void 0)throw r}playRemoteAudio(e){return this.assertNotDisposed(),this.remoteAudio.play(e)}getResourceCounts(){let e=new Set;this.resources.forEach(t=>{t.localTracks.forEach(t=>e.add(t)),t.pendingTracks.forEach(t=>e.add(t))});let t=this.remoteAudio.getResourceCounts();return{listeners:[...this.resources].filter(e=>e.trackSourceUnsubscribe!==void 0).length,tracks:e.size+t.tracks,peerConnections:this.resources.size,audioElements:t.audioElements}}releaseResource(e){let t=this.releaseOperations.get(e);if(t!==void 0)return t;if(!this.resources.has(e))return Promise.resolve();let n=e.callId;this.remoteAudio.release(n),this.releaseErrors.delete(e),this.calls.get(n)===e&&this.calls.delete(n),e.generation+=1,e.released=!0,this.unsubscribeTrackSource(e);let r=new Set([...e.localTracks,...e.pendingTracks]),i=[...e.senders.values()].filter(e=>e.audio).map(t=>({senderResource:t,promise:this.enqueueSender(e,t,()=>He(t.sender),!0)})),a=Promise.all(i.map(async e=>{try{return await e.promise,{senderResource:e.senderResource,cause:void 0}}catch(t){return{senderResource:e.senderResource,cause:t}}})).then(async t=>{let i=new Set,a=[];if(t.forEach(e=>{if(e.cause!==void 0){a.push(e.cause);let t=U(e.senderResource.sender);t?.kind===`audio`&&i.add(t);return}let t=U(e.senderResource.sender);t?.kind===`audio`&&r.add(t)}),r.forEach(e=>{i.has(e)||We(e)}),a.length>0)throw e.localTracks.clear(),e.pendingTracks.clear(),i.forEach(t=>e.localTracks.add(t)),new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:n,cause:a[0]});if(!e.peerClosed&&e.peerConnection.close!==void 0)try{await e.peerConnection.close(),e.peerClosed=!0}catch(t){let r=[...e.senders.values()].map(e=>U(e.sender)).find(e=>e?.kind===`audio`);throw e.localTracks.clear(),e.pendingTracks.clear(),r!=null&&e.localTracks.add(r),new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:n,cause:t})}e.localTracks.clear(),e.pendingTracks.clear(),e.senders.clear(),this.resources.delete(e),this.releaseUnusedSenderQueues()}).catch(t=>{throw this.releaseErrors.set(e,t),this.calls.get(n)===void 0&&this.calls.set(n,e),t}).finally(()=>{this.releaseOperations.get(e)===a&&this.releaseOperations.delete(e)});return this.releaseOperations.set(e,a),a}releaseCall(e){let t=this.callReleaseOperations.get(e);if(t!==void 0)return t;let n=[...this.resources].filter(t=>t.callId===e);if(n.length===0)return Promise.resolve();let r=Promise.all(n.map(async e=>{try{return await this.releaseResource(e),{cause:void 0}}catch(e){return{cause:e}}})).then(e=>{let t=e.find(e=>e.cause!==void 0)?.cause;if(t!==void 0)throw t}).finally(()=>{this.callReleaseOperations.get(e)===r&&this.callReleaseOperations.delete(e)});return this.callReleaseOperations.set(e,r),r}releaseAll(){if(this.releaseAllOperation!==void 0)return this.releaseAllOperation;this.remoteAudio.releaseAll();let e=new Set([...this.resources].map(e=>e.callId)),t=Promise.all([...e].map(async e=>{try{return await this.releaseCall(e),{cause:void 0}}catch(e){return{cause:e}}})).then(e=>{let t=e.find(e=>e.cause!==void 0)?.cause;if(t!==void 0)throw t}).finally(()=>{this.releaseAllOperation===t&&(this.releaseAllOperation=void 0)});return this.releaseAllOperation=t,t}dispose(){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposing=!0;let e=this.releaseAll(),t=this.waitForInputOperations(),n=Promise.allSettled([e,t]).then(e=>{let t=e.find(e=>e.status===`rejected`);if(t?.status===`rejected`)throw t.reason;this.inputOperations.clear(),this.disposed=!0,this.disposing=!1}).finally(()=>{this.disposeOperation===n&&!this.disposed&&(this.disposeOperation=void 0),!this.disposed&&this.disposeOperation===void 0&&(this.disposing=!1)});return this.disposeOperation=n,n}async waitForInputOperations(){let e=[...this.inputOperations.values()];e.length!==0&&await Promise.allSettled(e)}async performInputSwitch(e,t,n){if(this.assertActiveCall(t),this.assertDeviceSelectionCapability(t),!this.isCurrentResource(n)||t.peerConnection!==n.peerConnection)throw this.callOperationError(t.callId);let r=this.findAudioSender(n),i=U(r.sender),a=n.generation,o=await this.deviceManager.openInputStream(e),s;try{s=o.getTracks()}catch(e){throw Ue(o),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:t.callId,cause:e})}let c;try{c=o.getAudioTracks()}catch(e){throw W(s),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:t.callId,cause:e})}let l=c[0];if(l===void 0)throw W(s),new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{callId:t.callId});if(!this.canCommitInputSwitch(t,n,r,i,a))throw W(s),this.callOperationError(t.callId);s.forEach(e=>n.pendingTracks.add(e)),n.pendingTracks.add(l);try{await this.enqueueSender(n,r,()=>r.sender.replaceTrack(l))}catch(e){throw n.released?this.callOperationError(t.callId):(n.released||(s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),await this.rollbackSender(n,r,i,l),W(s)),new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{callId:t.callId,cause:e}))}if(!this.canCommitInputSwitch(t,n,r,l,a)){if(!n.released)try{await this.enqueueSender(n,r,()=>U(r.sender)===l?He(r.sender):Promise.resolve()),s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),W(s)}catch(e){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:t.callId,cause:e})}throw this.callOperationError(t.callId)}s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),n.localTracks.add(l),i!==null&&i!==l&&(n.localTracks.delete(i),We(i)),s.forEach(e=>{e!==l&&We(e)})}ensureCallMedia(e){let t=this.calls.get(e.callId);if(t!==void 0&&t.peerConnection===e.peerConnection)return t;if(e.peerConnection===void 0)throw this.capabilityError(e.callId);this.registerCallMedia(e.callId,e.peerConnection);let n=this.calls.get(e.callId);if(n===void 0)throw this.callOperationError(e.callId);return n}captureSenders(e,t){let n;try{n=e.peerConnection.getSenders()}catch(t){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e.callId,cause:t})}n.forEach(n=>{let r=U(n),i;try{i=t?.(n)??n.senderKind??n.kind}catch(t){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e.callId,cause:t})}e.senders.set(n,{sender:n,audio:i===`audio`||i===void 0&&r?.kind===`audio`,queue:this.senderQueues.get(n)??this.createSenderQueue(n)}),r?.kind===`audio`&&e.localTracks.add(r)})}findAudioSender(e){let t=[...e.senders.values()].find(e=>e.audio&&(U(e.sender)?.kind===`audio`||U(e.sender)===null));if(t===void 0)throw this.capabilityError(e.callId);return t}handleTrackEvent(e,t){if(!this.isCurrentResource(e)||t.track.kind!==`audio`)return;let n=t.streams[0]??this.createRemoteStream(t.track);n!==void 0&&this.bindRemoteTrack(e.callId,n).catch(()=>void 0)}canCommitInputSwitch(e,t,n,r,i){if(this.disposed||!this.isCurrentResource(t,i)||e.state!==`active`||e.peerConnection!==t.peerConnection||!t.senders.has(n.sender))return!1;try{if(!t.peerConnection.getSenders().includes(n.sender))return!1}catch{return!1}return U(n.sender)===r}enqueueSender(e,t,n,r=!1){t.queue.pending+=1;let i=t.queue.chain.then(async()=>{if(e.released&&!r)throw this.callOperationError(e.callId);return n()},async()=>{if(e.released&&!r)throw this.callOperationError(e.callId);return n()}),a=i.finally(()=>{--t.queue.pending});return t.queue.chain=a.catch(()=>void 0),i}createSenderQueue(e){let t={chain:Promise.resolve(),pending:0};return this.senderQueues.set(e,t),t}releaseUnusedSenderQueues(){let e=new Set;this.resources.forEach(t=>t.senders.forEach(t=>e.add(t.sender))),this.senderQueues.forEach((t,n)=>{t.pending===0&&!e.has(n)&&this.senderQueues.delete(n)})}async rollbackSender(e,t,n,r){e.released||U(t.sender)!==r||await this.enqueueSender(e,t,()=>t.sender.replaceTrack(n)).catch(()=>void 0)}isCurrentResource(e,t=e.generation){return!this.disposed&&this.calls.get(e.callId)===e&&e.generation===t}unsubscribeTrackSource(e){let t=e.trackSourceUnsubscribe;if(e.trackSourceUnsubscribe=void 0,t!==void 0)try{t()}catch{}}assertActiveCall(e){if(e===void 0||e.state!==`active`)throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e?.callId})}assertDeviceSelectionCapability(e){if(e.capabilities===void 0||!e.capabilities.has(`device_selection`))throw this.capabilityError(e.callId)}capabilityError(e){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e})}callOperationError(e){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e})}assertNotDisposed(){if(this.disposed||this.disposing)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}};function Be(e){return`peerConnection`in e}function U(e){try{return e.track}catch{return null}}function Ve(e){return typeof e==`object`&&!!e&&e.name===`InvalidStateError`}function He(e){try{return e.replaceTrack(null).catch(e=>{if(!Ve(e))throw e})}catch(e){return Ve(e)?Promise.resolve():Promise.reject(e)}}function Ue(e){try{W(e.getTracks())}catch{}}function W(e){e.forEach(We)}function We(e){try{e.stop()}catch{}}function Ge(e){if(typeof MediaStream<`u`)try{return new MediaStream([e])}catch{return}}m();function Ke(e,t={}){let n=new Map,r=new Map,i=new Set,a=t.ownershipRequired===!0,o=!1,s=!1,c,l=()=>e(),u=new ze({getActiveCall:l});return{publicMedia:{requestPermission:()=>(d(),u.requestPermission()),getDevices:()=>(d(),u.getDevices()),getCapabilities:()=>(d(),u.getCapabilities()),supportsOutputSelection:()=>(d(),u.supportsOutputSelection()),setInputDevice:e=>(d(),u.setInputDevice(e,l())),setOutputDevice:e=>(d(),u.setOutputDevice(e)),playRemoteAudio:e=>(d(),u.playRemoteAudio(e)),releaseAll:()=>(d(),u.releaseAll())},registerCall(e,t){o||s||!qe(t)||(r.set(e,t),(!a||i.has(e))&&f(e,t))},async setCallOwnership(e,t){if(o)return;if(t!==`owned`){i.delete(e),await u.releaseCall(e),n.delete(e);return}i.add(e);let a=r.get(e);a!==void 0&&f(e,a)},contextFor(e,t,r){let i=n.get(e);if(i!==void 0)return{callId:e,state:t,capabilities:r,peerConnection:i.peerConnection}},async releaseCall(e){o||(await u.releaseCall(e),n.delete(e),r.delete(e),i.delete(e))},releaseAll:async()=>{await u.releaseAll(),n.clear(),r.clear(),i.clear()},getResourceCounts:()=>u.getResourceCounts(),dispose:()=>{if(c!==void 0)return c;s=!0;let e=u.dispose().then(()=>{o=!0,s=!1,n.clear(),r.clear(),i.clear()}).finally(()=>{c===e&&!o&&(c=void 0,s=!1)});return c=e,e}};function d(){if(o)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}function f(e,t){if(!qe(t)||typeof t.getMediaRegistration!=`function`)return;let r=t.getMediaRegistration();if(Je(r)&&n.get(e)?.peerConnection!==r.peerConnection){n.set(e,r);try{u.registerCallMedia(e,r)}catch{n.delete(e)}}}}function qe(e){return typeof e==`object`&&!!e}function Je(e){return typeof e==`object`&&!!e&&`peerConnection`in e&&typeof e.peerConnection==`object`&&e.peerConnection!==null}var Ye=1e3,Xe=3e4;function Ze(e,t=Math.random){let n=Math.min(Xe,Ye*2**Math.max(0,Math.floor(e))),r=Math.min(1,Math.max(0,t()));return Math.round(n*(1+r*.2))}var Qe=class{recover;random;isOnline;onAttempt;attempt=0;pendingTimer;running=!1;online=!0;generation=0;disposed=!1;restartAfterRun=!1;constructor(e){this.recover=e.recover,this.random=e.random??Math.random,this.isOnline=e.isOnline??(()=>!0),this.onAttempt=e.onAttempt}start(){if(this.disposed||!this.online||!this.isOnline()||this.pendingTimer!==void 0||this.running)return;let e=this.generation,t=Ze(this.attempt,this.random);this.pendingTimer=setTimeout(()=>{this.pendingTimer=void 0,this.run(e)},t)}notifyOffline(){this.disposed||(this.online=!1,this.generation+=1,this.clearPendingTimer(),this.restartAfterRun=!1)}notifyOnline(){this.disposed||(this.online=!0,this.running&&(this.restartAfterRun=!0),this.start())}cancel(){this.disposed||(this.generation+=1,this.clearPendingTimer(),this.attempt=0,this.restartAfterRun=!1)}dispose(){this.disposed||(this.disposed=!0,this.generation+=1,this.clearPendingTimer(),this.restartAfterRun=!1)}getTimerCount(){return this.pendingTimer===void 0?0:1}async run(e){if(this.disposed||!this.online||e!==this.generation||this.running)return;this.running=!0;try{this.onAttempt?.(this.attempt)}catch{}let t=!1;try{await this.recover(),this.isCurrent(e)&&(this.attempt=0)}catch{this.isCurrent(e)&&(this.attempt+=1,t=!0)}finally{this.running=!1}this.restartAfterRun?(this.restartAfterRun=!1,this.isCurrent(this.generation)&&this.start()):t&&this.isCurrent(e)&&this.start()}isCurrent(e){return!this.disposed&&this.online&&e===this.generation&&this.isOnline()}clearPendingTimer(){this.pendingTimer!==void 0&&(clearTimeout(this.pendingTimer),this.pendingTimer=void 0)}},$e=class{capacity;entries=[];constructor(e){if(this.capacity=e,!Number.isInteger(e)||e<=0)throw RangeError(`RingBuffer capacity must be a positive integer`)}push(e){this.entries.length===this.capacity&&this.entries.shift(),this.entries.push(e)}toArray(){return[...this.entries]}},et=`@16x/webphone-sdk`,tt=200,nt=class{dependencies;logs=new $e(tt);now;constructor(e){this.dependencies=e,this.now=e.now??(()=>new Date)}log(e,t,n){this.logs.push({timestamp:this.now().toISOString(),level:e,message:fe(t),...n===void 0?{}:{context:z(n)}})}async getReport(e={}){let t=e.includeRecentLogs!==!1,n=e.includeDeviceNames===!0,r=e.maskPhoneNumbers!==!1,i=this.dependencies.getSnapshot(),a=this.dependencies.getPermission===void 0?i.permission:await rt(this.dependencies.getPermission,i.permission),o=n?await it(this.dependencies.getDeviceNames):void 0,s=ot(at(this.dependencies.getUserAgent));return z({generatedAt:this.now().toISOString(),sdk:{name:et,version:ie},browser:s.browser,os:s.os,...i,permission:a,recentLogs:t?this.logs.toArray():[],...o===void 0?{}:{deviceNames:o}},{maskPhoneNumbers:r})}};async function rt(e,t){try{return await e()}catch{return t}}async function it(e){if(e===void 0)return[];try{return[...await e()]}catch{return[]}}function at(e){if(e!==void 0)try{return e()}catch{return``}return typeof navigator>`u`?``:navigator.userAgent}function ot(e){return{browser:st(e),os:ct(e)}}function st(e){for(let[t,n]of[[`Edge`,/Edg\/([\d.]+)/],[`Chrome`,/(?:Chrome|CriOS)\/([\d.]+)/],[`Firefox`,/(?:Firefox|FxiOS)\/([\d.]+)/],[`Safari`,/Version\/([\d.]+).*Safari/]]){let r=e.match(n);if(r?.[1]!==void 0)return{name:t,version:r[1]}}return{name:`unknown`,version:``}}function ct(e){let t=e.match(/(?:iPhone|iPad).*OS ([\d_]+)/);if(t?.[1]!==void 0)return{name:`iOS`,version:t[1].replaceAll(`_`,`.`)};let n=e.match(/Android ([\d.]+)/);if(n?.[1]!==void 0)return{name:`Android`,version:n[1]};let r=e.match(/Windows NT ([\d.]+)/);if(r?.[1]!==void 0)return{name:`Windows`,version:r[1]};let i=e.match(/Mac OS X ([\d_]+)/);return i?.[1]===void 0?/Linux/.test(e)?{name:`Linux`,version:``}:{name:`unknown`,version:``}:{name:`macOS`,version:i[1].replaceAll(`_`,`.`)}}var lt=l({bugs:()=>bt,contributors:()=>ht,default:()=>wt,dependencies:()=>xt,description:()=>ft,devDependencies:()=>St,homepage:()=>mt,keywords:()=>vt,license:()=>`MIT`,main:()=>_t,name:()=>ut,repository:()=>yt,scripts:()=>Ct,title:()=>dt,types:()=>gt,version:()=>pt}),ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St,Ct,wt,Tt=s((()=>{ut=`jssip`,dt=`JsSIP`,ft=`the Javascript SIP library`,pt=`3.10.1`,mt=`https://jssip.net`,ht=[`José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)`,`Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)`],gt=`lib/JsSIP.d.ts`,_t=`lib-es5/JsSIP.js`,vt=[`sip`,`websocket`,`webrtc`,`node`,`browser`,`library`],yt={type:`git`,url:`https://github.com/versatica/JsSIP.git`},bt={url:`https://github.com/versatica/JsSIP/issues`},xt={"@types/events":`^3.0.0`,"@types/debug":`^4.1.7`,debug:`^4.3.1`,events:`^3.3.0`,"sdp-transform":`^2.14.1`},St={"@babel/core":`^7.19.6`,"@babel/preset-env":`^7.19.4`,"ansi-colors":`^3.2.4`,browserify:`^16.5.1`,eslint:`^5.16.0`,"fancy-log":`^1.3.3`,gulp:`^4.0.2`,"gulp-babel":`^8.0.0`,"gulp-eslint":`^5.0.0`,"gulp-expect-file":`^1.0.2`,"gulp-header":`^2.0.9`,"gulp-nodeunit-runner":`^0.2.2`,"gulp-plumber":`^1.2.1`,"gulp-rename":`^1.4.0`,"gulp-uglify-es":`^1.0.4`,pegjs:`^0.7.0`,"vinyl-buffer":`^1.0.1`,"vinyl-source-stream":`^2.0.0`},Ct={lint:`node npm-scripts.js lint`,test:`node npm-scripts.js test`,prepublish:`node npm-scripts.js prepublish`,release:`node npm-scripts.js release`},wt={name:ut,title:dt,description:ft,version:pt,homepage:mt,contributors:ht,types:gt,main:_t,keywords:vt,license:`MIT`,repository:yt,bugs:bt,dependencies:xt,devDependencies:St,scripts:Ct}})),G=c(((e,t)=>{var n=(Tt(),f(lt).default);t.exports={USER_AGENT:`${n.title} ${n.version}`,SIP:`sip`,SIPS:`sips`,causes:{CONNECTION_ERROR:`Connection Error`,REQUEST_TIMEOUT:`Request Timeout`,SIP_FAILURE_CODE:`SIP Failure Code`,INTERNAL_ERROR:`Internal Error`,BUSY:`Busy`,REJECTED:`Rejected`,REDIRECTED:`Redirected`,UNAVAILABLE:`Unavailable`,NOT_FOUND:`Not Found`,ADDRESS_INCOMPLETE:`Address Incomplete`,INCOMPATIBLE_SDP:`Incompatible SDP`,MISSING_SDP:`Missing SDP`,AUTHENTICATION_ERROR:`Authentication Error`,BYE:`Terminated`,WEBRTC_ERROR:`WebRTC Error`,CANCELED:`Canceled`,NO_ANSWER:`No Answer`,EXPIRES:`Expires`,NO_ACK:`No ACK`,DIALOG_ERROR:`Dialog Error`,USER_DENIED_MEDIA_ACCESS:`User Denied Media Access`,BAD_MEDIA_DESCRIPTION:`Bad Media Description`,RTP_TIMEOUT:`RTP Timeout`},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:`ACK`,BYE:`BYE`,CANCEL:`CANCEL`,INFO:`INFO`,INVITE:`INVITE`,MESSAGE:`MESSAGE`,NOTIFY:`NOTIFY`,OPTIONS:`OPTIONS`,REGISTER:`REGISTER`,REFER:`REFER`,UPDATE:`UPDATE`,SUBSCRIBE:`SUBSCRIBE`,DTMF_TRANSPORT:{INFO:`INFO`,RFC2833:`RFC2833`},REASON_PHRASE:{100:`Trying`,180:`Ringing`,181:`Call Is Being Forwarded`,182:`Queued`,183:`Session Progress`,199:`Early Dialog Terminated`,200:`OK`,202:`Accepted`,204:`No Notification`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Moved Temporarily`,305:`Use Proxy`,380:`Alternative Service`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,410:`Gone`,412:`Conditional Request Failed`,413:`Request Entity Too Large`,414:`Request-URI Too Long`,415:`Unsupported Media Type`,416:`Unsupported URI Scheme`,417:`Unknown Resource-Priority`,420:`Bad Extension`,421:`Extension Required`,422:`Session Interval Too Small`,423:`Interval Too Brief`,424:`Bad Location Information`,428:`Use Identity Header`,429:`Provide Referrer Identity`,430:`Flow Failed`,433:`Anonymity Disallowed`,436:`Bad Identity-Info`,437:`Unsupported Certificate`,438:`Invalid Identity Header`,439:`First Hop Lacks Outbound Support`,440:`Max-Breadth Exceeded`,469:`Bad Info Package`,470:`Consent Needed`,478:`Unresolvable Destination`,480:`Temporarily Unavailable`,481:`Call/Transaction Does Not Exist`,482:`Loop Detected`,483:`Too Many Hops`,484:`Address Incomplete`,485:`Ambiguous`,486:`Busy Here`,487:`Request Terminated`,488:`Not Acceptable Here`,489:`Bad Event`,491:`Request Pending`,493:`Undecipherable`,494:`Security Agreement Required`,500:`JsSIP Internal Error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Server Time-out`,505:`Version Not Supported`,513:`Message Too Large`,580:`Precondition Failure`,600:`Busy Everywhere`,603:`Decline`,604:`Does Not Exist Anywhere`,606:`Not Acceptable`},ALLOWED_METHODS:`INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY`,ACCEPTED_BODY_TYPES:`application/sdp, application/dtmf-relay`,MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}})),K=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}function a(e){var t=u();return function(){var n=p(e),r;if(t){var i=p(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}function o(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:s(e)}function s(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function c(e){var t=typeof Map==`function`?new Map:void 0;return c=function(e){if(e===null||!d(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,p(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)},c(e)}function l(e,t,n){return l=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&f(i,n.prototype),i},l.apply(null,arguments)}function u(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function d(e){return Function.toString.call(e).indexOf(`[native code]`)!==-1}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}t.exports={ConfigurationError:function(e){i(n,e);var t=a(n);function n(e,i){var a;return r(this,n),a=t.call(this),a.code=1,a.name=`CONFIGURATION_ERROR`,a.parameter=e,a.value=i,a.message=a.value?`Invalid value ${JSON.stringify(a.value)} for parameter "${a.parameter}"`:`Missing parameter: ${a.parameter}`,a}return n}(c(Error)),InvalidStateError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=2,i.name=`INVALID_STATE_ERROR`,i.status=e,i.message=`Invalid status: ${e}`,i}return n}(c(Error)),NotSupportedError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=3,i.name=`NOT_SUPPORTED_ERROR`,i.message=e,i}return n}(c(Error)),NotReadyError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=4,i.name=`NOT_READY_ERROR`,i.message=e,i}return n}(c(Error))}})),Et=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Dt(),o=q();t.exports=function(){i(e,null,[{key:`parse`,value:function(e){if(e=o.parse(e,`Name_Addr_Header`),e!==-1)return e}}]);function e(t,r,i){if(n(this,e),!t||!(t instanceof a))throw TypeError(`missing or invalid "uri" parameter`);for(var o in this._uri=t,this._parameters={},this.display_name=r,i)Object.prototype.hasOwnProperty.call(i,o)&&this.setParam(o,i[o])}return i(e,[{key:`setParam`,value:function(e,t){e&&(this._parameters[e.toLowerCase()]=t==null?null:t.toString())}},{key:`getParam`,value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:`hasParam`,value:function(e){if(e)return this._parameters.hasOwnProperty(e.toLowerCase())&&!0||!1}},{key:`deleteParam`,value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:`clearParams`,value:function(){this._parameters={}}},{key:`clone`,value:function(){return new e(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:`_quote`,value:function(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}},{key:`toString`,value:function(){var e=this._display_name?`"${this._quote(this._display_name)}" `:``;for(var t in e+=`<${this._uri.toString()}>`,this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=`;${t}`,this._parameters[t]!==null&&(e+=`=${this._parameters[t]}`));return e}},{key:`uri`,get:function(){return this._uri}},{key:`display_name`,get:function(){return this._display_name},set:function(e){this._display_name=e===0?`0`:e}}]),e}()})),q=c(((e,t)=>{t.exports=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 r={CRLF:l,DIGIT:u,ALPHA:d,HEXDIG:f,WSP:p,OCTET:m,DQUOTE:h,SP:g,HTAB:_,alphanum:v,reserved:y,unreserved:b,mark:x,escaped:S,LWS:C,SWS:w,HCOLON:T,TEXT_UTF8_TRIM:E,TEXT_UTF8char:D,UTF8_NONASCII:O,UTF8_CONT:k,LHEX:A,token:j,token_nodot:M,separators:N,word:P,STAR:ee,SLASH:F,EQUAL:I,LPAREN:te,RPAREN:ne,RAQUOT:re,LAQUOT:ie,COMMA:L,SEMI:R,COLON:ae,LDQUOT:oe,RDQUOT:se,comment:ce,ctext:le,quoted_string:ue,quoted_string_clean:de,qdtext:fe,quoted_pair:z,SIP_URI_noparams:pe,SIP_URI:me,uri_scheme:he,uri_scheme_sips:ge,uri_scheme_sip:B,userinfo:_e,user:ve,user_unreserved:ye,password:be,hostport:xe,host:Se,hostname:Ce,domainlabel:we,toplabel:Te,IPv6reference:Ee,IPv6address:De,h16:V,ls32:H,IPv4address:Oe,dec_octet:ke,port:Ae,uri_parameters:je,uri_parameter:Me,transport_param:Ne,user_param:Pe,method_param:Fe,ttl_param:Ie,maddr_param:Le,lr_param:Re,other_param:ze,pname:Be,pvalue:U,paramchar:Ve,param_unreserved:He,headers:Ue,header:W,hname:We,hvalue:Ge,hnv_unreserved:Ke,Request_Response:qe,Request_Line:Je,Request_URI:Ye,absoluteURI:Xe,hier_part:Ze,net_path:Qe,abs_path:$e,opaque_part:et,uric:tt,uric_no_slash:nt,path_segments:rt,segment:it,param:at,pchar:ot,scheme:st,authority:ct,srvr:lt,reg_name:ut,query:dt,SIP_Version:ft,INVITEm:pt,ACKm:mt,OPTIONSm:ht,BYEm:gt,CANCELm:_t,REGISTERm:vt,SUBSCRIBEm:yt,NOTIFYm:bt,REFERm:xt,Method:St,Status_Line:Ct,Status_Code:wt,extension_code:Tt,Reason_Phrase:G,Allow_Events:K,Call_ID:q,Contact:J,contact_param:Y,name_addr:Ot,display_name:kt,contact_params:At,c_p_q:X,c_p_expires:jt,delta_seconds:Mt,qvalue:Nt,generic_param:Z,gen_value:Q,Content_Disposition:Pt,disp_type:Ft,disp_param:It,handling_param:Lt,Content_Encoding:Rt,Content_Length:zt,Content_Type:Bt,media_type:Vt,m_type:Ht,discrete_type:Ut,composite_type:Wt,extension_token:Gt,x_token:Kt,m_subtype:qt,m_parameter:Jt,m_value:Yt,CSeq:Xt,CSeq_value:Zt,Expires:Qt,Event:$t,event_type:en,From:tn,from_param:nn,tag_param:rn,Max_Forwards:an,Min_Expires:on,Name_Addr_Header:sn,Proxy_Authenticate:cn,challenge:ln,other_challenge:un,auth_param:dn,digest_cln:fn,realm:pn,realm_value:mn,domain:hn,URI:gn,nonce:_n,nonce_value:vn,opaque:yn,stale:bn,algorithm:xn,qop_options:Sn,qop_value:Cn,Proxy_Require:wn,Record_Route:Tn,rec_route:En,Reason:Dn,reason_param:On,reason_cause:kn,Require:An,Route:jn,route_param:Mn,Subscription_State:Nn,substate_value:Pn,subexp_params:Fn,event_reason_value:In,Subject:Ln,Supported:Rn,To:zn,to_param:Bn,Via:Vn,via_param:Hn,via_params:Un,via_ttl:Wn,via_maddr:Gn,via_received:Kn,via_branch:qn,response_port:Jn,rport:Yn,sent_protocol:Xn,protocol_name:Zn,transport:Qn,sent_by:$n,via_host:er,via_port:tr,ttl:nr,WWW_Authenticate:rr,Session_Expires:ir,s_e_expires:ar,s_e_params:or,s_e_refresher:sr,extension_header:cr,header_value:lr,message_body:ur,uuid_URI:dr,uuid:fr,hex4:pr,hex8:mr,hex12:hr,Refer_To:gr,Replaces:_r,call_id:vr,replaces_param:yr,to_tag:br,from_tag:xr,early_flag:Sr};if(n!==void 0){if(r[n]===void 0)throw Error(`Invalid rule name: `+e(n)+`.`)}else n=`CRLF`;var i=0,a=0,o=0,s=[];function c(e){i<o||(i>o&&(o=i,s=[]),s.push(e))}function l(){var e;return t.substr(i,2)===`\r
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CCBarSDK={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},u=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},d=(e,r,i)=>(i=e==null?{}:t(a(e)),u(r||!e||!e.__esModule||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e)),f=e=>o.call(e,`module.exports`)?e[`module.exports`]:u(n({},`__esModule`,{value:!0}),e),p,m=s((()=>{p=class extends Error{code;category;retryable;requestId;callId;cause;serverCode;status;constructor(e,t,n,r={}){super(e),this.name=`CCBarError`,this.code=e,this.category=t,this.retryable=n,this.requestId=r.requestId,this.callId=r.callId,this.cause=r.cause,this.serverCode=r.serverCode,this.status=r.status}}}));m();var h=class{handlers=new Map;on(e,t){let n=this.handlers.get(e)??new Set;n.add(t),this.handlers.set(e,n);let r=!0;return()=>{r&&(r=!1,n.delete(t))}}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){[...this.handlers.get(e)??[]].forEach(e=>{try{e(t)}catch{}})}listenerCount(){return[...this.handlers.values()].reduce((e,t)=>e+t.size,0)}clear(){this.handlers.clear()}},g={new:new Set([`dialing`,`ringing`,`failed`]),dialing:new Set([`ringing`,`connecting`,`ended`,`failed`]),ringing:new Set([`connecting`,`ended`,`failed`]),connecting:new Set([`active`,`ended`,`failed`]),active:new Set([`held`,`ended`,`failed`]),held:new Set([`active`,`ended`,`failed`]),ended:new Set,failed:new Set},_=(e,t)=>g[e].has(t);function v(e,t){if(!_(e,t))throw new y(e,t);return t}var y=class extends p{constructor(e,t){super(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:{from:e,to:t}})}},b=v;function x(e){if(e.code!==`OK`)throw TypeError(`Unexpected session response code: ${e.code}`);if(e.data===void 0||e.data===null)throw TypeError(`Unexpected session response: missing data`);return e.data}m();var S=[`progress`,`accepted`,`confirmed`,`ended`,`failed`,`hold`,`unhold`,`mediaConnected`],C=3e4,w=class{options;currentState=`new`;sessionUnsubscribers=[];capabilities;disposed=!1;pendingOperation;incomingOperation;ownerTabId;ownerLost=!1;id;destination;platform;constructor(e){this.options=e,this.id=e.id,this.destination=e.destination,this.platform=e.platform,this.capabilities=e.capabilities??new Set;try{S.forEach(t=>{this.sessionUnsubscribers.push(e.session.on(t,e=>this.handleSessionEvent(t,e)))})}catch(t){this.cleanupSessionListeners();try{e.session.terminate()}catch{}throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:this.id,cause:t})}}get state(){return this.currentState}getResourceCounts(){return{timers:this.pendingOperation?.timer===void 0?0:1,listeners:this.sessionUnsubscribers.length}}async mute(e){this.assertNotDisposed(),this.assertOwner(e),this.assertMediaControlAllowed(),this.assertCapability(`mute`),this.invoke(()=>this.options.session.mute())}async unmute(e){this.assertNotDisposed(),this.assertOwner(e),this.assertMediaControlAllowed(),this.assertCapability(`mute`),this.invoke(()=>this.options.session.unmute())}async answer(e,t){this.assertNotDisposed(),this.assertOwner(t),this.assertIncomingCall(),this.assertCapability(`inbound`),this.assertIncomingOperationAvailable(),this.incomingOperation=`answer`;try{this.options.session.answer(e)}catch(e){throw this.incomingOperation=void 0,this.finishFailedIncomingOperation(e),this.operationError(e)}this.transitionIfAllowed(`connecting`,void 0,`accepted`)}async reject(e={},t){this.assertNotDisposed(),this.assertOwner(t),this.assertIncomingCall(),this.assertIncomingOperationAvailable(),this.incomingOperation=`reject`;let n;try{this.options.session.terminate()}catch(e){n=e}finally{this.incomingOperation=void 0,this.transitionIfStillRinging(`ended`,{reason:e.reason?.trim()||`rejected`})}if(n!==void 0)throw this.operationError(n)}async hold(e){this.assertNotDisposed(),this.assertOwner(e),this.assertHoldCapability(),this.assertState(`active`),this.assertCapability(`hold`),await this.startPendingOperation(`hold`,`held`,()=>this.options.session.hold())}async resume(e){this.assertNotDisposed(),this.assertOwner(e),this.assertHoldCapability(),this.assertState(`held`),this.assertCapability(`hold`),await this.startPendingOperation(`resume`,`active`,()=>this.options.session.unhold())}async sendDtmf(e,t){if(this.assertNotDisposed(),this.assertOwner(t),!/^[0-9A-D*#]$/.test(e))throw this.operationError();this.assertState(`active`),this.assertCapability(`dtmf`),this.invoke(()=>this.options.session.sendDtmf(e))}async transfer(e,t){if(this.assertNotDisposed(),this.assertOwner(t),this.assertTransferCapability(),this.assertState(`active`),this.assertCapability(`blind_transfer`),!E(e)||e.target.trim()===``)throw this.operationError();this.invoke(()=>this.options.session.refer(e.target.trim()))}async hangup(e){if(this.assertNotDisposed(),this.assertOwner(e),T(this.currentState))throw this.operationError();try{this.options.session.terminate(),T(this.currentState)||this.transitionTo(`ended`)}catch(e){throw this.operationError(e)}}beginOutbound(){this.assertNotDisposed(),this.assertCapability(`outbound`),this.transitionTo(`dialing`)}beginIncoming(){this.assertNotDisposed(),this.transitionTo(`ringing`)}setOwnerTabId(e){this.ownerTabId=e,this.ownerLost=!1}clearOwnerTabId(e={}){this.ownerTabId=void 0,this.ownerLost=e.lost===!0}getOwnerTabId(){return this.ownerTabId}assertOwnerForManager(e){this.assertOwner(e)}canBeReclaimed(){return this.currentState===`new`||this.currentState===`dialing`||this.currentState===`ringing`}dispose(){if(!this.disposed){if(this.rejectPendingOperation(),this.incomingOperation=void 0,this.disposed=!0,!T(this.currentState))try{this.options.session.terminate()}catch(e){this.reportOperationError(e)}this.cleanupSessionListeners();try{this.options.onDisposed?.()}catch{}}}handleSessionEvent(e,t){if((e===`accepted`||e===`confirmed`||e===`ended`||e===`failed`)&&(this.incomingOperation=void 0),!(this.disposed||T(this.currentState)))switch(e){case`progress`:this.transitionIfAllowed(`ringing`,t,e);break;case`accepted`:this.transitionIfAllowed(`connecting`,t,e);break;case`confirmed`:this.transitionToActive(t);break;case`mediaConnected`:this.currentState===`connecting`&&this.transitionTo(`active`,t);break;case`hold`:this.transitionIfAllowed(`held`,t,e);break;case`unhold`:this.transitionIfAllowed(`active`,t,e);break;case`ended`:this.transitionIfAllowed(`ended`,t,e);break;case`failed`:this.transitionIfAllowed(`failed`,t,e)}}transitionToActive(e){this.currentState!==`active`&&((this.currentState===`dialing`||this.currentState===`ringing`)&&this.transitionTo(`connecting`,e),this.transitionIfAllowed(`active`,e,`confirmed`))}transitionIfAllowed(e,t,n){this.currentState!==e&&(_(this.currentState,e)?this.transitionTo(e,t):this.reportIllegalTransition(e,n))}transitionIfStillRinging(e,t){this.currentState===`ringing`&&this.transitionTo(e,t)}transitionTo(e,t){if(this.currentState===e)return;if(!_(this.currentState,e))throw this.operationError();let n=this.currentState;this.currentState=e,T(e)&&this.rejectPendingOperation();try{this.options.onStateChanged?.({callId:this.id,from:n,to:e},t)}catch{}finally{T(e)&&this.dispose()}}startPendingOperation(e,t,n){if(this.pendingOperation!==void 0)throw this.operationError();return new Promise((r,i)=>{let a={kind:e,nextState:t,resolve:r,reject:i};this.pendingOperation=a,a.timer=setTimeout(()=>this.timeoutPendingOperation(a),C);let o;try{o=n()}catch(e){this.rejectPendingOperation(e);return}o.then(()=>this.resolvePendingOperation(a),e=>this.rejectPendingOperation(e,a))})}resolvePendingOperation(e){if(this.pendingOperation===e){if(this.clearPendingTimer(e),this.pendingOperation=void 0,this.disposed||T(this.currentState)){e.reject(this.operationError());return}try{this.transitionTo(e.nextState),e.resolve()}catch(t){e.reject(this.operationError(t))}}}rejectPendingOperation(e,t){let n=this.pendingOperation;n===void 0||t!==void 0&&n!==t||(this.clearPendingTimer(n),this.pendingOperation=void 0,n.reject(this.operationError(e)))}timeoutPendingOperation(e){this.pendingOperation===e&&(this.rejectPendingOperation(Error(`${e.kind} operation timed out`),e),this.dispose())}clearPendingTimer(e){e.timer!==void 0&&(clearTimeout(e.timer),e.timer=void 0)}reportIllegalTransition(e,t){this.reportOperationError({event:t,from:this.currentState,to:e})}reportOperationError(e){let t=e instanceof p&&e.callId===this.id?e:this.operationError(e);try{this.options.onError?.(t)}catch{}}finishFailedIncomingOperation(e){this.reportOperationError(e);try{this.options.session.terminate()}catch(t){e={operation:e,cleanup:t}}this.transitionIfStillRinging(`ended`,{reason:`incoming_operation_failed`,cause:e})}cleanupSessionListeners(){this.sessionUnsubscribers.splice(0).forEach(e=>{try{e()}catch{}})}assertState(e){if(this.currentState!==e)throw this.operationError()}assertMediaControlAllowed(){if(this.currentState!==`active`&&this.currentState!==`held`)throw this.operationError()}assertHoldCapability(){if(this.platform===`mobile-web`)throw this.capabilityError()}assertTransferCapability(){if(this.platform===`mobile-web`)throw this.capabilityError()}assertIncomingCall(){if(this.options.incoming!==!0||this.currentState!==`ringing`)throw this.operationError()}assertIncomingOperationAvailable(){if(this.incomingOperation!==void 0)throw this.operationError()}assertCapability(e){if(!this.capabilities.has(e))throw this.capabilityError()}invoke(e){try{e()}catch(e){throw this.operationError(e)}}assertNotDisposed(){if(this.disposed)throw this.operationError()}assertOwner(e){if(e!==void 0&&(this.ownerLost||this.ownerTabId!==void 0&&this.ownerTabId!==e))throw this.operationError()}capabilityError(){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:this.id})}operationError(e){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:this.id,cause:e})}};function T(e){return e===`ended`||e===`failed`}function E(e){return typeof e==`object`&&!!e&&e.type===`blind`&&typeof e.target==`string`}var D=0;function O(){return D+=1,`call_${Date.now().toString(36)}_${D.toString(36)}`}m();var k=`X-User-Data`,A=/[^\x20-\x7E]/,j=`userdata 只能是可见 ASCII(不能有换行/制表/中文):换行会构成 SIP 头注入;要传中文或 JSON 请调用方先 encodeURIComponent / base64,再在平台侧解回来`;function M(e){if(typeof e!=`string`)return[];let t=e.trim();if(t===``)return[];if(A.test(t))throw new p(`CALL_INVALID_USERDATA`,`call`,!1,{cause:j});return[`${k}: ${t}`]}m();var N=class{events=new P;calls=new Map;options;incomingUnsubscribe;activeCallId=null;incomingSessionSnapshot;callSessions=new Map;callOwners=new Map;ownerLostCalls=new Set;pendingDialCount=0;pendingDestinations=new Set;activeOperationPromise=Promise.resolve();operationGeneration=0;automaticActiveTransition;disposed=!1;terminalNotified=new Set;terminalOperations=new Map;disposeOperation;constructor(e){this.options=e,this.incomingSessionSnapshot=e.session;try{this.incomingUnsubscribe=e.sip.onIncoming(e=>this.handleIncoming(e))}catch(e){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}}on(e,t){return this.disposed?()=>void 0:this.events.on(e,t)}async dial(e,t){this.assertNotDisposed();let n=this.operationGeneration,r=e.destination.trim();if(r===``)throw new p(`CALL_INVALID_DESTINATION`,`call`,!1);let i=M(e.userdata);this.requireCapability(t,`outbound`);let a=this.callLimit(t);if(this.options.platform===`mobile-web`&&this.calls.size+this.pendingDialCount>=a)throw this.capabilityError();if(this.calls.size+this.pendingDialCount>=a||this.pendingDestinations.has(r)||[...this.calls.values()].some(e=>e.destination===r))throw new p(`CALL_ALREADY_EXISTS`,`call`,!1);this.pendingDialCount+=1,this.pendingDestinations.add(r);let o=O(),s;try{s=await this.holdActiveCallForNewCall(),this.assertGeneration(n,o);let a;try{a=this.options.sip.dial(r,this.dialOptions(o,t,e.type,i))}catch(e){throw this.dialError(e,o)}this.assertGeneration(n,o);let c;try{c=new w({id:o,destination:r,platform:this.options.platform,capabilities:this.effectiveCapabilities(t),session:a,onStateChanged:(e,t)=>this.handleStateChanged(c,e,t),onError:e=>this.events.emit(`error`,{error:e}),onDisposed:()=>this.handleDisposed(c)})}catch(e){throw this.dialError(e,o)}if(!this.isCurrentGeneration(n))throw c.dispose(),this.callOperationError(c.id);this.calls.set(c.id,c),this.callSessions.set(c.id,a),this.options.onCallCreated?.(c.id,a);try{c.beginOutbound()}catch(e){throw c.dispose(),this.calls.delete(c.id),this.callSessions.delete(c.id),this.dialError(e,c.id)}if(!this.isCurrentGeneration(n))throw c.dispose(),this.calls.delete(c.id),this.callSessions.delete(c.id),this.callOperationError(c.id);return this.events.emit(`call.created`,{callId:c.id,state:c.state}),c}catch(e){if(this.isCurrentGeneration(n)&&s!==void 0&&this.isManagedCall(s)&&s.state===`held`)try{await s.resume()}catch(t){throw this.compensationError(s.id,void 0,e,t)}throw e}finally{--this.pendingDialCount,this.pendingDestinations.delete(r)}}async answer(e,t,n,r){this.assertNotDisposed();let i=this.requireCall(e);if(this.options.platform===`mobile-web`&&t.policy.mobileIncomingEnabled!==!0)throw this.capabilityError(e);let a={iceServers:t.iceServers,pcConfig:{iceServers:t.iceServers},...n===void 0?{}:{mediaConstraints:n}};await i.answer(a,r)}async reject(e,t,n){this.assertNotDisposed(),await this.requireCall(e).reject(t,n)}getCalls(){return[...this.calls.values()]}hasNonTerminalCalls(){return this.calls.size>0}getResourceCounts(){let e=[...this.calls.values()].map(e=>e.getResourceCounts());return{timers:e.reduce((e,t)=>e+t.timers,0),listeners:this.events.listenerCount()+e.reduce((e,t)=>e+t.listeners,0),terminalRecords:this.terminalNotified.size+this.terminalOperations.size}}getActiveCall(){return this.activeCallId===null?void 0:this.calls.get(this.activeCallId)}async setActiveCall(e,t){this.assertNotDisposed(),this.requireCall(e).assertOwnerForManager(t),await this.enqueueActiveOperation(t=>this.switchActiveCall(e,t))}async claimCall(e,t){this.assertNotDisposed();let n=t.trim();if(n===``)throw this.callOperationError(e);let r=this.requireCall(e),i=this.callOwners.get(e);if(i!==n){if(i!==void 0||this.ownerLostCalls.has(e)&&!r.canBeReclaimed())throw this.callOperationError(e);this.ownerLostCalls.delete(e),this.callOwners.set(e,n),r.setOwnerTabId(n),this.emitOwnershipChanged({callId:e,state:`owned`,ownerTabId:n})}}async releaseCall(e,t){this.assertNotDisposed();let n=this.requireCall(e);if(this.callOwners.get(e)!==t)throw this.callOperationError(e);this.callOwners.delete(e);let r=!n.canBeReclaimed();r?this.ownerLostCalls.add(e):this.ownerLostCalls.delete(e),n.clearOwnerTabId({lost:r}),this.emitOwnershipChanged({callId:e,state:r?`owner-lost`:`released`})}getCallOwner(e){return this.callOwners.get(e)}releaseOwnedCalls(e){for(let[t,n]of[...this.callOwners.entries()]){if(n!==e)continue;let r=this.calls.get(t);if(r===void 0){this.callOwners.delete(t),this.ownerLostCalls.delete(t);continue}this.callOwners.delete(t);let i=!r.canBeReclaimed();i?this.ownerLostCalls.add(t):this.ownerLostCalls.delete(t),r.clearOwnerTabId({lost:i}),this.emitOwnershipChanged({callId:t,state:i?`owner-lost`:`released`})}}dispose(e={}){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposed=!0,this.operationGeneration+=1,this.automaticActiveTransition=void 0,this.activeOperationPromise=Promise.resolve(),this.events.clear();try{this.incomingUnsubscribe()}catch{}this.activeCallId=null;let t=[...this.calls.values()];this.calls.clear(),this.callSessions.clear(),this.callOwners.clear(),this.ownerLostCalls.clear();let n=Promise.all(t.map(async t=>{let n;try{e.terminateCalls===!0&&t.state!==`ended`&&t.state!==`failed`?await t.hangup():t.dispose()}catch(e){n=e,t.dispose()}try{await this.notifyCallTerminal(t.id)}catch(e){n??=e}if(n!==void 0)throw n})).finally(()=>{this.terminalNotified.clear(),this.terminalOperations.clear()}).then(()=>void 0);return this.disposeOperation=n,n}updateSession(e){this.disposed||(this.incomingSessionSnapshot=e)}async switchActiveCall(e,t){this.assertGeneration(t,e);let n=this.requireCall(e),r=this.getActiveCall();if(r?.id===n.id)return;if(n.state!==`held`&&n.state!==`active`)throw this.callOperationError(e);let i=n.state===`held`;try{if(r!==void 0&&await r.hold(),this.assertGeneration(t,n.id),n.state===`held`&&await n.resume(),this.assertGeneration(t,n.id),!this.isManagedCall(n)||n.state!==`active`)throw this.callOperationError(n.id);this.commitActive(n,t)}catch(a){if(!this.isCurrentGeneration(t))throw this.callOperationError(n.id,a);if(r===void 0)throw this.callOperationError(e,a);try{let e=n.state===`active`;i&&e&&this.isManagedCall(n)&&await n.hold(),this.assertGeneration(t,n.id),r.state===`held`&&this.isManagedCall(r)&&await r.resume(),this.assertGeneration(t,r.id),r.state===`active`&&this.isManagedCall(r)&&this.commitActive(r,t)}catch(e){throw this.compensationError(r.id,n.id,a,e)}throw this.isManagedCall(r)&&r.state===`active`&&this.commitActive(r,t),this.callOperationError(n.id,{operation:a,restoredCallId:r.id})}}handleStateChanged(e,t,n){if(this.disposed)return;let r=this.callSessions.get(e.id);if(r!==void 0&&this.options.onCallStateChanged?.(e.id,r),this.events.emit(`call.stateChanged`,t),t.to===`active`&&this.activeCallId!==e.id){let t=this.getActiveCall();if(this.options.autoHoldPreviousCall===!0&&t!==void 0&&t.id!==e.id&&t.state===`active`){let n=this.operationGeneration;this.enqueueActiveOperation(n=>this.switchAutomaticActiveCall(t,e,n)).catch(e=>{this.isCurrentGeneration(n)&&this.events.emit(`error`,{error:e})})}else this.commitActive(e)}t.to===`held`&&this.activeCallId===e.id&&this.automaticActiveTransition?.previous.id!==e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})),(t.to===`ended`||t.to===`failed`)&&(this.calls.delete(e.id),this.callSessions.delete(e.id),this.callOwners.delete(e.id),this.ownerLostCalls.delete(e.id),this.activeCallId===e.id&&this.automaticActiveTransition?.previous.id!==e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})),this.notifyCallTerminal(e.id),t.to===`ended`?this.events.emit(`call.ended`,{callId:e.id,reason:ee(n)}):this.events.emit(`call.failed`,{callId:e.id,error:te(n,e.id)}))}async switchAutomaticActiveCall(e,t,n){this.automaticActiveTransition={previous:e,target:t};let r;try{if(this.assertGeneration(n,t.id),!this.isManagedCall(t)||t.state!==`active`)return;if(!this.isManagedCall(e)||e.state!==`active`){this.commitActive(t,n);return}if(await e.hold(),this.assertGeneration(n,t.id),!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}if(!this.isManagedCall(t)||t.state!==`active`)r=Error(`target call is no longer active`);else{this.commitActive(t,n);return}}catch(e){r=e}finally{this.automaticActiveTransition?.target.id===t.id&&(this.automaticActiveTransition=void 0)}if(!this.isCurrentGeneration(n))return;if(!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}let i=await this.restoreAutomaticActiveCall(e,t,r,n);if(this.isCurrentGeneration(n)){if(i.error!==void 0)throw i.error;if(!this.isManagedCall(e)){this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,n);return}throw this.callOperationError(t.id,{operation:r,restoredCallId:e.id})}}async restoreAutomaticActiveCall(e,t,n,r){if(!this.isCurrentGeneration(r))return{};if(!this.isManagedCall(e))return this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,r),{};let i;try{this.isManagedCall(t)&&t.state===`active`&&await t.hold(),this.assertGeneration(r,t.id),this.isManagedCall(e)&&e.state===`held`&&await e.resume(),this.assertGeneration(r,e.id)}catch(e){i=e}return this.isCurrentGeneration(r)?this.isManagedCall(e)?i===void 0?(e.state===`active`&&this.commitActive(e,r),{}):{error:this.compensationError(e.id,t.id,n,i)}:(this.isManagedCall(t)&&t.state===`active`&&this.commitActive(t,r),{}):{}}handleDisposed(e){this.disposed||(this.calls.delete(e.id),this.callSessions.delete(e.id),this.callOwners.delete(e.id),this.ownerLostCalls.delete(e.id),this.notifyCallTerminal(e.id),this.activeCallId===e.id&&(this.activeCallId=null,this.events.emit(`call.activeChanged`,{callId:null})))}commitActive(e,t=this.operationGeneration){this.isCurrentGeneration(t)&&this.isManagedCall(e)&&e.state===`active`&&this.activeCallId!==e.id&&(this.activeCallId=e.id,this.events.emit(`call.activeChanged`,{callId:e.id}))}handleIncoming(e){if(this.disposed)return;let t=O(),n=this.incomingSessionSnapshot;if(n===void 0||!n.policy.incomingEnabled||!this.effectiveCapabilities(n).has(`inbound`)){this.terminateUnsupportedIncoming(e),this.events.emit(`error`,{error:this.capabilityError(t)});return}let r=e.from??e.id;if(this.calls.size+this.pendingDialCount>=this.callLimit(n)){this.terminateUnsupportedIncoming(e),this.events.emit(`error`,{error:new p(`CALL_ALREADY_EXISTS`,`call`,!1,{callId:t})});return}let i;try{i=new w({id:t,destination:r,platform:this.options.platform,incoming:!0,capabilities:this.effectiveCapabilities(n),session:e,onStateChanged:(e,t)=>this.handleStateChanged(i,e,t),onError:e=>this.events.emit(`error`,{error:e}),onDisposed:()=>this.handleDisposed(i)})}catch(e){this.events.emit(`error`,{error:this.callOperationError(t,e)});return}this.calls.set(i.id,i),this.callSessions.set(i.id,e),this.options.onCallCreated?.(i.id,e);try{i.beginIncoming(),this.events.emit(`call.incoming`,{callId:i.id,from:r})}catch(e){i.dispose(),this.events.emit(`error`,{error:this.callOperationError(i.id,e)})}}terminateUnsupportedIncoming(e){try{e.terminate()}catch{}}async holdActiveCallForNewCall(){if(this.options.autoHoldPreviousCall!==!0)return;let e=this.getActiveCall();if(e!==void 0&&e.state===`active`)return await e.hold(),e}enqueueActiveOperation(e){let t=this.operationGeneration,n=()=>this.isCurrentGeneration(t)?e(t):Promise.reject(this.callOperationError(``)),r=this.activeOperationPromise.then(n,n);return this.activeOperationPromise=r.catch(()=>void 0),r}isManagedCall(e){return!this.disposed&&this.calls.get(e.id)===e&&e.state!==`ended`&&e.state!==`failed`}isCurrentGeneration(e){return!this.disposed&&this.operationGeneration===e}assertGeneration(e,t){if(!this.isCurrentGeneration(e))throw this.callOperationError(t??``)}effectiveCapabilities(e){let t=new Set(e.capabilities);return this.options.platform===`mobile-web`&&(t.delete(`hold`),t.delete(`blind_transfer`),e.policy.mobileIncomingEnabled!==!0&&t.delete(`inbound`)),t}requireCapability(e,t,n){if(!this.effectiveCapabilities(e).has(t))throw this.capabilityError(n)}requireCall(e){let t=this.calls.get(e);if(t===void 0)throw this.callOperationError(e);return t}emitOwnershipChanged(e){this.events.emit(`call.ownershipChanged`,e)}notifyCallTerminal(e){let t=this.terminalOperations.get(e);if(t!==void 0)return t;if(this.terminalNotified.has(e))return Promise.resolve();this.terminalNotified.add(e);let n;try{n=this.options.onCallTerminal?.(e)}catch(t){this.events.emit(`error`,{error:this.callOperationError(e,t)});let n=Promise.reject(this.callOperationError(e,t));return this.terminalOperations.set(e,n),n.catch(()=>void 0).finally(()=>this.pruneTerminalRecord(e,n)),n}let r=Promise.resolve(n).catch(t=>{throw this.events.emit(`error`,{error:this.callOperationError(e,t)}),t});return this.terminalOperations.set(e,r),r.catch(()=>void 0).finally(()=>this.pruneTerminalRecord(e,r)),r}pruneTerminalRecord(e,t){this.terminalOperations.get(e)===t&&this.terminalOperations.delete(e),this.calls.has(e)||this.terminalNotified.delete(e)}assertNotDisposed(){if(this.disposed)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}callOperationError(e,t){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e,cause:t})}capabilityError(e){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e})}compensationError(e,t,n,r){return this.callOperationError(e,{operation:n,rollback:r,originalCallId:e,targetCallId:t})}callLimit(e){let t=this.options.platform===`mobile-web`?1:2,n=this.options.maxConcurrentCalls??t;return Math.min(t,Math.max(1,n),Math.max(1,e.policy.maxConcurrentCalls))}dialOptions(e,t,n,r=[]){return{iceServers:t.iceServers,extraHeaders:[`X-XCall-Call-ID: ${e}`,`X-XCall-Session-ID: ${t.sessionId}`,...r],...n===void 0?{}:{type:n}}}dialError(e,t){return e instanceof p?new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:t,cause:e.cause??e}):new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:e})}},P=class{handlers=new Map;on(e,t){let n=this.handlers.get(e)??new Set,r=t;n.add(r),this.handlers.set(e,n);let i=!0;return()=>{i&&(i=!1,n.delete(r))}}emit(e,t){let n=this.handlers.get(e);n!==void 0&&[...n].forEach(e=>{try{e(t)}catch{}})}listenerCount(){return[...this.handlers.values()].reduce((e,t)=>e+t.size,0)}clear(){this.handlers.clear()}};function ee(e){if(typeof e!=`object`||!e||!(`reason`in e))return`ended`;let t=e.reason;return typeof t==`string`&&t!==``?t:`ended`}function te(e,t){if(e instanceof p)return new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:t,cause:e.cause??e});if(typeof e==`object`&&e&&`error`in e){let n=e.error;if(n instanceof p)return new p(n.code,n.category,n.retryable,{requestId:n.requestId,callId:t,cause:n.cause??n});if(n instanceof Error)return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:n})}return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:t,cause:e})}var F=`3.1.9`,I=`[REDACTED]`,ne=/\bBearer\s+[^\s,;"'}]+/gi,re=/(\bAuthorization\s*[:=]\s*)Digest\s+[^\r\n]*/gi,ie=/(\bAuthorization\s*[:=]\s*)(?:(Bearer|Basic|Digest|Token)\s+)?[^\s,;"'}]+/gi,L=/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,R=/\b((?:sip|sips|turn|turns|ws|wss):(?:\/\/)?)[^/?#@\s:]+:[^/?#@\s]+@/gi,ae=/(\b(?:sip(?:Register)?Ticket|registerTicket|wssTicket|turnCredential|credential|accessToken|refreshToken|appSecret|password|jwt|ticket)\b\s*[:=]\s*)(["']?)([^\s,;&}"']+)(["']?)/gi,oe=/(?<!\d)(1[3-9]\d)\d{4}(\d{4})(?!\d)/g,se=/(?:authorization|token|ticket|credential|password|secret)$/i;function ce(e,t={}){let n=e.replace(ne,`Bearer ${I}`).replace(re,(e,t)=>`${t}Digest ${I}`).replace(ie,(e,t,n)=>`${t}${n===void 0?``:`${n} `}${I}`).replace(L,I).replace(R,(e,t)=>`${t}${I}@`).replace(ae,(e,t)=>`${t}${I}`);return t.maskPhoneNumbers!==!1&&(n=n.replace(oe,`$1****$2`)),n}function le(e,t={}){return ue(e,t,new WeakSet)}function ue(e,t,n){if(typeof e==`string`)return ce(e,t);if(typeof e!=`object`||!e)return e;if(n.has(e))return`[Circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>ue(e,t,n));let r={};return Object.entries(e).forEach(([e,i])=>{r[e]=se.test(e)?I:ue(i,t,n)}),r}m();function de(e){if(!z(e))throw B(`Invalid worker message`);if(e.version!==1)throw B(`Unsupported worker protocol version`);if(e.type===`attach`||e.type===`detach`)return fe(e),e;if(e.type===`command`){if(fe(e),typeof e.command!=`string`||e.payload!==void 0&&!z(e.payload))throw B(`Invalid worker command`);return e}if(e.type===`response`){if(typeof e.requestId!=`string`||typeof e.ok!=`boolean`)throw B(`Invalid worker response`);return e}if(e.type===`event`){if(typeof e.event!=`string`||!(`payload`in e))throw B(`Invalid worker event`);return e}throw B(`Unknown worker message type`)}function fe(e){if(typeof e.requestId!=`string`||typeof e.tabId!=`string`)throw B(`Worker request requires requestId and tabId`)}function z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function B(e){return new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}m();var pe=class{port;timeoutMs;pending=new Map;eventHandlers=new Set;closed=!1;lifecycleState=`connected`;constructor(e,t={}){this.port=e,this.timeoutMs=t.timeoutMs??15e3,this.port.onmessage=e=>this.handleMessage(e.data),this.port.start()}request(e){return this.closed?Promise.reject(new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)):this.pending.has(e.requestId)?Promise.reject(new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{requestId:e.requestId})):this.lifecycleState===`reconnecting`&&e.type===`command`&&(e.command===`dial`||e.command===`answer`)?Promise.reject(new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0,{callId:e.payload?.callId})):new Promise((t,n)=>{let r=setTimeout(()=>{this.pending.delete(e.requestId),n(new p(`NETWORK_TIMEOUT`,`network`,!0,{requestId:e.requestId}))},this.timeoutMs);this.pending.set(e.requestId,{resolve:e=>t(e),reject:n,timer:r}),this.port.postMessage(e)})}onEvent(e){return this.closed?()=>void 0:(this.eventHandlers.add(e),()=>this.eventHandlers.delete(e))}getLifecycleState(){return this.lifecycleState}close(){this.closed||(this.closed=!0,this.pending.forEach(e=>{clearTimeout(e.timer),e.reject(new p(`SDK_ALREADY_DISPOSED`,`internal`,!1))}),this.pending.clear(),this.eventHandlers.clear(),this.port.close())}handleMessage(e){try{let t=de(e);if(t.type===`event`){t.event===`connection.stateChanged`&&me(t.payload)&&(this.lifecycleState=t.payload.state),this.eventHandlers.forEach(e=>e(t));return}if(t.type!==`response`)return;let n=this.pending.get(t.requestId);if(n===void 0)return;this.pending.delete(t.requestId),clearTimeout(n.timer),t.ok?n.resolve(t.result):n.reject(he(t))}catch(e){this.pending.forEach(t=>{clearTimeout(t.timer),t.reject(e)}),this.pending.clear()}}};function me(e){return typeof e==`object`&&!!e&&`state`in e&&(e.state===`connected`||e.state===`reconnecting`)}function he(e){let t=e.error;return new p(t?.code??`SDK_INTERNAL_ERROR`,t?.category??`internal`,t?.retryable??!1,{requestId:e.requestId,...t?.message===void 0?{}:{cause:t.message},...t?.serverCode===void 0?{}:{serverCode:t.serverCode},...t?.status===void 0?{}:{status:t.status}})}m();function ge(e={}){if((e.enabled??`auto`)===!1)return{mode:`single-tab`,reason:`disabled`};let t=e.locationHref??ve(),n=_e(e.url,t),r=t=>{if(e.fallback===`error`)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:t});return{mode:`single-tab`,reason:t}};if(n===void 0)return r(`SharedWorker URL is unavailable`);if(!be(n,t))return r(`SharedWorker URL must be same-origin`);let i=e.workerCtor??ye();if(i===void 0)return r(`SharedWorker is not supported`);let a;try{a=new i(n,e.name===void 0?void 0:{name:e.name})}catch(e){return r(`SharedWorker construction failed: ${e instanceof Error?e.message:String(e)}`)}let o=e.tabId??xe(),s=new pe(a.port),c={version:1,type:`attach`,requestId:Se(),tabId:o},l=s.request(c).then(()=>void 0).catch(e=>{throw s.close(),e});return{mode:`shared`,worker:a,client:s,tabId:o,workerUrl:n,ready:l}}function _e(e,t=ve()){try{return t===void 0?void 0:new URL(e??`./shared-worker.js`,t).toString()}catch{return}}function ve(){return typeof location>`u`?void 0:location.href}function ye(){if(typeof SharedWorker==`function`)return SharedWorker}function be(e,t){if(t===void 0)return!0;try{return new URL(e,t).origin===new URL(t).origin}catch{return!1}}function xe(){return`tab-${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Se(){return`attach-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}m();var Ce=class{mediaDevices;createAudioElement;outputCapability;outputDeviceId;outputGeneration=0;outputTail;constructor(e={}){this.mediaDevices=e.mediaDevices===null?void 0:e.mediaDevices??we(),this.createAudioElement=e.createAudioElement}async requestPermission(e={}){let t=this.requireMediaDevices(),n;try{n=await t.getUserMedia({audio:e})}catch(e){throw De(e)}Te(n)}async getDevices(){if(this.mediaDevices===void 0)return[];try{return(await this.mediaDevices.enumerateDevices()).filter(e=>e.kind===`audioinput`||e.kind===`audiooutput`&&this.supportsOutputSelection())}catch(e){throw V(e)}}getCapabilities(){return{input:this.mediaDevices!==void 0,output:this.supportsOutputSelection()}}supportsOutputSelection(){if(this.outputCapability!==void 0)return this.outputCapability;let e=this.createAudioElementSafely();return this.outputCapability=e!==void 0&&typeof e.setSinkId==`function`,this.outputCapability}async setOutputDevice(e,t){if(!this.supportsOutputSelection())throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);this.outputDeviceId=e;let n=++this.outputGeneration;t!==void 0&&await this.enqueueOutput(async()=>{n===this.outputGeneration&&await this.applyOutputDevice(e,t)})}async applyConfiguredOutputDevice(e){if(this.outputDeviceId===void 0||e===void 0)return;let t=this.outputDeviceId,n=this.outputGeneration;await this.enqueueOutput(async()=>{n===this.outputGeneration&&await this.applyOutputDevice(t,e)})}getOutputDeviceId(){return this.outputDeviceId}async applyOutputDevice(e,t){let n=t;if(typeof n.setSinkId!=`function`)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);try{await n.setSinkId(e)}catch(e){throw H(e)}}enqueueOutput(e){let t=this.outputTail,n=t===void 0?e():t.then(e,e),r=n.catch(()=>void 0);return this.outputTail=r,r.then(()=>{this.outputTail===r&&(this.outputTail=void 0)}),n}async openInputStream(e){let t=this.requireMediaDevices();try{return await t.getUserMedia({audio:{deviceId:{exact:e}}})}catch(e){throw Ee(e)}}requireMediaDevices(){if(this.mediaDevices===void 0)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);return this.mediaDevices}createAudioElementSafely(){if(this.createAudioElement!==void 0)try{return this.createAudioElement()}catch{return}if(typeof document<`u`)try{return document.createElement(`audio`)}catch{return}}};function we(){return globalThis.navigator?.mediaDevices}function Te(e){let t;try{t=e.getTracks()}catch{return}t.forEach(e=>{try{e.stop()}catch{}})}function Ee(e){let t=Oe(e);return t===`NotFoundError`||t===`OverconstrainedError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotReadableError`||t===`AbortError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function De(e){let t=Oe(e);return t===`NotFoundError`||t===`OverconstrainedError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotReadableError`||t===`AbortError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function V(e){let t=Oe(e);return t===`NotFoundError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):t===`AbortError`||t===`NotReadableError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function H(e){let t=Oe(e);return t===`NotFoundError`?new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{cause:e}):t===`NotAllowedError`||t===`SecurityError`?new p(`MEDIA_PERMISSION_DENIED`,`media`,!1,{cause:e}):t===`AbortError`||t===`NotReadableError`?new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{cause:e}):new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}function Oe(e){if(typeof e!=`object`||!e||!(`name`in e))return;let t=e.name;return typeof t==`string`?t:void 0}m();var ke=class{createAudioElement;bindings=new Map;audioOwners=new Map;trackOwners=new Map;generations=new Map;pendingPlays=new Map;constructor(e=Ae){this.createAudioElement=e}async bind(e,t){let n=this.bindings.get(e);if(n?.stream===t)return;let r=je(e,t),i;try{i=this.createAudioElement()}catch(t){throw Me(r,this.trackOwners),new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e,cause:t})}let a=this.audioOwners.get(i);if(a!==void 0&&a!==e)throw Me(r,this.trackOwners),new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e});try{i.autoplay=!0,i.playsInline=!0}catch(t){throw Me(r,this.trackOwners),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:t})}try{i.srcObject=t}catch(t){throw Me(r,this.trackOwners),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:t})}this.acquireTracks(r),n!==void 0&&this.releaseBinding(n,n.audio!==i);let o=this.nextGeneration(e);this.audioOwners.set(i,e);let s={callId:e,audio:i,stream:t,tracks:r,generation:o};this.bindings.set(e,s),this.beginPlay(e);try{await i.play()}catch(t){if(!this.isCurrent(e,o))return;throw new p(`MEDIA_PLAYBACK_BLOCKED`,`media`,!1,{callId:e,cause:t})}finally{this.finishPlay(e)}this.isCurrent(e,o)}async play(e){let t=this.bindings.get(e);if(t===void 0)throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e});let n=t.generation;this.beginPlay(e);try{await t.audio.play()}catch(t){if(!this.isCurrent(e,n))return;throw new p(`MEDIA_PLAYBACK_BLOCKED`,`media`,!1,{callId:e,cause:t})}finally{this.finishPlay(e)}this.isCurrent(e,n)}getAudioElement(e){return this.bindings.get(e)?.audio}getResourceCounts(){return{tracks:this.trackOwners.size,audioElements:this.audioOwners.size}}release(e){this.nextGeneration(e);let t=this.bindings.get(e);t!==void 0&&this.releaseBinding(t),this.cleanupGeneration(e)}releaseAll(){[...this.bindings.keys()].forEach(e=>this.release(e))}releaseBinding(e,t=!0){if(this.bindings.get(e.callId)===e&&this.bindings.delete(e.callId),this.audioOwners.get(e.audio)===e.callId&&this.audioOwners.delete(e.audio),t)try{e.audio.srcObject=null}catch{}e.tracks.forEach(e=>this.releaseTrack(e))}acquireTracks(e){e.forEach(e=>this.trackOwners.set(e,(this.trackOwners.get(e)??0)+1))}releaseTrack(e){let t=this.trackOwners.get(e);if(t===void 0||t<=1){this.trackOwners.delete(e),Pe(e);return}this.trackOwners.set(e,t-1)}beginPlay(e){this.pendingPlays.set(e,(this.pendingPlays.get(e)??0)+1)}finishPlay(e){let t=this.pendingPlays.get(e)??0;t<=1?this.pendingPlays.delete(e):this.pendingPlays.set(e,t-1),this.cleanupGeneration(e)}nextGeneration(e){let t=(this.generations.get(e)??0)+1;return this.generations.set(e,t),t}cleanupGeneration(e){!this.bindings.has(e)&&!this.pendingPlays.has(e)&&this.generations.delete(e)}isCurrent(e,t){return this.generations.get(e)===t&&this.bindings.get(e)?.generation===t}};function Ae(){if(typeof document>`u`)throw new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1);return document.createElement(`audio`)}function je(e,t){try{return[...new Set(t.getAudioTracks())].filter(e=>e.kind===`audio`)}catch(n){try{return[...new Set(t.getTracks())].filter(e=>e.kind===`audio`)}catch(r){throw Ne(t),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e,cause:n??r})}}}function Me(e,t){e.forEach(e=>{(t.get(e)??0)===0&&Pe(e)})}function Ne(e){try{[...new Set(e.getTracks())].filter(e=>e.kind===`audio`).forEach(Pe)}catch{}}function Pe(e){try{e.stop()}catch{}}m();var Fe=class{deviceManager;remoteAudio;getActiveCall;createRemoteStream;calls=new Map;resources=new Set;inputOperations=new Map;senderQueues=new Map;releaseOperations=new Map;callReleaseOperations=new Map;releaseErrors=new WeakMap;releaseAllOperation;disposeOperation;disposing=!1;disposed=!1;constructor(e={}){let t={mediaDevices:e.mediaDevices,createAudioElement:e.createAudioElement};this.deviceManager=new Ce(t),this.remoteAudio=new ke(e.createAudioElement),this.getActiveCall=e.getActiveCall,this.createRemoteStream=e.createRemoteStream??He}requestPermission(e){return this.assertNotDisposed(),this.deviceManager.requestPermission(e)}getDevices(){return this.assertNotDisposed(),this.deviceManager.getDevices()}getCapabilities(){return this.assertNotDisposed(),this.deviceManager.getCapabilities()}supportsOutputSelection(){return this.assertNotDisposed(),this.deviceManager.supportsOutputSelection()}registerCallMedia(e,t){this.assertNotDisposed();let n=this.calls.get(e);n!==void 0&&this.releaseResource(n).catch(e=>{this.releaseErrors.set(n,e)});let r=Ie(t)?t:{peerConnection:t},i={callId:e,peerConnection:r.peerConnection,senders:new Map,localTracks:new Set,pendingTracks:new Set,generation:1,released:!1,peerClosed:!1};if(this.captureSenders(i,r.getSenderKind),this.resources.add(i),r.localTracks?.forEach(e=>{e.kind===`audio`&&i.localTracks.add(e)}),this.calls.set(e,i),r.trackSource!==void 0)try{i.trackSourceUnsubscribe=r.trackSource.onTrack(e=>this.handleTrackEvent(i,e))}catch{}return async()=>{let e=this.releaseOperations.get(i);if(e!==void 0)await e;else if(this.releaseErrors.has(i))throw this.releaseErrors.get(i);else await this.releaseResource(i);let t=this.releaseErrors.get(i);if(t!==void 0)throw t}}async setInputDevice(e,t){this.assertNotDisposed();let n=t??this.getActiveCall?.();this.assertActiveCall(n),this.assertDeviceSelectionCapability(n);let r=this.ensureCallMedia(n),i=(this.inputOperations.get(n.callId)??Promise.resolve()).then(()=>this.performInputSwitch(e,n,r),()=>this.performInputSwitch(e,n,r));this.inputOperations.set(n.callId,i);try{await i}finally{this.inputOperations.get(n.callId)===i&&this.inputOperations.delete(n.callId)}}setOutputDevice(e,t){this.assertNotDisposed();let n=t??this.getActiveCall?.()?.callId,r=n===void 0?void 0:this.remoteAudio.getAudioElement(n);return this.deviceManager.setOutputDevice(e,r)}async bindRemoteTrack(e,t){this.assertNotDisposed();let n;try{await this.remoteAudio.bind(e,t)}catch(e){n=e}let r;try{await this.deviceManager.applyConfiguredOutputDevice(this.remoteAudio.getAudioElement(e))}catch(e){r=e}if(n!==void 0)throw n;if(r!==void 0)throw r}playRemoteAudio(e){return this.assertNotDisposed(),this.remoteAudio.play(e)}getResourceCounts(){let e=new Set;this.resources.forEach(t=>{t.localTracks.forEach(t=>e.add(t)),t.pendingTracks.forEach(t=>e.add(t))});let t=this.remoteAudio.getResourceCounts();return{listeners:[...this.resources].filter(e=>e.trackSourceUnsubscribe!==void 0).length,tracks:e.size+t.tracks,peerConnections:this.resources.size,audioElements:t.audioElements}}releaseResource(e){let t=this.releaseOperations.get(e);if(t!==void 0)return t;if(!this.resources.has(e))return Promise.resolve();let n=e.callId;this.remoteAudio.release(n),this.releaseErrors.delete(e),this.calls.get(n)===e&&this.calls.delete(n),e.generation+=1,e.released=!0,this.unsubscribeTrackSource(e);let r=new Set([...e.localTracks,...e.pendingTracks]),i=[...e.senders.values()].filter(e=>e.audio).map(t=>({senderResource:t,promise:this.enqueueSender(e,t,()=>Re(t.sender),!0)})),a=Promise.all(i.map(async e=>{try{return await e.promise,{senderResource:e.senderResource,cause:void 0}}catch(t){return{senderResource:e.senderResource,cause:t}}})).then(async t=>{let i=new Set,a=[];if(t.forEach(e=>{if(e.cause!==void 0){a.push(e.cause);let t=U(e.senderResource.sender);t?.kind===`audio`&&i.add(t);return}let t=U(e.senderResource.sender);t?.kind===`audio`&&r.add(t)}),r.forEach(e=>{i.has(e)||Ve(e)}),a.length>0)throw e.localTracks.clear(),e.pendingTracks.clear(),i.forEach(t=>e.localTracks.add(t)),new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:n,cause:a[0]});if(!e.peerClosed&&e.peerConnection.close!==void 0)try{await e.peerConnection.close(),e.peerClosed=!0}catch(t){let r=[...e.senders.values()].map(e=>U(e.sender)).find(e=>e?.kind===`audio`);throw e.localTracks.clear(),e.pendingTracks.clear(),r!=null&&e.localTracks.add(r),new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:n,cause:t})}e.localTracks.clear(),e.pendingTracks.clear(),e.senders.clear(),this.resources.delete(e),this.releaseUnusedSenderQueues()}).catch(t=>{throw this.releaseErrors.set(e,t),this.calls.get(n)===void 0&&this.calls.set(n,e),t}).finally(()=>{this.releaseOperations.get(e)===a&&this.releaseOperations.delete(e)});return this.releaseOperations.set(e,a),a}releaseCall(e){let t=this.callReleaseOperations.get(e);if(t!==void 0)return t;let n=[...this.resources].filter(t=>t.callId===e);if(n.length===0)return Promise.resolve();let r=Promise.all(n.map(async e=>{try{return await this.releaseResource(e),{cause:void 0}}catch(e){return{cause:e}}})).then(e=>{let t=e.find(e=>e.cause!==void 0)?.cause;if(t!==void 0)throw t}).finally(()=>{this.callReleaseOperations.get(e)===r&&this.callReleaseOperations.delete(e)});return this.callReleaseOperations.set(e,r),r}releaseAll(){if(this.releaseAllOperation!==void 0)return this.releaseAllOperation;this.remoteAudio.releaseAll();let e=new Set([...this.resources].map(e=>e.callId)),t=Promise.all([...e].map(async e=>{try{return await this.releaseCall(e),{cause:void 0}}catch(e){return{cause:e}}})).then(e=>{let t=e.find(e=>e.cause!==void 0)?.cause;if(t!==void 0)throw t}).finally(()=>{this.releaseAllOperation===t&&(this.releaseAllOperation=void 0)});return this.releaseAllOperation=t,t}dispose(){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposing=!0;let e=this.releaseAll(),t=this.waitForInputOperations(),n=Promise.allSettled([e,t]).then(e=>{let t=e.find(e=>e.status===`rejected`);if(t?.status===`rejected`)throw t.reason;this.inputOperations.clear(),this.disposed=!0,this.disposing=!1}).finally(()=>{this.disposeOperation===n&&!this.disposed&&(this.disposeOperation=void 0),!this.disposed&&this.disposeOperation===void 0&&(this.disposing=!1)});return this.disposeOperation=n,n}async waitForInputOperations(){let e=[...this.inputOperations.values()];e.length!==0&&await Promise.allSettled(e)}async performInputSwitch(e,t,n){if(this.assertActiveCall(t),this.assertDeviceSelectionCapability(t),!this.isCurrentResource(n)||t.peerConnection!==n.peerConnection)throw this.callOperationError(t.callId);let r=this.findAudioSender(n),i=U(r.sender),a=n.generation,o=await this.deviceManager.openInputStream(e),s;try{s=o.getTracks()}catch(e){throw ze(o),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:t.callId,cause:e})}let c;try{c=o.getAudioTracks()}catch(e){throw Be(s),new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:t.callId,cause:e})}let l=c[0];if(l===void 0)throw Be(s),new p(`MEDIA_DEVICE_NOT_FOUND`,`media`,!1,{callId:t.callId});if(!this.canCommitInputSwitch(t,n,r,i,a))throw Be(s),this.callOperationError(t.callId);s.forEach(e=>n.pendingTracks.add(e)),n.pendingTracks.add(l);try{await this.enqueueSender(n,r,()=>r.sender.replaceTrack(l))}catch(e){throw n.released?this.callOperationError(t.callId):(n.released||(s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),await this.rollbackSender(n,r,i,l),Be(s)),new p(`MEDIA_DEVICE_IN_USE`,`media`,!0,{callId:t.callId,cause:e}))}if(!this.canCommitInputSwitch(t,n,r,l,a)){if(!n.released)try{await this.enqueueSender(n,r,()=>U(r.sender)===l?Re(r.sender):Promise.resolve()),s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),Be(s)}catch(e){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!0,{callId:t.callId,cause:e})}throw this.callOperationError(t.callId)}s.forEach(e=>n.pendingTracks.delete(e)),n.pendingTracks.delete(l),n.localTracks.add(l),i!==null&&i!==l&&(n.localTracks.delete(i),Ve(i)),s.forEach(e=>{e!==l&&Ve(e)})}ensureCallMedia(e){let t=this.calls.get(e.callId);if(t!==void 0&&t.peerConnection===e.peerConnection)return t;if(e.peerConnection===void 0)throw this.capabilityError(e.callId);this.registerCallMedia(e.callId,e.peerConnection);let n=this.calls.get(e.callId);if(n===void 0)throw this.callOperationError(e.callId);return n}captureSenders(e,t){let n;try{n=e.peerConnection.getSenders()}catch(t){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e.callId,cause:t})}n.forEach(n=>{let r=U(n),i;try{i=t?.(n)??n.senderKind??n.kind}catch(t){throw new p(`SDK_INTERNAL_ERROR`,`internal`,!1,{callId:e.callId,cause:t})}e.senders.set(n,{sender:n,audio:i===`audio`||i===void 0&&r?.kind===`audio`,queue:this.senderQueues.get(n)??this.createSenderQueue(n)}),r?.kind===`audio`&&e.localTracks.add(r)})}findAudioSender(e){let t=[...e.senders.values()].find(e=>e.audio&&(U(e.sender)?.kind===`audio`||U(e.sender)===null));if(t===void 0)throw this.capabilityError(e.callId);return t}handleTrackEvent(e,t){if(!this.isCurrentResource(e)||t.track.kind!==`audio`)return;let n=t.streams[0]??this.createRemoteStream(t.track);n!==void 0&&this.bindRemoteTrack(e.callId,n).catch(()=>void 0)}canCommitInputSwitch(e,t,n,r,i){if(this.disposed||!this.isCurrentResource(t,i)||e.state!==`active`||e.peerConnection!==t.peerConnection||!t.senders.has(n.sender))return!1;try{if(!t.peerConnection.getSenders().includes(n.sender))return!1}catch{return!1}return U(n.sender)===r}enqueueSender(e,t,n,r=!1){t.queue.pending+=1;let i=t.queue.chain.then(async()=>{if(e.released&&!r)throw this.callOperationError(e.callId);return n()},async()=>{if(e.released&&!r)throw this.callOperationError(e.callId);return n()}),a=i.finally(()=>{--t.queue.pending});return t.queue.chain=a.catch(()=>void 0),i}createSenderQueue(e){let t={chain:Promise.resolve(),pending:0};return this.senderQueues.set(e,t),t}releaseUnusedSenderQueues(){let e=new Set;this.resources.forEach(t=>t.senders.forEach(t=>e.add(t.sender))),this.senderQueues.forEach((t,n)=>{t.pending===0&&!e.has(n)&&this.senderQueues.delete(n)})}async rollbackSender(e,t,n,r){e.released||U(t.sender)!==r||await this.enqueueSender(e,t,()=>t.sender.replaceTrack(n)).catch(()=>void 0)}isCurrentResource(e,t=e.generation){return!this.disposed&&this.calls.get(e.callId)===e&&e.generation===t}unsubscribeTrackSource(e){let t=e.trackSourceUnsubscribe;if(e.trackSourceUnsubscribe=void 0,t!==void 0)try{t()}catch{}}assertActiveCall(e){if(e===void 0||e.state!==`active`)throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e?.callId})}assertDeviceSelectionCapability(e){if(e.capabilities===void 0||!e.capabilities.has(`device_selection`))throw this.capabilityError(e.callId)}capabilityError(e){return new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{callId:e})}callOperationError(e){return new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{callId:e})}assertNotDisposed(){if(this.disposed||this.disposing)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}};function Ie(e){return`peerConnection`in e}function U(e){try{return e.track}catch{return null}}function Le(e){return typeof e==`object`&&!!e&&e.name===`InvalidStateError`}function Re(e){try{return e.replaceTrack(null).catch(e=>{if(!Le(e))throw e})}catch(e){return Le(e)?Promise.resolve():Promise.reject(e)}}function ze(e){try{Be(e.getTracks())}catch{}}function Be(e){e.forEach(Ve)}function Ve(e){try{e.stop()}catch{}}function He(e){if(typeof MediaStream<`u`)try{return new MediaStream([e])}catch{return}}m();function Ue(e,t={}){let n=new Map,r=new Map,i=new Set,a=t.ownershipRequired===!0,o=!1,s=!1,c,l=()=>e(),u=new Fe({getActiveCall:l});return{publicMedia:{requestPermission:()=>(d(),u.requestPermission()),getDevices:()=>(d(),u.getDevices()),getCapabilities:()=>(d(),u.getCapabilities()),supportsOutputSelection:()=>(d(),u.supportsOutputSelection()),setInputDevice:e=>(d(),u.setInputDevice(e,l())),setOutputDevice:e=>(d(),u.setOutputDevice(e)),playRemoteAudio:e=>(d(),u.playRemoteAudio(e)),releaseAll:()=>(d(),u.releaseAll())},registerCall(e,t){o||s||!We(t)||(r.set(e,t),(!a||i.has(e))&&f(e,t))},async setCallOwnership(e,t){if(o)return;if(t!==`owned`){i.delete(e),await u.releaseCall(e),n.delete(e);return}i.add(e);let a=r.get(e);a!==void 0&&f(e,a)},contextFor(e,t,r){let i=n.get(e);if(i!==void 0)return{callId:e,state:t,capabilities:r,peerConnection:i.peerConnection}},async releaseCall(e){o||(await u.releaseCall(e),n.delete(e),r.delete(e),i.delete(e))},releaseAll:async()=>{await u.releaseAll(),n.clear(),r.clear(),i.clear()},getResourceCounts:()=>u.getResourceCounts(),dispose:()=>{if(c!==void 0)return c;s=!0;let e=u.dispose().then(()=>{o=!0,s=!1,n.clear(),r.clear(),i.clear()}).finally(()=>{c===e&&!o&&(c=void 0,s=!1)});return c=e,e}};function d(){if(o)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}function f(e,t){if(!We(t)||typeof t.getMediaRegistration!=`function`)return;let r=t.getMediaRegistration();if(Ge(r)&&n.get(e)?.peerConnection!==r.peerConnection){n.set(e,r);try{u.registerCallMedia(e,r)}catch{n.delete(e)}}}}function We(e){return typeof e==`object`&&!!e}function Ge(e){return typeof e==`object`&&!!e&&`peerConnection`in e&&typeof e.peerConnection==`object`&&e.peerConnection!==null}var Ke=1e3,qe=3e4;function Je(e,t=Math.random){let n=Math.min(qe,Ke*2**Math.max(0,Math.floor(e))),r=Math.min(1,Math.max(0,t()));return Math.round(n*(1+r*.2))}var Ye=class{recover;random;isOnline;onAttempt;attempt=0;pendingTimer;running=!1;online=!0;generation=0;disposed=!1;restartAfterRun=!1;constructor(e){this.recover=e.recover,this.random=e.random??Math.random,this.isOnline=e.isOnline??(()=>!0),this.onAttempt=e.onAttempt}start(){if(this.disposed||!this.online||!this.isOnline()||this.pendingTimer!==void 0||this.running)return;let e=this.generation,t=Je(this.attempt,this.random);this.pendingTimer=setTimeout(()=>{this.pendingTimer=void 0,this.run(e)},t)}notifyOffline(){this.disposed||(this.online=!1,this.generation+=1,this.clearPendingTimer(),this.restartAfterRun=!1)}notifyOnline(){this.disposed||(this.online=!0,this.running&&(this.restartAfterRun=!0),this.start())}cancel(){this.disposed||(this.generation+=1,this.clearPendingTimer(),this.attempt=0,this.restartAfterRun=!1)}dispose(){this.disposed||(this.disposed=!0,this.generation+=1,this.clearPendingTimer(),this.restartAfterRun=!1)}getTimerCount(){return this.pendingTimer===void 0?0:1}async run(e){if(this.disposed||!this.online||e!==this.generation||this.running)return;this.running=!0;try{this.onAttempt?.(this.attempt)}catch{}let t=!1;try{await this.recover(),this.isCurrent(e)&&(this.attempt=0)}catch{this.isCurrent(e)&&(this.attempt+=1,t=!0)}finally{this.running=!1}this.restartAfterRun?(this.restartAfterRun=!1,this.isCurrent(this.generation)&&this.start()):t&&this.isCurrent(e)&&this.start()}isCurrent(e){return!this.disposed&&this.online&&e===this.generation&&this.isOnline()}clearPendingTimer(){this.pendingTimer!==void 0&&(clearTimeout(this.pendingTimer),this.pendingTimer=void 0)}},Xe=class{capacity;entries=[];constructor(e){if(this.capacity=e,!Number.isInteger(e)||e<=0)throw RangeError(`RingBuffer capacity must be a positive integer`)}push(e){this.entries.length===this.capacity&&this.entries.shift(),this.entries.push(e)}toArray(){return[...this.entries]}},Ze=`@16x/webphone-sdk`,Qe=200,$e=class{dependencies;logs=new Xe(Qe);now;constructor(e){this.dependencies=e,this.now=e.now??(()=>new Date)}log(e,t,n){this.logs.push({timestamp:this.now().toISOString(),level:e,message:ce(t),...n===void 0?{}:{context:le(n)}})}async getReport(e={}){let t=e.includeRecentLogs!==!1,n=e.includeDeviceNames===!0,r=e.maskPhoneNumbers!==!1,i=this.dependencies.getSnapshot(),a=this.dependencies.getPermission===void 0?i.permission:await et(this.dependencies.getPermission,i.permission),o=n?await tt(this.dependencies.getDeviceNames):void 0,s=rt(nt(this.dependencies.getUserAgent));return le({generatedAt:this.now().toISOString(),sdk:{name:Ze,version:F},browser:s.browser,os:s.os,...i,permission:a,recentLogs:t?this.logs.toArray():[],...o===void 0?{}:{deviceNames:o}},{maskPhoneNumbers:r})}};async function et(e,t){try{return await e()}catch{return t}}async function tt(e){if(e===void 0)return[];try{return[...await e()]}catch{return[]}}function nt(e){if(e!==void 0)try{return e()}catch{return``}return typeof navigator>`u`?``:navigator.userAgent}function rt(e){return{browser:it(e),os:at(e)}}function it(e){for(let[t,n]of[[`Edge`,/Edg\/([\d.]+)/],[`Chrome`,/(?:Chrome|CriOS)\/([\d.]+)/],[`Firefox`,/(?:Firefox|FxiOS)\/([\d.]+)/],[`Safari`,/Version\/([\d.]+).*Safari/]]){let r=e.match(n);if(r?.[1]!==void 0)return{name:t,version:r[1]}}return{name:`unknown`,version:``}}function at(e){let t=e.match(/(?:iPhone|iPad).*OS ([\d_]+)/);if(t?.[1]!==void 0)return{name:`iOS`,version:t[1].replaceAll(`_`,`.`)};let n=e.match(/Android ([\d.]+)/);if(n?.[1]!==void 0)return{name:`Android`,version:n[1]};let r=e.match(/Windows NT ([\d.]+)/);if(r?.[1]!==void 0)return{name:`Windows`,version:r[1]};let i=e.match(/Mac OS X ([\d_]+)/);return i?.[1]===void 0?/Linux/.test(e)?{name:`Linux`,version:``}:{name:`unknown`,version:``}:{name:`macOS`,version:i[1].replaceAll(`_`,`.`)}}var ot=l({bugs:()=>_t,contributors:()=>ft,default:()=>xt,dependencies:()=>vt,description:()=>lt,devDependencies:()=>yt,homepage:()=>dt,keywords:()=>ht,license:()=>`MIT`,main:()=>mt,name:()=>st,repository:()=>gt,scripts:()=>bt,title:()=>ct,types:()=>pt,version:()=>ut}),st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St=s((()=>{st=`jssip`,ct=`JsSIP`,lt=`the Javascript SIP library`,ut=`3.10.1`,dt=`https://jssip.net`,ft=[`José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)`,`Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)`],pt=`lib/JsSIP.d.ts`,mt=`lib-es5/JsSIP.js`,ht=[`sip`,`websocket`,`webrtc`,`node`,`browser`,`library`],gt={type:`git`,url:`https://github.com/versatica/JsSIP.git`},_t={url:`https://github.com/versatica/JsSIP/issues`},vt={"@types/events":`^3.0.0`,"@types/debug":`^4.1.7`,debug:`^4.3.1`,events:`^3.3.0`,"sdp-transform":`^2.14.1`},yt={"@babel/core":`^7.19.6`,"@babel/preset-env":`^7.19.4`,"ansi-colors":`^3.2.4`,browserify:`^16.5.1`,eslint:`^5.16.0`,"fancy-log":`^1.3.3`,gulp:`^4.0.2`,"gulp-babel":`^8.0.0`,"gulp-eslint":`^5.0.0`,"gulp-expect-file":`^1.0.2`,"gulp-header":`^2.0.9`,"gulp-nodeunit-runner":`^0.2.2`,"gulp-plumber":`^1.2.1`,"gulp-rename":`^1.4.0`,"gulp-uglify-es":`^1.0.4`,pegjs:`^0.7.0`,"vinyl-buffer":`^1.0.1`,"vinyl-source-stream":`^2.0.0`},bt={lint:`node npm-scripts.js lint`,test:`node npm-scripts.js test`,prepublish:`node npm-scripts.js prepublish`,release:`node npm-scripts.js release`},xt={name:st,title:ct,description:lt,version:ut,homepage:dt,contributors:ft,types:pt,main:mt,keywords:ht,license:`MIT`,repository:gt,bugs:_t,dependencies:vt,devDependencies:yt,scripts:bt}})),W=c(((e,t)=>{var n=(St(),f(ot).default);t.exports={USER_AGENT:`${n.title} ${n.version}`,SIP:`sip`,SIPS:`sips`,causes:{CONNECTION_ERROR:`Connection Error`,REQUEST_TIMEOUT:`Request Timeout`,SIP_FAILURE_CODE:`SIP Failure Code`,INTERNAL_ERROR:`Internal Error`,BUSY:`Busy`,REJECTED:`Rejected`,REDIRECTED:`Redirected`,UNAVAILABLE:`Unavailable`,NOT_FOUND:`Not Found`,ADDRESS_INCOMPLETE:`Address Incomplete`,INCOMPATIBLE_SDP:`Incompatible SDP`,MISSING_SDP:`Missing SDP`,AUTHENTICATION_ERROR:`Authentication Error`,BYE:`Terminated`,WEBRTC_ERROR:`WebRTC Error`,CANCELED:`Canceled`,NO_ANSWER:`No Answer`,EXPIRES:`Expires`,NO_ACK:`No ACK`,DIALOG_ERROR:`Dialog Error`,USER_DENIED_MEDIA_ACCESS:`User Denied Media Access`,BAD_MEDIA_DESCRIPTION:`Bad Media Description`,RTP_TIMEOUT:`RTP Timeout`},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:`ACK`,BYE:`BYE`,CANCEL:`CANCEL`,INFO:`INFO`,INVITE:`INVITE`,MESSAGE:`MESSAGE`,NOTIFY:`NOTIFY`,OPTIONS:`OPTIONS`,REGISTER:`REGISTER`,REFER:`REFER`,UPDATE:`UPDATE`,SUBSCRIBE:`SUBSCRIBE`,DTMF_TRANSPORT:{INFO:`INFO`,RFC2833:`RFC2833`},REASON_PHRASE:{100:`Trying`,180:`Ringing`,181:`Call Is Being Forwarded`,182:`Queued`,183:`Session Progress`,199:`Early Dialog Terminated`,200:`OK`,202:`Accepted`,204:`No Notification`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Moved Temporarily`,305:`Use Proxy`,380:`Alternative Service`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,410:`Gone`,412:`Conditional Request Failed`,413:`Request Entity Too Large`,414:`Request-URI Too Long`,415:`Unsupported Media Type`,416:`Unsupported URI Scheme`,417:`Unknown Resource-Priority`,420:`Bad Extension`,421:`Extension Required`,422:`Session Interval Too Small`,423:`Interval Too Brief`,424:`Bad Location Information`,428:`Use Identity Header`,429:`Provide Referrer Identity`,430:`Flow Failed`,433:`Anonymity Disallowed`,436:`Bad Identity-Info`,437:`Unsupported Certificate`,438:`Invalid Identity Header`,439:`First Hop Lacks Outbound Support`,440:`Max-Breadth Exceeded`,469:`Bad Info Package`,470:`Consent Needed`,478:`Unresolvable Destination`,480:`Temporarily Unavailable`,481:`Call/Transaction Does Not Exist`,482:`Loop Detected`,483:`Too Many Hops`,484:`Address Incomplete`,485:`Ambiguous`,486:`Busy Here`,487:`Request Terminated`,488:`Not Acceptable Here`,489:`Bad Event`,491:`Request Pending`,493:`Undecipherable`,494:`Security Agreement Required`,500:`JsSIP Internal Error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Server Time-out`,505:`Version Not Supported`,513:`Message Too Large`,580:`Precondition Failure`,600:`Busy Everywhere`,603:`Decline`,604:`Does Not Exist Anywhere`,606:`Not Acceptable`},ALLOWED_METHODS:`INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY`,ACCEPTED_BODY_TYPES:`application/sdp, application/dtmf-relay`,MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}})),G=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}function a(e){var t=u();return function(){var n=p(e),r;if(t){var i=p(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}function o(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:s(e)}function s(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function c(e){var t=typeof Map==`function`?new Map:void 0;return c=function(e){if(e===null||!d(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,p(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)},c(e)}function l(e,t,n){return l=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&f(i,n.prototype),i},l.apply(null,arguments)}function u(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function d(e){return Function.toString.call(e).indexOf(`[native code]`)!==-1}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}t.exports={ConfigurationError:function(e){i(n,e);var t=a(n);function n(e,i){var a;return r(this,n),a=t.call(this),a.code=1,a.name=`CONFIGURATION_ERROR`,a.parameter=e,a.value=i,a.message=a.value?`Invalid value ${JSON.stringify(a.value)} for parameter "${a.parameter}"`:`Missing parameter: ${a.parameter}`,a}return n}(c(Error)),InvalidStateError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=2,i.name=`INVALID_STATE_ERROR`,i.status=e,i.message=`Invalid status: ${e}`,i}return n}(c(Error)),NotSupportedError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=3,i.name=`NOT_SUPPORTED_ERROR`,i.message=e,i}return n}(c(Error)),NotReadyError:function(e){i(n,e);var t=a(n);function n(e){var i;return r(this,n),i=t.call(this),i.code=4,i.name=`NOT_READY_ERROR`,i.message=e,i}return n}(c(Error))}})),Ct=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=wt(),o=K();t.exports=function(){i(e,null,[{key:`parse`,value:function(e){if(e=o.parse(e,`Name_Addr_Header`),e!==-1)return e}}]);function e(t,r,i){if(n(this,e),!t||!(t instanceof a))throw TypeError(`missing or invalid "uri" parameter`);for(var o in this._uri=t,this._parameters={},this.display_name=r,i)Object.prototype.hasOwnProperty.call(i,o)&&this.setParam(o,i[o])}return i(e,[{key:`setParam`,value:function(e,t){e&&(this._parameters[e.toLowerCase()]=t==null?null:t.toString())}},{key:`getParam`,value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:`hasParam`,value:function(e){if(e)return this._parameters.hasOwnProperty(e.toLowerCase())&&!0||!1}},{key:`deleteParam`,value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:`clearParams`,value:function(){this._parameters={}}},{key:`clone`,value:function(){return new e(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:`_quote`,value:function(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}},{key:`toString`,value:function(){var e=this._display_name?`"${this._quote(this._display_name)}" `:``;for(var t in e+=`<${this._uri.toString()}>`,this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=`;${t}`,this._parameters[t]!==null&&(e+=`=${this._parameters[t]}`));return e}},{key:`uri`,get:function(){return this._uri}},{key:`display_name`,get:function(){return this._display_name},set:function(e){this._display_name=e===0?`0`:e}}]),e}()})),K=c(((e,t)=>{t.exports=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 r={CRLF:l,DIGIT:u,ALPHA:d,HEXDIG:f,WSP:p,OCTET:m,DQUOTE:h,SP:g,HTAB:_,alphanum:v,reserved:y,unreserved:b,mark:x,escaped:S,LWS:C,SWS:w,HCOLON:T,TEXT_UTF8_TRIM:E,TEXT_UTF8char:D,UTF8_NONASCII:O,UTF8_CONT:k,LHEX:A,token:j,token_nodot:M,separators:N,word:P,STAR:ee,SLASH:te,EQUAL:F,LPAREN:I,RPAREN:ne,RAQUOT:re,LAQUOT:ie,COMMA:L,SEMI:R,COLON:ae,LDQUOT:oe,RDQUOT:se,comment:ce,ctext:le,quoted_string:ue,quoted_string_clean:de,qdtext:fe,quoted_pair:z,SIP_URI_noparams:B,SIP_URI:pe,uri_scheme:me,uri_scheme_sips:he,uri_scheme_sip:ge,userinfo:_e,user:ve,user_unreserved:ye,password:be,hostport:xe,host:Se,hostname:Ce,domainlabel:we,toplabel:Te,IPv6reference:Ee,IPv6address:De,h16:V,ls32:H,IPv4address:Oe,dec_octet:ke,port:Ae,uri_parameters:je,uri_parameter:Me,transport_param:Ne,user_param:Pe,method_param:Fe,ttl_param:Ie,maddr_param:U,lr_param:Le,other_param:Re,pname:ze,pvalue:Be,paramchar:Ve,param_unreserved:He,headers:Ue,header:We,hname:Ge,hvalue:Ke,hnv_unreserved:qe,Request_Response:Je,Request_Line:Ye,Request_URI:Xe,absoluteURI:Ze,hier_part:Qe,net_path:$e,abs_path:et,opaque_part:tt,uric:nt,uric_no_slash:rt,path_segments:it,segment:at,param:ot,pchar:st,scheme:ct,authority:lt,srvr:ut,reg_name:dt,query:ft,SIP_Version:pt,INVITEm:mt,ACKm:ht,OPTIONSm:gt,BYEm:_t,CANCELm:vt,REGISTERm:yt,SUBSCRIBEm:bt,NOTIFYm:xt,REFERm:St,Method:W,Status_Line:G,Status_Code:K,extension_code:q,Reason_Phrase:J,Allow_Events:Tt,Call_ID:Et,Contact:Dt,contact_param:Y,name_addr:X,display_name:Ot,contact_params:kt,c_p_q:At,c_p_expires:Z,delta_seconds:jt,qvalue:Mt,generic_param:Q,gen_value:Nt,Content_Disposition:Pt,disp_type:Ft,disp_param:It,handling_param:Lt,Content_Encoding:Rt,Content_Length:zt,Content_Type:Bt,media_type:Vt,m_type:Ht,discrete_type:Ut,composite_type:Wt,extension_token:Gt,x_token:Kt,m_subtype:qt,m_parameter:Jt,m_value:Yt,CSeq:Xt,CSeq_value:Zt,Expires:Qt,Event:$t,event_type:en,From:tn,from_param:nn,tag_param:rn,Max_Forwards:an,Min_Expires:on,Name_Addr_Header:sn,Proxy_Authenticate:cn,challenge:ln,other_challenge:un,auth_param:dn,digest_cln:fn,realm:pn,realm_value:mn,domain:hn,URI:gn,nonce:_n,nonce_value:vn,opaque:yn,stale:bn,algorithm:xn,qop_options:Sn,qop_value:Cn,Proxy_Require:wn,Record_Route:Tn,rec_route:En,Reason:Dn,reason_param:On,reason_cause:kn,Require:An,Route:jn,route_param:Mn,Subscription_State:Nn,substate_value:Pn,subexp_params:Fn,event_reason_value:In,Subject:Ln,Supported:Rn,To:zn,to_param:Bn,Via:Vn,via_param:Hn,via_params:Un,via_ttl:Wn,via_maddr:Gn,via_received:Kn,via_branch:qn,response_port:Jn,rport:Yn,sent_protocol:Xn,protocol_name:Zn,transport:Qn,sent_by:$n,via_host:er,via_port:tr,ttl:nr,WWW_Authenticate:rr,Session_Expires:ir,s_e_expires:ar,s_e_params:or,s_e_refresher:sr,extension_header:cr,header_value:lr,message_body:ur,uuid_URI:dr,uuid:fr,hex4:pr,hex8:mr,hex12:hr,Refer_To:gr,Replaces:_r,call_id:vr,replaces_param:yr,to_tag:br,from_tag:xr,early_flag:Sr};if(n!==void 0){if(r[n]===void 0)throw Error(`Invalid rule name: `+e(n)+`.`)}else n=`CRLF`;var i=0,a=0,o=0,s=[];function c(e){i<o||(i>o&&(o=i,s=[]),s.push(e))}function l(){var e;return t.substr(i,2)===`\r
2
2
  `?(e=`\r
3
- `,i+=2):(e=null,a===0&&c(`"\\r\\n"`)),e}function u(){var e;return/^[0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[0-9]`)),e}function d(){var e;return/^[a-zA-Z]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-zA-Z]`)),e}function f(){var e;return/^[0-9a-fA-F]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[0-9a-fA-F]`)),e}function p(){var e=g();return e===null&&(e=_()),e}function m(){var e;return/^[\0-\xFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\0-\\xFF]`)),e}function h(){var e;return/^["]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`["]`)),e}function g(){var e;return t.charCodeAt(i)===32?(e=` `,i++):(e=null,a===0&&c(`" "`)),e}function _(){var e;return t.charCodeAt(i)===9?(e=` `,i++):(e=null,a===0&&c(`"\\t"`)),e}function v(){var e;return/^[a-zA-Z0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-zA-Z0-9]`)),e}function y(){var e;return t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`))))))))))),e}function b(){var e=v();return e===null&&(e=x()),e}function x(){var e;return t.charCodeAt(i)===45?(e=`-`,i++):(e=null,a===0&&c(`"-"`)),e===null&&(t.charCodeAt(i)===95?(e=`_`,i++):(e=null,a===0&&c(`"_"`)),e===null&&(t.charCodeAt(i)===46?(e=`.`,i++):(e=null,a===0&&c(`"."`)),e===null&&(t.charCodeAt(i)===33?(e=`!`,i++):(e=null,a===0&&c(`"!"`)),e===null&&(t.charCodeAt(i)===126?(e=`~`,i++):(e=null,a===0&&c(`"~"`)),e===null&&(t.charCodeAt(i)===42?(e=`*`,i++):(e=null,a===0&&c(`"*"`)),e===null&&(t.charCodeAt(i)===39?(e=`'`,i++):(e=null,a===0&&c(`"'"`)),e===null&&(t.charCodeAt(i)===40?(e=`(`,i++):(e=null,a===0&&c(`"("`)),e===null&&(t.charCodeAt(i)===41?(e=`)`,i++):(e=null,a===0&&c(`")"`)))))))))),e}function S(){var e,n,r,o=i,s=i;return t.charCodeAt(i)===37?(e=`%`,i++):(e=null,a===0&&c(`"%"`)),e===null?(e=null,i=s):(n=f(),n===null?(e=null,i=s):(r=f(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){return t.join(``)}(o,e)),e===null&&(i=o),e}function C(){var e,t,n,r=i,a=i,o=i;for(e=[],t=p();t!==null;)e.push(t),t=p();if(e===null?(e=null,i=o):(t=l(),t===null?(e=null,i=o):e=[e,t]),e=e===null?``:e,e!==null){if(n=p(),n!==null)for(t=[];n!==null;)t.push(n),n=p();else t=null;t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e!==null&&(e=function(e){return` `}(r)),e===null&&(i=r),e}function w(){var e=C();return e=e===null?``:e,e}function T(){var e,n,r,o=i,s=i;for(e=[],n=g(),n===null&&(n=_());n!==null;)e.push(n),n=g(),n===null&&(n=_());return e===null?(e=null,i=s):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`:`}(o)),e===null&&(i=o),e}function E(){var e,n,r,a,o=i,s=i,c;if(n=D(),n!==null)for(e=[];n!==null;)e.push(n),n=D();else e=null;if(e!==null){for(n=[],c=i,r=[],a=C();a!==null;)r.push(a),a=C();for(r===null?(r=null,i=c):(a=D(),a===null?(r=null,i=c):r=[r,a]);r!==null;){for(n.push(r),c=i,r=[],a=C();a!==null;)r.push(a),a=C();r===null?(r=null,i=c):(a=D(),a===null?(r=null,i=c):r=[r,a])}n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e!==null&&(e=function(e){return t.substring(i,e)}(o)),e===null&&(i=o),e}function D(){var e;return/^[!-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[!-~]`)),e===null&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\x80-\\uFFFF]`)),e}function k(){var e;return/^[\x80-\xBF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\x80-\\xBF]`)),e}function A(){var e=u();return e===null&&(/^[a-f]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-f]`))),e}function j(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`))))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function M(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function N(){var e;return t.charCodeAt(i)===40?(e=`(`,i++):(e=null,a===0&&c(`"("`)),e===null&&(t.charCodeAt(i)===41?(e=`)`,i++):(e=null,a===0&&c(`")"`)),e===null&&(t.charCodeAt(i)===60?(e=`<`,i++):(e=null,a===0&&c(`"<"`)),e===null&&(t.charCodeAt(i)===62?(e=`>`,i++):(e=null,a===0&&c(`">"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===92?(e=`\\`,i++):(e=null,a===0&&c(`"\\\\"`)),e===null&&(e=h(),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===123?(e=`{`,i++):(e=null,a===0&&c(`"{"`)),e===null&&(t.charCodeAt(i)===125?(e=`}`,i++):(e=null,a===0&&c(`"}"`)),e===null&&(e=g(),e===null&&(e=_())))))))))))))))))),e}function P(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)),n===null&&(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null&&(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null&&(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null&&(t.charCodeAt(i)===62?(n=`>`,i++):(n=null,a===0&&c(`">"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===92?(n=`\\`,i++):(n=null,a===0&&c(`"\\\\"`)),n===null&&(n=h(),n===null&&(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null&&(t.charCodeAt(i)===91?(n=`[`,i++):(n=null,a===0&&c(`"["`)),n===null&&(t.charCodeAt(i)===93?(n=`]`,i++):(n=null,a===0&&c(`"]"`)),n===null&&(t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null&&(t.charCodeAt(i)===123?(n=`{`,i++):(n=null,a===0&&c(`"{"`)),n===null&&(t.charCodeAt(i)===125?(n=`}`,i++):(n=null,a===0&&c(`"}"`))))))))))))))))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)),n===null&&(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null&&(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null&&(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null&&(t.charCodeAt(i)===62?(n=`>`,i++):(n=null,a===0&&c(`">"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===92?(n=`\\`,i++):(n=null,a===0&&c(`"\\\\"`)),n===null&&(n=h(),n===null&&(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null&&(t.charCodeAt(i)===91?(n=`[`,i++):(n=null,a===0&&c(`"["`)),n===null&&(t.charCodeAt(i)===93?(n=`]`,i++):(n=null,a===0&&c(`"]"`)),n===null&&(t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null&&(t.charCodeAt(i)===123?(n=`{`,i++):(n=null,a===0&&c(`"{"`)),n===null&&(t.charCodeAt(i)===125?(n=`}`,i++):(n=null,a===0&&c(`"}"`)))))))))))))))))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function ee(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`*`}(o)),e===null&&(i=o),e}function F(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`/`}(o)),e===null&&(i=o),e}function I(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`=`}(o)),e===null&&(i=o),e}function te(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`(`}(o)),e===null&&(i=o),e}function ne(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`)`}(o)),e===null&&(i=o),e}function re(){var e,n,r=i,o=i;return t.charCodeAt(i)===62?(e=`>`,i++):(e=null,a===0&&c(`">"`)),e===null?(e=null,i=o):(n=w(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e){return`>`}(r)),e===null&&(i=r),e}function ie(){var e,n,r=i,o=i;return e=w(),e===null?(e=null,i=o):(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e){return`<`}(r)),e===null&&(i=r),e}function L(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`,`}(o)),e===null&&(i=o),e}function R(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`;`}(o)),e===null&&(i=o),e}function ae(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`:`}(o)),e===null&&(i=o),e}function oe(){var e,t,n=i,r=i;return e=w(),e===null?(e=null,i=r):(t=h(),t===null?(e=null,i=r):e=[e,t]),e!==null&&(e=function(e){return`"`}(n)),e===null&&(i=n),e}function se(){var e,t,n=i,r=i;return e=h(),e===null?(e=null,i=r):(t=w(),t===null?(e=null,i=r):e=[e,t]),e!==null&&(e=function(e){return`"`}(n)),e===null&&(i=n),e}function ce(){var e,t,n,r=i;if(e=te(),e!==null){for(t=[],n=le(),n===null&&(n=z(),n===null&&(n=ce()));n!==null;)t.push(n),n=le(),n===null&&(n=z(),n===null&&(n=ce()));t===null?(e=null,i=r):(n=ne(),n===null?(e=null,i=r):e=[e,t,n])}else e=null,i=r;return e}function le(){var e;return/^[!-']/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[!-']`)),e===null&&(/^[*-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[*-[]`)),e===null&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\]-~]`)),e===null&&(e=O(),e===null&&(e=C())))),e}function ue(){var e,n,r,a,o=i,s=i;if(e=w(),e!==null){if(n=h(),n!==null){for(r=[],a=fe(),a===null&&(a=z());a!==null;)r.push(a),a=fe(),a===null&&(a=z());r===null?(e=null,i=s):(a=h(),a===null?(e=null,i=s):e=[e,n,r,a])}else e=null,i=s}else e=null,i=s;return e!==null&&(e=function(e){return t.substring(i,e)}(o)),e===null&&(i=o),e}function de(){var e,n,r,a,o=i,s=i;if(e=w(),e!==null){if(n=h(),n!==null){for(r=[],a=fe(),a===null&&(a=z());a!==null;)r.push(a),a=fe(),a===null&&(a=z());r===null?(e=null,i=s):(a=h(),a===null?(e=null,i=s):e=[e,n,r,a])}else e=null,i=s}else e=null,i=s;return e!==null&&(e=function(e){var n=t.substring(i,e).trim();return n.substring(1,n.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,`$1`)}(o)),e===null&&(i=o),e}function fe(){var e=C();return e===null&&(t.charCodeAt(i)===33?(e=`!`,i++):(e=null,a===0&&c(`"!"`)),e===null&&(/^[#-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[#-[]`)),e===null&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\]-~]`)),e===null&&(e=O())))),e}function z(){var e,n,r=i;return t.charCodeAt(i)===92?(e=`\\`,i++):(e=null,a===0&&c(`"\\\\"`)),e===null?(e=null,i=r):(/^[\0-\t]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\0-\\t]`)),n===null&&(/^[\x0B-\f]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\x0B-\\f]`)),n===null&&(/^[\x0E-]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\x0E-]`)))),n===null?(e=null,i=r):e=[e,n]),e}function pe(){var e,n,r,o,s=i,l=i;return e=he(),e===null?(e=null,i=l):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=l):(r=_e(),r=r===null?``:r,r===null?(e=null,i=l):(o=xe(),o===null?(e=null,i=l):e=[e,n,r,o]))),e!==null&&(e=function(e){try{$.uri=new Tr($.scheme,$.user,$.host,$.port),delete $.scheme,delete $.user,delete $.host,delete $.host_type,delete $.port}catch{$=-1}}(s)),e===null&&(i=s),e}function me(){var e,r,o,s,l,u,d=i,f=i;return e=he(),e===null?(e=null,i=f):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=f):(o=_e(),o=o===null?``:o,o===null?(e=null,i=f):(s=xe(),s===null?(e=null,i=f):(l=je(),l===null?(e=null,i=f):(u=Ue(),u=u===null?``:u,u===null?(e=null,i=f):e=[e,r,o,s,l,u]))))),e!==null&&(e=function(e){try{$.uri=new Tr($.scheme,$.user,$.host,$.port,$.uri_params,$.uri_headers),delete $.scheme,delete $.user,delete $.host,delete $.host_type,delete $.port,delete $.uri_params,n===`SIP_URI`&&($=$.uri)}catch{$=-1}}(d)),e===null&&(i=d),e}function he(){var e=ge();return e===null&&(e=B()),e}function ge(){var e,n=i;return t.substr(i,4).toLowerCase()===`sips`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"sips"`)),e!==null&&(e=function(e,t){$.scheme=t.toLowerCase()}(n,e)),e===null&&(i=n),e}function B(){var e,n=i;return t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"sip"`)),e!==null&&(e=function(e,t){$.scheme=t.toLowerCase()}(n,e)),e===null&&(i=n),e}function _e(){var e,n,r,o=i,s=i,l;return e=ve(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=l):(r=be(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):(t.charCodeAt(i)===64?(r=`@`,i++):(r=null,a===0&&c(`"@"`)),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){$.user=decodeURIComponent(t.substring(i-1,e))}(o)),e===null&&(i=o),e}function ve(){var e,t=b();if(t===null&&(t=S(),t===null&&(t=ye())),t!==null)for(e=[];t!==null;)e.push(t),t=b(),t===null&&(t=S(),t===null&&(t=ye()));else e=null;return e}function ye(){var e;return t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`))))))))),e}function be(){var e,n,r=i;for(e=[],n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`))))))));n!==null;)e.push(n),n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`))))))));return e!==null&&(e=function(e){$.password=t.substring(i,e)}(r)),e===null&&(i=r),e}function xe(){var e,n,r,o=i,s;return e=Se(),e===null?(e=null,i=o):(s=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=s):(r=Ae(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function Se(){var e,n=i;return e=Ce(),e===null&&(e=Oe(),e===null&&(e=Ee())),e!==null&&(e=function(e){return $.host=t.substring(i,e).toLowerCase(),$.host}(n)),e===null&&(i=n),e}function Ce(){var e,n,r,o=i,s=i,l;for(e=[],l=i,n=we(),n===null?(n=null,i=l):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(n=null,i=l):n=[n,r]);n!==null;)e.push(n),l=i,n=we(),n===null?(n=null,i=l):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(n=null,i=l):n=[n,r]);return e===null?(e=null,i=s):(n=Te(),n===null?(e=null,i=s):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r=r===null?``:r,r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return $.host_type=`domain`,t.substring(i,e)}(o)),e===null&&(i=o),e}function we(){var e,n,r,o=i;if(e=v(),e!==null){for(n=[],r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));r!==null;)n.push(r),r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));n===null?(e=null,i=o):e=[e,n]}else e=null,i=o;return e}function Te(){var e,n,r,o=i;if(e=d(),e!==null){for(n=[],r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));r!==null;)n.push(r),r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));n===null?(e=null,i=o):e=[e,n]}else e=null,i=o;return e}function Ee(){var e,n,r,o=i,s=i;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null?(e=null,i=s):(n=De(),n===null?(e=null,i=s):(t.charCodeAt(i)===93?(r=`]`,i++):(r=null,a===0&&c(`"]"`)),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return $.host_type=`IPv6`,t.substring(i,e)}(o)),e===null&&(i=o),e}function De(){var e,n,r,o,s,l,u,d,f,p,m,h,g,_=i,v=i,y;return e=V(),e===null?(e=null,i=v):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=v):(r=V(),r===null?(e=null,i=v):(t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=V(),f===null?(e=null,i=v):(t.charCodeAt(i)===58?(p=`:`,i++):(p=null,a===0&&c(`":"`)),p===null?(e=null,i=v):(m=V(),m===null?(e=null,i=v):(t.charCodeAt(i)===58?(h=`:`,i++):(h=null,a===0&&c(`":"`)),h===null?(e=null,i=v):(g=H(),g===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m,h,g])))))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=V(),p===null?(e=null,i=v):(t.charCodeAt(i)===58?(m=`:`,i++):(m=null,a===0&&c(`":"`)),m===null?(e=null,i=v):(h=H(),h===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m,h]))))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=H(),p===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p]))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=H(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=H(),l===null?(e=null,i=v):e=[e,n,r,o,s,l]))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=H(),o===null?(e=null,i=v):e=[e,n,r,o]))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=H(),n===null?(e=null,i=v):e=[e,n]),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):e=[e,n]),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(t.substr(i,2)===`::`?(n=`::`,i+=2):(n=null,a===0&&c(`"::"`)),n===null?(e=null,i=v):(r=V(),r===null?(e=null,i=v):(t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=V(),f===null?(e=null,i=v):(t.charCodeAt(i)===58?(p=`:`,i++):(p=null,a===0&&c(`":"`)),p===null?(e=null,i=v):(m=H(),m===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m])))))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(t.substr(i,2)===`::`?(r=`::`,i+=2):(r=null,a===0&&c(`"::"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=H(),p===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p]))))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(t.substr(i,2)===`::`?(o=`::`,i+=2):(o=null,a===0&&c(`"::"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=H(),f===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f])))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(t.substr(i,2)===`::`?(s=`::`,i+=2):(s=null,a===0&&c(`"::"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=H(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(t.substr(i,2)===`::`?(l=`::`,i+=2):(l=null,a===0&&c(`"::"`)),l===null?(e=null,i=v):(u=H(),u===null?(e=null,i=v):e=[e,n,r,o,s,l,u])))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(l=null,i=y):(u=V(),u===null?(l=null,i=y):l=[l,u]),l=l===null?``:l,l===null?(e=null,i=v):(t.substr(i,2)===`::`?(u=`::`,i+=2):(u=null,a===0&&c(`"::"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(l=null,i=y):(u=V(),u===null?(l=null,i=y):l=[l,u]),l=l===null?``:l,l===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(u=null,i=y):(d=V(),d===null?(u=null,i=y):u=[u,d]),u=u===null?``:u,u===null?(e=null,i=v):(t.substr(i,2)===`::`?(d=`::`,i+=2):(d=null,a===0&&c(`"::"`)),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))))))))))))))))),e!==null&&(e=function(e){return $.host_type=`IPv6`,t.substring(i,e)}(_)),e===null&&(i=_),e}function V(){var e,t,n,r,a=i;return e=f(),e===null?(e=null,i=a):(t=f(),t=t===null?``:t,t===null?(e=null,i=a):(n=f(),n=n===null?``:n,n===null?(e=null,i=a):(r=f(),r=r===null?``:r,r===null?(e=null,i=a):e=[e,t,n,r]))),e}function H(){var e,n,r,o=i;return e=V(),e===null?(e=null,i=o):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=o):(r=V(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(e=Oe()),e}function Oe(){var e,n,r,o,s,l,u,d=i,f=i;return e=ke(),e===null?(e=null,i=f):(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null?(e=null,i=f):(r=ke(),r===null?(e=null,i=f):(t.charCodeAt(i)===46?(o=`.`,i++):(o=null,a===0&&c(`"."`)),o===null?(e=null,i=f):(s=ke(),s===null?(e=null,i=f):(t.charCodeAt(i)===46?(l=`.`,i++):(l=null,a===0&&c(`"."`)),l===null?(e=null,i=f):(u=ke(),u===null?(e=null,i=f):e=[e,n,r,o,s,l,u])))))),e!==null&&(e=function(e){return $.host_type=`IPv4`,t.substring(i,e)}(d)),e===null&&(i=d),e}function ke(){var e,n,r,o=i;return t.substr(i,2)===`25`?(e=`25`,i+=2):(e=null,a===0&&c(`"25"`)),e===null?(e=null,i=o):(/^[0-5]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[0-5]`)),n===null?(e=null,i=o):e=[e,n]),e===null&&(o=i,t.charCodeAt(i)===50?(e=`2`,i++):(e=null,a===0&&c(`"2"`)),e===null?(e=null,i=o):(/^[0-4]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[0-4]`)),n===null?(e=null,i=o):(r=u(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(o=i,t.charCodeAt(i)===49?(e=`1`,i++):(e=null,a===0&&c(`"1"`)),e===null?(e=null,i=o):(n=u(),n===null?(e=null,i=o):(r=u(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(o=i,/^[1-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[1-9]`)),e===null?(e=null,i=o):(n=u(),n===null?(e=null,i=o):e=[e,n]),e===null&&(e=u())))),e}function Ae(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){return t=parseInt(t.join(``)),$.port=t,t}(o,e)),e===null&&(i=o),e}function je(){var e=[],n,r,o=i;for(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(n=null,i=o):(r=Me(),r===null?(n=null,i=o):n=[n,r]);n!==null;)e.push(n),o=i,t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(n=null,i=o):(r=Me(),r===null?(n=null,i=o):n=[n,r]);return e}function Me(){var e=Ne();return e===null&&(e=Pe(),e===null&&(e=Fe(),e===null&&(e=Ie(),e===null&&(e=Le(),e===null&&(e=Re(),e===null&&(e=ze())))))),e}function Ne(){var e,n,r=i,o=i;return t.substr(i,10).toLowerCase()===`transport=`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"transport="`)),e===null?(e=null,i=o):(t.substr(i,3).toLowerCase()===`udp`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"udp"`)),n===null&&(t.substr(i,3).toLowerCase()===`tcp`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"tcp"`)),n===null&&(t.substr(i,4).toLowerCase()===`sctp`?(n=t.substr(i,4),i+=4):(n=null,a===0&&c(`"sctp"`)),n===null&&(t.substr(i,3).toLowerCase()===`tls`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"tls"`)),n===null&&(n=j())))),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.transport=t.toLowerCase()}(r,e[1])),e===null&&(i=r),e}function Pe(){var e,n,r=i,o=i;return t.substr(i,5).toLowerCase()===`user=`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"user="`)),e===null?(e=null,i=o):(t.substr(i,5).toLowerCase()===`phone`?(n=t.substr(i,5),i+=5):(n=null,a===0&&c(`"phone"`)),n===null&&(t.substr(i,2).toLowerCase()===`ip`?(n=t.substr(i,2),i+=2):(n=null,a===0&&c(`"ip"`)),n===null&&(n=j())),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.user=t.toLowerCase()}(r,e[1])),e===null&&(i=r),e}function Fe(){var e,n,r=i,o=i;return t.substr(i,7).toLowerCase()===`method=`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"method="`)),e===null?(e=null,i=o):(n=St(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.method=t}(r,e[1])),e===null&&(i=r),e}function Ie(){var e,n,r=i,o=i;return t.substr(i,4).toLowerCase()===`ttl=`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"ttl="`)),e===null?(e=null,i=o):(n=nr(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.ttl=t}(r,e[1])),e===null&&(i=r),e}function Le(){var e,n,r=i,o=i;return t.substr(i,6).toLowerCase()===`maddr=`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"maddr="`)),e===null?(e=null,i=o):(n=Se(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.maddr=t}(r,e[1])),e===null&&(i=r),e}function Re(){var e,n,r,o=i,s=i,l;return t.substr(i,2).toLowerCase()===`lr`?(e=t.substr(i,2),i+=2):(e=null,a===0&&c(`"lr"`)),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(n=null,i=l):(r=j(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$.uri_params||($.uri_params={}),$.uri_params.lr=void 0}(o)),e===null&&(i=o),e}function ze(){var e,n,r,o=i,s=i,l;return e=Be(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(n=null,i=l):(r=U(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e,t,n){$.uri_params||($.uri_params={}),n=n===void 0?void 0:n[1],$.uri_params[t.toLowerCase()]=n}(o,e[0],e[1])),e===null&&(i=o),e}function Be(){var e,t,n=i;if(t=Ve(),t!==null)for(e=[];t!==null;)e.push(t),t=Ve();else e=null;return e!==null&&(e=function(e,t){return t.join(``)}(n,e)),e===null&&(i=n),e}function U(){var e,t,n=i;if(t=Ve(),t!==null)for(e=[];t!==null;)e.push(t),t=Ve();else e=null;return e!==null&&(e=function(e,t){return t.join(``)}(n,e)),e===null&&(i=n),e}function Ve(){var e=He();return e===null&&(e=b(),e===null&&(e=S())),e}function He(){var e;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)))))))),e}function Ue(){var e,n,r,o,s,l=i,u;if(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e!==null){if(n=W(),n!==null){for(r=[],u=i,t.charCodeAt(i)===38?(o=`&`,i++):(o=null,a===0&&c(`"&"`)),o===null?(o=null,i=u):(s=W(),s===null?(o=null,i=u):o=[o,s]);o!==null;)r.push(o),u=i,t.charCodeAt(i)===38?(o=`&`,i++):(o=null,a===0&&c(`"&"`)),o===null?(o=null,i=u):(s=W(),s===null?(o=null,i=u):o=[o,s]);r===null?(e=null,i=l):e=[e,n,r]}else e=null,i=l}else e=null,i=l;return e}function W(){var e,n,r,o=i,s=i;return e=We(),e===null?(e=null,i=s):(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(e=null,i=s):(r=Ge(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t,n){t=t.join(``).toLowerCase(),n=n.join(``),$.uri_headers||($.uri_headers={}),$.uri_headers[t]?$.uri_headers[t].push(n):$.uri_headers[t]=[n]}(o,e[0],e[2])),e===null&&(i=o),e}function We(){var e,t=Ke();if(t===null&&(t=b(),t===null&&(t=S())),t!==null)for(e=[];t!==null;)e.push(t),t=Ke(),t===null&&(t=b(),t===null&&(t=S()));else e=null;return e}function Ge(){var e=[],t=Ke();for(t===null&&(t=b(),t===null&&(t=S()));t!==null;)e.push(t),t=Ke(),t===null&&(t=b(),t===null&&(t=S()));return e}function Ke(){var e;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)))))))),e}function qe(){var e=Ct();return e===null&&(e=Je()),e}function Je(){var e,t,n,r,a,o=i;return e=St(),e===null?(e=null,i=o):(t=g(),t===null?(e=null,i=o):(n=Ye(),n===null?(e=null,i=o):(r=g(),r===null?(e=null,i=o):(a=ft(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function Ye(){var e=me();return e===null&&(e=Xe()),e}function Xe(){var e,n,r,o=i;return e=st(),e===null?(e=null,i=o):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=o):(r=Ze(),r===null&&(r=et()),r===null?(e=null,i=o):e=[e,n,r])),e}function Ze(){var e,n,r,o=i,s;return e=Qe(),e===null&&(e=$e()),e===null?(e=null,i=o):(s=i,t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null?(n=null,i=s):(r=dt(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function Qe(){var e,n,r,o=i;return t.substr(i,2)===`//`?(e=`//`,i+=2):(e=null,a===0&&c(`"//"`)),e===null?(e=null,i=o):(n=ct(),n===null?(e=null,i=o):(r=$e(),r=r===null?``:r,r===null?(e=null,i=o):e=[e,n,r])),e}function $e(){var e,n,r=i;return t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null?(e=null,i=r):(n=rt(),n===null?(e=null,i=r):e=[e,n]),e}function et(){var e,t,n,r=i;if(e=nt(),e!==null){for(t=[],n=tt();n!==null;)t.push(n),n=tt();t===null?(e=null,i=r):e=[e,t]}else e=null,i=r;return e}function tt(){var e=y();return e===null&&(e=b(),e===null&&(e=S())),e}function nt(){var e=b();return e===null&&(e=S(),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)))))))))))),e}function rt(){var e,n,r,o,s=i,l;if(e=it(),e!==null){for(n=[],l=i,t.charCodeAt(i)===47?(r=`/`,i++):(r=null,a===0&&c(`"/"`)),r===null?(r=null,i=l):(o=it(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===47?(r=`/`,i++):(r=null,a===0&&c(`"/"`)),r===null?(r=null,i=l):(o=it(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function it(){var e,n,r,o,s=i,l;for(e=[],n=ot();n!==null;)e.push(n),n=ot();if(e!==null){for(n=[],l=i,t.charCodeAt(i)===59?(r=`;`,i++):(r=null,a===0&&c(`";"`)),r===null?(r=null,i=l):(o=at(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===59?(r=`;`,i++):(r=null,a===0&&c(`";"`)),r===null?(r=null,i=l):(o=at(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function at(){for(var e=[],t=ot();t!==null;)e.push(t),t=ot();return e}function ot(){var e=b();return e===null&&(e=S(),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)))))))))),e}function st(){var e,n,r,o=i,s=i;if(e=d(),e!==null){for(n=[],r=d(),r===null&&(r=u(),r===null&&(t.charCodeAt(i)===43?(r=`+`,i++):(r=null,a===0&&c(`"+"`)),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`))))));r!==null;)n.push(r),r=d(),r===null&&(r=u(),r===null&&(t.charCodeAt(i)===43?(r=`+`,i++):(r=null,a===0&&c(`"+"`)),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`))))));n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e!==null&&(e=function(e){$.scheme=t.substring(i,e)}(o)),e===null&&(i=o),e}function ct(){var e=lt();return e===null&&(e=ut()),e}function lt(){var e,n,r=i,o=i;return e=_e(),e===null?(e=null,i=o):(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(e=null,i=o):e=[e,n]),e=e===null?``:e,e===null?(e=null,i=r):(n=xe(),n===null?(e=null,i=r):e=[e,n]),e=e===null?``:e,e}function ut(){var e,n=b();if(n===null&&(n=S(),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null&&(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null&&(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)))))))))));else e=null;return e}function dt(){for(var e=[],t=tt();t!==null;)e.push(t),t=tt();return e}function ft(){var e,n,r,o,s,l,d=i,f=i;if(t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e!==null){if(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n!==null){if(o=u(),o!==null)for(r=[];o!==null;)r.push(o),o=u();else r=null;if(r!==null){if(t.charCodeAt(i)===46?(o=`.`,i++):(o=null,a===0&&c(`"."`)),o!==null){if(l=u(),l!==null)for(s=[];l!==null;)s.push(l),l=u();else s=null;s===null?(e=null,i=f):e=[e,n,r,o,s]}else e=null,i=f}else e=null,i=f}else e=null,i=f}else e=null,i=f;return e!==null&&(e=function(e){$.sip_version=t.substring(i,e)}(d)),e===null&&(i=d),e}function pt(){var e;return t.substr(i,6)===`INVITE`?(e=`INVITE`,i+=6):(e=null,a===0&&c(`"INVITE"`)),e}function mt(){var e;return t.substr(i,3)===`ACK`?(e=`ACK`,i+=3):(e=null,a===0&&c(`"ACK"`)),e}function ht(){var e;return t.substr(i,7)===`OPTIONS`?(e=`OPTIONS`,i+=7):(e=null,a===0&&c(`"OPTIONS"`)),e}function gt(){var e;return t.substr(i,3)===`BYE`?(e=`BYE`,i+=3):(e=null,a===0&&c(`"BYE"`)),e}function _t(){var e;return t.substr(i,6)===`CANCEL`?(e=`CANCEL`,i+=6):(e=null,a===0&&c(`"CANCEL"`)),e}function vt(){var e;return t.substr(i,8)===`REGISTER`?(e=`REGISTER`,i+=8):(e=null,a===0&&c(`"REGISTER"`)),e}function yt(){var e;return t.substr(i,9)===`SUBSCRIBE`?(e=`SUBSCRIBE`,i+=9):(e=null,a===0&&c(`"SUBSCRIBE"`)),e}function bt(){var e;return t.substr(i,6)===`NOTIFY`?(e=`NOTIFY`,i+=6):(e=null,a===0&&c(`"NOTIFY"`)),e}function xt(){var e;return t.substr(i,5)===`REFER`?(e=`REFER`,i+=5):(e=null,a===0&&c(`"REFER"`)),e}function St(){var e,n=i;return e=pt(),e===null&&(e=mt(),e===null&&(e=ht(),e===null&&(e=gt(),e===null&&(e=_t(),e===null&&(e=vt(),e===null&&(e=yt(),e===null&&(e=bt(),e===null&&(e=xt(),e===null&&(e=j()))))))))),e!==null&&(e=function(e){return $.method=t.substring(i,e),$.method}(n)),e===null&&(i=n),e}function Ct(){var e,t,n,r,a,o=i;return e=ft(),e===null?(e=null,i=o):(t=g(),t===null?(e=null,i=o):(n=wt(),n===null?(e=null,i=o):(r=g(),r===null?(e=null,i=o):(a=G(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function wt(){var e,t=i;return e=Tt(),e!==null&&(e=function(e,t){$.status_code=parseInt(t.join(``))}(t,e)),e===null&&(i=t),e}function Tt(){var e,t,n,r=i;return e=u(),e===null?(e=null,i=r):(t=u(),t===null?(e=null,i=r):(n=u(),n===null?(e=null,i=r):e=[e,t,n])),e}function G(){var e,n,r=i;for(e=[],n=y(),n===null&&(n=b(),n===null&&(n=S(),n===null&&(n=O(),n===null&&(n=k(),n===null&&(n=g(),n===null&&(n=_()))))));n!==null;)e.push(n),n=y(),n===null&&(n=b(),n===null&&(n=S(),n===null&&(n=O(),n===null&&(n=k(),n===null&&(n=g(),n===null&&(n=_()))))));return e!==null&&(e=function(e){$.reason_phrase=t.substring(i,e)}(r)),e===null&&(i=r),e}function K(){var e,t,n,r,a=i,o;if(e=en(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=en(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=en(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function q(){var e,n,r,o=i,s=i,l;return e=P(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(n=null,i=l):(r=P(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$=t.substring(i,e)}(o)),e===null&&(i=o),e}function J(){var e,t,n,r,a=i,o,s;if(e=ee(),e===null){if(o=i,e=Y(),e!==null){for(t=[],s=i,n=L(),n===null?(n=null,i=s):(r=Y(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=L(),n===null?(n=null,i=s):(r=Y(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o}return e!==null&&(e=function(e){var t,n=$.multi_header.length;for(t=0;t<n;t++)if($.multi_header[t].parsed===null){$=null;break}$=$===null?-1:$.multi_header}(a)),e===null&&(i=a),e}function Y(){var e,t,n,r,a=i,o=i,s;if(e=pe(),e===null&&(e=Ot()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=At(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=At(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t;$.multi_header||($.multi_header=[]);try{t=new Er($.uri,$.display_name,$.params),delete $.uri,delete $.display_name,delete $.params}catch{t=null}$.multi_header.push({possition:i,offset:e,parsed:t})}(a)),e===null&&(i=a),e}function Ot(){var e,t,n,r,a=i;return e=kt(),e=e===null?``:e,e===null?(e=null,i=a):(t=ie(),t===null?(e=null,i=a):(n=me(),n===null?(e=null,i=a):(r=re(),r===null?(e=null,i=a):e=[e,t,n,r]))),e}function kt(){var e,t,n,r,a=i,o=i,s;if(e=j(),e!==null){for(t=[],s=i,n=C(),n===null?(n=null,i=s):(r=j(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=C(),n===null?(n=null,i=s):(r=j(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e===null&&(e=de()),e!==null&&(e=function(e,t){typeof t==`string`?$.display_name=t:$.display_name=t[1].reduce(function(e,t){return e+t[0]+t[1]},t[0])}(a,e)),e===null&&(i=a),e}function At(){var e=X();return e===null&&(e=jt(),e===null&&(e=Z())),e}function X(){var e,n,r,o=i,s=i;return t.substr(i,1).toLowerCase()===`q`?(e=t.substr(i,1),i++):(e=null,a===0&&c(`"q"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Nt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.q=t}(o,e[2])),e===null&&(i=o),e}function jt(){var e,n,r,o=i,s=i;return t.substr(i,7).toLowerCase()===`expires`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"expires"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Mt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.expires=t}(o,e[2])),e===null&&(i=o),e}function Mt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){return parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Nt(){var e,n,r,o,s,l=i,d=i,f;return t.charCodeAt(i)===48?(e=`0`,i++):(e=null,a===0&&c(`"0"`)),e===null?(e=null,i=d):(f=i,t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null?(n=null,i=f):(r=u(),r=r===null?``:r,r===null?(n=null,i=f):(o=u(),o=o===null?``:o,o===null?(n=null,i=f):(s=u(),s=s===null?``:s,s===null?(n=null,i=f):n=[n,r,o,s]))),n=n===null?``:n,n===null?(e=null,i=d):e=[e,n]),e!==null&&(e=function(e){return parseFloat(t.substring(i,e))}(l)),e===null&&(i=l),e}function Z(){var e,t,n,r=i,a=i,o;return e=j(),e===null?(e=null,i=a):(o=i,t=I(),t===null?(t=null,i=o):(n=Q(),n===null?(t=null,i=o):t=[t,n]),t=t===null?``:t,t===null?(e=null,i=a):e=[e,t]),e!==null&&(e=function(e,t,n){$.params||($.params={}),n=n===void 0?void 0:n[1],$.params[t.toLowerCase()]=n}(r,e[0],e[1])),e===null&&(i=r),e}function Q(){var e=j();return e===null&&(e=Se(),e===null&&(e=ue())),e}function Pt(){var e,t,n,r,a=i,o;if(e=Ft(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=It(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=It(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Ft(){var e;return t.substr(i,6).toLowerCase()===`render`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"render"`)),e===null&&(t.substr(i,7).toLowerCase()===`session`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"session"`)),e===null&&(t.substr(i,4).toLowerCase()===`icon`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"icon"`)),e===null&&(t.substr(i,5).toLowerCase()===`alert`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"alert"`)),e===null&&(e=j())))),e}function It(){var e=Lt();return e===null&&(e=Z()),e}function Lt(){var e,n,r,o=i;return t.substr(i,8).toLowerCase()===`handling`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"handling"`)),e===null?(e=null,i=o):(n=I(),n===null?(e=null,i=o):(t.substr(i,8).toLowerCase()===`optional`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"optional"`)),r===null&&(t.substr(i,8).toLowerCase()===`required`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"required"`)),r===null&&(r=j())),r===null?(e=null,i=o):e=[e,n,r])),e}function Rt(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function zt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Bt(){var e,n=i;return e=Vt(),e!==null&&(e=function(e){$=t.substring(i,e)}(n)),e===null&&(i=n),e}function Vt(){var e,t,n,r,a,o,s=i,c;if(e=Ht(),e!==null){if(t=F(),t!==null){if(n=qt(),n!==null){for(r=[],c=i,a=R(),a===null?(a=null,i=c):(o=Jt(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=R(),a===null?(a=null,i=c):(o=Jt(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function Ht(){var e=Ut();return e===null&&(e=Wt()),e}function Ut(){var e;return t.substr(i,4).toLowerCase()===`text`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"text"`)),e===null&&(t.substr(i,5).toLowerCase()===`image`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"image"`)),e===null&&(t.substr(i,5).toLowerCase()===`audio`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"audio"`)),e===null&&(t.substr(i,5).toLowerCase()===`video`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"video"`)),e===null&&(t.substr(i,11).toLowerCase()===`application`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"application"`)),e===null&&(e=Gt()))))),e}function Wt(){var e;return t.substr(i,7).toLowerCase()===`message`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"message"`)),e===null&&(t.substr(i,9).toLowerCase()===`multipart`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"multipart"`)),e===null&&(e=Gt())),e}function Gt(){var e=j();return e===null&&(e=Kt()),e}function Kt(){var e,n,r=i;return t.substr(i,2).toLowerCase()===`x-`?(e=t.substr(i,2),i+=2):(e=null,a===0&&c(`"x-"`)),e===null?(e=null,i=r):(n=j(),n===null?(e=null,i=r):e=[e,n]),e}function qt(){var e=Gt();return e===null&&(e=j()),e}function Jt(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=I(),t===null?(e=null,i=r):(n=Yt(),n===null?(e=null,i=r):e=[e,t,n])),e}function Yt(){var e=j();return e===null&&(e=ue()),e}function Xt(){var e,t,n,r=i;return e=Zt(),e===null?(e=null,i=r):(t=C(),t===null?(e=null,i=r):(n=St(),n===null?(e=null,i=r):e=[e,t,n])),e}function Zt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$.value=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Qt(){var e,t=i;return e=Mt(),e!==null&&(e=function(e,t){$=t}(t,e)),e===null&&(i=t),e}function $t(){var e,t,n,r,a=i,o=i,s;if(e=en(),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e,t){$.event=t.join(``).toLowerCase()}(a,e[0])),e===null&&(i=a),e}function en(){var e,n,r,o,s=i,l;if(e=M(),e!==null){for(n=[],l=i,t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(r=null,i=l):(o=M(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(r=null,i=l):(o=M(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function tn(){var e,t,n,r,a=i,o=i,s;if(e=pe(),e===null&&(e=Ot()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=nn(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=nn(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t=$.tag;try{$=new Er($.uri,$.display_name,$.params),t&&$.setParam(`tag`,t)}catch{$=-1}}(a)),e===null&&(i=a),e}function nn(){var e=rn();return e===null&&(e=Z()),e}function rn(){var e,n,r,o=i,s=i;return t.substr(i,3).toLowerCase()===`tag`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"tag"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.tag=t}(o,e[2])),e===null&&(i=o),e}function an(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function on(){var e,t=i;return e=Mt(),e!==null&&(e=function(e,t){$=t}(t,e)),e===null&&(i=t),e}function sn(){var e,t,n,r,a,o,s,c=i,l=i,u;for(e=[],t=kt();t!==null;)e.push(t),t=kt();if(e!==null){if(t=ie(),t!==null){if(n=me(),n!==null){if(r=re(),r!==null){for(a=[],u=i,o=R(),o===null?(o=null,i=u):(s=Z(),s===null?(o=null,i=u):o=[o,s]);o!==null;)a.push(o),u=i,o=R(),o===null?(o=null,i=u):(s=Z(),s===null?(o=null,i=u):o=[o,s]);a===null?(e=null,i=l):e=[e,t,n,r,a]}else e=null,i=l}else e=null,i=l}else e=null,i=l}else e=null,i=l;return e!==null&&(e=function(e){try{$=new Er($.uri,$.display_name,$.params)}catch{$=-1}}(c)),e===null&&(i=c),e}function cn(){return ln()}function ln(){var e,n,r,o,s,l,u=i,d;if(t.substr(i,6).toLowerCase()===`digest`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"Digest"`)),e!==null){if(n=C(),n!==null){if(r=fn(),r!==null){for(o=[],d=i,s=L(),s===null?(s=null,i=d):(l=fn(),l===null?(s=null,i=d):s=[s,l]);s!==null;)o.push(s),d=i,s=L(),s===null?(s=null,i=d):(l=fn(),l===null?(s=null,i=d):s=[s,l]);o===null?(e=null,i=u):e=[e,n,r,o]}else e=null,i=u}else e=null,i=u}else e=null,i=u;return e===null&&(e=un()),e}function un(){var e,t,n,r,a,o,s=i,c;if(e=j(),e!==null){if(t=C(),t!==null){if(n=dn(),n!==null){for(r=[],c=i,a=L(),a===null?(a=null,i=c):(o=dn(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=L(),a===null?(a=null,i=c):(o=dn(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function dn(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=I(),t===null?(e=null,i=r):(n=j(),n===null&&(n=ue()),n===null?(e=null,i=r):e=[e,t,n])),e}function fn(){var e=pn();return e===null&&(e=hn(),e===null&&(e=_n(),e===null&&(e=yn(),e===null&&(e=bn(),e===null&&(e=xn(),e===null&&(e=Sn(),e===null&&(e=dn()))))))),e}function pn(){var e,n,r,o=i;return t.substr(i,5).toLowerCase()===`realm`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"realm"`)),e===null?(e=null,i=o):(n=I(),n===null?(e=null,i=o):(r=mn(),r===null?(e=null,i=o):e=[e,n,r])),e}function mn(){var e,t=i;return e=de(),e!==null&&(e=function(e,t){$.realm=t}(t,e)),e===null&&(i=t),e}function hn(){var e,n,r,o,s,l,u,d=i,f;if(t.substr(i,6).toLowerCase()===`domain`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"domain"`)),e!==null){if(n=I(),n!==null){if(r=oe(),r!==null){if(o=gn(),o!==null){if(s=[],f=i,u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;for(l===null?(l=null,i=f):(u=gn(),u===null?(l=null,i=f):l=[l,u]);l!==null;){if(s.push(l),f=i,u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l===null?(l=null,i=f):(u=gn(),u===null?(l=null,i=f):l=[l,u])}s===null?(e=null,i=d):(l=se(),l===null?(e=null,i=d):e=[e,n,r,o,s,l])}else e=null,i=d}else e=null,i=d}else e=null,i=d}else e=null,i=d;return e}function gn(){var e=Xe();return e===null&&(e=$e()),e}function _n(){var e,n,r,o=i;return t.substr(i,5).toLowerCase()===`nonce`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"nonce"`)),e===null?(e=null,i=o):(n=I(),n===null?(e=null,i=o):(r=vn(),r===null?(e=null,i=o):e=[e,n,r])),e}function vn(){var e,t=i;return e=de(),e!==null&&(e=function(e,t){$.nonce=t}(t,e)),e===null&&(i=t),e}function yn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`opaque`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"opaque"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=de(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.opaque=t}(o,e[2])),e===null&&(i=o),e}function bn(){var e,n,r,o=i,s;return t.substr(i,5).toLowerCase()===`stale`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"stale"`)),e===null?(e=null,i=o):(n=I(),n===null?(e=null,i=o):(s=i,t.substr(i,4).toLowerCase()===`true`?(r=t.substr(i,4),i+=4):(r=null,a===0&&c(`"true"`)),r!==null&&(r=function(e){$.stale=!0}(s)),r===null&&(i=s),r===null&&(s=i,t.substr(i,5).toLowerCase()===`false`?(r=t.substr(i,5),i+=5):(r=null,a===0&&c(`"false"`)),r!==null&&(r=function(e){$.stale=!1}(s)),r===null&&(i=s)),r===null?(e=null,i=o):e=[e,n,r])),e}function xn(){var e,n,r,o=i,s=i;return t.substr(i,9).toLowerCase()===`algorithm`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"algorithm"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(t.substr(i,3).toLowerCase()===`md5`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"MD5"`)),r===null&&(t.substr(i,8).toLowerCase()===`md5-sess`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"MD5-sess"`)),r===null&&(r=j())),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.algorithm=t.toUpperCase()}(o,e[2])),e===null&&(i=o),e}function Sn(){var e,n,r,o,s,l,u,d=i,f,p;if(t.substr(i,3).toLowerCase()===`qop`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"qop"`)),e!==null){if(n=I(),n!==null){if(r=oe(),r!==null){if(f=i,o=Cn(),o!==null){for(s=[],p=i,t.charCodeAt(i)===44?(l=`,`,i++):(l=null,a===0&&c(`","`)),l===null?(l=null,i=p):(u=Cn(),u===null?(l=null,i=p):l=[l,u]);l!==null;)s.push(l),p=i,t.charCodeAt(i)===44?(l=`,`,i++):(l=null,a===0&&c(`","`)),l===null?(l=null,i=p):(u=Cn(),u===null?(l=null,i=p):l=[l,u]);s===null?(o=null,i=f):o=[o,s]}else o=null,i=f;o===null?(e=null,i=d):(s=se(),s===null?(e=null,i=d):e=[e,n,r,o,s])}else e=null,i=d}else e=null,i=d}else e=null,i=d;return e}function Cn(){var e,n=i;return t.substr(i,8).toLowerCase()===`auth-int`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"auth-int"`)),e===null&&(t.substr(i,4).toLowerCase()===`auth`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"auth"`)),e===null&&(e=j())),e!==null&&(e=function(e,t){$.qop||($.qop=[]),$.qop.push(t.toLowerCase())}(n,e)),e===null&&(i=n),e}function wn(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Tn(){var e,t,n,r,a=i,o=i,s;if(e=En(),e!==null){for(t=[],s=i,n=L(),n===null?(n=null,i=s):(r=En(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=L(),n===null?(n=null,i=s):(r=En(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t,n=$.multi_header.length;for(t=0;t<n;t++)if($.multi_header[t].parsed===null){$=null;break}$=$===null?-1:$.multi_header}(a)),e===null&&(i=a),e}function En(){var e,t,n,r,a=i,o=i,s;if(e=Ot(),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t;$.multi_header||($.multi_header=[]);try{t=new Er($.uri,$.display_name,$.params),delete $.uri,delete $.display_name,delete $.params}catch{t=null}$.multi_header.push({possition:i,offset:e,parsed:t})}(a)),e===null&&(i=a),e}function Dn(){var e,n,r,o,s=i,l=i,u;if(t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e===null&&(e=j()),e!==null){for(n=[],u=i,r=R(),r===null?(r=null,i=u):(o=On(),o===null?(r=null,i=u):r=[r,o]);r!==null;)n.push(r),u=i,r=R(),r===null?(r=null,i=u):(o=On(),o===null?(r=null,i=u):r=[r,o]);n===null?(e=null,i=l):e=[e,n]}else e=null,i=l;return e!==null&&(e=function(e,t){if($.protocol=t.toLowerCase(),$.params||($.params={}),$.params.text&&$.params.text[0]===`"`){var n=$.params.text;$.text=n.substring(1,n.length-1),delete $.params.text}}(s,e[0])),e===null&&(i=s),e}function On(){var e=kn();return e===null&&(e=Z()),e}function kn(){var e,n,r,o,s=i,l=i;if(t.substr(i,5).toLowerCase()===`cause`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"cause"`)),e!==null){if(n=I(),n!==null){if(o=u(),o!==null)for(r=[];o!==null;)r.push(o),o=u();else r=null;r===null?(e=null,i=l):e=[e,n,r]}else e=null,i=l}else e=null,i=l;return e!==null&&(e=function(e,t){$.cause=parseInt(t.join(``))}(s,e[2])),e===null&&(i=s),e}function An(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function jn(){var e,t,n,r,a=i,o;if(e=Mn(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=Mn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=Mn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Mn(){var e,t,n,r,a=i,o;if(e=Ot(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=Z(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=Z(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Nn(){var e,t,n,r,a=i,o;if(e=Pn(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=Fn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=Fn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Pn(){var e,n=i;return t.substr(i,6).toLowerCase()===`active`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"active"`)),e===null&&(t.substr(i,7).toLowerCase()===`pending`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"pending"`)),e===null&&(t.substr(i,10).toLowerCase()===`terminated`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"terminated"`)),e===null&&(e=j()))),e!==null&&(e=function(e){$.state=t.substring(i,e)}(n)),e===null&&(i=n),e}function Fn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`reason`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"reason"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=In(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.reason=t)}(o,e[2])),e===null&&(i=o),e===null&&(o=i,s=i,t.substr(i,7).toLowerCase()===`expires`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"expires"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Mt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.expires=t)}(o,e[2])),e===null&&(i=o),e===null&&(o=i,s=i,t.substr(i,11).toLowerCase()===`retry_after`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"retry_after"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Mt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.retry_after=t)}(o,e[2])),e===null&&(i=o),e===null&&(e=Z()))),e}function In(){var e;return t.substr(i,11).toLowerCase()===`deactivated`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"deactivated"`)),e===null&&(t.substr(i,9).toLowerCase()===`probation`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"probation"`)),e===null&&(t.substr(i,8).toLowerCase()===`rejected`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"rejected"`)),e===null&&(t.substr(i,7).toLowerCase()===`timeout`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"timeout"`)),e===null&&(t.substr(i,6).toLowerCase()===`giveup`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"giveup"`)),e===null&&(t.substr(i,10).toLowerCase()===`noresource`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"noresource"`)),e===null&&(t.substr(i,9).toLowerCase()===`invariant`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"invariant"`)),e===null&&(e=j()))))))),e}function Ln(){var e=E();return e=e===null?``:e,e}function Rn(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e=e===null?``:e,e}function zn(){var e,t,n,r,a=i,o=i,s;if(e=pe(),e===null&&(e=Ot()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Bn(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Bn(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t=$.tag;try{$=new Er($.uri,$.display_name,$.params),t&&$.setParam(`tag`,t)}catch{$=-1}}(a)),e===null&&(i=a),e}function Bn(){var e=rn();return e===null&&(e=Z()),e}function Vn(){var e,t,n,r,a=i,o;if(e=Hn(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=Hn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=Hn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Hn(){var e,t,n,r,a,o,s=i,c;if(e=Xn(),e!==null){if(t=C(),t!==null){if(n=$n(),n!==null){for(r=[],c=i,a=R(),a===null?(a=null,i=c):(o=Un(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=R(),a===null?(a=null,i=c):(o=Un(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function Un(){var e=Wn();return e===null&&(e=Gn(),e===null&&(e=Kn(),e===null&&(e=qn(),e===null&&(e=Jn(),e===null&&(e=Z()))))),e}function Wn(){var e,n,r,o=i,s=i;return t.substr(i,3).toLowerCase()===`ttl`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"ttl"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=nr(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.ttl=t}(o,e[2])),e===null&&(i=o),e}function Gn(){var e,n,r,o=i,s=i;return t.substr(i,5).toLowerCase()===`maddr`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"maddr"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Se(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.maddr=t}(o,e[2])),e===null&&(i=o),e}function Kn(){var e,n,r,o=i,s=i;return t.substr(i,8).toLowerCase()===`received`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"received"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=Oe(),r===null&&(r=De()),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.received=t}(o,e[2])),e===null&&(i=o),e}function qn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`branch`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"branch"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.branch=t}(o,e[2])),e===null&&(i=o),e}function Jn(){var e,n,r,o=i,s;return t.substr(i,5).toLowerCase()===`rport`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"rport"`)),e===null?(e=null,i=o):(s=i,n=I(),n===null?(n=null,i=s):(r=Yn(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function Yn(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){$.rport=parseInt(t.join(``))}(o,e)),e===null&&(i=o),e}function Xn(){var e,t,n,r,a,o=i;return e=Zn(),e===null?(e=null,i=o):(t=F(),t===null?(e=null,i=o):(n=j(),n===null?(e=null,i=o):(r=F(),r===null?(e=null,i=o):(a=Qn(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function Zn(){var e,n=i;return t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e===null&&(e=j()),e!==null&&(e=function(e,t){$.protocol=t}(n,e)),e===null&&(i=n),e}function Qn(){var e,n=i;return t.substr(i,3).toLowerCase()===`udp`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"UDP"`)),e===null&&(t.substr(i,3).toLowerCase()===`tcp`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"TCP"`)),e===null&&(t.substr(i,3).toLowerCase()===`tls`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"TLS"`)),e===null&&(t.substr(i,4).toLowerCase()===`sctp`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"SCTP"`)),e===null&&(e=j())))),e!==null&&(e=function(e,t){$.transport=t}(n,e)),e===null&&(i=n),e}function $n(){var e,t,n,r=i,a;return e=er(),e===null?(e=null,i=r):(a=i,t=ae(),t===null?(t=null,i=a):(n=tr(),n===null?(t=null,i=a):t=[t,n]),t=t===null?``:t,t===null?(e=null,i=r):e=[e,t]),e}function er(){var e,n=i;return e=Oe(),e===null&&(e=Ee(),e===null&&(e=Ce())),e!==null&&(e=function(e){$.host=t.substring(i,e)}(n)),e===null&&(i=n),e}function tr(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){$.port=parseInt(t.join(``))}(o,e)),e===null&&(i=o),e}function nr(){var e,t,n,r=i,a=i;return e=u(),e===null?(e=null,i=a):(t=u(),t=t===null?``:t,t===null?(e=null,i=a):(n=u(),n=n===null?``:n,n===null?(e=null,i=a):e=[e,t,n])),e!==null&&(e=function(e,t){return parseInt(t.join(``))}(r,e)),e===null&&(i=r),e}function rr(){return ln()}function ir(){var e,t,n,r,a=i,o;if(e=ar(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=or(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=or(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function ar(){var e,t=i;return e=Mt(),e!==null&&(e=function(e,t){$.expires=t}(t,e)),e===null&&(i=t),e}function or(){var e=sr();return e===null&&(e=Z()),e}function sr(){var e,n,r,o=i,s=i;return t.substr(i,9).toLowerCase()===`refresher`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"refresher"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(t.substr(i,3).toLowerCase()===`uac`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"uac"`)),r===null&&(t.substr(i,3).toLowerCase()===`uas`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"uas"`))),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.refresher=t.toLowerCase()}(o,e[2])),e===null&&(i=o),e}function cr(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=T(),t===null?(e=null,i=r):(n=lr(),n===null?(e=null,i=r):e=[e,t,n])),e}function lr(){var e=[],t=D();for(t===null&&(t=k(),t===null&&(t=C()));t!==null;)e.push(t),t=D(),t===null&&(t=k(),t===null&&(t=C()));return e}function ur(){for(var e=[],t=m();t!==null;)e.push(t),t=m();return e}function dr(){var e,n,r=i;return t.substr(i,5)===`uuid:`?(e=`uuid:`,i+=5):(e=null,a===0&&c(`"uuid:"`)),e===null?(e=null,i=r):(n=fr(),n===null?(e=null,i=r):e=[e,n]),e}function fr(){var e,n,r,o,s,l,u,d,f,p=i,m=i;return e=mr(),e===null?(e=null,i=m):(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null?(e=null,i=m):(r=pr(),r===null?(e=null,i=m):(t.charCodeAt(i)===45?(o=`-`,i++):(o=null,a===0&&c(`"-"`)),o===null?(e=null,i=m):(s=pr(),s===null?(e=null,i=m):(t.charCodeAt(i)===45?(l=`-`,i++):(l=null,a===0&&c(`"-"`)),l===null?(e=null,i=m):(u=pr(),u===null?(e=null,i=m):(t.charCodeAt(i)===45?(d=`-`,i++):(d=null,a===0&&c(`"-"`)),d===null?(e=null,i=m):(f=hr(),f===null?(e=null,i=m):e=[e,n,r,o,s,l,u,d,f])))))))),e!==null&&(e=function(e,n){$=t.substring(i+5,e)}(p,e[0])),e===null&&(i=p),e}function pr(){var e,t,n,r,a=i;return e=f(),e===null?(e=null,i=a):(t=f(),t===null?(e=null,i=a):(n=f(),n===null?(e=null,i=a):(r=f(),r===null?(e=null,i=a):e=[e,t,n,r]))),e}function mr(){var e,t,n=i;return e=pr(),e===null?(e=null,i=n):(t=pr(),t===null?(e=null,i=n):e=[e,t]),e}function hr(){var e,t,n,r=i;return e=pr(),e===null?(e=null,i=r):(t=pr(),t===null?(e=null,i=r):(n=pr(),n===null?(e=null,i=r):e=[e,t,n])),e}function gr(){var e,t,n,r,a=i,o=i,s;if(e=pe(),e===null&&(e=Ot()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Z(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){try{$=new Er($.uri,$.display_name,$.params)}catch{$=-1}}(a)),e===null&&(i=a),e}function _r(){var e,t,n,r,a=i,o;if(e=vr(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=yr(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=yr(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function vr(){var e,n,r,o=i,s=i,l;return e=P(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(n=null,i=l):(r=P(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$.call_id=t.substring(i,e)}(o)),e===null&&(i=o),e}function yr(){var e=br();return e===null&&(e=xr(),e===null&&(e=Sr(),e===null&&(e=Z()))),e}function br(){var e,n,r,o=i,s=i;return t.substr(i,6)===`to-tag`?(e=`to-tag`,i+=6):(e=null,a===0&&c(`"to-tag"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.to_tag=t}(o,e[2])),e===null&&(i=o),e}function xr(){var e,n,r,o=i,s=i;return t.substr(i,8)===`from-tag`?(e=`from-tag`,i+=8):(e=null,a===0&&c(`"from-tag"`)),e===null?(e=null,i=s):(n=I(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.from_tag=t}(o,e[2])),e===null&&(i=o),e}function Sr(){var e,n=i;return t.substr(i,10)===`early-only`?(e=`early-only`,i+=10):(e=null,a===0&&c(`"early-only"`)),e!==null&&(e=function(e){$.early_only=!0}(n)),e===null&&(i=n),e}function Cr(e){e.sort();for(var t=null,n=[],r=0;r<e.length;r++)e[r]!==t&&(n.push(e[r]),t=e[r]);return n}function wr(){for(var e=1,n=1,r=!1,a=0;a<Math.max(i,o);a++){var s=t.charAt(a);s===`
4
- `?(r||e++,n=1,r=!1):s===`\r`||s===`\u2028`||s===`\u2029`?(e++,n=1,r=!0):(n++,r=!1)}return{line:e,column:n}}var Tr=Dt(),Er=Et(),$={};if(r[n]()===null||i!==t.length){var Dr=Math.max(i,o),Or=Dr<t.length?t.charAt(Dr):null,kr=wr();return new this.SyntaxError(Cr(s),Or,Dr,kr.line,kr.column),-1}return $},toSource:function(){return this._source}};return t.SyntaxError=function(t,n,r,i,a){function o(t,n){var r,i;switch(t.length){case 0:r=`end of input`;break;case 1:r=t[0];break;default:r=t.slice(0,t.length-1).join(`, `)+` or `+t[t.length-1]}return i=n?e(n):`end of input`,`Expected `+r+` but `+i+` found.`}this.name=`SyntaxError`,this.expected=t,this.found=n,this.message=o(t,n),this.offset=r,this.line=i,this.column=a},t.SyntaxError.prototype=Error.prototype,t}()})),Dt=c(((e,t)=>{function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}var c=G(),l=J(),u=q();t.exports=function(){s(e,null,[{key:`parse`,value:function(e){if(e=u.parse(e,`SIP_URI`),e!==-1)return e}}]);function e(t,n,r,i){var o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},s=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(a(this,e),!r)throw TypeError(`missing or invalid "host" parameter`);for(var l in this._parameters={},this._headers={},this._scheme=t||c.SIP,this._user=n,this._host=r,this._port=i,o)Object.prototype.hasOwnProperty.call(o,l)&&this.setParam(l,o[l]);for(var u in s)Object.prototype.hasOwnProperty.call(s,u)&&this.setHeader(u,s[u])}return s(e,[{key:`setParam`,value:function(e,t){e&&(this._parameters[e.toLowerCase()]=t==null?null:t.toString())}},{key:`getParam`,value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:`hasParam`,value:function(e){if(e)return this._parameters.hasOwnProperty(e.toLowerCase())&&!0||!1}},{key:`deleteParam`,value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:`clearParams`,value:function(){this._parameters={}}},{key:`setHeader`,value:function(e,t){this._headers[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:`getHeader`,value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:`hasHeader`,value:function(e){if(e)return this._headers.hasOwnProperty(l.headerize(e))&&!0||!1}},{key:`deleteHeader`,value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:`clearHeaders`,value:function(){this._headers={}}},{key:`clone`,value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:`toString`,value:function(){var e=[],t=`${this._scheme}:`;for(var r in this._user&&(t+=`${l.escapeUser(this._user)}@`),t+=this._host,(this._port||this._port===0)&&(t+=`:${this._port}`),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(t+=`;${r}`,this._parameters[r]!==null&&(t+=`=${this._parameters[r]}`));for(var i in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,i)){var a=n(this._headers[i]),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;e.push(`${i}=${s}`)}}catch(e){a.e(e)}finally{a.f()}}return e.length>0&&(t+=`?${e.join(`&`)}`),t}},{key:`toAor`,value:function(e){var t=`${this._scheme}:`;return this._user&&(t+=`${l.escapeUser(this._user)}@`),t+=this._host,e&&(this._port||this._port===0)&&(t+=`:${this._port}`),t}},{key:`scheme`,get:function(){return this._scheme},set:function(e){this._scheme=e.toLowerCase()}},{key:`user`,get:function(){return this._user},set:function(e){this._user=e}},{key:`host`,get:function(){return this._host},set:function(e){this._host=e.toLowerCase()}},{key:`port`,get:function(){return this._port},set:function(e){this._port=e===0?e:parseInt(e,10)||null}}]),e}()})),J=c((e=>{function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
6
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=G(),o=Dt(),s=q();e.str_utf8_length=function(e){return unescape(encodeURIComponent(e)).length};var c=e.isFunction=function(e){return e!==void 0&&Object.prototype.toString.call(e)===`[object Function]`};e.isString=function(e){return e!==void 0&&Object.prototype.toString.call(e)===`[object String]`},e.isDecimal=function(e){return!isNaN(e)&&parseFloat(e)===parseInt(e,10)},e.isEmpty=function(e){return e===null||e===``||e===void 0||Array.isArray(e)&&e.length===0||typeof e==`number`&&isNaN(e)},e.hasMethods=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var i=0,a=n;i<a.length;i++){var o=a[i];if(c(e[o]))return!1}return!0};var l=e.createRandomToken=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,n,r,i=``;for(n=0;n<e;n++)r=Math.random()*t|0,i+=r.toString(t);return i};e.newTag=function(){return l(10)},e.newUUID=function(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){var t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})},e.hostType=function(e){if(e&&(e=s.parse(e,`host`),e!==-1))return e.host_type};var u=e.escapeUser=function(e){return encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,`:`).replace(/%2B/gi,`+`).replace(/%3F/gi,`?`).replace(/%2F/gi,`/`)};e.normalizeTarget=function(e,t){if(e){if(e instanceof o)return e;if(typeof e==`string`){var n=e.split(`@`),r,i;switch(n.length){case 1:if(!t)return;r=e,i=t;break;case 2:r=n[0],i=n[1];break;default:r=n.slice(0,n.length-1).join(`@`),i=n[n.length-1]}r=r.replace(/^(sips?|tel):/i,``),/^[-.()]*\+?[0-9\-.()]+$/.test(r)&&(r=r.replace(/[-.()]/g,``)),e=`${a.SIP}:${u(r)}@${i}`;var s;return(s=o.parse(e))?s:void 0}}},e.headerize=function(e){for(var t={"Call-Id":`Call-ID`,Cseq:`CSeq`,"Www-Authenticate":`WWW-Authenticate`},n=e.toLowerCase().replace(/_/g,`-`).split(`-`),r=``,i=n.length,a=0;a<i;a++)a!==0&&(r+=`-`),r+=n[a].charAt(0).toUpperCase()+n[a].substring(1);return t[r]&&(r=t[r]),r},e.sipErrorCause=function(e){for(var t in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[t].indexOf(e)!==-1)return a.causes[t];return a.causes.SIP_FAILURE_CODE},e.getRandomTestNetIP=function(){function e(e,t){return Math.floor(Math.random()*(t-e+1)+e)}return`192.0.2.${e(1,254)}`},e.calculateMD5=function(e){function t(e,t){return e<<t|e>>>32-t}function n(e,t){var n=e&2147483648,r=t&2147483648,i=e&1073741824,a=t&1073741824,o=(e&1073741823)+(t&1073741823);return i&a?o^2147483648^n^r:i|a?o&1073741824?o^3221225472^n^r:o^1073741824^n^r:o^n^r}function r(e,t,n){return e&t|~e&n}function i(e,t,n){return e&n|t&~n}function a(e,t,n){return e^t^n}function o(e,t,n){return t^(e|~n)}function s(e,i,a,o,s,c,l){return e=n(e,n(n(r(i,a,o),s),l)),n(t(e,c),i)}function c(e,r,a,o,s,c,l){return e=n(e,n(n(i(r,a,o),s),l)),n(t(e,c),r)}function l(e,r,i,o,s,c,l){return e=n(e,n(n(a(r,i,o),s),l)),n(t(e,c),r)}function u(e,r,i,a,s,c,l){return e=n(e,n(n(o(r,i,a),s),l)),n(t(e,c),r)}function d(e){for(var t,n=e.length,r=n+8,i=((r-r%64)/64+1)*16,a=Array(i-1),o=0,s=0;s<n;)t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|e.charCodeAt(s)<<o,s++;return t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|128<<o,a[i-2]=n<<3,a[i-1]=n>>>29,a}function f(e){for(var t=``,n=``,r,i=0;i<=3;i++)r=e>>>i*8&255,n=`0${r.toString(16)}`,t+=n.substr(n.length-2,2);return t}function p(e){for(var t=``,n=0;n<e.length;n++){var r=e.charCodeAt(n);r<128?t+=String.fromCharCode(r):r>127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(r&63|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(r&63|128))}return t}var m=[],h,g,_,v,y,b,x,S,C,w=7,T=12,E=17,D=22,O=5,k=9,A=14,j=20,M=4,N=11,P=16,ee=23,F=6,I=10,te=15,ne=21;for(e=p(e),m=d(e),b=1732584193,x=4023233417,S=2562383102,C=271733878,h=0;h<m.length;h+=16)g=b,_=x,v=S,y=C,b=s(b,x,S,C,m[h+0],w,3614090360),C=s(C,b,x,S,m[h+1],T,3905402710),S=s(S,C,b,x,m[h+2],E,606105819),x=s(x,S,C,b,m[h+3],D,3250441966),b=s(b,x,S,C,m[h+4],w,4118548399),C=s(C,b,x,S,m[h+5],T,1200080426),S=s(S,C,b,x,m[h+6],E,2821735955),x=s(x,S,C,b,m[h+7],D,4249261313),b=s(b,x,S,C,m[h+8],w,1770035416),C=s(C,b,x,S,m[h+9],T,2336552879),S=s(S,C,b,x,m[h+10],E,4294925233),x=s(x,S,C,b,m[h+11],D,2304563134),b=s(b,x,S,C,m[h+12],w,1804603682),C=s(C,b,x,S,m[h+13],T,4254626195),S=s(S,C,b,x,m[h+14],E,2792965006),x=s(x,S,C,b,m[h+15],D,1236535329),b=c(b,x,S,C,m[h+1],O,4129170786),C=c(C,b,x,S,m[h+6],k,3225465664),S=c(S,C,b,x,m[h+11],A,643717713),x=c(x,S,C,b,m[h+0],j,3921069994),b=c(b,x,S,C,m[h+5],O,3593408605),C=c(C,b,x,S,m[h+10],k,38016083),S=c(S,C,b,x,m[h+15],A,3634488961),x=c(x,S,C,b,m[h+4],j,3889429448),b=c(b,x,S,C,m[h+9],O,568446438),C=c(C,b,x,S,m[h+14],k,3275163606),S=c(S,C,b,x,m[h+3],A,4107603335),x=c(x,S,C,b,m[h+8],j,1163531501),b=c(b,x,S,C,m[h+13],O,2850285829),C=c(C,b,x,S,m[h+2],k,4243563512),S=c(S,C,b,x,m[h+7],A,1735328473),x=c(x,S,C,b,m[h+12],j,2368359562),b=l(b,x,S,C,m[h+5],M,4294588738),C=l(C,b,x,S,m[h+8],N,2272392833),S=l(S,C,b,x,m[h+11],P,1839030562),x=l(x,S,C,b,m[h+14],ee,4259657740),b=l(b,x,S,C,m[h+1],M,2763975236),C=l(C,b,x,S,m[h+4],N,1272893353),S=l(S,C,b,x,m[h+7],P,4139469664),x=l(x,S,C,b,m[h+10],ee,3200236656),b=l(b,x,S,C,m[h+13],M,681279174),C=l(C,b,x,S,m[h+0],N,3936430074),S=l(S,C,b,x,m[h+3],P,3572445317),x=l(x,S,C,b,m[h+6],ee,76029189),b=l(b,x,S,C,m[h+9],M,3654602809),C=l(C,b,x,S,m[h+12],N,3873151461),S=l(S,C,b,x,m[h+15],P,530742520),x=l(x,S,C,b,m[h+2],ee,3299628645),b=u(b,x,S,C,m[h+0],F,4096336452),C=u(C,b,x,S,m[h+7],I,1126891415),S=u(S,C,b,x,m[h+14],te,2878612391),x=u(x,S,C,b,m[h+5],ne,4237533241),b=u(b,x,S,C,m[h+12],F,1700485571),C=u(C,b,x,S,m[h+3],I,2399980690),S=u(S,C,b,x,m[h+10],te,4293915773),x=u(x,S,C,b,m[h+1],ne,2240044497),b=u(b,x,S,C,m[h+8],F,1873313359),C=u(C,b,x,S,m[h+15],I,4264355552),S=u(S,C,b,x,m[h+6],te,2734768916),x=u(x,S,C,b,m[h+13],ne,1309151649),b=u(b,x,S,C,m[h+4],F,4149444226),C=u(C,b,x,S,m[h+11],I,3174756917),S=u(S,C,b,x,m[h+2],te,718787259),x=u(x,S,C,b,m[h+9],ne,3951481745),b=n(b,g),x=n(x,_),S=n(S,v),C=n(C,y);return(f(b)+f(x)+f(S)+f(C)).toLowerCase()},e.closeMediaStream=function(e){if(e)try{var r;if(e.getTracks){r=e.getTracks();var i=n(r),a;try{for(i.s();!(a=i.n()).done;)a.value.stop()}catch(e){i.e(e)}finally{i.f()}}else{r=e.getAudioTracks();var o=n(r),s;try{for(o.s();!(s=o.n()).done;)s.value.stop()}catch(e){o.e(e)}finally{o.f()}r=e.getVideoTracks();var c=n(r),l;try{for(c.s();!(l=c.n()).done;)l.value.stop()}catch(e){c.e(e)}finally{c.f()}}}catch{(typeof e.stop==`function`||t(e.stop)===`object`)&&e.stop()}},e.cloneArray=function(e){return e&&e.slice()||[]},e.cloneObject=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return e&&Object.assign({},e)||t}})),Y=c(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),Ot=c(((e,t)=>{var n=1e3,r=n*60,i=r*60,a=i*24,o=a*7,s=a*365.25;t.exports=function(e,t){t||={};var n=typeof e;if(n===`string`&&e.length>0)return c(e);if(n===`number`&&isFinite(e))return t.long?u(e):l(e);throw Error(`val is not a non-empty string or a valid number. val=`+JSON.stringify(e))};function c(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var c=parseFloat(t[1]);switch((t[2]||`ms`).toLowerCase()){case`years`:case`year`:case`yrs`:case`yr`:case`y`:return c*s;case`weeks`:case`week`:case`w`:return c*o;case`days`:case`day`:case`d`:return c*a;case`hours`:case`hour`:case`hrs`:case`hr`:case`h`:return c*i;case`minutes`:case`minute`:case`mins`:case`min`:case`m`:return c*r;case`seconds`:case`second`:case`secs`:case`sec`:case`s`:return c*n;case`milliseconds`:case`millisecond`:case`msecs`:case`msec`:case`ms`:return c;default:return}}}}function l(e){var t=Math.abs(e);return t>=a?Math.round(e/a)+`d`:t>=i?Math.round(e/i)+`h`:t>=r?Math.round(e/r)+`m`:t>=n?Math.round(e/n)+`s`:e+`ms`}function u(e){var t=Math.abs(e);return t>=a?d(e,t,a,`day`):t>=i?d(e,t,i,`hour`):t>=r?d(e,t,r,`minute`):t>=n?d(e,t,n,`second`):e+` ms`}function d(e,t,n,r){var i=t>=n*1.5;return Math.round(e/n)+` `+r+(i?`s`:``)}})),kt=c(((e,t)=>{function n(e){n.debug=n,n.default=n,n.coerce=c,n.disable=o,n.enable=i,n.enabled=s,n.humanize=Ot(),n.destroy=l,Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={};function t(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]}n.selectColor=t;function n(e){let t,i=null,a,o;function s(...e){if(!s.enabled)return;let r=s,i=Number(new Date);r.diff=i-(t||i),r.prev=t,r.curr=i,t=i,e[0]=n.coerce(e[0]),typeof e[0]!=`string`&&e.unshift(`%O`);let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,i)=>{if(t===`%%`)return`%`;a++;let o=n.formatters[i];if(typeof o==`function`){let n=e[a];t=o.call(r,n),e.splice(a,1),a--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return s.namespace=e,s.useColors=n.useColors(),s.color=n.selectColor(e),s.extend=r,s.destroy=n.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>i===null?(a!==n.namespaces&&(a=n.namespaces,o=n.enabled(e)),o):i,set:e=>{i=e}}),typeof n.init==`function`&&n.init(s),s}function r(e,t){let r=n(this.namespace+(t===void 0?`:`:t)+e);return r.log=this.log,r}function i(e){n.save(e),n.namespaces=e,n.names=[],n.skips=[];let t=(typeof e==`string`?e:``).trim().replace(/\s+/g,`,`).split(`,`).filter(Boolean);for(let e of t)e[0]===`-`?n.skips.push(e.slice(1)):n.names.push(e)}function a(e,t){let n=0,r=0,i=-1,a=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||t[r]===`*`))t[r]===`*`?(i=r,a=n,r++):(n++,r++);else if(i!==-1)r=i+1,a++,n=a;else return!1;for(;r<t.length&&t[r]===`*`;)r++;return r===t.length}function o(){let e=[...n.names,...n.skips.map(e=>`-`+e)].join(`,`);return n.enable(``),e}function s(e){for(let t of n.skips)if(a(e,t))return!1;for(let t of n.names)if(a(e,t))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}t.exports=n})),At=c(((e,t)=>{e.formatArgs=r,e.save=i,e.load=a,e.useColors=n,e.storage=o(),e.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`."))}})(),e.colors=`#0000CC.#0000FF.#0033CC.#0033FF.#0066CC.#0066FF.#0099CC.#0099FF.#00CC00.#00CC33.#00CC66.#00CC99.#00CCCC.#00CCFF.#3300CC.#3300FF.#3333CC.#3333FF.#3366CC.#3366FF.#3399CC.#3399FF.#33CC00.#33CC33.#33CC66.#33CC99.#33CCCC.#33CCFF.#6600CC.#6600FF.#6633CC.#6633FF.#66CC00.#66CC33.#9900CC.#9900FF.#9933CC.#9933FF.#99CC00.#99CC33.#CC0000.#CC0033.#CC0066.#CC0099.#CC00CC.#CC00FF.#CC3300.#CC3333.#CC3366.#CC3399.#CC33CC.#CC33FF.#CC6600.#CC6633.#CC9900.#CC9933.#CCCC00.#CCCC33.#FF0000.#FF0033.#FF0066.#FF0099.#FF00CC.#FF00FF.#FF3300.#FF3333.#FF3366.#FF3399.#FF33CC.#FF33FF.#FF6600.#FF6633.#FF9900.#FF9933.#FFCC00.#FFCC33`.split(`.`);function n(){if(typeof window<`u`&&window.process&&(window.process.type===`renderer`||window.process.__nwjs))return!0;if(typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<`u`&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<`u`&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<`u`&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function r(e){if(e[0]=(this.useColors?`%c`:``)+this.namespace+(this.useColors?` %c`:` `)+e[0]+(this.useColors?`%c `:` `)+`+`+t.exports.humanize(this.diff),!this.useColors)return;let n=`color: `+this.color;e.splice(1,0,n,`color: inherit`);let r=0,i=0;e[0].replace(/%[a-zA-Z%]/g,e=>{e!==`%%`&&(r++,e===`%c`&&(i=r))}),e.splice(i,0,n)}e.log=console.debug||console.log||(()=>{});function i(t){try{t?e.storage.setItem(`debug`,t):e.storage.removeItem(`debug`)}catch{}}function a(){let t;try{t=e.storage.getItem(`debug`)||e.storage.getItem(`DEBUG`)}catch{}return!t&&typeof process<`u`&&`env`in process&&(t=process.env.DEBUG),t}function o(){try{return localStorage}catch{}}t.exports=kt()(e);var{formatters:s}=t.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: `+e.message}}})),X=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=At(),o=`JsSIP`;t.exports=function(){function e(t){n(this,e),t?(this._debug=a.default(`${o}:${t}`),this._warn=a.default(`${o}:WARN:${t}`),this._error=a.default(`${o}:ERROR:${t}`)):(this._debug=a.default(o),this._warn=a.default(`${o}:WARN`),this._error=a.default(`${o}:ERROR`)),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return i(e,[{key:`debug`,get:function(){return this._debug}},{key:`warn`,get:function(){return this._warn}},{key:`error`,get:function(){return this._error}}]),e}()})),jt=c(((e,t)=>{var n=t.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 e.address==null?`rtcp:%d`:`rtcp:%d %s IP%d %s`}},{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 e.subtype==null?`rtcp-fb:%s %s`:`rtcp-fb:%s %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 e.sessionConfig==null?`crypto:%d %s %s`:`crypto:%d %s %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+=e.raddr==null?`%v%v`:` raddr %s rport %d`,t+=e.tcptype==null?`%v`:` tcptype %s`,e.generation!=null&&(t+=` generation %d`),t+=e[`network-id`]==null?`%v`:` network-id %d`,t+=e[`network-cost`]==null?`%v`:` network-cost %d`,t}},{name:`endOfCandidates`,reg:/^(end-of-candidates)/},{name:`remoteCandidates`,reg:/^remote-candidates:(.*)/,format:`remote-candidates:%s`},{name:`iceOptions`,reg:/^ice-options:(\S*)/,format:`ice-options:%s`},{push:`ssrcs`,reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:[`id`,`attribute`,`value`],format:function(e){var t=`ssrc:%d`;return e.attribute!=null&&(t+=` %s`,e.value!=null&&(t+=`:%s`)),t}},{push:`ssrcGroups`,reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:[`semantics`,`ssrcs`],format:`ssrc-group:%s %s`},{name:`msidSemantic`,reg:/^msid-semantic:\s?(\w*) (\S*)/,names:[`semantic`,`token`],format:`msid-semantic: %s %s`},{push:`groups`,reg:/^group:(\w*) (.*)/,names:[`type`,`mids`],format:`group:%s %s`},{name:`rtcpMux`,reg:/^(rtcp-mux)/},{name:`rtcpRsize`,reg:/^(rtcp-rsize)/},{name:`sctpmap`,reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:[`sctpmapNumber`,`app`,`maxMessageSize`],format:function(e){return e.maxMessageSize==null?`sctpmap:%s %s`:`sctpmap:%s %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: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: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`+(e.clksrcExt==null?``:`=%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+=e.id==null?`%v%s`:`id=%s %s`,t+=e.mediaClockValue==null?``:`=%s`,t+=e.rateNumerator==null?``:` rate=%s`,t+=e.rateDenominator==null?``:`/%s`,t}},{name:`keywords`,reg:/^keywds:(.+)$/,format:`keywds:%s`},{name:`content`,reg:/^content:(.+)/,format:`content:%s`},{name:`bfcpFloorCtrl`,reg:/^floorctrl:(c-only|s-only|c-s)/,format:`floorctrl:%s`},{name:`bfcpConfId`,reg:/^confid:(\d+)/,format:`confid:%s`},{name:`bfcpUserId`,reg:/^userid:(\d+)/,format:`userid:%s`},{name:`bfcpFloorId`,reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:[`id`,`mStream`],format:`floorid:%s mstrm:%s`},{push:`invalid`,names:[`value`]}]};Object.keys(n).forEach(function(e){n[e].forEach(function(e){e.reg||=/(.*)/,e.format||=`%s`})})})),Mt=c((e=>{var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,r,i){if(i&&!r)n[i]=t(e[1]);else for(var a=0;a<r.length;a+=1)e[a+1]!=null&&(n[r[a]]=t(e[a+1]))},r=function(e,t,r){var i=e.name&&e.names;e.push&&!t[e.push]?t[e.push]=[]:i&&!t[e.name]&&(t[e.name]={});var a=e.push?{}:i?t[e.name]:t;n(r.match(e.reg),a,e.names,e.name),e.push&&t[e.push].push(a)},i=jt(),a=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},n=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(a).forEach(function(e){var t=e[0],a=e.slice(2);t===`m`&&(n.push({rtp:[],fmtp:[]}),o=n[n.length-1]);for(var s=0;s<(i[t]||[]).length;s+=1){var c=i[t][s];if(c.reg.test(a))return r(c,o,a)}}),t.media=n,t};var o=function(e,n){var r=n.split(/=(.+)/,2);return r.length===2?e[r[0]]=t(r[1]):r.length===1&&n.length>1&&(e[r[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(o,{})},e.parseFmtpConfig=e.parseParams,e.parsePayloads=function(e){return e.toString().split(` `).map(Number)},e.parseRemoteCandidates=function(e){for(var n=[],r=e.split(` `).map(t),i=0;i<r.length;i+=3)n.push({component:r[i],ip:r[i+1],port:r[i+2]});return n},e.parseImageAttributes=function(e){return e.split(` `).map(function(e){return e.substring(1,e.length-1).split(`,`).reduce(o,{})})},e.parseSimulcastStreamList=function(e){return e.split(`;`).map(function(e){return e.split(`,`).map(function(e){var n,r=!1;return e[0]===`~`?(n=t(e.substring(1,e.length)),r=!0):n=t(e),{scid:n,paused:r}})})}})),Nt=c(((e,t)=>{var n=jt(),r=/%[sdv%]/g,i=function(e){var t=1,n=arguments,i=n.length;return e.replace(r,function(e){if(t>=i)return e;var r=n[t];switch(t+=1,e){case`%%`:return`%`;case`%s`:return String(r);case`%d`:return Number(r);case`%v`:return``}})},a=function(e,t,n){var r=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,a=[e+`=`+r];if(t.names)for(var o=0;o<t.names.length;o+=1){var s=t.names[o];t.name?a.push(n[t.name][s]):a.push(n[t.names[o]])}else a.push(n[t.name]);return i.apply(null,a)},o=[`v`,`o`,`s`,`i`,`u`,`e`,`p`,`c`,`b`,`t`,`r`,`z`,`a`],s=[`i`,`c`,`b`,`a`];t.exports=function(e,t){t||={},e.version??=0,e.name??=` `,e.media.forEach(function(e){e.payloads??=``});var r=t.outerOrder||o,i=t.innerOrder||s,c=[];return r.forEach(function(t){n[t].forEach(function(n){n.name in e&&e[n.name]!=null?c.push(a(t,n,e)):n.push in e&&e[n.push]!=null&&e[n.push].forEach(function(e){c.push(a(t,n,e))})})}),e.media.forEach(function(e){c.push(a(`m`,n.m[0],e)),i.forEach(function(t){n[t].forEach(function(n){n.name in e&&e[n.name]!=null?c.push(a(t,n,e)):n.push in e&&e[n.push]!=null&&e[n.push].forEach(function(e){c.push(a(t,n,e))})})})}),c.join(`\r
3
+ `,i+=2):(e=null,a===0&&c(`"\\r\\n"`)),e}function u(){var e;return/^[0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[0-9]`)),e}function d(){var e;return/^[a-zA-Z]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-zA-Z]`)),e}function f(){var e;return/^[0-9a-fA-F]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[0-9a-fA-F]`)),e}function p(){var e=g();return e===null&&(e=_()),e}function m(){var e;return/^[\0-\xFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\0-\\xFF]`)),e}function h(){var e;return/^["]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`["]`)),e}function g(){var e;return t.charCodeAt(i)===32?(e=` `,i++):(e=null,a===0&&c(`" "`)),e}function _(){var e;return t.charCodeAt(i)===9?(e=` `,i++):(e=null,a===0&&c(`"\\t"`)),e}function v(){var e;return/^[a-zA-Z0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-zA-Z0-9]`)),e}function y(){var e;return t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`))))))))))),e}function b(){var e=v();return e===null&&(e=x()),e}function x(){var e;return t.charCodeAt(i)===45?(e=`-`,i++):(e=null,a===0&&c(`"-"`)),e===null&&(t.charCodeAt(i)===95?(e=`_`,i++):(e=null,a===0&&c(`"_"`)),e===null&&(t.charCodeAt(i)===46?(e=`.`,i++):(e=null,a===0&&c(`"."`)),e===null&&(t.charCodeAt(i)===33?(e=`!`,i++):(e=null,a===0&&c(`"!"`)),e===null&&(t.charCodeAt(i)===126?(e=`~`,i++):(e=null,a===0&&c(`"~"`)),e===null&&(t.charCodeAt(i)===42?(e=`*`,i++):(e=null,a===0&&c(`"*"`)),e===null&&(t.charCodeAt(i)===39?(e=`'`,i++):(e=null,a===0&&c(`"'"`)),e===null&&(t.charCodeAt(i)===40?(e=`(`,i++):(e=null,a===0&&c(`"("`)),e===null&&(t.charCodeAt(i)===41?(e=`)`,i++):(e=null,a===0&&c(`")"`)))))))))),e}function S(){var e,n,r,o=i,s=i;return t.charCodeAt(i)===37?(e=`%`,i++):(e=null,a===0&&c(`"%"`)),e===null?(e=null,i=s):(n=f(),n===null?(e=null,i=s):(r=f(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){return t.join(``)}(o,e)),e===null&&(i=o),e}function C(){var e,t,n,r=i,a=i,o=i;for(e=[],t=p();t!==null;)e.push(t),t=p();if(e===null?(e=null,i=o):(t=l(),t===null?(e=null,i=o):e=[e,t]),e=e===null?``:e,e!==null){if(n=p(),n!==null)for(t=[];n!==null;)t.push(n),n=p();else t=null;t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e!==null&&(e=function(e){return` `}(r)),e===null&&(i=r),e}function w(){var e=C();return e=e===null?``:e,e}function T(){var e,n,r,o=i,s=i;for(e=[],n=g(),n===null&&(n=_());n!==null;)e.push(n),n=g(),n===null&&(n=_());return e===null?(e=null,i=s):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`:`}(o)),e===null&&(i=o),e}function E(){var e,n,r,a,o=i,s=i,c;if(n=D(),n!==null)for(e=[];n!==null;)e.push(n),n=D();else e=null;if(e!==null){for(n=[],c=i,r=[],a=C();a!==null;)r.push(a),a=C();for(r===null?(r=null,i=c):(a=D(),a===null?(r=null,i=c):r=[r,a]);r!==null;){for(n.push(r),c=i,r=[],a=C();a!==null;)r.push(a),a=C();r===null?(r=null,i=c):(a=D(),a===null?(r=null,i=c):r=[r,a])}n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e!==null&&(e=function(e){return t.substring(i,e)}(o)),e===null&&(i=o),e}function D(){var e;return/^[!-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[!-~]`)),e===null&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\x80-\\uFFFF]`)),e}function k(){var e;return/^[\x80-\xBF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\x80-\\xBF]`)),e}function A(){var e=u();return e===null&&(/^[a-f]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[a-f]`))),e}function j(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`))))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function M(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function N(){var e;return t.charCodeAt(i)===40?(e=`(`,i++):(e=null,a===0&&c(`"("`)),e===null&&(t.charCodeAt(i)===41?(e=`)`,i++):(e=null,a===0&&c(`")"`)),e===null&&(t.charCodeAt(i)===60?(e=`<`,i++):(e=null,a===0&&c(`"<"`)),e===null&&(t.charCodeAt(i)===62?(e=`>`,i++):(e=null,a===0&&c(`">"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===92?(e=`\\`,i++):(e=null,a===0&&c(`"\\\\"`)),e===null&&(e=h(),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===123?(e=`{`,i++):(e=null,a===0&&c(`"{"`)),e===null&&(t.charCodeAt(i)===125?(e=`}`,i++):(e=null,a===0&&c(`"}"`)),e===null&&(e=g(),e===null&&(e=_())))))))))))))))))),e}function P(){var e,n,r=i;if(n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)),n===null&&(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null&&(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null&&(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null&&(t.charCodeAt(i)===62?(n=`>`,i++):(n=null,a===0&&c(`">"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===92?(n=`\\`,i++):(n=null,a===0&&c(`"\\\\"`)),n===null&&(n=h(),n===null&&(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null&&(t.charCodeAt(i)===91?(n=`[`,i++):(n=null,a===0&&c(`"["`)),n===null&&(t.charCodeAt(i)===93?(n=`]`,i++):(n=null,a===0&&c(`"]"`)),n===null&&(t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null&&(t.charCodeAt(i)===123?(n=`{`,i++):(n=null,a===0&&c(`"{"`)),n===null&&(t.charCodeAt(i)===125?(n=`}`,i++):(n=null,a===0&&c(`"}"`))))))))))))))))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=v(),n===null&&(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null&&(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null&&(t.charCodeAt(i)===33?(n=`!`,i++):(n=null,a===0&&c(`"!"`)),n===null&&(t.charCodeAt(i)===37?(n=`%`,i++):(n=null,a===0&&c(`"%"`)),n===null&&(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null&&(t.charCodeAt(i)===95?(n=`_`,i++):(n=null,a===0&&c(`"_"`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===96?(n="`",i++):(n=null,a===0&&c('"`"')),n===null&&(t.charCodeAt(i)===39?(n=`'`,i++):(n=null,a===0&&c(`"'"`)),n===null&&(t.charCodeAt(i)===126?(n=`~`,i++):(n=null,a===0&&c(`"~"`)),n===null&&(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null&&(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null&&(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null&&(t.charCodeAt(i)===62?(n=`>`,i++):(n=null,a===0&&c(`">"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===92?(n=`\\`,i++):(n=null,a===0&&c(`"\\\\"`)),n===null&&(n=h(),n===null&&(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null&&(t.charCodeAt(i)===91?(n=`[`,i++):(n=null,a===0&&c(`"["`)),n===null&&(t.charCodeAt(i)===93?(n=`]`,i++):(n=null,a===0&&c(`"]"`)),n===null&&(t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null&&(t.charCodeAt(i)===123?(n=`{`,i++):(n=null,a===0&&c(`"{"`)),n===null&&(t.charCodeAt(i)===125?(n=`}`,i++):(n=null,a===0&&c(`"}"`)))))))))))))))))))))))));else e=null;return e!==null&&(e=function(e){return t.substring(i,e)}(r)),e===null&&(i=r),e}function ee(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===42?(n=`*`,i++):(n=null,a===0&&c(`"*"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`*`}(o)),e===null&&(i=o),e}function te(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`/`}(o)),e===null&&(i=o),e}function F(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`=`}(o)),e===null&&(i=o),e}function I(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===40?(n=`(`,i++):(n=null,a===0&&c(`"("`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`(`}(o)),e===null&&(i=o),e}function ne(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===41?(n=`)`,i++):(n=null,a===0&&c(`")"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`)`}(o)),e===null&&(i=o),e}function re(){var e,n,r=i,o=i;return t.charCodeAt(i)===62?(e=`>`,i++):(e=null,a===0&&c(`">"`)),e===null?(e=null,i=o):(n=w(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e){return`>`}(r)),e===null&&(i=r),e}function ie(){var e,n,r=i,o=i;return e=w(),e===null?(e=null,i=o):(t.charCodeAt(i)===60?(n=`<`,i++):(n=null,a===0&&c(`"<"`)),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e){return`<`}(r)),e===null&&(i=r),e}function L(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`,`}(o)),e===null&&(i=o),e}function R(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`;`}(o)),e===null&&(i=o),e}function ae(){var e,n,r,o=i,s=i;return e=w(),e===null?(e=null,i=s):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=s):(r=w(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return`:`}(o)),e===null&&(i=o),e}function oe(){var e,t,n=i,r=i;return e=w(),e===null?(e=null,i=r):(t=h(),t===null?(e=null,i=r):e=[e,t]),e!==null&&(e=function(e){return`"`}(n)),e===null&&(i=n),e}function se(){var e,t,n=i,r=i;return e=h(),e===null?(e=null,i=r):(t=w(),t===null?(e=null,i=r):e=[e,t]),e!==null&&(e=function(e){return`"`}(n)),e===null&&(i=n),e}function ce(){var e,t,n,r=i;if(e=I(),e!==null){for(t=[],n=le(),n===null&&(n=z(),n===null&&(n=ce()));n!==null;)t.push(n),n=le(),n===null&&(n=z(),n===null&&(n=ce()));t===null?(e=null,i=r):(n=ne(),n===null?(e=null,i=r):e=[e,t,n])}else e=null,i=r;return e}function le(){var e;return/^[!-']/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[!-']`)),e===null&&(/^[*-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[*-[]`)),e===null&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\]-~]`)),e===null&&(e=O(),e===null&&(e=C())))),e}function ue(){var e,n,r,a,o=i,s=i;if(e=w(),e!==null){if(n=h(),n!==null){for(r=[],a=fe(),a===null&&(a=z());a!==null;)r.push(a),a=fe(),a===null&&(a=z());r===null?(e=null,i=s):(a=h(),a===null?(e=null,i=s):e=[e,n,r,a])}else e=null,i=s}else e=null,i=s;return e!==null&&(e=function(e){return t.substring(i,e)}(o)),e===null&&(i=o),e}function de(){var e,n,r,a,o=i,s=i;if(e=w(),e!==null){if(n=h(),n!==null){for(r=[],a=fe(),a===null&&(a=z());a!==null;)r.push(a),a=fe(),a===null&&(a=z());r===null?(e=null,i=s):(a=h(),a===null?(e=null,i=s):e=[e,n,r,a])}else e=null,i=s}else e=null,i=s;return e!==null&&(e=function(e){var n=t.substring(i,e).trim();return n.substring(1,n.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,`$1`)}(o)),e===null&&(i=o),e}function fe(){var e=C();return e===null&&(t.charCodeAt(i)===33?(e=`!`,i++):(e=null,a===0&&c(`"!"`)),e===null&&(/^[#-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[#-[]`)),e===null&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[\\]-~]`)),e===null&&(e=O())))),e}function z(){var e,n,r=i;return t.charCodeAt(i)===92?(e=`\\`,i++):(e=null,a===0&&c(`"\\\\"`)),e===null?(e=null,i=r):(/^[\0-\t]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\0-\\t]`)),n===null&&(/^[\x0B-\f]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\x0B-\\f]`)),n===null&&(/^[\x0E-]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[\\x0E-]`)))),n===null?(e=null,i=r):e=[e,n]),e}function B(){var e,n,r,o,s=i,l=i;return e=me(),e===null?(e=null,i=l):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=l):(r=_e(),r=r===null?``:r,r===null?(e=null,i=l):(o=xe(),o===null?(e=null,i=l):e=[e,n,r,o]))),e!==null&&(e=function(e){try{$.uri=new Tr($.scheme,$.user,$.host,$.port),delete $.scheme,delete $.user,delete $.host,delete $.host_type,delete $.port}catch{$=-1}}(s)),e===null&&(i=s),e}function pe(){var e,r,o,s,l,u,d=i,f=i;return e=me(),e===null?(e=null,i=f):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=f):(o=_e(),o=o===null?``:o,o===null?(e=null,i=f):(s=xe(),s===null?(e=null,i=f):(l=je(),l===null?(e=null,i=f):(u=Ue(),u=u===null?``:u,u===null?(e=null,i=f):e=[e,r,o,s,l,u]))))),e!==null&&(e=function(e){try{$.uri=new Tr($.scheme,$.user,$.host,$.port,$.uri_params,$.uri_headers),delete $.scheme,delete $.user,delete $.host,delete $.host_type,delete $.port,delete $.uri_params,n===`SIP_URI`&&($=$.uri)}catch{$=-1}}(d)),e===null&&(i=d),e}function me(){var e=he();return e===null&&(e=ge()),e}function he(){var e,n=i;return t.substr(i,4).toLowerCase()===`sips`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"sips"`)),e!==null&&(e=function(e,t){$.scheme=t.toLowerCase()}(n,e)),e===null&&(i=n),e}function ge(){var e,n=i;return t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"sip"`)),e!==null&&(e=function(e,t){$.scheme=t.toLowerCase()}(n,e)),e===null&&(i=n),e}function _e(){var e,n,r,o=i,s=i,l;return e=ve(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=l):(r=be(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):(t.charCodeAt(i)===64?(r=`@`,i++):(r=null,a===0&&c(`"@"`)),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){$.user=decodeURIComponent(t.substring(i-1,e))}(o)),e===null&&(i=o),e}function ve(){var e,t=b();if(t===null&&(t=S(),t===null&&(t=ye())),t!==null)for(e=[];t!==null;)e.push(t),t=b(),t===null&&(t=S(),t===null&&(t=ye()));else e=null;return e}function ye(){var e;return t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`))))))))),e}function be(){var e,n,r=i;for(e=[],n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`))))))));n!==null;)e.push(n),n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`))))))));return e!==null&&(e=function(e){$.password=t.substring(i,e)}(r)),e===null&&(i=r),e}function xe(){var e,n,r,o=i,s;return e=Se(),e===null?(e=null,i=o):(s=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=s):(r=Ae(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function Se(){var e,n=i;return e=Ce(),e===null&&(e=Oe(),e===null&&(e=Ee())),e!==null&&(e=function(e){return $.host=t.substring(i,e).toLowerCase(),$.host}(n)),e===null&&(i=n),e}function Ce(){var e,n,r,o=i,s=i,l;for(e=[],l=i,n=we(),n===null?(n=null,i=l):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(n=null,i=l):n=[n,r]);n!==null;)e.push(n),l=i,n=we(),n===null?(n=null,i=l):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(n=null,i=l):n=[n,r]);return e===null?(e=null,i=s):(n=Te(),n===null?(e=null,i=s):(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r=r===null?``:r,r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return $.host_type=`domain`,t.substring(i,e)}(o)),e===null&&(i=o),e}function we(){var e,n,r,o=i;if(e=v(),e!==null){for(n=[],r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));r!==null;)n.push(r),r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));n===null?(e=null,i=o):e=[e,n]}else e=null,i=o;return e}function Te(){var e,n,r,o=i;if(e=d(),e!==null){for(n=[],r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));r!==null;)n.push(r),r=v(),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===95?(r=`_`,i++):(r=null,a===0&&c(`"_"`))));n===null?(e=null,i=o):e=[e,n]}else e=null,i=o;return e}function Ee(){var e,n,r,o=i,s=i;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null?(e=null,i=s):(n=De(),n===null?(e=null,i=s):(t.charCodeAt(i)===93?(r=`]`,i++):(r=null,a===0&&c(`"]"`)),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e){return $.host_type=`IPv6`,t.substring(i,e)}(o)),e===null&&(i=o),e}function De(){var e,n,r,o,s,l,u,d,f,p,m,h,g,_=i,v=i,y;return e=V(),e===null?(e=null,i=v):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=v):(r=V(),r===null?(e=null,i=v):(t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=V(),f===null?(e=null,i=v):(t.charCodeAt(i)===58?(p=`:`,i++):(p=null,a===0&&c(`":"`)),p===null?(e=null,i=v):(m=V(),m===null?(e=null,i=v):(t.charCodeAt(i)===58?(h=`:`,i++):(h=null,a===0&&c(`":"`)),h===null?(e=null,i=v):(g=H(),g===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m,h,g])))))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=V(),p===null?(e=null,i=v):(t.charCodeAt(i)===58?(m=`:`,i++):(m=null,a===0&&c(`":"`)),m===null?(e=null,i=v):(h=H(),h===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m,h]))))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=H(),p===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p]))))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=H(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=H(),l===null?(e=null,i=v):e=[e,n,r,o,s,l]))))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):(t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(e=null,i=v):(o=H(),o===null?(e=null,i=v):e=[e,n,r,o]))),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=H(),n===null?(e=null,i=v):e=[e,n]),e===null&&(v=i,t.substr(i,2)===`::`?(e=`::`,i+=2):(e=null,a===0&&c(`"::"`)),e===null?(e=null,i=v):(n=V(),n===null?(e=null,i=v):e=[e,n]),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(t.substr(i,2)===`::`?(n=`::`,i+=2):(n=null,a===0&&c(`"::"`)),n===null?(e=null,i=v):(r=V(),r===null?(e=null,i=v):(t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=V(),f===null?(e=null,i=v):(t.charCodeAt(i)===58?(p=`:`,i++):(p=null,a===0&&c(`":"`)),p===null?(e=null,i=v):(m=H(),m===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p,m])))))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(t.substr(i,2)===`::`?(r=`::`,i+=2):(r=null,a===0&&c(`"::"`)),r===null?(e=null,i=v):(o=V(),o===null?(e=null,i=v):(t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):(t.charCodeAt(i)===58?(f=`:`,i++):(f=null,a===0&&c(`":"`)),f===null?(e=null,i=v):(p=H(),p===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f,p]))))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(t.substr(i,2)===`::`?(o=`::`,i+=2):(o=null,a===0&&c(`"::"`)),o===null?(e=null,i=v):(s=V(),s===null?(e=null,i=v):(t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(e=null,i=v):(u=V(),u===null?(e=null,i=v):(t.charCodeAt(i)===58?(d=`:`,i++):(d=null,a===0&&c(`":"`)),d===null?(e=null,i=v):(f=H(),f===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d,f])))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(t.substr(i,2)===`::`?(s=`::`,i+=2):(s=null,a===0&&c(`"::"`)),s===null?(e=null,i=v):(l=V(),l===null?(e=null,i=v):(t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(e=null,i=v):(d=H(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(t.substr(i,2)===`::`?(l=`::`,i+=2):(l=null,a===0&&c(`"::"`)),l===null?(e=null,i=v):(u=H(),u===null?(e=null,i=v):e=[e,n,r,o,s,l,u])))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(l=null,i=y):(u=V(),u===null?(l=null,i=y):l=[l,u]),l=l===null?``:l,l===null?(e=null,i=v):(t.substr(i,2)===`::`?(u=`::`,i+=2):(u=null,a===0&&c(`"::"`)),u===null?(e=null,i=v):(d=V(),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))),e===null&&(v=i,e=V(),e===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(n=null,i=y):(r=V(),r===null?(n=null,i=y):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(r=`:`,i++):(r=null,a===0&&c(`":"`)),r===null?(r=null,i=y):(o=V(),o===null?(r=null,i=y):r=[r,o]),r=r===null?``:r,r===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(o=`:`,i++):(o=null,a===0&&c(`":"`)),o===null?(o=null,i=y):(s=V(),s===null?(o=null,i=y):o=[o,s]),o=o===null?``:o,o===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(s=`:`,i++):(s=null,a===0&&c(`":"`)),s===null?(s=null,i=y):(l=V(),l===null?(s=null,i=y):s=[s,l]),s=s===null?``:s,s===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(l=`:`,i++):(l=null,a===0&&c(`":"`)),l===null?(l=null,i=y):(u=V(),u===null?(l=null,i=y):l=[l,u]),l=l===null?``:l,l===null?(e=null,i=v):(y=i,t.charCodeAt(i)===58?(u=`:`,i++):(u=null,a===0&&c(`":"`)),u===null?(u=null,i=y):(d=V(),d===null?(u=null,i=y):u=[u,d]),u=u===null?``:u,u===null?(e=null,i=v):(t.substr(i,2)===`::`?(d=`::`,i+=2):(d=null,a===0&&c(`"::"`)),d===null?(e=null,i=v):e=[e,n,r,o,s,l,u,d]))))))))))))))))))))),e!==null&&(e=function(e){return $.host_type=`IPv6`,t.substring(i,e)}(_)),e===null&&(i=_),e}function V(){var e,t,n,r,a=i;return e=f(),e===null?(e=null,i=a):(t=f(),t=t===null?``:t,t===null?(e=null,i=a):(n=f(),n=n===null?``:n,n===null?(e=null,i=a):(r=f(),r=r===null?``:r,r===null?(e=null,i=a):e=[e,t,n,r]))),e}function H(){var e,n,r,o=i;return e=V(),e===null?(e=null,i=o):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=o):(r=V(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(e=Oe()),e}function Oe(){var e,n,r,o,s,l,u,d=i,f=i;return e=ke(),e===null?(e=null,i=f):(t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null?(e=null,i=f):(r=ke(),r===null?(e=null,i=f):(t.charCodeAt(i)===46?(o=`.`,i++):(o=null,a===0&&c(`"."`)),o===null?(e=null,i=f):(s=ke(),s===null?(e=null,i=f):(t.charCodeAt(i)===46?(l=`.`,i++):(l=null,a===0&&c(`"."`)),l===null?(e=null,i=f):(u=ke(),u===null?(e=null,i=f):e=[e,n,r,o,s,l,u])))))),e!==null&&(e=function(e){return $.host_type=`IPv4`,t.substring(i,e)}(d)),e===null&&(i=d),e}function ke(){var e,n,r,o=i;return t.substr(i,2)===`25`?(e=`25`,i+=2):(e=null,a===0&&c(`"25"`)),e===null?(e=null,i=o):(/^[0-5]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[0-5]`)),n===null?(e=null,i=o):e=[e,n]),e===null&&(o=i,t.charCodeAt(i)===50?(e=`2`,i++):(e=null,a===0&&c(`"2"`)),e===null?(e=null,i=o):(/^[0-4]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,a===0&&c(`[0-4]`)),n===null?(e=null,i=o):(r=u(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(o=i,t.charCodeAt(i)===49?(e=`1`,i++):(e=null,a===0&&c(`"1"`)),e===null?(e=null,i=o):(n=u(),n===null?(e=null,i=o):(r=u(),r===null?(e=null,i=o):e=[e,n,r])),e===null&&(o=i,/^[1-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,a===0&&c(`[1-9]`)),e===null?(e=null,i=o):(n=u(),n===null?(e=null,i=o):e=[e,n]),e===null&&(e=u())))),e}function Ae(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){return t=parseInt(t.join(``)),$.port=t,t}(o,e)),e===null&&(i=o),e}function je(){var e=[],n,r,o=i;for(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(n=null,i=o):(r=Me(),r===null?(n=null,i=o):n=[n,r]);n!==null;)e.push(n),o=i,t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null?(n=null,i=o):(r=Me(),r===null?(n=null,i=o):n=[n,r]);return e}function Me(){var e=Ne();return e===null&&(e=Pe(),e===null&&(e=Fe(),e===null&&(e=Ie(),e===null&&(e=U(),e===null&&(e=Le(),e===null&&(e=Re())))))),e}function Ne(){var e,n,r=i,o=i;return t.substr(i,10).toLowerCase()===`transport=`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"transport="`)),e===null?(e=null,i=o):(t.substr(i,3).toLowerCase()===`udp`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"udp"`)),n===null&&(t.substr(i,3).toLowerCase()===`tcp`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"tcp"`)),n===null&&(t.substr(i,4).toLowerCase()===`sctp`?(n=t.substr(i,4),i+=4):(n=null,a===0&&c(`"sctp"`)),n===null&&(t.substr(i,3).toLowerCase()===`tls`?(n=t.substr(i,3),i+=3):(n=null,a===0&&c(`"tls"`)),n===null&&(n=j())))),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.transport=t.toLowerCase()}(r,e[1])),e===null&&(i=r),e}function Pe(){var e,n,r=i,o=i;return t.substr(i,5).toLowerCase()===`user=`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"user="`)),e===null?(e=null,i=o):(t.substr(i,5).toLowerCase()===`phone`?(n=t.substr(i,5),i+=5):(n=null,a===0&&c(`"phone"`)),n===null&&(t.substr(i,2).toLowerCase()===`ip`?(n=t.substr(i,2),i+=2):(n=null,a===0&&c(`"ip"`)),n===null&&(n=j())),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.user=t.toLowerCase()}(r,e[1])),e===null&&(i=r),e}function Fe(){var e,n,r=i,o=i;return t.substr(i,7).toLowerCase()===`method=`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"method="`)),e===null?(e=null,i=o):(n=W(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.method=t}(r,e[1])),e===null&&(i=r),e}function Ie(){var e,n,r=i,o=i;return t.substr(i,4).toLowerCase()===`ttl=`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"ttl="`)),e===null?(e=null,i=o):(n=nr(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.ttl=t}(r,e[1])),e===null&&(i=r),e}function U(){var e,n,r=i,o=i;return t.substr(i,6).toLowerCase()===`maddr=`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"maddr="`)),e===null?(e=null,i=o):(n=Se(),n===null?(e=null,i=o):e=[e,n]),e!==null&&(e=function(e,t){$.uri_params||($.uri_params={}),$.uri_params.maddr=t}(r,e[1])),e===null&&(i=r),e}function Le(){var e,n,r,o=i,s=i,l;return t.substr(i,2).toLowerCase()===`lr`?(e=t.substr(i,2),i+=2):(e=null,a===0&&c(`"lr"`)),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(n=null,i=l):(r=j(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$.uri_params||($.uri_params={}),$.uri_params.lr=void 0}(o)),e===null&&(i=o),e}function Re(){var e,n,r,o=i,s=i,l;return e=ze(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(n=null,i=l):(r=Be(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e,t,n){$.uri_params||($.uri_params={}),n=n===void 0?void 0:n[1],$.uri_params[t.toLowerCase()]=n}(o,e[0],e[1])),e===null&&(i=o),e}function ze(){var e,t,n=i;if(t=Ve(),t!==null)for(e=[];t!==null;)e.push(t),t=Ve();else e=null;return e!==null&&(e=function(e,t){return t.join(``)}(n,e)),e===null&&(i=n),e}function Be(){var e,t,n=i;if(t=Ve(),t!==null)for(e=[];t!==null;)e.push(t),t=Ve();else e=null;return e!==null&&(e=function(e,t){return t.join(``)}(n,e)),e===null&&(i=n),e}function Ve(){var e=He();return e===null&&(e=b(),e===null&&(e=S())),e}function He(){var e;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)))))))),e}function Ue(){var e,n,r,o,s,l=i,u;if(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e!==null){if(n=We(),n!==null){for(r=[],u=i,t.charCodeAt(i)===38?(o=`&`,i++):(o=null,a===0&&c(`"&"`)),o===null?(o=null,i=u):(s=We(),s===null?(o=null,i=u):o=[o,s]);o!==null;)r.push(o),u=i,t.charCodeAt(i)===38?(o=`&`,i++):(o=null,a===0&&c(`"&"`)),o===null?(o=null,i=u):(s=We(),s===null?(o=null,i=u):o=[o,s]);r===null?(e=null,i=l):e=[e,n,r]}else e=null,i=l}else e=null,i=l;return e}function We(){var e,n,r,o=i,s=i;return e=Ge(),e===null?(e=null,i=s):(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null?(e=null,i=s):(r=Ke(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t,n){t=t.join(``).toLowerCase(),n=n.join(``),$.uri_headers||($.uri_headers={}),$.uri_headers[t]?$.uri_headers[t].push(n):$.uri_headers[t]=[n]}(o,e[0],e[2])),e===null&&(i=o),e}function Ge(){var e,t=qe();if(t===null&&(t=b(),t===null&&(t=S())),t!==null)for(e=[];t!==null;)e.push(t),t=qe(),t===null&&(t=b(),t===null&&(t=S()));else e=null;return e}function Ke(){var e=[],t=qe();for(t===null&&(t=b(),t===null&&(t=S()));t!==null;)e.push(t),t=qe(),t===null&&(t=b(),t===null&&(t=S()));return e}function qe(){var e;return t.charCodeAt(i)===91?(e=`[`,i++):(e=null,a===0&&c(`"["`)),e===null&&(t.charCodeAt(i)===93?(e=`]`,i++):(e=null,a===0&&c(`"]"`)),e===null&&(t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)))))))),e}function Je(){var e=G();return e===null&&(e=Ye()),e}function Ye(){var e,t,n,r,a,o=i;return e=W(),e===null?(e=null,i=o):(t=g(),t===null?(e=null,i=o):(n=Xe(),n===null?(e=null,i=o):(r=g(),r===null?(e=null,i=o):(a=pt(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function Xe(){var e=pe();return e===null&&(e=Ze()),e}function Ze(){var e,n,r,o=i;return e=ct(),e===null?(e=null,i=o):(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null?(e=null,i=o):(r=Qe(),r===null&&(r=tt()),r===null?(e=null,i=o):e=[e,n,r])),e}function Qe(){var e,n,r,o=i,s;return e=$e(),e===null&&(e=et()),e===null?(e=null,i=o):(s=i,t.charCodeAt(i)===63?(n=`?`,i++):(n=null,a===0&&c(`"?"`)),n===null?(n=null,i=s):(r=ft(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function $e(){var e,n,r,o=i;return t.substr(i,2)===`//`?(e=`//`,i+=2):(e=null,a===0&&c(`"//"`)),e===null?(e=null,i=o):(n=lt(),n===null?(e=null,i=o):(r=et(),r=r===null?``:r,r===null?(e=null,i=o):e=[e,n,r])),e}function et(){var e,n,r=i;return t.charCodeAt(i)===47?(e=`/`,i++):(e=null,a===0&&c(`"/"`)),e===null?(e=null,i=r):(n=it(),n===null?(e=null,i=r):e=[e,n]),e}function tt(){var e,t,n,r=i;if(e=rt(),e!==null){for(t=[],n=nt();n!==null;)t.push(n),n=nt();t===null?(e=null,i=r):e=[e,t]}else e=null,i=r;return e}function nt(){var e=y();return e===null&&(e=b(),e===null&&(e=S())),e}function rt(){var e=b();return e===null&&(e=S(),e===null&&(t.charCodeAt(i)===59?(e=`;`,i++):(e=null,a===0&&c(`";"`)),e===null&&(t.charCodeAt(i)===63?(e=`?`,i++):(e=null,a===0&&c(`"?"`)),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)))))))))))),e}function it(){var e,n,r,o,s=i,l;if(e=at(),e!==null){for(n=[],l=i,t.charCodeAt(i)===47?(r=`/`,i++):(r=null,a===0&&c(`"/"`)),r===null?(r=null,i=l):(o=at(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===47?(r=`/`,i++):(r=null,a===0&&c(`"/"`)),r===null?(r=null,i=l):(o=at(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function at(){var e,n,r,o,s=i,l;for(e=[],n=st();n!==null;)e.push(n),n=st();if(e!==null){for(n=[],l=i,t.charCodeAt(i)===59?(r=`;`,i++):(r=null,a===0&&c(`";"`)),r===null?(r=null,i=l):(o=ot(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===59?(r=`;`,i++):(r=null,a===0&&c(`";"`)),r===null?(r=null,i=l):(o=ot(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function ot(){for(var e=[],t=st();t!==null;)e.push(t),t=st();return e}function st(){var e=b();return e===null&&(e=S(),e===null&&(t.charCodeAt(i)===58?(e=`:`,i++):(e=null,a===0&&c(`":"`)),e===null&&(t.charCodeAt(i)===64?(e=`@`,i++):(e=null,a===0&&c(`"@"`)),e===null&&(t.charCodeAt(i)===38?(e=`&`,i++):(e=null,a===0&&c(`"&"`)),e===null&&(t.charCodeAt(i)===61?(e=`=`,i++):(e=null,a===0&&c(`"="`)),e===null&&(t.charCodeAt(i)===43?(e=`+`,i++):(e=null,a===0&&c(`"+"`)),e===null&&(t.charCodeAt(i)===36?(e=`$`,i++):(e=null,a===0&&c(`"$"`)),e===null&&(t.charCodeAt(i)===44?(e=`,`,i++):(e=null,a===0&&c(`","`)))))))))),e}function ct(){var e,n,r,o=i,s=i;if(e=d(),e!==null){for(n=[],r=d(),r===null&&(r=u(),r===null&&(t.charCodeAt(i)===43?(r=`+`,i++):(r=null,a===0&&c(`"+"`)),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`))))));r!==null;)n.push(r),r=d(),r===null&&(r=u(),r===null&&(t.charCodeAt(i)===43?(r=`+`,i++):(r=null,a===0&&c(`"+"`)),r===null&&(t.charCodeAt(i)===45?(r=`-`,i++):(r=null,a===0&&c(`"-"`)),r===null&&(t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`))))));n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e!==null&&(e=function(e){$.scheme=t.substring(i,e)}(o)),e===null&&(i=o),e}function lt(){var e=ut();return e===null&&(e=dt()),e}function ut(){var e,n,r=i,o=i;return e=_e(),e===null?(e=null,i=o):(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(e=null,i=o):e=[e,n]),e=e===null?``:e,e===null?(e=null,i=r):(n=xe(),n===null?(e=null,i=r):e=[e,n]),e=e===null?``:e,e}function dt(){var e,n=b();if(n===null&&(n=S(),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null&&(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`))))))))))),n!==null)for(e=[];n!==null;)e.push(n),n=b(),n===null&&(n=S(),n===null&&(t.charCodeAt(i)===36?(n=`$`,i++):(n=null,a===0&&c(`"$"`)),n===null&&(t.charCodeAt(i)===44?(n=`,`,i++):(n=null,a===0&&c(`","`)),n===null&&(t.charCodeAt(i)===59?(n=`;`,i++):(n=null,a===0&&c(`";"`)),n===null&&(t.charCodeAt(i)===58?(n=`:`,i++):(n=null,a===0&&c(`":"`)),n===null&&(t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null&&(t.charCodeAt(i)===38?(n=`&`,i++):(n=null,a===0&&c(`"&"`)),n===null&&(t.charCodeAt(i)===61?(n=`=`,i++):(n=null,a===0&&c(`"="`)),n===null&&(t.charCodeAt(i)===43?(n=`+`,i++):(n=null,a===0&&c(`"+"`)))))))))));else e=null;return e}function ft(){for(var e=[],t=nt();t!==null;)e.push(t),t=nt();return e}function pt(){var e,n,r,o,s,l,d=i,f=i;if(t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e!==null){if(t.charCodeAt(i)===47?(n=`/`,i++):(n=null,a===0&&c(`"/"`)),n!==null){if(o=u(),o!==null)for(r=[];o!==null;)r.push(o),o=u();else r=null;if(r!==null){if(t.charCodeAt(i)===46?(o=`.`,i++):(o=null,a===0&&c(`"."`)),o!==null){if(l=u(),l!==null)for(s=[];l!==null;)s.push(l),l=u();else s=null;s===null?(e=null,i=f):e=[e,n,r,o,s]}else e=null,i=f}else e=null,i=f}else e=null,i=f}else e=null,i=f;return e!==null&&(e=function(e){$.sip_version=t.substring(i,e)}(d)),e===null&&(i=d),e}function mt(){var e;return t.substr(i,6)===`INVITE`?(e=`INVITE`,i+=6):(e=null,a===0&&c(`"INVITE"`)),e}function ht(){var e;return t.substr(i,3)===`ACK`?(e=`ACK`,i+=3):(e=null,a===0&&c(`"ACK"`)),e}function gt(){var e;return t.substr(i,7)===`OPTIONS`?(e=`OPTIONS`,i+=7):(e=null,a===0&&c(`"OPTIONS"`)),e}function _t(){var e;return t.substr(i,3)===`BYE`?(e=`BYE`,i+=3):(e=null,a===0&&c(`"BYE"`)),e}function vt(){var e;return t.substr(i,6)===`CANCEL`?(e=`CANCEL`,i+=6):(e=null,a===0&&c(`"CANCEL"`)),e}function yt(){var e;return t.substr(i,8)===`REGISTER`?(e=`REGISTER`,i+=8):(e=null,a===0&&c(`"REGISTER"`)),e}function bt(){var e;return t.substr(i,9)===`SUBSCRIBE`?(e=`SUBSCRIBE`,i+=9):(e=null,a===0&&c(`"SUBSCRIBE"`)),e}function xt(){var e;return t.substr(i,6)===`NOTIFY`?(e=`NOTIFY`,i+=6):(e=null,a===0&&c(`"NOTIFY"`)),e}function St(){var e;return t.substr(i,5)===`REFER`?(e=`REFER`,i+=5):(e=null,a===0&&c(`"REFER"`)),e}function W(){var e,n=i;return e=mt(),e===null&&(e=ht(),e===null&&(e=gt(),e===null&&(e=_t(),e===null&&(e=vt(),e===null&&(e=yt(),e===null&&(e=bt(),e===null&&(e=xt(),e===null&&(e=St(),e===null&&(e=j()))))))))),e!==null&&(e=function(e){return $.method=t.substring(i,e),$.method}(n)),e===null&&(i=n),e}function G(){var e,t,n,r,a,o=i;return e=pt(),e===null?(e=null,i=o):(t=g(),t===null?(e=null,i=o):(n=K(),n===null?(e=null,i=o):(r=g(),r===null?(e=null,i=o):(a=J(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function K(){var e,t=i;return e=q(),e!==null&&(e=function(e,t){$.status_code=parseInt(t.join(``))}(t,e)),e===null&&(i=t),e}function q(){var e,t,n,r=i;return e=u(),e===null?(e=null,i=r):(t=u(),t===null?(e=null,i=r):(n=u(),n===null?(e=null,i=r):e=[e,t,n])),e}function J(){var e,n,r=i;for(e=[],n=y(),n===null&&(n=b(),n===null&&(n=S(),n===null&&(n=O(),n===null&&(n=k(),n===null&&(n=g(),n===null&&(n=_()))))));n!==null;)e.push(n),n=y(),n===null&&(n=b(),n===null&&(n=S(),n===null&&(n=O(),n===null&&(n=k(),n===null&&(n=g(),n===null&&(n=_()))))));return e!==null&&(e=function(e){$.reason_phrase=t.substring(i,e)}(r)),e===null&&(i=r),e}function Tt(){var e,t,n,r,a=i,o;if(e=en(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=en(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=en(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Et(){var e,n,r,o=i,s=i,l;return e=P(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(n=null,i=l):(r=P(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$=t.substring(i,e)}(o)),e===null&&(i=o),e}function Dt(){var e,t,n,r,a=i,o,s;if(e=ee(),e===null){if(o=i,e=Y(),e!==null){for(t=[],s=i,n=L(),n===null?(n=null,i=s):(r=Y(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=L(),n===null?(n=null,i=s):(r=Y(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o}return e!==null&&(e=function(e){var t,n=$.multi_header.length;for(t=0;t<n;t++)if($.multi_header[t].parsed===null){$=null;break}$=$===null?-1:$.multi_header}(a)),e===null&&(i=a),e}function Y(){var e,t,n,r,a=i,o=i,s;if(e=B(),e===null&&(e=X()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=kt(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=kt(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t;$.multi_header||($.multi_header=[]);try{t=new Er($.uri,$.display_name,$.params),delete $.uri,delete $.display_name,delete $.params}catch{t=null}$.multi_header.push({possition:i,offset:e,parsed:t})}(a)),e===null&&(i=a),e}function X(){var e,t,n,r,a=i;return e=Ot(),e=e===null?``:e,e===null?(e=null,i=a):(t=ie(),t===null?(e=null,i=a):(n=pe(),n===null?(e=null,i=a):(r=re(),r===null?(e=null,i=a):e=[e,t,n,r]))),e}function Ot(){var e,t,n,r,a=i,o=i,s;if(e=j(),e!==null){for(t=[],s=i,n=C(),n===null?(n=null,i=s):(r=j(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=C(),n===null?(n=null,i=s):(r=j(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e===null&&(e=de()),e!==null&&(e=function(e,t){typeof t==`string`?$.display_name=t:$.display_name=t[1].reduce(function(e,t){return e+t[0]+t[1]},t[0])}(a,e)),e===null&&(i=a),e}function kt(){var e=At();return e===null&&(e=Z(),e===null&&(e=Q())),e}function At(){var e,n,r,o=i,s=i;return t.substr(i,1).toLowerCase()===`q`?(e=t.substr(i,1),i++):(e=null,a===0&&c(`"q"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=Mt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.q=t}(o,e[2])),e===null&&(i=o),e}function Z(){var e,n,r,o=i,s=i;return t.substr(i,7).toLowerCase()===`expires`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"expires"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=jt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.params||($.params={}),$.params.expires=t}(o,e[2])),e===null&&(i=o),e}function jt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){return parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Mt(){var e,n,r,o,s,l=i,d=i,f;return t.charCodeAt(i)===48?(e=`0`,i++):(e=null,a===0&&c(`"0"`)),e===null?(e=null,i=d):(f=i,t.charCodeAt(i)===46?(n=`.`,i++):(n=null,a===0&&c(`"."`)),n===null?(n=null,i=f):(r=u(),r=r===null?``:r,r===null?(n=null,i=f):(o=u(),o=o===null?``:o,o===null?(n=null,i=f):(s=u(),s=s===null?``:s,s===null?(n=null,i=f):n=[n,r,o,s]))),n=n===null?``:n,n===null?(e=null,i=d):e=[e,n]),e!==null&&(e=function(e){return parseFloat(t.substring(i,e))}(l)),e===null&&(i=l),e}function Q(){var e,t,n,r=i,a=i,o;return e=j(),e===null?(e=null,i=a):(o=i,t=F(),t===null?(t=null,i=o):(n=Nt(),n===null?(t=null,i=o):t=[t,n]),t=t===null?``:t,t===null?(e=null,i=a):e=[e,t]),e!==null&&(e=function(e,t,n){$.params||($.params={}),n=n===void 0?void 0:n[1],$.params[t.toLowerCase()]=n}(r,e[0],e[1])),e===null&&(i=r),e}function Nt(){var e=j();return e===null&&(e=Se(),e===null&&(e=ue())),e}function Pt(){var e,t,n,r,a=i,o;if(e=Ft(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=It(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=It(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Ft(){var e;return t.substr(i,6).toLowerCase()===`render`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"render"`)),e===null&&(t.substr(i,7).toLowerCase()===`session`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"session"`)),e===null&&(t.substr(i,4).toLowerCase()===`icon`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"icon"`)),e===null&&(t.substr(i,5).toLowerCase()===`alert`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"alert"`)),e===null&&(e=j())))),e}function It(){var e=Lt();return e===null&&(e=Q()),e}function Lt(){var e,n,r,o=i;return t.substr(i,8).toLowerCase()===`handling`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"handling"`)),e===null?(e=null,i=o):(n=F(),n===null?(e=null,i=o):(t.substr(i,8).toLowerCase()===`optional`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"optional"`)),r===null&&(t.substr(i,8).toLowerCase()===`required`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"required"`)),r===null&&(r=j())),r===null?(e=null,i=o):e=[e,n,r])),e}function Rt(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function zt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Bt(){var e,n=i;return e=Vt(),e!==null&&(e=function(e){$=t.substring(i,e)}(n)),e===null&&(i=n),e}function Vt(){var e,t,n,r,a,o,s=i,c;if(e=Ht(),e!==null){if(t=te(),t!==null){if(n=qt(),n!==null){for(r=[],c=i,a=R(),a===null?(a=null,i=c):(o=Jt(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=R(),a===null?(a=null,i=c):(o=Jt(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function Ht(){var e=Ut();return e===null&&(e=Wt()),e}function Ut(){var e;return t.substr(i,4).toLowerCase()===`text`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"text"`)),e===null&&(t.substr(i,5).toLowerCase()===`image`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"image"`)),e===null&&(t.substr(i,5).toLowerCase()===`audio`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"audio"`)),e===null&&(t.substr(i,5).toLowerCase()===`video`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"video"`)),e===null&&(t.substr(i,11).toLowerCase()===`application`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"application"`)),e===null&&(e=Gt()))))),e}function Wt(){var e;return t.substr(i,7).toLowerCase()===`message`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"message"`)),e===null&&(t.substr(i,9).toLowerCase()===`multipart`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"multipart"`)),e===null&&(e=Gt())),e}function Gt(){var e=j();return e===null&&(e=Kt()),e}function Kt(){var e,n,r=i;return t.substr(i,2).toLowerCase()===`x-`?(e=t.substr(i,2),i+=2):(e=null,a===0&&c(`"x-"`)),e===null?(e=null,i=r):(n=j(),n===null?(e=null,i=r):e=[e,n]),e}function qt(){var e=Gt();return e===null&&(e=j()),e}function Jt(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=F(),t===null?(e=null,i=r):(n=Yt(),n===null?(e=null,i=r):e=[e,t,n])),e}function Yt(){var e=j();return e===null&&(e=ue()),e}function Xt(){var e,t,n,r=i;return e=Zt(),e===null?(e=null,i=r):(t=C(),t===null?(e=null,i=r):(n=W(),n===null?(e=null,i=r):e=[e,t,n])),e}function Zt(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$.value=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function Qt(){var e,t=i;return e=jt(),e!==null&&(e=function(e,t){$=t}(t,e)),e===null&&(i=t),e}function $t(){var e,t,n,r,a=i,o=i,s;if(e=en(),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e,t){$.event=t.join(``).toLowerCase()}(a,e[0])),e===null&&(i=a),e}function en(){var e,n,r,o,s=i,l;if(e=M(),e!==null){for(n=[],l=i,t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(r=null,i=l):(o=M(),o===null?(r=null,i=l):r=[r,o]);r!==null;)n.push(r),l=i,t.charCodeAt(i)===46?(r=`.`,i++):(r=null,a===0&&c(`"."`)),r===null?(r=null,i=l):(o=M(),o===null?(r=null,i=l):r=[r,o]);n===null?(e=null,i=s):e=[e,n]}else e=null,i=s;return e}function tn(){var e,t,n,r,a=i,o=i,s;if(e=B(),e===null&&(e=X()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=nn(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=nn(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t=$.tag;try{$=new Er($.uri,$.display_name,$.params),t&&$.setParam(`tag`,t)}catch{$=-1}}(a)),e===null&&(i=a),e}function nn(){var e=rn();return e===null&&(e=Q()),e}function rn(){var e,n,r,o=i,s=i;return t.substr(i,3).toLowerCase()===`tag`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"tag"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.tag=t}(o,e[2])),e===null&&(i=o),e}function an(){var e,t,n=i;if(t=u(),t!==null)for(e=[];t!==null;)e.push(t),t=u();else e=null;return e!==null&&(e=function(e,t){$=parseInt(t.join(``))}(n,e)),e===null&&(i=n),e}function on(){var e,t=i;return e=jt(),e!==null&&(e=function(e,t){$=t}(t,e)),e===null&&(i=t),e}function sn(){var e,t,n,r,a,o,s,c=i,l=i,u;for(e=[],t=Ot();t!==null;)e.push(t),t=Ot();if(e!==null){if(t=ie(),t!==null){if(n=pe(),n!==null){if(r=re(),r!==null){for(a=[],u=i,o=R(),o===null?(o=null,i=u):(s=Q(),s===null?(o=null,i=u):o=[o,s]);o!==null;)a.push(o),u=i,o=R(),o===null?(o=null,i=u):(s=Q(),s===null?(o=null,i=u):o=[o,s]);a===null?(e=null,i=l):e=[e,t,n,r,a]}else e=null,i=l}else e=null,i=l}else e=null,i=l}else e=null,i=l;return e!==null&&(e=function(e){try{$=new Er($.uri,$.display_name,$.params)}catch{$=-1}}(c)),e===null&&(i=c),e}function cn(){return ln()}function ln(){var e,n,r,o,s,l,u=i,d;if(t.substr(i,6).toLowerCase()===`digest`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"Digest"`)),e!==null){if(n=C(),n!==null){if(r=fn(),r!==null){for(o=[],d=i,s=L(),s===null?(s=null,i=d):(l=fn(),l===null?(s=null,i=d):s=[s,l]);s!==null;)o.push(s),d=i,s=L(),s===null?(s=null,i=d):(l=fn(),l===null?(s=null,i=d):s=[s,l]);o===null?(e=null,i=u):e=[e,n,r,o]}else e=null,i=u}else e=null,i=u}else e=null,i=u;return e===null&&(e=un()),e}function un(){var e,t,n,r,a,o,s=i,c;if(e=j(),e!==null){if(t=C(),t!==null){if(n=dn(),n!==null){for(r=[],c=i,a=L(),a===null?(a=null,i=c):(o=dn(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=L(),a===null?(a=null,i=c):(o=dn(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function dn(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=F(),t===null?(e=null,i=r):(n=j(),n===null&&(n=ue()),n===null?(e=null,i=r):e=[e,t,n])),e}function fn(){var e=pn();return e===null&&(e=hn(),e===null&&(e=_n(),e===null&&(e=yn(),e===null&&(e=bn(),e===null&&(e=xn(),e===null&&(e=Sn(),e===null&&(e=dn()))))))),e}function pn(){var e,n,r,o=i;return t.substr(i,5).toLowerCase()===`realm`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"realm"`)),e===null?(e=null,i=o):(n=F(),n===null?(e=null,i=o):(r=mn(),r===null?(e=null,i=o):e=[e,n,r])),e}function mn(){var e,t=i;return e=de(),e!==null&&(e=function(e,t){$.realm=t}(t,e)),e===null&&(i=t),e}function hn(){var e,n,r,o,s,l,u,d=i,f;if(t.substr(i,6).toLowerCase()===`domain`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"domain"`)),e!==null){if(n=F(),n!==null){if(r=oe(),r!==null){if(o=gn(),o!==null){if(s=[],f=i,u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;for(l===null?(l=null,i=f):(u=gn(),u===null?(l=null,i=f):l=[l,u]);l!==null;){if(s.push(l),f=i,u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l===null?(l=null,i=f):(u=gn(),u===null?(l=null,i=f):l=[l,u])}s===null?(e=null,i=d):(l=se(),l===null?(e=null,i=d):e=[e,n,r,o,s,l])}else e=null,i=d}else e=null,i=d}else e=null,i=d}else e=null,i=d;return e}function gn(){var e=Ze();return e===null&&(e=et()),e}function _n(){var e,n,r,o=i;return t.substr(i,5).toLowerCase()===`nonce`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"nonce"`)),e===null?(e=null,i=o):(n=F(),n===null?(e=null,i=o):(r=vn(),r===null?(e=null,i=o):e=[e,n,r])),e}function vn(){var e,t=i;return e=de(),e!==null&&(e=function(e,t){$.nonce=t}(t,e)),e===null&&(i=t),e}function yn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`opaque`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"opaque"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=de(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.opaque=t}(o,e[2])),e===null&&(i=o),e}function bn(){var e,n,r,o=i,s;return t.substr(i,5).toLowerCase()===`stale`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"stale"`)),e===null?(e=null,i=o):(n=F(),n===null?(e=null,i=o):(s=i,t.substr(i,4).toLowerCase()===`true`?(r=t.substr(i,4),i+=4):(r=null,a===0&&c(`"true"`)),r!==null&&(r=function(e){$.stale=!0}(s)),r===null&&(i=s),r===null&&(s=i,t.substr(i,5).toLowerCase()===`false`?(r=t.substr(i,5),i+=5):(r=null,a===0&&c(`"false"`)),r!==null&&(r=function(e){$.stale=!1}(s)),r===null&&(i=s)),r===null?(e=null,i=o):e=[e,n,r])),e}function xn(){var e,n,r,o=i,s=i;return t.substr(i,9).toLowerCase()===`algorithm`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"algorithm"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(t.substr(i,3).toLowerCase()===`md5`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"MD5"`)),r===null&&(t.substr(i,8).toLowerCase()===`md5-sess`?(r=t.substr(i,8),i+=8):(r=null,a===0&&c(`"MD5-sess"`)),r===null&&(r=j())),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.algorithm=t.toUpperCase()}(o,e[2])),e===null&&(i=o),e}function Sn(){var e,n,r,o,s,l,u,d=i,f,p;if(t.substr(i,3).toLowerCase()===`qop`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"qop"`)),e!==null){if(n=F(),n!==null){if(r=oe(),r!==null){if(f=i,o=Cn(),o!==null){for(s=[],p=i,t.charCodeAt(i)===44?(l=`,`,i++):(l=null,a===0&&c(`","`)),l===null?(l=null,i=p):(u=Cn(),u===null?(l=null,i=p):l=[l,u]);l!==null;)s.push(l),p=i,t.charCodeAt(i)===44?(l=`,`,i++):(l=null,a===0&&c(`","`)),l===null?(l=null,i=p):(u=Cn(),u===null?(l=null,i=p):l=[l,u]);s===null?(o=null,i=f):o=[o,s]}else o=null,i=f;o===null?(e=null,i=d):(s=se(),s===null?(e=null,i=d):e=[e,n,r,o,s])}else e=null,i=d}else e=null,i=d}else e=null,i=d;return e}function Cn(){var e,n=i;return t.substr(i,8).toLowerCase()===`auth-int`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"auth-int"`)),e===null&&(t.substr(i,4).toLowerCase()===`auth`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"auth"`)),e===null&&(e=j())),e!==null&&(e=function(e,t){$.qop||($.qop=[]),$.qop.push(t.toLowerCase())}(n,e)),e===null&&(i=n),e}function wn(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Tn(){var e,t,n,r,a=i,o=i,s;if(e=En(),e!==null){for(t=[],s=i,n=L(),n===null?(n=null,i=s):(r=En(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=L(),n===null?(n=null,i=s):(r=En(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t,n=$.multi_header.length;for(t=0;t<n;t++)if($.multi_header[t].parsed===null){$=null;break}$=$===null?-1:$.multi_header}(a)),e===null&&(i=a),e}function En(){var e,t,n,r,a=i,o=i,s;if(e=X(),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t;$.multi_header||($.multi_header=[]);try{t=new Er($.uri,$.display_name,$.params),delete $.uri,delete $.display_name,delete $.params}catch{t=null}$.multi_header.push({possition:i,offset:e,parsed:t})}(a)),e===null&&(i=a),e}function Dn(){var e,n,r,o,s=i,l=i,u;if(t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e===null&&(e=j()),e!==null){for(n=[],u=i,r=R(),r===null?(r=null,i=u):(o=On(),o===null?(r=null,i=u):r=[r,o]);r!==null;)n.push(r),u=i,r=R(),r===null?(r=null,i=u):(o=On(),o===null?(r=null,i=u):r=[r,o]);n===null?(e=null,i=l):e=[e,n]}else e=null,i=l;return e!==null&&(e=function(e,t){if($.protocol=t.toLowerCase(),$.params||($.params={}),$.params.text&&$.params.text[0]===`"`){var n=$.params.text;$.text=n.substring(1,n.length-1),delete $.params.text}}(s,e[0])),e===null&&(i=s),e}function On(){var e=kn();return e===null&&(e=Q()),e}function kn(){var e,n,r,o,s=i,l=i;if(t.substr(i,5).toLowerCase()===`cause`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"cause"`)),e!==null){if(n=F(),n!==null){if(o=u(),o!==null)for(r=[];o!==null;)r.push(o),o=u();else r=null;r===null?(e=null,i=l):e=[e,n,r]}else e=null,i=l}else e=null,i=l;return e!==null&&(e=function(e,t){$.cause=parseInt(t.join(``))}(s,e[2])),e===null&&(i=s),e}function An(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function jn(){var e,t,n,r,a=i,o;if(e=Mn(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=Mn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=Mn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Mn(){var e,t,n,r,a=i,o;if(e=X(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=Q(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=Q(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Nn(){var e,t,n,r,a=i,o;if(e=Pn(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=Fn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=Fn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Pn(){var e,n=i;return t.substr(i,6).toLowerCase()===`active`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"active"`)),e===null&&(t.substr(i,7).toLowerCase()===`pending`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"pending"`)),e===null&&(t.substr(i,10).toLowerCase()===`terminated`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"terminated"`)),e===null&&(e=j()))),e!==null&&(e=function(e){$.state=t.substring(i,e)}(n)),e===null&&(i=n),e}function Fn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`reason`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"reason"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=In(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.reason=t)}(o,e[2])),e===null&&(i=o),e===null&&(o=i,s=i,t.substr(i,7).toLowerCase()===`expires`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"expires"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=jt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.expires=t)}(o,e[2])),e===null&&(i=o),e===null&&(o=i,s=i,t.substr(i,11).toLowerCase()===`retry_after`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"retry_after"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=jt(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){t!==void 0&&($.retry_after=t)}(o,e[2])),e===null&&(i=o),e===null&&(e=Q()))),e}function In(){var e;return t.substr(i,11).toLowerCase()===`deactivated`?(e=t.substr(i,11),i+=11):(e=null,a===0&&c(`"deactivated"`)),e===null&&(t.substr(i,9).toLowerCase()===`probation`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"probation"`)),e===null&&(t.substr(i,8).toLowerCase()===`rejected`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"rejected"`)),e===null&&(t.substr(i,7).toLowerCase()===`timeout`?(e=t.substr(i,7),i+=7):(e=null,a===0&&c(`"timeout"`)),e===null&&(t.substr(i,6).toLowerCase()===`giveup`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"giveup"`)),e===null&&(t.substr(i,10).toLowerCase()===`noresource`?(e=t.substr(i,10),i+=10):(e=null,a===0&&c(`"noresource"`)),e===null&&(t.substr(i,9).toLowerCase()===`invariant`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"invariant"`)),e===null&&(e=j()))))))),e}function Ln(){var e=E();return e=e===null?``:e,e}function Rn(){var e,t,n,r,a=i,o;if(e=j(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=j(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e=e===null?``:e,e}function zn(){var e,t,n,r,a=i,o=i,s;if(e=B(),e===null&&(e=X()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Bn(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Bn(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){var t=$.tag;try{$=new Er($.uri,$.display_name,$.params),t&&$.setParam(`tag`,t)}catch{$=-1}}(a)),e===null&&(i=a),e}function Bn(){var e=rn();return e===null&&(e=Q()),e}function Vn(){var e,t,n,r,a=i,o;if(e=Hn(),e!==null){for(t=[],o=i,n=L(),n===null?(n=null,i=o):(r=Hn(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=L(),n===null?(n=null,i=o):(r=Hn(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function Hn(){var e,t,n,r,a,o,s=i,c;if(e=Xn(),e!==null){if(t=C(),t!==null){if(n=$n(),n!==null){for(r=[],c=i,a=R(),a===null?(a=null,i=c):(o=Un(),o===null?(a=null,i=c):a=[a,o]);a!==null;)r.push(a),c=i,a=R(),a===null?(a=null,i=c):(o=Un(),o===null?(a=null,i=c):a=[a,o]);r===null?(e=null,i=s):e=[e,t,n,r]}else e=null,i=s}else e=null,i=s}else e=null,i=s;return e}function Un(){var e=Wn();return e===null&&(e=Gn(),e===null&&(e=Kn(),e===null&&(e=qn(),e===null&&(e=Jn(),e===null&&(e=Q()))))),e}function Wn(){var e,n,r,o=i,s=i;return t.substr(i,3).toLowerCase()===`ttl`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"ttl"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=nr(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.ttl=t}(o,e[2])),e===null&&(i=o),e}function Gn(){var e,n,r,o=i,s=i;return t.substr(i,5).toLowerCase()===`maddr`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"maddr"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=Se(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.maddr=t}(o,e[2])),e===null&&(i=o),e}function Kn(){var e,n,r,o=i,s=i;return t.substr(i,8).toLowerCase()===`received`?(e=t.substr(i,8),i+=8):(e=null,a===0&&c(`"received"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=Oe(),r===null&&(r=De()),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.received=t}(o,e[2])),e===null&&(i=o),e}function qn(){var e,n,r,o=i,s=i;return t.substr(i,6).toLowerCase()===`branch`?(e=t.substr(i,6),i+=6):(e=null,a===0&&c(`"branch"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.branch=t}(o,e[2])),e===null&&(i=o),e}function Jn(){var e,n,r,o=i,s;return t.substr(i,5).toLowerCase()===`rport`?(e=t.substr(i,5),i+=5):(e=null,a===0&&c(`"rport"`)),e===null?(e=null,i=o):(s=i,n=F(),n===null?(n=null,i=s):(r=Yn(),r===null?(n=null,i=s):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=o):e=[e,n]),e}function Yn(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){$.rport=parseInt(t.join(``))}(o,e)),e===null&&(i=o),e}function Xn(){var e,t,n,r,a,o=i;return e=Zn(),e===null?(e=null,i=o):(t=te(),t===null?(e=null,i=o):(n=j(),n===null?(e=null,i=o):(r=te(),r===null?(e=null,i=o):(a=Qn(),a===null?(e=null,i=o):e=[e,t,n,r,a])))),e}function Zn(){var e,n=i;return t.substr(i,3).toLowerCase()===`sip`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"SIP"`)),e===null&&(e=j()),e!==null&&(e=function(e,t){$.protocol=t}(n,e)),e===null&&(i=n),e}function Qn(){var e,n=i;return t.substr(i,3).toLowerCase()===`udp`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"UDP"`)),e===null&&(t.substr(i,3).toLowerCase()===`tcp`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"TCP"`)),e===null&&(t.substr(i,3).toLowerCase()===`tls`?(e=t.substr(i,3),i+=3):(e=null,a===0&&c(`"TLS"`)),e===null&&(t.substr(i,4).toLowerCase()===`sctp`?(e=t.substr(i,4),i+=4):(e=null,a===0&&c(`"SCTP"`)),e===null&&(e=j())))),e!==null&&(e=function(e,t){$.transport=t}(n,e)),e===null&&(i=n),e}function $n(){var e,t,n,r=i,a;return e=er(),e===null?(e=null,i=r):(a=i,t=ae(),t===null?(t=null,i=a):(n=tr(),n===null?(t=null,i=a):t=[t,n]),t=t===null?``:t,t===null?(e=null,i=r):e=[e,t]),e}function er(){var e,n=i;return e=Oe(),e===null&&(e=Ee(),e===null&&(e=Ce())),e!==null&&(e=function(e){$.host=t.substring(i,e)}(n)),e===null&&(i=n),e}function tr(){var e,t,n,r,a,o=i,s=i;return e=u(),e=e===null?``:e,e===null?(e=null,i=s):(t=u(),t=t===null?``:t,t===null?(e=null,i=s):(n=u(),n=n===null?``:n,n===null?(e=null,i=s):(r=u(),r=r===null?``:r,r===null?(e=null,i=s):(a=u(),a=a===null?``:a,a===null?(e=null,i=s):e=[e,t,n,r,a])))),e!==null&&(e=function(e,t){$.port=parseInt(t.join(``))}(o,e)),e===null&&(i=o),e}function nr(){var e,t,n,r=i,a=i;return e=u(),e===null?(e=null,i=a):(t=u(),t=t===null?``:t,t===null?(e=null,i=a):(n=u(),n=n===null?``:n,n===null?(e=null,i=a):e=[e,t,n])),e!==null&&(e=function(e,t){return parseInt(t.join(``))}(r,e)),e===null&&(i=r),e}function rr(){return ln()}function ir(){var e,t,n,r,a=i,o;if(e=ar(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=or(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=or(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function ar(){var e,t=i;return e=jt(),e!==null&&(e=function(e,t){$.expires=t}(t,e)),e===null&&(i=t),e}function or(){var e=sr();return e===null&&(e=Q()),e}function sr(){var e,n,r,o=i,s=i;return t.substr(i,9).toLowerCase()===`refresher`?(e=t.substr(i,9),i+=9):(e=null,a===0&&c(`"refresher"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(t.substr(i,3).toLowerCase()===`uac`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"uac"`)),r===null&&(t.substr(i,3).toLowerCase()===`uas`?(r=t.substr(i,3),i+=3):(r=null,a===0&&c(`"uas"`))),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.refresher=t.toLowerCase()}(o,e[2])),e===null&&(i=o),e}function cr(){var e,t,n,r=i;return e=j(),e===null?(e=null,i=r):(t=T(),t===null?(e=null,i=r):(n=lr(),n===null?(e=null,i=r):e=[e,t,n])),e}function lr(){var e=[],t=D();for(t===null&&(t=k(),t===null&&(t=C()));t!==null;)e.push(t),t=D(),t===null&&(t=k(),t===null&&(t=C()));return e}function ur(){for(var e=[],t=m();t!==null;)e.push(t),t=m();return e}function dr(){var e,n,r=i;return t.substr(i,5)===`uuid:`?(e=`uuid:`,i+=5):(e=null,a===0&&c(`"uuid:"`)),e===null?(e=null,i=r):(n=fr(),n===null?(e=null,i=r):e=[e,n]),e}function fr(){var e,n,r,o,s,l,u,d,f,p=i,m=i;return e=mr(),e===null?(e=null,i=m):(t.charCodeAt(i)===45?(n=`-`,i++):(n=null,a===0&&c(`"-"`)),n===null?(e=null,i=m):(r=pr(),r===null?(e=null,i=m):(t.charCodeAt(i)===45?(o=`-`,i++):(o=null,a===0&&c(`"-"`)),o===null?(e=null,i=m):(s=pr(),s===null?(e=null,i=m):(t.charCodeAt(i)===45?(l=`-`,i++):(l=null,a===0&&c(`"-"`)),l===null?(e=null,i=m):(u=pr(),u===null?(e=null,i=m):(t.charCodeAt(i)===45?(d=`-`,i++):(d=null,a===0&&c(`"-"`)),d===null?(e=null,i=m):(f=hr(),f===null?(e=null,i=m):e=[e,n,r,o,s,l,u,d,f])))))))),e!==null&&(e=function(e,n){$=t.substring(i+5,e)}(p,e[0])),e===null&&(i=p),e}function pr(){var e,t,n,r,a=i;return e=f(),e===null?(e=null,i=a):(t=f(),t===null?(e=null,i=a):(n=f(),n===null?(e=null,i=a):(r=f(),r===null?(e=null,i=a):e=[e,t,n,r]))),e}function mr(){var e,t,n=i;return e=pr(),e===null?(e=null,i=n):(t=pr(),t===null?(e=null,i=n):e=[e,t]),e}function hr(){var e,t,n,r=i;return e=pr(),e===null?(e=null,i=r):(t=pr(),t===null?(e=null,i=r):(n=pr(),n===null?(e=null,i=r):e=[e,t,n])),e}function gr(){var e,t,n,r,a=i,o=i,s;if(e=B(),e===null&&(e=X()),e!==null){for(t=[],s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);n!==null;)t.push(n),s=i,n=R(),n===null?(n=null,i=s):(r=Q(),r===null?(n=null,i=s):n=[n,r]);t===null?(e=null,i=o):e=[e,t]}else e=null,i=o;return e!==null&&(e=function(e){try{$=new Er($.uri,$.display_name,$.params)}catch{$=-1}}(a)),e===null&&(i=a),e}function _r(){var e,t,n,r,a=i,o;if(e=vr(),e!==null){for(t=[],o=i,n=R(),n===null?(n=null,i=o):(r=yr(),r===null?(n=null,i=o):n=[n,r]);n!==null;)t.push(n),o=i,n=R(),n===null?(n=null,i=o):(r=yr(),r===null?(n=null,i=o):n=[n,r]);t===null?(e=null,i=a):e=[e,t]}else e=null,i=a;return e}function vr(){var e,n,r,o=i,s=i,l;return e=P(),e===null?(e=null,i=s):(l=i,t.charCodeAt(i)===64?(n=`@`,i++):(n=null,a===0&&c(`"@"`)),n===null?(n=null,i=l):(r=P(),r===null?(n=null,i=l):n=[n,r]),n=n===null?``:n,n===null?(e=null,i=s):e=[e,n]),e!==null&&(e=function(e){$.call_id=t.substring(i,e)}(o)),e===null&&(i=o),e}function yr(){var e=br();return e===null&&(e=xr(),e===null&&(e=Sr(),e===null&&(e=Q()))),e}function br(){var e,n,r,o=i,s=i;return t.substr(i,6)===`to-tag`?(e=`to-tag`,i+=6):(e=null,a===0&&c(`"to-tag"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.to_tag=t}(o,e[2])),e===null&&(i=o),e}function xr(){var e,n,r,o=i,s=i;return t.substr(i,8)===`from-tag`?(e=`from-tag`,i+=8):(e=null,a===0&&c(`"from-tag"`)),e===null?(e=null,i=s):(n=F(),n===null?(e=null,i=s):(r=j(),r===null?(e=null,i=s):e=[e,n,r])),e!==null&&(e=function(e,t){$.from_tag=t}(o,e[2])),e===null&&(i=o),e}function Sr(){var e,n=i;return t.substr(i,10)===`early-only`?(e=`early-only`,i+=10):(e=null,a===0&&c(`"early-only"`)),e!==null&&(e=function(e){$.early_only=!0}(n)),e===null&&(i=n),e}function Cr(e){e.sort();for(var t=null,n=[],r=0;r<e.length;r++)e[r]!==t&&(n.push(e[r]),t=e[r]);return n}function wr(){for(var e=1,n=1,r=!1,a=0;a<Math.max(i,o);a++){var s=t.charAt(a);s===`
4
+ `?(r||e++,n=1,r=!1):s===`\r`||s===`\u2028`||s===`\u2029`?(e++,n=1,r=!0):(n++,r=!1)}return{line:e,column:n}}var Tr=wt(),Er=Ct(),$={};if(r[n]()===null||i!==t.length){var Dr=Math.max(i,o),Or=Dr<t.length?t.charAt(Dr):null,kr=wr();return new this.SyntaxError(Cr(s),Or,Dr,kr.line,kr.column),-1}return $},toSource:function(){return this._source}};return t.SyntaxError=function(t,n,r,i,a){function o(t,n){var r,i;switch(t.length){case 0:r=`end of input`;break;case 1:r=t[0];break;default:r=t.slice(0,t.length-1).join(`, `)+` or `+t[t.length-1]}return i=n?e(n):`end of input`,`Expected `+r+` but `+i+` found.`}this.name=`SyntaxError`,this.expected=t,this.found=n,this.message=o(t,n),this.offset=r,this.line=i,this.column=a},t.SyntaxError.prototype=Error.prototype,t}()})),wt=c(((e,t)=>{function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}var c=W(),l=q(),u=K();t.exports=function(){s(e,null,[{key:`parse`,value:function(e){if(e=u.parse(e,`SIP_URI`),e!==-1)return e}}]);function e(t,n,r,i){var o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},s=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(a(this,e),!r)throw TypeError(`missing or invalid "host" parameter`);for(var l in this._parameters={},this._headers={},this._scheme=t||c.SIP,this._user=n,this._host=r,this._port=i,o)Object.prototype.hasOwnProperty.call(o,l)&&this.setParam(l,o[l]);for(var u in s)Object.prototype.hasOwnProperty.call(s,u)&&this.setHeader(u,s[u])}return s(e,[{key:`setParam`,value:function(e,t){e&&(this._parameters[e.toLowerCase()]=t==null?null:t.toString())}},{key:`getParam`,value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:`hasParam`,value:function(e){if(e)return this._parameters.hasOwnProperty(e.toLowerCase())&&!0||!1}},{key:`deleteParam`,value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:`clearParams`,value:function(){this._parameters={}}},{key:`setHeader`,value:function(e,t){this._headers[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:`getHeader`,value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:`hasHeader`,value:function(e){if(e)return this._headers.hasOwnProperty(l.headerize(e))&&!0||!1}},{key:`deleteHeader`,value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:`clearHeaders`,value:function(){this._headers={}}},{key:`clone`,value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:`toString`,value:function(){var e=[],t=`${this._scheme}:`;for(var r in this._user&&(t+=`${l.escapeUser(this._user)}@`),t+=this._host,(this._port||this._port===0)&&(t+=`:${this._port}`),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(t+=`;${r}`,this._parameters[r]!==null&&(t+=`=${this._parameters[r]}`));for(var i in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,i)){var a=n(this._headers[i]),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;e.push(`${i}=${s}`)}}catch(e){a.e(e)}finally{a.f()}}return e.length>0&&(t+=`?${e.join(`&`)}`),t}},{key:`toAor`,value:function(e){var t=`${this._scheme}:`;return this._user&&(t+=`${l.escapeUser(this._user)}@`),t+=this._host,e&&(this._port||this._port===0)&&(t+=`:${this._port}`),t}},{key:`scheme`,get:function(){return this._scheme},set:function(e){this._scheme=e.toLowerCase()}},{key:`user`,get:function(){return this._user},set:function(e){this._user=e}},{key:`host`,get:function(){return this._host},set:function(e){this._host=e.toLowerCase()}},{key:`port`,get:function(){return this._port},set:function(e){this._port=e===0?e:parseInt(e,10)||null}}]),e}()})),q=c((e=>{function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
6
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=W(),o=wt(),s=K();e.str_utf8_length=function(e){return unescape(encodeURIComponent(e)).length};var c=e.isFunction=function(e){return e!==void 0&&Object.prototype.toString.call(e)===`[object Function]`};e.isString=function(e){return e!==void 0&&Object.prototype.toString.call(e)===`[object String]`},e.isDecimal=function(e){return!isNaN(e)&&parseFloat(e)===parseInt(e,10)},e.isEmpty=function(e){return e===null||e===``||e===void 0||Array.isArray(e)&&e.length===0||typeof e==`number`&&isNaN(e)},e.hasMethods=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var i=0,a=n;i<a.length;i++){var o=a[i];if(c(e[o]))return!1}return!0};var l=e.createRandomToken=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,n,r,i=``;for(n=0;n<e;n++)r=Math.random()*t|0,i+=r.toString(t);return i};e.newTag=function(){return l(10)},e.newUUID=function(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){var t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})},e.hostType=function(e){if(e&&(e=s.parse(e,`host`),e!==-1))return e.host_type};var u=e.escapeUser=function(e){return encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,`:`).replace(/%2B/gi,`+`).replace(/%3F/gi,`?`).replace(/%2F/gi,`/`)};e.normalizeTarget=function(e,t){if(e){if(e instanceof o)return e;if(typeof e==`string`){var n=e.split(`@`),r,i;switch(n.length){case 1:if(!t)return;r=e,i=t;break;case 2:r=n[0],i=n[1];break;default:r=n.slice(0,n.length-1).join(`@`),i=n[n.length-1]}r=r.replace(/^(sips?|tel):/i,``),/^[-.()]*\+?[0-9\-.()]+$/.test(r)&&(r=r.replace(/[-.()]/g,``)),e=`${a.SIP}:${u(r)}@${i}`;var s;return(s=o.parse(e))?s:void 0}}},e.headerize=function(e){for(var t={"Call-Id":`Call-ID`,Cseq:`CSeq`,"Www-Authenticate":`WWW-Authenticate`},n=e.toLowerCase().replace(/_/g,`-`).split(`-`),r=``,i=n.length,a=0;a<i;a++)a!==0&&(r+=`-`),r+=n[a].charAt(0).toUpperCase()+n[a].substring(1);return t[r]&&(r=t[r]),r},e.sipErrorCause=function(e){for(var t in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[t].indexOf(e)!==-1)return a.causes[t];return a.causes.SIP_FAILURE_CODE},e.getRandomTestNetIP=function(){function e(e,t){return Math.floor(Math.random()*(t-e+1)+e)}return`192.0.2.${e(1,254)}`},e.calculateMD5=function(e){function t(e,t){return e<<t|e>>>32-t}function n(e,t){var n=e&2147483648,r=t&2147483648,i=e&1073741824,a=t&1073741824,o=(e&1073741823)+(t&1073741823);return i&a?o^2147483648^n^r:i|a?o&1073741824?o^3221225472^n^r:o^1073741824^n^r:o^n^r}function r(e,t,n){return e&t|~e&n}function i(e,t,n){return e&n|t&~n}function a(e,t,n){return e^t^n}function o(e,t,n){return t^(e|~n)}function s(e,i,a,o,s,c,l){return e=n(e,n(n(r(i,a,o),s),l)),n(t(e,c),i)}function c(e,r,a,o,s,c,l){return e=n(e,n(n(i(r,a,o),s),l)),n(t(e,c),r)}function l(e,r,i,o,s,c,l){return e=n(e,n(n(a(r,i,o),s),l)),n(t(e,c),r)}function u(e,r,i,a,s,c,l){return e=n(e,n(n(o(r,i,a),s),l)),n(t(e,c),r)}function d(e){for(var t,n=e.length,r=n+8,i=((r-r%64)/64+1)*16,a=Array(i-1),o=0,s=0;s<n;)t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|e.charCodeAt(s)<<o,s++;return t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|128<<o,a[i-2]=n<<3,a[i-1]=n>>>29,a}function f(e){for(var t=``,n=``,r,i=0;i<=3;i++)r=e>>>i*8&255,n=`0${r.toString(16)}`,t+=n.substr(n.length-2,2);return t}function p(e){for(var t=``,n=0;n<e.length;n++){var r=e.charCodeAt(n);r<128?t+=String.fromCharCode(r):r>127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(r&63|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(r&63|128))}return t}var m=[],h,g,_,v,y,b,x,S,C,w=7,T=12,E=17,D=22,O=5,k=9,A=14,j=20,M=4,N=11,P=16,ee=23,te=6,F=10,I=15,ne=21;for(e=p(e),m=d(e),b=1732584193,x=4023233417,S=2562383102,C=271733878,h=0;h<m.length;h+=16)g=b,_=x,v=S,y=C,b=s(b,x,S,C,m[h+0],w,3614090360),C=s(C,b,x,S,m[h+1],T,3905402710),S=s(S,C,b,x,m[h+2],E,606105819),x=s(x,S,C,b,m[h+3],D,3250441966),b=s(b,x,S,C,m[h+4],w,4118548399),C=s(C,b,x,S,m[h+5],T,1200080426),S=s(S,C,b,x,m[h+6],E,2821735955),x=s(x,S,C,b,m[h+7],D,4249261313),b=s(b,x,S,C,m[h+8],w,1770035416),C=s(C,b,x,S,m[h+9],T,2336552879),S=s(S,C,b,x,m[h+10],E,4294925233),x=s(x,S,C,b,m[h+11],D,2304563134),b=s(b,x,S,C,m[h+12],w,1804603682),C=s(C,b,x,S,m[h+13],T,4254626195),S=s(S,C,b,x,m[h+14],E,2792965006),x=s(x,S,C,b,m[h+15],D,1236535329),b=c(b,x,S,C,m[h+1],O,4129170786),C=c(C,b,x,S,m[h+6],k,3225465664),S=c(S,C,b,x,m[h+11],A,643717713),x=c(x,S,C,b,m[h+0],j,3921069994),b=c(b,x,S,C,m[h+5],O,3593408605),C=c(C,b,x,S,m[h+10],k,38016083),S=c(S,C,b,x,m[h+15],A,3634488961),x=c(x,S,C,b,m[h+4],j,3889429448),b=c(b,x,S,C,m[h+9],O,568446438),C=c(C,b,x,S,m[h+14],k,3275163606),S=c(S,C,b,x,m[h+3],A,4107603335),x=c(x,S,C,b,m[h+8],j,1163531501),b=c(b,x,S,C,m[h+13],O,2850285829),C=c(C,b,x,S,m[h+2],k,4243563512),S=c(S,C,b,x,m[h+7],A,1735328473),x=c(x,S,C,b,m[h+12],j,2368359562),b=l(b,x,S,C,m[h+5],M,4294588738),C=l(C,b,x,S,m[h+8],N,2272392833),S=l(S,C,b,x,m[h+11],P,1839030562),x=l(x,S,C,b,m[h+14],ee,4259657740),b=l(b,x,S,C,m[h+1],M,2763975236),C=l(C,b,x,S,m[h+4],N,1272893353),S=l(S,C,b,x,m[h+7],P,4139469664),x=l(x,S,C,b,m[h+10],ee,3200236656),b=l(b,x,S,C,m[h+13],M,681279174),C=l(C,b,x,S,m[h+0],N,3936430074),S=l(S,C,b,x,m[h+3],P,3572445317),x=l(x,S,C,b,m[h+6],ee,76029189),b=l(b,x,S,C,m[h+9],M,3654602809),C=l(C,b,x,S,m[h+12],N,3873151461),S=l(S,C,b,x,m[h+15],P,530742520),x=l(x,S,C,b,m[h+2],ee,3299628645),b=u(b,x,S,C,m[h+0],te,4096336452),C=u(C,b,x,S,m[h+7],F,1126891415),S=u(S,C,b,x,m[h+14],I,2878612391),x=u(x,S,C,b,m[h+5],ne,4237533241),b=u(b,x,S,C,m[h+12],te,1700485571),C=u(C,b,x,S,m[h+3],F,2399980690),S=u(S,C,b,x,m[h+10],I,4293915773),x=u(x,S,C,b,m[h+1],ne,2240044497),b=u(b,x,S,C,m[h+8],te,1873313359),C=u(C,b,x,S,m[h+15],F,4264355552),S=u(S,C,b,x,m[h+6],I,2734768916),x=u(x,S,C,b,m[h+13],ne,1309151649),b=u(b,x,S,C,m[h+4],te,4149444226),C=u(C,b,x,S,m[h+11],F,3174756917),S=u(S,C,b,x,m[h+2],I,718787259),x=u(x,S,C,b,m[h+9],ne,3951481745),b=n(b,g),x=n(x,_),S=n(S,v),C=n(C,y);return(f(b)+f(x)+f(S)+f(C)).toLowerCase()},e.closeMediaStream=function(e){if(e)try{var r;if(e.getTracks){r=e.getTracks();var i=n(r),a;try{for(i.s();!(a=i.n()).done;)a.value.stop()}catch(e){i.e(e)}finally{i.f()}}else{r=e.getAudioTracks();var o=n(r),s;try{for(o.s();!(s=o.n()).done;)s.value.stop()}catch(e){o.e(e)}finally{o.f()}r=e.getVideoTracks();var c=n(r),l;try{for(c.s();!(l=c.n()).done;)l.value.stop()}catch(e){c.e(e)}finally{c.f()}}}catch{(typeof e.stop==`function`||t(e.stop)===`object`)&&e.stop()}},e.cloneArray=function(e){return e&&e.slice()||[]},e.cloneObject=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return e&&Object.assign({},e)||t}})),J=c(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),Tt=c(((e,t)=>{var n=1e3,r=n*60,i=r*60,a=i*24,o=a*7,s=a*365.25;t.exports=function(e,t){t||={};var n=typeof e;if(n===`string`&&e.length>0)return c(e);if(n===`number`&&isFinite(e))return t.long?u(e):l(e);throw Error(`val is not a non-empty string or a valid number. val=`+JSON.stringify(e))};function c(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var c=parseFloat(t[1]);switch((t[2]||`ms`).toLowerCase()){case`years`:case`year`:case`yrs`:case`yr`:case`y`:return c*s;case`weeks`:case`week`:case`w`:return c*o;case`days`:case`day`:case`d`:return c*a;case`hours`:case`hour`:case`hrs`:case`hr`:case`h`:return c*i;case`minutes`:case`minute`:case`mins`:case`min`:case`m`:return c*r;case`seconds`:case`second`:case`secs`:case`sec`:case`s`:return c*n;case`milliseconds`:case`millisecond`:case`msecs`:case`msec`:case`ms`:return c;default:return}}}}function l(e){var t=Math.abs(e);return t>=a?Math.round(e/a)+`d`:t>=i?Math.round(e/i)+`h`:t>=r?Math.round(e/r)+`m`:t>=n?Math.round(e/n)+`s`:e+`ms`}function u(e){var t=Math.abs(e);return t>=a?d(e,t,a,`day`):t>=i?d(e,t,i,`hour`):t>=r?d(e,t,r,`minute`):t>=n?d(e,t,n,`second`):e+` ms`}function d(e,t,n,r){var i=t>=n*1.5;return Math.round(e/n)+` `+r+(i?`s`:``)}})),Et=c(((e,t)=>{function n(e){n.debug=n,n.default=n,n.coerce=c,n.disable=o,n.enable=i,n.enabled=s,n.humanize=Tt(),n.destroy=l,Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={};function t(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]}n.selectColor=t;function n(e){let t,i=null,a,o;function s(...e){if(!s.enabled)return;let r=s,i=Number(new Date);r.diff=i-(t||i),r.prev=t,r.curr=i,t=i,e[0]=n.coerce(e[0]),typeof e[0]!=`string`&&e.unshift(`%O`);let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,i)=>{if(t===`%%`)return`%`;a++;let o=n.formatters[i];if(typeof o==`function`){let n=e[a];t=o.call(r,n),e.splice(a,1),a--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return s.namespace=e,s.useColors=n.useColors(),s.color=n.selectColor(e),s.extend=r,s.destroy=n.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>i===null?(a!==n.namespaces&&(a=n.namespaces,o=n.enabled(e)),o):i,set:e=>{i=e}}),typeof n.init==`function`&&n.init(s),s}function r(e,t){let r=n(this.namespace+(t===void 0?`:`:t)+e);return r.log=this.log,r}function i(e){n.save(e),n.namespaces=e,n.names=[],n.skips=[];let t=(typeof e==`string`?e:``).trim().replace(/\s+/g,`,`).split(`,`).filter(Boolean);for(let e of t)e[0]===`-`?n.skips.push(e.slice(1)):n.names.push(e)}function a(e,t){let n=0,r=0,i=-1,a=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||t[r]===`*`))t[r]===`*`?(i=r,a=n,r++):(n++,r++);else if(i!==-1)r=i+1,a++,n=a;else return!1;for(;r<t.length&&t[r]===`*`;)r++;return r===t.length}function o(){let e=[...n.names,...n.skips.map(e=>`-`+e)].join(`,`);return n.enable(``),e}function s(e){for(let t of n.skips)if(a(e,t))return!1;for(let t of n.names)if(a(e,t))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}t.exports=n})),Dt=c(((e,t)=>{e.formatArgs=r,e.save=i,e.load=a,e.useColors=n,e.storage=o(),e.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`."))}})(),e.colors=`#0000CC.#0000FF.#0033CC.#0033FF.#0066CC.#0066FF.#0099CC.#0099FF.#00CC00.#00CC33.#00CC66.#00CC99.#00CCCC.#00CCFF.#3300CC.#3300FF.#3333CC.#3333FF.#3366CC.#3366FF.#3399CC.#3399FF.#33CC00.#33CC33.#33CC66.#33CC99.#33CCCC.#33CCFF.#6600CC.#6600FF.#6633CC.#6633FF.#66CC00.#66CC33.#9900CC.#9900FF.#9933CC.#9933FF.#99CC00.#99CC33.#CC0000.#CC0033.#CC0066.#CC0099.#CC00CC.#CC00FF.#CC3300.#CC3333.#CC3366.#CC3399.#CC33CC.#CC33FF.#CC6600.#CC6633.#CC9900.#CC9933.#CCCC00.#CCCC33.#FF0000.#FF0033.#FF0066.#FF0099.#FF00CC.#FF00FF.#FF3300.#FF3333.#FF3366.#FF3399.#FF33CC.#FF33FF.#FF6600.#FF6633.#FF9900.#FF9933.#FFCC00.#FFCC33`.split(`.`);function n(){if(typeof window<`u`&&window.process&&(window.process.type===`renderer`||window.process.__nwjs))return!0;if(typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<`u`&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<`u`&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<`u`&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function r(e){if(e[0]=(this.useColors?`%c`:``)+this.namespace+(this.useColors?` %c`:` `)+e[0]+(this.useColors?`%c `:` `)+`+`+t.exports.humanize(this.diff),!this.useColors)return;let n=`color: `+this.color;e.splice(1,0,n,`color: inherit`);let r=0,i=0;e[0].replace(/%[a-zA-Z%]/g,e=>{e!==`%%`&&(r++,e===`%c`&&(i=r))}),e.splice(i,0,n)}e.log=console.debug||console.log||(()=>{});function i(t){try{t?e.storage.setItem(`debug`,t):e.storage.removeItem(`debug`)}catch{}}function a(){let t;try{t=e.storage.getItem(`debug`)||e.storage.getItem(`DEBUG`)}catch{}return!t&&typeof process<`u`&&`env`in process&&(t=process.env.DEBUG),t}function o(){try{return localStorage}catch{}}t.exports=Et()(e);var{formatters:s}=t.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: `+e.message}}})),Y=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Dt(),o=`JsSIP`;t.exports=function(){function e(t){n(this,e),t?(this._debug=a.default(`${o}:${t}`),this._warn=a.default(`${o}:WARN:${t}`),this._error=a.default(`${o}:ERROR:${t}`)):(this._debug=a.default(o),this._warn=a.default(`${o}:WARN`),this._error=a.default(`${o}:ERROR`)),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return i(e,[{key:`debug`,get:function(){return this._debug}},{key:`warn`,get:function(){return this._warn}},{key:`error`,get:function(){return this._error}}]),e}()})),X=c(((e,t)=>{var n=t.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 e.address==null?`rtcp:%d`:`rtcp:%d %s IP%d %s`}},{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 e.subtype==null?`rtcp-fb:%s %s`:`rtcp-fb:%s %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 e.sessionConfig==null?`crypto:%d %s %s`:`crypto:%d %s %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+=e.raddr==null?`%v%v`:` raddr %s rport %d`,t+=e.tcptype==null?`%v`:` tcptype %s`,e.generation!=null&&(t+=` generation %d`),t+=e[`network-id`]==null?`%v`:` network-id %d`,t+=e[`network-cost`]==null?`%v`:` network-cost %d`,t}},{name:`endOfCandidates`,reg:/^(end-of-candidates)/},{name:`remoteCandidates`,reg:/^remote-candidates:(.*)/,format:`remote-candidates:%s`},{name:`iceOptions`,reg:/^ice-options:(\S*)/,format:`ice-options:%s`},{push:`ssrcs`,reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:[`id`,`attribute`,`value`],format:function(e){var t=`ssrc:%d`;return e.attribute!=null&&(t+=` %s`,e.value!=null&&(t+=`:%s`)),t}},{push:`ssrcGroups`,reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:[`semantics`,`ssrcs`],format:`ssrc-group:%s %s`},{name:`msidSemantic`,reg:/^msid-semantic:\s?(\w*) (\S*)/,names:[`semantic`,`token`],format:`msid-semantic: %s %s`},{push:`groups`,reg:/^group:(\w*) (.*)/,names:[`type`,`mids`],format:`group:%s %s`},{name:`rtcpMux`,reg:/^(rtcp-mux)/},{name:`rtcpRsize`,reg:/^(rtcp-rsize)/},{name:`sctpmap`,reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:[`sctpmapNumber`,`app`,`maxMessageSize`],format:function(e){return e.maxMessageSize==null?`sctpmap:%s %s`:`sctpmap:%s %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: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: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`+(e.clksrcExt==null?``:`=%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+=e.id==null?`%v%s`:`id=%s %s`,t+=e.mediaClockValue==null?``:`=%s`,t+=e.rateNumerator==null?``:` rate=%s`,t+=e.rateDenominator==null?``:`/%s`,t}},{name:`keywords`,reg:/^keywds:(.+)$/,format:`keywds:%s`},{name:`content`,reg:/^content:(.+)/,format:`content:%s`},{name:`bfcpFloorCtrl`,reg:/^floorctrl:(c-only|s-only|c-s)/,format:`floorctrl:%s`},{name:`bfcpConfId`,reg:/^confid:(\d+)/,format:`confid:%s`},{name:`bfcpUserId`,reg:/^userid:(\d+)/,format:`userid:%s`},{name:`bfcpFloorId`,reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:[`id`,`mStream`],format:`floorid:%s mstrm:%s`},{push:`invalid`,names:[`value`]}]};Object.keys(n).forEach(function(e){n[e].forEach(function(e){e.reg||=/(.*)/,e.format||=`%s`})})})),Ot=c((e=>{var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,r,i){if(i&&!r)n[i]=t(e[1]);else for(var a=0;a<r.length;a+=1)e[a+1]!=null&&(n[r[a]]=t(e[a+1]))},r=function(e,t,r){var i=e.name&&e.names;e.push&&!t[e.push]?t[e.push]=[]:i&&!t[e.name]&&(t[e.name]={});var a=e.push?{}:i?t[e.name]:t;n(r.match(e.reg),a,e.names,e.name),e.push&&t[e.push].push(a)},i=X(),a=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},n=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(a).forEach(function(e){var t=e[0],a=e.slice(2);t===`m`&&(n.push({rtp:[],fmtp:[]}),o=n[n.length-1]);for(var s=0;s<(i[t]||[]).length;s+=1){var c=i[t][s];if(c.reg.test(a))return r(c,o,a)}}),t.media=n,t};var o=function(e,n){var r=n.split(/=(.+)/,2);return r.length===2?e[r[0]]=t(r[1]):r.length===1&&n.length>1&&(e[r[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(o,{})},e.parseFmtpConfig=e.parseParams,e.parsePayloads=function(e){return e.toString().split(` `).map(Number)},e.parseRemoteCandidates=function(e){for(var n=[],r=e.split(` `).map(t),i=0;i<r.length;i+=3)n.push({component:r[i],ip:r[i+1],port:r[i+2]});return n},e.parseImageAttributes=function(e){return e.split(` `).map(function(e){return e.substring(1,e.length-1).split(`,`).reduce(o,{})})},e.parseSimulcastStreamList=function(e){return e.split(`;`).map(function(e){return e.split(`,`).map(function(e){var n,r=!1;return e[0]===`~`?(n=t(e.substring(1,e.length)),r=!0):n=t(e),{scid:n,paused:r}})})}})),kt=c(((e,t)=>{var n=X(),r=/%[sdv%]/g,i=function(e){var t=1,n=arguments,i=n.length;return e.replace(r,function(e){if(t>=i)return e;var r=n[t];switch(t+=1,e){case`%%`:return`%`;case`%s`:return String(r);case`%d`:return Number(r);case`%v`:return``}})},a=function(e,t,n){var r=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,a=[e+`=`+r];if(t.names)for(var o=0;o<t.names.length;o+=1){var s=t.names[o];t.name?a.push(n[t.name][s]):a.push(n[t.names[o]])}else a.push(n[t.name]);return i.apply(null,a)},o=[`v`,`o`,`s`,`i`,`u`,`e`,`p`,`c`,`b`,`t`,`r`,`z`,`a`],s=[`i`,`c`,`b`,`a`];t.exports=function(e,t){t||={},e.version??=0,e.name??=` `,e.media.forEach(function(e){e.payloads??=``});var r=t.outerOrder||o,i=t.innerOrder||s,c=[];return r.forEach(function(t){n[t].forEach(function(n){n.name in e&&e[n.name]!=null?c.push(a(t,n,e)):n.push in e&&e[n.push]!=null&&e[n.push].forEach(function(e){c.push(a(t,n,e))})})}),e.media.forEach(function(e){c.push(a(`m`,n.m[0],e)),i.forEach(function(t){n[t].forEach(function(n){n.name in e&&e[n.name]!=null?c.push(a(t,n,e)):n.push in e&&e[n.push]!=null&&e[n.push].forEach(function(e){c.push(a(t,n,e))})})})}),c.join(`\r
7
7
  `)+`\r
8
- `}})),Z=c((e=>{var t=Mt(),n=Nt();e.grammar=jt(),e.write=n,e.parse=t.parse,e.parseParams=t.parseParams,e.parseFmtpConfig=t.parseFmtpConfig,e.parsePayloads=t.parsePayloads,e.parseRemoteCandidates=t.parseRemoteCandidates,e.parseImageAttributes=t.parseImageAttributes,e.parseSimulcastStreamList=t.parseSimulcastStreamList})),Q=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}function i(e,t){return i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},i(e,t)}function a(e){var t=c();return function(){var n=l(e),r;if(t){var i=l(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}function o(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:s(e)}function s(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function c(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function u(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=d(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
9
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a=!0,o=!1,s;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{!a&&n.return!=null&&n.return()}finally{if(o)throw s}}}}function d(e,t){if(e){if(typeof e==`string`)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}function f(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function m(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t,n){return t&&m(e.prototype,t),n&&m(e,n),e}var g=Z(),_=X(),v=G(),y=J(),b=Et(),x=q(),S=new _(`SIPMessage`),C=function(){function e(t,n,r,i,a,o){if(p(this,e),!t||!n||!r)return null;i||={},this.ua=r,this.headers={},this.method=t,this.ruri=n,this.body=o,this.extraHeaders=y.cloneArray(a),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),i.route_set?this.setHeader(`route`,i.route_set):r.configuration.use_preloaded_route&&this.setHeader(`route`,`<${r.transport.sip_uri};lr>`),this.setHeader(`via`,``),this.setHeader(`max-forwards`,v.MAX_FORWARDS);var s=i.to_uri||n,c=i.to_tag?{tag:i.to_tag}:null,l=i.to_display_name===void 0?null:i.to_display_name;this.to=new b(s,l,c),this.setHeader(`to`,this.to.toString());var u=i.from_uri||r.configuration.uri,d={tag:i.from_tag||y.newTag()},f=i.from_display_name===void 0?r.configuration.display_name?r.configuration.display_name:null:i.from_display_name;this.from=new b(u,f,d),this.setHeader(`from`,this.from.toString());var m=i.call_id||r.configuration.jssip_id+y.createRandomToken(15);this.call_id=m,this.setHeader(`call-id`,m);var h=i.cseq||Math.floor(Math.random()*1e4);this.cseq=h,this.setHeader(`cseq`,`${h} ${t}`)}return h(e,[{key:`setHeader`,value:function(e,t){for(var n=RegExp(`^\\s*${e}\\s*:`,`i`),r=0;r<this.extraHeaders.length;r++)n.test(this.extraHeaders[r])&&this.extraHeaders.splice(r,1);this.headers[y.headerize(e)]=Array.isArray(t)?t:[t]}},{key:`getHeader`,value:function(e){var t=this.headers[y.headerize(e)];if(t){if(t[0])return t[0]}else{var n=RegExp(`^\\s*${e}\\s*:`,`i`),r=u(this.extraHeaders),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;if(n.test(a))return a.substring(a.indexOf(`:`)+1).trim()}}catch(e){r.e(e)}finally{r.f()}}}},{key:`getHeaders`,value:function(e){var t=this.headers[y.headerize(e)],n=[];if(t){var r=u(t),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;n.push(a)}}catch(e){r.e(e)}finally{r.f()}return n}var o=RegExp(`^\\s*${e}\\s*:`,`i`),s=u(this.extraHeaders),c;try{for(s.s();!(c=s.n()).done;){var l=c.value;o.test(l)&&n.push(l.substring(l.indexOf(`:`)+1).trim())}}catch(e){s.e(e)}finally{s.f()}return n}},{key:`hasHeader`,value:function(e){if(this.headers[y.headerize(e)])return!0;var t=RegExp(`^\\s*${e}\\s*:`,`i`),n=u(this.extraHeaders),r;try{for(n.s();!(r=n.n()).done;){var i=r.value;if(t.test(i))return!0}}catch(e){n.e(e)}finally{n.f()}return!1}},{key:`parseSDP`,value:function(e){return!e&&this.sdp||(this.sdp=g.parse(this.body||``)),this.sdp}},{key:`toString`,value:function(){var e=`${this.method} ${this.ruri} SIP/2.0\r
8
+ `}})),At=c((e=>{var t=Ot(),n=kt();e.grammar=X(),e.write=n,e.parse=t.parse,e.parseParams=t.parseParams,e.parseFmtpConfig=t.parseFmtpConfig,e.parsePayloads=t.parsePayloads,e.parseRemoteCandidates=t.parseRemoteCandidates,e.parseImageAttributes=t.parseImageAttributes,e.parseSimulcastStreamList=t.parseSimulcastStreamList})),Z=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}function i(e,t){return i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},i(e,t)}function a(e){var t=c();return function(){var n=l(e),r;if(t){var i=l(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}function o(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:s(e)}function s(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function c(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function u(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=d(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
9
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a=!0,o=!1,s;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{!a&&n.return!=null&&n.return()}finally{if(o)throw s}}}}function d(e,t){if(e){if(typeof e==`string`)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}function f(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function m(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t,n){return t&&m(e.prototype,t),n&&m(e,n),e}var g=At(),_=Y(),v=W(),y=q(),b=Ct(),x=K(),S=new _(`SIPMessage`),C=function(){function e(t,n,r,i,a,o){if(p(this,e),!t||!n||!r)return null;i||={},this.ua=r,this.headers={},this.method=t,this.ruri=n,this.body=o,this.extraHeaders=y.cloneArray(a),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),i.route_set?this.setHeader(`route`,i.route_set):r.configuration.use_preloaded_route&&this.setHeader(`route`,`<${r.transport.sip_uri};lr>`),this.setHeader(`via`,``),this.setHeader(`max-forwards`,v.MAX_FORWARDS);var s=i.to_uri||n,c=i.to_tag?{tag:i.to_tag}:null,l=i.to_display_name===void 0?null:i.to_display_name;this.to=new b(s,l,c),this.setHeader(`to`,this.to.toString());var u=i.from_uri||r.configuration.uri,d={tag:i.from_tag||y.newTag()},f=i.from_display_name===void 0?r.configuration.display_name?r.configuration.display_name:null:i.from_display_name;this.from=new b(u,f,d),this.setHeader(`from`,this.from.toString());var m=i.call_id||r.configuration.jssip_id+y.createRandomToken(15);this.call_id=m,this.setHeader(`call-id`,m);var h=i.cseq||Math.floor(Math.random()*1e4);this.cseq=h,this.setHeader(`cseq`,`${h} ${t}`)}return h(e,[{key:`setHeader`,value:function(e,t){for(var n=RegExp(`^\\s*${e}\\s*:`,`i`),r=0;r<this.extraHeaders.length;r++)n.test(this.extraHeaders[r])&&this.extraHeaders.splice(r,1);this.headers[y.headerize(e)]=Array.isArray(t)?t:[t]}},{key:`getHeader`,value:function(e){var t=this.headers[y.headerize(e)];if(t){if(t[0])return t[0]}else{var n=RegExp(`^\\s*${e}\\s*:`,`i`),r=u(this.extraHeaders),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;if(n.test(a))return a.substring(a.indexOf(`:`)+1).trim()}}catch(e){r.e(e)}finally{r.f()}}}},{key:`getHeaders`,value:function(e){var t=this.headers[y.headerize(e)],n=[];if(t){var r=u(t),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;n.push(a)}}catch(e){r.e(e)}finally{r.f()}return n}var o=RegExp(`^\\s*${e}\\s*:`,`i`),s=u(this.extraHeaders),c;try{for(s.s();!(c=s.n()).done;){var l=c.value;o.test(l)&&n.push(l.substring(l.indexOf(`:`)+1).trim())}}catch(e){s.e(e)}finally{s.f()}return n}},{key:`hasHeader`,value:function(e){if(this.headers[y.headerize(e)])return!0;var t=RegExp(`^\\s*${e}\\s*:`,`i`),n=u(this.extraHeaders),r;try{for(n.s();!(r=n.n()).done;){var i=r.value;if(t.test(i))return!0}}catch(e){n.e(e)}finally{n.f()}return!1}},{key:`parseSDP`,value:function(e){return!e&&this.sdp||(this.sdp=g.parse(this.body||``)),this.sdp}},{key:`toString`,value:function(){var e=`${this.method} ${this.ruri} SIP/2.0\r
10
10
  `;for(var t in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,t)){var n=u(this.headers[t]),r;try{for(n.s();!(r=n.n()).done;){var i=r.value;e+=`${t}: ${i}\r
11
11
  `}}catch(e){n.e(e)}finally{n.f()}}var a=u(this.extraHeaders),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;e+=`${s.trim()}\r
12
12
  `}}catch(e){a.e(e)}finally{a.f()}var c=[];switch(this.method){case v.REGISTER:c.push(`path`,`gruu`);break;case v.INVITE:this.ua.configuration.session_timers&&c.push(`timer`),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&c.push(`gruu`),c.push(`ice`,`replaces`);break;case v.UPDATE:this.ua.configuration.session_timers&&c.push(`timer`),c.push(`ice`)}c.push(`outbound`);var l=this.ua.configuration.user_agent||v.USER_AGENT;if(e+=`Allow: ${v.ALLOWED_METHODS}\r
@@ -43,11 +43,11 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
43
43
  `,this.ua.configuration.extra_headers){var c=u(this.ua.configuration.extra_headers),l;try{for(c.s();!(l=c.n()).done;){var d=l.value;r+=`${d.trim()}\r
44
44
  `}}catch(e){c.e(e)}finally{c.f()}}r+=`Content-Length: 0\r
45
45
  \r
46
- `,this.transport.send(r)}}]),n}(T),IncomingResponse:function(e){r(n,e);var t=a(n);function n(){var e;return p(this,n),e=t.call(this),e.headers={},e.status_code=null,e.reason_phrase=null,e}return n}(T)}})),Pt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=J(),s=new a(`DigestAuthentication`);t.exports=function(){function e(t){n(this,e),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex=`00000000`,this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return i(e,[{key:`get`,value:function(e){switch(e){case`realm`:return this._realm;case`ha1`:return this._ha1;default:s.warn(`get() | cannot get "%s" parameter`,e);return}}},{key:`authenticate`,value:function(e,t){var n=e.method,r=e.ruri,i=e.body,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=t.algorithm,this._realm=t.realm,this._nonce=t.nonce,this._opaque=t.opaque,this._stale=t.stale,this._algorithm){if(this._algorithm!==`MD5`)return s.warn(`authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted`),!1}else this._algorithm=`MD5`;if(!this._nonce)return s.warn(`authenticate() | challenge without Digest nonce, authentication aborted`),!1;if(!this._realm)return s.warn(`authenticate() | challenge without Digest realm, authentication aborted`),!1;if(!this._credentials.password){if(!this._credentials.ha1)return s.warn(`authenticate() | no plain SIP password nor ha1 provided, authentication aborted`),!1;if(this._credentials.realm!==this._realm)return s.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop){if(t.qop.indexOf(`auth-int`)>-1)this._qop=`auth-int`;else if(t.qop.indexOf(`auth`)>-1)this._qop=`auth`;else return s.warn(`authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted`),!1}else this._qop=null;this._method=n,this._uri=r,this._cnonce=a||o.createRandomToken(12),this._nc+=1;var c=Number(this._nc).toString(16);this._ncHex=`00000000`.substr(0,8-c.length)+c,this._nc===4294967296&&(this._nc=1,this._ncHex=`00000001`),this._ha1=this._credentials.password?o.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._credentials.ha1;var l,u;return this._qop===`auth`?(l=`${this._method}:${this._uri}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=auth [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${u}`)):this._qop===`auth-int`?(l=`${this._method}:${this._uri}:${o.calculateMD5(i||``)}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=auth-int [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${u}`)):this._qop===null&&(l=`${this._method}:${this._uri}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=null [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${u}`)),s.debug(`authenticate() | response generated`),!0}},{key:`toString`,value:function(){var e=[];if(!this._response)throw 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(`, `)}`}}]),e}()})),Ft=c(((e,t)=>{var n=500,r=4e3,i=5e3;t.exports={T1:n,T2:r,T4:i,TIMER_B:64*n,TIMER_D:0*n,TIMER_F:64*n,TIMER_H:64*n,TIMER_I:0*n,TIMER_J:0*n,TIMER_K:0*i,TIMER_L:64*n,TIMER_M:64*n,PROVISIONAL_RESPONSE_INTERVAL:6e4}})),It=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=Q(),_=Ft(),v=new m(`NonInviteClientTransaction`),y=new m(`InviteClientTransaction`),b=new m(`AckClientTransaction`),x=new m(`NonInviteServerTransaction`),S=new m(`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`},w=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.type=C.NON_INVITE_CLIENT,s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.ua=e,s.transport=i,s.request=a,s.eventHandlers=o;var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s.ua.newTransaction(u(s)),s}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`send`,value:function(){var e=this;this.stateChanged(C.STATUS_TRYING),this.F=setTimeout(function(){e.timer_F()},_.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){v.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()}},{key:`timer_F`,value:function(){v.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:`timer_K`,value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`receiveResponse`,value:function(e){var t=this,n=e.status_code;if(n<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),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(function(){t.timer_K()},_.TIMER_K);break;case C.STATUS_COMPLETED:}}},{key:`C`,get:function(){return C}}]),n}(p),T=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.type=C.INVITE_CLIENT,s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.ua=e,s.transport=i,s.request=a,s.eventHandlers=o,a.transaction=u(s);var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s.ua.newTransaction(u(s)),s}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`send`,value:function(){var e=this;this.stateChanged(C.STATUS_CALLING),this.B=setTimeout(function(){e.timer_B()},_.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==C.STATUS_ACCEPTED&&(y.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_M`,value:function(){y.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))}},{key:`timer_B`,value:function(){y.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())}},{key:`timer_D`,value:function(){y.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`sendACK`,value:function(e){var t=this,n=new g.OutgoingRequest(h.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders(`route`),call_id:this.request.getHeader(`call-id`),cseq:this.request.cseq});n.setHeader(`from`,this.request.getHeader(`from`)),n.setHeader(`via`,this.request.getHeader(`via`)),n.setHeader(`to`,e.getHeader(`to`)),this.D=setTimeout(function(){t.timer_D()},_.TIMER_D),this.transport.send(n)}},{key:`cancel`,value:function(e){if(this.state===C.STATUS_PROCEEDING){var t=new g.OutgoingRequest(h.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)}}},{key:`receiveResponse`,value:function(e){var t=this,n=e.status_code;if(n>=100&&n<=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(n>=200&&n<=299)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},_.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=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)}}},{key:`C`,get:function(){return C}}]),n}(p),E=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.transport=i,s.request=a,s.eventHandlers=o;var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s}return a(n,[{key:`send`,value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){b.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}},{key:`C`,get:function(){return C}}]),n}(p),D=function(e){o(n,e);var t=c(n);function n(e,i,a){var o;return r(this,n),o=t.call(this),o.type=C.NON_INVITE_SERVER,o.id=a.via_branch,o.ua=e,o.transport=i,o.request=a,o.last_response=``,a.server_transaction=u(o),o.state=C.STATUS_TRYING,e.newTransaction(u(o)),o}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`timer_J`,value:function(){x.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`onTransportError`,value:function(){this.transportError||(this.transportError=!0,x.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`receiveResponse`,value:function(e,t,n,r){var i=this;if(e===100)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(),r&&r())}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(function(){i.timer_J()},_.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case C.STATUS_COMPLETED:}}},{key:`C`,get:function(){return C}}]),n}(p),O=function(e){o(n,e);var t=c(n);function n(e,i,a){var o;return r(this,n),o=t.call(this),o.type=C.INVITE_SERVER,o.id=a.via_branch,o.ua=e,o.transport=i,o.request=a,o.last_response=``,a.server_transaction=u(o),o.state=C.STATUS_PROCEEDING,e.newTransaction(u(o)),o.resendProvisionalTimer=null,a.reply(100),o}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`timer_H`,value:function(){S.debug(`Timer H expired for transaction ${this.id}`),this.state===C.STATUS_COMPLETED&&S.debug(`ACK not received, dialog will be terminated`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_I`,value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_L`,value:function(){S.debug(`Timer L expired for transaction ${this.id}`),this.state===C.STATUS_ACCEPTED&&(this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`onTransportError`,value:function(){this.transportError||(this.transportError=!0,S.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`resend_provisional`,value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:`receiveResponse`,value:function(e,t,n,r){var i=this;if(e>=100&&e<=199)switch(this.state){case C.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===C.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){i.resend_provisional()},_.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(function(){i.timer_L()},_.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case C.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case C.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(C.STATUS_COMPLETED),this.H=setTimeout(function(){i.timer_H()},_.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:`C`,get:function(){return C}}]),n}(p);function k(e,t){var n=e._transactions,r;switch(t.method){case h.INVITE:if(r=n.ist[t.via_branch],r){switch(r.state){case C.STATUS_PROCEEDING:r.transport.send(r.last_response);break;case C.STATUS_ACCEPTED:}return!0}break;case h.ACK:if(r=n.ist[t.via_branch],r){if(r.state===C.STATUS_ACCEPTED)return!1;if(r.state===C.STATUS_COMPLETED)return r.state=C.STATUS_CONFIRMED,r.I=setTimeout(function(){r.timer_I()},_.TIMER_I),!0}else return!1;break;case h.CANCEL:return r=n.ist[t.via_branch],r?(t.reply_sl(200),r.state!==C.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(r=n.nist[t.via_branch],r){switch(r.state){case C.STATUS_TRYING:break;case C.STATUS_PROCEEDING:case C.STATUS_COMPLETED:r.transport.send(r.last_response)}return!0}}}t.exports={C,NonInviteClientTransaction:w,InviteClientTransaction:T,AckClientTransaction:E,NonInviteServerTransaction:D,InviteServerTransaction:O,checkTransaction:k}})),Lt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=G(),s=Pt(),c=It(),l=new a(`RequestSender`),u={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}};t.exports=function(){function e(t,r,i){for(var a in n(this,e),this._ua=t,this._eventHandlers=i,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1,u)Object.prototype.hasOwnProperty.call(u,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=u[a]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==o.BYE||this._method!==o.ACK)&&this._eventHandlers.onTransportError()}return i(e,[{key:`send`,value:function(){var e=this,t={onRequestTimeout:function(){e._eventHandlers.onRequestTimeout()},onTransportError:function(){e._eventHandlers.onTransportError()},onReceiveResponse:function(t){e._receiveResponse(t)}};switch(this._method){case`INVITE`:this.clientTransaction=new c.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case`ACK`:this.clientTransaction=new c.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new c.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader(`Authorization`,this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:`_receiveResponse`,value:function(e){var t,n,r=e.status_code;if((r===401||r===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(e.status_code===401?(t=e.parseHeader(`www-authenticate`),n=`authorization`):(t=e.parseHeader(`proxy-authenticate`),n=`proxy-authorization`),!t){l.debug(`${e.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(e);return}if(!this._challenged||!this._staled&&t.stale===!0){if(this._auth||=new s({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1}),!this._auth.authenticate(this._request,t)){this._eventHandlers.onReceiveResponse(e);return}this._challenged=!0,this._ua.set(`realm`,this._auth.get(`realm`)),this._ua.set(`ha1`,this._auth.get(`ha1`)),t.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader(`cseq`,`${this._request.cseq} ${this._method}`),this._request.setHeader(n,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}else this._eventHandlers.onReceiveResponse(e)}}]),e}()})),Rt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=J(),s=G(),c=Q(),l=Lt(),u=new a(`Registrator`),d=10;t.exports=function(){function e(t,r){n(this,e),this._reg_id=1,this._ua=t,this._transport=r,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=o.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=`;+sip.ice`,this._extraHeaders=[],this._extraContactParams=``,this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}return i(e,[{key:`setExtraHeaders`,value:function(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}},{key:`setExtraContactParams`,value:function(e){for(var t in e instanceof Object||(e={}),this._extraContactParams=``,e)if(Object.prototype.hasOwnProperty.call(e,t)){var n=e[t];this._extraContactParams+=`;${t}`,n&&(this._extraContactParams+=`=${n}`)}}},{key:`register`,value:function(){var e=this;if(this._registering){u.debug(`Register request in progress...`);return}var t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);var n=new c.OutgoingRequest(s.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new l(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,s.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,s.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(e._registrationTimer!==null&&(clearTimeout(e._registrationTimer),e._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):if(e._registering=!1,!t.hasHeader(`Contact`)){u.debug(`no Contact header in response to REGISTER, response ignored`);break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam(`+sip.instance`)&&e._reg_id===parseInt(t.getParam(`reg-id`))});if(r||=n.find(function(t){return t.uri.user===e._ua.contact.uri.user}),!r){u.debug(`no Contact header pointing to us, response ignored`);break}var i=r.getParam(`expires`);!i&&t.hasHeader(`expires`)&&(i=t.getHeader(`expires`)),i||=e._expires,i=Number(i),i<d&&(i=d);var a=i>64?i*1e3/2+Math.floor((i/2-32)*1e3*Math.random()):i*1e3-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,e._ua.listeners(`registrationExpiring`).length===0?e.register():e._ua.emit(`registrationExpiring`)},a),r.hasParam(`temp-gruu`)&&(e._ua.contact.temp_gruu=r.getParam(`temp-gruu`).replace(/"/g,``)),r.hasParam(`pub-gruu`)&&(e._ua.contact.pub_gruu=r.getParam(`pub-gruu`).replace(/"/g,``)),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader(`min-expires`)?(e._expires=Number(t.getHeader(`min-expires`)),e._expires<d&&(e._expires=d),e.register()):(u.debug(`423 response received for REGISTER without Min-Expires`),e._registrationFailure(t,s.causes.SIP_FAILURE_CODE));break;default:var c=o.sipErrorCause(t.status_code);e._registrationFailure(t,c)}}});this._registering=!0,r.send()}},{key:`unregister`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){u.debug(`already unregistered`);return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push(`Expires: 0`);var r=new c.OutgoingRequest(s.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new l(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,s.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,s.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):e._unregistered(t);break;default:var n=o.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}},{key:`close`,value:function(){this._registered&&this.unregister()}},{key:`onTransportClosed`,value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:`_registrationFailure`,value:function(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}))}},{key:`_unregistered`,value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:`registered`,get:function(){return this._registered}}]),e}()})),zt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=G(),o=It(),s=Lt(),c={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}};t.exports=function(){function e(t,r,i){for(var a in n(this,e),this._dialog=t,this._ua=t._ua,this._request=r,this._eventHandlers=i,this._reattempt=!1,this._reattemptTimer=null,c)Object.prototype.hasOwnProperty.call(c,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=c[a]))}return i(e,[{key:`send`,value:function(){var e=this,t=new s(this._ua,this._request,{onRequestTimeout:function(){e._eventHandlers.onRequestTimeout()},onTransportError:function(){e._eventHandlers.onTransportError()},onAuthenticated:function(t){e._eventHandlers.onAuthenticated(t)},onReceiveResponse:function(t){e._receiveResponse(t)}});t.send(),(this._request.method===a.INVITE||this._request.method===a.UPDATE&&this._request.body)&&t.clientTransaction.state!==o.C.STATUS_TERMINATED&&(this._dialog.uac_pending_reply=!0,t.clientTransaction.on(`stateChanged`,function n(){(t.clientTransaction.state===o.C.STATUS_ACCEPTED||t.clientTransaction.state===o.C.STATUS_COMPLETED||t.clientTransaction.state===o.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener(`stateChanged`,n),e._dialog.uac_pending_reply=!1)}))}},{key:`_receiveResponse`,value:function(e){var t=this;e.status_code===408||e.status_code===481?this._eventHandlers.onDialogError(e):e.method===a.INVITE&&e.status_code===491?this._reattempt?e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.isTerminated()||(t._reattempt=!0,t.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:`request`,get:function(){return this._request}}]),e}()})),Bt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=Q(),s=G(),c=It(),l=zt(),u=J(),d=new a(`Dialog`),f={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};t.exports=function(){i(e,null,[{key:`C`,get:function(){return f}}]);function e(t,r,i){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:f.STATUS_CONFIRMED;if(n(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!r.hasHeader(`contact`))return{error:`unable to create a Dialog without Contact header field`};r instanceof o.IncomingResponse&&(a=r.status_code<200?f.STATUS_EARLY:f.STATUS_CONFIRMED);var s=r.parseHeader(`contact`);i===`UAS`?(this._id={call_id:r.call_id,local_tag:r.to_tag,remote_tag:r.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=r.cseq,this._local_uri=r.parseHeader(`to`).uri,this._remote_uri=r.parseHeader(`from`).uri,this._remote_target=s.uri,this._route_set=r.getHeaders(`record-route`),this._ack_seqnum=this._remote_seqnum):i===`UAC`&&(this._id={call_id:r.call_id,local_tag:r.from_tag,remote_tag:r.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=r.cseq,this._local_uri=r.parseHeader(`from`).uri,this._remote_uri=r.parseHeader(`to`).uri,this._remote_target=s.uri,this._route_set=r.getHeaders(`record-route`).reverse(),this._ack_seqnum=null),this._ua.newDialog(this),d.debug(`new ${i} dialog created with status ${this._state===f.STATUS_EARLY?`EARLY`:`CONFIRMED`}`)}return i(e,[{key:`isTerminated`,value:function(){return this._status===f.STATUS_TERMINATED}},{key:`update`,value:function(e,t){this._state=f.STATUS_CONFIRMED,d.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t===`UAC`&&(this._route_set=e.getHeaders(`record-route`).reverse())}},{key:`terminate`,value:function(){d.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=f.STATUS_TERMINATED}},{key:`sendRequest`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=u.cloneArray(n.extraHeaders),i=u.cloneObject(n.eventHandlers),a=n.body||null,o=this._createRequest(e,r,a);return i.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,i).send(),o}},{key:`receiveRequest`,value:function(e){this._checkInDialogRequest(e)&&(e.method===s.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:e.method===s.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:`_createRequest`,value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||=Math.floor(Math.random()*1e4);var r=e===s.CANCEL||e===s.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:`_checkInDialogRequest`,value:function(e){var t=this;if(!this._remote_seqnum)this._remote_seqnum=e.cseq;else if(e.cseq<this._remote_seqnum){if(e.method===s.ACK){if(this._ack_seqnum===null||e.cseq!==this._ack_seqnum)return!1}else return e.reply(500),!1}else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);if(e.method===s.INVITE||e.method===s.UPDATE&&e.body){if(this._uac_pending_reply===!0)e.reply(491);else if(this._uas_pending_reply===!0){var n=(Math.random()*10|0)+1;return e.reply(500,null,[`Retry-After:${n}`]),!1}else this._uas_pending_reply=!0,e.server_transaction.on(`stateChanged`,function n(){(e.server_transaction.state===c.C.STATUS_ACCEPTED||e.server_transaction.state===c.C.STATUS_COMPLETED||e.server_transaction.state===c.C.STATUS_TERMINATED)&&(e.server_transaction.removeListener(`stateChanged`,n),t._uas_pending_reply=!1)});e.hasHeader(`contact`)&&e.server_transaction.on(`stateChanged`,function(){e.server_transaction.state===c.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader(`contact`).uri)})}else e.method===s.NOTIFY&&e.hasHeader(`contact`)&&e.server_transaction.on(`stateChanged`,function(){e.server_transaction.state===c.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader(`contact`).uri)});return!0}},{key:`id`,get:function(){return this._id}},{key:`local_seqnum`,get:function(){return this._local_seqnum},set:function(e){this._local_seqnum=e}},{key:`owner`,get:function(){return this._owner}},{key:`uac_pending_reply`,get:function(){return this._uac_pending_reply},set:function(e){this._uac_pending_reply=e}},{key:`uas_pending_reply`,get:function(){return this._uas_pending_reply}}]),e}()})),Vt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=K(),_=J(),v=new m(`RTCSession:DTMF`),y={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._session=e,i._direction=null,i._tone=null,i._duration=null,i._request=null,i}return a(n,[{key:`send`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e===void 0)throw TypeError(`Not enough arguments`);if(this._direction=`outgoing`,this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new g.InvalidStateError(this._session.status);var r=_.cloneArray(n.extraHeaders);if(this.eventHandlers=_.cloneObject(n.eventHandlers),typeof e==`string`)e=e.toUpperCase();else if(typeof e==`number`)e=e.toString();else throw TypeError(`Invalid tone: ${e}`);if(e.match(/^[0-9A-DR#*]$/))this._tone=e;else throw TypeError(`Invalid tone: ${e}`);this._duration=n.duration,r.push(`Content-Type: application/dtmf-relay`);var i=`Signal=${this._tone}\r
46
+ `,this.transport.send(r)}}]),n}(T),IncomingResponse:function(e){r(n,e);var t=a(n);function n(){var e;return p(this,n),e=t.call(this),e.headers={},e.status_code=null,e.reason_phrase=null,e}return n}(T)}})),jt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=q(),s=new a(`DigestAuthentication`);t.exports=function(){function e(t){n(this,e),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex=`00000000`,this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return i(e,[{key:`get`,value:function(e){switch(e){case`realm`:return this._realm;case`ha1`:return this._ha1;default:s.warn(`get() | cannot get "%s" parameter`,e);return}}},{key:`authenticate`,value:function(e,t){var n=e.method,r=e.ruri,i=e.body,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=t.algorithm,this._realm=t.realm,this._nonce=t.nonce,this._opaque=t.opaque,this._stale=t.stale,this._algorithm){if(this._algorithm!==`MD5`)return s.warn(`authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted`),!1}else this._algorithm=`MD5`;if(!this._nonce)return s.warn(`authenticate() | challenge without Digest nonce, authentication aborted`),!1;if(!this._realm)return s.warn(`authenticate() | challenge without Digest realm, authentication aborted`),!1;if(!this._credentials.password){if(!this._credentials.ha1)return s.warn(`authenticate() | no plain SIP password nor ha1 provided, authentication aborted`),!1;if(this._credentials.realm!==this._realm)return s.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop){if(t.qop.indexOf(`auth-int`)>-1)this._qop=`auth-int`;else if(t.qop.indexOf(`auth`)>-1)this._qop=`auth`;else return s.warn(`authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted`),!1}else this._qop=null;this._method=n,this._uri=r,this._cnonce=a||o.createRandomToken(12),this._nc+=1;var c=Number(this._nc).toString(16);this._ncHex=`00000000`.substr(0,8-c.length)+c,this._nc===4294967296&&(this._nc=1,this._ncHex=`00000001`),this._ha1=this._credentials.password?o.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._credentials.ha1;var l,u;return this._qop===`auth`?(l=`${this._method}:${this._uri}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=auth [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${u}`)):this._qop===`auth-int`?(l=`${this._method}:${this._uri}:${o.calculateMD5(i||``)}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=auth-int [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${u}`)):this._qop===null&&(l=`${this._method}:${this._uri}`,u=o.calculateMD5(l),s.debug(`authenticate() | using qop=null [a2:"%s"]`,l),this._response=o.calculateMD5(`${this._ha1}:${this._nonce}:${u}`)),s.debug(`authenticate() | response generated`),!0}},{key:`toString`,value:function(){var e=[];if(!this._response)throw 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(`, `)}`}}]),e}()})),Mt=c(((e,t)=>{var n=500,r=4e3,i=5e3;t.exports={T1:n,T2:r,T4:i,TIMER_B:64*n,TIMER_D:0*n,TIMER_F:64*n,TIMER_H:64*n,TIMER_I:0*n,TIMER_J:0*n,TIMER_K:0*i,TIMER_L:64*n,TIMER_M:64*n,PROVISIONAL_RESPONSE_INTERVAL:6e4}})),Q=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=Z(),_=Mt(),v=new m(`NonInviteClientTransaction`),y=new m(`InviteClientTransaction`),b=new m(`AckClientTransaction`),x=new m(`NonInviteServerTransaction`),S=new m(`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`},w=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.type=C.NON_INVITE_CLIENT,s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.ua=e,s.transport=i,s.request=a,s.eventHandlers=o;var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s.ua.newTransaction(u(s)),s}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`send`,value:function(){var e=this;this.stateChanged(C.STATUS_TRYING),this.F=setTimeout(function(){e.timer_F()},_.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){v.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()}},{key:`timer_F`,value:function(){v.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:`timer_K`,value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`receiveResponse`,value:function(e){var t=this,n=e.status_code;if(n<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),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(function(){t.timer_K()},_.TIMER_K);break;case C.STATUS_COMPLETED:}}},{key:`C`,get:function(){return C}}]),n}(p),T=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.type=C.INVITE_CLIENT,s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.ua=e,s.transport=i,s.request=a,s.eventHandlers=o,a.transaction=u(s);var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s.ua.newTransaction(u(s)),s}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`send`,value:function(){var e=this;this.stateChanged(C.STATUS_CALLING),this.B=setTimeout(function(){e.timer_B()},_.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==C.STATUS_ACCEPTED&&(y.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_M`,value:function(){y.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))}},{key:`timer_B`,value:function(){y.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())}},{key:`timer_D`,value:function(){y.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`sendACK`,value:function(e){var t=this,n=new g.OutgoingRequest(h.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders(`route`),call_id:this.request.getHeader(`call-id`),cseq:this.request.cseq});n.setHeader(`from`,this.request.getHeader(`from`)),n.setHeader(`via`,this.request.getHeader(`via`)),n.setHeader(`to`,e.getHeader(`to`)),this.D=setTimeout(function(){t.timer_D()},_.TIMER_D),this.transport.send(n)}},{key:`cancel`,value:function(e){if(this.state===C.STATUS_PROCEEDING){var t=new g.OutgoingRequest(h.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)}}},{key:`receiveResponse`,value:function(e){var t=this,n=e.status_code;if(n>=100&&n<=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(n>=200&&n<=299)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},_.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=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)}}},{key:`C`,get:function(){return C}}]),n}(p),E=function(e){o(n,e);var t=c(n);function n(e,i,a,o){var s;r(this,n),s=t.call(this),s.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,s.transport=i,s.request=a,s.eventHandlers=o;var c=`SIP/2.0/${i.via_transport}`;return c+=` ${e.configuration.via_host};branch=${s.id}`,s.request.setHeader(`via`,c),s}return a(n,[{key:`send`,value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:`onTransportError`,value:function(){b.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}},{key:`C`,get:function(){return C}}]),n}(p),D=function(e){o(n,e);var t=c(n);function n(e,i,a){var o;return r(this,n),o=t.call(this),o.type=C.NON_INVITE_SERVER,o.id=a.via_branch,o.ua=e,o.transport=i,o.request=a,o.last_response=``,a.server_transaction=u(o),o.state=C.STATUS_TRYING,e.newTransaction(u(o)),o}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`timer_J`,value:function(){x.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`onTransportError`,value:function(){this.transportError||(this.transportError=!0,x.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`receiveResponse`,value:function(e,t,n,r){var i=this;if(e===100)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(),r&&r())}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(function(){i.timer_J()},_.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case C.STATUS_COMPLETED:}}},{key:`C`,get:function(){return C}}]),n}(p),O=function(e){o(n,e);var t=c(n);function n(e,i,a){var o;return r(this,n),o=t.call(this),o.type=C.INVITE_SERVER,o.id=a.via_branch,o.ua=e,o.transport=i,o.request=a,o.last_response=``,a.server_transaction=u(o),o.state=C.STATUS_PROCEEDING,e.newTransaction(u(o)),o.resendProvisionalTimer=null,a.reply(100),o}return a(n,[{key:`stateChanged`,value:function(e){this.state=e,this.emit(`stateChanged`)}},{key:`timer_H`,value:function(){S.debug(`Timer H expired for transaction ${this.id}`),this.state===C.STATUS_COMPLETED&&S.debug(`ACK not received, dialog will be terminated`),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_I`,value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:`timer_L`,value:function(){S.debug(`Timer L expired for transaction ${this.id}`),this.state===C.STATUS_ACCEPTED&&(this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`onTransportError`,value:function(){this.transportError||(this.transportError=!0,S.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:`resend_provisional`,value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:`receiveResponse`,value:function(e,t,n,r){var i=this;if(e>=100&&e<=199)switch(this.state){case C.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===C.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){i.resend_provisional()},_.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(function(){i.timer_L()},_.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case C.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case C.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(C.STATUS_COMPLETED),this.H=setTimeout(function(){i.timer_H()},_.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:`C`,get:function(){return C}}]),n}(p);function k(e,t){var n=e._transactions,r;switch(t.method){case h.INVITE:if(r=n.ist[t.via_branch],r){switch(r.state){case C.STATUS_PROCEEDING:r.transport.send(r.last_response);break;case C.STATUS_ACCEPTED:}return!0}break;case h.ACK:if(r=n.ist[t.via_branch],r){if(r.state===C.STATUS_ACCEPTED)return!1;if(r.state===C.STATUS_COMPLETED)return r.state=C.STATUS_CONFIRMED,r.I=setTimeout(function(){r.timer_I()},_.TIMER_I),!0}else return!1;break;case h.CANCEL:return r=n.ist[t.via_branch],r?(t.reply_sl(200),r.state!==C.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(r=n.nist[t.via_branch],r){switch(r.state){case C.STATUS_TRYING:break;case C.STATUS_PROCEEDING:case C.STATUS_COMPLETED:r.transport.send(r.last_response)}return!0}}}t.exports={C,NonInviteClientTransaction:w,InviteClientTransaction:T,AckClientTransaction:E,NonInviteServerTransaction:D,InviteServerTransaction:O,checkTransaction:k}})),Nt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=W(),s=jt(),c=Q(),l=new a(`RequestSender`),u={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}};t.exports=function(){function e(t,r,i){for(var a in n(this,e),this._ua=t,this._eventHandlers=i,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1,u)Object.prototype.hasOwnProperty.call(u,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=u[a]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==o.BYE||this._method!==o.ACK)&&this._eventHandlers.onTransportError()}return i(e,[{key:`send`,value:function(){var e=this,t={onRequestTimeout:function(){e._eventHandlers.onRequestTimeout()},onTransportError:function(){e._eventHandlers.onTransportError()},onReceiveResponse:function(t){e._receiveResponse(t)}};switch(this._method){case`INVITE`:this.clientTransaction=new c.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case`ACK`:this.clientTransaction=new c.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new c.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader(`Authorization`,this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:`_receiveResponse`,value:function(e){var t,n,r=e.status_code;if((r===401||r===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(e.status_code===401?(t=e.parseHeader(`www-authenticate`),n=`authorization`):(t=e.parseHeader(`proxy-authenticate`),n=`proxy-authorization`),!t){l.debug(`${e.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(e);return}if(!this._challenged||!this._staled&&t.stale===!0){if(this._auth||=new s({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1}),!this._auth.authenticate(this._request,t)){this._eventHandlers.onReceiveResponse(e);return}this._challenged=!0,this._ua.set(`realm`,this._auth.get(`realm`)),this._ua.set(`ha1`,this._auth.get(`ha1`)),t.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader(`cseq`,`${this._request.cseq} ${this._method}`),this._request.setHeader(n,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}else this._eventHandlers.onReceiveResponse(e)}}]),e}()})),Pt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=q(),s=W(),c=Z(),l=Nt(),u=new a(`Registrator`),d=10;t.exports=function(){function e(t,r){n(this,e),this._reg_id=1,this._ua=t,this._transport=r,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=o.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=`;+sip.ice`,this._extraHeaders=[],this._extraContactParams=``,this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}return i(e,[{key:`setExtraHeaders`,value:function(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}},{key:`setExtraContactParams`,value:function(e){for(var t in e instanceof Object||(e={}),this._extraContactParams=``,e)if(Object.prototype.hasOwnProperty.call(e,t)){var n=e[t];this._extraContactParams+=`;${t}`,n&&(this._extraContactParams+=`=${n}`)}}},{key:`register`,value:function(){var e=this;if(this._registering){u.debug(`Register request in progress...`);return}var t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);var n=new c.OutgoingRequest(s.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new l(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,s.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,s.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(e._registrationTimer!==null&&(clearTimeout(e._registrationTimer),e._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):if(e._registering=!1,!t.hasHeader(`Contact`)){u.debug(`no Contact header in response to REGISTER, response ignored`);break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam(`+sip.instance`)&&e._reg_id===parseInt(t.getParam(`reg-id`))});if(r||=n.find(function(t){return t.uri.user===e._ua.contact.uri.user}),!r){u.debug(`no Contact header pointing to us, response ignored`);break}var i=r.getParam(`expires`);!i&&t.hasHeader(`expires`)&&(i=t.getHeader(`expires`)),i||=e._expires,i=Number(i),i<d&&(i=d);var a=i>64?i*1e3/2+Math.floor((i/2-32)*1e3*Math.random()):i*1e3-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,e._ua.listeners(`registrationExpiring`).length===0?e.register():e._ua.emit(`registrationExpiring`)},a),r.hasParam(`temp-gruu`)&&(e._ua.contact.temp_gruu=r.getParam(`temp-gruu`).replace(/"/g,``)),r.hasParam(`pub-gruu`)&&(e._ua.contact.pub_gruu=r.getParam(`pub-gruu`).replace(/"/g,``)),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader(`min-expires`)?(e._expires=Number(t.getHeader(`min-expires`)),e._expires<d&&(e._expires=d),e.register()):(u.debug(`423 response received for REGISTER without Min-Expires`),e._registrationFailure(t,s.causes.SIP_FAILURE_CODE));break;default:var c=o.sipErrorCause(t.status_code);e._registrationFailure(t,c)}}});this._registering=!0,r.send()}},{key:`unregister`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){u.debug(`already unregistered`);return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push(`Expires: 0`);var r=new c.OutgoingRequest(s.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new l(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,s.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,s.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):e._unregistered(t);break;default:var n=o.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}},{key:`close`,value:function(){this._registered&&this.unregister()}},{key:`onTransportClosed`,value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:`_registrationFailure`,value:function(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}))}},{key:`_unregistered`,value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:`registered`,get:function(){return this._registered}}]),e}()})),Ft=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=W(),o=Q(),s=Nt(),c={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}};t.exports=function(){function e(t,r,i){for(var a in n(this,e),this._dialog=t,this._ua=t._ua,this._request=r,this._eventHandlers=i,this._reattempt=!1,this._reattemptTimer=null,c)Object.prototype.hasOwnProperty.call(c,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=c[a]))}return i(e,[{key:`send`,value:function(){var e=this,t=new s(this._ua,this._request,{onRequestTimeout:function(){e._eventHandlers.onRequestTimeout()},onTransportError:function(){e._eventHandlers.onTransportError()},onAuthenticated:function(t){e._eventHandlers.onAuthenticated(t)},onReceiveResponse:function(t){e._receiveResponse(t)}});t.send(),(this._request.method===a.INVITE||this._request.method===a.UPDATE&&this._request.body)&&t.clientTransaction.state!==o.C.STATUS_TERMINATED&&(this._dialog.uac_pending_reply=!0,t.clientTransaction.on(`stateChanged`,function n(){(t.clientTransaction.state===o.C.STATUS_ACCEPTED||t.clientTransaction.state===o.C.STATUS_COMPLETED||t.clientTransaction.state===o.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener(`stateChanged`,n),e._dialog.uac_pending_reply=!1)}))}},{key:`_receiveResponse`,value:function(e){var t=this;e.status_code===408||e.status_code===481?this._eventHandlers.onDialogError(e):e.method===a.INVITE&&e.status_code===491?this._reattempt?e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.isTerminated()||(t._reattempt=!0,t.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:`request`,get:function(){return this._request}}]),e}()})),It=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=Z(),s=W(),c=Q(),l=Ft(),u=q(),d=new a(`Dialog`),f={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};t.exports=function(){i(e,null,[{key:`C`,get:function(){return f}}]);function e(t,r,i){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:f.STATUS_CONFIRMED;if(n(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!r.hasHeader(`contact`))return{error:`unable to create a Dialog without Contact header field`};r instanceof o.IncomingResponse&&(a=r.status_code<200?f.STATUS_EARLY:f.STATUS_CONFIRMED);var s=r.parseHeader(`contact`);i===`UAS`?(this._id={call_id:r.call_id,local_tag:r.to_tag,remote_tag:r.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=r.cseq,this._local_uri=r.parseHeader(`to`).uri,this._remote_uri=r.parseHeader(`from`).uri,this._remote_target=s.uri,this._route_set=r.getHeaders(`record-route`),this._ack_seqnum=this._remote_seqnum):i===`UAC`&&(this._id={call_id:r.call_id,local_tag:r.from_tag,remote_tag:r.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=r.cseq,this._local_uri=r.parseHeader(`from`).uri,this._remote_uri=r.parseHeader(`to`).uri,this._remote_target=s.uri,this._route_set=r.getHeaders(`record-route`).reverse(),this._ack_seqnum=null),this._ua.newDialog(this),d.debug(`new ${i} dialog created with status ${this._state===f.STATUS_EARLY?`EARLY`:`CONFIRMED`}`)}return i(e,[{key:`isTerminated`,value:function(){return this._status===f.STATUS_TERMINATED}},{key:`update`,value:function(e,t){this._state=f.STATUS_CONFIRMED,d.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),t===`UAC`&&(this._route_set=e.getHeaders(`record-route`).reverse())}},{key:`terminate`,value:function(){d.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=f.STATUS_TERMINATED}},{key:`sendRequest`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=u.cloneArray(n.extraHeaders),i=u.cloneObject(n.eventHandlers),a=n.body||null,o=this._createRequest(e,r,a);return i.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,i).send(),o}},{key:`receiveRequest`,value:function(e){this._checkInDialogRequest(e)&&(e.method===s.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:e.method===s.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:`_createRequest`,value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||=Math.floor(Math.random()*1e4);var r=e===s.CANCEL||e===s.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:`_checkInDialogRequest`,value:function(e){var t=this;if(!this._remote_seqnum)this._remote_seqnum=e.cseq;else if(e.cseq<this._remote_seqnum){if(e.method===s.ACK){if(this._ack_seqnum===null||e.cseq!==this._ack_seqnum)return!1}else return e.reply(500),!1}else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);if(e.method===s.INVITE||e.method===s.UPDATE&&e.body){if(this._uac_pending_reply===!0)e.reply(491);else if(this._uas_pending_reply===!0){var n=(Math.random()*10|0)+1;return e.reply(500,null,[`Retry-After:${n}`]),!1}else this._uas_pending_reply=!0,e.server_transaction.on(`stateChanged`,function n(){(e.server_transaction.state===c.C.STATUS_ACCEPTED||e.server_transaction.state===c.C.STATUS_COMPLETED||e.server_transaction.state===c.C.STATUS_TERMINATED)&&(e.server_transaction.removeListener(`stateChanged`,n),t._uas_pending_reply=!1)});e.hasHeader(`contact`)&&e.server_transaction.on(`stateChanged`,function(){e.server_transaction.state===c.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader(`contact`).uri)})}else e.method===s.NOTIFY&&e.hasHeader(`contact`)&&e.server_transaction.on(`stateChanged`,function(){e.server_transaction.state===c.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader(`contact`).uri)});return!0}},{key:`id`,get:function(){return this._id}},{key:`local_seqnum`,get:function(){return this._local_seqnum},set:function(e){this._local_seqnum=e}},{key:`owner`,get:function(){return this._owner}},{key:`uac_pending_reply`,get:function(){return this._uac_pending_reply},set:function(e){this._uac_pending_reply=e}},{key:`uas_pending_reply`,get:function(){return this._uas_pending_reply}}]),e}()})),Lt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=G(),_=q(),v=new m(`RTCSession:DTMF`),y={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._session=e,i._direction=null,i._tone=null,i._duration=null,i._request=null,i}return a(n,[{key:`send`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e===void 0)throw TypeError(`Not enough arguments`);if(this._direction=`outgoing`,this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new g.InvalidStateError(this._session.status);var r=_.cloneArray(n.extraHeaders);if(this.eventHandlers=_.cloneObject(n.eventHandlers),typeof e==`string`)e=e.toUpperCase();else if(typeof e==`number`)e=e.toString();else throw TypeError(`Invalid tone: ${e}`);if(e.match(/^[0-9A-DR#*]$/))this._tone=e;else throw TypeError(`Invalid tone: ${e}`);this._duration=n.duration,r.push(`Content-Type: application/dtmf-relay`);var i=`Signal=${this._tone}\r
47
47
  `;i+=`Duration=${this._duration}`,this._session.newDTMF({originator:`local`,dtmf:this,request:this._request}),this._session.sendRequest(h.INFO,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t.emit(`succeeded`,{originator:`remote`,response:e})},onErrorResponse:function(e){t.eventHandlers.onFailed&&t.eventHandlers.onFailed(),t.emit(`failed`,{originator:`remote`,response:e})},onRequestTimeout:function(){t._session.onRequestTimeout()},onTransportError:function(){t._session.onTransportError()},onDialogError:function(){t._session.onDialogError()}},body:i})}},{key:`init_incoming`,value:function(e){var 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){var r=e.body.split(`
48
- `);r.length>=1&&t.test(r[0])&&(this._tone=r[0].replace(t,`$2`)),r.length>=2&&n.test(r[1])&&(this._duration=parseInt(r[1].replace(n,`$2`),10))}this._duration||=y.DEFAULT_DURATION,this._tone?this._session.newDTMF({originator:`remote`,dtmf:this,request:e}):v.debug(`invalid INFO DTMF received, discarded`)}},{key:`tone`,get:function(){return this._tone}},{key:`duration`,get:function(){return this._duration}}]),n}(p),t.exports.C=y})),Ht=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=G(),h=K(),g=J();t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._session=e,i._direction=null,i._contentType=null,i._body=null,i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction=`outgoing`,e===void 0)throw 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 h.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var i=g.cloneArray(r.extraHeaders);i.push(`Content-Type: ${e}`),this._session.newInfo({originator:`local`,info:this,request:this.request}),this._session.sendRequest(m.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:function(e){n.emit(`succeeded`,{originator:`remote`,response:e})},onErrorResponse:function(e){n.emit(`failed`,{originator:`remote`,response:e})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:`init_incoming`,value:function(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})}},{key:`contentType`,get:function(){return this._contentType}},{key:`body`,get:function(){return this._body}}]),n}(p)})),Ut=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=G(),s=new a(`RTCSession:ReferNotifier`),c={event_type:`refer`,body_type:`message/sipfrag;version=2.0`,expires:300};t.exports=function(){function e(t,r,i){n(this,e),this._session=t,this._id=r,this._expires=i||c.expires,this._active=!0,this.notify(100)}return i(e,[{key:`notify`,value:function(e,t){if(s.debug(`notify()`),this._active!==!1){t=t||o.REASON_PHRASE[e]||``;var n=e>=200?`terminated;reason=noresource`:`active;expires=${this._expires}`;this._session.sendRequest(o.NOTIFY,{extraHeaders:[`Event: ${c.event_type};id=${this._id}`,`Subscription-State: ${n}`,`Content-Type: ${c.body_type}`],body:`SIP/2.0 ${e} ${t}`,eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),e}()})),Wt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=q(),_=J(),v=new m(`RTCSession:ReferSubscriber`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._id=null,i._session=e,i}return a(n,[{key:`sendRefer`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};v.debug(`sendRefer()`);var r=_.cloneArray(n.extraHeaders),i=_.cloneObject(n.eventHandlers);for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&this.on(a,i[a]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=`;to-tag=${n.replaces._to_tag}`,o+=`;from-tag=${n.replaces._from_tag}`,o=encodeURIComponent(o));var s=`Refer-To: <${e}${o?`?Replaces=${o}`:``}>`;if(r.push(s),!r.some(function(e){return e.toLowerCase().startsWith(`referred-by:`)})){var c=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;r.push(c)}r.push(`Contact: ${this._session.contact}`);var l=this._session.sendRequest(h.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,h.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,h.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,h.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,h.causes.DIALOG_ERROR)}}});this._id=l.cseq}},{key:`receiveNotify`,value:function(e){if(v.debug(`receiveNotify()`),e.body){var t=g.parse(e.body.trim().split(`\r
49
- `,1)[0],`Status_Line`);if(t===-1){v.debug(`receiveNotify() | error parsing NOTIFY body: "${e.body}"`);return}switch(!0){case/^100$/.test(t.status_code):this.emit(`trying`,{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit(`progress`,{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit(`accepted`,{request:e,status_line:t});break;default:this.emit(`failed`,{request:e,status_line:t})}}}},{key:`_requestSucceeded`,value:function(e){v.debug(`REFER succeeded`),v.debug(`emit "requestSucceeded"`),this.emit(`requestSucceeded`,{response:e})}},{key:`_requestFailed`,value:function(e,t){v.debug(`REFER failed`),v.debug(`emit "requestFailed"`),this.emit(`requestFailed`,{response:e||null,cause:t})}},{key:`id`,get:function(){return this._id}}]),n}(p)})),Gt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=i(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
50
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function i(e,t){if(e){if(typeof e==`string`)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}}function a(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function d(e){var t=m();return function(){var n=h(e),r;if(t){var i=h(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return f(this,r)}}function f(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:p(e)}function p(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function m(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var g=Y().EventEmitter,_=Z(),v=X(),y=G(),b=K(),x=It(),S=J(),C=Ft(),w=Q(),T=Bt(),E=Lt(),D=Vt(),O=Ht(),k=Ut(),A=Wt(),j=Dt(),M=new v(`RTCSession`),N={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},P=[`audio`,`video`];t.exports=function(e){l(n,e);var t=d(n);c(n,null,[{key:`C`,get:function(){return N}}]);function n(e){var r;return o(this,n),M.debug(`new`),r=t.call(this),r._id=null,r._ua=e,r._status=N.STATUS_NULL,r._dialog=null,r._earlyDialogs={},r._contact=null,r._from_tag=null,r._to_tag=null,r._connection=null,r._connectionPromiseQueue=Promise.resolve(),r._request=null,r._is_canceled=!1,r._cancel_reason=``,r._is_confirmed=!1,r._late_sdp=!1,r._rtcOfferConstraints=null,r._rtcAnswerConstraints=null,r._localMediaStream=null,r._localMediaStreamLocallyGenerated=!1,r._rtcReady=!0,r._iceReady=!1,r._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},r._direction=null,r._local_identity=null,r._remote_identity=null,r._start_time=null,r._end_time=null,r._tones=null,r._audioMuted=!1,r._videoMuted=!1,r._localHold=!1,r._remoteHold=!1,r._sessionTimers={enabled:r._ua.configuration.session_timers,refreshMethod:r._ua.configuration.session_timers_refresh_method,defaultExpires:y.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},r._referSubscribers={},r._data={},r}return c(n,[{key:`isInProgress`,value:function(){switch(this._status){case N.STATUS_NULL:case N.STATUS_INVITE_SENT:case N.STATUS_1XX_RECEIVED:case N.STATUS_INVITE_RECEIVED:case N.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:`isEstablished`,value:function(){switch(this._status){case N.STATUS_ANSWERED:case N.STATUS_WAITING_FOR_ACK:case N.STATUS_CONFIRMED:return!0;default:return!1}}},{key:`isEnded`,value:function(){switch(this._status){case N.STATUS_CANCELED:case N.STATUS_TERMINATED:return!0;default:return!1}}},{key:`isMuted`,value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:`isOnHold`,value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:`connect`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;M.debug(`connect()`);var r=e,i=S.cloneObject(t.eventHandlers),a=S.cloneArray(t.extraHeaders),o=S.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),s=t.mediaStream||null,c=S.cloneObject(t.pcConfig,{iceServers:[]}),l=t.rtcConstraints||null,u=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=u,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,e===void 0)throw TypeError(`Not enough arguments`);if(this._status!==N.STATUS_NULL)throw new b.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new b.NotSupportedError(`WebRTC not supported`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${r}`);for(var d in this._sessionTimers.enabled&&S.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=y.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=y.SESSION_EXPIRES),i)Object.prototype.hasOwnProperty.call(i,d)&&this.on(d,i[d]);this._from_tag=S.newTag();var f=t.anonymous||!1,p={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:f,outbound:!0}),f?(p.from_display_name=`Anonymous`,p.from_uri=new j(`sip`,`anonymous`,`anonymous.invalid`),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),a.push(`Privacy: id`)):t.fromUserName&&(p.from_uri=new j(`sip`,t.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(p.from_display_name=t.fromDisplayName),a.push(`Contact: ${this._contact}`),a.push(`Content-Type: application/sdp`),this._sessionTimers.enabled&&a.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?`;refresher=uac`:``}`),this._request=new w.InitialOutgoingInviteRequest(e,this._ua,p,a),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(c,l),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(o,u,s)}},{key:`init_incoming`,value:function(e,t){var n=this;M.debug(`init_incoming()`);var r,i=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0;if(e.body&&i!==`application/sdp`){e.reply(415);return}if(this._status=N.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader(`expires`)&&(r=e.getHeader(`expires`)*1e3),e.to_tag=S.newTag(),!this._createDialog(e,`UAS`,!0)){e.reply(500,`Missing Contact header field`);return}this._late_sdp=!e.body,this._status=N.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),n._failed(`local`,null,y.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),r&&(this._timers.expiresTimer=setTimeout(function(){n._status===N.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),n._failed(`system`,null,y.causes.EXPIRES))},r)),this._direction=`incoming`,this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession(`remote`,e),this._status!==N.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._contact}`]),this._progress(`local`,null))}},{key:`answer`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`answer()`);var n=this._request,i=S.cloneArray(t.extraHeaders),a=S.cloneObject(t.mediaConstraints),o=t.mediaStream||null,s=S.cloneObject(t.pcConfig,{iceServers:[]}),c=t.rtcConstraints||null,l=t.rtcAnswerConstraints||null,u=S.cloneObject(t.rtcOfferConstraints),d,f=!1,p=!1,m=!1,h=!1;if(this._rtcAnswerConstraints=l,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!==`incoming`)throw new b.NotSupportedError(`"answer" not supported for outgoing RTCSession`);if(this._status!==N.STATUS_WAITING_FOR_ANSWER)throw new b.InvalidStateError(this._status);if(this._sessionTimers.enabled&&S.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=y.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=y.SESSION_EXPIRES),this._status=N.STATUS_ANSWERED,!this._createDialog(n,`UAS`)){n.reply(500,`Error creating dialog`);return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);var g=n.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);var _=r(g.media),v;try{for(_.s();!(v=_.n()).done;){var x=v.value;x.type===`audio`&&(f=!0,(!x.direction||x.direction===`sendrecv`)&&(m=!0)),x.type===`video`&&(p=!0,(!x.direction||x.direction===`sendrecv`)&&(h=!0))}}catch(e){_.e(e)}finally{_.f()}if(o&&a.audio===!1){d=o.getAudioTracks();var C=r(d),w;try{for(C.s();!(w=C.n()).done;){var T=w.value;o.removeTrack(T)}}catch(e){C.e(e)}finally{C.f()}}if(o&&a.video===!1){d=o.getVideoTracks();var E=r(d),D;try{for(E.s();!(D=E.n()).done;){var O=D.value;o.removeTrack(O)}}catch(e){E.e(e)}finally{E.f()}}!o&&a.audio===void 0&&(a.audio=m),!o&&a.video===void 0&&(a.video=h),!o&&!f&&!u.offerToReceiveAudio&&(a.audio=!1),!o&&!p&&!u.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(s,c),Promise.resolve().then(function(){if(o)return o;if(a.audio||a.video)return e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(function(t){throw e._status===N.STATUS_TERMINATED?Error(`terminated`):(n.reply(480),e._failed(`local`,null,y.causes.USER_DENIED_MEDIA_ACCESS),M.warn(`emit "getusermediafailed" [error:%o]`,t),e.emit(`getusermediafailed`,t),Error(`getUserMedia() failed`))})}).then(function(t){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:`remote`,type:`offer`,sdp:n.body};M.debug(`emit "sdp"`),e.emit(`sdp`,t);var r=new RTCSessionDescription({type:`offer`,sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed(`system`,null,y.causes.WEBRTC_ERROR),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,t),e.emit(`peerconnection:setremotedescriptionfailed`,t),Error(`peerconnection.setRemoteDescription() failed`)}),e._connectionPromiseQueue}}).then(function(){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);return e._connecting(n),e._late_sdp?e._createLocalDescription(`offer`,e._rtcOfferConstraints).catch(function(){throw n.reply(500),Error(`_createLocalDescription() failed`)}):e._createLocalDescription(`answer`,l).catch(function(){throw n.reply(500),Error(`_createLocalDescription() failed`)})}).then(function(t){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);e._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,t,function(){e._status=N.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted(`local`)},function(){e._failed(`system`,null,y.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==N.STATUS_TERMINATED&&M.warn(t)})}},{key:`terminate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`terminate()`);var n=t.cause||y.causes.BYE,r=S.cloneArray(t.extraHeaders),i=t.body,a,o=t.status_code,s=t.reason_phrase;if(this._status===N.STATUS_TERMINATED)throw new b.InvalidStateError(this._status);switch(this._status){case N.STATUS_NULL:case N.STATUS_INVITE_SENT:case N.STATUS_1XX_RECEIVED:if(M.debug(`canceling session`),o&&(o<200||o>=700))throw TypeError(`Invalid status_code: ${o}`);o&&(s=s||y.REASON_PHRASE[o]||``,a=`SIP ;cause=${o} ;text="${s}"`),this._status===N.STATUS_NULL||this._status===N.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=a):this._status===N.STATUS_1XX_RECEIVED&&this._request.cancel(a),this._status=N.STATUS_CANCELED,this._failed(`local`,null,y.causes.CANCELED);break;case N.STATUS_WAITING_FOR_ANSWER:case N.STATUS_ANSWERED:if(M.debug(`rejecting session`),o||=480,o<300||o>=700)throw TypeError(`Invalid status_code: ${o}`);this._request.reply(o,s,r,i),this._failed(`local`,null,y.causes.REJECTED);break;case N.STATUS_WAITING_FOR_ACK:case N.STATUS_CONFIRMED:if(M.debug(`terminating session`),s=t.reason_phrase||y.REASON_PHRASE[o]||``,o&&(o<200||o>=700))throw TypeError(`Invalid status_code: ${o}`);if(o&&r.push(`Reason: SIP ;cause=${o}; text="${s}"`),this._status===N.STATUS_WAITING_FOR_ACK&&this._direction===`incoming`&&this._request.server_transaction.state!==x.C.STATUS_TERMINATED){var c=this._dialog;this.receiveRequest=function(t){t.method===y.ACK&&(e.sendRequest(y.BYE,{extraHeaders:r,body:i}),c.terminate())},this._request.server_transaction.on(`stateChanged`,function(){e._request.server_transaction.state===x.C.STATUS_TERMINATED&&(e.sendRequest(y.BYE,{extraHeaders:r,body:i}),c.terminate())}),this._ended(`local`,null,n),this._dialog=c,this._ua.newDialog(c)}else this.sendRequest(y.BYE,{extraHeaders:r,body:i}),this._ended(`local`,null,n)}}},{key:`sendDTMF`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};M.debug(`sendDTMF() | tones: %s`,e);var n=0,r=t.duration||null,i=t.interToneGap||null,a=t.transportType||y.DTMF_TRANSPORT.INFO;if(e===void 0)throw TypeError(`Not enough arguments`);if(this._status!==N.STATUS_CONFIRMED&&this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_1XX_RECEIVED)throw new b.InvalidStateError(this._status);if(a!==y.DTMF_TRANSPORT.INFO&&a!==y.DTMF_TRANSPORT.RFC2833)throw TypeError(`invalid transportType: ${a}`);if(typeof e==`number`&&(e=e.toString()),!e||typeof e!=`string`||!e.match(/^[0-9A-DR#*,]+$/i))throw TypeError(`Invalid tones: ${e}`);if(r&&!S.isDecimal(r))throw TypeError(`Invalid tone duration: ${r}`);if(r?r<D.C.MIN_DURATION?(M.debug(`"duration" value is lower than the minimum allowed, setting it to ${D.C.MIN_DURATION} milliseconds`),r=D.C.MIN_DURATION):r>D.C.MAX_DURATION?(M.debug(`"duration" value is greater than the maximum allowed, setting it to ${D.C.MAX_DURATION} milliseconds`),r=D.C.MAX_DURATION):r=Math.abs(r):r=D.C.DEFAULT_DURATION,t.duration=r,i&&!S.isDecimal(i))throw TypeError(`Invalid interToneGap: ${i}`);if(i?i<D.C.MIN_INTER_TONE_GAP?(M.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${D.C.MIN_INTER_TONE_GAP} milliseconds`),i=D.C.MIN_INTER_TONE_GAP):i=Math.abs(i):i=D.C.DEFAULT_INTER_TONE_GAP,a===y.DTMF_TRANSPORT.RFC2833){var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,i));return}if(this._tones){this._tones+=e;return}this._tones=e,s.call(this);function s(){var e=this,a;if(this._status===N.STATUS_TERMINATED||!this._tones||n>=this._tones.length){this._tones=null;return}var o=this._tones[n];if(n+=1,o===`,`)a=2e3;else{var c=new D(this);t.eventHandlers={onFailed:function(){e._tones=null}},c.send(o,t),a=r+i}setTimeout(s.bind(this),a)}}},{key:`sendInfo`,value:function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(M.debug(`sendInfo()`),this._status!==N.STATUS_CONFIRMED&&this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_1XX_RECEIVED)throw new b.InvalidStateError(this._status);new O(this).send(e,t,n)}},{key:`mute`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};M.debug(`mute()`);var t=!1,n=!1;this._audioMuted===!1&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(t===!0||n===!0)&&this._onmute({audio:t,video:n})}},{key:`unmute`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};M.debug(`unmute()`);var t=!1,n=!1;this._audioMuted===!0&&e.audio&&(t=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&e.video&&(n=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(t===!0||n===!0)&&this._onunmute({audio:t,video:n})}},{key:`hold`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(M.debug(`hold()`),this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold(`local`);var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Hold Failed`})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:`unhold`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(M.debug(`unhold()`),this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold(`local`);var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Unhold Failed`})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:`renegotiate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;M.debug(`renegotiate()`);var r=t.rtcOfferConstraints||null;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var i={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Media Renegotiation Failed`})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:`refer`,value:function(e,t){var n=this;M.debug(`refer()`);var r=e;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${r}`);var i=new A(this);i.sendRefer(e,t);var a=i.id;return this._referSubscribers[a]=i,i.on(`requestFailed`,function(){delete n._referSubscribers[a]}),i.on(`accepted`,function(){delete n._referSubscribers[a]}),i.on(`failed`,function(){delete n._referSubscribers[a]}),i}},{key:`sendRequest`,value:function(e,t){return M.debug(`sendRequest()`),this._dialog.sendRequest(e,t)}},{key:`receiveRequest`,value:function(e){var t=this;if(M.debug(`receiveRequest()`),e.method===y.CANCEL)(this._status===N.STATUS_WAITING_FOR_ANSWER||this._status===N.STATUS_ANSWERED)&&(this._status=N.STATUS_CANCELED,this._request.reply(487),this._failed(`remote`,e,y.causes.CANCELED));else switch(e.method){case y.ACK:if(this._status!==N.STATUS_WAITING_FOR_ACK)return;if(this._status=N.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:y.causes.MISSING_SDP,status_code:400});break}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var r=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed(`remote`,e)}).catch(function(e){t.terminate({cause:y.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}else this._is_confirmed||this._confirmed(`remote`,e);break;case y.BYE:this._status===N.STATUS_CONFIRMED||this._status===N.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended(`remote`,e,y.causes.BYE)):this._status===N.STATUS_INVITE_RECEIVED||this._status===N.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,`BYE Received`),this._ended(`remote`,e,y.causes.BYE)):e.reply(403,`Wrong Status`);break;case y.INVITE:this._status===N.STATUS_CONFIRMED?e.hasHeader(`replaces`)?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,`Wrong Status`);break;case y.INFO:if(this._status===N.STATUS_1XX_RECEIVED||this._status===N.STATUS_WAITING_FOR_ANSWER||this._status===N.STATUS_ANSWERED||this._status===N.STATUS_WAITING_FOR_ACK||this._status===N.STATUS_CONFIRMED){var i=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new D(this).init_incoming(e):i===void 0?e.reply(415):new O(this).init_incoming(e)}else e.reply(403,`Wrong Status`);break;case y.UPDATE:this._status===N.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,`Wrong Status`);break;case y.REFER:this._status===N.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,`Wrong Status`);break;case y.NOTIFY:this._status===N.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,`Wrong Status`);break;default:e.reply(501)}}},{key:`onTransportError`,value:function(){M.warn(`onTransportError()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:y.causes.CONNECTION_ERROR,cause:y.causes.CONNECTION_ERROR})}},{key:`onRequestTimeout`,value:function(){M.warn(`onRequestTimeout()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:y.causes.REQUEST_TIMEOUT,cause:y.causes.REQUEST_TIMEOUT})}},{key:`onDialogError`,value:function(){M.warn(`onDialogError()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:y.causes.DIALOG_ERROR,cause:y.causes.DIALOG_ERROR})}},{key:`newDTMF`,value:function(e){M.debug(`newDTMF()`),this.emit(`newDTMF`,e)}},{key:`newInfo`,value:function(e){M.debug(`newInfo()`),this.emit(`newInfo`,e)}},{key:`_isReadyToReOffer`,value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(M.debug(`_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress`),!1):!0:(M.debug(`_isReadyToReOffer() | session not established yet`),!1):(M.debug(`_isReadyToReOffer() | internal WebRTC status not ready`),!1)}},{key:`_close`,value:function(){if(M.debug(`close()`),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(M.debug(`close() | closing local MediaStream`),S.closeMediaStream(this._localMediaStream)),this._status!==N.STATUS_TERMINATED){if(this._status=N.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){M.warn(`close() | error closing the RTCPeerConnection: %o`,e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:`_setInvite2xxTimer`,value:function(e,t){var n=C.T1;function r(){this._status===N.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),n<C.T2&&(n*=2,n>C.T2&&(n=C.T2)),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}this._timers.invite2xxTimer=setTimeout(r.bind(this),n)}},{key:`_setACKTimer`,value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===N.STATUS_WAITING_FOR_ACK&&(M.debug(`no ACK received, terminating the session`),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(y.BYE),e._ended(`remote`,null,y.causes.NO_ACK))},C.TIMER_H)}},{key:`_createRTCConnection`,value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener(`iceconnectionstatechange`,function(){n._connection.iceConnectionState===`failed`&&n.terminate({cause:y.causes.RTP_TIMEOUT,status_code:408,reason_phrase:y.causes.RTP_TIMEOUT})}),M.debug(`emit "peerconnection"`),this.emit(`peerconnection`,{peerconnection:this._connection})}},{key:`_createLocalDescription`,value:function(e,t){var n=this;if(M.debug(`createLocalDescription()`),e!==`offer`&&e!==`answer`)throw Error(`createLocalDescription() | invalid type "${e}"`);var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return e===`offer`?r.createOffer(t).catch(function(e){return M.warn(`emit "peerconnection:createofferfailed" [error:%o]`,e),n.emit(`peerconnection:createofferfailed`,e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return M.warn(`emit "peerconnection:createanswerfailed" [error:%o]`,e),n.emit(`peerconnection:createanswerfailed`,e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,M.warn(`emit "peerconnection:setlocaldescriptionfailed" [error:%o]`,e),n.emit(`peerconnection:setlocaldescriptionfailed`,e),Promise.reject(e)})}).then(function(){var i=t&&t.iceRestart;if(r.iceGatheringState===`complete`&&!i||r.iceGatheringState===`gathering`&&n._iceReady){n._rtcReady=!0;var a={originator:`local`,type:e,sdp:r.localDescription.sdp};return M.debug(`emit "sdp"`),n.emit(`sdp`,a),Promise.resolve(a.sdp)}return new Promise(function(t){var i=!1,a,o;n._iceReady=!1;var s=function(){if(!i){r.removeEventListener(`icecandidate`,a),r.removeEventListener(`icegatheringstatechange`,o),i=!0,n._rtcReady=!0,n._iceReady=!0;var s={originator:`local`,type:e,sdp:r.localDescription.sdp};M.debug(`emit "sdp"`),n.emit(`sdp`,s),t(s.sdp)}};r.addEventListener(`icecandidate`,a=function(e){var t=e.candidate;t?n.emit(`icecandidate`,{candidate:t,ready:s}):s()}),r.addEventListener(`icegatheringstatechange`,o=function(){r.iceGatheringState===`complete`&&s()})})})}},{key:`_createDialog`,value:function(e,t,n){var r=t===`UAS`?e.to_tag:e.from_tag,i=t===`UAS`?e.from_tag:e.to_tag,a=e.call_id+r+i,o=this._earlyDialogs[a];if(n)return o?!0:(o=new T(this,e,t,T.C.STATUS_EARLY),o.error?(M.debug(o.error),this._failed(`remote`,e,y.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[a]=o,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,o)return o.update(e,t),this._dialog=o,delete this._earlyDialogs[a],!0;var s=new T(this,e,t);return s.error?(M.debug(s.error),this._failed(`remote`,e,y.causes.INTERNAL_ERROR),!1):(this._dialog=s,!0)}},{key:`_receiveReinvite`,value:function(e){var t=this;M.debug(`receiveReinvite()`);var n=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0,r={request:e,callback:void 0,reject:a.bind(this)},i=!1;function a(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||``,a=S.cloneArray(t.extraHeaders);if(this._status!==N.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw TypeError(`Invalid status_code: ${n}`);e.reply(n,r,a)}if(this.emit(`reinvite`,r),i)return;if(this._late_sdp=!1,!e.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold(`remote`)),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription(`offer`,t._rtcOfferConstraints)}).then(function(e){o.call(t,e)}).catch(function(){e.reply(500)});return}if(n!==`application/sdp`){M.debug(`invalid Content-Type`),e.reply(415);return}this._processInDialogSdpOffer(e).then(function(e){t._status!==N.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){M.warn(e)});function o(t){var n=this,i=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,i),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,i,t,function(){n._status=N.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),typeof r.callback==`function`&&r.callback()}}},{key:`_receiveUpdate`,value:function(e){var t=this;M.debug(`receiveUpdate()`);var n=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0,r={request:e,callback:void 0,reject:a.bind(this)},i=!1;function a(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||``,a=S.cloneArray(t.extraHeaders);if(this._status!==N.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw TypeError(`Invalid status_code: ${n}`);e.reply(n,r,a)}if(this.emit(`update`,r),i)return;if(!e.body){o.call(this,null);return}if(n!==`application/sdp`){M.debug(`invalid Content-Type`),e.reply(415);return}this._processInDialogSdpOffer(e).then(function(e){t._status!==N.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){M.warn(e)});function o(t){var n=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),typeof r.callback==`function`&&r.callback()}}},{key:`_processInDialogSdpOffer`,value:function(e){var t=this;M.debug(`_processInDialogSdpOffer()`);var n=e.parseSDP(),i=!1,a=r(n.media),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(P.indexOf(s.type)!==-1){var c=s.direction||n.direction||`sendrecv`;if(c===`sendonly`||c===`inactive`)i=!0;else{i=!1;break}}}}catch(e){a.e(e)}finally{a.f()}var l={originator:`remote`,type:`offer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,l);var u=new RTCSessionDescription({type:`offer`,sdp:l.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);return t._connection.setRemoteDescription(u).catch(function(n){throw e.reply(488),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,n),t.emit(`peerconnection:setremotedescriptionfailed`,n),n})}).then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);t._remoteHold===!0&&i===!1?(t._remoteHold=!1,t._onunhold(`remote`)):t._remoteHold===!1&&i===!0&&(t._remoteHold=!0,t._onhold(`remote`))}).then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);return t._createLocalDescription(`answer`,t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),M.warn(`emit "peerconnection:createtelocaldescriptionfailed" [error:%o]`,t),t})}).catch(function(e){M.warn(`_processInDialogSdpOffer() failed [error: %o]`,e)}),this._connectionPromiseQueue}},{key:`_receiveRefer`,value:function(e){var t=this;if(M.debug(`receiveRefer()`),!e.refer_to){M.debug(`no Refer-To header field present in REFER`),e.reply(400);return}if(e.refer_to.uri.scheme!==y.SIP){M.debug(`Refer-To header field points to a non-SIP URI scheme`),e.reply(416);return}e.reply(202);var r=new k(this,e.cseq);M.debug(`emit "refer"`),this.emit(`refer`,{request:e,accept:function(e,n){i.call(t,e,n)},reject:function(){a.call(t)}});function i(t){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(t=typeof t==`function`?t:null,this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;var a=new n(this._ua);if(a.on(`progress`,function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),a.on(`accepted`,function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),a.on(`_failed`,function(e){var t=e.message,n=e.cause;t?r.notify(t.status_code,t.reason_phrase):r.notify(487,n)}),e.refer_to.uri.hasHeader(`replaces`)){var o=decodeURIComponent(e.refer_to.uri.getHeader(`replaces`));i.extraHeaders=S.cloneArray(i.extraHeaders),i.extraHeaders.push(`Replaces: ${o}`)}a.connect(e.refer_to.uri.toAor(),i,t)}function a(){r.notify(603)}}},{key:`_receiveNotify`,value:function(e){switch(M.debug(`receiveNotify()`),e.event||e.reply(400),e.event.event){case`refer`:var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else if(Object.keys(this._referSubscribers).length===1)n=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{e.reply(400,`Missing event id parameter`);return}if(!n){e.reply(481,`Subscription does not exist`);return}n.receiveNotify(e),e.reply(200);break;default:e.reply(489)}}},{key:`_receiveReplaces`,value:function(e){var t=this;M.debug(`receiveReplaces()`);function r(t){var r=this;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;var i=new n(this._ua);i.on(`confirmed`,function(){r.terminate()}),i.init_incoming(e,t)}function i(){M.debug(`Replaced INVITE rejected by the user`),e.reply(486)}this.emit(`replaces`,{request:e,accept:function(e){r.call(t,e)},reject:function(){i.call(t)}})}},{key:`_sendInitialRequest`,value:function(e,t,n){var r=this,i=new E(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){if(n)return n;if(e.audio||e.video)return r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){throw r._status===N.STATUS_TERMINATED?Error(`terminated`):(r._failed(`local`,null,y.causes.USER_DENIED_MEDIA_ACCESS),M.warn(`emit "getusermediafailed" [error:%o]`,e),r.emit(`getusermediafailed`,e),e)})}).then(function(e){if(r._status===N.STATUS_TERMINATED)throw Error(`terminated`);return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription(`offer`,t).catch(function(e){throw r._failed(`local`,null,y.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===N.STATUS_TERMINATED)throw Error(`terminated`);r._request.body=e,r._status=N.STATUS_INVITE_SENT,M.debug(`emit "sending" [request:%o]`,r._request),r.emit(`sending`,{request:r._request}),i.send()}).catch(function(e){r._status!==N.STATUS_TERMINATED&&M.warn(e)})}},{key:`_getDTMFRTPSender`,value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&e.track.kind===`audio`});if(!(e&&e.dtmf)){M.warn(`sendDTMF() | no local audio track to send DTMF with`);return}return e.dtmf}},{key:`_receiveInviteResponse`,value:function(e){var t=this;if(M.debug(`receiveInviteResponse()`),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag){this.sendRequest(y.ACK);return}var n=new T(this,e,`UAC`);if(n.error!==void 0){M.debug(n.error);return}this.sendRequest(y.ACK),this.sendRequest(y.BYE);return}if(this._is_canceled){e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);return}if(this._status===N.STATUS_INVITE_SENT||this._status===N.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=N.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){M.debug(`1xx response received without to tag`);break}if(e.hasHeader(`contact`)&&!this._createDialog(e,`UAC`,!0))break;if(this._status=N.STATUS_1XX_RECEIVED,!e.body){this._progress(`remote`,e);break}var r={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,r);var i=new RTCSessionDescription({type:`answer`,sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){return t._progress(`remote`,e)}).catch(function(e){M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=N.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,y.causes.MISSING_SDP),this._failed(`remote`,e,y.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,`UAC`))break;var a={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,a);var o=new RTCSessionDescription({type:`answer`,sdp:a.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._connection.signalingState===`stable`)return t._connection.createOffer(t._rtcOfferConstraints).then(function(e){return t._connection.setLocalDescription(e)}).catch(function(n){t._acceptAndTerminate(e,500,n.toString()),t._failed(`local`,e,y.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted(`remote`,e),t.sendRequest(y.ACK),t._confirmed(`local`,null)}).catch(function(n){t._acceptAndTerminate(e,488,`Not Acceptable Here`),t._failed(`remote`,e,y.causes.BAD_MEDIA_DESCRIPTION),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,n),t.emit(`peerconnection:setremotedescriptionfailed`,n)})});break;default:var s=S.sipErrorCause(e.status_code);this._failed(`remote`,e,s)}}},{key:`_sendReinvite`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`sendReinvite()`);var n=S.cloneArray(t.extraHeaders),r=S.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,a=!1;n.push(`Contact: ${this._contact}`),n.push(`Content-Type: application/sdp`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?`uac`:`uas`}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription(`offer`,i)}).then(function(t){t=e._mangleOffer(t);var r={originator:`local`,type:`offer`,sdp:t};M.debug(`emit "sdp"`),e.emit(`sdp`,r),e.sendRequest(y.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){o.call(e,t),a=!0},onErrorResponse:function(t){s.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){s()});function o(e){var t=this;if(this._status!==N.STATUS_TERMINATED&&(this.sendRequest(y.ACK),!a)){if(this._handleSessionTimersInIncomingResponse(e),!e.body){s.call(this);return}if(!e.hasHeader(`Content-Type`)||e.getHeader(`Content-Type`).toLowerCase()!==`application/sdp`){s.call(this);return}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var i=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){s.call(t),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}}function s(e){r.failed&&r.failed(e)}}},{key:`_sendUpdate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`sendUpdate()`);var n=S.cloneArray(t.extraHeaders),r=S.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,a=t.sdpOffer||!1,o=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?`uac`:`uas`}`),a?(n.push(`Content-Type: application/sdp`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription(`offer`,i)}).then(function(t){t=e._mangleOffer(t);var r={originator:`local`,type:`offer`,sdp:t};M.debug(`emit "sdp"`),e.emit(`sdp`,r),e.sendRequest(y.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){s.call(e,t),o=!0},onErrorResponse:function(t){c.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){c.call(e)})):this.sendRequest(y.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){s.call(e,t)},onErrorResponse:function(t){c.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}});function s(e){var t=this;if(this._status!==N.STATUS_TERMINATED&&!o){if(this._handleSessionTimersInIncomingResponse(e),a){if(!e.body){c.call(this);return}if(!e.hasHeader(`Content-Type`)||e.getHeader(`Content-Type`).toLowerCase()!==`application/sdp`){c.call(this);return}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var i=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){c.call(t),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}else r.succeeded&&r.succeeded(e)}}function c(e){r.failed&&r.failed(e)}}},{key:`_acceptAndTerminate`,value:function(e,t,n){M.debug(`acceptAndTerminate()`);var r=[];t&&(n=n||y.REASON_PHRASE[t]||``,r.push(`Reason: SIP ;cause=${t}; text="${n}"`)),(this._dialog||this._createDialog(e,`UAC`))&&(this.sendRequest(y.ACK),this.sendRequest(y.BYE,{extraHeaders:r})),this._status=N.STATUS_TERMINATED}},{key:`_mangleOffer`,value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=_.parse(e),this._localHold&&!this._remoteHold){M.debug(`mangleOffer() | me on hold, mangling offer`);var t=r(e.media),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;P.indexOf(i.type)!==-1&&(i.direction?i.direction===`sendrecv`?i.direction=`sendonly`:i.direction===`recvonly`&&(i.direction=`inactive`):i.direction=`sendonly`)}}catch(e){t.e(e)}finally{t.f()}}else if(this._localHold&&this._remoteHold){M.debug(`mangleOffer() | both on hold, mangling offer`);var a=r(e.media),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;P.indexOf(s.type)!==-1&&(s.direction=`inactive`)}}catch(e){a.e(e)}finally{a.f()}}else if(this._remoteHold){M.debug(`mangleOffer() | remote on hold, mangling offer`);var c=r(e.media),l;try{for(c.s();!(l=c.n()).done;){var u=l.value;P.indexOf(u.type)!==-1&&(u.direction?u.direction===`sendrecv`?u.direction=`recvonly`:u.direction===`recvonly`&&(u.direction=`inactive`):u.direction=`recvonly`)}}catch(e){c.e(e)}finally{c.f()}}return _.write(e)}},{key:`_setLocalMediaStatus`,value:function(){var 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)}},{key:`_handleSessionTimersInIncomingRequest`,value:function(e,t){if(this._sessionTimers.enabled){var n;e.session_expires&&e.session_expires>=y.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=n===`uas`,this._runSessionTimer()}}},{key:`_handleSessionTimersInIncomingResponse`,value:function(e){if(this._sessionTimers.enabled){var t;e.session_expires&&e.session_expires>=y.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||`uac`):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t=`uac`),this._sessionTimers.refresher=t===`uac`,this._runSessionTimer()}}},{key:`_runSessionTimer`,value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==N.STATUS_TERMINATED&&e._isReadyToReOffer()&&(M.debug(`runSessionTimer() | sending session refresh request`),e._sessionTimers.refreshMethod===y.UPDATE?e._sendUpdate():e._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(function(){e._status!==N.STATUS_TERMINATED&&(M.warn(`runSessionTimer() | timer expired, terminating the session`),e.terminate({cause:y.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:`Session Timer Expired`}))},t*1100)}},{key:`_toggleMuteAudio`,value:function(e){var t=r(this._connection.getSenders().filter(function(e){return e.track&&e.track.kind===`audio`})),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;i.track.enabled=!e}}catch(e){t.e(e)}finally{t.f()}}},{key:`_toggleMuteVideo`,value:function(e){var t=r(this._connection.getSenders().filter(function(e){return e.track&&e.track.kind===`video`})),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;i.track.enabled=!e}}catch(e){t.e(e)}finally{t.f()}}},{key:`_newRTCSession`,value:function(e,t){M.debug(`newRTCSession()`),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:`_connecting`,value:function(e){M.debug(`session connecting`),M.debug(`emit "connecting"`),this.emit(`connecting`,{request:e})}},{key:`_progress`,value:function(e,t){M.debug(`session progress`),M.debug(`emit "progress"`),this.emit(`progress`,{originator:e,response:t||null})}},{key:`_accepted`,value:function(e,t){M.debug(`session accepted`),this._start_time=new Date,M.debug(`emit "accepted"`),this.emit(`accepted`,{originator:e,response:t||null})}},{key:`_confirmed`,value:function(e,t){M.debug(`session confirmed`),this._is_confirmed=!0,M.debug(`emit "confirmed"`),this.emit(`confirmed`,{originator:e,ack:t||null})}},{key:`_ended`,value:function(e,t,n){M.debug(`session ended`),this._end_time=new Date,this._close(),M.debug(`emit "ended"`),this.emit(`ended`,{originator:e,message:t||null,cause:n})}},{key:`_failed`,value:function(e,t,n){M.debug(`session failed`),M.debug(`emit "_failed"`),this.emit(`_failed`,{originator:e,message:t||null,cause:n}),this._close(),M.debug(`emit "failed"`),this.emit(`failed`,{originator:e,message:t||null,cause:n})}},{key:`_onhold`,value:function(e){M.debug(`session onhold`),this._setLocalMediaStatus(),M.debug(`emit "hold"`),this.emit(`hold`,{originator:e})}},{key:`_onunhold`,value:function(e){M.debug(`session onunhold`),this._setLocalMediaStatus(),M.debug(`emit "unhold"`),this.emit(`unhold`,{originator:e})}},{key:`_onmute`,value:function(e){var t=e.audio,n=e.video;M.debug(`session onmute`),this._setLocalMediaStatus(),M.debug(`emit "muted"`),this.emit(`muted`,{audio:t,video:n})}},{key:`_onunmute`,value:function(e){var t=e.audio,n=e.video;M.debug(`session onunmute`),this._setLocalMediaStatus(),M.debug(`emit "unmuted"`),this.emit(`unmuted`,{audio:t,video:n})}},{key:`C`,get:function(){return N}},{key:`causes`,get:function(){return y.causes}},{key:`id`,get:function(){return this._id}},{key:`connection`,get:function(){return this._connection}},{key:`contact`,get:function(){return this._contact}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}},{key:`start_time`,get:function(){return this._start_time}},{key:`end_time`,get:function(){return this._end_time}},{key:`data`,get:function(){return this._data},set:function(e){this._data=e}},{key:`status`,get:function(){return this._status}}]),n}(g)})),Kt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=Q(),_=J(),v=Lt(),y=K(),b=Dt(),x=new m(`Message`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._ua=e,i._request=null,i._closed=!1,i._direction=null,i._local_identity=null,i._remote_identity=null,i._is_replied=!1,i._data={},i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=e;if(e===void 0||t===void 0)throw TypeError(`Not enough arguments`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${i}`);var a=_.cloneArray(r.extraHeaders),o=_.cloneObject(r.eventHandlers),s=r.contentType||`text/plain`,c={};for(var l in r.fromUserName&&(c.from_uri=new b(`sip`,r.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),r.fromDisplayName&&(c.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,l)&&this.on(l,o[l]);a.push(`Content-Type: ${s}`),this._request=new g.OutgoingRequest(h.MESSAGE,e,this._ua,c,a),t&&(this._request.body=t);var u=new v(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage(`local`,this._request),u.send()}},{key:`init_incoming`,value:function(e){this._request=e,this._newMessage(`remote`,e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:`accept`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=_.cloneArray(e.extraHeaders),n=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"accept" not supported for outgoing Message`);if(this._is_replied)throw Error(`incoming Message already replied`);this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:`reject`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=_.cloneArray(e.extraHeaders),i=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"reject" not supported for outgoing Message`);if(this._is_replied)throw Error(`incoming Message already replied`);if(t<300||t>=700)throw TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:`_receiveResponse`,value:function(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:var t=_.sipErrorCause(e.status_code);this._failed(`remote`,e,t)}}},{key:`_onRequestTimeout`,value:function(){this._closed||this._failed(`system`,null,h.causes.REQUEST_TIMEOUT)}},{key:`_onTransportError`,value:function(){this._closed||this._failed(`system`,null,h.causes.CONNECTION_ERROR)}},{key:`_close`,value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:`_newMessage`,value:function(e,t){e===`remote`?(this._direction=`incoming`,this._local_identity=t.to,this._remote_identity=t.from):e===`local`&&(this._direction=`outgoing`,this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:`_failed`,value:function(e,t,n){x.debug(`MESSAGE failed`),this._close(),x.debug(`emit "failed"`),this.emit(`failed`,{originator:e,response:t||null,cause:n})}},{key:`_succeeded`,value:function(e,t){x.debug(`MESSAGE succeeded`),this._close(),x.debug(`emit "succeeded"`),this.emit(`succeeded`,{originator:e,response:t})}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}}]),n}(p)})),qt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=Q(),_=J(),v=Lt(),y=K(),b=new m(`Options`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._ua=e,i._request=null,i._closed=!1,i._direction=null,i._local_identity=null,i._remote_identity=null,i._is_replied=!1,i._data={},i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=e;if(e===void 0)throw TypeError(`A target is required for OPTIONS`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${i}`);var a=_.cloneArray(r.extraHeaders),o=_.cloneObject(r.eventHandlers),s=r.contentType||`application/sdp`;for(var c in o)Object.prototype.hasOwnProperty.call(o,c)&&this.on(c,o[c]);a.push(`Content-Type: ${s}`),this._request=new g.OutgoingRequest(h.OPTIONS,e,this._ua,null,a),t&&(this._request.body=t);var l=new v(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions(`local`,this._request),l.send()}},{key:`init_incoming`,value:function(e){this._request=e,this._newOptions(`remote`,e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:`accept`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=_.cloneArray(e.extraHeaders),n=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"accept" not supported for outgoing Options`);if(this._is_replied)throw Error(`incoming Options already replied`);this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:`reject`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=_.cloneArray(e.extraHeaders),i=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"reject" not supported for outgoing Options`);if(this._is_replied)throw Error(`incoming Options already replied`);if(t<300||t>=700)throw TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:`_receiveResponse`,value:function(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:var t=_.sipErrorCause(e.status_code);this._failed(`remote`,e,t)}}},{key:`_onRequestTimeout`,value:function(){this._closed||this._failed(`system`,null,h.causes.REQUEST_TIMEOUT)}},{key:`_onTransportError`,value:function(){this._closed||this._failed(`system`,null,h.causes.CONNECTION_ERROR)}},{key:`_close`,value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:`_newOptions`,value:function(e,t){e===`remote`?(this._direction=`incoming`,this._local_identity=t.to,this._remote_identity=t.from):e===`local`&&(this._direction=`outgoing`,this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:`_failed`,value:function(e,t,n){b.debug(`OPTIONS failed`),this._close(),b.debug(`emit "failed"`),this.emit(`failed`,{originator:e,response:t||null,cause:n})}},{key:`_succeeded`,value:function(e,t){b.debug(`OPTIONS succeeded`),this._close(),b.debug(`emit "succeeded"`),this.emit(`succeeded`,{originator:e,response:t})}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}}]),n}(p)})),Jt=c((e=>{var t=X(),n=J(),r=q(),i=new t(`Socket`);e.isSocket=function(e){if(Array.isArray(e))return!1;if(e===void 0)return i.warn(`undefined JsSIP.Socket instance`),!1;try{if(!n.isString(e.url))throw i.warn(`missing or invalid JsSIP.Socket url property`),Error(`Missing or invalid JsSIP.Socket url property`);if(!n.isString(e.via_transport))throw i.warn(`missing or invalid JsSIP.Socket via_transport property`),Error(`Missing or invalid JsSIP.Socket via_transport property`);if(r.parse(e.sip_uri,`SIP_URI`)===-1)throw i.warn(`missing or invalid JsSIP.Socket sip_uri property`),Error(`missing or invalid JsSIP.Socket sip_uri property`)}catch{return!1}try{[`connect`,`disconnect`,`send`].forEach(function(t){if(!n.isFunction(e[t]))throw i.warn(`missing or invalid JsSIP.Socket method: ${t}`),Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0}})),Yt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=Jt(),s=G(),c=new a(`Transport`),l={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:s.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:s.CONNECTION_RECOVERY_MAX_INTERVAL}};t.exports=function(){function e(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:l.recovery_options;n(this,e),c.debug(`new()`),this.status=l.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=r,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder(`utf8`)}catch(e){c.warn(`cannot use TextDecoder: ${e}`)}if(t===void 0)throw TypeError(`Invalid argument. undefined 'sockets' argument`);t instanceof Array||(t=[t]),t.forEach(function(e){if(!o.isSocket(e.socket))throw TypeError(`Invalid argument. invalid 'JsSIP.Socket' instance`);if(e.weight&&!Number(e.weight))throw TypeError(`Invalid argument. 'weight' attribute is not a number`);this.sockets.push({socket:e.socket,weight:e.weight||0,status:l.SOCKET_STATUS_READY})},this),this._getSocket()}return i(e,[{key:`connect`,value:function(){if(c.debug(`connect()`),this.isConnected()){c.debug(`Transport is already connected`);return}if(this.isConnecting()){c.debug(`Transport is connecting`);return}this.close_requested=!1,this.status=l.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:`disconnect`,value:function(){c.debug(`close()`),this.close_requested=!0,this.recover_attempts=0,this.status=l.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:`send`,value:function(e){if(c.debug(`send()`),!this.isConnected())return c.warn(`unable to send message, transport is not connected`),!1;var t=e.toString();return c.debug(`sending message:
48
+ `);r.length>=1&&t.test(r[0])&&(this._tone=r[0].replace(t,`$2`)),r.length>=2&&n.test(r[1])&&(this._duration=parseInt(r[1].replace(n,`$2`),10))}this._duration||=y.DEFAULT_DURATION,this._tone?this._session.newDTMF({originator:`remote`,dtmf:this,request:e}):v.debug(`invalid INFO DTMF received, discarded`)}},{key:`tone`,get:function(){return this._tone}},{key:`duration`,get:function(){return this._duration}}]),n}(p),t.exports.C=y})),Rt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=W(),h=G(),g=q();t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._session=e,i._direction=null,i._contentType=null,i._body=null,i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction=`outgoing`,e===void 0)throw 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 h.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var i=g.cloneArray(r.extraHeaders);i.push(`Content-Type: ${e}`),this._session.newInfo({originator:`local`,info:this,request:this.request}),this._session.sendRequest(m.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:function(e){n.emit(`succeeded`,{originator:`remote`,response:e})},onErrorResponse:function(e){n.emit(`failed`,{originator:`remote`,response:e})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:`init_incoming`,value:function(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})}},{key:`contentType`,get:function(){return this._contentType}},{key:`body`,get:function(){return this._body}}]),n}(p)})),zt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=W(),s=new a(`RTCSession:ReferNotifier`),c={event_type:`refer`,body_type:`message/sipfrag;version=2.0`,expires:300};t.exports=function(){function e(t,r,i){n(this,e),this._session=t,this._id=r,this._expires=i||c.expires,this._active=!0,this.notify(100)}return i(e,[{key:`notify`,value:function(e,t){if(s.debug(`notify()`),this._active!==!1){t=t||o.REASON_PHRASE[e]||``;var n=e>=200?`terminated;reason=noresource`:`active;expires=${this._expires}`;this._session.sendRequest(o.NOTIFY,{extraHeaders:[`Event: ${c.event_type};id=${this._id}`,`Subscription-State: ${n}`,`Content-Type: ${c.body_type}`],body:`SIP/2.0 ${e} ${t}`,eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),e}()})),Bt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=K(),_=q(),v=new m(`RTCSession:ReferSubscriber`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._id=null,i._session=e,i}return a(n,[{key:`sendRefer`,value:function(e){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};v.debug(`sendRefer()`);var r=_.cloneArray(n.extraHeaders),i=_.cloneObject(n.eventHandlers);for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&this.on(a,i[a]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=`;to-tag=${n.replaces._to_tag}`,o+=`;from-tag=${n.replaces._from_tag}`,o=encodeURIComponent(o));var s=`Refer-To: <${e}${o?`?Replaces=${o}`:``}>`;if(r.push(s),!r.some(function(e){return e.toLowerCase().startsWith(`referred-by:`)})){var c=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;r.push(c)}r.push(`Contact: ${this._session.contact}`);var l=this._session.sendRequest(h.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,h.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,h.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,h.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,h.causes.DIALOG_ERROR)}}});this._id=l.cseq}},{key:`receiveNotify`,value:function(e){if(v.debug(`receiveNotify()`),e.body){var t=g.parse(e.body.trim().split(`\r
49
+ `,1)[0],`Status_Line`);if(t===-1){v.debug(`receiveNotify() | error parsing NOTIFY body: "${e.body}"`);return}switch(!0){case/^100$/.test(t.status_code):this.emit(`trying`,{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit(`progress`,{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit(`accepted`,{request:e,status_line:t});break;default:this.emit(`failed`,{request:e,status_line:t})}}}},{key:`_requestSucceeded`,value:function(e){v.debug(`REFER succeeded`),v.debug(`emit "requestSucceeded"`),this.emit(`requestSucceeded`,{response:e})}},{key:`_requestFailed`,value:function(e,t){v.debug(`REFER failed`),v.debug(`emit "requestFailed"`),this.emit(`requestFailed`,{response:e||null,cause:t})}},{key:`id`,get:function(){return this._id}}]),n}(p)})),Vt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=i(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
50
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function i(e,t){if(e){if(typeof e==`string`)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}}function a(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function d(e){var t=m();return function(){var n=h(e),r;if(t){var i=h(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return f(this,r)}}function f(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:p(e)}function p(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function m(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var g=J().EventEmitter,_=At(),v=Y(),y=W(),b=G(),x=Q(),S=q(),C=Mt(),w=Z(),T=It(),E=Nt(),D=Lt(),O=Rt(),k=zt(),A=Bt(),j=wt(),M=new v(`RTCSession`),N={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},P=[`audio`,`video`];t.exports=function(e){l(n,e);var t=d(n);c(n,null,[{key:`C`,get:function(){return N}}]);function n(e){var r;return o(this,n),M.debug(`new`),r=t.call(this),r._id=null,r._ua=e,r._status=N.STATUS_NULL,r._dialog=null,r._earlyDialogs={},r._contact=null,r._from_tag=null,r._to_tag=null,r._connection=null,r._connectionPromiseQueue=Promise.resolve(),r._request=null,r._is_canceled=!1,r._cancel_reason=``,r._is_confirmed=!1,r._late_sdp=!1,r._rtcOfferConstraints=null,r._rtcAnswerConstraints=null,r._localMediaStream=null,r._localMediaStreamLocallyGenerated=!1,r._rtcReady=!0,r._iceReady=!1,r._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},r._direction=null,r._local_identity=null,r._remote_identity=null,r._start_time=null,r._end_time=null,r._tones=null,r._audioMuted=!1,r._videoMuted=!1,r._localHold=!1,r._remoteHold=!1,r._sessionTimers={enabled:r._ua.configuration.session_timers,refreshMethod:r._ua.configuration.session_timers_refresh_method,defaultExpires:y.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},r._referSubscribers={},r._data={},r}return c(n,[{key:`isInProgress`,value:function(){switch(this._status){case N.STATUS_NULL:case N.STATUS_INVITE_SENT:case N.STATUS_1XX_RECEIVED:case N.STATUS_INVITE_RECEIVED:case N.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:`isEstablished`,value:function(){switch(this._status){case N.STATUS_ANSWERED:case N.STATUS_WAITING_FOR_ACK:case N.STATUS_CONFIRMED:return!0;default:return!1}}},{key:`isEnded`,value:function(){switch(this._status){case N.STATUS_CANCELED:case N.STATUS_TERMINATED:return!0;default:return!1}}},{key:`isMuted`,value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:`isOnHold`,value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:`connect`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;M.debug(`connect()`);var r=e,i=S.cloneObject(t.eventHandlers),a=S.cloneArray(t.extraHeaders),o=S.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),s=t.mediaStream||null,c=S.cloneObject(t.pcConfig,{iceServers:[]}),l=t.rtcConstraints||null,u=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=u,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,e===void 0)throw TypeError(`Not enough arguments`);if(this._status!==N.STATUS_NULL)throw new b.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new b.NotSupportedError(`WebRTC not supported`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${r}`);for(var d in this._sessionTimers.enabled&&S.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=y.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=y.SESSION_EXPIRES),i)Object.prototype.hasOwnProperty.call(i,d)&&this.on(d,i[d]);this._from_tag=S.newTag();var f=t.anonymous||!1,p={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:f,outbound:!0}),f?(p.from_display_name=`Anonymous`,p.from_uri=new j(`sip`,`anonymous`,`anonymous.invalid`),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),a.push(`Privacy: id`)):t.fromUserName&&(p.from_uri=new j(`sip`,t.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(p.from_display_name=t.fromDisplayName),a.push(`Contact: ${this._contact}`),a.push(`Content-Type: application/sdp`),this._sessionTimers.enabled&&a.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?`;refresher=uac`:``}`),this._request=new w.InitialOutgoingInviteRequest(e,this._ua,p,a),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(c,l),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(o,u,s)}},{key:`init_incoming`,value:function(e,t){var n=this;M.debug(`init_incoming()`);var r,i=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0;if(e.body&&i!==`application/sdp`){e.reply(415);return}if(this._status=N.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader(`expires`)&&(r=e.getHeader(`expires`)*1e3),e.to_tag=S.newTag(),!this._createDialog(e,`UAS`,!0)){e.reply(500,`Missing Contact header field`);return}this._late_sdp=!e.body,this._status=N.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),n._failed(`local`,null,y.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),r&&(this._timers.expiresTimer=setTimeout(function(){n._status===N.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),n._failed(`system`,null,y.causes.EXPIRES))},r)),this._direction=`incoming`,this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession(`remote`,e),this._status!==N.STATUS_TERMINATED&&(e.reply(180,null,[`Contact: ${this._contact}`]),this._progress(`local`,null))}},{key:`answer`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`answer()`);var n=this._request,i=S.cloneArray(t.extraHeaders),a=S.cloneObject(t.mediaConstraints),o=t.mediaStream||null,s=S.cloneObject(t.pcConfig,{iceServers:[]}),c=t.rtcConstraints||null,l=t.rtcAnswerConstraints||null,u=S.cloneObject(t.rtcOfferConstraints),d,f=!1,p=!1,m=!1,h=!1;if(this._rtcAnswerConstraints=l,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!==`incoming`)throw new b.NotSupportedError(`"answer" not supported for outgoing RTCSession`);if(this._status!==N.STATUS_WAITING_FOR_ANSWER)throw new b.InvalidStateError(this._status);if(this._sessionTimers.enabled&&S.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=y.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=y.SESSION_EXPIRES),this._status=N.STATUS_ANSWERED,!this._createDialog(n,`UAS`)){n.reply(500,`Error creating dialog`);return}clearTimeout(this._timers.userNoAnswerTimer),i.unshift(`Contact: ${this._contact}`);var g=n.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);var _=r(g.media),v;try{for(_.s();!(v=_.n()).done;){var x=v.value;x.type===`audio`&&(f=!0,(!x.direction||x.direction===`sendrecv`)&&(m=!0)),x.type===`video`&&(p=!0,(!x.direction||x.direction===`sendrecv`)&&(h=!0))}}catch(e){_.e(e)}finally{_.f()}if(o&&a.audio===!1){d=o.getAudioTracks();var C=r(d),w;try{for(C.s();!(w=C.n()).done;){var T=w.value;o.removeTrack(T)}}catch(e){C.e(e)}finally{C.f()}}if(o&&a.video===!1){d=o.getVideoTracks();var E=r(d),D;try{for(E.s();!(D=E.n()).done;){var O=D.value;o.removeTrack(O)}}catch(e){E.e(e)}finally{E.f()}}!o&&a.audio===void 0&&(a.audio=m),!o&&a.video===void 0&&(a.video=h),!o&&!f&&!u.offerToReceiveAudio&&(a.audio=!1),!o&&!p&&!u.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(s,c),Promise.resolve().then(function(){if(o)return o;if(a.audio||a.video)return e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(function(t){throw e._status===N.STATUS_TERMINATED?Error(`terminated`):(n.reply(480),e._failed(`local`,null,y.causes.USER_DENIED_MEDIA_ACCESS),M.warn(`emit "getusermediafailed" [error:%o]`,t),e.emit(`getusermediafailed`,t),Error(`getUserMedia() failed`))})}).then(function(t){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:`remote`,type:`offer`,sdp:n.body};M.debug(`emit "sdp"`),e.emit(`sdp`,t);var r=new RTCSessionDescription({type:`offer`,sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed(`system`,null,y.causes.WEBRTC_ERROR),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,t),e.emit(`peerconnection:setremotedescriptionfailed`,t),Error(`peerconnection.setRemoteDescription() failed`)}),e._connectionPromiseQueue}}).then(function(){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);return e._connecting(n),e._late_sdp?e._createLocalDescription(`offer`,e._rtcOfferConstraints).catch(function(){throw n.reply(500),Error(`_createLocalDescription() failed`)}):e._createLocalDescription(`answer`,l).catch(function(){throw n.reply(500),Error(`_createLocalDescription() failed`)})}).then(function(t){if(e._status===N.STATUS_TERMINATED)throw Error(`terminated`);e._handleSessionTimersInIncomingRequest(n,i),n.reply(200,null,i,t,function(){e._status=N.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted(`local`)},function(){e._failed(`system`,null,y.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==N.STATUS_TERMINATED&&M.warn(t)})}},{key:`terminate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`terminate()`);var n=t.cause||y.causes.BYE,r=S.cloneArray(t.extraHeaders),i=t.body,a,o=t.status_code,s=t.reason_phrase;if(this._status===N.STATUS_TERMINATED)throw new b.InvalidStateError(this._status);switch(this._status){case N.STATUS_NULL:case N.STATUS_INVITE_SENT:case N.STATUS_1XX_RECEIVED:if(M.debug(`canceling session`),o&&(o<200||o>=700))throw TypeError(`Invalid status_code: ${o}`);o&&(s=s||y.REASON_PHRASE[o]||``,a=`SIP ;cause=${o} ;text="${s}"`),this._status===N.STATUS_NULL||this._status===N.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=a):this._status===N.STATUS_1XX_RECEIVED&&this._request.cancel(a),this._status=N.STATUS_CANCELED,this._failed(`local`,null,y.causes.CANCELED);break;case N.STATUS_WAITING_FOR_ANSWER:case N.STATUS_ANSWERED:if(M.debug(`rejecting session`),o||=480,o<300||o>=700)throw TypeError(`Invalid status_code: ${o}`);this._request.reply(o,s,r,i),this._failed(`local`,null,y.causes.REJECTED);break;case N.STATUS_WAITING_FOR_ACK:case N.STATUS_CONFIRMED:if(M.debug(`terminating session`),s=t.reason_phrase||y.REASON_PHRASE[o]||``,o&&(o<200||o>=700))throw TypeError(`Invalid status_code: ${o}`);if(o&&r.push(`Reason: SIP ;cause=${o}; text="${s}"`),this._status===N.STATUS_WAITING_FOR_ACK&&this._direction===`incoming`&&this._request.server_transaction.state!==x.C.STATUS_TERMINATED){var c=this._dialog;this.receiveRequest=function(t){t.method===y.ACK&&(e.sendRequest(y.BYE,{extraHeaders:r,body:i}),c.terminate())},this._request.server_transaction.on(`stateChanged`,function(){e._request.server_transaction.state===x.C.STATUS_TERMINATED&&(e.sendRequest(y.BYE,{extraHeaders:r,body:i}),c.terminate())}),this._ended(`local`,null,n),this._dialog=c,this._ua.newDialog(c)}else this.sendRequest(y.BYE,{extraHeaders:r,body:i}),this._ended(`local`,null,n)}}},{key:`sendDTMF`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};M.debug(`sendDTMF() | tones: %s`,e);var n=0,r=t.duration||null,i=t.interToneGap||null,a=t.transportType||y.DTMF_TRANSPORT.INFO;if(e===void 0)throw TypeError(`Not enough arguments`);if(this._status!==N.STATUS_CONFIRMED&&this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_1XX_RECEIVED)throw new b.InvalidStateError(this._status);if(a!==y.DTMF_TRANSPORT.INFO&&a!==y.DTMF_TRANSPORT.RFC2833)throw TypeError(`invalid transportType: ${a}`);if(typeof e==`number`&&(e=e.toString()),!e||typeof e!=`string`||!e.match(/^[0-9A-DR#*,]+$/i))throw TypeError(`Invalid tones: ${e}`);if(r&&!S.isDecimal(r))throw TypeError(`Invalid tone duration: ${r}`);if(r?r<D.C.MIN_DURATION?(M.debug(`"duration" value is lower than the minimum allowed, setting it to ${D.C.MIN_DURATION} milliseconds`),r=D.C.MIN_DURATION):r>D.C.MAX_DURATION?(M.debug(`"duration" value is greater than the maximum allowed, setting it to ${D.C.MAX_DURATION} milliseconds`),r=D.C.MAX_DURATION):r=Math.abs(r):r=D.C.DEFAULT_DURATION,t.duration=r,i&&!S.isDecimal(i))throw TypeError(`Invalid interToneGap: ${i}`);if(i?i<D.C.MIN_INTER_TONE_GAP?(M.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${D.C.MIN_INTER_TONE_GAP} milliseconds`),i=D.C.MIN_INTER_TONE_GAP):i=Math.abs(i):i=D.C.DEFAULT_INTER_TONE_GAP,a===y.DTMF_TRANSPORT.RFC2833){var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,i));return}if(this._tones){this._tones+=e;return}this._tones=e,s.call(this);function s(){var e=this,a;if(this._status===N.STATUS_TERMINATED||!this._tones||n>=this._tones.length){this._tones=null;return}var o=this._tones[n];if(n+=1,o===`,`)a=2e3;else{var c=new D(this);t.eventHandlers={onFailed:function(){e._tones=null}},c.send(o,t),a=r+i}setTimeout(s.bind(this),a)}}},{key:`sendInfo`,value:function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(M.debug(`sendInfo()`),this._status!==N.STATUS_CONFIRMED&&this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_1XX_RECEIVED)throw new b.InvalidStateError(this._status);new O(this).send(e,t,n)}},{key:`mute`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};M.debug(`mute()`);var t=!1,n=!1;this._audioMuted===!1&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(t===!0||n===!0)&&this._onmute({audio:t,video:n})}},{key:`unmute`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};M.debug(`unmute()`);var t=!1,n=!1;this._audioMuted===!0&&e.audio&&(t=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&e.video&&(n=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(t===!0||n===!0)&&this._onunmute({audio:t,video:n})}},{key:`hold`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(M.debug(`hold()`),this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold(`local`);var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Hold Failed`})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:`unhold`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(M.debug(`unhold()`),this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold(`local`);var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Unhold Failed`})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:`renegotiate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;M.debug(`renegotiate()`);var r=t.rtcOfferConstraints||null;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var i={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:y.causes.WEBRTC_ERROR,status_code:500,reason_phrase:`Media Renegotiation Failed`})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:`refer`,value:function(e,t){var n=this;M.debug(`refer()`);var r=e;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${r}`);var i=new A(this);i.sendRefer(e,t);var a=i.id;return this._referSubscribers[a]=i,i.on(`requestFailed`,function(){delete n._referSubscribers[a]}),i.on(`accepted`,function(){delete n._referSubscribers[a]}),i.on(`failed`,function(){delete n._referSubscribers[a]}),i}},{key:`sendRequest`,value:function(e,t){return M.debug(`sendRequest()`),this._dialog.sendRequest(e,t)}},{key:`receiveRequest`,value:function(e){var t=this;if(M.debug(`receiveRequest()`),e.method===y.CANCEL)(this._status===N.STATUS_WAITING_FOR_ANSWER||this._status===N.STATUS_ANSWERED)&&(this._status=N.STATUS_CANCELED,this._request.reply(487),this._failed(`remote`,e,y.causes.CANCELED));else switch(e.method){case y.ACK:if(this._status!==N.STATUS_WAITING_FOR_ACK)return;if(this._status=N.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:y.causes.MISSING_SDP,status_code:400});break}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var r=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed(`remote`,e)}).catch(function(e){t.terminate({cause:y.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}else this._is_confirmed||this._confirmed(`remote`,e);break;case y.BYE:this._status===N.STATUS_CONFIRMED||this._status===N.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended(`remote`,e,y.causes.BYE)):this._status===N.STATUS_INVITE_RECEIVED||this._status===N.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,`BYE Received`),this._ended(`remote`,e,y.causes.BYE)):e.reply(403,`Wrong Status`);break;case y.INVITE:this._status===N.STATUS_CONFIRMED?e.hasHeader(`replaces`)?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,`Wrong Status`);break;case y.INFO:if(this._status===N.STATUS_1XX_RECEIVED||this._status===N.STATUS_WAITING_FOR_ANSWER||this._status===N.STATUS_ANSWERED||this._status===N.STATUS_WAITING_FOR_ACK||this._status===N.STATUS_CONFIRMED){var i=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new D(this).init_incoming(e):i===void 0?e.reply(415):new O(this).init_incoming(e)}else e.reply(403,`Wrong Status`);break;case y.UPDATE:this._status===N.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,`Wrong Status`);break;case y.REFER:this._status===N.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,`Wrong Status`);break;case y.NOTIFY:this._status===N.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,`Wrong Status`);break;default:e.reply(501)}}},{key:`onTransportError`,value:function(){M.warn(`onTransportError()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:y.causes.CONNECTION_ERROR,cause:y.causes.CONNECTION_ERROR})}},{key:`onRequestTimeout`,value:function(){M.warn(`onRequestTimeout()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:y.causes.REQUEST_TIMEOUT,cause:y.causes.REQUEST_TIMEOUT})}},{key:`onDialogError`,value:function(){M.warn(`onDialogError()`),this._status!==N.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:y.causes.DIALOG_ERROR,cause:y.causes.DIALOG_ERROR})}},{key:`newDTMF`,value:function(e){M.debug(`newDTMF()`),this.emit(`newDTMF`,e)}},{key:`newInfo`,value:function(e){M.debug(`newInfo()`),this.emit(`newInfo`,e)}},{key:`_isReadyToReOffer`,value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(M.debug(`_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress`),!1):!0:(M.debug(`_isReadyToReOffer() | session not established yet`),!1):(M.debug(`_isReadyToReOffer() | internal WebRTC status not ready`),!1)}},{key:`_close`,value:function(){if(M.debug(`close()`),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(M.debug(`close() | closing local MediaStream`),S.closeMediaStream(this._localMediaStream)),this._status!==N.STATUS_TERMINATED){if(this._status=N.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){M.warn(`close() | error closing the RTCPeerConnection: %o`,e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:`_setInvite2xxTimer`,value:function(e,t){var n=C.T1;function r(){this._status===N.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,[`Contact: ${this._contact}`],t),n<C.T2&&(n*=2,n>C.T2&&(n=C.T2)),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}this._timers.invite2xxTimer=setTimeout(r.bind(this),n)}},{key:`_setACKTimer`,value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===N.STATUS_WAITING_FOR_ACK&&(M.debug(`no ACK received, terminating the session`),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(y.BYE),e._ended(`remote`,null,y.causes.NO_ACK))},C.TIMER_H)}},{key:`_createRTCConnection`,value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener(`iceconnectionstatechange`,function(){n._connection.iceConnectionState===`failed`&&n.terminate({cause:y.causes.RTP_TIMEOUT,status_code:408,reason_phrase:y.causes.RTP_TIMEOUT})}),M.debug(`emit "peerconnection"`),this.emit(`peerconnection`,{peerconnection:this._connection})}},{key:`_createLocalDescription`,value:function(e,t){var n=this;if(M.debug(`createLocalDescription()`),e!==`offer`&&e!==`answer`)throw Error(`createLocalDescription() | invalid type "${e}"`);var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return e===`offer`?r.createOffer(t).catch(function(e){return M.warn(`emit "peerconnection:createofferfailed" [error:%o]`,e),n.emit(`peerconnection:createofferfailed`,e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return M.warn(`emit "peerconnection:createanswerfailed" [error:%o]`,e),n.emit(`peerconnection:createanswerfailed`,e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,M.warn(`emit "peerconnection:setlocaldescriptionfailed" [error:%o]`,e),n.emit(`peerconnection:setlocaldescriptionfailed`,e),Promise.reject(e)})}).then(function(){var i=t&&t.iceRestart;if(r.iceGatheringState===`complete`&&!i||r.iceGatheringState===`gathering`&&n._iceReady){n._rtcReady=!0;var a={originator:`local`,type:e,sdp:r.localDescription.sdp};return M.debug(`emit "sdp"`),n.emit(`sdp`,a),Promise.resolve(a.sdp)}return new Promise(function(t){var i=!1,a,o;n._iceReady=!1;var s=function(){if(!i){r.removeEventListener(`icecandidate`,a),r.removeEventListener(`icegatheringstatechange`,o),i=!0,n._rtcReady=!0,n._iceReady=!0;var s={originator:`local`,type:e,sdp:r.localDescription.sdp};M.debug(`emit "sdp"`),n.emit(`sdp`,s),t(s.sdp)}};r.addEventListener(`icecandidate`,a=function(e){var t=e.candidate;t?n.emit(`icecandidate`,{candidate:t,ready:s}):s()}),r.addEventListener(`icegatheringstatechange`,o=function(){r.iceGatheringState===`complete`&&s()})})})}},{key:`_createDialog`,value:function(e,t,n){var r=t===`UAS`?e.to_tag:e.from_tag,i=t===`UAS`?e.from_tag:e.to_tag,a=e.call_id+r+i,o=this._earlyDialogs[a];if(n)return o?!0:(o=new T(this,e,t,T.C.STATUS_EARLY),o.error?(M.debug(o.error),this._failed(`remote`,e,y.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[a]=o,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,o)return o.update(e,t),this._dialog=o,delete this._earlyDialogs[a],!0;var s=new T(this,e,t);return s.error?(M.debug(s.error),this._failed(`remote`,e,y.causes.INTERNAL_ERROR),!1):(this._dialog=s,!0)}},{key:`_receiveReinvite`,value:function(e){var t=this;M.debug(`receiveReinvite()`);var n=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0,r={request:e,callback:void 0,reject:a.bind(this)},i=!1;function a(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||``,a=S.cloneArray(t.extraHeaders);if(this._status!==N.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw TypeError(`Invalid status_code: ${n}`);e.reply(n,r,a)}if(this.emit(`reinvite`,r),i)return;if(this._late_sdp=!1,!e.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold(`remote`)),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription(`offer`,t._rtcOfferConstraints)}).then(function(e){o.call(t,e)}).catch(function(){e.reply(500)});return}if(n!==`application/sdp`){M.debug(`invalid Content-Type`),e.reply(415);return}this._processInDialogSdpOffer(e).then(function(e){t._status!==N.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){M.warn(e)});function o(t){var n=this,i=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,i),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,i,t,function(){n._status=N.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),typeof r.callback==`function`&&r.callback()}}},{key:`_receiveUpdate`,value:function(e){var t=this;M.debug(`receiveUpdate()`);var n=e.hasHeader(`Content-Type`)?e.getHeader(`Content-Type`).toLowerCase():void 0,r={request:e,callback:void 0,reject:a.bind(this)},i=!1;function a(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||``,a=S.cloneArray(t.extraHeaders);if(this._status!==N.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw TypeError(`Invalid status_code: ${n}`);e.reply(n,r,a)}if(this.emit(`update`,r),i)return;if(!e.body){o.call(this,null);return}if(n!==`application/sdp`){M.debug(`invalid Content-Type`),e.reply(415);return}this._processInDialogSdpOffer(e).then(function(e){t._status!==N.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){M.warn(e)});function o(t){var n=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),typeof r.callback==`function`&&r.callback()}}},{key:`_processInDialogSdpOffer`,value:function(e){var t=this;M.debug(`_processInDialogSdpOffer()`);var n=e.parseSDP(),i=!1,a=r(n.media),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(P.indexOf(s.type)!==-1){var c=s.direction||n.direction||`sendrecv`;if(c===`sendonly`||c===`inactive`)i=!0;else{i=!1;break}}}}catch(e){a.e(e)}finally{a.f()}var l={originator:`remote`,type:`offer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,l);var u=new RTCSessionDescription({type:`offer`,sdp:l.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);return t._connection.setRemoteDescription(u).catch(function(n){throw e.reply(488),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,n),t.emit(`peerconnection:setremotedescriptionfailed`,n),n})}).then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);t._remoteHold===!0&&i===!1?(t._remoteHold=!1,t._onunhold(`remote`)):t._remoteHold===!1&&i===!0&&(t._remoteHold=!0,t._onhold(`remote`))}).then(function(){if(t._status===N.STATUS_TERMINATED)throw Error(`terminated`);return t._createLocalDescription(`answer`,t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),M.warn(`emit "peerconnection:createtelocaldescriptionfailed" [error:%o]`,t),t})}).catch(function(e){M.warn(`_processInDialogSdpOffer() failed [error: %o]`,e)}),this._connectionPromiseQueue}},{key:`_receiveRefer`,value:function(e){var t=this;if(M.debug(`receiveRefer()`),!e.refer_to){M.debug(`no Refer-To header field present in REFER`),e.reply(400);return}if(e.refer_to.uri.scheme!==y.SIP){M.debug(`Refer-To header field points to a non-SIP URI scheme`),e.reply(416);return}e.reply(202);var r=new k(this,e.cseq);M.debug(`emit "refer"`),this.emit(`refer`,{request:e,accept:function(e,n){i.call(t,e,n)},reject:function(){a.call(t)}});function i(t){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(t=typeof t==`function`?t:null,this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;var a=new n(this._ua);if(a.on(`progress`,function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),a.on(`accepted`,function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),a.on(`_failed`,function(e){var t=e.message,n=e.cause;t?r.notify(t.status_code,t.reason_phrase):r.notify(487,n)}),e.refer_to.uri.hasHeader(`replaces`)){var o=decodeURIComponent(e.refer_to.uri.getHeader(`replaces`));i.extraHeaders=S.cloneArray(i.extraHeaders),i.extraHeaders.push(`Replaces: ${o}`)}a.connect(e.refer_to.uri.toAor(),i,t)}function a(){r.notify(603)}}},{key:`_receiveNotify`,value:function(e){switch(M.debug(`receiveNotify()`),e.event||e.reply(400),e.event.event){case`refer`:var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else if(Object.keys(this._referSubscribers).length===1)n=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{e.reply(400,`Missing event id parameter`);return}if(!n){e.reply(481,`Subscription does not exist`);return}n.receiveNotify(e),e.reply(200);break;default:e.reply(489)}}},{key:`_receiveReplaces`,value:function(e){var t=this;M.debug(`receiveReplaces()`);function r(t){var r=this;if(this._status!==N.STATUS_WAITING_FOR_ACK&&this._status!==N.STATUS_CONFIRMED)return!1;var i=new n(this._ua);i.on(`confirmed`,function(){r.terminate()}),i.init_incoming(e,t)}function i(){M.debug(`Replaced INVITE rejected by the user`),e.reply(486)}this.emit(`replaces`,{request:e,accept:function(e){r.call(t,e)},reject:function(){i.call(t)}})}},{key:`_sendInitialRequest`,value:function(e,t,n){var r=this,i=new E(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){if(n)return n;if(e.audio||e.video)return r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){throw r._status===N.STATUS_TERMINATED?Error(`terminated`):(r._failed(`local`,null,y.causes.USER_DENIED_MEDIA_ACCESS),M.warn(`emit "getusermediafailed" [error:%o]`,e),r.emit(`getusermediafailed`,e),e)})}).then(function(e){if(r._status===N.STATUS_TERMINATED)throw Error(`terminated`);return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription(`offer`,t).catch(function(e){throw r._failed(`local`,null,y.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===N.STATUS_TERMINATED)throw Error(`terminated`);r._request.body=e,r._status=N.STATUS_INVITE_SENT,M.debug(`emit "sending" [request:%o]`,r._request),r.emit(`sending`,{request:r._request}),i.send()}).catch(function(e){r._status!==N.STATUS_TERMINATED&&M.warn(e)})}},{key:`_getDTMFRTPSender`,value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&e.track.kind===`audio`});if(!(e&&e.dtmf)){M.warn(`sendDTMF() | no local audio track to send DTMF with`);return}return e.dtmf}},{key:`_receiveInviteResponse`,value:function(e){var t=this;if(M.debug(`receiveInviteResponse()`),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag){this.sendRequest(y.ACK);return}var n=new T(this,e,`UAC`);if(n.error!==void 0){M.debug(n.error);return}this.sendRequest(y.ACK),this.sendRequest(y.BYE);return}if(this._is_canceled){e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);return}if(this._status===N.STATUS_INVITE_SENT||this._status===N.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=N.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){M.debug(`1xx response received without to tag`);break}if(e.hasHeader(`contact`)&&!this._createDialog(e,`UAC`,!0))break;if(this._status=N.STATUS_1XX_RECEIVED,!e.body){this._progress(`remote`,e);break}var r={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,r);var i=new RTCSessionDescription({type:`answer`,sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){return t._progress(`remote`,e)}).catch(function(e){M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=N.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,y.causes.MISSING_SDP),this._failed(`remote`,e,y.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,`UAC`))break;var a={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,a);var o=new RTCSessionDescription({type:`answer`,sdp:a.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._connection.signalingState===`stable`)return t._connection.createOffer(t._rtcOfferConstraints).then(function(e){return t._connection.setLocalDescription(e)}).catch(function(n){t._acceptAndTerminate(e,500,n.toString()),t._failed(`local`,e,y.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted(`remote`,e),t.sendRequest(y.ACK),t._confirmed(`local`,null)}).catch(function(n){t._acceptAndTerminate(e,488,`Not Acceptable Here`),t._failed(`remote`,e,y.causes.BAD_MEDIA_DESCRIPTION),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,n),t.emit(`peerconnection:setremotedescriptionfailed`,n)})});break;default:var s=S.sipErrorCause(e.status_code);this._failed(`remote`,e,s)}}},{key:`_sendReinvite`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`sendReinvite()`);var n=S.cloneArray(t.extraHeaders),r=S.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,a=!1;n.push(`Contact: ${this._contact}`),n.push(`Content-Type: application/sdp`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?`uac`:`uas`}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription(`offer`,i)}).then(function(t){t=e._mangleOffer(t);var r={originator:`local`,type:`offer`,sdp:t};M.debug(`emit "sdp"`),e.emit(`sdp`,r),e.sendRequest(y.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){o.call(e,t),a=!0},onErrorResponse:function(t){s.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){s()});function o(e){var t=this;if(this._status!==N.STATUS_TERMINATED&&(this.sendRequest(y.ACK),!a)){if(this._handleSessionTimersInIncomingResponse(e),!e.body){s.call(this);return}if(!e.hasHeader(`Content-Type`)||e.getHeader(`Content-Type`).toLowerCase()!==`application/sdp`){s.call(this);return}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var i=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){s.call(t),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}}function s(e){r.failed&&r.failed(e)}}},{key:`_sendUpdate`,value:function(){var e=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};M.debug(`sendUpdate()`);var n=S.cloneArray(t.extraHeaders),r=S.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,a=t.sdpOffer||!1,o=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?`uac`:`uas`}`),a?(n.push(`Content-Type: application/sdp`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription(`offer`,i)}).then(function(t){t=e._mangleOffer(t);var r={originator:`local`,type:`offer`,sdp:t};M.debug(`emit "sdp"`),e.emit(`sdp`,r),e.sendRequest(y.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){s.call(e,t),o=!0},onErrorResponse:function(t){c.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){c.call(e)})):this.sendRequest(y.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){s.call(e,t)},onErrorResponse:function(t){c.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}});function s(e){var t=this;if(this._status!==N.STATUS_TERMINATED&&!o){if(this._handleSessionTimersInIncomingResponse(e),a){if(!e.body){c.call(this);return}if(!e.hasHeader(`Content-Type`)||e.getHeader(`Content-Type`).toLowerCase()!==`application/sdp`){c.call(this);return}var n={originator:`remote`,type:`answer`,sdp:e.body};M.debug(`emit "sdp"`),this.emit(`sdp`,n);var i=new RTCSessionDescription({type:`answer`,sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){c.call(t),M.warn(`emit "peerconnection:setremotedescriptionfailed" [error:%o]`,e),t.emit(`peerconnection:setremotedescriptionfailed`,e)})}else r.succeeded&&r.succeeded(e)}}function c(e){r.failed&&r.failed(e)}}},{key:`_acceptAndTerminate`,value:function(e,t,n){M.debug(`acceptAndTerminate()`);var r=[];t&&(n=n||y.REASON_PHRASE[t]||``,r.push(`Reason: SIP ;cause=${t}; text="${n}"`)),(this._dialog||this._createDialog(e,`UAC`))&&(this.sendRequest(y.ACK),this.sendRequest(y.BYE,{extraHeaders:r})),this._status=N.STATUS_TERMINATED}},{key:`_mangleOffer`,value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=_.parse(e),this._localHold&&!this._remoteHold){M.debug(`mangleOffer() | me on hold, mangling offer`);var t=r(e.media),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;P.indexOf(i.type)!==-1&&(i.direction?i.direction===`sendrecv`?i.direction=`sendonly`:i.direction===`recvonly`&&(i.direction=`inactive`):i.direction=`sendonly`)}}catch(e){t.e(e)}finally{t.f()}}else if(this._localHold&&this._remoteHold){M.debug(`mangleOffer() | both on hold, mangling offer`);var a=r(e.media),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;P.indexOf(s.type)!==-1&&(s.direction=`inactive`)}}catch(e){a.e(e)}finally{a.f()}}else if(this._remoteHold){M.debug(`mangleOffer() | remote on hold, mangling offer`);var c=r(e.media),l;try{for(c.s();!(l=c.n()).done;){var u=l.value;P.indexOf(u.type)!==-1&&(u.direction?u.direction===`sendrecv`?u.direction=`recvonly`:u.direction===`recvonly`&&(u.direction=`inactive`):u.direction=`recvonly`)}}catch(e){c.e(e)}finally{c.f()}}return _.write(e)}},{key:`_setLocalMediaStatus`,value:function(){var 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)}},{key:`_handleSessionTimersInIncomingRequest`,value:function(e,t){if(this._sessionTimers.enabled){var n;e.session_expires&&e.session_expires>=y.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=n===`uas`,this._runSessionTimer()}}},{key:`_handleSessionTimersInIncomingResponse`,value:function(e){if(this._sessionTimers.enabled){var t;e.session_expires&&e.session_expires>=y.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||`uac`):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t=`uac`),this._sessionTimers.refresher=t===`uac`,this._runSessionTimer()}}},{key:`_runSessionTimer`,value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==N.STATUS_TERMINATED&&e._isReadyToReOffer()&&(M.debug(`runSessionTimer() | sending session refresh request`),e._sessionTimers.refreshMethod===y.UPDATE?e._sendUpdate():e._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(function(){e._status!==N.STATUS_TERMINATED&&(M.warn(`runSessionTimer() | timer expired, terminating the session`),e.terminate({cause:y.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:`Session Timer Expired`}))},t*1100)}},{key:`_toggleMuteAudio`,value:function(e){var t=r(this._connection.getSenders().filter(function(e){return e.track&&e.track.kind===`audio`})),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;i.track.enabled=!e}}catch(e){t.e(e)}finally{t.f()}}},{key:`_toggleMuteVideo`,value:function(e){var t=r(this._connection.getSenders().filter(function(e){return e.track&&e.track.kind===`video`})),n;try{for(t.s();!(n=t.n()).done;){var i=n.value;i.track.enabled=!e}}catch(e){t.e(e)}finally{t.f()}}},{key:`_newRTCSession`,value:function(e,t){M.debug(`newRTCSession()`),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:`_connecting`,value:function(e){M.debug(`session connecting`),M.debug(`emit "connecting"`),this.emit(`connecting`,{request:e})}},{key:`_progress`,value:function(e,t){M.debug(`session progress`),M.debug(`emit "progress"`),this.emit(`progress`,{originator:e,response:t||null})}},{key:`_accepted`,value:function(e,t){M.debug(`session accepted`),this._start_time=new Date,M.debug(`emit "accepted"`),this.emit(`accepted`,{originator:e,response:t||null})}},{key:`_confirmed`,value:function(e,t){M.debug(`session confirmed`),this._is_confirmed=!0,M.debug(`emit "confirmed"`),this.emit(`confirmed`,{originator:e,ack:t||null})}},{key:`_ended`,value:function(e,t,n){M.debug(`session ended`),this._end_time=new Date,this._close(),M.debug(`emit "ended"`),this.emit(`ended`,{originator:e,message:t||null,cause:n})}},{key:`_failed`,value:function(e,t,n){M.debug(`session failed`),M.debug(`emit "_failed"`),this.emit(`_failed`,{originator:e,message:t||null,cause:n}),this._close(),M.debug(`emit "failed"`),this.emit(`failed`,{originator:e,message:t||null,cause:n})}},{key:`_onhold`,value:function(e){M.debug(`session onhold`),this._setLocalMediaStatus(),M.debug(`emit "hold"`),this.emit(`hold`,{originator:e})}},{key:`_onunhold`,value:function(e){M.debug(`session onunhold`),this._setLocalMediaStatus(),M.debug(`emit "unhold"`),this.emit(`unhold`,{originator:e})}},{key:`_onmute`,value:function(e){var t=e.audio,n=e.video;M.debug(`session onmute`),this._setLocalMediaStatus(),M.debug(`emit "muted"`),this.emit(`muted`,{audio:t,video:n})}},{key:`_onunmute`,value:function(e){var t=e.audio,n=e.video;M.debug(`session onunmute`),this._setLocalMediaStatus(),M.debug(`emit "unmuted"`),this.emit(`unmuted`,{audio:t,video:n})}},{key:`C`,get:function(){return N}},{key:`causes`,get:function(){return y.causes}},{key:`id`,get:function(){return this._id}},{key:`connection`,get:function(){return this._connection}},{key:`contact`,get:function(){return this._contact}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}},{key:`start_time`,get:function(){return this._start_time}},{key:`end_time`,get:function(){return this._end_time}},{key:`data`,get:function(){return this._data},set:function(e){this._data=e}},{key:`status`,get:function(){return this._status}}]),n}(g)})),Ht=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=Z(),_=q(),v=Nt(),y=G(),b=wt(),x=new m(`Message`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._ua=e,i._request=null,i._closed=!1,i._direction=null,i._local_identity=null,i._remote_identity=null,i._is_replied=!1,i._data={},i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=e;if(e===void 0||t===void 0)throw TypeError(`Not enough arguments`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${i}`);var a=_.cloneArray(r.extraHeaders),o=_.cloneObject(r.eventHandlers),s=r.contentType||`text/plain`,c={};for(var l in r.fromUserName&&(c.from_uri=new b(`sip`,r.fromUserName,this._ua.configuration.uri.host),a.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),r.fromDisplayName&&(c.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,l)&&this.on(l,o[l]);a.push(`Content-Type: ${s}`),this._request=new g.OutgoingRequest(h.MESSAGE,e,this._ua,c,a),t&&(this._request.body=t);var u=new v(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage(`local`,this._request),u.send()}},{key:`init_incoming`,value:function(e){this._request=e,this._newMessage(`remote`,e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:`accept`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=_.cloneArray(e.extraHeaders),n=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"accept" not supported for outgoing Message`);if(this._is_replied)throw Error(`incoming Message already replied`);this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:`reject`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=_.cloneArray(e.extraHeaders),i=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"reject" not supported for outgoing Message`);if(this._is_replied)throw Error(`incoming Message already replied`);if(t<300||t>=700)throw TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:`_receiveResponse`,value:function(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:var t=_.sipErrorCause(e.status_code);this._failed(`remote`,e,t)}}},{key:`_onRequestTimeout`,value:function(){this._closed||this._failed(`system`,null,h.causes.REQUEST_TIMEOUT)}},{key:`_onTransportError`,value:function(){this._closed||this._failed(`system`,null,h.causes.CONNECTION_ERROR)}},{key:`_close`,value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:`_newMessage`,value:function(e,t){e===`remote`?(this._direction=`incoming`,this._local_identity=t.to,this._remote_identity=t.from):e===`local`&&(this._direction=`outgoing`,this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:`_failed`,value:function(e,t,n){x.debug(`MESSAGE failed`),this._close(),x.debug(`emit "failed"`),this.emit(`failed`,{originator:e,response:t||null,cause:n})}},{key:`_succeeded`,value:function(e,t){x.debug(`MESSAGE succeeded`),this._close(),x.debug(`emit "succeeded"`),this.emit(`succeeded`,{originator:e,response:t})}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}}]),n}(p)})),Ut=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=Z(),_=q(),v=Nt(),y=G(),b=new m(`Options`);t.exports=function(e){o(n,e);var t=c(n);function n(e){var i;return r(this,n),i=t.call(this),i._ua=e,i._request=null,i._closed=!1,i._direction=null,i._local_identity=null,i._remote_identity=null,i._is_replied=!1,i._data={},i}return a(n,[{key:`send`,value:function(e,t){var n=this,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=e;if(e===void 0)throw TypeError(`A target is required for OPTIONS`);if(e=this._ua.normalizeTarget(e),!e)throw TypeError(`Invalid target: ${i}`);var a=_.cloneArray(r.extraHeaders),o=_.cloneObject(r.eventHandlers),s=r.contentType||`application/sdp`;for(var c in o)Object.prototype.hasOwnProperty.call(o,c)&&this.on(c,o[c]);a.push(`Content-Type: ${s}`),this._request=new g.OutgoingRequest(h.OPTIONS,e,this._ua,null,a),t&&(this._request.body=t);var l=new v(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions(`local`,this._request),l.send()}},{key:`init_incoming`,value:function(e){this._request=e,this._newOptions(`remote`,e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:`accept`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=_.cloneArray(e.extraHeaders),n=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"accept" not supported for outgoing Options`);if(this._is_replied)throw Error(`incoming Options already replied`);this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:`reject`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=_.cloneArray(e.extraHeaders),i=e.body;if(this._direction!==`incoming`)throw new y.NotSupportedError(`"reject" not supported for outgoing Options`);if(this._is_replied)throw Error(`incoming Options already replied`);if(t<300||t>=700)throw TypeError(`Invalid status_code: ${t}`);this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:`_receiveResponse`,value:function(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:var t=_.sipErrorCause(e.status_code);this._failed(`remote`,e,t)}}},{key:`_onRequestTimeout`,value:function(){this._closed||this._failed(`system`,null,h.causes.REQUEST_TIMEOUT)}},{key:`_onTransportError`,value:function(){this._closed||this._failed(`system`,null,h.causes.CONNECTION_ERROR)}},{key:`_close`,value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:`_newOptions`,value:function(e,t){e===`remote`?(this._direction=`incoming`,this._local_identity=t.to,this._remote_identity=t.from):e===`local`&&(this._direction=`outgoing`,this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:`_failed`,value:function(e,t,n){b.debug(`OPTIONS failed`),this._close(),b.debug(`emit "failed"`),this.emit(`failed`,{originator:e,response:t||null,cause:n})}},{key:`_succeeded`,value:function(e,t){b.debug(`OPTIONS succeeded`),this._close(),b.debug(`emit "succeeded"`),this.emit(`succeeded`,{originator:e,response:t})}},{key:`direction`,get:function(){return this._direction}},{key:`local_identity`,get:function(){return this._local_identity}},{key:`remote_identity`,get:function(){return this._remote_identity}}]),n}(p)})),Wt=c((e=>{var t=Y(),n=q(),r=K(),i=new t(`Socket`);e.isSocket=function(e){if(Array.isArray(e))return!1;if(e===void 0)return i.warn(`undefined JsSIP.Socket instance`),!1;try{if(!n.isString(e.url))throw i.warn(`missing or invalid JsSIP.Socket url property`),Error(`Missing or invalid JsSIP.Socket url property`);if(!n.isString(e.via_transport))throw i.warn(`missing or invalid JsSIP.Socket via_transport property`),Error(`Missing or invalid JsSIP.Socket via_transport property`);if(r.parse(e.sip_uri,`SIP_URI`)===-1)throw i.warn(`missing or invalid JsSIP.Socket sip_uri property`),Error(`missing or invalid JsSIP.Socket sip_uri property`)}catch{return!1}try{[`connect`,`disconnect`,`send`].forEach(function(t){if(!n.isFunction(e[t]))throw i.warn(`missing or invalid JsSIP.Socket method: ${t}`),Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0}})),Gt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=Wt(),s=W(),c=new a(`Transport`),l={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:s.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:s.CONNECTION_RECOVERY_MAX_INTERVAL}};t.exports=function(){function e(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:l.recovery_options;n(this,e),c.debug(`new()`),this.status=l.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=r,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder(`utf8`)}catch(e){c.warn(`cannot use TextDecoder: ${e}`)}if(t===void 0)throw TypeError(`Invalid argument. undefined 'sockets' argument`);t instanceof Array||(t=[t]),t.forEach(function(e){if(!o.isSocket(e.socket))throw TypeError(`Invalid argument. invalid 'JsSIP.Socket' instance`);if(e.weight&&!Number(e.weight))throw TypeError(`Invalid argument. 'weight' attribute is not a number`);this.sockets.push({socket:e.socket,weight:e.weight||0,status:l.SOCKET_STATUS_READY})},this),this._getSocket()}return i(e,[{key:`connect`,value:function(){if(c.debug(`connect()`),this.isConnected()){c.debug(`Transport is already connected`);return}if(this.isConnecting()){c.debug(`Transport is connecting`);return}this.close_requested=!1,this.status=l.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:`disconnect`,value:function(){c.debug(`close()`),this.close_requested=!0,this.recover_attempts=0,this.status=l.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:`send`,value:function(e){if(c.debug(`send()`),!this.isConnected())return c.warn(`unable to send message, transport is not connected`),!1;var t=e.toString();return c.debug(`sending message:
51
51
 
52
52
  ${t}
53
53
  `),this.socket.send(t)}},{key:`isConnected`,value:function(){return this.status===l.STATUS_CONNECTED}},{key:`isConnecting`,value:function(){return this.status===l.STATUS_CONNECTING}},{key:`_reconnect`,value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*2**this.recover_attempts+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),c.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${t} seconds`),this.recovery_timer=setTimeout(function(){!e.close_requested&&!(e.isConnected()||e.isConnecting())&&(e._getSocket(),e.connect())},t*1e3)}},{key:`_getSocket`,value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==l.SOCKET_STATUS_ERROR&&(e.length===0?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),e.length===0){this.sockets.forEach(function(e){e.status=l.SOCKET_STATUS_READY}),this._getSocket();return}var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:`_onConnect`,value:function(){this.recover_attempts=0,this.status=l.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:`_onDisconnect`,value:function(e,t,n){this.status=l.STATUS_DISCONNECTED,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=l.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:`_onData`,value:function(e){if(e===`\r
@@ -60,16 +60,16 @@ ${e}
60
60
  `)}else c.debug(`received text message:
61
61
 
62
62
  ${e}
63
- `);this.ondata({transport:this,message:e})}},{key:`via_transport`,get:function(){return this.socket.via_transport}},{key:`url`,get:function(){return this.socket.url}},{key:`sip_uri`,get:function(){return this.socket.sip_uri}}]),e}()})),Xt=c((e=>{function t(e,t){var r;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(r=n(e))||t&&e&&typeof e.length==`number`){r&&(e=r);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
64
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&r.return!=null&&r.return()}finally{if(s)throw c}}}}function n(e,t){if(e){if(typeof e==`string`)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}}function r(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var i=X(),a=q(),o=Q(),s=new i(`Parser`);e.parseMessage=function(e,t){var n,r,i=e.indexOf(`\r
63
+ `);this.ondata({transport:this,message:e})}},{key:`via_transport`,get:function(){return this.socket.via_transport}},{key:`url`,get:function(){return this.socket.url}},{key:`sip_uri`,get:function(){return this.socket.sip_uri}}]),e}()})),Kt=c((e=>{function t(e,t){var r;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(r=n(e))||t&&e&&typeof e.length==`number`){r&&(e=r);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
64
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&r.return!=null&&r.return()}finally{if(s)throw c}}}}function n(e,t){if(e){if(typeof e==`string`)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}}function r(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var i=Y(),a=K(),o=Z(),s=new i(`Parser`);e.parseMessage=function(e,t){var n,r,i=e.indexOf(`\r
65
65
  `);if(i===-1){s.warn(`parseMessage() | no CRLF found, not a SIP message`);return}var u=e.substring(0,i),d=a.parse(u,`Request_Response`);if(d===-1){s.warn(`parseMessage() | error parsing first line of SIP message: "${u}"`);return}d.status_code?(n=new o.IncomingResponse,n.status_code=d.status_code,n.reason_phrase=d.reason_phrase):(n=new o.IncomingRequest(t),n.method=d.method,n.ruri=d.uri),n.data=e;for(var f=i+2;;){if(i=c(e,f),i===-2){r=f+2;break}if(i===-1){s.warn(`parseMessage() | malformed message`);return}if(d=l(n,e,f,i),d!==!0){s.warn(`parseMessage() |`,d.error);return}f=i+2}if(n.hasHeader(`content-length`)){var p=n.getHeader(`content-length`);n.body=e.substr(r,p)}else n.body=e.substring(r);return n};function c(e,t){var n=t,r=0,i=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;r===0;){if(i=e.indexOf(`\r
66
- `,n),i===-1)return i;!e.substring(i+2,i+4).match(/(^\r\n)/)&&e.charAt(i+2).match(/(^\s+)/)?n=i+2:r=i}return r}function l(e,n,r,i){var s,c=n.indexOf(`:`,r),l=n.substring(r,c).trim(),u=n.substring(c+1,i).trim();switch(l.toLowerCase()){case`via`:case`v`:e.addHeader(`via`,u),e.getHeaders(`via`).length===1?(s=e.parseHeader(`Via`),s&&(e.via=s,e.via_branch=s.branch)):s=0;break;case`from`:case`f`:e.setHeader(`from`,u),s=e.parseHeader(`from`),s&&(e.from=s,e.from_tag=s.getParam(`tag`));break;case`to`:case`t`:e.setHeader(`to`,u),s=e.parseHeader(`to`),s&&(e.to=s,e.to_tag=s.getParam(`tag`));break;case`record-route`:if(s=a.parse(u,`Record_Route`),s===-1)s=void 0;else{var d=t(s),f;try{for(d.s();!(f=d.n()).done;){var p=f.value;e.addHeader(`record-route`,u.substring(p.possition,p.offset)),e.headers[`Record-Route`][e.getHeaders(`record-route`).length-1].parsed=p.parsed}}catch(e){d.e(e)}finally{d.f()}}break;case`call-id`:case`i`:e.setHeader(`call-id`,u),s=e.parseHeader(`call-id`),s&&(e.call_id=u);break;case`contact`:case`m`:if(s=a.parse(u,`Contact`),s===-1)s=void 0;else{var m=t(s),h;try{for(m.s();!(h=m.n()).done;){var g=h.value;e.addHeader(`contact`,u.substring(g.possition,g.offset)),e.headers.Contact[e.getHeaders(`contact`).length-1].parsed=g.parsed}}catch(e){m.e(e)}finally{m.f()}}break;case`content-length`:case`l`:e.setHeader(`content-length`,u),s=e.parseHeader(`content-length`);break;case`content-type`:case`c`:e.setHeader(`content-type`,u),s=e.parseHeader(`content-type`);break;case`cseq`:e.setHeader(`cseq`,u),s=e.parseHeader(`cseq`),s&&(e.cseq=s.value),e instanceof o.IncomingResponse&&(e.method=s.method);break;case`max-forwards`:e.setHeader(`max-forwards`,u),s=e.parseHeader(`max-forwards`);break;case`www-authenticate`:e.setHeader(`www-authenticate`,u),s=e.parseHeader(`www-authenticate`);break;case`proxy-authenticate`:e.setHeader(`proxy-authenticate`,u),s=e.parseHeader(`proxy-authenticate`);break;case`session-expires`:case`x`:e.setHeader(`session-expires`,u),s=e.parseHeader(`session-expires`),s&&(e.session_expires=s.expires,e.session_expires_refresher=s.refresher);break;case`refer-to`:case`r`:e.setHeader(`refer-to`,u),s=e.parseHeader(`refer-to`),s&&(e.refer_to=s);break;case`replaces`:e.setHeader(`replaces`,u),s=e.parseHeader(`replaces`),s&&(e.replaces=s);break;case`event`:case`o`:e.setHeader(`event`,u),s=e.parseHeader(`event`),s&&(e.event=s);break;default:e.addHeader(l,u),s=0}return s!==void 0||{error:`error parsing header "${l}"`}}})),Zt=c(((e,t)=>{function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
67
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=X(),o=G(),s=Q(),c=J(),l=new a(`sanityCheck`),u=[S],d=[g,_,v,y],f=[b,x],p,m,h;t.exports=function(e,t,r){p=e,m=t,h=r;var i=n(u),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(o()===!1)return!1}}catch(e){i.e(e)}finally{i.f()}if(p instanceof s.IncomingRequest){var c=n(d),l;try{for(c.s();!(l=c.n()).done;){var g=l.value;if(g()===!1)return!1}}catch(e){c.e(e)}finally{c.f()}}else if(p instanceof s.IncomingResponse){var _=n(f),v;try{for(_.s();!(v=_.n()).done;){var y=v.value;if(y()===!1)return!1}}catch(e){_.e(e)}finally{_.f()}}return!0};function g(){if(p.s(`to`).uri.scheme!==`sip`)return C(416),!1}function _(){if(!p.to_tag&&p.call_id.substr(0,5)===m.configuration.jssip_id)return C(482),!1}function v(){if(c.str_utf8_length(p.body)<p.getHeader(`content-length`))return C(400),!1}function y(){var e=p.from_tag,t=p.call_id,n=p.cseq,r;if(!p.to_tag){if(p.method===o.INVITE){if(m._transactions.ist[p.via_branch])return!1;for(var i in m._transactions.ist)if(Object.prototype.hasOwnProperty.call(m._transactions.ist,i)&&(r=m._transactions.ist[i],r.request.from_tag===e&&r.request.call_id===t&&r.request.cseq===n))return C(482),!1}else if(m._transactions.nist[p.via_branch])return!1;else for(var a in m._transactions.nist)if(Object.prototype.hasOwnProperty.call(m._transactions.nist,a)&&(r=m._transactions.nist[a],r.request.from_tag===e&&r.request.call_id===t&&r.request.cseq===n))return C(482),!1}}function b(){if(p.getHeaders(`via`).length>1)return l.debug(`more than one Via header field present in the response, dropping the response`),!1}function x(){if(c.str_utf8_length(p.body)<p.getHeader(`content-length`))return l.debug(`message body length is lower than the value in Content-Length header field, dropping the response`),!1}function S(){for(var e=[`from`,`to`,`call_id`,`cseq`,`via`],t=0,n=e;t<n.length;t++){var r=n[t];if(!p.hasHeader(r))return l.debug(`missing mandatory header field : ${r}, dropping the response`),!1}}function C(e){var t=p.getHeaders(`via`),r,i=`SIP/2.0 ${e} ${o.REASON_PHRASE[e]}\r
66
+ `,n),i===-1)return i;!e.substring(i+2,i+4).match(/(^\r\n)/)&&e.charAt(i+2).match(/(^\s+)/)?n=i+2:r=i}return r}function l(e,n,r,i){var s,c=n.indexOf(`:`,r),l=n.substring(r,c).trim(),u=n.substring(c+1,i).trim();switch(l.toLowerCase()){case`via`:case`v`:e.addHeader(`via`,u),e.getHeaders(`via`).length===1?(s=e.parseHeader(`Via`),s&&(e.via=s,e.via_branch=s.branch)):s=0;break;case`from`:case`f`:e.setHeader(`from`,u),s=e.parseHeader(`from`),s&&(e.from=s,e.from_tag=s.getParam(`tag`));break;case`to`:case`t`:e.setHeader(`to`,u),s=e.parseHeader(`to`),s&&(e.to=s,e.to_tag=s.getParam(`tag`));break;case`record-route`:if(s=a.parse(u,`Record_Route`),s===-1)s=void 0;else{var d=t(s),f;try{for(d.s();!(f=d.n()).done;){var p=f.value;e.addHeader(`record-route`,u.substring(p.possition,p.offset)),e.headers[`Record-Route`][e.getHeaders(`record-route`).length-1].parsed=p.parsed}}catch(e){d.e(e)}finally{d.f()}}break;case`call-id`:case`i`:e.setHeader(`call-id`,u),s=e.parseHeader(`call-id`),s&&(e.call_id=u);break;case`contact`:case`m`:if(s=a.parse(u,`Contact`),s===-1)s=void 0;else{var m=t(s),h;try{for(m.s();!(h=m.n()).done;){var g=h.value;e.addHeader(`contact`,u.substring(g.possition,g.offset)),e.headers.Contact[e.getHeaders(`contact`).length-1].parsed=g.parsed}}catch(e){m.e(e)}finally{m.f()}}break;case`content-length`:case`l`:e.setHeader(`content-length`,u),s=e.parseHeader(`content-length`);break;case`content-type`:case`c`:e.setHeader(`content-type`,u),s=e.parseHeader(`content-type`);break;case`cseq`:e.setHeader(`cseq`,u),s=e.parseHeader(`cseq`),s&&(e.cseq=s.value),e instanceof o.IncomingResponse&&(e.method=s.method);break;case`max-forwards`:e.setHeader(`max-forwards`,u),s=e.parseHeader(`max-forwards`);break;case`www-authenticate`:e.setHeader(`www-authenticate`,u),s=e.parseHeader(`www-authenticate`);break;case`proxy-authenticate`:e.setHeader(`proxy-authenticate`,u),s=e.parseHeader(`proxy-authenticate`);break;case`session-expires`:case`x`:e.setHeader(`session-expires`,u),s=e.parseHeader(`session-expires`),s&&(e.session_expires=s.expires,e.session_expires_refresher=s.refresher);break;case`refer-to`:case`r`:e.setHeader(`refer-to`,u),s=e.parseHeader(`refer-to`),s&&(e.refer_to=s);break;case`replaces`:e.setHeader(`replaces`,u),s=e.parseHeader(`replaces`),s&&(e.replaces=s);break;case`event`:case`o`:e.setHeader(`event`,u),s=e.parseHeader(`event`),s&&(e.event=s);break;default:e.addHeader(l,u),s=0}return s!==void 0||{error:`error parsing header "${l}"`}}})),qt=c(((e,t)=>{function n(e,t){var n;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
67
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=Y(),o=W(),s=Z(),c=q(),l=new a(`sanityCheck`),u=[S],d=[g,_,v,y],f=[b,x],p,m,h;t.exports=function(e,t,r){p=e,m=t,h=r;var i=n(u),a;try{for(i.s();!(a=i.n()).done;){var o=a.value;if(o()===!1)return!1}}catch(e){i.e(e)}finally{i.f()}if(p instanceof s.IncomingRequest){var c=n(d),l;try{for(c.s();!(l=c.n()).done;){var g=l.value;if(g()===!1)return!1}}catch(e){c.e(e)}finally{c.f()}}else if(p instanceof s.IncomingResponse){var _=n(f),v;try{for(_.s();!(v=_.n()).done;){var y=v.value;if(y()===!1)return!1}}catch(e){_.e(e)}finally{_.f()}}return!0};function g(){if(p.s(`to`).uri.scheme!==`sip`)return C(416),!1}function _(){if(!p.to_tag&&p.call_id.substr(0,5)===m.configuration.jssip_id)return C(482),!1}function v(){if(c.str_utf8_length(p.body)<p.getHeader(`content-length`))return C(400),!1}function y(){var e=p.from_tag,t=p.call_id,n=p.cseq,r;if(!p.to_tag){if(p.method===o.INVITE){if(m._transactions.ist[p.via_branch])return!1;for(var i in m._transactions.ist)if(Object.prototype.hasOwnProperty.call(m._transactions.ist,i)&&(r=m._transactions.ist[i],r.request.from_tag===e&&r.request.call_id===t&&r.request.cseq===n))return C(482),!1}else if(m._transactions.nist[p.via_branch])return!1;else for(var a in m._transactions.nist)if(Object.prototype.hasOwnProperty.call(m._transactions.nist,a)&&(r=m._transactions.nist[a],r.request.from_tag===e&&r.request.call_id===t&&r.request.cseq===n))return C(482),!1}}function b(){if(p.getHeaders(`via`).length>1)return l.debug(`more than one Via header field present in the response, dropping the response`),!1}function x(){if(c.str_utf8_length(p.body)<p.getHeader(`content-length`))return l.debug(`message body length is lower than the value in Content-Length header field, dropping the response`),!1}function S(){for(var e=[`from`,`to`,`call_id`,`cseq`,`via`],t=0,n=e;t<n.length;t++){var r=n[t];if(!p.hasHeader(r))return l.debug(`missing mandatory header field : ${r}, dropping the response`),!1}}function C(e){var t=p.getHeaders(`via`),r,i=`SIP/2.0 ${e} ${o.REASON_PHRASE[e]}\r
68
68
  `,a=n(t),s;try{for(a.s();!(s=a.n()).done;){var l=s.value;i+=`Via: ${l}\r
69
69
  `}}catch(e){a.e(e)}finally{a.f()}r=p.getHeader(`To`),p.to_tag||(r+=`;tag=${c.newTag()}`),i+=`To: ${r}\r
70
70
  `,i+=`From: ${p.getHeader(`From`)}\r
71
71
  `,i+=`Call-ID: ${p.call_id}\r
72
72
  `,i+=`CSeq: ${p.cseq} ${p.method}\r
73
73
  `,i+=`\r
74
- `,h.send(i)}})),Qt=c((e=>{function t(e,t){var r;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(r=n(e))||t&&e&&typeof e.length==`number`){r&&(e=r);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
75
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&r.return!=null&&r.return()}finally{if(s)throw c}}}}function n(e,t){if(e){if(typeof e==`string`)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}}function r(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var i=J(),a=G(),o=q(),s=Dt(),c=Jt(),l=K();e.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:a.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:a.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:a.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${i.createRandomToken(12)}.invalid`};var u={mandatory:{sockets:function(e){var n=[];if(c.isSocket(e))n.push({socket:e});else if(Array.isArray(e)&&e.length){var r=t(e),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;Object.prototype.hasOwnProperty.call(a,`socket`)&&c.isSocket(a.socket)?n.push(a):c.isSocket(a)&&n.push({socket:a})}}catch(e){r.e(e)}finally{r.f()}}else return;return n},uri:function(e){/^sip:/i.test(e)||(e=`${a.SIP}:${e}`);var t=s.parse(e);if(t&&t.user)return t}},optional:{authorization_user:function(e){if(o.parse(`"${e}"`,`quoted_string`)!==-1)return e},authorization_jwt:function(e){if(typeof e==`string`)return e},user_agent:function(e){if(typeof e==`string`)return e},connection_recovery_max_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if(typeof e==`string`){var t=o.parse(e,`SIP_URI`);if(t!==-1)return t}},display_name:function(e){return e},instance_id:function(e){if(/^uuid:/i.test(e)&&(e=e.substr(5)),o.parse(e,`uuid`)!==-1)return e},no_answer_timeout:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if(typeof e==`boolean`)return e},session_timers_refresh_method:function(e){if(typeof e==`string`&&(e=e.toUpperCase(),e===a.INVITE||e===a.UPDATE))return e},session_timers_force_refresher:function(e){if(typeof e==`boolean`)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if(typeof e==`boolean`)return e},register_expires:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e=`${a.SIP}:${e}`);var t=s.parse(e);if(t&&!t.user)return t},use_preloaded_route:function(e){if(typeof e==`boolean`)return e},extra_headers:function(e){var n=[];if(Array.isArray(e)&&e.length){var r=t(e),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;typeof a==`string`&&n.push(a)}}catch(e){r.e(e)}finally{r.f()}}else return;return n}}};e.load=function(e,t){for(var n in u.mandatory)if(t.hasOwnProperty(n)){var r=t[n],a=u.mandatory[n](r);if(a!==void 0)e[n]=a;else throw new l.ConfigurationError(n,r)}else throw new l.ConfigurationError(n);for(var o in u.optional)if(t.hasOwnProperty(o)){var s=t[o];if(i.isEmpty(s))continue;var c=u.optional[o](s);if(c!==void 0)e[o]=c;else throw new l.ConfigurationError(o,s)}}})),$t=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=Y().EventEmitter,m=X(),h=G(),g=Rt(),_=Gt(),v=Kt(),y=qt(),b=It(),x=Yt(),S=J(),C=K(),w=Dt(),T=Xt(),E=Q(),D=Zt(),O=Qt(),k=new m(`UA`),A={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};t.exports=function(e){o(n,e);var t=c(n);a(n,null,[{key:`C`,get:function(){return A}}]);function n(e){var i;if(r(this,n),k.debug(`new() [configuration:%o]`,e),i=t.call(this),i._cache={credentials:{}},i._configuration=Object.assign({},O.settings),i._dynConfiguration={},i._dialogs={},i._applicants={},i._sessions={},i._transport=null,i._contact=null,i._status=A.STATUS_INIT,i._error=null,i._transactions={nist:{},nict:{},ist:{},ict:{}},i._data={},i._closeTimer=null,e===void 0)throw TypeError(`Not enough arguments`);try{i._loadConfig(e)}catch(e){throw i._status=A.STATUS_NOT_READY,i._error=A.CONFIGURATION_ERROR,e}return i._registrator=new g(u(i)),i}return a(n,[{key:`start`,value:function(){k.debug(`start()`),this._status===A.STATUS_INIT?this._transport.connect():this._status===A.STATUS_USER_CLOSED?(k.debug(`restarting UA`),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=A.STATUS_INIT,this._transport.connect()):this._status===A.STATUS_READY?k.debug(`UA is in READY status, not restarted`):k.debug(`ERROR: connection is down, Auto-Recovery system is trying to reconnect`),this._dynConfiguration.register=this._configuration.register}},{key:`register`,value:function(){k.debug(`register()`),this._dynConfiguration.register=!0,this._registrator.register()}},{key:`unregister`,value:function(e){k.debug(`unregister()`),this._dynConfiguration.register=!1,this._registrator.unregister(e)}},{key:`registrator`,value:function(){return this._registrator}},{key:`isRegistered`,value:function(){return this._registrator.registered}},{key:`isConnected`,value:function(){return this._transport.isConnected()}},{key:`call`,value:function(e,t){k.debug(`call()`);var n=new _(this);return n.connect(e,t),n}},{key:`sendMessage`,value:function(e,t,n){k.debug(`sendMessage()`);var r=new v(this);return r.send(e,t,n),r}},{key:`sendOptions`,value:function(e,t,n){k.debug(`sendOptions()`);var r=new y(this);return r.send(e,t,n),r}},{key:`terminateSessions`,value:function(e){for(var t in k.debug(`terminateSessions()`),this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}},{key:`stop`,value:function(){var e=this;if(k.debug(`stop()`),this._dynConfiguration={},this._status===A.STATUS_USER_CLOSED){k.debug(`UA already closed`);return}this._registrator.close();var t=Object.keys(this._sessions).length;for(var n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){k.debug(`closing session ${n}`);try{this._sessions[n].terminate()}catch{}}for(var r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch{}this._status=A.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){e._closeTimer=null,e._transport.disconnect()},2e3)}},{key:`normalizeTarget`,value:function(e){return S.normalizeTarget(e,this._configuration.hostport_params)}},{key:`get`,value:function(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:k.warn(`get() | cannot get "%s" parameter in runtime`,e);return}}},{key:`set`,value:function(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 k.warn(`set() | cannot set "%s" parameter in runtime`,e),!1}return!0}},{key:`newTransaction`,value:function(e){this._transactions[e.type][e.id]=e,this.emit(`newTransaction`,{transaction:e})}},{key:`destroyTransaction`,value:function(e){delete this._transactions[e.type][e.id],this.emit(`transactionDestroyed`,{transaction:e})}},{key:`newDialog`,value:function(e){this._dialogs[e.id]=e}},{key:`destroyDialog`,value:function(e){delete this._dialogs[e.id]}},{key:`newMessage`,value:function(e,t){this._applicants[e]=e,this.emit(`newMessage`,t)}},{key:`newOptions`,value:function(e,t){this._applicants[e]=e,this.emit(`newOptions`,t)}},{key:`destroyMessage`,value:function(e){delete this._applicants[e]}},{key:`newRTCSession`,value:function(e,t){this._sessions[e.id]=e,this.emit(`newRTCSession`,t)}},{key:`destroyRTCSession`,value:function(e){delete this._sessions[e.id]}},{key:`registered`,value:function(e){this.emit(`registered`,e)}},{key:`unregistered`,value:function(e){this.emit(`unregistered`,e)}},{key:`registrationFailed`,value:function(e){this.emit(`registrationFailed`,e)}},{key:`receiveRequest`,value:function(e){var t=e.method;if(e.ruri.user!==this._configuration.uri.user&&e.ruri.user!==this._contact.uri.user){k.debug(`Request-URI does not point to us`),e.method!==h.ACK&&e.reply_sl(404);return}if(e.ruri.scheme===h.SIPS){e.reply_sl(416);return}if(!b.checkTransaction(this,e)){if(t===h.INVITE?new b.InviteServerTransaction(this,this._transport,e):t!==h.ACK&&t!==h.CANCEL&&new b.NonInviteServerTransaction(this,this._transport,e),t===h.OPTIONS){if(this.listeners(`newOptions`).length===0){e.reply(200);return}new y(this).init_incoming(e)}else if(t===h.MESSAGE){if(this.listeners(`newMessage`).length===0){e.reply(405);return}new v(this).init_incoming(e)}else if(t===h.INVITE&&!e.to_tag&&this.listeners(`newRTCSession`).length===0){e.reply(405);return}var n,r;if(e.to_tag)n=this._findDialog(e.call_id,e.from_tag,e.to_tag),n?n.receiveRequest(e):t===h.NOTIFY?(r=this._findSession(e),r?r.receiveRequest(e):(k.debug(`received NOTIFY request for a non existent subscription`),e.reply(481,`Subscription does not exist`))):t!==h.ACK&&e.reply(481);else switch(t){case h.INVITE:if(window.RTCPeerConnection){if(e.hasHeader(`replaces`)){var i=e.replaces;n=this._findDialog(i.call_id,i.from_tag,i.to_tag),n?(r=n.owner,r.isEnded()?e.reply(603):r.receiveRequest(e)):e.reply(481)}else r=new _(this),r.init_incoming(e)}else k.warn(`INVITE received but WebRTC is not supported`),e.reply(488);break;case h.BYE:e.reply(481);break;case h.CANCEL:r=this._findSession(e),r?r.receiveRequest(e):k.debug(`received CANCEL request for a non existent session`);break;case h.ACK:break;case h.NOTIFY:this.emit(`sipEvent`,{event:e.event,request:e}),e.reply(200);break;default:e.reply(405)}}}},{key:`_findSession`,value:function(e){var t=e.call_id,n=e.from_tag,r=e.to_tag,i=t+n,a=this._sessions[i],o=t+r,s=this._sessions[o];return a||s||null}},{key:`_findDialog`,value:function(e,t,n){var r=e+t+n,i=this._dialogs[r];return i||(r=e+n+t,i=this._dialogs[r],i||null)}},{key:`_loadConfig`,value:function(e){try{O.load(this._configuration,e)}catch(e){throw e}this._configuration.display_name===0&&(this._configuration.display_name=`0`),this._configuration.instance_id||(this._configuration.instance_id=S.newUUID()),this._configuration.jssip_id=S.createRandomToken(5);var t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,``);try{this._transport=new x(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=j.bind(this),this._transport.onconnect=M.bind(this),this._transport.ondisconnect=N.bind(this),this._transport.ondata=P.bind(this)}catch(e){throw k.warn(e),new C.ConfigurationError(`sockets`,this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var n=this._configuration.uri.clone();n.user=null,n.clearParams(),n.clearHeaders(),this._configuration.registrar_server=n}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new w(`sip`,S.createRandomToken(8),this._configuration.via_host,null,{transport:`ws`}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r=`<`;return r+=t?this.temp_gruu||`sip:anonymous@anonymous.invalid;transport=ws`:this.pub_gruu||this.uri.toString(),n&&(t?!this.temp_gruu:!this.pub_gruu)&&(r+=`;ob`),r+=`>`,r}};var r=[`authorization_user`,`password`,`realm`,`ha1`,`authorization_jwt`,`display_name`,`register`,`extra_headers`];for(var i in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,i)&&(r.indexOf(i)===-1?Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}));for(var a in k.debug(`configuration parameters after validation:`),this._configuration)if(Object.prototype.hasOwnProperty.call(O.settings,a))switch(a){case`uri`:case`registrar_server`:k.debug(`- ${a}: ${this._configuration[a]}`);break;case`password`:case`ha1`:case`authorization_jwt`:k.debug(`- ${a}: NOT SHOWN`);break;default:k.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}},{key:`C`,get:function(){return A}},{key:`status`,get:function(){return this._status}},{key:`contact`,get:function(){return this._contact}},{key:`configuration`,get:function(){return this._configuration}},{key:`transport`,get:function(){return this._transport}}]),n}(p);function j(e){this.emit(`connecting`,e)}function M(e){this._status!==A.STATUS_USER_CLOSED&&(this._status=A.STATUS_READY,this._error=null,this.emit(`connected`,e),this._dynConfiguration.register&&this._registrator.register())}function N(e){for(var t=[`nict`,`ict`,`nist`,`ist`],n=0,r=t;n<r.length;n++){var i=r[n];for(var a in this._transactions[i])Object.prototype.hasOwnProperty.call(this._transactions[i],a)&&this._transactions[i][a].onTransportError()}this.emit(`disconnected`,e),this._registrator.onTransportClosed(),this._status!==A.STATUS_USER_CLOSED&&(this._status=A.STATUS_NOT_READY,this._error=A.NETWORK_ERROR)}function P(e){var t=e.transport,n=e.message;if(n=T.parseMessage(n,this),n&&!(this._status===A.STATUS_USER_CLOSED&&n instanceof E.IncomingRequest)&&D(n,this,t)){if(n instanceof E.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof E.IncomingResponse){var r;switch(n.method){case h.INVITE:r=this._transactions.ict[n.via_branch],r&&r.receiveResponse(n);break;case h.ACK:break;default:r=this._transactions.nict[n.via_branch],r&&r.receiveResponse(n)}}}}})),en=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=X(),o=q(),s=new a(`WebSocketInterface`);t.exports=function(){function e(t){n(this,e),s.debug(`new() [url:"%s"]`,t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var r=o.parse(t,`absoluteURI`);if(r===-1)throw s.warn(`invalid WebSocket URI: ${t}`),TypeError(`Invalid argument: ${t}`);if(r.scheme!==`wss`&&r.scheme!==`ws`)throw s.warn(`invalid WebSocket URI scheme: ${r.scheme}`),TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${r.host}${r.port?`:${r.port}`:``};transport=ws`,this._via_transport=r.scheme.toUpperCase()}return i(e,[{key:`connect`,value:function(){if(s.debug(`connect()`),this.isConnected()){s.debug(`WebSocket ${this._url} is already connected`);return}if(this.isConnecting()){s.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),s.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)}}},{key:`disconnect`,value:function(){s.debug(`disconnect()`),this._ws&&=(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),null)}},{key:`send`,value:function(e){return s.debug(`send()`),this.isConnected()?(this._ws.send(e),!0):(s.warn(`unable to send message, WebSocket is not open`),!1)}},{key:`isConnected`,value:function(){return this._ws&&this._ws.readyState===this._ws.OPEN}},{key:`isConnecting`,value:function(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}},{key:`_onOpen`,value:function(){s.debug(`WebSocket ${this._url} connected`),this.onconnect()}},{key:`_onClose`,value:function(e){var t=e.wasClean,n=e.code,r=e.reason;s.debug(`WebSocket ${this._url} closed`),t===!1&&s.debug(`WebSocket abrupt disconnection`),this.ondisconnect(!t,n,r)}},{key:`_onMessage`,value:function(e){var t=e.data;s.debug(`received WebSocket message`),this.ondata(t)}},{key:`_onError`,value:function(e){s.warn(`WebSocket ${this._url} error: `,e)}},{key:`via_transport`,get:function(){return this._via_transport},set:function(e){this._via_transport=e.toUpperCase()}},{key:`sip_uri`,get:function(){return this._sip_uri}},{key:`url`,get:function(){return this._url}}]),e}()})),tn=c(((e,t)=>{var n=(Tt(),f(lt).default),r=G(),i=K(),a=J(),o=$t(),s=Dt(),c=Et(),l=q(),u=en();At()(`JsSIP`)(`version %s`,n.version),t.exports={C:r,Exceptions:i,Utils:a,UA:o,URI:s,NameAddrHeader:c,WebSocketInterface:u,Grammar:l,debug:At(),get name(){return n.title},get version(){return n.version}}})),nn=l({createJsSipFactory:()=>rn});function rn(){return{createSocket:(e,t)=>new on(e,t),createUa:e=>new an.UA(e)}}var an,on,sn=s((()=>{an=d(tn(),1),on=class extends an.WebSocketInterface{ticket;constructor(e,t){super(e),this.ticket=t}protocols(){return this.ticket===``?[`sip`]:[`xcall-ticket.${this.ticket}`,`sip`]}connect(){if(this.isConnected()||this.isConnecting())return;let e=this;e._ws&&this.disconnect();try{e._ws=new WebSocket(this.url,this.protocols()),e._ws.binaryType=`arraybuffer`,e._ws.onopen=e._onOpen.bind(this),e._ws.onclose=e._onClose.bind(this),e._ws.onmessage=e._onMessage.bind(this),e._ws.onerror=e._onError.bind(this)}catch(t){e._onError.call(this,t)}}}}));function cn(e){let t=new Map;return{peerConnection:{getSenders:()=>e.getSenders().map(n=>{let r=t.get(n);if(r!==void 0)return r;let i={get track(){return n.track},get senderKind(){let t=n.track;if(t!==null)return t.kind===`audio`||t.kind===`video`?t.kind:void 0;let r=e.getTransceivers().find(e=>e.sender===n)?.receiver.track;if(r?.kind===`audio`||r?.kind===`video`)return r.kind;let i=n.getParameters().codecs?.find(e=>typeof e.mimeType==`string`);if(i?.mimeType?.toLowerCase().startsWith(`video/`))return`video`;if(i?.mimeType?.toLowerCase().startsWith(`audio/`))return`audio`},replaceTrack:e=>n.replaceTrack(e)};return t.set(n,i),i}),close:()=>{e.connectionState!==`closed`&&e.close()}},trackSource:{onTrack(t){let n=e=>{let n=e.track;t({streams:[...e.streams],track:n})};return e.addEventListener(`track`,n),()=>e.removeEventListener(`track`,n)}}}}var ln=s((()=>{})),un=l({JsSipAdapter:()=>Sn});function dn(e){let t=Math.floor(Number(e.sip.registerExpires));return Number.isFinite(t)&&t>0?t:_n}function fn(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.originator===`remote`&&pn(t.session)}function pn(e){return typeof e==`object`&&!!e&&`id`in e}function mn(e){return typeof e==`object`&&e&&(e.via_transport=`WSS`),e}function hn(e){let t=e.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`0:0:0:0:0:0:0:1`}function gn(e){let t=e?.uri;if(t==null)return;if(typeof t.user==`string`&&t.user!==``)return t.user;let n=t.toString();return n.match(/^sips?:([^@;>]+)/i)?.[1]??(n===``?void 0:n)}var _n,vn,yn,bn,xn,Sn,Cn,wn=s((()=>{m(),ln(),_n=300,vn=25,yn=2,bn=``,xn=120,Sn=class{factory;transportBaseUrl;keepaliveSeconds;agentTerminal;sessionTimers;ua;uaListeners;incomingHandlers;iceServers;pendingConnection;disposed=!1;warmPc;keepaliveTimer;keepaliveBusy=!1;registerExpiresSeconds=0;connectionHandlers=new Set;constructor(e,t,n=vn,r=bn,i=!1){this.factory=e,this.transportBaseUrl=t,this.keepaliveSeconds=n,this.agentTerminal=r,this.sessionTimers=i}terminalHeaders(){return this.agentTerminal===``?[]:[`X-Agent-Terminal: ${this.agentTerminal}`]}warmIceCandidatePool(){if(this.closeWarmPc(),typeof RTCPeerConnection<`u`&&this.iceServers!==void 0)try{this.warmPc=new RTCPeerConnection({iceServers:[...this.iceServers],iceCandidatePoolSize:yn})}catch{this.warmPc=void 0}}closeWarmPc(){try{this.warmPc?.close()}catch{}this.warmPc=void 0}keepaliveTick(e){if(this.isCurrentUa(e)&&!this.keepaliveBusy)try{if(typeof e.isConnected==`function`&&e.isConnected()===!1||typeof e.register!=`function`)return;this.keepaliveBusy=!0,e.register({extraHeaders:this.terminalHeaders()})}catch{}finally{this.keepaliveBusy=!1}}startKeepalive(e,t){if(this.stopKeepalive(),!Number.isFinite(this.keepaliveSeconds)||this.keepaliveSeconds<=0||t>0&&t<=this.keepaliveSeconds)return;let n=Math.max(10,Math.floor(this.keepaliveSeconds))*1e3;this.keepaliveTimer=setInterval(()=>this.keepaliveTick(e),n)}stopKeepalive(){this.keepaliveTimer!==void 0&&clearInterval(this.keepaliveTimer),this.keepaliveTimer=void 0}connect(e){this.assertNotDisposed(),this.disconnect(this.registrationError(`SIP connection replaced`));try{let t=this.factory.createUa({sockets:mn(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(e.transport.wssUrl)),e.transport.ticket)),uri:e.sip.uri,password:e.sip.registerTicket,registrar_server:e.sip.registrar,register:!0,register_expires:dn(e),session_timers:this.sessionTimers,...this.agentTerminal===``?{}:{user_agent:this.agentTerminal}});return this.ua=t,this.registerExpiresSeconds=dn(e),this.iceServers=e.iceServers,this.uaListeners=[],this.startRegistration(t)}catch(e){let t=e instanceof p&&e.code===`CONFIG_INVALID`?e:this.transportError(e);return this.disconnect(t),Promise.reject(t)}}disconnect(e=this.registrationError(`SIP connection disconnected`)){this.stopKeepalive(),this.closeWarmPc();let t=this.pendingConnection;this.pendingConnection=void 0,this.ua!==void 0&&(this.removeUaListeners(this.ua),this.ua.stop()),this.ua=void 0,this.uaListeners=void 0,this.iceServers=void 0,t?.reject(e)}dial(e,t){let n=this.requireUa();if(e.trim()===``)throw new p(`CALL_INVALID_DESTINATION`,`call`,!1);try{let r=t===void 0?{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:xn,pcConfig:{iceServers:this.iceServers,iceCandidatePoolSize:yn}}:{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:xn,pcConfig:{iceServers:[...t.iceServers],iceCandidatePoolSize:yn},extraHeaders:[...this.terminalHeaders(),...t.extraHeaders,...t.type===`extension`?[`X-XCall-Destination-Type: extension`]:[]]};return new Cn(n.call(e,r))}catch(e){throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:e})}}onIncoming(e){this.assertNotDisposed();let t=this.incomingHandlers??new Set;return this.incomingHandlers=t,t.add(e),()=>t.delete(e)}onConnectionStateChanged(e){return this.disposed?()=>void 0:(this.connectionHandlers.add(e),()=>this.connectionHandlers.delete(e))}dispose(){this.disposed||(this.disposed=!0,this.disconnect(),this.incomingHandlers=void 0,this.connectionHandlers.clear())}getResourceCounts(){return{listeners:(this.uaListeners?.length??0)+(this.incomingHandlers?.size??0)+this.connectionHandlers.size,webSockets:this.ua===void 0?0:1}}handleIncoming(e){if(!fn(e))return;let t=e.session;if(t===void 0)return;let n=new Cn(t);this.incomingHandlers?.forEach(e=>e(n))}startRegistration(e){let t=!0,n=!1,r=new Promise((t,n)=>{this.pendingConnection={ua:e,resolve:t,reject:n}});this.listen(e,`registered`,()=>{if(this.isCurrentUa(e)){if(t){n=!0;return}this.resolveConnection(e)}}),this.listen(e,`registrationFailed`,t=>{if(!this.isCurrentUa(e))return;let n=this.registrationError(this.registrationFailureCause(t));this.connectionHandlers.forEach(e=>e(`failed`,n)),this.disconnect(n)}),this.listen(e,`disconnected`,t=>{if(!this.isCurrentUa(e))return;let n=this.transportError(t);this.connectionHandlers.forEach(e=>e(`disconnected`,n)),this.disconnect(n)}),this.listen(e,`newRTCSession`,t=>{this.isCurrentUa(e)&&this.handleIncoming(t)});try{e.start()}catch(e){let t=this.transportError(e);this.connectionHandlers.forEach(e=>e(`failed`,t)),this.disconnect(t)}finally{t=!1}return n&&this.resolveConnection(e),r}listen(e,t,n){e.on(t,n),this.uaListeners?.push({event:t,handler:n})}removeUaListeners(e){this.uaListeners?.forEach(({event:t,handler:n})=>e.off(t,n))}isCurrentUa(e){return this.ua===e}resolveConnection(e){let t=this.pendingConnection;t?.ua===e&&(this.pendingConnection=void 0,t.resolve(),this.warmIceCandidatePool(),this.startKeepalive(e,this.registerExpiresSeconds),this.connectionHandlers.forEach(e=>e(`registered`)))}resolveWssUrl(e){let t=this.transportBaseUrl?.trim()===``||this.transportBaseUrl===void 0?typeof location>`u`?`http://localhost`:location.origin:this.transportBaseUrl,n=e.startsWith(`/`)?new URL(e,t):new URL(e);return n.protocol===`http:`&&(n.protocol=`ws:`),n.protocol===`https:`&&(n.protocol=`wss:`),this.assertAllowedWssUrl(n),n.toString()}assertAllowedWssUrl(e){if(e.protocol!==`wss:`&&!(e.protocol===`ws:`&&hn(e.hostname)))throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:e.origin})}withoutTicket(e){let t=new URL(e);return t.searchParams.delete(`ticket`),t.toString()}requireUa(){if(this.assertNotDisposed(),this.ua===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return this.ua}assertNotDisposed(){if(this.disposed)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}registrationError(e){return new p(`REGISTRATION_FAILED`,`registration`,!0,{cause:e})}transportError(e){return new p(`SIP_WS_UNAVAILABLE`,`registration`,!0,{cause:e})}registrationFailureCause(e){return typeof e==`object`&&e&&`cause`in e?e.cause:e}},Cn=class{session;pendingHoldReject;mediaRegistration;mediaConnection;mediaHandlers=new Set;mediaWatchStarted=!1;sessionUnsubscribeFromPeerConnection;constructor(e){this.session=e}get id(){return this.session.id}get from(){return this.session.from??gn(this.session.remote_identity)}getMediaRegistration(){let e=this.session.connection;if(e!=null)return this.mediaRegistration!==void 0&&this.mediaConnection===e?this.mediaRegistration:(this.mediaConnection=e,this.mediaRegistration=cn(e),this.mediaRegistration)}answer(e){this.session.answer({mediaConstraints:e.mediaConstraints,pcConfig:{iceServers:[...e.pcConfig.iceServers]}})}terminate(){this.pendingHoldReject?.(Error(`SIP session terminated`)),this.session.terminate()}hold(){return this.changeHoldState(`hold`)}unhold(){return this.changeHoldState(`unhold`)}mute(){this.session.mute()}unmute(){this.session.unmute()}sendDtmf(e){this.session.sendDTMF(e)}refer(e){this.session.refer(e)}on(e,t){return e===`mediaConnected`?(this.mediaHandlers.add(t),this.watchMediaConnection(),()=>{this.mediaHandlers.delete(t),this.mediaHandlers.size===0&&(this.sessionUnsubscribeFromPeerConnection?.(),this.sessionUnsubscribeFromPeerConnection=void 0)}):(this.session.on(e,t),()=>this.session.off(e,t))}watchMediaConnection(){if(this.mediaWatchStarted)return;this.mediaWatchStarted=!0;let e=!1,t=t=>{if(t==null)return;let n=()=>{if(e)return;let n=t.connectionState||t.iceConnectionState;if(n===`connected`){e=!0;for(let e of this.mediaHandlers)try{e({state:n})}catch{}}};t.addEventListener(`connectionstatechange`,n),n()},n=this.session.connection;if(n!=null){t(n);return}let r=e=>{t(e?.peerconnection??void 0)};this.session.on(`peerconnection`,r),this.sessionUnsubscribeFromPeerConnection=()=>this.session.off(`peerconnection`,r)}changeHoldState(e){return new Promise((t,n)=>{let r=!1,i=e=>{s(e)},a=()=>{try{this.session.off(`ended`,i)}catch{}try{this.session.off(`failed`,i)}catch{}this.pendingHoldReject===s&&(this.pendingHoldReject=void 0)},o=()=>{r||(r=!0,a(),t())},s=e=>{r||(r=!0,a(),n(new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:e})))};try{this.session.on(`ended`,i),this.session.on(`failed`,i)}catch(e){s(e);return}this.pendingHoldReject=s;try{this.session[e](void 0,o)||s()}catch(e){s(e)}})}}}));m();var Tn=class e{media;options;api;suppliedSip;sip;events=new h;mediaBridge;reconnect;diagnostics;callManager;session;state=`idle`;initialized=!1;disposed=!1;intentionalDisconnect=!1;deferredRebuild=!1;sessionRecoveryPending=!1;detectedPlatform;support;acceptingEvents=!0;connectOperation;disconnectOperation;refreshOperation;disposeOperation;refreshTimer;lifecycleGeneration=0;managerUnsubscribers=[];sipUnsubscribe;networkUnsubscribers=[];sessionDeleteOperations=new Map;deletedSessions=new Set;ownedSessionIds=new Set;terminalReleaseOperations=new Map;tokenRequest={};sharedWorkerSelection;constructor(e){if(this.options=e,e.api===void 0&&e.sessionProvider===void 0&&e.tokenProvider===void 0)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:`CCBarClient 需要 tokenProvider 或 sessionProvider`});let t=e.tokenProvider,n=e=>t===void 0?Promise.reject(new p(`CONFIG_INVALID`,`configuration`,!1,{cause:`未提供 tokenProvider`})):t({...e,...this.tokenRequest});this.api=e.api===void 0?e.sessionProvider===void 0?new T({baseUrl:e.baseUrl??``,tokenProvider:n}):On(kn(e.sessionProvider)):On(e.api),this.suppliedSip=e.sip===void 0?void 0:An(e.sip),this.mediaBridge=Ke(()=>this.getActiveMediaContext()),this.media=this.mediaBridge.publicMedia,this.reconnect=new Qe({recover:()=>this.recoverConnection(),onAttempt:e=>{this.disposed||this.events.emit(`connection.reconnecting`,{attempt:e})}}),this.diagnostics=new nt({getSnapshot:()=>this.createDiagnosticsSnapshot(),getPermission:()=>this.readMicrophonePermission(),getDeviceNames:async()=>(await this.media.getDevices()).map(e=>e.label).filter(e=>e!==``)}),this.sharedWorkerSelection=e.sharedWorker===void 0?{mode:`single-tab`,reason:`disabled`}:be({...e.sharedWorker,...e.sharedWorkerHost??{}})}static async checkSupport(){let e=typeof navigator<`u`&&navigator.mediaDevices!==void 0,t=typeof WebSocket<`u`,n=Dn(typeof navigator<`u`?navigator.userAgent:``);return{supported:e&&t,platform:n,hasMediaDevices:e,hasWebSocket:t,...e&&t?{}:{reason:`当前运行环境缺少 WebPhone 所需的浏览器能力`}}}async initialize(){if(this.assertNotDisposed(),this.initialized)return;let t=await e.checkSupport();this.support=t,this.options.platform===void 0&&(t.platform===`web`||t.platform===`mobile-web`)&&(this.detectedPlatform=t.platform),await this.awaitSharedWorkerReady(),this.assertNotDisposed(),this.initialized=!0}connect(e){this.assertNotDisposed();let t=e?.extension?.trim();if(this.tokenRequest=t===void 0||t===``?{}:{extension:t},this.api.invalidateToken?.(),this.connectOperation!==void 0)return this.connectOperation;if(this.state===`connected`)return Promise.resolve();let n=this.lifecycleGeneration,r=this.performConnect(n).finally(()=>{this.connectOperation===r&&(this.connectOperation=void 0)});return this.connectOperation=r,r}disconnect(){if(this.assertNotDisposed(),this.disconnectOperation!==void 0)return this.disconnectOperation;if(this.state===`idle`&&this.connectOperation===void 0||this.state===`disconnected`&&this.connectOperation===void 0)return Promise.resolve();this.lifecycleGeneration+=1,this.acceptingEvents=!1;let e=this.performDisconnect().finally(()=>{this.disconnectOperation===e&&(this.disconnectOperation=void 0)});return this.disconnectOperation=e,e}dispose(){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposed=!0,this.lifecycleGeneration+=1,this.intentionalDisconnect=!0,this.acceptingEvents=!1,this.reconnect.dispose(),this.clearRefreshTimer(),this.detachNetworkListeners(),this.releaseSharedWorker(),this.state=`disconnected`,this.diagnostics.log(`info`,`connection.stateChanged`,{state:`disconnected`}),this.detachSipListener(),this.detachManagerListeners();let e=!1,t=this.performDispose().then(()=>{e=!0}).finally(()=>{this.disposeOperation===t&&!e&&(this.disposeOperation=void 0)});return this.disposeOperation=t,t}recover(){return this.assertNotDisposed(),this.recoverConnection()}dial(e){this.assertConnected();let t=this.callManager,n=this.session;if(t===void 0||n===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return t.dial(e,n)}answer(e,t){this.assertConnected();let n=this.callManager,r=this.session;if(n===void 0||r===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return n.answer(e,r,t)}setActiveCall(e){this.assertConnected();let t=this.callManager;if(t===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return t.setActiveCall(e)}getCalls(){return this.callManager?.getCalls()??[]}getActiveCall(){return this.callManager?.getActiveCall()}getAgent(){return this.session?.agent}getSharedWorkerState(){let e=this.sharedWorkerSelection;return e.mode===`shared`?{mode:`shared`,tabId:e.tabId}:{mode:`single-tab`,reason:e.reason}}getDiagnostics(e={}){return this.diagnostics.getReport(e)}async setAgentStatus(e){this.assertNotDisposed(),await this.api.setAgentStatus({status:e,reason:``}),this.disposed||this.events.emit(`agent.statusChanged`,{status:e})}on(e,t){return this.disposed?()=>void 0:this.events.on(e,t)}off(e,t){this.events.off(e,t)}async performConnect(e){let t,n,r;try{await this.initialize(),this.assertGeneration(e);let i=this.resolvePlatform();this.intentionalDisconnect=!1,this.acceptingEvents=!0,this.setConnectionState(`connecting`),t=await this.api.createSession({sdkVersion:ie,platform:i===`mobile-web`?`mobile_web`:`web`,...this.options.locale===void 0?{}:{locale:this.options.locale},requestedCapabilities:[...this.options.requestedCapabilities??Ln(i)]}),this.ownedSessionIds.add(t.sessionId),this.assertGeneration(e),n=await this.getSip(),this.assertGeneration(e),this.session=t;let a=this.callManager??this.createCallManager(n,t,i);this.callManager===void 0&&(r=a),a.updateSession(t),this.callManager=a,this.attachSipListener(n),this.attachNetworkListeners(),await n.connect(t),this.assertGeneration(e),this.setConnectionState(`connected`),this.events.emit(`connection.registered`,{registered:!0}),this.scheduleRefresh(t)}catch(i){if(await this.rollbackConnect(t,n,r),this.disposed)throw this.disposedError();if(e!==this.lifecycleGeneration)throw i;let a=jn(i,`REGISTRATION_FAILED`,`registration`,!0);throw this.setConnectionState(`failed`),this.events.emit(`connection.failed`,{error:a}),a}}async performDisconnect(){let e,t=this.connectOperation;if(t!==void 0)try{await t}catch(t){Pn(t)||(e??=t)}let n=this.refreshOperation;if(n!==void 0)try{await n}catch(t){Pn(t)||(e??=t)}this.reconnect.cancel(),this.clearRefreshTimer(),this.intentionalDisconnect=!0,this.detachNetworkListeners(),this.detachSipListener(),this.detachManagerListeners();let r=this.callManager,i=this.sip;this.callManager=void 0;try{await r?.dispose({terminateCalls:!0})}catch(t){e??=t}try{await this.awaitMediaReleaseBarriers()}catch(t){e??=t}try{i!==void 0&&await i.disconnect()}catch(t){e??=t}this.session=void 0;try{await this.deleteOwnedSessions()}catch(t){e??=t}if(this.pruneDeletedSessionTombstones(),this.disposed||(this.acceptingEvents=!0,this.setConnectionState(`disconnected`)),e!==void 0)throw e}createCallManager(e,t,n){let r=new I({sip:e,platform:n,session:t,maxConcurrentCalls:this.options.maxConcurrentCalls,autoHoldPreviousCall:this.options.autoHoldPreviousCall,onCallCreated:(e,t)=>this.handleCallCreated(e,t),onCallStateChanged:(e,t)=>this.handleCallStateChanged(e,t),onCallTerminal:e=>this.handleCallTerminal(e)});return this.bindManagerEvents(r),r}async rollbackConnect(e,t,n){if(n!==void 0){this.detachManagerListeners(),this.callManager===n&&(this.callManager=void 0);try{await n.dispose({terminateCalls:!0})}catch{}}if(t!==void 0){this.detachSipListener();try{await t.disconnect()}catch{}}if(this.session===e&&(this.session=void 0),e!==void 0)try{await this.deleteSession(e.sessionId)}catch{}}async performDispose(){let e,t=[this.connectOperation,this.disconnectOperation,this.refreshOperation].filter(e=>e!==void 0);for(let n of t)try{await n}catch(t){Pn(t)||(e??=t)}let n=this.callManager;this.callManager=void 0;try{await n?.dispose({terminateCalls:!0})}catch(t){e??=t}try{await this.awaitMediaReleaseBarriers()}catch(t){e??=t}try{await this.media.releaseAll()}catch(t){Nn(t)||(e??=t)}try{await this.mediaBridge.dispose()}catch(t){e??=t}try{await this.sip?.dispose()}catch(t){e??=t}try{await this.deleteOwnedSessions()}catch(t){e??=t}if(this.pruneDeletedSessionTombstones(),this.session=void 0,this.sipUnsubscribe=void 0,this.events.clear(),e!==void 0)throw e}async awaitMediaReleaseBarriers(){let e;for(let[t,n]of[...this.terminalReleaseOperations])try{await n,this.terminalReleaseOperations.delete(t)}catch(n){try{await this.mediaBridge.releaseCall(t),this.terminalReleaseOperations.delete(t)}catch(t){e??=t??n}}if(e!==void 0)throw e}detachSipListener(){let e=this.sipUnsubscribe;this.sipUnsubscribe=void 0;try{e?.()}catch{}}detachManagerListeners(){this.managerUnsubscribers.splice(0).forEach(e=>{try{e()}catch{}})}bindManagerEvents(e){[`call.created`,`call.incoming`,`call.stateChanged`,`call.activeChanged`,`call.ended`,`call.failed`,`error`].forEach(t=>{let n=e.on(t,e=>{this.acceptingEvents&&!this.disposed&&(this.diagnostics.log(t===`error`||t===`call.failed`?`error`:`info`,String(t),e),this.events.emit(t,e))});this.managerUnsubscribers.push(n)})}handleCallCreated(e,t){this.acceptingEvents&&!this.disposed&&this.mediaBridge.registerCall(e,t)}handleCallStateChanged(e,t){this.acceptingEvents&&!this.disposed&&this.mediaBridge.registerCall(e,t)}handleCallTerminal(e){let t=this.startTerminalRelease(e);return this.deferredRebuild&&!this.hasNonTerminalCalls()&&this.startDeferredRecovery(),t}startTerminalRelease(e){let t=this.terminalReleaseOperations.get(e);if(t!==void 0)return t;let n=this.mediaBridge.releaseCall(e).then(()=>{this.terminalReleaseOperations.get(e)===n&&this.terminalReleaseOperations.delete(e)}).catch(t=>{throw this.acceptingEvents&&!this.disposed&&this.events.emit(`error`,{error:jn(t,`SDK_INTERNAL_ERROR`,`internal`,!0,e)}),t});return this.terminalReleaseOperations.set(e,n),n}async startDeferredRecovery(){try{if(await this.awaitMediaReleaseBarriers(),this.deferredRebuild&&!this.hasNonTerminalCalls()&&!this.disposed){if(this.sessionRecoveryPending){this.recoverInvalidSession();return}this.deferredRebuild=!1,this.clearRefreshTimer(),this.reconnect.start()}}catch{!this.disposed&&!this.sessionRecoveryPending&&this.reconnect.start()}}async refreshAndRebuild(){if(this.refreshOperation!==void 0)return this.refreshOperation;let e=this.performRefreshAndRebuild().finally(()=>{this.refreshOperation===e&&(this.refreshOperation=void 0),this.sessionRecoveryPending&&!this.hasNonTerminalCalls()&&!this.disposed&&this.recoverInvalidSession()});return this.refreshOperation=e,e}async performRefreshAndRebuild(){if(this.disposed||this.session===void 0)return;let e=this.lifecycleGeneration,t=this.session;try{let n=await this.api.refreshSession(t.sessionId);if(!this.isCurrentGeneration(e)||this.session!==t)return;if(this.session=n,this.callManager?.updateSession(n),this.events.emit(`token.refreshed`,{expiresAt:n.expiresAt}),this.hasNonTerminalCalls()){this.deferredRebuild=!0,this.scheduleRefresh(n);return}let r=await this.getSip();if(!this.isCurrentGeneration(e))return;await r.connect(n),this.isCurrentGeneration(e)&&(this.deferredRebuild=!1,this.setConnectionState(`connected`),this.scheduleRefresh(n))}catch(n){if(!this.isCurrentGeneration(e))return;throw this.handleRefreshFailure(t,n),n}}handleRefreshFailure(e,t){if(this.disposed)return;let n=jn(t,`NETWORK_OFFLINE`,`network`,!0);if(this.events.emit(`token.expiring`,{expiresAt:e.expiresAt}),this.events.emit(`error`,{error:n}),Mn(t)){this.clearRefreshTimer(),this.reconnect.cancel(),this.deletedSessions.add(e.sessionId),this.sessionRecoveryPending=!0,this.deferredRebuild=!0,(n.code===`AUTH_TOKEN_UNAVAILABLE`||n.code===`AUTH_TOKEN_EXPIRED`)&&this.api.invalidateToken?.();return}this.deferredRebuild=!0,this.hasNonTerminalCalls()||this.reconnect.start()}async recoverInvalidSession(){if(!(!this.sessionRecoveryPending||this.disposed||this.hasNonTerminalCalls())){this.sessionRecoveryPending=!1,this.deferredRebuild=!1;try{await this.performDisconnect()}catch(e){this.disposed||this.events.emit(`error`,{error:jn(e,`SDK_INTERNAL_ERROR`,`internal`,!0)});return}if(!this.disposed)try{await this.performConnect(this.lifecycleGeneration)}catch{this.reconnect.cancel()}}}scheduleRefresh(e){this.clearRefreshTimer();let t=e.expiresAt*1e3-Date.now()-6e4,n=Math.max(1e3,t);this.refreshTimer=setTimeout(()=>{this.refreshTimer=void 0,this.refreshAndRebuild().catch(()=>void 0)},n)}async recoverConnection(){this.disposed||this.intentionalDisconnect||this.hasNonTerminalCalls()||(await this.awaitMediaReleaseBarriers(),await this.refreshAndRebuild())}async getSip(){if(this.sip!==void 0)return this.sip;if(this.suppliedSip!==void 0)return this.sip=this.suppliedSip,this.sip;let[e,t]=await Promise.all([Promise.resolve().then(()=>(sn(),nn)),Promise.resolve().then(()=>(wn(),un))]);return this.sip=new t.JsSipAdapter(e.createJsSipFactory(),this.options.baseUrl,this.options.sipKeepaliveSeconds,this.options.agentTerminal,this.options.sipSessionTimers??!1),this.sip}attachSipListener(e){this.sipUnsubscribe===void 0&&e.onConnectionStateChanged!==void 0&&(this.sipUnsubscribe=e.onConnectionStateChanged((e,t)=>{if(!(this.disposed||this.intentionalDisconnect||!this.acceptingEvents)){if(e===`registered`){this.setConnectionState(`connected`);return}this.state===`connected`&&(this.setConnectionState(`reconnecting`),this.reconnect.start(),t!==void 0&&this.events.emit(`error`,{error:jn(t,`SIP_WS_UNAVAILABLE`,`registration`,!0)}))}}))}attachNetworkListeners(){if(this.networkUnsubscribers.length>0||typeof window>`u`)return;let e=window,t=()=>this.reconnect.notifyOnline(),n=()=>this.reconnect.notifyOffline();e.addEventListener(`online`,t),e.addEventListener(`offline`,n),this.networkUnsubscribers=[()=>e.removeEventListener(`online`,t),()=>e.removeEventListener(`offline`,n)]}detachNetworkListeners(){this.networkUnsubscribers.splice(0).forEach(e=>e())}getActiveMediaContext(){let e=this.callManager?.getActiveCall();return e===void 0?void 0:this.mediaBridge.contextFor(e.id,e.state,new Set(this.session?.capabilities??[]))}hasNonTerminalCalls(){return this.callManager?.hasNonTerminalCalls()??!1}clearRefreshTimer(){this.refreshTimer!==void 0&&(clearTimeout(this.refreshTimer),this.refreshTimer=void 0)}createDiagnosticsSnapshot(){let e=this.session;return{connectionState:this.state,calls:this.getCalls().map(e=>({callId:e.id,state:e.state,destination:e.destination})),permission:this.support?.hasMediaDevices===!1?`unsupported`:`unknown`,ice:En(e),wss:{configured:e!==void 0,secure:e?.transport.wssUrl.toLowerCase().startsWith(`wss://`)??!1,state:this.state},resources:this.getDiagnosticsResourceCounts()}}getDiagnosticsResourceCounts(){let e=this.mediaBridge.getResourceCounts(),t=this.callManager?.getResourceCounts()??{timers:0,listeners:0},n=this.sip?.getResourceCounts?.(),r=(this.callManager===void 0?0:1)+(this.sipUnsubscribe===void 0?0:1),i=this.session!==void 0&&this.state!==`idle`&&this.state!==`disconnected`;return{timers:(this.refreshTimer===void 0?0:1)+this.reconnect.getTimerCount()+t.timers,listeners:this.events.listenerCount()+t.listeners+e.listeners+this.networkUnsubscribers.length+(n?.listeners??r),tracks:e.tracks,peerConnections:e.peerConnections,audioElements:e.audioElements,webSockets:n?.webSockets??+!!i,deletedSessions:this.deletedSessions.size}}async readMicrophonePermission(){if(typeof navigator>`u`||navigator.mediaDevices===void 0)return`unsupported`;if(navigator.permissions===void 0)return`unknown`;try{return(await navigator.permissions.query({name:`microphone`})).state}catch{return`unknown`}}deleteSession(e){if(this.deletedSessions.has(e))return Promise.resolve();let t=this.sessionDeleteOperations.get(e);if(t!==void 0)return t;let n=this.api.deleteSession(e).then(()=>{this.deletedSessions.add(e)}).catch(t=>{if(Mn(t)){this.deletedSessions.add(e);return}throw t}).finally(()=>{this.sessionDeleteOperations.get(e)===n&&this.sessionDeleteOperations.delete(e)});return this.sessionDeleteOperations.set(e,n),n}pruneDeletedSessionTombstones(){for(let e of[...this.deletedSessions])!this.ownedSessionIds.has(e)&&!this.sessionDeleteOperations.has(e)&&this.deletedSessions.delete(e)}async deleteOwnedSessions(){let e;for(let t of[...this.ownedSessionIds])try{await this.deleteSession(t),this.ownedSessionIds.delete(t)}catch(t){e??=t}if(e!==void 0)throw e}resolvePlatform(){let e=this.options.platform??this.detectedPlatform;if(e===void 0)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:this.support?.platform??`unknown`});return e}setConnectionState(e){this.state===e||this.disposed||(this.state=e,this.diagnostics.log(`info`,`connection.stateChanged`,{state:e}),this.events.emit(`connection.stateChanged`,{state:e===`disconnected`||e===`idle`?`offline`:e}))}assertConnected(){if(this.assertNotDisposed(),this.state!==`connected`||this.callManager===void 0||this.session===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1)}assertGeneration(e){if(this.disposed)throw this.disposedError();if(e!==this.lifecycleGeneration)throw new p(`CALL_NOT_CONNECTED`,`call`,!1)}isCurrentGeneration(e){return!this.disposed&&e===this.lifecycleGeneration}async awaitSharedWorkerReady(){let e=this.sharedWorkerSelection;if(e.mode===`shared`)try{await e.ready}catch(e){if(this.disposed)return;if(this.options.sharedWorker?.fallback===`error`)throw e;this.sharedWorkerSelection={mode:`single-tab`,reason:e instanceof Error?e.message:`SharedWorker attach failed`}}}releaseSharedWorker(){let e=this.sharedWorkerSelection;if(this.sharedWorkerSelection={mode:`single-tab`,reason:`disposed`},e.mode===`shared`){try{e.client.request({version:1,type:`detach`,requestId:`detach-${e.tabId}`,tabId:e.tabId}).catch(()=>void 0)}catch{}e.client.close()}}assertNotDisposed(){if(this.disposed)throw this.disposedError()}disposedError(){return new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}};function En(e){if(e===void 0)return{configured:!1,serverCount:0,stunServerCount:0,turnServerCount:0};let t=0,n=0;return e.iceServers.forEach(e=>{let r=e.urls.map(e=>e.toLowerCase());r.some(e=>e.startsWith(`stun:`))&&(t+=1),r.some(e=>e.startsWith(`turn:`)||e.startsWith(`turns:`))&&(n+=1)}),{configured:e.iceServers.length>0,serverCount:e.iceServers.length,stunServerCount:t,turnServerCount:n}}function Dn(e){return e===``?`unknown`:/iPhone|iPad|Android/i.test(e)?`mobile-web`:`web`}function On(e){if(typeof e!=`object`||!e)throw new p(`CONFIG_INVALID`,`configuration`,!1);return e}function kn(e){let t={createSession:t=>e.createSession(t),refreshSession:t=>e.refreshSession===void 0?e.createSession({sdkVersion:ie,platform:`web`}):e.refreshSession(t),deleteSession:async t=>{e.deleteSession!==void 0&&await e.deleteSession(t)},setAgentStatus:t=>e.setAgentStatus===void 0?Promise.reject(new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{cause:`当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)`})):e.setAgentStatus(t)},n=e.invalidateToken;return n!==void 0&&(t.invalidateToken=()=>n()),t}function An(e){if(typeof e!=`object`||!e)throw new p(`CONFIG_INVALID`,`configuration`,!1);return e}function jn(e,t,n,r,i){return e instanceof p?new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:i??e.callId,cause:e.cause??e,serverCode:e.serverCode,status:e.status}):new p(t,n,r,{callId:i,cause:e})}function Mn(e){return e instanceof p?e.status!==void 0&&e.status>=400&&e.status<500||e.serverCode===`SESSION_NOT_FOUND`||e.serverCode===`SESSION_EXPIRED`||e.serverCode===`TOKEN_INVALID`||e.serverCode===`TOKEN_EXPIRED`||e.code===`AUTH_TOKEN_UNAVAILABLE`||e.code===`AUTH_TOKEN_EXPIRED`:!1}function Nn(e){return e instanceof p&&e.code===`SDK_ALREADY_DISPOSED`}function Pn(e){return e instanceof p&&(e.code===`SDK_ALREADY_DISPOSED`||e.code===`CALL_NOT_CONNECTED`)}var Fn=[`outbound`,`inbound`,`mute`,`hold`,`dtmf`,`blind_transfer`,`device_selection`],In=[`outbound`,`mute`,`dtmf`];function Ln(e){return e===`mobile-web`?In:Fn}m(),m();function Rn(e={}){return{version:`0.1.0`,options:e}}e.CCBarCall=O,e.CCBarClient=Tn,e.CCBarError=p,e.CallManager=I,e.CallStateError=y,e.Diagnostics=nt,e.RingBuffer=$e,e.TokenManager=S,e.TypedEventBus=h,e.WebPhoneApi=T,e.assertCallTransition=v,e.canTransition=_,e.createSdk=Rn,e.createSharedWorkerSelection=be,e.diagnosticsVersion=ie,e.parseSessionResponse=C,e.redactText=fe,e.redactValue=z,e.resolveWorkerUrl=xe,e.transition=b,e.transitions=g,e.version=`0.1.0`});
74
+ `,h.send(i)}})),Jt=c((e=>{function t(e,t){var r;if(typeof Symbol>`u`||e[Symbol.iterator]==null){if(Array.isArray(e)||(r=n(e))||t&&e&&typeof e.length==`number`){r&&(e=r);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
75
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&r.return!=null&&r.return()}finally{if(s)throw c}}}}function n(e,t){if(e){if(typeof e==`string`)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}}function r(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var i=q(),a=W(),o=K(),s=wt(),c=Wt(),l=G();e.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:a.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:a.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:a.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${i.createRandomToken(12)}.invalid`};var u={mandatory:{sockets:function(e){var n=[];if(c.isSocket(e))n.push({socket:e});else if(Array.isArray(e)&&e.length){var r=t(e),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;Object.prototype.hasOwnProperty.call(a,`socket`)&&c.isSocket(a.socket)?n.push(a):c.isSocket(a)&&n.push({socket:a})}}catch(e){r.e(e)}finally{r.f()}}else return;return n},uri:function(e){/^sip:/i.test(e)||(e=`${a.SIP}:${e}`);var t=s.parse(e);if(t&&t.user)return t}},optional:{authorization_user:function(e){if(o.parse(`"${e}"`,`quoted_string`)!==-1)return e},authorization_jwt:function(e){if(typeof e==`string`)return e},user_agent:function(e){if(typeof e==`string`)return e},connection_recovery_max_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if(typeof e==`string`){var t=o.parse(e,`SIP_URI`);if(t!==-1)return t}},display_name:function(e){return e},instance_id:function(e){if(/^uuid:/i.test(e)&&(e=e.substr(5)),o.parse(e,`uuid`)!==-1)return e},no_answer_timeout:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if(typeof e==`boolean`)return e},session_timers_refresh_method:function(e){if(typeof e==`string`&&(e=e.toUpperCase(),e===a.INVITE||e===a.UPDATE))return e},session_timers_force_refresher:function(e){if(typeof e==`boolean`)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if(typeof e==`boolean`)return e},register_expires:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e=`${a.SIP}:${e}`);var t=s.parse(e);if(t&&!t.user)return t},use_preloaded_route:function(e){if(typeof e==`boolean`)return e},extra_headers:function(e){var n=[];if(Array.isArray(e)&&e.length){var r=t(e),i;try{for(r.s();!(i=r.n()).done;){var a=i.value;typeof a==`string`&&n.push(a)}}catch(e){r.e(e)}finally{r.f()}}else return;return n}}};e.load=function(e,t){for(var n in u.mandatory)if(t.hasOwnProperty(n)){var r=t[n],a=u.mandatory[n](r);if(a!==void 0)e[n]=a;else throw new l.ConfigurationError(n,r)}else throw new l.ConfigurationError(n);for(var o in u.optional)if(t.hasOwnProperty(o)){var s=t[o];if(i.isEmpty(s))continue;var c=u.optional[o](s);if(c!==void 0)e[o]=c;else throw new l.ConfigurationError(o,s)}}})),Yt=c(((e,t)=>{function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(e){var t=d();return function(){var n=f(e),r;if(t){var i=f(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function l(e,t){return t&&(n(t)===`object`||typeof t==`function`)?t:u(e)}function u(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function d(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}var p=J().EventEmitter,m=Y(),h=W(),g=Pt(),_=Vt(),v=Ht(),y=Ut(),b=Q(),x=Gt(),S=q(),C=G(),w=wt(),T=Kt(),E=Z(),D=qt(),O=Jt(),k=new m(`UA`),A={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};t.exports=function(e){o(n,e);var t=c(n);a(n,null,[{key:`C`,get:function(){return A}}]);function n(e){var i;if(r(this,n),k.debug(`new() [configuration:%o]`,e),i=t.call(this),i._cache={credentials:{}},i._configuration=Object.assign({},O.settings),i._dynConfiguration={},i._dialogs={},i._applicants={},i._sessions={},i._transport=null,i._contact=null,i._status=A.STATUS_INIT,i._error=null,i._transactions={nist:{},nict:{},ist:{},ict:{}},i._data={},i._closeTimer=null,e===void 0)throw TypeError(`Not enough arguments`);try{i._loadConfig(e)}catch(e){throw i._status=A.STATUS_NOT_READY,i._error=A.CONFIGURATION_ERROR,e}return i._registrator=new g(u(i)),i}return a(n,[{key:`start`,value:function(){k.debug(`start()`),this._status===A.STATUS_INIT?this._transport.connect():this._status===A.STATUS_USER_CLOSED?(k.debug(`restarting UA`),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=A.STATUS_INIT,this._transport.connect()):this._status===A.STATUS_READY?k.debug(`UA is in READY status, not restarted`):k.debug(`ERROR: connection is down, Auto-Recovery system is trying to reconnect`),this._dynConfiguration.register=this._configuration.register}},{key:`register`,value:function(){k.debug(`register()`),this._dynConfiguration.register=!0,this._registrator.register()}},{key:`unregister`,value:function(e){k.debug(`unregister()`),this._dynConfiguration.register=!1,this._registrator.unregister(e)}},{key:`registrator`,value:function(){return this._registrator}},{key:`isRegistered`,value:function(){return this._registrator.registered}},{key:`isConnected`,value:function(){return this._transport.isConnected()}},{key:`call`,value:function(e,t){k.debug(`call()`);var n=new _(this);return n.connect(e,t),n}},{key:`sendMessage`,value:function(e,t,n){k.debug(`sendMessage()`);var r=new v(this);return r.send(e,t,n),r}},{key:`sendOptions`,value:function(e,t,n){k.debug(`sendOptions()`);var r=new y(this);return r.send(e,t,n),r}},{key:`terminateSessions`,value:function(e){for(var t in k.debug(`terminateSessions()`),this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}},{key:`stop`,value:function(){var e=this;if(k.debug(`stop()`),this._dynConfiguration={},this._status===A.STATUS_USER_CLOSED){k.debug(`UA already closed`);return}this._registrator.close();var t=Object.keys(this._sessions).length;for(var n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){k.debug(`closing session ${n}`);try{this._sessions[n].terminate()}catch{}}for(var r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch{}this._status=A.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){e._closeTimer=null,e._transport.disconnect()},2e3)}},{key:`normalizeTarget`,value:function(e){return S.normalizeTarget(e,this._configuration.hostport_params)}},{key:`get`,value:function(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:k.warn(`get() | cannot get "%s" parameter in runtime`,e);return}}},{key:`set`,value:function(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 k.warn(`set() | cannot set "%s" parameter in runtime`,e),!1}return!0}},{key:`newTransaction`,value:function(e){this._transactions[e.type][e.id]=e,this.emit(`newTransaction`,{transaction:e})}},{key:`destroyTransaction`,value:function(e){delete this._transactions[e.type][e.id],this.emit(`transactionDestroyed`,{transaction:e})}},{key:`newDialog`,value:function(e){this._dialogs[e.id]=e}},{key:`destroyDialog`,value:function(e){delete this._dialogs[e.id]}},{key:`newMessage`,value:function(e,t){this._applicants[e]=e,this.emit(`newMessage`,t)}},{key:`newOptions`,value:function(e,t){this._applicants[e]=e,this.emit(`newOptions`,t)}},{key:`destroyMessage`,value:function(e){delete this._applicants[e]}},{key:`newRTCSession`,value:function(e,t){this._sessions[e.id]=e,this.emit(`newRTCSession`,t)}},{key:`destroyRTCSession`,value:function(e){delete this._sessions[e.id]}},{key:`registered`,value:function(e){this.emit(`registered`,e)}},{key:`unregistered`,value:function(e){this.emit(`unregistered`,e)}},{key:`registrationFailed`,value:function(e){this.emit(`registrationFailed`,e)}},{key:`receiveRequest`,value:function(e){var t=e.method;if(e.ruri.user!==this._configuration.uri.user&&e.ruri.user!==this._contact.uri.user){k.debug(`Request-URI does not point to us`),e.method!==h.ACK&&e.reply_sl(404);return}if(e.ruri.scheme===h.SIPS){e.reply_sl(416);return}if(!b.checkTransaction(this,e)){if(t===h.INVITE?new b.InviteServerTransaction(this,this._transport,e):t!==h.ACK&&t!==h.CANCEL&&new b.NonInviteServerTransaction(this,this._transport,e),t===h.OPTIONS){if(this.listeners(`newOptions`).length===0){e.reply(200);return}new y(this).init_incoming(e)}else if(t===h.MESSAGE){if(this.listeners(`newMessage`).length===0){e.reply(405);return}new v(this).init_incoming(e)}else if(t===h.INVITE&&!e.to_tag&&this.listeners(`newRTCSession`).length===0){e.reply(405);return}var n,r;if(e.to_tag)n=this._findDialog(e.call_id,e.from_tag,e.to_tag),n?n.receiveRequest(e):t===h.NOTIFY?(r=this._findSession(e),r?r.receiveRequest(e):(k.debug(`received NOTIFY request for a non existent subscription`),e.reply(481,`Subscription does not exist`))):t!==h.ACK&&e.reply(481);else switch(t){case h.INVITE:if(window.RTCPeerConnection){if(e.hasHeader(`replaces`)){var i=e.replaces;n=this._findDialog(i.call_id,i.from_tag,i.to_tag),n?(r=n.owner,r.isEnded()?e.reply(603):r.receiveRequest(e)):e.reply(481)}else r=new _(this),r.init_incoming(e)}else k.warn(`INVITE received but WebRTC is not supported`),e.reply(488);break;case h.BYE:e.reply(481);break;case h.CANCEL:r=this._findSession(e),r?r.receiveRequest(e):k.debug(`received CANCEL request for a non existent session`);break;case h.ACK:break;case h.NOTIFY:this.emit(`sipEvent`,{event:e.event,request:e}),e.reply(200);break;default:e.reply(405)}}}},{key:`_findSession`,value:function(e){var t=e.call_id,n=e.from_tag,r=e.to_tag,i=t+n,a=this._sessions[i],o=t+r,s=this._sessions[o];return a||s||null}},{key:`_findDialog`,value:function(e,t,n){var r=e+t+n,i=this._dialogs[r];return i||(r=e+n+t,i=this._dialogs[r],i||null)}},{key:`_loadConfig`,value:function(e){try{O.load(this._configuration,e)}catch(e){throw e}this._configuration.display_name===0&&(this._configuration.display_name=`0`),this._configuration.instance_id||(this._configuration.instance_id=S.newUUID()),this._configuration.jssip_id=S.createRandomToken(5);var t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,``);try{this._transport=new x(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=j.bind(this),this._transport.onconnect=M.bind(this),this._transport.ondisconnect=N.bind(this),this._transport.ondata=P.bind(this)}catch(e){throw k.warn(e),new C.ConfigurationError(`sockets`,this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var n=this._configuration.uri.clone();n.user=null,n.clearParams(),n.clearHeaders(),this._configuration.registrar_server=n}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new w(`sip`,S.createRandomToken(8),this._configuration.via_host,null,{transport:`ws`}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r=`<`;return r+=t?this.temp_gruu||`sip:anonymous@anonymous.invalid;transport=ws`:this.pub_gruu||this.uri.toString(),n&&(t?!this.temp_gruu:!this.pub_gruu)&&(r+=`;ob`),r+=`>`,r}};var r=[`authorization_user`,`password`,`realm`,`ha1`,`authorization_jwt`,`display_name`,`register`,`extra_headers`];for(var i in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,i)&&(r.indexOf(i)===-1?Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}));for(var a in k.debug(`configuration parameters after validation:`),this._configuration)if(Object.prototype.hasOwnProperty.call(O.settings,a))switch(a){case`uri`:case`registrar_server`:k.debug(`- ${a}: ${this._configuration[a]}`);break;case`password`:case`ha1`:case`authorization_jwt`:k.debug(`- ${a}: NOT SHOWN`);break;default:k.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}},{key:`C`,get:function(){return A}},{key:`status`,get:function(){return this._status}},{key:`contact`,get:function(){return this._contact}},{key:`configuration`,get:function(){return this._configuration}},{key:`transport`,get:function(){return this._transport}}]),n}(p);function j(e){this.emit(`connecting`,e)}function M(e){this._status!==A.STATUS_USER_CLOSED&&(this._status=A.STATUS_READY,this._error=null,this.emit(`connected`,e),this._dynConfiguration.register&&this._registrator.register())}function N(e){for(var t=[`nict`,`ict`,`nist`,`ist`],n=0,r=t;n<r.length;n++){var i=r[n];for(var a in this._transactions[i])Object.prototype.hasOwnProperty.call(this._transactions[i],a)&&this._transactions[i][a].onTransportError()}this.emit(`disconnected`,e),this._registrator.onTransportClosed(),this._status!==A.STATUS_USER_CLOSED&&(this._status=A.STATUS_NOT_READY,this._error=A.NETWORK_ERROR)}function P(e){var t=e.transport,n=e.message;if(n=T.parseMessage(n,this),n&&!(this._status===A.STATUS_USER_CLOSED&&n instanceof E.IncomingRequest)&&D(n,this,t)){if(n instanceof E.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof E.IncomingResponse){var r;switch(n.method){case h.INVITE:r=this._transactions.ict[n.via_branch],r&&r.receiveResponse(n);break;case h.ACK:break;default:r=this._transactions.nict[n.via_branch],r&&r.receiveResponse(n)}}}}})),Xt=c(((e,t)=>{function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var a=Y(),o=K(),s=new a(`WebSocketInterface`);t.exports=function(){function e(t){n(this,e),s.debug(`new() [url:"%s"]`,t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var r=o.parse(t,`absoluteURI`);if(r===-1)throw s.warn(`invalid WebSocket URI: ${t}`),TypeError(`Invalid argument: ${t}`);if(r.scheme!==`wss`&&r.scheme!==`ws`)throw s.warn(`invalid WebSocket URI scheme: ${r.scheme}`),TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${r.host}${r.port?`:${r.port}`:``};transport=ws`,this._via_transport=r.scheme.toUpperCase()}return i(e,[{key:`connect`,value:function(){if(s.debug(`connect()`),this.isConnected()){s.debug(`WebSocket ${this._url} is already connected`);return}if(this.isConnecting()){s.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),s.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)}}},{key:`disconnect`,value:function(){s.debug(`disconnect()`),this._ws&&=(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),null)}},{key:`send`,value:function(e){return s.debug(`send()`),this.isConnected()?(this._ws.send(e),!0):(s.warn(`unable to send message, WebSocket is not open`),!1)}},{key:`isConnected`,value:function(){return this._ws&&this._ws.readyState===this._ws.OPEN}},{key:`isConnecting`,value:function(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}},{key:`_onOpen`,value:function(){s.debug(`WebSocket ${this._url} connected`),this.onconnect()}},{key:`_onClose`,value:function(e){var t=e.wasClean,n=e.code,r=e.reason;s.debug(`WebSocket ${this._url} closed`),t===!1&&s.debug(`WebSocket abrupt disconnection`),this.ondisconnect(!t,n,r)}},{key:`_onMessage`,value:function(e){var t=e.data;s.debug(`received WebSocket message`),this.ondata(t)}},{key:`_onError`,value:function(e){s.warn(`WebSocket ${this._url} error: `,e)}},{key:`via_transport`,get:function(){return this._via_transport},set:function(e){this._via_transport=e.toUpperCase()}},{key:`sip_uri`,get:function(){return this._sip_uri}},{key:`url`,get:function(){return this._url}}]),e}()})),Zt=c(((e,t)=>{var n=(St(),f(ot).default),r=W(),i=G(),a=q(),o=Yt(),s=wt(),c=Ct(),l=K(),u=Xt();Dt()(`JsSIP`)(`version %s`,n.version),t.exports={C:r,Exceptions:i,Utils:a,UA:o,URI:s,NameAddrHeader:c,WebSocketInterface:u,Grammar:l,debug:Dt(),get name(){return n.title},get version(){return n.version}}})),Qt=l({createJsSipFactory:()=>$t});function $t(){return{createSocket:(e,t)=>new tn(e,t),createUa:e=>new en.UA(e)}}var en,tn,nn=s((()=>{en=d(Zt(),1),tn=class extends en.WebSocketInterface{ticket;constructor(e,t){super(e),this.ticket=t}protocols(){return this.ticket===``?[`sip`]:[`xcall-ticket.${this.ticket}`,`sip`]}connect(){if(this.isConnected()||this.isConnecting())return;let e=this;e._ws&&this.disconnect();try{e._ws=new WebSocket(this.url,this.protocols()),e._ws.binaryType=`arraybuffer`,e._ws.onopen=e._onOpen.bind(this),e._ws.onclose=e._onClose.bind(this),e._ws.onmessage=e._onMessage.bind(this),e._ws.onerror=e._onError.bind(this)}catch(t){e._onError.call(this,t)}}}}));function rn(e){let t=new Map;return{peerConnection:{getSenders:()=>e.getSenders().map(n=>{let r=t.get(n);if(r!==void 0)return r;let i={get track(){return n.track},get senderKind(){let t=n.track;if(t!==null)return t.kind===`audio`||t.kind===`video`?t.kind:void 0;let r=e.getTransceivers().find(e=>e.sender===n)?.receiver.track;if(r?.kind===`audio`||r?.kind===`video`)return r.kind;let i=n.getParameters().codecs?.find(e=>typeof e.mimeType==`string`);if(i?.mimeType?.toLowerCase().startsWith(`video/`))return`video`;if(i?.mimeType?.toLowerCase().startsWith(`audio/`))return`audio`},replaceTrack:e=>n.replaceTrack(e)};return t.set(n,i),i}),close:()=>{e.connectionState!==`closed`&&e.close()}},trackSource:{onTrack(t){let n=e=>{let n=e.track;t({streams:[...e.streams],track:n})};return e.addEventListener(`track`,n),()=>e.removeEventListener(`track`,n)}}}}var an=s((()=>{})),on=l({JsSipAdapter:()=>vn});function sn(e){let t=Math.floor(Number(e.sip.registerExpires));return Number.isFinite(t)&&t>0?t:pn}function cn(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.originator===`remote`&&ln(t.session)}function ln(e){return typeof e==`object`&&!!e&&`id`in e}function un(e){return typeof e==`object`&&e&&(e.via_transport=`WSS`),e}function dn(e){let t=e.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`0:0:0:0:0:0:0:1`}function fn(e){let t=e?.uri;if(t==null)return;if(typeof t.user==`string`&&t.user!==``)return t.user;let n=t.toString();return n.match(/^sips?:([^@;>]+)/i)?.[1]??(n===``?void 0:n)}var pn,mn,hn,gn,_n,vn,yn,bn=s((()=>{m(),an(),pn=300,mn=25,hn=2,gn=``,_n=120,vn=class{factory;transportBaseUrl;keepaliveSeconds;agentTerminal;sessionTimers;ua;uaListeners;incomingHandlers;iceServers;pendingConnection;disposed=!1;warmPc;keepaliveTimer;keepaliveBusy=!1;registerExpiresSeconds=0;connectionHandlers=new Set;constructor(e,t,n=mn,r=gn,i=!1){this.factory=e,this.transportBaseUrl=t,this.keepaliveSeconds=n,this.agentTerminal=r,this.sessionTimers=i}terminalHeaders(){return this.agentTerminal===``?[]:[`X-Agent-Terminal: ${this.agentTerminal}`]}warmIceCandidatePool(){if(this.closeWarmPc(),typeof RTCPeerConnection<`u`&&this.iceServers!==void 0)try{this.warmPc=new RTCPeerConnection({iceServers:[...this.iceServers],iceCandidatePoolSize:hn})}catch{this.warmPc=void 0}}closeWarmPc(){try{this.warmPc?.close()}catch{}this.warmPc=void 0}keepaliveTick(e){if(this.isCurrentUa(e)&&!this.keepaliveBusy)try{if(typeof e.isConnected==`function`&&e.isConnected()===!1||typeof e.register!=`function`)return;this.keepaliveBusy=!0,e.register({extraHeaders:this.terminalHeaders()})}catch{}finally{this.keepaliveBusy=!1}}startKeepalive(e,t){if(this.stopKeepalive(),!Number.isFinite(this.keepaliveSeconds)||this.keepaliveSeconds<=0||t>0&&t<=this.keepaliveSeconds)return;let n=Math.max(10,Math.floor(this.keepaliveSeconds))*1e3;this.keepaliveTimer=setInterval(()=>this.keepaliveTick(e),n)}stopKeepalive(){this.keepaliveTimer!==void 0&&clearInterval(this.keepaliveTimer),this.keepaliveTimer=void 0}connect(e){this.assertNotDisposed(),this.disconnect(this.registrationError(`SIP connection replaced`));try{let t=this.factory.createUa({sockets:un(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(e.transport.wssUrl)),e.transport.ticket)),uri:e.sip.uri,password:e.sip.registerTicket,registrar_server:e.sip.registrar,register:!0,register_expires:sn(e),session_timers:this.sessionTimers,...this.agentTerminal===``?{}:{user_agent:this.agentTerminal}});return this.ua=t,this.registerExpiresSeconds=sn(e),this.iceServers=e.iceServers,this.uaListeners=[],this.startRegistration(t)}catch(e){let t=e instanceof p&&e.code===`CONFIG_INVALID`?e:this.transportError(e);return this.disconnect(t),Promise.reject(t)}}disconnect(e=this.registrationError(`SIP connection disconnected`)){this.stopKeepalive(),this.closeWarmPc();let t=this.pendingConnection;this.pendingConnection=void 0,this.ua!==void 0&&(this.removeUaListeners(this.ua),this.ua.stop()),this.ua=void 0,this.uaListeners=void 0,this.iceServers=void 0,t?.reject(e)}dial(e,t){let n=this.requireUa();if(e.trim()===``)throw new p(`CALL_INVALID_DESTINATION`,`call`,!1);try{let r=t===void 0?{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:_n,pcConfig:{iceServers:this.iceServers,iceCandidatePoolSize:hn}}:{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:_n,pcConfig:{iceServers:[...t.iceServers],iceCandidatePoolSize:hn},extraHeaders:[...this.terminalHeaders(),...t.extraHeaders,...t.type===`extension`?[`X-XCall-Destination-Type: extension`]:[]]};return new yn(n.call(e,r))}catch(e){throw new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:e})}}onIncoming(e){this.assertNotDisposed();let t=this.incomingHandlers??new Set;return this.incomingHandlers=t,t.add(e),()=>t.delete(e)}onConnectionStateChanged(e){return this.disposed?()=>void 0:(this.connectionHandlers.add(e),()=>this.connectionHandlers.delete(e))}dispose(){this.disposed||(this.disposed=!0,this.disconnect(),this.incomingHandlers=void 0,this.connectionHandlers.clear())}getResourceCounts(){return{listeners:(this.uaListeners?.length??0)+(this.incomingHandlers?.size??0)+this.connectionHandlers.size,webSockets:this.ua===void 0?0:1}}handleIncoming(e){if(!cn(e))return;let t=e.session;if(t===void 0)return;let n=new yn(t);this.incomingHandlers?.forEach(e=>e(n))}startRegistration(e){let t=!0,n=!1,r=new Promise((t,n)=>{this.pendingConnection={ua:e,resolve:t,reject:n}});this.listen(e,`registered`,()=>{if(this.isCurrentUa(e)){if(t){n=!0;return}this.resolveConnection(e)}}),this.listen(e,`registrationFailed`,t=>{if(!this.isCurrentUa(e))return;let n=this.registrationError(this.registrationFailureCause(t));this.connectionHandlers.forEach(e=>e(`failed`,n)),this.disconnect(n)}),this.listen(e,`disconnected`,t=>{if(!this.isCurrentUa(e))return;let n=this.transportError(t);this.connectionHandlers.forEach(e=>e(`disconnected`,n)),this.disconnect(n)}),this.listen(e,`newRTCSession`,t=>{this.isCurrentUa(e)&&this.handleIncoming(t)});try{e.start()}catch(e){let t=this.transportError(e);this.connectionHandlers.forEach(e=>e(`failed`,t)),this.disconnect(t)}finally{t=!1}return n&&this.resolveConnection(e),r}listen(e,t,n){e.on(t,n),this.uaListeners?.push({event:t,handler:n})}removeUaListeners(e){this.uaListeners?.forEach(({event:t,handler:n})=>e.off(t,n))}isCurrentUa(e){return this.ua===e}resolveConnection(e){let t=this.pendingConnection;t?.ua===e&&(this.pendingConnection=void 0,t.resolve(),this.warmIceCandidatePool(),this.startKeepalive(e,this.registerExpiresSeconds),this.connectionHandlers.forEach(e=>e(`registered`)))}resolveWssUrl(e){let t=this.transportBaseUrl?.trim()===``||this.transportBaseUrl===void 0?typeof location>`u`?`http://localhost`:location.origin:this.transportBaseUrl,n=e.startsWith(`/`)?new URL(e,t):new URL(e);return n.protocol===`http:`&&(n.protocol=`ws:`),n.protocol===`https:`&&(n.protocol=`wss:`),this.assertAllowedWssUrl(n),n.toString()}assertAllowedWssUrl(e){if(e.protocol!==`wss:`&&!(e.protocol===`ws:`&&dn(e.hostname)))throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:e.origin})}withoutTicket(e){let t=new URL(e);return t.searchParams.delete(`ticket`),t.toString()}requireUa(){if(this.assertNotDisposed(),this.ua===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return this.ua}assertNotDisposed(){if(this.disposed)throw new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}registrationError(e){return new p(`REGISTRATION_FAILED`,`registration`,!0,{cause:e})}transportError(e){return new p(`SIP_WS_UNAVAILABLE`,`registration`,!0,{cause:e})}registrationFailureCause(e){return typeof e==`object`&&e&&`cause`in e?e.cause:e}},yn=class{session;pendingHoldReject;mediaRegistration;mediaConnection;mediaHandlers=new Set;mediaWatchStarted=!1;sessionUnsubscribeFromPeerConnection;constructor(e){this.session=e}get id(){return this.session.id}get from(){return this.session.from??fn(this.session.remote_identity)}getMediaRegistration(){let e=this.session.connection;if(e!=null)return this.mediaRegistration!==void 0&&this.mediaConnection===e?this.mediaRegistration:(this.mediaConnection=e,this.mediaRegistration=rn(e),this.mediaRegistration)}answer(e){this.session.answer({mediaConstraints:e.mediaConstraints,pcConfig:{iceServers:[...e.pcConfig.iceServers]}})}terminate(){this.pendingHoldReject?.(Error(`SIP session terminated`)),this.session.terminate()}hold(){return this.changeHoldState(`hold`)}unhold(){return this.changeHoldState(`unhold`)}mute(){this.session.mute()}unmute(){this.session.unmute()}sendDtmf(e){this.session.sendDTMF(e)}refer(e){this.session.refer(e)}on(e,t){return e===`mediaConnected`?(this.mediaHandlers.add(t),this.watchMediaConnection(),()=>{this.mediaHandlers.delete(t),this.mediaHandlers.size===0&&(this.sessionUnsubscribeFromPeerConnection?.(),this.sessionUnsubscribeFromPeerConnection=void 0)}):(this.session.on(e,t),()=>this.session.off(e,t))}watchMediaConnection(){if(this.mediaWatchStarted)return;this.mediaWatchStarted=!0;let e=!1,t=t=>{if(t==null)return;let n=()=>{if(e)return;let n=t.connectionState||t.iceConnectionState;if(n===`connected`){e=!0;for(let e of this.mediaHandlers)try{e({state:n})}catch{}}};t.addEventListener(`connectionstatechange`,n),n()},n=this.session.connection;if(n!=null){t(n);return}let r=e=>{t(e?.peerconnection??void 0)};this.session.on(`peerconnection`,r),this.sessionUnsubscribeFromPeerConnection=()=>this.session.off(`peerconnection`,r)}changeHoldState(e){return new Promise((t,n)=>{let r=!1,i=e=>{s(e)},a=()=>{try{this.session.off(`ended`,i)}catch{}try{this.session.off(`failed`,i)}catch{}this.pendingHoldReject===s&&(this.pendingHoldReject=void 0)},o=()=>{r||(r=!0,a(),t())},s=e=>{r||(r=!0,a(),n(new p(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:e})))};try{this.session.on(`ended`,i),this.session.on(`failed`,i)}catch(e){s(e);return}this.pendingHoldReject=s;try{this.session[e](void 0,o)||s()}catch(e){s(e)}})}}}));m();var xn=class e{media;options;api;suppliedSip;sip;events=new h;mediaBridge;reconnect;diagnostics;callManager;session;state=`idle`;initialized=!1;disposed=!1;intentionalDisconnect=!1;deferredRebuild=!1;sessionRecoveryPending=!1;detectedPlatform;support;acceptingEvents=!0;connectOperation;disconnectOperation;refreshOperation;disposeOperation;refreshTimer;lifecycleGeneration=0;managerUnsubscribers=[];sipUnsubscribe;networkUnsubscribers=[];sessionDeleteOperations=new Map;deletedSessions=new Set;ownedSessionIds=new Set;terminalReleaseOperations=new Map;sharedWorkerSelection;constructor(e){if(this.options=e,e.api===void 0&&e.sessionProvider===void 0)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:`CCBarClient 需要 sessionProvider`});this.api=e.api===void 0?wn(Tn(e.sessionProvider)):wn(e.api),this.suppliedSip=e.sip===void 0?void 0:En(e.sip),this.mediaBridge=Ue(()=>this.getActiveMediaContext()),this.media=this.mediaBridge.publicMedia,this.reconnect=new Ye({recover:()=>this.recoverConnection(),onAttempt:e=>{this.disposed||this.events.emit(`connection.reconnecting`,{attempt:e})}}),this.diagnostics=new $e({getSnapshot:()=>this.createDiagnosticsSnapshot(),getPermission:()=>this.readMicrophonePermission(),getDeviceNames:async()=>(await this.media.getDevices()).map(e=>e.label).filter(e=>e!==``)}),this.sharedWorkerSelection=e.sharedWorker===void 0?{mode:`single-tab`,reason:`disabled`}:ge({...e.sharedWorker,...e.sharedWorkerHost??{}})}static async checkSupport(){let e=typeof navigator<`u`&&navigator.mediaDevices!==void 0,t=typeof WebSocket<`u`,n=Cn(typeof navigator<`u`?navigator.userAgent:``);return{supported:e&&t,platform:n,hasMediaDevices:e,hasWebSocket:t,...e&&t?{}:{reason:`当前运行环境缺少 WebPhone 所需的浏览器能力`}}}async initialize(){if(this.assertNotDisposed(),this.initialized)return;let t=await e.checkSupport();this.support=t,this.options.platform===void 0&&(t.platform===`web`||t.platform===`mobile-web`)&&(this.detectedPlatform=t.platform),await this.awaitSharedWorkerReady(),this.assertNotDisposed(),this.initialized=!0}connect(){if(this.assertNotDisposed(),this.api.invalidateToken?.(),this.connectOperation!==void 0)return this.connectOperation;if(this.state===`connected`)return Promise.resolve();let e=this.lifecycleGeneration,t=this.performConnect(e).finally(()=>{this.connectOperation===t&&(this.connectOperation=void 0)});return this.connectOperation=t,t}disconnect(){if(this.assertNotDisposed(),this.disconnectOperation!==void 0)return this.disconnectOperation;if(this.state===`idle`&&this.connectOperation===void 0||this.state===`disconnected`&&this.connectOperation===void 0)return Promise.resolve();this.lifecycleGeneration+=1,this.acceptingEvents=!1;let e=this.performDisconnect().finally(()=>{this.disconnectOperation===e&&(this.disconnectOperation=void 0)});return this.disconnectOperation=e,e}dispose(){if(this.disposeOperation!==void 0)return this.disposeOperation;this.disposed=!0,this.lifecycleGeneration+=1,this.intentionalDisconnect=!0,this.acceptingEvents=!1,this.reconnect.dispose(),this.clearRefreshTimer(),this.detachNetworkListeners(),this.releaseSharedWorker(),this.state=`disconnected`,this.diagnostics.log(`info`,`connection.stateChanged`,{state:`disconnected`}),this.detachSipListener(),this.detachManagerListeners();let e=!1,t=this.performDispose().then(()=>{e=!0}).finally(()=>{this.disposeOperation===t&&!e&&(this.disposeOperation=void 0)});return this.disposeOperation=t,t}recover(){return this.assertNotDisposed(),this.recoverConnection()}dial(e){this.assertConnected();let t=this.callManager,n=this.session;if(t===void 0||n===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return t.dial(e,n)}answer(e,t){this.assertConnected();let n=this.callManager,r=this.session;if(n===void 0||r===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return n.answer(e,r,t)}setActiveCall(e){this.assertConnected();let t=this.callManager;if(t===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1);return t.setActiveCall(e)}getCalls(){return this.callManager?.getCalls()??[]}getActiveCall(){return this.callManager?.getActiveCall()}getAgent(){return this.session?.agent}getSharedWorkerState(){let e=this.sharedWorkerSelection;return e.mode===`shared`?{mode:`shared`,tabId:e.tabId}:{mode:`single-tab`,reason:e.reason}}getDiagnostics(e={}){return this.diagnostics.getReport(e)}async setAgentStatus(e){this.assertNotDisposed();let t=this.session?.transport.wssUrl;await this.api.setAgentStatus({status:e,reason:``},t===void 0?void 0:{wssUrl:t}),this.disposed||this.events.emit(`agent.statusChanged`,{status:e})}on(e,t){return this.disposed?()=>void 0:this.events.on(e,t)}off(e,t){this.events.off(e,t)}async performConnect(e){let t,n,r;try{await this.initialize(),this.assertGeneration(e);let i=this.resolvePlatform();this.intentionalDisconnect=!1,this.acceptingEvents=!0,this.setConnectionState(`connecting`),t=await this.api.createSession({sdkVersion:F,platform:i===`mobile-web`?`mobile_web`:`web`,...this.options.locale===void 0?{}:{locale:this.options.locale},requestedCapabilities:[...this.options.requestedCapabilities??Nn(i)]}),this.ownedSessionIds.add(t.sessionId),this.assertGeneration(e),n=await this.getSip(),this.assertGeneration(e),this.session=t;let a=this.callManager??this.createCallManager(n,t,i);this.callManager===void 0&&(r=a),a.updateSession(t),this.callManager=a,this.attachSipListener(n),this.attachNetworkListeners(),await n.connect(t),this.assertGeneration(e),this.setConnectionState(`connected`),this.events.emit(`connection.registered`,{registered:!0}),this.scheduleRefresh(t)}catch(i){if(await this.rollbackConnect(t,n,r),this.disposed)throw this.disposedError();if(e!==this.lifecycleGeneration)throw i;let a=Dn(i,`REGISTRATION_FAILED`,`registration`,!0);throw this.setConnectionState(`failed`),this.events.emit(`connection.failed`,{error:a}),a}}async performDisconnect(){let e,t=this.connectOperation;if(t!==void 0)try{await t}catch(t){An(t)||(e??=t)}let n=this.refreshOperation;if(n!==void 0)try{await n}catch(t){An(t)||(e??=t)}this.reconnect.cancel(),this.clearRefreshTimer(),this.intentionalDisconnect=!0,this.detachNetworkListeners(),this.detachSipListener(),this.detachManagerListeners();let r=this.callManager,i=this.sip;this.callManager=void 0;try{await r?.dispose({terminateCalls:!0})}catch(t){e??=t}try{await this.awaitMediaReleaseBarriers()}catch(t){e??=t}try{i!==void 0&&await i.disconnect()}catch(t){e??=t}this.session=void 0;try{await this.deleteOwnedSessions()}catch(t){e??=t}if(this.pruneDeletedSessionTombstones(),this.disposed||(this.acceptingEvents=!0,this.setConnectionState(`disconnected`)),e!==void 0)throw e}createCallManager(e,t,n){let r=new N({sip:e,platform:n,session:t,maxConcurrentCalls:this.options.maxConcurrentCalls,autoHoldPreviousCall:this.options.autoHoldPreviousCall,onCallCreated:(e,t)=>this.handleCallCreated(e,t),onCallStateChanged:(e,t)=>this.handleCallStateChanged(e,t),onCallTerminal:e=>this.handleCallTerminal(e)});return this.bindManagerEvents(r),r}async rollbackConnect(e,t,n){if(n!==void 0){this.detachManagerListeners(),this.callManager===n&&(this.callManager=void 0);try{await n.dispose({terminateCalls:!0})}catch{}}if(t!==void 0){this.detachSipListener();try{await t.disconnect()}catch{}}if(this.session===e&&(this.session=void 0),e!==void 0)try{await this.deleteSession(e.sessionId)}catch{}}async performDispose(){let e,t=[this.connectOperation,this.disconnectOperation,this.refreshOperation].filter(e=>e!==void 0);for(let n of t)try{await n}catch(t){An(t)||(e??=t)}let n=this.callManager;this.callManager=void 0;try{await n?.dispose({terminateCalls:!0})}catch(t){e??=t}try{await this.awaitMediaReleaseBarriers()}catch(t){e??=t}try{await this.media.releaseAll()}catch(t){kn(t)||(e??=t)}try{await this.mediaBridge.dispose()}catch(t){e??=t}try{await this.sip?.dispose()}catch(t){e??=t}try{await this.deleteOwnedSessions()}catch(t){e??=t}if(this.pruneDeletedSessionTombstones(),this.session=void 0,this.sipUnsubscribe=void 0,this.events.clear(),e!==void 0)throw e}async awaitMediaReleaseBarriers(){let e;for(let[t,n]of[...this.terminalReleaseOperations])try{await n,this.terminalReleaseOperations.delete(t)}catch(n){try{await this.mediaBridge.releaseCall(t),this.terminalReleaseOperations.delete(t)}catch(t){e??=t??n}}if(e!==void 0)throw e}detachSipListener(){let e=this.sipUnsubscribe;this.sipUnsubscribe=void 0;try{e?.()}catch{}}detachManagerListeners(){this.managerUnsubscribers.splice(0).forEach(e=>{try{e()}catch{}})}bindManagerEvents(e){[`call.created`,`call.incoming`,`call.stateChanged`,`call.activeChanged`,`call.ended`,`call.failed`,`error`].forEach(t=>{let n=e.on(t,e=>{this.acceptingEvents&&!this.disposed&&(this.diagnostics.log(t===`error`||t===`call.failed`?`error`:`info`,String(t),e),this.events.emit(t,e))});this.managerUnsubscribers.push(n)})}handleCallCreated(e,t){this.acceptingEvents&&!this.disposed&&this.mediaBridge.registerCall(e,t)}handleCallStateChanged(e,t){this.acceptingEvents&&!this.disposed&&this.mediaBridge.registerCall(e,t)}handleCallTerminal(e){let t=this.startTerminalRelease(e);return this.deferredRebuild&&!this.hasNonTerminalCalls()&&this.startDeferredRecovery(),t}startTerminalRelease(e){let t=this.terminalReleaseOperations.get(e);if(t!==void 0)return t;let n=this.mediaBridge.releaseCall(e).then(()=>{this.terminalReleaseOperations.get(e)===n&&this.terminalReleaseOperations.delete(e)}).catch(t=>{throw this.acceptingEvents&&!this.disposed&&this.events.emit(`error`,{error:Dn(t,`SDK_INTERNAL_ERROR`,`internal`,!0,e)}),t});return this.terminalReleaseOperations.set(e,n),n}async startDeferredRecovery(){try{if(await this.awaitMediaReleaseBarriers(),this.deferredRebuild&&!this.hasNonTerminalCalls()&&!this.disposed){if(this.sessionRecoveryPending){this.recoverInvalidSession();return}this.deferredRebuild=!1,this.clearRefreshTimer(),this.reconnect.start()}}catch{!this.disposed&&!this.sessionRecoveryPending&&this.reconnect.start()}}async refreshAndRebuild(){if(this.refreshOperation!==void 0)return this.refreshOperation;let e=this.performRefreshAndRebuild().finally(()=>{this.refreshOperation===e&&(this.refreshOperation=void 0),this.sessionRecoveryPending&&!this.hasNonTerminalCalls()&&!this.disposed&&this.recoverInvalidSession()});return this.refreshOperation=e,e}async performRefreshAndRebuild(){if(this.disposed||this.session===void 0)return;let e=this.lifecycleGeneration,t=this.session;try{let n=await this.api.refreshSession(t.sessionId);if(!this.isCurrentGeneration(e)||this.session!==t)return;if(this.session=n,this.callManager?.updateSession(n),this.events.emit(`token.refreshed`,{expiresAt:n.expiresAt}),this.hasNonTerminalCalls()){this.deferredRebuild=!0,this.scheduleRefresh(n);return}let r=await this.getSip();if(!this.isCurrentGeneration(e))return;await r.connect(n),this.isCurrentGeneration(e)&&(this.deferredRebuild=!1,this.setConnectionState(`connected`),this.scheduleRefresh(n))}catch(n){if(!this.isCurrentGeneration(e))return;throw this.handleRefreshFailure(t,n),n}}handleRefreshFailure(e,t){if(this.disposed)return;let n=Dn(t,`NETWORK_OFFLINE`,`network`,!0);if(this.events.emit(`token.expiring`,{expiresAt:e.expiresAt}),this.events.emit(`error`,{error:n}),On(t)){this.clearRefreshTimer(),this.reconnect.cancel(),this.deletedSessions.add(e.sessionId),this.sessionRecoveryPending=!0,this.deferredRebuild=!0,(n.code===`AUTH_TOKEN_UNAVAILABLE`||n.code===`AUTH_TOKEN_EXPIRED`)&&this.api.invalidateToken?.();return}this.deferredRebuild=!0,this.hasNonTerminalCalls()||this.reconnect.start()}async recoverInvalidSession(){if(!(!this.sessionRecoveryPending||this.disposed||this.hasNonTerminalCalls())){this.sessionRecoveryPending=!1,this.deferredRebuild=!1;try{await this.performDisconnect()}catch(e){this.disposed||this.events.emit(`error`,{error:Dn(e,`SDK_INTERNAL_ERROR`,`internal`,!0)});return}if(!this.disposed)try{await this.performConnect(this.lifecycleGeneration)}catch{this.reconnect.cancel()}}}scheduleRefresh(e){this.clearRefreshTimer();let t=e.expiresAt*1e3-Date.now()-6e4,n=Math.max(1e3,t);this.refreshTimer=setTimeout(()=>{this.refreshTimer=void 0,this.refreshAndRebuild().catch(()=>void 0)},n)}async recoverConnection(){this.disposed||this.intentionalDisconnect||this.hasNonTerminalCalls()||(await this.awaitMediaReleaseBarriers(),await this.refreshAndRebuild())}async getSip(){if(this.sip!==void 0)return this.sip;if(this.suppliedSip!==void 0)return this.sip=this.suppliedSip,this.sip;let[e,t]=await Promise.all([Promise.resolve().then(()=>(nn(),Qt)),Promise.resolve().then(()=>(bn(),on))]);return this.sip=new t.JsSipAdapter(e.createJsSipFactory(),this.options.baseUrl,this.options.sipKeepaliveSeconds,this.options.agentTerminal,this.options.sipSessionTimers??!1),this.sip}attachSipListener(e){this.sipUnsubscribe===void 0&&e.onConnectionStateChanged!==void 0&&(this.sipUnsubscribe=e.onConnectionStateChanged((e,t)=>{if(!(this.disposed||this.intentionalDisconnect||!this.acceptingEvents)){if(e===`registered`){this.setConnectionState(`connected`);return}this.state===`connected`&&(this.setConnectionState(`reconnecting`),this.reconnect.start(),t!==void 0&&this.events.emit(`error`,{error:Dn(t,`SIP_WS_UNAVAILABLE`,`registration`,!0)}))}}))}attachNetworkListeners(){if(this.networkUnsubscribers.length>0||typeof window>`u`)return;let e=window,t=()=>this.reconnect.notifyOnline(),n=()=>this.reconnect.notifyOffline();e.addEventListener(`online`,t),e.addEventListener(`offline`,n),this.networkUnsubscribers=[()=>e.removeEventListener(`online`,t),()=>e.removeEventListener(`offline`,n)]}detachNetworkListeners(){this.networkUnsubscribers.splice(0).forEach(e=>e())}getActiveMediaContext(){let e=this.callManager?.getActiveCall();return e===void 0?void 0:this.mediaBridge.contextFor(e.id,e.state,new Set(this.session?.capabilities??[]))}hasNonTerminalCalls(){return this.callManager?.hasNonTerminalCalls()??!1}clearRefreshTimer(){this.refreshTimer!==void 0&&(clearTimeout(this.refreshTimer),this.refreshTimer=void 0)}createDiagnosticsSnapshot(){let e=this.session;return{connectionState:this.state,calls:this.getCalls().map(e=>({callId:e.id,state:e.state,destination:e.destination})),permission:this.support?.hasMediaDevices===!1?`unsupported`:`unknown`,ice:Sn(e),wss:{configured:e!==void 0,secure:e?.transport.wssUrl.toLowerCase().startsWith(`wss://`)??!1,state:this.state},resources:this.getDiagnosticsResourceCounts()}}getDiagnosticsResourceCounts(){let e=this.mediaBridge.getResourceCounts(),t=this.callManager?.getResourceCounts()??{timers:0,listeners:0},n=this.sip?.getResourceCounts?.(),r=(this.callManager===void 0?0:1)+(this.sipUnsubscribe===void 0?0:1),i=this.session!==void 0&&this.state!==`idle`&&this.state!==`disconnected`;return{timers:(this.refreshTimer===void 0?0:1)+this.reconnect.getTimerCount()+t.timers,listeners:this.events.listenerCount()+t.listeners+e.listeners+this.networkUnsubscribers.length+(n?.listeners??r),tracks:e.tracks,peerConnections:e.peerConnections,audioElements:e.audioElements,webSockets:n?.webSockets??+!!i,deletedSessions:this.deletedSessions.size}}async readMicrophonePermission(){if(typeof navigator>`u`||navigator.mediaDevices===void 0)return`unsupported`;if(navigator.permissions===void 0)return`unknown`;try{return(await navigator.permissions.query({name:`microphone`})).state}catch{return`unknown`}}deleteSession(e){if(this.deletedSessions.has(e))return Promise.resolve();let t=this.sessionDeleteOperations.get(e);if(t!==void 0)return t;let n=this.api.deleteSession(e).then(()=>{this.deletedSessions.add(e)}).catch(t=>{if(On(t)){this.deletedSessions.add(e);return}throw t}).finally(()=>{this.sessionDeleteOperations.get(e)===n&&this.sessionDeleteOperations.delete(e)});return this.sessionDeleteOperations.set(e,n),n}pruneDeletedSessionTombstones(){for(let e of[...this.deletedSessions])!this.ownedSessionIds.has(e)&&!this.sessionDeleteOperations.has(e)&&this.deletedSessions.delete(e)}async deleteOwnedSessions(){let e;for(let t of[...this.ownedSessionIds])try{await this.deleteSession(t),this.ownedSessionIds.delete(t)}catch(t){e??=t}if(e!==void 0)throw e}resolvePlatform(){let e=this.options.platform??this.detectedPlatform;if(e===void 0)throw new p(`CONFIG_INVALID`,`configuration`,!1,{cause:this.support?.platform??`unknown`});return e}setConnectionState(e){this.state===e||this.disposed||(this.state=e,this.diagnostics.log(`info`,`connection.stateChanged`,{state:e}),this.events.emit(`connection.stateChanged`,{state:e===`disconnected`||e===`idle`?`offline`:e}))}assertConnected(){if(this.assertNotDisposed(),this.state!==`connected`||this.callManager===void 0||this.session===void 0)throw new p(`CALL_NOT_CONNECTED`,`call`,!1)}assertGeneration(e){if(this.disposed)throw this.disposedError();if(e!==this.lifecycleGeneration)throw new p(`CALL_NOT_CONNECTED`,`call`,!1)}isCurrentGeneration(e){return!this.disposed&&e===this.lifecycleGeneration}async awaitSharedWorkerReady(){let e=this.sharedWorkerSelection;if(e.mode===`shared`)try{await e.ready}catch(e){if(this.disposed)return;if(this.options.sharedWorker?.fallback===`error`)throw e;this.sharedWorkerSelection={mode:`single-tab`,reason:e instanceof Error?e.message:`SharedWorker attach failed`}}}releaseSharedWorker(){let e=this.sharedWorkerSelection;if(this.sharedWorkerSelection={mode:`single-tab`,reason:`disposed`},e.mode===`shared`){try{e.client.request({version:1,type:`detach`,requestId:`detach-${e.tabId}`,tabId:e.tabId}).catch(()=>void 0)}catch{}e.client.close()}}assertNotDisposed(){if(this.disposed)throw this.disposedError()}disposedError(){return new p(`SDK_ALREADY_DISPOSED`,`internal`,!1)}};function Sn(e){if(e===void 0)return{configured:!1,serverCount:0,stunServerCount:0,turnServerCount:0};let t=0,n=0;return e.iceServers.forEach(e=>{let r=e.urls.map(e=>e.toLowerCase());r.some(e=>e.startsWith(`stun:`))&&(t+=1),r.some(e=>e.startsWith(`turn:`)||e.startsWith(`turns:`))&&(n+=1)}),{configured:e.iceServers.length>0,serverCount:e.iceServers.length,stunServerCount:t,turnServerCount:n}}function Cn(e){return e===``?`unknown`:/iPhone|iPad|Android/i.test(e)?`mobile-web`:`web`}function wn(e){if(typeof e!=`object`||!e)throw new p(`CONFIG_INVALID`,`configuration`,!1);return e}function Tn(e){let t={createSession:t=>e.createSession(t),refreshSession:t=>e.refreshSession===void 0?e.createSession({sdkVersion:F,platform:`web`}):e.refreshSession(t),deleteSession:async t=>{e.deleteSession!==void 0&&await e.deleteSession(t)},setAgentStatus:(t,n)=>e.setAgentStatus===void 0?Promise.reject(new p(`CAPABILITY_NOT_SUPPORTED`,`capability`,!1,{cause:`当前会话来源不支持坐席状态设置(sessionProvider.setAgentStatus 未提供)`})):e.setAgentStatus(t,n)},n=e.invalidateToken;return n!==void 0&&(t.invalidateToken=()=>n()),t}function En(e){if(typeof e!=`object`||!e)throw new p(`CONFIG_INVALID`,`configuration`,!1);return e}function Dn(e,t,n,r,i){return e instanceof p?new p(e.code,e.category,e.retryable,{requestId:e.requestId,callId:i??e.callId,cause:e.cause??e,serverCode:e.serverCode,status:e.status}):new p(t,n,r,{callId:i,cause:e})}function On(e){return e instanceof p?e.status!==void 0&&e.status>=400&&e.status<500||e.serverCode===`SESSION_NOT_FOUND`||e.serverCode===`SESSION_EXPIRED`||e.serverCode===`TOKEN_INVALID`||e.serverCode===`TOKEN_EXPIRED`||e.code===`AUTH_TOKEN_UNAVAILABLE`||e.code===`AUTH_TOKEN_EXPIRED`:!1}function kn(e){return e instanceof p&&e.code===`SDK_ALREADY_DISPOSED`}function An(e){return e instanceof p&&(e.code===`SDK_ALREADY_DISPOSED`||e.code===`CALL_NOT_CONNECTED`)}var jn=[`outbound`,`inbound`,`mute`,`hold`,`dtmf`,`blind_transfer`,`device_selection`],Mn=[`outbound`,`mute`,`dtmf`];function Nn(e){return e===`mobile-web`?Mn:jn}m(),m();function Pn(e={}){return{version:`0.1.0`,options:e}}e.CCBarCall=w,e.CCBarClient=xn,e.CCBarError=p,e.CallManager=N,e.CallStateError=y,e.Diagnostics=$e,e.RingBuffer=Xe,e.TypedEventBus=h,e.assertCallTransition=v,e.canTransition=_,e.createSdk=Pn,e.createSharedWorkerSelection=ge,e.diagnosticsVersion=F,e.parseSessionResponse=x,e.redactText=ce,e.redactValue=le,e.resolveWorkerUrl=_e,e.transition=b,e.transitions=g,e.version=`0.1.0`});