@telegenta/webclient 3.0.1 → 3.1.1
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/demos/calldata_available.html +1 -1
- package/demos/event_client.html +1 -1
- package/dist/telegenta.js +87 -5
- package/dist/telegenta.min.js +1 -1
- package/docs/EventServiceNotConnected.html +1 -1
- package/docs/NoActiveSession.html +1 -1
- package/docs/NotAllowed.html +1 -1
- package/docs/Phone.html +1 -1
- package/docs/Session.html +4 -1
- package/docs/UnableToConnect.html +1 -1
- package/docs/data/search.json +1 -1
- package/docs/event-client.js.html +1 -1
- package/docs/exceptions.js.html +3 -2
- package/docs/global.html +3 -3
- package/docs/phone-client.js.html +45 -1
- package/package.json +2 -2
package/dist/telegenta.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Telegenta=function(e){"use strict";class t{constructor(e=2,t=null){this.extHandler=t,this.level=e}debug(...e){this._doLog(n.DEBUG,e)}info(...e){this._doLog(n.INFO,e)}warn(...e){this._doLog(n.WARN,e)}warning(...e){this._doLog(n.WARN,e)}error(...e){this._doLog(n.ERROR,e)}_doLog(e,t){if(!(e>this.level))if(1===t.length&&(t=t[0]),this.extHandler)this.extHandler(r[e],t);else switch(e){case n.DEBUG:console.debug(t);break;case n.INFO:console.info(t);break;case n.WARN:console.warn(t);break;case n.ERROR:console.error(t);break;default:console.log(t)}}}const n={DEBUG:3,INFO:2,WARN:1,ERROR:0},r={3:"DEBUG",2:"INFO ",1:"WARN ",0:"ERROR"};function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s,o={exports:{}};function l(){if(s)return o.exports;s=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}o.exports=i,o.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,s),r(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}m(e,t,s,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&m(e,"error",t,n)}(e,i,{once:!0})})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var l=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function u(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,s,o,l;if(a(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=u(e))>0&&o.length>i&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,l=c,console&&console.warn&&console.warn(l)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=h.bind(r);return i.listener=n,r.wrapFn=i,i}function f(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function _(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function m(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(s){r.once&&e.removeEventListener(t,i),n(s)})}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return l},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");l=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return u(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,s=this._events;if(void 0!==s)i=i&&void 0===s.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var l=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw l.context=o,l}var a=s[e];if(void 0===a)return!1;if("function"==typeof a)n(a,this,t);else{var u=a.length,c=p(a,u);for(r=0;r<u;++r)n(c[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return a(t),this.on(e,d(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,d(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,i,s,o;if(a(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,s=Object.keys(n);for(r=0;r<s.length;++r)"removeListener"!==(i=s[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return f(this,e,!0)},i.prototype.rawListeners=function(e){return f(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):_.call(e,t)},i.prototype.listenerCount=_,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},o.exports}var a=i(l());class u extends Error{constructor(e){super(),this.name="MediaNotPrepared",this.message=e}}class c extends Error{constructor(e){super(),this.name="NotReady",this.message=e}}class h extends Error{constructor(e){super(),this.name="InvalidMediaDevice",this.message=e}}class d extends Error{constructor(e,t){super(),this.name="InvalidOptions",this.param=e,this.message=t}}class f extends Error{constructor(e){super(),this.name="InvalidParameter",this.message=e}}class _ extends Error{constructor(){super(),this.name="NoActiveSession"}}class p extends Error{constructor(){super(),this.name="UnableToConnect"}}class m extends Error{constructor(e){super(),this.name="NotAllowed",this.message=e}}class g extends Error{constructor(){super(),this.name="EventServiceNotConnected"}}function v(){let e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function y(e){const t=Math.floor(e/1e3);let n="";return t/86400>=1&&(n=n+Math.floor(t/86400)+"d "),t/3600>=1&&(n=n+Math.floor(t/3600)%24+"h "),t>=0?(n=n+("00"+Math.floor(t/60)%60).slice(-2)+":",n+=("00"+t%60).slice(-2)):n="00:00",n}function T(){return-1!==(navigator.userAgent.indexOf("Opera")||navigator.userAgent.indexOf("OPR"))}function b(){return-1!==navigator.userAgent.indexOf("Chrome")}function S(){return-1!==navigator.userAgent.indexOf("Firefox")}function C(){return-1!==navigator.userAgent.indexOf("Safari")}class E{constructor(e,t,n){this.socket=t,this._owner=e,this._request=n,this._handled=!1,this.data=n.data}resolve(e=null){this._assertSingleRequest();try{this.socket.send(JSON.stringify({type:"_ACK",id:this._request.id,data:e}))}catch(e){this._owner.log.warning(`Unable to resolve request ${this._request.id}: ${e}`)}}reject(e=null){this._assertSingleRequest();try{this.socket.send(JSON.stringify({type:"_NACK",id:this._request.id,reason:e}))}catch(e){this._owner.log.warning(`Unable to reject request ${this._request.id}: ${e}`)}}_assertSingleRequest(){if(this._handled)throw new m(`Request ${this._request.id} already fulfilled`);this._handled=!0}}class A extends a{constructor(e=null){super(),this.log=e||new t(n.INFO),this._pendingRequests=[]}receiveMessage(e,t){let n;this.log.debug("Received message: "+t);try{n=JSON.parse(t)}catch(e){return void this.log.warning("Unable to parse message: "+t)}if(n.hasOwnProperty("type")&&n.hasOwnProperty("id")){if("_ACK"===n.type||"_NACK"===n.type){const e=this.findPendingRequest(n.id);return e?("_ACK"===n.type?(this.log.debug(`Received ACK with id=${n.id}`),e.resolve(n.data)):"_NACK"===n.type&&(this.log.debug(`Received NACK with id=${n.id}`),e.reject(n.reason)),void this.removePendingRequest(n.id)):void this.log.warning(`Received message with invalid request id: ${n.id} - timed out?`)}if("_PING"===n.type)return this.log.debug("Received ping, sending pong (ACK)"),void e.send(JSON.stringify({type:"_ACK",id:n.id,data:"pong"}));this.log.debug(`Received new request of type '${n.type}' with id=${n.id}`),this.emit(n.type,new E(this,e,n))||(this.log.warning("Received request with no listeners, rejecting"),e.send(JSON.stringify({type:"_NACK",id:n.id,reason:"No handlers for that request type"})))}else this.log.warning(`Invalid message received: ${n} - missing type or id`)}sendRequest(e,t,n={}){if(!e||!t)throw new f("You must specify socket and request type");let r={type:t,id:v(),data:n};this.log.debug(`Sending request type '${t}' with id ${r.id}`);try{e.send(JSON.stringify(r))}catch(e){return this.log.warning(`Unable to send request ${r.id} socket error: ${e}`),new Promise(function(t,n){n(`Unable to send request: ${e}`)})}const i=this;return new Promise(function(e,t){i._pendingRequests.push({request:r,resolve:e,reject:t,timeoutObj:setTimeout(function(){i.log.info(`Timeout on request ${r.id}, rejecting!`),i.removePendingRequest(r.id),t("Request timed out")},1e4)})})}ping(e){return this.log.debug("Sending ping"),this.sendRequest(e,"_PING")}removePendingRequest(e){for(let t in this._pendingRequests)if(this._pendingRequests[t].request.id===e)return clearTimeout(this._pendingRequests[t].timeoutObj),this._pendingRequests.splice(t,1),this.log.debug(`Removed request id: ${e}`),!0;return this.log.warning(`Unable to remove request ${e} => not found`),!1}findPendingRequest(e){for(let t of this._pendingRequests)if(t.request.id===e)return t;return null}}const w=1+Math.random();class R{constructor(e,t,n){this.id=e,this.specification=t,this.callback=n}doCallback(e,t){return this.callback.apply(e,[t])}}class I{constructor(e=null){this._socket=null,this._previousSubscriptions=[],this._activeSubscriptions=[],this._pingTimerObj=null,this._autoReconnect=!1,this._reconnectRetrySeconds=w,this.log=e||new t(LOGLVL.ERROR),this._requestor=new A(this.log),this._requestor.on("event",e=>{this._handleIncomingEvent(e)})}connect(e=null){return e||(e="wss://api.telegenta.com/es/"),this._serverAddress=e,this._previousSubscriptions=[],this._activeSubscriptions=[],this._connectServer()}disconnect(){if(1!==this._socket.readyState)throw new g;this._activeSubscriptions=[],this._autoReconnect=!1,this._socket.close()}isConnected(){return!!this._socket&&1===this._socket.readyState}subscribe(e,t){if(!e||!t)throw new f("You must specify both event spec and callback function");if(!e.hasOwnProperty("event_name"))throw new f("Your event specification must contain event name");if(!this.isConnected())throw new g;const n=this;return new Promise(function(r,i){n._requestor.sendRequest(n._socket,"subscribe",e).then(function(i){n.log.debug(`Subscription to '${e.event_name}' was successful, ID = ${i}`),n._activeSubscriptions.push(new R(i,e,t)),r(i)},function(t){n.log.warning(`Subscription to '${e.event_name}' failed: ${t}`),i(t)})})}unsubscribe(e){if(!e)throw new f("You must specify subscription id");if(!this.isConnected())throw new g;this.log.info("Unsubscribe id: "+e);const t=this;return new Promise(function(n,r){t._requestor.sendRequest(t._socket,"unsubscribe",{id:e}).then(r=>{t.log.info(`Unsubscribe to '${e}' was successful`),t._removeSubscription(e),n(r)},n=>{t.log.warning(`Remote unsubscribe to '${e}' failed: ${n}`),r(n)})})}fireEvent(e,t){if(!this.isConnected())throw new g;return new Promise((n,r)=>{this._requestor.sendRequest(this._socket,e,t).then(t=>{this.log.info(`Event ${e} was successful`),n(t)},t=>{this.log.warning(`Event ${e} failed: ${t}`),r(t)})})}_removeSubscription(e){for(let t in this._activeSubscriptions)if(this._activeSubscriptions[t].id===e)return this.log.debug(`Removed local subscription: ${e}`),this._activeSubscriptions.splice(t,1),!0;return this.log.warning(`Unable to remove subscription ${e} locally, not found?`),!1}_connectServer(){this.log.info("Connecting to event server: "+this._serverAddress);const e=this;return new Promise(function(t,n){if(e._socket)switch(e._socket.readyState){case 0:return void n("Unable to connect, already connecting");case 1:return void n("Unable to connect, already connected");case 2:return void n("Unable to connect, socket is still closing")}e._socket=new WebSocket(e._serverAddress);let r=!1;e._socket.addEventListener("open",function(){e.log.info("Successfully connected to event service"),r=!0,e._autoReconnect=!0,e._reconnectRetrySeconds=w,e._socket.addEventListener("message",function(t){e._requestor.receiveMessage(e._socket,t.data)}),clearTimeout(e._pingTimerObj),e._pingTimerObj=setInterval(function(){e._requestor.ping(e._socket).then(function(){},function(t){e.log.warning("Ping failed: "+t),e._reconnectServer()})},5e4),e._previousSubscriptions=e._activeSubscriptions,e._activeSubscriptions=[];for(let t of e._previousSubscriptions)e.subscribe(t.specification,t.callback).catch(function(n){e.log.error(`Resubscribing to ${t.specification.event_name} failed: ${n}`)});t()}),e._socket.addEventListener("close",function(){e.log.info("Disconnected from event service"),clearTimeout(e._pingTimerObj),e._reconnectServer()}),e._socket.addEventListener("error",function(t){e.log.error("Websocket connection error"),r||n("Unable to connect: "+t)})})}_reconnectServer(){if(this._autoReconnect){const e=Math.floor(this._reconnectRetrySeconds);this.log.info(`Reconnecting in ${e} secs`);const t=this;setTimeout(function(){t._connectServer().then(function(){t.log.info("Reconnect attempt successful")},function(){t.log.warning("Reconnect attempt failed")}),t._reconnectRetrySeconds<=300&&(t._reconnectRetrySeconds=2*t._reconnectRetrySeconds)},1e3*t._reconnectRetrySeconds)}else this.log.info("Auto reconnect disabled (disconnecting?)")}_handleIncomingEvent(e){const t=e.data.subscription_id;for(let n of this._activeSubscriptions)if(n.id===t){this.log.debug(`Received event for subcription id ${n.id} payload: `+JSON.stringify(e.data.payload));try{n.callback(e.data.payload)}catch(t){this.log.warning(`Callback had unhandled exception ${t}`),e.resolve()}return void e.resolve()}e.reject(`Invalid subscription id for event: ${t}`)}}var O,N,k,D,x={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.1",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};function U(){if(N)return O;N=1;var e=x;return O={USER_AGENT:"".concat(e.title," ").concat(e.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}}function P(){if(D)return k;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if("function"!=typeof t&&null!==t)throw new 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&&l(e,t)}function r(t){var n=o();return function(){var r,i=a(t);if(n){var s=a(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)},i(e)}function s(e,t,n){return s=o()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&l(i,n.prototype),i},s.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}function l(e,t){return l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},l(e,t)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}D=1;var u=function(e){n(s,e);var i=r(s);function s(e,n){var r;return t(this,s),(r=i.call(this)).code=1,r.name="CONFIGURATION_ERROR",r.parameter=e,r.value=n,r.message=r.value?"Invalid value ".concat(JSON.stringify(r.value),' for parameter "').concat(r.parameter,'"'):"Missing parameter: ".concat(r.parameter),r}return s}(i(Error)),c=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=2,n.name="INVALID_STATE_ERROR",n.status=e,n.message="Invalid status: ".concat(e),n}return s}(i(Error)),h=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=3,n.name="NOT_SUPPORTED_ERROR",n.message=e,n}return s}(i(Error)),d=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=4,n.name="NOT_READY_ERROR",n.message=e,n}return s}(i(Error));return k={ConfigurationError:u,InvalidStateError:c,NotSupportedError:h,NotReadyError:d}}var M,q,L,H,F,j,G,$={};function B(){if(q)return M;function e(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 t(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}q=1;var n=V(),r=W();return M=function(){function e(t,r,i){if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!(t&&t instanceof n))throw new TypeError('missing or invalid "uri" parameter');for(var s in this._uri=t,this._parameters={},this.display_name=r,i)Object.prototype.hasOwnProperty.call(i,s)&&this.setParam(s,i[s])}return t(e,null,[{key:"parse",value:function(e){return-1!==(e=r.parse(e,"Name_Addr_Header"))?e:void 0}}]),t(e,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?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())}},{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?'"'.concat(this._quote(this._display_name),'" '):"";for(var t in e+="<".concat(this._uri.toString(),">"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(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=0===e?"0":e}}]),e}()}function W(){return H||(H=1,L=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:a,DIGIT:u,ALPHA:c,HEXDIG:h,WSP:d,OCTET:f,DQUOTE:_,SP:p,HTAB:m,alphanum:g,reserved:v,unreserved:y,mark:T,escaped:b,LWS:S,SWS:C,HCOLON:E,TEXT_UTF8_TRIM:A,TEXT_UTF8char:w,UTF8_NONASCII:R,UTF8_CONT:I,LHEX:function(){var e;null===(e=u())&&(/^[a-f]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-f]")));return e},token:O,token_nodot:N,separators:function(){var e;40===t.charCodeAt(i)?(e="(",i++):(e=null,l('"("'));null===e&&(41===t.charCodeAt(i)?(e=")",i++):(e=null,l('")"')),null===e&&(60===t.charCodeAt(i)?(e="<",i++):(e=null,l('"<"')),null===e&&(62===t.charCodeAt(i)?(e=">",i++):(e=null,l('">"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","')),null===e&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(92===t.charCodeAt(i)?(e="\\",i++):(e=null,l('"\\\\"')),null===e&&null===(e=_())&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(123===t.charCodeAt(i)?(e="{",i++):(e=null,l('"{"')),null===e&&(125===t.charCodeAt(i)?(e="}",i++):(e=null,l('"}"')),null===e&&null===(e=p())&&(e=m()))))))))))))))));return e},word:k,STAR:D,SLASH:x,EQUAL:U,LPAREN:P,RPAREN:M,RAQUOT:q,LAQUOT:L,COMMA:H,SEMI:F,COLON:j,LDQUOT:G,RDQUOT:$,comment:function e(){var t,n,r,s;if(s=i,null!==(t=P())){for(n=[],null===(r=W())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=W())&&null===(r=X())&&(r=e());null!==n&&null!==(r=M())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:W,quoted_string:z,quoted_string_clean:K,qdtext:Y,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:ie,password:se,hostport:oe,host:le,hostname:ae,domainlabel:ue,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ge,uri_parameters:ve,uri_parameter:ye,transport_param:Te,user_param:be,method_param:Se,ttl_param:Ce,maddr_param:Ee,lr_param:Ae,other_param:we,pname:Re,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:xe,hvalue:Ue,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:Le,hier_part:He,net_path:Fe,abs_path:je,opaque_part:Ge,uric:$e,uric_no_slash:Be,path_segments:We,segment:Ve,param:ze,pchar:Ke,scheme:Ye,authority:Xe,srvr:Je,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:it,CANCELm:st,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:at,REFERm:ut,Method:ct,Status_Line:ht,Status_Code:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=H())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Call_ID:function(){var e,n,r,s,o,a;s=i,o=i,null!==(e=k())?(a=i,64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n&&null!==(r=k())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o);null!==e&&(e=function(e){jn=t.substring(i,e)}(s));null===e&&(i=s);return e},Contact:function(){var e,t,n,r,s,o,l;if(s=i,null===(e=D()))if(o=i,null!==(e=pt())){for(t=[],l=i,null!==(n=H())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=H())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e,t;for(t=jn.multi_header.length,e=0;e<t;e++)if(null===jn.multi_header[e].parsed){jn=null;break}jn=null!==jn?jn.multi_header:-1}());null===e&&(i=s);return e},contact_param:pt,name_addr:mt,display_name:gt,contact_params:vt,c_p_q:yt,c_p_expires:Tt,delta_seconds:bt,qvalue:St,generic_param:Ct,gen_value:Et,Content_Disposition:function(){var e,t,n,r,s,o;if(s=i,null!==(e=At())){for(t=[],o=i,null!==(n=F())&&null!==(r=wt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=wt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},disp_type:At,disp_param:wt,handling_param:Rt,Content_Encoding:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Content_Length:function(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(jn=parseInt(e.join(""))));null===e&&(i=n);return e},Content_Type:function(){var e,n;n=i,null!==(e=It())&&(e=function(e){jn=t.substring(i,e)}(n));null===e&&(i=n);return e},media_type:It,m_type:Ot,discrete_type:Nt,composite_type:kt,extension_token:Dt,x_token:xt,m_subtype:Ut,m_parameter:Pt,m_value:Mt,CSeq:function(){var e,t,n,r;r=i,null!==(e=qt())&&null!==(t=S())&&null!==(n=ct())?e=[e,t,n]:(e=null,i=r);return e},CSeq_value:qt,Expires:function(){var e,t;t=i,null!==(e=bt())&&(e=void(jn=e));null===e&&(i=t);return e},Event:function(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=Lt())){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(a=e[0],e=void(jn.event=a.join("").toLowerCase()));var a;null===e&&(i=s);return e},event_type:Lt,From:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=Ht())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ht())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),e&&jn.setParam("tag",e)}catch(e){jn=-1}}());null===e&&(i=s);return e},from_param:Ht,tag_param:Ft,Max_Forwards:function(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(jn=parseInt(e.join(""))));null===e&&(i=n);return e},Min_Expires:function(){var e,t;t=i,null!==(e=bt())&&(e=void(jn=e));null===e&&(i=t);return e},Name_Addr_Header:function(){var e,t,n,r,s,o,l,a,u,c;a=i,u=i,e=[],t=gt();for(;null!==t;)e.push(t),t=gt();if(null!==e)if(null!==(t=L()))if(null!==(n=Q()))if(null!==(r=q())){for(s=[],c=i,null!==(o=F())&&null!==(l=Ct())?o=[o,l]:(o=null,i=c);null!==o;)s.push(o),c=i,null!==(o=F())&&null!==(l=Ct())?o=[o,l]:(o=null,i=c);null!==s?e=[e,t,n,r,s]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;else e=null,i=u;else e=null,i=u;null!==e&&(e=function(){try{jn=new Fn(jn.uri,jn.display_name,jn.params)}catch(e){jn=-1}}());null===e&&(i=a);return e},Proxy_Authenticate:function(){return jt()},challenge:jt,other_challenge:Gt,auth_param:$t,digest_cln:Bt,realm:Wt,realm_value:Vt,domain:zt,URI:Kt,nonce:Yt,nonce_value:Xt,opaque:Jt,stale:Qt,algorithm:Zt,qop_options:en,qop_value:tn,Proxy_Require:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Record_Route:function(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=nn())){for(t=[],l=i,null!==(n=H())&&null!==(r=nn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=H())&&null!==(r=nn())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e,t;for(t=jn.multi_header.length,e=0;e<t;e++)if(null===jn.multi_header[e].parsed){jn=null;break}jn=null!==jn?jn.multi_header:-1}());null===e&&(i=s);return e},rec_route:nn,Reason:function(){var e,n,r,s,o,a,u;o=i,a=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"'));null===e&&(e=O());if(null!==e){for(n=[],u=i,null!==(r=F())&&null!==(s=rn())?r=[r,s]:(r=null,i=u);null!==r;)n.push(r),u=i,null!==(r=F())&&null!==(s=rn())?r=[r,s]:(r=null,i=u);null!==n?e=[e,n]:(e=null,i=a)}else e=null,i=a;null!==e&&(e=function(e,t){if(jn.protocol=t.toLowerCase(),jn.params||(jn.params={}),jn.params.text&&'"'===jn.params.text[0]){var n=jn.params.text;jn.text=n.substring(1,n.length-1),delete jn.params.text}}(0,e[0]));null===e&&(i=o);return e},reason_param:rn,reason_cause:sn,Require:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Route:function(){var e,t,n,r,s,o;if(s=i,null!==(e=on())){for(t=[],o=i,null!==(n=H())&&null!==(r=on())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=on())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},route_param:on,Subscription_State:function(){var e,t,n,r,s,o;if(s=i,null!==(e=ln())){for(t=[],o=i,null!==(n=F())&&null!==(r=an())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=an())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},substate_value:ln,subexp_params:an,event_reason_value:un,Subject:function(){var e;return e=null!==(e=A())?e:""},Supported:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e=null!==e?e:""},To:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=cn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=cn())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),e&&jn.setParam("tag",e)}catch(e){jn=-1}}());null===e&&(i=s);return e},to_param:cn,Via:function(){var e,t,n,r,s,o;if(s=i,null!==(e=hn())){for(t=[],o=i,null!==(n=H())&&null!==(r=hn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=hn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},via_param:hn,via_params:dn,via_ttl:fn,via_maddr:_n,via_received:pn,via_branch:mn,response_port:gn,rport:vn,sent_protocol:yn,protocol_name:Tn,transport:bn,sent_by:Sn,via_host:Cn,via_port:En,ttl:An,WWW_Authenticate:function(){return jt()},Session_Expires:function(){var e,t,n,r,s,o;if(s=i,null!==(e=wn())){for(t=[],o=i,null!==(n=F())&&null!==(r=Rn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Rn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},s_e_expires:wn,s_e_params:Rn,s_e_refresher:In,extension_header:function(){var e,t,n,r;r=i,null!==(e=O())&&null!==(t=E())&&null!==(n=On())?e=[e,t,n]:(e=null,i=r);return e},header_value:On,message_body:function(){var e,t;e=[],t=f();for(;null!==t;)e.push(t),t=f();return e},uuid_URI:function(){var e,n,r;r=i,"uuid:"===t.substr(i,5)?(e="uuid:",i+=5):(e=null,l('"uuid:"'));null!==e&&null!==(n=Nn())?e=[e,n]:(e=null,i=r);return e},uuid:Nn,hex4:kn,hex8:Dn,hex12:xn,Refer_To:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){try{jn=new Fn(jn.uri,jn.display_name,jn.params)}catch(e){jn=-1}}());null===e&&(i=s);return e},Replaces:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Un())){for(t=[],o=i,null!==(n=F())&&null!==(r=Pn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Pn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},call_id:Un,replaces_param:Pn,to_tag:Mn,from_tag:qn,early_flag:Ln};if(void 0!==n){if(void 0===r[n])throw new Error("Invalid rule name: "+e(n)+".")}else n="CRLF";var i=0,s=0,o=[];function l(e){i<s||(i>s&&(s=i,o=[]),o.push(e))}function a(){var e;return"\r\n"===t.substr(i,2)?(e="\r\n",i+=2):(e=null,l('"\\r\\n"')),e}function u(){var e;return/^[0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[0-9]")),e}function c(){var e;return/^[a-zA-Z]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-zA-Z]")),e}function h(){var e;return/^[0-9a-fA-F]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[0-9a-fA-F]")),e}function d(){var e;return null===(e=p())&&(e=m()),e}function f(){var e;return/^[\0-\xFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\0-\\xFF]")),e}function _(){var e;return/^["]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l('["]')),e}function p(){var e;return 32===t.charCodeAt(i)?(e=" ",i++):(e=null,l('" "')),e}function m(){var e;return 9===t.charCodeAt(i)?(e="\t",i++):(e=null,l('"\\t"')),e}function g(){var e;return/^[a-zA-Z0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-zA-Z0-9]")),e}function v(){var e;return 59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))))),e}function y(){var e;return null===(e=g())&&(e=T()),e}function T(){var e;return 45===t.charCodeAt(i)?(e="-",i++):(e=null,l('"-"')),null===e&&(95===t.charCodeAt(i)?(e="_",i++):(e=null,l('"_"')),null===e&&(46===t.charCodeAt(i)?(e=".",i++):(e=null,l('"."')),null===e&&(33===t.charCodeAt(i)?(e="!",i++):(e=null,l('"!"')),null===e&&(126===t.charCodeAt(i)?(e="~",i++):(e=null,l('"~"')),null===e&&(42===t.charCodeAt(i)?(e="*",i++):(e=null,l('"*"')),null===e&&(39===t.charCodeAt(i)?(e="'",i++):(e=null,l('"\'"')),null===e&&(40===t.charCodeAt(i)?(e="(",i++):(e=null,l('"("')),null===e&&(41===t.charCodeAt(i)?(e=")",i++):(e=null,l('")"')))))))))),e}function b(){var e,n,r,s,o;return s=i,o=i,37===t.charCodeAt(i)?(e="%",i++):(e=null,l('"%"')),null!==e&&null!==(n=h())&&null!==(r=h())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=e.join("")),null===e&&(i=s),e}function S(){var e,t,n,r,s,o;for(r=i,s=i,o=i,e=[],t=d();null!==t;)e.push(t),t=d();if(null!==e&&null!==(t=a())?e=[e,t]:(e=null,i=o),null!==(e=null!==e?e:"")){if(null!==(n=d()))for(t=[];null!==n;)t.push(n),n=d();else t=null;null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return null!==e&&(e=" "),null===e&&(i=r),e}function C(){var e;return e=null!==(e=S())?e:""}function E(){var e,n,r,s,o;for(s=i,o=i,e=[],null===(n=p())&&(n=m());null!==n;)e.push(n),null===(n=p())&&(n=m());return null!==e?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=":"),null===e&&(i=s),e}function A(){var e,n,r,s,o,l,a;if(o=i,l=i,null!==(n=w()))for(e=[];null!==n;)e.push(n),n=w();else e=null;if(null!==e){for(n=[],a=i,r=[],s=S();null!==s;)r.push(s),s=S();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(n.push(r),a=i,r=[],s=S();null!==s;)r.push(s),s=S();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==n?e=[e,n]:(e=null,i=l)}else e=null,i=l;return null!==e&&(e=function(e){return t.substring(i,e)}(o)),null===e&&(i=o),e}function w(){var e;return/^[!-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[!-~]")),null===e&&(e=R()),e}function R(){var e;return/^[\x80-\uFFFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\x80-\\uFFFF]")),e}function I(){var e;return/^[\x80-\xBF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\x80-\\xBF]")),e}function O(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"'))))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function N(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"'))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function k(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(i)?(n=">",i++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(i)?(n="\\",i++):(n=null,l('"\\\\"')),null===n&&null===(n=_())&&(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(i)?(n="[",i++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(i)?(n="]",i++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(i)?(n="{",i++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(i)?(n="}",i++):(n=null,l('"}"')))))))))))))))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(i)?(n=">",i++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(i)?(n="\\",i++):(n=null,l('"\\\\"')),null===n&&null===(n=_())&&(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(i)?(n="[",i++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(i)?(n="]",i++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(i)?(n="{",i++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(i)?(n="}",i++):(n=null,l('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function D(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="*"),null===e&&(i=s),e}function x(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="/"),null===e&&(i=s),e}function U(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="="),null===e&&(i=s),e}function P(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="("),null===e&&(i=s),e}function M(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=")"),null===e&&(i=s),e}function q(){var e,n,r,s;return r=i,s=i,62===t.charCodeAt(i)?(e=">",i++):(e=null,l('">"')),null!==e&&null!==(n=C())?e=[e,n]:(e=null,i=s),null!==e&&(e=">"),null===e&&(i=r),e}function L(){var e,n,r,s;return r=i,s=i,null!==(e=C())?(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(e="<"),null===e&&(i=r),e}function H(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=","),null===e&&(i=s),e}function F(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=";"),null===e&&(i=s),e}function j(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=":"),null===e&&(i=s),e}function G(){var e,t,n,r;return n=i,r=i,null!==(e=C())&&null!==(t=_())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function $(){var e,t,n,r;return n=i,r=i,null!==(e=_())&&null!==(t=C())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e;return/^[!-']/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[!-']")),null===e&&(/^[*-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[*-[]")),null===e&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\]-~]")),null===e&&null===(e=R())&&(e=S()))),e}function z(){var e,n,r,s,o,l;if(o=i,l=i,null!==(e=C()))if(null!==(n=_())){for(r=[],null===(s=Y())&&(s=X());null!==s;)r.push(s),null===(s=Y())&&(s=X());null!==r&&null!==(s=_())?e=[e,n,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(e=function(e){return t.substring(i,e)}(o)),null===e&&(i=o),e}function K(){var e,n,r,s,o,l;if(o=i,l=i,null!==(e=C()))if(null!==(n=_())){for(r=[],null===(s=Y())&&(s=X());null!==s;)r.push(s),null===(s=Y())&&(s=X());null!==r&&null!==(s=_())?e=[e,n,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(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)),null===e&&(i=o),e}function Y(){var e;return null===(e=S())&&(33===t.charCodeAt(i)?(e="!",i++):(e=null,l('"!"')),null===e&&(/^[#-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[#-[]")),null===e&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\]-~]")),null===e&&(e=R())))),e}function X(){var e,n,r;return r=i,92===t.charCodeAt(i)?(e="\\",i++):(e=null,l('"\\\\"')),null!==e?(/^[\0-\t]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\0-\\t]")),null===n&&(/^[\x0B-\f]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\x0B-\\f]")),null===n&&(/^[\x0E-]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\x0E-]")))),null!==n?e=[e,n]:(e=null,i=r)):(e=null,i=r),e}function J(){var e,n,r,s,o,a;return o=i,a=i,null!==(e=Z())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,n,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port}catch(e){jn=-1}}()),null===e&&(i=o),e}function Q(){var e,r,s,o,a,u,c,h;return c=i,h=i,null!==(e=Z())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=null!==(s=ne())?s:"")&&null!==(o=oe())&&null!==(a=ve())&&null!==(u=null!==(u=ke())?u:"")?e=[e,r,s,o,a,u]:(e=null,i=h)):(e=null,i=h),null!==e&&(e=function(){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port,jn.uri_params,jn.uri_headers),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port,delete jn.uri_params,"SIP_URI"===n&&(jn=jn.uri)}catch(e){jn=-1}}()),null===e&&(i=c),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,n,r;return n=i,"sips"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"sips"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=n),e}function te(){var e,n,r;return n=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=n),e}function ne(){var e,n,r,s,o,a;return s=i,o=i,null!==(e=re())?(a=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=se())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?(64===t.charCodeAt(i)?(r="@",i++):(r=null,l('"@"')),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){jn.user=decodeURIComponent(t.substring(i-1,e))}(s)),null===e&&(i=s),e}function re(){var e,t;if(null===(t=y())&&null===(t=b())&&(t=ie()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&null===(t=b())&&(t=ie());else e=null;return e}function ie(){var e;return 38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","')),null===e&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"'))))))))),e}function se(){var e,n,r;for(r=i,e=[],null===(n=y())&&null===(n=b())&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')))))));null!==n;)e.push(n),null===(n=y())&&null===(n=b())&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')))))));return null!==e&&(e=function(e){jn.password=t.substring(i,e)}(r)),null===e&&(i=r),e}function oe(){var e,n,r,s,o;return s=i,null!==(e=le())?(o=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=ge())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function le(){var e,n;return n=i,null===(e=ae())&&null===(e=pe())&&(e=he()),null!==e&&(e=function(e){return jn.host=t.substring(i,e).toLowerCase(),jn.host}(n)),null===e&&(i=n),e}function ae(){var e,n,r,s,o,a;for(s=i,o=i,e=[],a=i,null!==(n=ue())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r?n=[n,r]:(n=null,i=a)):(n=null,i=a);null!==n;)e.push(n),a=i,null!==(n=ue())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r?n=[n,r]:(n=null,i=a)):(n=null,i=a);return null!==e&&null!==(n=ce())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==(r=null!==r?r:"")?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){return jn.host_type="domain",t.substring(i,e)}(s)),null===e&&(i=s),e}function ue(){var e,n,r,s;if(s=i,null!==(e=g())){for(n=[],null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==r;)n.push(r),null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==n?e=[e,n]:(e=null,i=s)}else e=null,i=s;return e}function ce(){var e,n,r,s;if(s=i,null!==(e=c())){for(n=[],null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==r;)n.push(r),null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==n?e=[e,n]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,n,r,s,o;return s=i,o=i,91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null!==e&&null!==(n=de())?(93===t.charCodeAt(i)?(r="]",i++):(r=null,l('"]"')),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){return jn.host_type="IPv6",t.substring(i,e)}(s)),null===e&&(i=s),e}function de(){var e,n,r,s,o,a,u,c,h,d,f,_,p,m,g,v;return m=i,g=i,null!==(e=fe())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?(58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=fe())?(58===t.charCodeAt(i)?(d=":",i++):(d=null,l('":"')),null!==d&&null!==(f=fe())?(58===t.charCodeAt(i)?(_=":",i++):(_=null,l('":"')),null!==_&&null!==(p=_e())?e=[e,n,r,s,o,a,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=fe())?(58===t.charCodeAt(i)?(f=":",i++):(f=null,l('":"')),null!==f&&null!==(_=_e())?e=[e,n,r,s,o,a,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=_e())?e=[e,n,r,s,o,a,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=_e())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=_e())?e=[e,n,r,s,o,a]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=_e())?e=[e,n,r,s]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?e=[e,n]:(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?e=[e,n]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===t.substr(i,2)?(n="::",i+=2):(n=null,l('"::"')),null!==n&&null!==(r=fe())?(58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=fe())?(58===t.charCodeAt(i)?(d=":",i++):(d=null,l('":"')),null!==d&&null!==(f=_e())?e=[e,n,r,s,o,a,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?("::"===t.substr(i,2)?(r="::",i+=2):(r=null,l('"::"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=_e())?e=[e,n,r,s,o,a,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?("::"===t.substr(i,2)?(s="::",i+=2):(s=null,l('"::"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=_e())?e=[e,n,r,s,o,a,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?("::"===t.substr(i,2)?(o="::",i+=2):(o=null,l('"::"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=_e())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?("::"===t.substr(i,2)?(a="::",i+=2):(a=null,l('"::"')),null!==a&&null!==(u=_e())?e=[e,n,r,s,o,a,u]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?(v=i,58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?a=[a,u]:(a=null,i=v),null!==(a=null!==a?a:"")?("::"===t.substr(i,2)?(u="::",i+=2):(u=null,l('"::"')),null!==u&&null!==(c=fe())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?(v=i,58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?a=[a,u]:(a=null,i=v),null!==(a=null!==a?a:"")?(v=i,58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?u=[u,c]:(u=null,i=v),null!==(u=null!==u?u:"")?("::"===t.substr(i,2)?(c="::",i+=2):(c=null,l('"::"')),null!==c?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(e=function(e){return jn.host_type="IPv6",t.substring(i,e)}(m)),null===e&&(i=m),e}function fe(){var e,t,n,r,s;return s=i,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,n,r,s;return s=i,null!==(e=fe())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),null===e&&(e=pe()),e}function pe(){var e,n,r,s,o,a,u,c,h;return c=i,h=i,null!==(e=me())?(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null!==n&&null!==(r=me())?(46===t.charCodeAt(i)?(s=".",i++):(s=null,l('"."')),null!==s&&null!==(o=me())?(46===t.charCodeAt(i)?(a=".",i++):(a=null,l('"."')),null!==a&&null!==(u=me())?e=[e,n,r,s,o,a,u]:(e=null,i=h)):(e=null,i=h)):(e=null,i=h)):(e=null,i=h),null!==e&&(e=function(e){return jn.host_type="IPv4",t.substring(i,e)}(c)),null===e&&(i=c),e}function me(){var e,n,r,s;return s=i,"25"===t.substr(i,2)?(e="25",i+=2):(e=null,l('"25"')),null!==e?(/^[0-5]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[0-5]")),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,50===t.charCodeAt(i)?(e="2",i++):(e=null,l('"2"')),null!==e?(/^[0-4]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[0-4]")),null!==n&&null!==(r=u())?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,49===t.charCodeAt(i)?(e="1",i++):(e=null,l('"1"')),null!==e&&null!==(n=u())&&null!==(r=u())?e=[e,n,r]:(e=null,i=s),null===e&&(s=i,/^[1-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[1-9]")),null!==e&&null!==(n=u())?e=[e,n]:(e=null,i=s),null===e&&(e=u())))),e}function ge(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),null===e&&(i=o),e}function ve(){var e,n,r,s;for(e=[],s=i,59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=ye())?n=[n,r]:(n=null,i=s);null!==n;)e.push(n),s=i,59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=ye())?n=[n,r]:(n=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=be())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=Ae())&&(e=we()),e}function Te(){var e,n,r,s,o;return r=i,s=i,"transport="===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"transport="')),null!==e?("udp"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"udp"')),null===n&&("tcp"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"tcp"')),null===n&&("sctp"===t.substr(i,4).toLowerCase()?(n=t.substr(i,4),i+=4):(n=null,l('"sctp"')),null===n&&("tls"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"tls"')),null===n&&(n=O())))),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.transport=o.toLowerCase())),null===e&&(i=r),e}function be(){var e,n,r,s,o;return r=i,s=i,"user="===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"user="')),null!==e?("phone"===t.substr(i,5).toLowerCase()?(n=t.substr(i,5),i+=5):(n=null,l('"phone"')),null===n&&("ip"===t.substr(i,2).toLowerCase()?(n=t.substr(i,2),i+=2):(n=null,l('"ip"')),null===n&&(n=O())),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.user=o.toLowerCase())),null===e&&(i=r),e}function Se(){var e,n,r,s,o;return r=i,s=i,"method="===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"method="')),null!==e&&null!==(n=ct())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.method=o)),null===e&&(i=r),e}function Ce(){var e,n,r,s,o;return r=i,s=i,"ttl="===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"ttl="')),null!==e&&null!==(n=An())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.params||(jn.params={}),e=void(jn.params.ttl=o)),null===e&&(i=r),e}function Ee(){var e,n,r,s,o;return r=i,s=i,"maddr="===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"maddr="')),null!==e&&null!==(n=le())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.maddr=o)),null===e&&(i=r),e}function Ae(){var e,n,r,s,o,a;return s=i,o=i,"lr"===t.substr(i,2).toLowerCase()?(e=t.substr(i,2),i+=2):(e=null,l('"lr"')),null!==e?(a=i,61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=O())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.lr=void 0)),null===e&&(i=s),e}function we(){var e,n,r,s,o,a,u,c;return s=i,o=i,null!==(e=Re())?(a=i,61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=Ie())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(u=e[0],c=e[1],jn.uri_params||(jn.uri_params={}),c=void 0===c?void 0:c[1],e=void(jn.uri_params[u.toLowerCase()]=c)),null===e&&(i=s),e}function Re(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Ie(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=y())&&(e=b()),e}function Ne(){var e;return 91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')))))))),e}function ke(){var e,n,r,s,o,a,u;if(a=i,63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null!==e)if(null!==(n=De())){for(r=[],u=i,38===t.charCodeAt(i)?(s="&",i++):(s=null,l('"&"')),null!==s&&null!==(o=De())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,38===t.charCodeAt(i)?(s="&",i++):(s=null,l('"&"')),null!==s&&null!==(o=De())?s=[s,o]:(s=null,i=u);null!==r?e=[e,n,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function De(){var e,n,r,s,o,a,u;return s=i,o=i,null!==(e=xe())?(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=Ue())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[0],u=e[2],a=a.join("").toLowerCase(),u=u.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(u):jn.uri_headers[a]=[u])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=Pe())&&null===(t=y())&&(t=b()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=y())&&(t=b());else e=null;return e}function Ue(){var e,t;for(e=[],null===(t=Pe())&&null===(t=y())&&(t=b());null!==t;)e.push(t),null===(t=Pe())&&null===(t=y())&&(t=b());return e}function Pe(){var e;return 91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')))))))),e}function Me(){var e,t,n,r,s,o;return o=i,null!==(e=ct())&&null!==(t=p())&&null!==(n=qe())&&null!==(r=p())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function qe(){var e;return null===(e=Q())&&(e=Le()),e}function Le(){var e,n,r,s;return s=i,null!==(e=Ye())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n?(null===(r=He())&&(r=Ge()),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function He(){var e,n,r,s,o;return s=i,null===(e=Fe())&&(e=je()),null!==e?(o=i,63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null!==n&&null!==(r=Ze())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function Fe(){var e,n,r,s;return s=i,"//"===t.substr(i,2)?(e="//",i+=2):(e=null,l('"//"')),null!==e&&null!==(n=Xe())&&null!==(r=null!==(r=je())?r:"")?e=[e,n,r]:(e=null,i=s),e}function je(){var e,n,r;return r=i,47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null!==e&&null!==(n=We())?e=[e,n]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Be())){for(t=[],n=$e();null!==n;)t.push(n),n=$e();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function $e(){var e;return null===(e=v())&&null===(e=y())&&(e=b()),e}function Be(){var e;return null===(e=y())&&null===(e=b())&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))))),e}function We(){var e,n,r,s,o,a;if(o=i,null!==(e=Ve())){for(n=[],a=i,47===t.charCodeAt(i)?(r="/",i++):(r=null,l('"/"')),null!==r&&null!==(s=Ve())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,47===t.charCodeAt(i)?(r="/",i++):(r=null,l('"/"')),null!==r&&null!==(s=Ve())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function Ve(){var e,n,r,s,o,a;for(o=i,e=[],n=Ke();null!==n;)e.push(n),n=Ke();if(null!==e){for(n=[],a=i,59===t.charCodeAt(i)?(r=";",i++):(r=null,l('";"')),null!==r&&null!==(s=ze())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,59===t.charCodeAt(i)?(r=";",i++):(r=null,l('";"')),null!==r&&null!==(s=ze())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function ze(){var e,t;for(e=[],t=Ke();null!==t;)e.push(t),t=Ke();return e}function Ke(){var e;return null===(e=y())&&null===(e=b())&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))),e}function Ye(){var e,n,r,s,o;if(s=i,o=i,null!==(e=c())){for(n=[],null===(r=c())&&null===(r=u())&&(43===t.charCodeAt(i)?(r="+",i++):(r=null,l('"+"')),null===r&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')))));null!==r;)n.push(r),null===(r=c())&&null===(r=u())&&(43===t.charCodeAt(i)?(r="+",i++):(r=null,l('"+"')),null===r&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')))));null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){jn.scheme=t.substring(i,e)}(s)),null===e&&(i=s),e}function Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){var e,n,r,s;return r=i,s=i,null!==(e=ne())?(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==(e=null!==e?e:"")&&null!==(n=oe())?e=[e,n]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,n;if(null===(n=y())&&null===(n=b())&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null===n&&(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=y())&&null===(n=b())&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null===n&&(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=$e();null!==t;)e.push(t),t=$e();return e}function et(){var e,n,r,s,o,a,c,h;if(c=i,h=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"')),null!==e)if(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null!==n){if(null!==(s=u()))for(r=[];null!==s;)r.push(s),s=u();else r=null;if(null!==r)if(46===t.charCodeAt(i)?(s=".",i++):(s=null,l('"."')),null!==s){if(null!==(a=u()))for(o=[];null!==a;)o.push(a),a=u();else o=null;null!==o?e=[e,n,r,s,o]:(e=null,i=h)}else e=null,i=h;else e=null,i=h}else e=null,i=h;else e=null,i=h;return null!==e&&(e=function(e){jn.sip_version=t.substring(i,e)}(c)),null===e&&(i=c),e}function tt(){var e;return"INVITE"===t.substr(i,6)?(e="INVITE",i+=6):(e=null,l('"INVITE"')),e}function nt(){var e;return"ACK"===t.substr(i,3)?(e="ACK",i+=3):(e=null,l('"ACK"')),e}function rt(){var e;return"OPTIONS"===t.substr(i,7)?(e="OPTIONS",i+=7):(e=null,l('"OPTIONS"')),e}function it(){var e;return"BYE"===t.substr(i,3)?(e="BYE",i+=3):(e=null,l('"BYE"')),e}function st(){var e;return"CANCEL"===t.substr(i,6)?(e="CANCEL",i+=6):(e=null,l('"CANCEL"')),e}function ot(){var e;return"REGISTER"===t.substr(i,8)?(e="REGISTER",i+=8):(e=null,l('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===t.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,l('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===t.substr(i,6)?(e="NOTIFY",i+=6):(e=null,l('"NOTIFY"')),e}function ut(){var e;return"REFER"===t.substr(i,5)?(e="REFER",i+=5):(e=null,l('"REFER"')),e}function ct(){var e,n;return n=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=it())&&null===(e=st())&&null===(e=ot())&&null===(e=lt())&&null===(e=at())&&null===(e=ut())&&(e=O()),null!==e&&(e=function(e){return jn.method=t.substring(i,e),jn.method}(n)),null===e&&(i=n),e}function ht(){var e,t,n,r,s,o;return o=i,null!==(e=et())&&null!==(t=p())&&null!==(n=dt())&&null!==(r=p())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=u())&&null!==(t=u())&&null!==(n=u())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,n,r;for(r=i,e=[],null===(n=v())&&null===(n=y())&&null===(n=b())&&null===(n=R())&&null===(n=I())&&null===(n=p())&&(n=m());null!==n;)e.push(n),null===(n=v())&&null===(n=y())&&null===(n=b())&&null===(n=R())&&null===(n=I())&&null===(n=p())&&(n=m());return null!==e&&(e=function(e){jn.reason_phrase=t.substring(i,e)}(r)),null===e&&(i=r),e}function pt(){var e,t,n,r,s,o,l;if(s=i,o=i,null===(e=J())&&(e=mt()),null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=vt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=vt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function mt(){var e,t,n,r,s;return s=i,null!==(e=null!==(e=gt())?e:"")&&null!==(t=L())&&null!==(n=Q())&&null!==(r=q())?e=[e,t,n,r]:(e=null,i=s),e}function gt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=O())){for(t=[],l=i,null!==(n=S())&&null!==(r=O())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=S())&&null!==(r=O())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null===e&&(e=K()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function vt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,n,r,s,o,a;return s=i,o=i,"q"===t.substr(i,1).toLowerCase()?(e=t.substr(i,1),i++):(e=null,l('"q"')),null!==e&&null!==(n=U())&&null!==(r=St())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,n,r,s,o,a;return s=i,o=i,"expires"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"expires"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function bt(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function St(){var e,n,r,s,o,a,c,h;return a=i,c=i,48===t.charCodeAt(i)?(e="0",i++):(e=null,l('"0"')),null!==e?(h=i,46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null!==n&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")&&null!==(o=null!==(o=u())?o:"")?n=[n,r,s,o]:(n=null,i=h),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=c)):(e=null,i=c),null!==e&&(e=function(e){return parseFloat(t.substring(i,e))}(a)),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=O())?(o=i,null!==(t=U())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function Et(){var e;return null===(e=O())&&null===(e=le())&&(e=z()),e}function At(){var e;return"render"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"render"')),null===e&&("session"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"session"')),null===e&&("icon"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"icon"')),null===e&&("alert"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"alert"')),null===e&&(e=O())))),e}function wt(){var e;return null===(e=Rt())&&(e=Ct()),e}function Rt(){var e,n,r,s;return s=i,"handling"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"handling"')),null!==e&&null!==(n=U())?("optional"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"optional"')),null===r&&("required"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"required"')),null===r&&(r=O())),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),e}function It(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=x()))if(null!==(n=Ut())){for(r=[],a=i,null!==(s=F())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=F())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"text"')),null===e&&("image"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"image"')),null===e&&("audio"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"audio"')),null===e&&("video"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"video"')),null===e&&("application"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"application"')),null===e&&(e=Dt()))))),e}function kt(){var e;return"message"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"message"')),null===e&&("multipart"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"multipart"')),null===e&&(e=Dt())),e}function Dt(){var e;return null===(e=O())&&(e=xt()),e}function xt(){var e,n,r;return r=i,"x-"===t.substr(i,2).toLowerCase()?(e=t.substr(i,2),i+=2):(e=null,l('"x-"')),null!==e&&null!==(n=O())?e=[e,n]:(e=null,i=r),e}function Ut(){var e;return null===(e=Dt())&&(e=O()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=O())&&null!==(t=U())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=O())&&(e=z()),e}function qt(){var e,t,n,r;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(r=e,e=void(jn.value=parseInt(r.join("")))),null===e&&(i=n),e}function Lt(){var e,n,r,s,o,a;if(o=i,null!==(e=N())){for(n=[],a=i,46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r&&null!==(s=N())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r&&null!==(s=N())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function Ht(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,n,r,s,o,a;return s=i,o=i,"tag"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,n,r,s,o,a,u,c;if(u=i,"digest"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"Digest"')),null!==e)if(null!==(n=S()))if(null!==(r=Bt())){for(s=[],c=i,null!==(o=H())&&null!==(a=Bt())?o=[o,a]:(o=null,i=c);null!==o;)s.push(o),c=i,null!==(o=H())&&null!==(a=Bt())?o=[o,a]:(o=null,i=c);null!==s?e=[e,n,r,s]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;else e=null,i=u;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=O()))if(null!==(t=S()))if(null!==(n=$t())){for(r=[],a=i,null!==(s=H())&&null!==(o=$t())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=H())&&null!==(o=$t())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function $t(){var e,t,n,r;return r=i,null!==(e=O())&&null!==(t=U())?(null===(n=O())&&(n=z()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Bt(){var e;return null===(e=Wt())&&null===(e=zt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=$t()),e}function Wt(){var e,n,r,s;return s=i,"realm"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"realm"')),null!==e&&null!==(n=U())&&null!==(r=Vt())?e=[e,n,r]:(e=null,i=s),e}function Vt(){var e,t,n;return t=i,null!==(e=K())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function zt(){var e,n,r,s,o,a,u,c,h;if(c=i,"domain"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"domain"')),null!==e)if(null!==(n=U()))if(null!==(r=G()))if(null!==(s=Kt())){if(o=[],h=i,null!==(u=p()))for(a=[];null!==u;)a.push(u),u=p();else a=null;for(null!==a&&null!==(u=Kt())?a=[a,u]:(a=null,i=h);null!==a;){if(o.push(a),h=i,null!==(u=p()))for(a=[];null!==u;)a.push(u),u=p();else a=null;null!==a&&null!==(u=Kt())?a=[a,u]:(a=null,i=h)}null!==o&&null!==(a=$())?e=[e,n,r,s,o,a]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;else e=null,i=c;return e}function Kt(){var e;return null===(e=Le())&&(e=je()),e}function Yt(){var e,n,r,s;return s=i,"nonce"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"nonce"')),null!==e&&null!==(n=U())&&null!==(r=Xt())?e=[e,n,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=K())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){var e,n,r,s,o,a;return s=i,o=i,"opaque"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"opaque"')),null!==e&&null!==(n=U())&&null!==(r=K())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.opaque=a)),null===e&&(i=s),e}function Qt(){var e,n,r,s,o;return s=i,"stale"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"stale"')),null!==e&&null!==(n=U())?(o=i,"true"===t.substr(i,4).toLowerCase()?(r=t.substr(i,4),i+=4):(r=null,l('"true"')),null!==r&&(r=void(jn.stale=!0)),null===r&&(i=o),null===r&&(o=i,"false"===t.substr(i,5).toLowerCase()?(r=t.substr(i,5),i+=5):(r=null,l('"false"')),null!==r&&(r=void(jn.stale=!1)),null===r&&(i=o)),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),e}function Zt(){var e,n,r,s,o,a;return s=i,o=i,"algorithm"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"algorithm"')),null!==e&&null!==(n=U())?("md5"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"MD5"')),null===r&&("md5-sess"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"MD5-sess"')),null===r&&(r=O())),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,n,r,s,o,a,u,c,h,d;if(c=i,"qop"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"qop"')),null!==e)if(null!==(n=U()))if(null!==(r=G())){if(h=i,null!==(s=tn())){for(o=[],d=i,44===t.charCodeAt(i)?(a=",",i++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,i=d);null!==a;)o.push(a),d=i,44===t.charCodeAt(i)?(a=",",i++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,i=d);null!==o?s=[s,o]:(s=null,i=h)}else s=null,i=h;null!==s&&null!==(o=$())?e=[e,n,r,s,o]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;return e}function tn(){var e,n,r;return n=i,"auth-int"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"auth-int"')),null===e&&("auth"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"auth"')),null===e&&(e=O())),null!==e&&(r=e,jn.qop||(jn.qop=[]),e=void jn.qop.push(r.toLowerCase())),null===e&&(i=n),e}function nn(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=mt())){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,n,r,s,o,a,c;if(o=i,a=i,"cause"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"cause"')),null!==e)if(null!==(n=U())){if(null!==(s=u()))for(r=[];null!==s;)r.push(s),s=u();else r=null;null!==r?e=[e,n,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=o),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,n;return n=i,"active"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"active"')),null===e&&("pending"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"pending"')),null===e&&("terminated"===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"terminated"')),null===e&&(e=O()))),null!==e&&(e=function(e){jn.state=t.substring(i,e)}(n)),null===e&&(i=n),e}function an(){var e,n,r,s,o,a,u,c;return s=i,o=i,"reason"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"reason"')),null!==e&&null!==(n=U())&&null!==(r=un())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),null===e&&(i=s),null===e&&(s=i,o=i,"expires"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"expires"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(c=e[2])&&(jn.expires=c))),null===e&&(i=s),null===e&&(s=i,o=i,"retry_after"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"retry_after"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(u=e[2])&&(jn.retry_after=u))),null===e&&(i=s),null===e&&(e=Ct()))),e}function un(){var e;return"deactivated"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"deactivated"')),null===e&&("probation"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"probation"')),null===e&&("rejected"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"rejected"')),null===e&&("timeout"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"timeout"')),null===e&&("giveup"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"giveup"')),null===e&&("noresource"===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"noresource"')),null===e&&("invariant"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"invariant"')),null===e&&(e=O()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=S()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=F())&&null!==(o=dn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=F())&&null!==(o=dn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=gn())&&(e=Ct()),e}function fn(){var e,n,r,s,o,a;return s=i,o=i,"ttl"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"ttl"')),null!==e&&null!==(n=U())&&null!==(r=An())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,n,r,s,o,a;return s=i,o=i,"maddr"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"maddr"')),null!==e&&null!==(n=U())&&null!==(r=le())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,n,r,s,o,a;return s=i,o=i,"received"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"received"')),null!==e&&null!==(n=U())?(null===(r=pe())&&(r=de()),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,n,r,s,o,a;return s=i,o=i,"branch"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"branch"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.branch=a)),null===e&&(i=s),e}function gn(){var e,n,r,s,o;return s=i,"rport"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"rport"')),null!==e?(o=i,null!==(n=U())&&null!==(r=vn())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function vn(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=x())&&null!==(n=O())&&null!==(r=x())&&null!==(s=bn())?e=[e,t,n,r,s]:(e=null,i=o),e}function Tn(){var e,n,r;return n=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"')),null===e&&(e=O()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=n),e}function bn(){var e,n,r;return n=i,"udp"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"UDP"')),null===e&&("tcp"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"TCP"')),null===e&&("tls"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"TLS"')),null===e&&("sctp"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"SCTP"')),null===e&&(e=O())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=n),e}function Sn(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=j())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,n;return n=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(e=function(e){jn.host=t.substring(i,e)}(n)),null===e&&(i=n),e}function En(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=u())&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")?e=[e,t,n]:(e=null,i=s),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function wn(){var e,t,n;return t=i,null!==(e=bt())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function Rn(){var e;return null===(e=In())&&(e=Ct()),e}function In(){var e,n,r,s,o,a;return s=i,o=i,"refresher"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"refresher"')),null!==e&&null!==(n=U())?("uac"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"uac"')),null===r&&("uas"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"uas"'))),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=I())&&(t=S());null!==t;)e.push(t),null===(t=w())&&null===(t=I())&&(t=S());return e}function Nn(){var e,n,r,s,o,a,u,c,h,d,f;return d=i,f=i,null!==(e=Dn())?(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null!==n&&null!==(r=kn())?(45===t.charCodeAt(i)?(s="-",i++):(s=null,l('"-"')),null!==s&&null!==(o=kn())?(45===t.charCodeAt(i)?(a="-",i++):(a=null,l('"-"')),null!==a&&null!==(u=kn())?(45===t.charCodeAt(i)?(c="-",i++):(c=null,l('"-"')),null!==c&&null!==(h=xn())?e=[e,n,r,s,o,a,u,c,h]:(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){jn=t.substring(i+5,e)}(d,e[0])),null===e&&(i=d),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=h())&&null!==(t=h())&&null!==(n=h())&&null!==(r=h())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Un(){var e,n,r,s,o,a;return s=i,o=i,null!==(e=k())?(a=i,64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n&&null!==(r=k())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){jn.call_id=t.substring(i,e)}(s)),null===e&&(i=s),e}function Pn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Ct()),e}function Mn(){var e,n,r,s,o,a;return s=i,o=i,"to-tag"===t.substr(i,6)?(e="to-tag",i+=6):(e=null,l('"to-tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,n,r,s,o,a;return s=i,o=i,"from-tag"===t.substr(i,8)?(e="from-tag",i+=8):(e=null,l('"from-tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Ln(){var e,n;return n=i,"early-only"===t.substr(i,10)?(e="early-only",i+=10):(e=null,l('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=n),e}var Hn=V(),Fn=B(),jn={};if(null===r[n]()||i!==t.length){var Gn=Math.max(i,s),$n=Gn<t.length?t.charAt(Gn):null,Bn=function(){for(var e=1,n=1,r=!1,o=0;o<Math.max(i,s);o++){var l=t.charAt(o);"\n"===l?(r||e++,n=1,r=!1):"\r"===l||"\u2028"===l||"\u2029"===l?(e++,n=1,r=!0):(n++,r=!1)}return{line:e,column:n}}();return new this.SyntaxError(function(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}(o),$n,Gn,Bn.line,Bn.column),-1}return jn},toSource:function(){return this._source},SyntaxError:function(t,n,r,i,s){this.name="SyntaxError",this.expected=t,this.found=n,this.message=function(t,n){var r;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"Expected "+r+" but "+(n?e(n):"end of input")+" found."}(t,n),this.offset=r,this.line=i,this.column=s}};return t.SyntaxError.prototype=Error.prototype,t}()),L}function V(){if(j)return F;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(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 r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}j=1;var i=U(),s=z(),o=W();return F=function(){function t(e,n,r,s){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=e||i.SIP,this._user=n,this._host=r,this._port=s,o)Object.prototype.hasOwnProperty.call(o,a)&&this.setParam(a,o[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}return r(t,null,[{key:"parse",value:function(e){return-1!==(e=o.parse(e,"SIP_URI"))?e:void 0}}]),r(t,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?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())}},{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[s.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[s.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(s.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=s.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 t(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var t=[],n="".concat(this._scheme,":");for(var r in this._user&&(n+="".concat(s.escapeUser(this._user),"@")),n+=this._host,(this._port||0===this._port)&&(n+=":".concat(this._port)),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(n+=";".concat(r),null!==this._parameters[r]&&(n+="=".concat(this._parameters[r])));for(var i in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,i)){var o,l=e(this._headers[i]);try{for(l.s();!(o=l.n()).done;){var a=o.value;t.push("".concat(i,"=").concat(a))}}catch(e){l.e(e)}finally{l.f()}}return t.length>0&&(n+="?".concat(t.join("&"))),n}},{key:"toAor",value:function(e){var t="".concat(this._scheme,":");return this._user&&(t+="".concat(s.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(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=0===e?e:parseInt(e,10)||null}}]),t}(),F}function z(){if(G)return $;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}G=1;var r=U(),i=V(),s=W();$.str_utf8_length=function(e){return unescape(encodeURIComponent(e)).length};var o=$.isFunction=function(e){return void 0!==e&&"[object Function]"===Object.prototype.toString.call(e)};$.isString=function(e){return void 0!==e&&"[object String]"===Object.prototype.toString.call(e)},$.isDecimal=function(e){return!isNaN(e)&&parseFloat(e)===parseInt(e,10)},$.isEmpty=function(e){return null===e||""===e||void 0===e||Array.isArray(e)&&0===e.length||"number"==typeof e&&isNaN(e)},$.hasMethods=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var i=0,s=n;i<s.length;i++){var l=s[i];if(o(e[l]))return!1}return!0};var l=$.createRandomToken=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t<e;t++)r+=(Math.random()*n|0).toString(n);return r};$.newTag=function(){return l(10)},$.newUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},$.hostType=function(e){if(e)return-1!==(e=s.parse(e,"host"))?e.host_type:void 0};var a=$.escapeUser=function(e){return encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")};return $.normalizeTarget=function(e,t){if(e){if(e instanceof i)return e;if("string"==typeof e){var n,s,o,l=e.split("@");switch(l.length){case 1:if(!t)return;n=e,s=t;break;case 2:n=l[0],s=l[1];break;default:n=l.slice(0,l.length-1).join("@"),s=l[l.length-1]}return n=n.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(n)&&(n=n.replace(/[-.()]/g,"")),e="".concat(r.SIP,":").concat(a(n),"@").concat(s),(o=i.parse(e))?o:void 0}}else;},$.headerize=function(e){var t,n={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},r=e.toLowerCase().replace(/_/g,"-").split("-"),i="",s=r.length;for(t=0;t<s;t++)0!==t&&(i+="-"),i+=r[t].charAt(0).toUpperCase()+r[t].substring(1);return n[i]&&(i=n[i]),i},$.sipErrorCause=function(e){for(var t in r.SIP_ERROR_CAUSES)if(-1!==r.SIP_ERROR_CAUSES[t].indexOf(e))return r.causes[t];return r.causes.SIP_FAILURE_CODE},$.getRandomTestNetIP=function(){return"192.0.2.".concat((e=1,t=254,Math.floor(Math.random()*(t-e+1)+e)));var e,t},$.calculateMD5=function(e){function t(e,t){return e<<t|e>>>32-t}function n(e,t){var n=2147483648&e,r=2147483648&t,i=1073741824&e,s=1073741824&t,o=(1073741823&e)+(1073741823&t);return i&s?2147483648^o^n^r:i|s?1073741824&o?3221225472^o^n^r:1073741824^o^n^r:o^n^r}function r(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,i,s),o),a)),n(t(e,l),r)}function i(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,i,s),o),a)),n(t(e,l),r)}function s(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,i,s),o),a)),n(t(e,l),r)}function o(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,i,s),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,d,f,_,p,m,g;for(a=function(e){for(var t,n=e.length,r=n+8,i=16*((r-r%64)/64+1),s=new Array(i-1),o=0,l=0;l<n;)o=l%4*8,s[t=(l-l%4)/4]=s[t]|e.charCodeAt(l)<<o,l++;return o=l%4*8,s[t=(l-l%4)/4]=s[t]|128<<o,s[i-2]=n<<3,s[i-1]=n>>>29,s}(e=function(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(63&r|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(63&r|128))}return t}(e)),_=1732584193,p=4023233417,m=2562383102,g=271733878,u=0;u<a.length;u+=16)c=_,h=p,d=m,f=g,_=r(_,p,m,g,a[u+0],7,3614090360),g=r(g,_,p,m,a[u+1],12,3905402710),m=r(m,g,_,p,a[u+2],17,606105819),p=r(p,m,g,_,a[u+3],22,3250441966),_=r(_,p,m,g,a[u+4],7,4118548399),g=r(g,_,p,m,a[u+5],12,1200080426),m=r(m,g,_,p,a[u+6],17,2821735955),p=r(p,m,g,_,a[u+7],22,4249261313),_=r(_,p,m,g,a[u+8],7,1770035416),g=r(g,_,p,m,a[u+9],12,2336552879),m=r(m,g,_,p,a[u+10],17,4294925233),p=r(p,m,g,_,a[u+11],22,2304563134),_=r(_,p,m,g,a[u+12],7,1804603682),g=r(g,_,p,m,a[u+13],12,4254626195),m=r(m,g,_,p,a[u+14],17,2792965006),_=i(_,p=r(p,m,g,_,a[u+15],22,1236535329),m,g,a[u+1],5,4129170786),g=i(g,_,p,m,a[u+6],9,3225465664),m=i(m,g,_,p,a[u+11],14,643717713),p=i(p,m,g,_,a[u+0],20,3921069994),_=i(_,p,m,g,a[u+5],5,3593408605),g=i(g,_,p,m,a[u+10],9,38016083),m=i(m,g,_,p,a[u+15],14,3634488961),p=i(p,m,g,_,a[u+4],20,3889429448),_=i(_,p,m,g,a[u+9],5,568446438),g=i(g,_,p,m,a[u+14],9,3275163606),m=i(m,g,_,p,a[u+3],14,4107603335),p=i(p,m,g,_,a[u+8],20,1163531501),_=i(_,p,m,g,a[u+13],5,2850285829),g=i(g,_,p,m,a[u+2],9,4243563512),m=i(m,g,_,p,a[u+7],14,1735328473),_=s(_,p=i(p,m,g,_,a[u+12],20,2368359562),m,g,a[u+5],4,4294588738),g=s(g,_,p,m,a[u+8],11,2272392833),m=s(m,g,_,p,a[u+11],16,1839030562),p=s(p,m,g,_,a[u+14],23,4259657740),_=s(_,p,m,g,a[u+1],4,2763975236),g=s(g,_,p,m,a[u+4],11,1272893353),m=s(m,g,_,p,a[u+7],16,4139469664),p=s(p,m,g,_,a[u+10],23,3200236656),_=s(_,p,m,g,a[u+13],4,681279174),g=s(g,_,p,m,a[u+0],11,3936430074),m=s(m,g,_,p,a[u+3],16,3572445317),p=s(p,m,g,_,a[u+6],23,76029189),_=s(_,p,m,g,a[u+9],4,3654602809),g=s(g,_,p,m,a[u+12],11,3873151461),m=s(m,g,_,p,a[u+15],16,530742520),_=o(_,p=s(p,m,g,_,a[u+2],23,3299628645),m,g,a[u+0],6,4096336452),g=o(g,_,p,m,a[u+7],10,1126891415),m=o(m,g,_,p,a[u+14],15,2878612391),p=o(p,m,g,_,a[u+5],21,4237533241),_=o(_,p,m,g,a[u+12],6,1700485571),g=o(g,_,p,m,a[u+3],10,2399980690),m=o(m,g,_,p,a[u+10],15,4293915773),p=o(p,m,g,_,a[u+1],21,2240044497),_=o(_,p,m,g,a[u+8],6,1873313359),g=o(g,_,p,m,a[u+15],10,4264355552),m=o(m,g,_,p,a[u+6],15,2734768916),p=o(p,m,g,_,a[u+13],21,1309151649),_=o(_,p,m,g,a[u+4],6,4149444226),g=o(g,_,p,m,a[u+11],10,3174756917),m=o(m,g,_,p,a[u+2],15,718787259),p=o(p,m,g,_,a[u+9],21,3951481745),_=n(_,c),p=n(p,h),m=n(m,d),g=n(g,f);return(l(_)+l(p)+l(m)+l(g)).toLowerCase()},$.closeMediaStream=function(n){if(n)try{if(n.getTracks){var r,i=t(n.getTracks());try{for(i.s();!(r=i.n()).done;){r.value.stop()}}catch(e){i.e(e)}finally{i.f()}}else{var s,o=t(n.getAudioTracks());try{for(o.s();!(s=o.n()).done;){s.value.stop()}}catch(e){o.e(e)}finally{o.f()}var l,a=t(n.getVideoTracks());try{for(a.s();!(l=a.n()).done;){l.value.stop()}}catch(e){a.e(e)}finally{a.f()}}}catch(t){"function"!=typeof n.stop&&"object"!==e(n.stop)||n.stop()}},$.cloneArray=function(e){return e&&e.slice()||[]},$.cloneObject=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t},$}var K,Y,X,J,Q,Z,ee,te={exports:{}};function ne(){if(Y)return K;Y=1;var e=1e3,t=60*e,n=60*t,r=24*n,i=7*r,s=365.25*r;function o(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}return K=function(l,a){a=a||{};var u=typeof l;if("string"===u&&l.length>0)return function(o){if((o=String(o)).length>100)return;var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!l)return;var a=parseFloat(l[1]);switch((l[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*s;case"weeks":case"week":case"w":return a*i;case"days":case"day":case"d":return a*r;case"hours":case"hour":case"hrs":case"hr":case"h":return a*n;case"minutes":case"minute":case"mins":case"min":case"m":return a*t;case"seconds":case"second":case"secs":case"sec":case"s":return a*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(l);if("number"===u&&isFinite(l))return a.long?function(i){var s=Math.abs(i);if(s>=r)return o(i,s,r,"day");if(s>=n)return o(i,s,n,"hour");if(s>=t)return o(i,s,t,"minute");if(s>=e)return o(i,s,e,"second");return i+" ms"}(l):function(i){var s=Math.abs(i);if(s>=r)return Math.round(i/r)+"d";if(s>=n)return Math.round(i/n)+"h";if(s>=t)return Math.round(i/t)+"m";if(s>=e)return Math.round(i/e)+"s";return i+"ms"}(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))},K}function re(){return Q||(Q=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(J||(J=1,X=function(e){function t(e){let r,i,s,o=null;function l(...e){if(!l.enabled)return;const n=l,i=Number(new Date),s=i-(r||i);n.diff=s,n.prev=r,n.curr=i,r=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,i)=>{if("%%"===r)return"%";o++;const s=t.formatters[i];if("function"==typeof s){const t=e[o];r=s.call(n,t),e.splice(o,1),o--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return l.namespace=e,l.useColors=t.useColors(),l.color=t.selectColor(e),l.extend=n,l.destroy=t.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(i!==t.namespaces&&(i=t.namespaces,s=t.enabled(e)),s),set:e=>{o=e}}),"function"==typeof t.init&&t.init(l),l}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,i=-1,s=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(i=r,s=n,r++):(n++,r++);else{if(-1===i)return!1;r=i+1,s++,n=s}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=ne(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}),X)(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(te,te.exports)),te.exports}function ie(){if(ee)return Z;function e(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)}}ee=1;var t=re(),n="JsSIP";return Z=function(){function r(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),e?(this._debug=t.default("".concat(n,":").concat(e)),this._warn=t.default("".concat(n,":WARN:").concat(e)),this._error=t.default("".concat(n,":ERROR:").concat(e))):(this._debug=t.default(n),this._warn=t.default("".concat(n,":WARN")),this._error=t.default("".concat(n,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}var i,s,o;return i=r,(s=[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}])&&e(i.prototype,s),o&&e(i,o),r}()}var se,oe,le,ae,ue,ce,he,de,fe,_e,pe,me,ge,ve,ye,Te,be,Se,Ce,Ee,Ae,we={},Re={},Ie={exports:{}};function Oe(){if(se)return Ie.exports;se=1;var e=Ie.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(e){return e.encoding?"rtpmap:%d %s/%s/%s":e.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(e){return null!=e.address?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(e){return null!=e.subtype?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(e){return"extmap:%d"+(e.direction?"/%s":"%v")+(e["encrypt-uri"]?" %s":"%v")+" %s"+(e.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(e){return null!=e.sessionConfig?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(e){var t="candidate:%s %d %s %d %s %d typ %s";return t+=null!=e.raddr?" raddr %s rport %d":"%v%v",t+=null!=e.tcptype?" tcptype %s":"%v",null!=e.generation&&(t+=" generation %d"),t+=null!=e["network-id"]?" network-id %d":"%v",t+=null!=e["network-cost"]?" network-cost %d":"%v"}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(e){var t="ssrc:%d";return null!=e.attribute&&(t+=" %s",null!=e.value&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(e){return null!=e.maxMessageSize?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(e){return e.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(e){return"imageattr:%s %s %s"+(e.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(e){return"simulcast:%s %s"+(e.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(e){return"ts-refclk:%s"+(null!=e.clksrcExt?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(e){var t="mediaclk:";return t+=null!=e.id?"id=%s %s":"%v%s",t+=null!=e.mediaClockValue?"=%s":"",t+=null!=e.rateNumerator?" rate=%s":"",t+=null!=e.rateDenominator?"/%s":""}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};return Object.keys(e).forEach(function(t){e[t].forEach(function(e){e.reg||(e.reg=/(.*)/),e.format||(e.format="%s")})}),Ie.exports}function Ne(){return oe||(oe=1,function(e){var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,r){var i=e.name&&e.names;e.push&&!n[e.push]?n[e.push]=[]:i&&!n[e.name]&&(n[e.name]={});var s=e.push?{}:i?n[e.name]:n;!function(e,n,r,i){if(i&&!r)n[i]=t(e[1]);else for(var s=0;s<r.length;s+=1)null!=e[s+1]&&(n[r[s]]=t(e[s+1]))}(r.match(e.reg),s,e.names,e.name),e.push&&n[e.push].push(s)},r=Oe(),i=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},s=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(i).forEach(function(e){var t=e[0],i=e.slice(2);"m"===t&&(s.push({rtp:[],fmtp:[]}),o=s[s.length-1]);for(var l=0;l<(r[t]||[]).length;l+=1){var a=r[t][l];if(a.reg.test(i))return n(a,o,i)}}),t.media=s,t};var s=function(e,n){var r=n.split(/=(.+)/,2);return 2===r.length?e[r[0]]=t(r[1]):1===r.length&&n.length>1&&(e[r[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(s,{})},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(s,{})})},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):(n=t(e.substring(1,e.length)),r=!0),{scid:n,paused:r}})})}}(Re)),Re}function ke(){if(ae)return le;ae=1;var e=Oe(),t=/%[sdv%]/g,n=function(e){var n=1,r=arguments,i=r.length;return e.replace(t,function(e){if(n>=i)return e;var t=r[n];switch(n+=1,e){case"%%":return"%";case"%s":return String(t);case"%d":return Number(t);case"%v":return""}})},r=function(e,t,r){var i=[e+"="+(t.format instanceof Function?t.format(t.push?r:r[t.name]):t.format)];if(t.names)for(var s=0;s<t.names.length;s+=1){var o=t.names[s];t.name?i.push(r[t.name][o]):i.push(r[t.names[s]])}else i.push(r[t.name]);return n.apply(null,i)},i=["v","o","s","i","u","e","p","c","b","t","r","z","a"],s=["i","c","b","a"];return le=function(t,n){n=n||{},null==t.version&&(t.version=0),null==t.name&&(t.name=" "),t.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var o=n.outerOrder||i,l=n.innerOrder||s,a=[];return o.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(r(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(r(n,e,t))})})}),t.media.forEach(function(t){a.push(r("m",e.m[0],t)),l.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(r(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(r(n,e,t))})})})}),a.join("\r\n")+"\r\n"}}function De(){if(ue)return we;ue=1;var e=Ne(),t=ke(),n=Oe();return we.grammar=n,we.write=t,we.parse=e.parse,we.parseParams=e.parseParams,we.parseFmtpConfig=e.parseFmtpConfig,we.parsePayloads=e.parsePayloads,we.parseRemoteCandidates=e.parseRemoteCandidates,we.parseImageAttributes=e.parseImageAttributes,we.parseSimulcastStreamList=e.parseSimulcastStreamList,we}function xe(){if(he)return ce;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}function n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}(e))||t&&e&&"number"==typeof e.length){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 new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(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 u(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}he=1;var c=De(),h=ie(),d=U(),f=z(),_=B(),p=W(),m=new h("SIPMessage"),g=function(){function e(t,n,r,i,s,o){if(l(this,e),!t||!n||!r)return null;i=i||{},this.ua=r,this.headers={},this.method=t,this.ruri=n,this.body=o,this.extraHeaders=f.cloneArray(s),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","<".concat(r.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",d.MAX_FORWARDS);var a=i.to_uri||n,u=i.to_tag?{tag:i.to_tag}:null,c=void 0!==i.to_display_name?i.to_display_name:null;this.to=new _(a,c,u),this.setHeader("to",this.to.toString());var h,p=i.from_uri||r.configuration.uri,m={tag:i.from_tag||f.newTag()};h=void 0!==i.from_display_name?i.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new _(p,h,m),this.setHeader("from",this.from.toString());var g=i.call_id||r.configuration.jssip_id+f.createRandomToken(15);this.call_id=g,this.setHeader("call-id",g);var v=i.cseq||Math.floor(1e4*Math.random());this.cseq=v,this.setHeader("cseq","".concat(v," ").concat(t))}return u(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r<this.extraHeaders.length;r++)n.test(this.extraHeaders[r])&&this.extraHeaders.splice(r,1);this.headers[f.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){var t=this.headers[f.headerize(e)];if(t){if(t[0])return t[0]}else{var n,r=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),i=s(this.extraHeaders);try{for(i.s();!(n=i.n()).done;){var o=n.value;if(r.test(o))return o.substring(o.indexOf(":")+1).trim()}}catch(e){i.e(e)}finally{i.f()}}}},{key:"getHeaders",value:function(e){var t=this.headers[f.headerize(e)],n=[];if(t){var r,i=s(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;n.push(o)}}catch(e){i.e(e)}finally{i.f()}return n}var l,a=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),u=s(this.extraHeaders);try{for(u.s();!(l=u.n()).done;){var c=l.value;a.test(c)&&n.push(c.substring(c.indexOf(":")+1).trim())}}catch(e){u.e(e)}finally{u.f()}return n}},{key:"hasHeader",value:function(e){if(this.headers[f.headerize(e)])return!0;var t,n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=s(this.extraHeaders);try{for(r.s();!(t=r.n()).done;){var i=t.value;if(n.test(i))return!0}}catch(e){r.e(e)}finally{r.f()}return!1}},{key:"parseSDP",value:function(e){return!e&&this.sdp||(this.sdp=c.parse(this.body||"")),this.sdp}},{key:"toString",value:function(){var e="".concat(this.method," ").concat(this.ruri," SIP/2.0\r\n");for(var t in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,t)){var n,r=s(this.headers[t]);try{for(r.s();!(n=r.n()).done;){var i=n.value;e+="".concat(t,": ").concat(i,"\r\n")}}catch(e){r.e(e)}finally{r.f()}}var o,l=s(this.extraHeaders);try{for(l.s();!(o=l.n()).done;){var a=o.value;e+="".concat(a.trim(),"\r\n")}}catch(e){l.e(e)}finally{l.f()}var u=[];switch(this.method){case d.REGISTER:u.push("path","gruu");break;case d.INVITE:this.ua.configuration.session_timers&&u.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&u.push("gruu"),u.push("ice","replaces");break;case d.UPDATE:this.ua.configuration.session_timers&&u.push("timer"),u.push("ice")}u.push("outbound");var c=this.ua.configuration.user_agent||d.USER_AGENT;if(e+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"),e+="Supported: ".concat(u,"\r\n"),e+="User-Agent: ".concat(c,"\r\n"),this.body){var h=f.str_utf8_length(this.body);e+="Content-Length: ".concat(h,"\r\n\r\n"),e+=this.body}else e+="Content-Length: 0\r\n\r\n";return e}},{key:"clone",value:function(){var t=new e(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(e){t.headers[e]=this.headers[e].slice()},this),t.body=this.body,t.extraHeaders=f.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}]),e}(),v=function(e){t(i,e);var n=r(i);function i(e,t,r,s,o){var a;return l(this,i),(a=n.call(this,d.INVITE,e,t,r,s,o)).transaction=null,a}return u(i,[{key:"cancel",value:function(e){this.transaction.cancel(e)}},{key:"clone",value:function(){var e=new i(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=f.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e.transaction=this.transaction,e}}]),i}(g),y=function(){function e(){l(this,e),this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}return u(e,[{key:"addHeader",value:function(e,t){var n={raw:t};e=f.headerize(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[f.headerize(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[f.headerize(e)],n=[];if(!t)return[];var r,i=s(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;n.push(o.raw)}}catch(e){i.e(e)}finally{i.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[f.headerize(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=f.headerize(e),this.headers[e]){if(!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var i=p.parse(r,e.replace(/-/g,"_"));return-1===i?(this.headers[e].splice(t,1),void m.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=i,i)}m.debug('not so many "'.concat(e,'" headers present'))}else m.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[f.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp||(this.sdp=c.parse(this.body||"")),this.sdp}},{key:"toString",value:function(){return this.data}}]),e}(),T=function(e){t(i,e);var n=r(i);function i(e){var t;return l(this,i),(t=n.call(this)).ua=e,t.headers={},t.ruri=null,t.transport=null,t.server_transaction=null,t}return u(i,[{key:"reply",value:function(e,t,n,r,i,o){var l=[],a=this.getHeader("To");if(t=t||null,!(e=e||null)||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||d.REASON_PHRASE[e]||"",n=f.cloneArray(n),this.ua.configuration.extra_headers&&(n=n.concat(this.ua.configuration.extra_headers));var u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===d.INVITE&&e>100&&e<=200){var c,h=s(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var _=c.value;u+="Record-Route: ".concat(_,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var p,m=s(this.getHeaders("via"));try{for(m.s();!(p=m.n()).done;){var g=p.value;u+="Via: ".concat(g,"\r\n")}}catch(e){m.e(e)}finally{m.f()}!this.to_tag&&e>100?a+=";tag=".concat(f.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(a+=";tag=".concat(this.to_tag)),u+="To: ".concat(a,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var v,y=s(n);try{for(y.s();!(v=y.n()).done;){var T=v.value;u+="".concat(T.trim(),"\r\n")}}catch(e){y.e(e)}finally{y.f()}switch(this.method){case d.INVITE:this.ua.configuration.session_timers&&l.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&l.push("gruu"),l.push("ice","replaces");break;case d.UPDATE:this.ua.configuration.session_timers&&l.push("timer"),r&&l.push("ice"),l.push("replaces")}if(l.push("outbound"),this.method===d.OPTIONS?(u+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(d.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(d.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(l,"\r\n"),r){var b=f.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(b,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,i,o)}},{key:"reply_sl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||d.REASON_PHRASE[e]||"";var r,i="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),o=s(n);try{for(o.s();!(r=o.n()).done;){var l=r.value;i+="Via: ".concat(l,"\r\n")}}catch(e){o.e(e)}finally{o.f()}var a=this.getHeader("To");if(!this.to_tag&&e>100?a+=";tag=".concat(f.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(a+=";tag=".concat(this.to_tag)),i+="To: ".concat(a,"\r\n"),i+="From: ".concat(this.getHeader("From"),"\r\n"),i+="Call-ID: ".concat(this.call_id,"\r\n"),i+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),this.ua.configuration.extra_headers){var u,c=s(this.ua.configuration.extra_headers);try{for(c.s();!(u=c.n()).done;){var h=u.value;i+="".concat(h.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}i+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(i)}}]),i}(y);return ce={OutgoingRequest:g,InitialOutgoingInviteRequest:v,IncomingRequest:T,IncomingResponse:function(e){t(i,e);var n=r(i);function i(){var e;return l(this,i),(e=n.call(this)).headers={},e.status_code=null,e.reason_phrase=null,e}return i}(y)}}function Ue(){if(fe)return de;function e(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)}}fe=1;var t=ie(),n=z(),r=new t("DigestAuthentication");return de=function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._credentials=e,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}var i,s,o;return i=t,s=[{key:"get",value:function(e){switch(e){case"realm":return this._realm;case"ha1":return this._ha1;default:return void r.warn('get() | cannot get "%s" parameter',e)}}},{key:"authenticate",value:function(e,t){var i=e.method,s=e.ruri,o=e.body,l=arguments.length>2&&void 0!==arguments[2]?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("MD5"!==this._algorithm)return r.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return r.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return r.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return r.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return r.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))return r.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=i,this._uri=s,this._cnonce=l||n.createRandomToken(12),this._nc+=1;var a,u,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=n.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(a="".concat(this._method,":").concat(this._uri),u=n.calculateMD5(a),r.debug('authenticate() | using qop=auth [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(u))):"auth-int"===this._qop?(a="".concat(this._method,":").concat(this._uri,":").concat(n.calculateMD5(o||"")),u=n.calculateMD5(a),r.debug('authenticate() | using qop=auth-int [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(u))):null===this._qop&&(a="".concat(this._method,":").concat(this._uri),u=n.calculateMD5(a),r.debug('authenticate() | using qop=null [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(u))),r.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}],s&&e(i.prototype,s),o&&e(i,o),t}(),de}function Pe(){if(pe)return _e;pe=1;var e=500;return _e={T1:e,T2:4e3,T4:5e3,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4}}function Me(){if(ge)return me;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(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 r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new 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 o(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=u(t);if(n){var s=u(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return a(t)}(this,r)}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}ge=1;var c=l().EventEmitter,h=ie(),d=U(),f=xe(),_=Pe(),p=new h("NonInviteClientTransaction"),m=new h("InviteClientTransaction"),g=new h("AckClientTransaction"),v=new h("NonInviteServerTransaction"),y=new h("InviteServerTransaction"),T={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"};return me={C:T,NonInviteClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).type=T.NON_INVITE_CLIENT,l.id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.ua=e,l.transport=r,l.request=i,l.eventHandlers=o;var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l.ua.newTransaction(a(l)),l}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(T.STATUS_TRYING),this.F=setTimeout(function(){e.timer_F()},_.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){p.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){p.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(T.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 T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e)}else switch(this.state){case T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_COMPLETED),clearTimeout(this.F),408===n?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(function(){t.timer_K()},_.TIMER_K)}}},{key:"C",get:function(){return T}}]),s}(c),InviteClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).type=T.INVITE_CLIENT,l.id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.ua=e,l.transport=r,l.request=i,l.eventHandlers=o,i.transaction=a(l);var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l.ua.newTransaction(a(l)),l}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(T.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!==T.STATUS_ACCEPTED&&(m.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){m.debug("Timer M expired for transaction ".concat(this.id)),this.state===T.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){m.debug("Timer B expired for transaction ".concat(this.id)),this.state===T.STATUS_CALLING&&(this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){m.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(e){var t=this,n=new f.OutgoingRequest(d.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===T.STATUS_PROCEEDING){var t=new f.OutgoingRequest(d.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 T.STATUS_CALLING:this.stateChanged(T.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case T.STATUS_CALLING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},_.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case T.STATUS_CALLING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return T}}]),s}(c),AckClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.transport=r,l.request=i,l.eventHandlers=o;var a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return r(s,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){g.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return T}}]),s}(c),NonInviteServerTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i){var o;return t(this,s),(o=n.call(this)).type=T.NON_INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=a(o),o.state=T.STATUS_TRYING,e.newTransaction(a(o)),o}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_J",value:function(){v.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,v.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var i=this;if(100===e)switch(this.state){case T.STATUS_TRYING:this.stateChanged(T.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case T.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 T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.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())}}},{key:"C",get:function(){return T}}]),s}(c),InviteServerTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i){var o;return t(this,s),(o=n.call(this)).type=T.INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=a(o),o.state=T.STATUS_PROCEEDING,e.newTransaction(a(o)),o.resendProvisionalTimer=null,i.reply(100),o}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){y.debug("Timer H expired for transaction ".concat(this.id)),this.state===T.STATUS_COMPLETED&&y.debug("ACK not received, dialog will be terminated"),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){y.debug("Timer L expired for transaction ".concat(this.id)),this.state===T.STATUS_ACCEPTED&&(this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,y.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(T.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&&this.state===T.STATUS_PROCEEDING)this.transport.send(t)||this.onTransportError(),this.last_response=t;if(e>100&&e<=199&&this.state===T.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){i.resend_provisional()},_.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){i.timer_L()},_.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case T.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699&&this.state===T.STATUS_PROCEEDING)null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(T.STATUS_COMPLETED),this.H=setTimeout(function(){i.timer_H()},_.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}},{key:"C",get:function(){return T}}]),s}(c),checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case d.INVITE:if(n=r.ist[t.via_branch]){if(n.state===T.STATUS_PROCEEDING)n.transport.send(n.last_response);return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===T.STATUS_ACCEPTED)return!1;if(n.state===T.STATUS_COMPLETED)return n.state=T.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},_.TIMER_I),!0;break;case d.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==T.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case T.STATUS_TRYING:break;case T.STATUS_PROCEEDING:case T.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}}function qe(){if(ye)return ve;function e(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)}}ye=1;var t=ie(),n=U(),r=Ue(),i=Me(),s=new t("RequestSender"),o={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}};return ve=function(){function t(e,r,i){for(var s in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._ua=e,this._eventHandlers=i,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1,o)Object.prototype.hasOwnProperty.call(o,s)&&(this._eventHandlers[s]||(this._eventHandlers[s]=o[s]));e.status!==e.C.STATUS_USER_CLOSED||this._method===n.BYE&&this._method===n.ACK||this._eventHandlers.onTransportError()}var l,a,u;return l=t,(a=[{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 i.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new i.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new i.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,i=e.status_code;if(401!==i&&407!==i||null===this._ua.configuration.password&&null===this._ua.configuration.ha1)this._eventHandlers.onReceiveResponse(e);else{if(401===e.status_code?(t=e.parseHeader("www-authenticate"),n="authorization"):(t=e.parseHeader("proxy-authenticate"),n="proxy-authorization"),!t)return s.debug("".concat(e.status_code," with wrong or missing challenge, cannot authenticate")),void this._eventHandlers.onReceiveResponse(e);if(!this._challenged||!this._staled&&!0===t.stale){if(this._auth||(this._auth=new r({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),t.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(n,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}}}])&&e(l.prototype,a),u&&e(l,u),t}()}function Le(){if(be)return Te;function e(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)}}be=1;var t=ie(),n=z(),r=U(),i=xe(),s=qe(),o=new t("Registrator");return Te=function(){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._reg_id=1,this._ua=e,this._transport=r,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=n.createRandomToken(22),this._cseq=0,this._to_uri=e.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var l,a,u;return l=t,a=[{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+=";".concat(t),n&&(this._extraContactParams+="=".concat(n))}}},{key:"register",value:function(){var e=this;if(this._registering)o.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var l=new i.OutgoingRequest(r.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new s(this._ua,l,{onRequestTimeout:function(){e._registrationFailure(null,r.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,r.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(null!==e._registrationTimer&&(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")){o.debug("no Contact header in response to REGISTER, response ignored");break}var i=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),s=i.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(s||(s=i.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!s){o.debug("no Contact header pointing to us, response ignored");break}var l=s.getParam("expires");!l&&t.hasHeader("expires")&&(l=t.getHeader("expires")),l||(l=e._expires),(l=Number(l))<10&&(l=10);var a=l>64?1e3*l/2+Math.floor(1e3*(l/2-32)*Math.random()):1e3*l-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},a),s.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=s.getParam("temp-gruu").replace(/"/g,"")),s.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=s.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<10&&(e._expires=10),e.register()):(o.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,r.causes.SIP_FAILURE_CODE));break;default:var u=n.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});this._registering=!0,a.send()}}},{key:"unregister",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this._registered){this._registered=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var l=this._extraHeaders.slice();t.all?l.push("Contact: *".concat(this._extraContactParams)):l.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),l.push("Expires: 0");var a=new i.OutgoingRequest(r.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l);new s(this._ua,a,{onRequestTimeout:function(){e._unregistered(null,r.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,r.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 r=n.sipErrorCause(t.status_code);e._unregistered(t,r)}}}).send()}else o.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(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}}],a&&e(l.prototype,a),u&&e(l,u),t}(),Te}function He(){if(Ce)return Se;function e(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)}}Ce=1;var t=U(),n=Me(),r=qe(),i={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}};return Se=function(){function s(e,t,n){for(var r in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),this._dialog=e,this._ua=e._ua,this._request=t,this._eventHandlers=n,this._reattempt=!1,this._reattemptTimer=null,i)Object.prototype.hasOwnProperty.call(i,r)&&(this._eventHandlers[r]||(this._eventHandlers[r]=i[r]))}var o,l,a;return o=s,(l=[{key:"send",value:function(){var e=this,i=new r(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)}});i.send(),(this._request.method===t.INVITE||this._request.method===t.UPDATE&&this._request.body)&&i.clientTransaction.state!==n.C.STATUS_TERMINATED&&(this._dialog.uac_pending_reply=!0,i.clientTransaction.on("stateChanged",function t(){i.clientTransaction.state!==n.C.STATUS_ACCEPTED&&i.clientTransaction.state!==n.C.STATUS_COMPLETED&&i.clientTransaction.state!==n.C.STATUS_TERMINATED||(i.clientTransaction.removeListener("stateChanged",t),e._dialog.uac_pending_reply=!1)}))}},{key:"_receiveResponse",value:function(e){var n=this;408===e.status_code||481===e.status_code?this._eventHandlers.onDialogError(e):e.method===t.INVITE&&491===e.status_code?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(){n._dialog.isTerminated()||(n._reattempt=!0,n.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(o.prototype,l),a&&e(o,a),s}()}function Fe(){if(Ae)return Ee;function e(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 t(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}Ae=1;var n=ie(),r=xe(),i=U(),s=Me(),o=He(),l=z(),a=new n("Dialog"),u={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};return Ee=function(){function e(t,n,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:u.STATUS_CONFIRMED;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof r.IncomingResponse&&(s=n.status_code<200?u.STATUS_EARLY:u.STATUS_CONFIRMED);var o=n.parseHeader("contact");"UAS"===i?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):"UAC"===i&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a.debug("new ".concat(i," dialog created with status ").concat(this._state===u.STATUS_EARLY?"EARLY":"CONFIRMED"))}return t(e,null,[{key:"C",get:function(){return u}}]),t(e,[{key:"isTerminated",value:function(){return this._status===u.STATUS_TERMINATED}},{key:"update",value:function(e,t){this._state=u.STATUS_CONFIRMED,a.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=u.STATUS_TERMINATED}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=l.cloneArray(n.extraHeaders),i=l.cloneObject(n.eventHandlers),s=n.body||null,a=this._createRequest(e,r,s);return i.onAuthenticated=function(){t._local_seqnum+=1},new o(this,a,i).send(),a}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=l.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var s=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new r.OutgoingRequest(e,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseq<this._remote_seqnum){if(e.method!==i.ACK)return e.reply(500),!1;if(null===this._ack_seqnum||e.cseq!==this._ack_seqnum)return!1}else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==s.C.STATUS_ACCEPTED&&e.server_transaction.state!==s.C.STATUS_COMPLETED&&e.server_transaction.state!==s.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",n),t._uas_pending_reply=!1)})}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===s.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===s.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}(),Ee}var je,Ge,$e,Be,We,Ve,ze,Ke,Ye,Xe,Je,Qe,Ze,et={exports:{}};function tt(){if(je)return et.exports;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}je=1;var s=l().EventEmitter,o=ie(),a=U(),u=P(),c=z(),h=new o("RTCSession:DTMF"),d={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};return et.exports=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(f,e);var i,s,o,l=r(f);function f(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,f),(t=l.call(this))._session=e,t._direction=null,t._tone=null,t._duration=null,t._request=null,t}return i=f,s=[{key:"send",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===e)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new u.InvalidStateError(this._session.status);var r=c.cloneArray(n.extraHeaders);if(this.eventHandlers=c.cloneObject(n.eventHandlers),"string"==typeof e)e=e.toUpperCase();else{if("number"!=typeof e)throw new TypeError("Invalid tone: ".concat(e));e=e.toString()}if(!e.match(/^[0-9A-DR#*]$/))throw new TypeError("Invalid tone: ".concat(e));this._tone=e,this._duration=n.duration,r.push("Content-Type: application/dtmf-relay");var i="Signal=".concat(this._tone,"\r\n");i+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(a.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("\n");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||(this._duration=d.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):h.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}],s&&t(i.prototype,s),o&&t(i,o),f}(s),et.exports.C=d,et.exports}function nt(){if($e)return Ge;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}$e=1;var s=l().EventEmitter,o=U(),a=P(),u=z();return Ge=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(h,e);var i,s,l,c=r(h);function h(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),(t=c.call(this))._session=e,t._direction=null,t._contentType=null,t._body=null,t}return i=h,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new a.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var i=u.cloneArray(r.extraHeaders);i.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(o.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}}],s&&t(i.prototype,s),l&&t(i,l),h}(s),Ge}function rt(){if(We)return Be;function e(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)}}We=1;var t=ie(),n=U(),r=new t("RTCSession:ReferNotifier"),i="refer",s="message/sipfrag;version=2.0",o=300;return Be=function(){function t(e,n,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._session=e,this._id=n,this._expires=r||o,this._active=!0,this.notify(100)}var l,a,u;return l=t,(a=[{key:"notify",value:function(e,t){var o;r.debug("notify()"),!1!==this._active&&(t=t||n.REASON_PHRASE[e]||"",o=e>=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(n.NOTIFY,{extraHeaders:["Event: ".concat(i,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(s)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&e(l.prototype,a),u&&e(l,u),t}()}function it(){if(ze)return Ve;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}ze=1;var s=l().EventEmitter,o=ie(),a=U(),u=W(),c=z(),h=new o("RTCSession:ReferSubscriber");return Ve=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(d,e);var i,s,o,l=r(d);function d(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,d),(t=l.call(this))._id=null,t._session=e,t}return i=d,s=[{key:"sendRefer",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};h.debug("sendRefer()");var r=c.cloneArray(n.extraHeaders),i=c.cloneObject(n.eventHandlers);for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&this.on(s,i[s]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=";to-tag=".concat(n.replaces._to_tag),o+=";from-tag=".concat(n.replaces._from_tag),o=encodeURIComponent(o));var l="Refer-To: <".concat(e).concat(o?"?Replaces=".concat(o):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var d=this._session.sendRequest(a.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,a.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,a.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,a.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,a.causes.DIALOG_ERROR)}}});this._id=d.cseq}},{key:"receiveNotify",value:function(e){if(h.debug("receiveNotify()"),e.body){var t=u.parse(e.body.trim().split("\r\n",1)[0],"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else h.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){h.debug("REFER succeeded"),h.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){h.debug("REFER failed"),h.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}},{key:"id",get:function(){return this._id}}],s&&t(i.prototype,s),o&&t(i,o),d}(s),Ve}function st(){if(Ye)return Ke;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}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}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function o(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=a(t);if(n){var s=a(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}Ye=1;var u=l().EventEmitter,c=De(),h=ie(),d=U(),f=P(),_=Me(),p=z(),m=Pe(),g=xe(),v=Fe(),y=qe(),T=tt(),b=nt(),S=rt(),C=it(),E=V(),A=new h("RTCSession"),w={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},R=["audio","video"];return Ke=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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)}(r,e);var n=o(r);function r(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),A.debug("new"),(t=n.call(this))._id=null,t._ua=e,t._status=w.STATUS_NULL,t._dialog=null,t._earlyDialogs={},t._contact=null,t._from_tag=null,t._to_tag=null,t._connection=null,t._connectionPromiseQueue=Promise.resolve(),t._request=null,t._is_canceled=!1,t._cancel_reason="",t._is_confirmed=!1,t._late_sdp=!1,t._rtcOfferConstraints=null,t._rtcAnswerConstraints=null,t._localMediaStream=null,t._localMediaStreamLocallyGenerated=!1,t._rtcReady=!0,t._iceReady=!1,t._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},t._direction=null,t._local_identity=null,t._remote_identity=null,t._start_time=null,t._end_time=null,t._tones=null,t._audioMuted=!1,t._videoMuted=!1,t._localHold=!1,t._remoteHold=!1,t._sessionTimers={enabled:t._ua.configuration.session_timers,refreshMethod:t._ua.configuration.session_timers_refresh_method,defaultExpires:d.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},t._referSubscribers={},t._data={},t}return i(r,null,[{key:"C",get:function(){return w}}]),i(r,[{key:"isInProgress",value:function(){switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:case w.STATUS_INVITE_RECEIVED:case w.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case w.STATUS_ANSWERED:case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case w.STATUS_CANCELED:case w.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&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A.debug("connect()");var r=e,i=p.cloneObject(t.eventHandlers),s=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new f.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new f.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),i)Object.prototype.hasOwnProperty.call(i,h)&&this.on(h,i[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new E("sip","anonymous","anonymous.invalid"),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),s.push("Privacy: id")):t.fromUserName&&(m.from_uri=new E("sip",t.fromUserName,this._ua.configuration.uri.host),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),s.push("Contact: ".concat(this._contact)),s.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&s.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new g.InitialOutgoingInviteRequest(e,this._ua,m,s),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),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,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A.debug("init_incoming()");var i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==i?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,d.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,d.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("answer()");var r=this._request,i=p.cloneArray(n.extraHeaders),s=p.cloneObject(n.mediaConstraints),o=n.mediaStream||null,l=p.cloneObject(n.pcConfig,{iceServers:[]}),a=n.rtcConstraints||null,u=n.rtcAnswerConstraints||null,c=p.cloneObject(n.rtcOfferConstraints),h=!1,_=!1,m=!1,g=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=n.rtcOfferConstraints||null,this._data=n.data||this._data,"incoming"!==this._direction)throw new f.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new f.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),this._status=w.STATUS_ANSWERED,this._createDialog(r,"UAS")){clearTimeout(this._timers.userNoAnswerTimer),i.unshift("Contact: ".concat(this._contact));var v=r.parseSDP();Array.isArray(v.media)||(v.media=[v.media]);var y,T=t(v.media);try{for(T.s();!(y=T.n()).done;){var b=y.value;"audio"===b.type&&(h=!0,b.direction&&"sendrecv"!==b.direction||(m=!0)),"video"===b.type&&(_=!0,b.direction&&"sendrecv"!==b.direction||(g=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===s.audio){var S,C=t(o.getAudioTracks());try{for(C.s();!(S=C.n()).done;){var E=S.value;o.removeTrack(E)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===s.video){var R,I=t(o.getVideoTracks());try{for(I.s();!(R=I.n()).done;){var O=R.value;o.removeTrack(O)}}catch(e){I.e(e)}finally{I.f()}}o||void 0!==s.audio||(s.audio=m),o||void 0!==s.video||(s.video=g),o||h||c.offerToReceiveAudio||(s.audio=!1),o||_||c.offerToReceiveVideo||(s.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(s.audio||s.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r.reply(480),e._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),A.warn('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new 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:r.body};A.debug('emit "sdp"'),e.emit("sdp",t);var n=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(n)}).catch(function(t){throw r.reply(488),e._failed("system",null,d.causes.WEBRTC_ERROR),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(r),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(r,i),r.reply(200,null,i,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(r,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,d.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&A.warn(t)})}else r.reply(500,"Error creating dialog")}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("terminate()");var n,r=t.cause||d.causes.BYE,i=p.cloneArray(t.extraHeaders),s=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new f.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||d.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,d.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A.debug("rejecting session"),(o=o||480)<300||o>=700)throw new TypeError("Invalid status_code: ".concat(o));this._request.reply(o,l,i,s),this._failed("local",null,d.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A.debug("terminating session"),l=t.reason_phrase||d.REASON_PHRASE[o]||"",o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));if(o&&i.push("Reason: SIP ;cause=".concat(o,'; text="').concat(l,'"')),this._status===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===d.ACK&&(e.sendRequest(d.BYE,{extraHeaders:i,body:s}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(d.BYE,{extraHeaders:i,body:s}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(d.BYE,{extraHeaders:i,body:s}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};A.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,i=t.interToneGap||null,s=t.transportType||d.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_1XX_RECEIVED)throw new f.InvalidStateError(this._status);if(s!==d.DTMF_TRANSPORT.INFO&&s!==d.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(s));if("number"==typeof e&&(e=e.toString()),!e||"string"!=typeof e||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(e));if(r&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?r<T.C.MIN_DURATION?(A.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(T.C.MIN_DURATION," milliseconds")),r=T.C.MIN_DURATION):r>T.C.MAX_DURATION?(A.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,i&&!p.isDecimal(i))throw new TypeError("Invalid interToneGap: ".concat(i));if(i?i<T.C.MIN_INTER_TONE_GAP?(A.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(T.C.MIN_INTER_TONE_GAP," milliseconds")),i=T.C.MIN_INTER_TONE_GAP):i=Math.abs(i):i=T.C.DEFAULT_INTER_TONE_GAP,s!==d.DTMF_TRANSPORT.RFC2833)this._tones?this._tones+=e:(this._tones=e,function e(){var s,o=this;if(this._status===w.STATUS_TERMINATED||!this._tones||n>=this._tones.length)return void(this._tones=null);var l=this._tones[n];if(n+=1,","===l)s=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){o._tones=null}},a.send(l,t),s=r+i}setTimeout(e.bind(this),s)}.call(this));else{var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,i))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(A.debug("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_1XX_RECEIVED)throw new f.InvalidStateError(this._status);new b(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A.debug("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A.debug("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A.debug("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var i={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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;A.debug("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var i=new C(this);i.sendRefer(e,t);var s=i.id;return this._referSubscribers[s]=i,i.on("requestFailed",function(){delete n._referSubscribers[s]}),i.on("accepted",function(){delete n._referSubscribers[s]}),i.on("failed",function(){delete n._referSubscribers[s]}),i}},{key:"sendRequest",value:function(e,t){return A.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A.debug("receiveRequest()"),e.method===d.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,d.causes.CANCELED));else switch(e.method){case d.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:d.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A.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:d.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case d.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,d.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,d.causes.BYE)):e.reply(403,"Wrong Status");break;case d.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case d.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==i?new b(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case d.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case d.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case d.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){A.warn("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.CONNECTION_ERROR,cause:d.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){A.warn("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:d.causes.REQUEST_TIMEOUT,cause:d.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){A.warn("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.DIALOG_ERROR,cause:d.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A.debug("_isReadyToReOffer() | session not established yet"),!1):(A.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A.debug("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){A.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=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),n<m.T2&&(n*=2)>m.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(d.BYE),e._ended("remote",null,d.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})}),A.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return A.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return A.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,A.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var i=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!i||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var s={originator:"local",type:e,sdp:r.localDescription.sdp};return A.debug('emit "sdp"'),n.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(function(t){var i,s,o=!1;n._iceReady=!1;var l=function(){if(!o){r.removeEventListener("icecandidate",i),r.removeEventListener("icegatheringstatechange",s),o=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};A.debug('emit "sdp"'),n.emit("sdp",l),t(l.sdp)}};r.addEventListener("icecandidate",i=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):l()}),r.addEventListener("icegatheringstatechange",s=function(){"complete"===r.iceGatheringState&&l()})})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,i="UAS"===t?e.from_tag:e.to_tag,s=e.call_id+r+i,o=this._earlyDialogs[s];if(n)return!!o||((o=new v(this,e,t,v.C.STATUS_EARLY)).error?(A.debug(o.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[s]=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[s],!0;var l=new v(this,e,t);return l.error?(A.debug(l.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",s=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,s)}.bind(this)},i=!1;if(this.emit("reinvite",r),!i){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){s.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return A.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&s.call(t,e)}).catch(function(e){A.warn(e)})}function s(t){var n=this,i=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,i),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,i,t,function(){n._status=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",s=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,s)}.bind(this)},i=!1;if(this.emit("update",r),!i)if(e.body){if("application/sdp"!==n)return A.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&s.call(t,e)}).catch(function(e){A.warn(e)})}else s.call(this,null);function s(t){var n=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),"function"==typeof r.callback&&r.callback()}}},{key:"_processInDialogSdpOffer",value:function(e){var n=this;A.debug("_processInDialogSdpOffer()");var r,i=e.parseSDP(),s=!1,o=t(i.media);try{for(o.s();!(r=o.n()).done;){var l=r.value;if(-1!==R.indexOf(l.type)){var a=l.direction||i.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){s=!1;break}s=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A.debug('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");return n._connection.setRemoteDescription(c).catch(function(t){throw e.reply(488),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),n.emit("peerconnection:setremotedescriptionfailed",t),t})}).then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");!0===n._remoteHold&&!1===s?(n._remoteHold=!1,n._onunhold("remote")):!1===n._remoteHold&&!0===s&&(n._remoteHold=!0,n._onhold("remote"))}).then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");return n._createLocalDescription("answer",n._rtcAnswerConstraints).catch(function(t){throw e.reply(500),A.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){A.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A.debug("receiveRefer()"),!e.refer_to)return A.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==d.SIP)return A.debug("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);function i(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new r(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var o=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));i.extraHeaders=p.cloneArray(i.extraHeaders),i.extraHeaders.push("Replaces: ".concat(o))}s.connect(e.refer_to.uri.toAor(),i,t)}function s(){n.notify(603)}A.debug('emit "refer"'),this.emit("refer",{request:e,accept:function(e,n){i.call(t,e,n)},reject:function(){s.call(t)}})}},{key:"_receiveNotify",value:function(e){if(A.debug("receiveNotify()"),e.event||e.reply(400),"refer"===e.event.event){var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200)}else e.reply(489)}},{key:"_receiveReplaces",value:function(e){var t=this;function n(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var i=new r(this._ua);i.on("confirmed",function(){n.terminate()}),i.init_incoming(e,t)}function i(){A.debug("Replaced INVITE rejected by the user"),e.reply(486)}A.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(e){n.call(t,e)},reject:function(){i.call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,i=new y(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(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),A.warn('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new 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,d.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),i.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&A.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;A.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(d.ACK);var n=new v(this,e,"UAC");return void 0!==n.error?void A.debug(n.error):(this.sendRequest(d.ACK),void this.sendRequest(d.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A.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){A.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=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,d.causes.MISSING_SDP),this._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var s={originator:"remote",type:"answer",sdp:e.body};A.debug('emit "sdp"'),this.emit("sdp",s);var o=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if("stable"===t._connection.signalingState)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,d.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(d.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=!1;function o(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&(this.sendRequest(d.ACK),!s))if(this._handleSessionTimersInIncomingResponse(e),e.body)if(e.hasHeader("Content-Type")&&"application/sdp"===e.getHeader("Content-Type").toLowerCase()){var n={originator:"remote",type:"answer",sdp:e.body};A.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){l.call(t),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else l.call(this);else l.call(this)}function l(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};A.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(d.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){o.call(e,t),s=!0},onErrorResponse:function(t){l.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){l()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),s){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A.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){a.call(t),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};A.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(d.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(d.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A.debug("acceptAndTerminate()");var r=[];t&&(n=n||d.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(d.ACK),this.sendRequest(d.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=c.parse(e),this._localHold&&!this._remoteHold){A.debug("mangleOffer() | me on hold, mangling offer");var n,r=t(e.media);try{for(r.s();!(n=r.n()).done;){var i=n.value;-1!==R.indexOf(i.type)&&(i.direction?"sendrecv"===i.direction?i.direction="sendonly":"recvonly"===i.direction&&(i.direction="inactive"):i.direction="sendonly")}}catch(e){r.e(e)}finally{r.f()}}else if(this._localHold&&this._remoteHold){A.debug("mangleOffer() | both on hold, mangling offer");var s,o=t(e.media);try{for(o.s();!(s=o.n()).done;){var l=s.value;-1!==R.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A.debug("mangleOffer() | remote on hold, mangling offer");var a,u=t(e.media);try{for(u.s();!(a=u.n()).done;){var h=a.value;-1!==R.indexOf(h.type)&&(h.direction?"sendrecv"===h.direction?h.direction="recvonly":"recvonly"===h.direction&&(h.direction="inactive"):h.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return c.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){var n;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.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: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(n)),this._sessionTimers.refresher="uas"===n,this._runSessionTimer())}},{key:"_handleSessionTimersInIncomingResponse",value:function(e){var t;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{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!==w.STATUS_TERMINATED&&e._isReadyToReOffer()&&(A.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===d.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:d.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},1100*t)}},{key:"_toggleMuteAudio",value:function(e){var n,r=this._connection.getSenders().filter(function(e){return e.track&&"audio"===e.track.kind}),i=t(r);try{for(i.s();!(n=i.n()).done;){n.value.track.enabled=!e}}catch(e){i.e(e)}finally{i.f()}}},{key:"_toggleMuteVideo",value:function(e){var n,r=this._connection.getSenders().filter(function(e){return e.track&&"video"===e.track.kind}),i=t(r);try{for(i.s();!(n=i.n()).done;){n.value.track.enabled=!e}}catch(e){i.e(e)}finally{i.f()}}},{key:"_newRTCSession",value:function(e,t){A.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A.debug("session connecting"),A.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A.debug("session progress"),A.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A.debug("session accepted"),this._start_time=new Date,A.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A.debug("session confirmed"),this._is_confirmed=!0,A.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A.debug("session ended"),this._end_time=new Date,this._close(),A.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A.debug("session failed"),A.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A.debug("session onhold"),this._setLocalMediaStatus(),A.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A.debug("session onunhold"),this._setLocalMediaStatus(),A.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A.debug("session onmute"),this._setLocalMediaStatus(),A.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A.debug("session onunmute"),this._setLocalMediaStatus(),A.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return w}},{key:"causes",get:function(){return d.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}}]),r}(u),Ke}function ot(){if(Je)return Xe;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}Je=1;var s=l().EventEmitter,o=ie(),a=U(),u=xe(),c=z(),h=qe(),d=P(),f=V(),_=new o("Message");return Xe=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(p,e);var i,s,o,l=r(p);function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),(t=l.call(this))._ua=e,t._request=null,t._closed=!1,t._direction=null,t._local_identity=null,t._remote_identity=null,t._is_replied=!1,t._data={},t}return i=p,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var s=c.cloneArray(r.extraHeaders),o=c.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",d={};for(var _ in r.fromUserName&&(d.from_uri=new f("sip",r.fromUserName,this._ua.configuration.uri.host),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),r.fromDisplayName&&(d.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,_)&&this.on(_,o[_]);s.push("Content-Type: ".concat(l)),this._request=new u.OutgoingRequest(a.MESSAGE,e,this._ua,d,s),t&&(this._request.body=t);var p=new h(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),p.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&&void 0!==arguments[0]?arguments[0]:{},t=c.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=c.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(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=c.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,a.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,a.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){_.debug("MESSAGE failed"),this._close(),_.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){_.debug("MESSAGE succeeded"),this._close(),_.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}}],s&&t(i.prototype,s),o&&t(i,o),p}(s),Xe}function lt(){if(Ze)return Qe;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}Ze=1;var s=l().EventEmitter,o=ie(),a=U(),u=xe(),c=z(),h=qe(),d=P(),f=new o("Options");return Qe=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(_,e);var i,s,o,l=r(_);function _(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,_),(t=l.call(this))._ua=e,t._request=null,t._closed=!1,t._direction=null,t._local_identity=null,t._remote_identity=null,t._is_replied=!1,t._data={},t}return i=_,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var s=c.cloneArray(r.extraHeaders),o=c.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";for(var d in o)Object.prototype.hasOwnProperty.call(o,d)&&this.on(d,o[d]);s.push("Content-Type: ".concat(l)),this._request=new u.OutgoingRequest(a.OPTIONS,e,this._ua,null,s),t&&(this._request.body=t);var f=new h(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions("local",this._request),f.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&&void 0!==arguments[0]?arguments[0]:{},t=c.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=c.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(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=c.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,a.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,a.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){f.debug("OPTIONS failed"),this._close(),f.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){f.debug("OPTIONS succeeded"),this._close(),f.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}}],s&&t(i.prototype,s),o&&t(i,o),_}(s),Qe}var at,ut,ct,ht={};function dt(){if(at)return ht;at=1;var e=ie(),t=z(),n=W(),r=new e("Socket");return ht.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return r.warn("undefined JsSIP.Socket instance"),!1;try{if(!t.isString(e.url))throw r.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!t.isString(e.via_transport))throw r.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===n.parse(e.sip_uri,"SIP_URI"))throw r.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(n){if(!t.isFunction(e[n]))throw r.warn("missing or invalid JsSIP.Socket method: ".concat(n)),new Error("Missing or invalid JsSIP.Socket method: ".concat(n))})}catch(e){return!1}return!0},ht}function ft(){if(ct)return ut;function e(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)}}ct=1;var t=ie(),n=dt(),r=U(),i=new t("Transport"),s={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:r.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:r.CONNECTION_RECOVERY_MAX_INTERVAL}};return ut=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),i.debug("new()"),this.status=s.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){i.warn("cannot use TextDecoder: ".concat(e))}if(void 0===e)throw new TypeError("Invalid argument. undefined 'sockets' argument");e instanceof Array||(e=[e]),e.forEach(function(e){if(!n.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:s.SOCKET_STATUS_READY})},this),this._getSocket()}var r,o,l;return r=t,(o=[{key:"connect",value:function(){i.debug("connect()"),this.isConnected()?i.debug("Transport is already connected"):this.isConnecting()?i.debug("Transport is connecting"):(this.close_requested=!1,this.status=s.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(){i.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=s.STATUS_DISCONNECTED,null!==this.recovery_timer&&(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(i.debug("send()"),!this.isConnected())return i.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return i.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===s.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===s.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==s.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=s.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=s.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=s.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=s.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n\r\n"!==e)if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i.debug("received binary message failed to be converted into string, message discarded")}i.debug("received binary message:\n\n".concat(e,"\n"))}else i.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i.debug("received message with CRLF Keep Alive response");else{i.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(e){i.warn("error sending Keep Alive response: ".concat(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(r.prototype,o),l&&e(r,l),t}(),ut}var _t,pt,mt,gt={};function vt(){if(_t)return gt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}_t=1;var n=ie(),r=W(),i=xe(),s=new n("Parser");function o(e,t){var n=t,r=0,i=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===r;){if(-1===(i=e.indexOf("\r\n",n)))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(t,n,s,o){var l,a=n.indexOf(":",s),u=n.substring(s,a).trim(),c=n.substring(a+1,o).trim();switch(u.toLowerCase()){case"via":case"v":t.addHeader("via",c),1===t.getHeaders("via").length?(l=t.parseHeader("Via"))&&(t.via=l,t.via_branch=l.branch):l=0;break;case"from":case"f":t.setHeader("from",c),(l=t.parseHeader("from"))&&(t.from=l,t.from_tag=l.getParam("tag"));break;case"to":case"t":t.setHeader("to",c),(l=t.parseHeader("to"))&&(t.to=l,t.to_tag=l.getParam("tag"));break;case"record-route":if(-1===(l=r.parse(c,"Record_Route")))l=void 0;else{var h,d=e(l);try{for(d.s();!(h=d.n()).done;){var f=h.value;t.addHeader("record-route",c.substring(f.possition,f.offset)),t.headers["Record-Route"][t.getHeaders("record-route").length-1].parsed=f.parsed}}catch(e){d.e(e)}finally{d.f()}}break;case"call-id":case"i":t.setHeader("call-id",c),(l=t.parseHeader("call-id"))&&(t.call_id=c);break;case"contact":case"m":if(-1===(l=r.parse(c,"Contact")))l=void 0;else{var _,p=e(l);try{for(p.s();!(_=p.n()).done;){var m=_.value;t.addHeader("contact",c.substring(m.possition,m.offset)),t.headers.Contact[t.getHeaders("contact").length-1].parsed=m.parsed}}catch(e){p.e(e)}finally{p.f()}}break;case"content-length":case"l":t.setHeader("content-length",c),l=t.parseHeader("content-length");break;case"content-type":case"c":t.setHeader("content-type",c),l=t.parseHeader("content-type");break;case"cseq":t.setHeader("cseq",c),(l=t.parseHeader("cseq"))&&(t.cseq=l.value),t instanceof i.IncomingResponse&&(t.method=l.method);break;case"max-forwards":t.setHeader("max-forwards",c),l=t.parseHeader("max-forwards");break;case"www-authenticate":t.setHeader("www-authenticate",c),l=t.parseHeader("www-authenticate");break;case"proxy-authenticate":t.setHeader("proxy-authenticate",c),l=t.parseHeader("proxy-authenticate");break;case"session-expires":case"x":t.setHeader("session-expires",c),(l=t.parseHeader("session-expires"))&&(t.session_expires=l.expires,t.session_expires_refresher=l.refresher);break;case"refer-to":case"r":t.setHeader("refer-to",c),(l=t.parseHeader("refer-to"))&&(t.refer_to=l);break;case"replaces":t.setHeader("replaces",c),(l=t.parseHeader("replaces"))&&(t.replaces=l);break;case"event":case"o":t.setHeader("event",c),(l=t.parseHeader("event"))&&(t.event=l);break;default:t.addHeader(u,c),l=0}return void 0!==l||{error:'error parsing header "'.concat(u,'"')}}return gt.parseMessage=function(e,t){var n,a,u=e.indexOf("\r\n");if(-1!==u){var c=e.substring(0,u),h=r.parse(c,"Request_Response");if(-1!==h){h.status_code?((n=new i.IncomingResponse).status_code=h.status_code,n.reason_phrase=h.reason_phrase):((n=new i.IncomingRequest(t)).method=h.method,n.ruri=h.uri),n.data=e;for(var d=u+2;;){if(-2===(u=o(e,d))){a=d+2;break}if(-1===u)return void s.warn("parseMessage() | malformed message");if(!0!==(h=l(n,e,d,u)))return void s.warn("parseMessage() |",h.error);d=u+2}if(n.hasHeader("content-length")){var f=n.getHeader("content-length");n.body=e.substr(a,f)}else n.body=e.substring(a);return n}s.warn('parseMessage() | error parsing first line of SIP message: "'.concat(c,'"'))}else s.warn("parseMessage() | no CRLF found, not a SIP message")},gt}function yt(){if(mt)return pt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}mt=1;var n,r,i,s=ie(),o=U(),l=xe(),a=z(),u=new s("sanityCheck"),c=[function(){for(var e=0,t=["from","to","call_id","cseq","via"];e<t.length;e++){var r=t[e];if(!n.hasHeader(r))return u.debug("missing mandatory header field : ".concat(r,", dropping the response")),!1}}],h=[function(){if("sip"!==n.s("to").uri.scheme)return f(416),!1},function(){if(!n.to_tag&&n.call_id.substr(0,5)===r.configuration.jssip_id)return f(482),!1},function(){var e=a.str_utf8_length(n.body),t=n.getHeader("content-length");if(e<t)return f(400),!1},function(){var e,t=n.from_tag,i=n.call_id,s=n.cseq;if(n.to_tag)return;if(n.method===o.INVITE){if(r._transactions.ist[n.via_branch])return!1;for(var l in r._transactions.ist)if(Object.prototype.hasOwnProperty.call(r._transactions.ist,l)&&(e=r._transactions.ist[l]).request.from_tag===t&&e.request.call_id===i&&e.request.cseq===s)return f(482),!1}else{if(r._transactions.nist[n.via_branch])return!1;for(var a in r._transactions.nist)if(Object.prototype.hasOwnProperty.call(r._transactions.nist,a)&&(e=r._transactions.nist[a]).request.from_tag===t&&e.request.call_id===i&&e.request.cseq===s)return f(482),!1}}],d=[function(){if(n.getHeaders("via").length>1)return u.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=a.str_utf8_length(n.body),t=n.getHeader("content-length");if(e<t)return u.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}];function f(t){var r,s,l=n.getHeaders("via"),u="SIP/2.0 ".concat(t," ").concat(o.REASON_PHRASE[t],"\r\n"),c=e(l);try{for(c.s();!(s=c.n()).done;){var h=s.value;u+="Via: ".concat(h,"\r\n")}}catch(e){c.e(e)}finally{c.f()}r=n.getHeader("To"),n.to_tag||(r+=";tag=".concat(a.newTag())),u+="To: ".concat(r,"\r\n"),u+="From: ".concat(n.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(n.call_id,"\r\n"),u+="CSeq: ".concat(n.cseq," ").concat(n.method,"\r\n"),u+="\r\n",i.send(u)}return pt=function(t,s,o){n=t,r=s,i=o;var a,u=e(c);try{for(u.s();!(a=u.n()).done;){if(!1===(0,a.value)())return!1}}catch(e){u.e(e)}finally{u.f()}if(n instanceof l.IncomingRequest){var f,_=e(h);try{for(_.s();!(f=_.n()).done;){if(!1===(0,f.value)())return!1}}catch(e){_.e(e)}finally{_.f()}}else if(n instanceof l.IncomingResponse){var p,m=e(d);try{for(m.s();!(p=m.n()).done;){if(!1===(0,p.value)())return!1}}catch(e){m.e(e)}finally{m.f()}}return!0}}var Tt,bt,St,Ct,Et,At,wt,Rt={};function It(){if(Tt)return Rt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}Tt=1;var n=z(),r=U(),i=W(),s=V(),o=dt(),l=P();Rt.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:r.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:r.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:r.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(n.createRandomToken(12),".invalid")};var a={mandatory:{sockets:function(t){var n=[];if(o.isSocket(t))n.push({socket:t});else{if(!Array.isArray(t)||!t.length)return;var r,i=e(t);try{for(i.s();!(r=i.n()).done;){var s=r.value;Object.prototype.hasOwnProperty.call(s,"socket")&&o.isSocket(s.socket)?n.push(s):o.isSocket(s)&&n.push({socket:s})}}catch(e){i.e(e)}finally{i.f()}}return n},uri:function(e){/^sip:/i.test(e)||(e="".concat(r.SIP,":").concat(e));var t=s.parse(e);return t&&t.user?t:void 0}},optional:{authorization_user:function(e){return-1===i.parse('"'.concat(e,'"'),"quoted_string")?void 0:e},authorization_jwt:function(e){if("string"==typeof e)return e},user_agent:function(e){if("string"==typeof e)return e},connection_recovery_max_interval:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if("string"==typeof e){var t=i.parse(e,"SIP_URI");if(-1!==t)return t}},display_name:function(e){return e},instance_id:function(e){return/^uuid:/i.test(e)&&(e=e.substr(5)),-1===i.parse(e,"uuid")?void 0:e},no_answer_timeout:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if("boolean"==typeof e)return e},session_timers_refresh_method:function(e){if("string"==typeof e&&((e=e.toUpperCase())===r.INVITE||e===r.UPDATE))return e},session_timers_force_refresher:function(e){if("boolean"==typeof e)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if("boolean"==typeof e)return e},register_expires:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(r.SIP,":").concat(e));var t=s.parse(e);return t?t.user?void 0:t:void 0},use_preloaded_route:function(e){if("boolean"==typeof e)return e},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var r,i=e(t);try{for(i.s();!(r=i.n()).done;){var s=r.value;"string"==typeof s&&n.push(s)}}catch(e){i.e(e)}finally{i.f()}return n}}}};return Rt.load=function(e,t){for(var r in a.mandatory){if(!t.hasOwnProperty(r))throw new l.ConfigurationError(r);var i=t[r],s=a.mandatory[r](i);if(void 0===s)throw new l.ConfigurationError(r,i);e[r]=s}for(var o in a.optional)if(t.hasOwnProperty(o)){var u=t[o];if(n.isEmpty(u))continue;var c=a.optional[o](u);if(void 0===c)throw new l.ConfigurationError(o,u);e[o]=c}},Rt}function Ot(){if(St)return bt;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function i(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=o(t);if(n){var l=o(this).constructor;r=Reflect.construct(i,arguments,l)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return s(t)}(this,r)}}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}St=1;var a=l().EventEmitter,u=ie(),c=U(),h=Le(),d=st(),f=ot(),_=lt(),p=Me(),m=ft(),g=z(),v=P(),y=V(),T=vt(),b=xe(),S=yt(),C=It(),E=new u("UA"),A={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};function w(e){this.emit("connecting",e)}function R(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 I(e){for(var t=0,n=["nict","ict","nist","ist"];t<n.length;t++){var r=n[t];for(var i in this._transactions[r])Object.prototype.hasOwnProperty.call(this._transactions[r],i)&&this._transactions[r][i].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 O(e){var t=e.transport,n=e.message;if((n=T.parseMessage(n,this))&&!(this._status===A.STATUS_USER_CLOSED&&n instanceof b.IncomingRequest)&&S(n,this,t))if(n instanceof b.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof b.IncomingResponse){var r;switch(n.method){case c.INVITE:(r=this._transactions.ict[n.via_branch])&&r.receiveResponse(n);break;case c.ACK:break;default:(r=this._transactions.nict[n.via_branch])&&r.receiveResponse(n)}}}return bt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&r(e,t)}(o,e);var t=i(o);function o(e){var n;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),E.debug("new() [configuration:%o]",e),(n=t.call(this))._cache={credentials:{}},n._configuration=Object.assign({},C.settings),n._dynConfiguration={},n._dialogs={},n._applicants={},n._sessions={},n._transport=null,n._contact=null,n._status=A.STATUS_INIT,n._error=null,n._transactions={nist:{},nict:{},ist:{},ict:{}},n._data={},n._closeTimer=null,void 0===e)throw new TypeError("Not enough arguments");try{n._loadConfig(e)}catch(e){throw n._status=A.STATUS_NOT_READY,n._error=A.CONFIGURATION_ERROR,e}return n._registrator=new h(s(n)),n}return n(o,null,[{key:"C",get:function(){return A}}]),n(o,[{key:"start",value:function(){E.debug("start()"),this._status===A.STATUS_INIT?this._transport.connect():this._status===A.STATUS_USER_CLOSED?(E.debug("restarting UA"),null!==this._closeTimer&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=A.STATUS_INIT,this._transport.connect()):this._status===A.STATUS_READY?E.debug("UA is in READY status, not restarted"):E.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){E.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(e){E.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){E.debug("call()");var n=new d(this);return n.connect(e,t),n}},{key:"sendMessage",value:function(e,t,n){E.debug("sendMessage()");var r=new f(this);return r.send(e,t,n),r}},{key:"sendOptions",value:function(e,t,n){E.debug("sendOptions()");var r=new _(this);return r.send(e,t,n),r}},{key:"terminateSessions",value:function(e){for(var t in E.debug("terminateSessions()"),this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}},{key:"stop",value:function(){var e=this;if(E.debug("stop()"),this._dynConfiguration={},this._status!==A.STATUS_USER_CLOSED){this._registrator.close();var t=Object.keys(this._sessions).length;for(var n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){E.debug("closing session ".concat(n));try{this._sessions[n].terminate()}catch(e){}}for(var r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch(e){}this._status=A.STATUS_USER_CLOSED,0===Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length&&0===t?this._transport.disconnect():this._closeTimer=setTimeout(function(){e._closeTimer=null,e._transport.disconnect()},2e3)}else E.debug("UA already closed")}},{key:"normalizeTarget",value:function(e){return g.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:return void E.warn('get() | cannot get "%s" parameter in runtime',e)}}},{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 E.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)return E.debug("Request-URI does not point to us"),void(e.method!==c.ACK&&e.reply_sl(404));if(e.ruri.scheme!==c.SIPS){if(!p.checkTransaction(this,e)){if(t===c.INVITE?new p.InviteServerTransaction(this,this._transport,e):t!==c.ACK&&t!==c.CANCEL&&new p.NonInviteServerTransaction(this,this._transport,e),t===c.OPTIONS){if(0===this.listeners("newOptions").length)return void e.reply(200);new _(this).init_incoming(e)}else if(t===c.MESSAGE){if(0===this.listeners("newMessage").length)return void e.reply(405);new f(this).init_incoming(e)}else if(t===c.INVITE&&!e.to_tag&&0===this.listeners("newRTCSession").length)return void e.reply(405);var n,r;if(e.to_tag)(n=this._findDialog(e.call_id,e.from_tag,e.to_tag))?n.receiveRequest(e):t===c.NOTIFY?(r=this._findSession(e))?r.receiveRequest(e):(E.debug("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist")):t!==c.ACK&&e.reply(481);else switch(t){case c.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){var i=e.replaces;(n=this._findDialog(i.call_id,i.from_tag,i.to_tag))?(r=n.owner).isEnded()?e.reply(603):r.receiveRequest(e):e.reply(481)}else(r=new d(this)).init_incoming(e);else E.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case c.BYE:e.reply(481);break;case c.CANCEL:(r=this._findSession(e))?r.receiveRequest(e):E.debug("received CANCEL request for a non existent session");break;case c.ACK:break;case c.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;default:e.reply(405)}}}else e.reply_sl(416)}},{key:"_findSession",value:function(e){var t=e.call_id,n=e.from_tag,r=e.to_tag,i=t+n,s=this._sessions[i],o=t+r,l=this._sessions[o];return s||(l||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])||null)}},{key:"_loadConfig",value:function(e){try{C.load(this._configuration,e)}catch(e){throw e}0===this._configuration.display_name&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=g.newUUID()),this._configuration.jssip_id=g.createRandomToken(5);var t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new m(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=w.bind(this),this._transport.onconnect=R.bind(this),this._transport.ondisconnect=I.bind(this),this._transport.ondata=O.bind(this)}catch(e){throw E.warn(e),new v.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 y("sip",g.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&&void 0!==arguments[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+=">"}};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)&&(-1!==r.indexOf(i)?Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}));for(var s in E.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(C.settings,s))switch(s){case"uri":case"registrar_server":E.debug("- ".concat(s,": ").concat(this._configuration[s]));break;case"password":case"ha1":case"authorization_jwt":E.debug("- ".concat(s,": NOT SHOWN"));break;default:E.debug("- ".concat(s,": ").concat(JSON.stringify(this._configuration[s])))}}},{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}}]),o}(a),bt}function Nt(){if(Et)return Ct;function e(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)}}Et=1;var t=ie(),n=W(),r=new t("WebSocketInterface");return Ct=function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),r.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;var i=n.parse(e,"absoluteURI");if(-1===i)throw r.warn("invalid WebSocket URI: ".concat(e)),new TypeError("Invalid argument: ".concat(e));if("wss"!==i.scheme&&"ws"!==i.scheme)throw r.warn("invalid WebSocket URI scheme: ".concat(i.scheme)),new TypeError("Invalid argument: ".concat(e));this._sip_uri="sip:".concat(i.host).concat(i.port?":".concat(i.port):"",";transport=ws"),this._via_transport=i.scheme.toUpperCase()}var i,s,o;return i=t,(s=[{key:"connect",value:function(){if(r.debug("connect()"),this.isConnected())r.debug("WebSocket ".concat(this._url," is already connected"));else if(this.isConnecting())r.debug("WebSocket ".concat(this._url," is connecting"));else{this._ws&&this.disconnect(),r.debug("connecting to WebSocket ".concat(this._url));try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(e){this._onError(e)}}}},{key:"disconnect",value:function(){r.debug("disconnect()"),this._ws&&(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),this._ws=null)}},{key:"send",value:function(e){return r.debug("send()"),this.isConnected()?(this._ws.send(e),!0):(r.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(){r.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(e){var t=e.wasClean,n=e.code,i=e.reason;r.debug("WebSocket ".concat(this._url," closed")),!1===t&&r.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,i)}},{key:"_onMessage",value:function(e){var t=e.data;r.debug("received WebSocket message"),this.ondata(t)}},{key:"_onError",value:function(e){r.warn("WebSocket ".concat(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(i.prototype,s),o&&e(i,o),t}()}var kt=function(){if(wt)return At;wt=1;var e=x,t=U(),n=P(),r=z(),i=Ot(),s=V(),o=B(),l=W(),a=Nt();return re()("JsSIP")("version %s",e.version),At={C:t,Exceptions:n,Utils:r,UA:i,URI:s,NameAddrHeader:o,WebSocketInterface:a,Grammar:l,debug:re(),get name(){return e.title},get version(){return e.version}}}(),Dt=i(kt);const xt=e=>"object"==typeof e&&null!==e,Ut=e=>xt(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date)&&!(globalThis.Blob&&e instanceof globalThis.Blob),Pt=Symbol("mapObjectSkip"),Mt=(e,t,n,r=new WeakMap)=>{if(n={deep:!1,target:{},...n},r.has(e))return r.get(e);r.set(e,n.target);const{target:i}=n;delete n.target;const s=e=>e.map(e=>Ut(e)?Mt(e,t,n,r):e);if(Array.isArray(e))return s(e);for(const[o,l]of Object.entries(e)){const a=t(o,l,e);if(a===Pt)continue;let[u,c,{shouldRecurse:h=!0}={}]=a;"__proto__"!==u&&(n.deep&&h&&Ut(c)&&(c=Array.isArray(c)?s(c):Mt(c,t,n,r)),i[u]=c)}return i};const qt=/[\p{Lu}]/u,Lt=/[\p{Ll}]/u,Ht=/^[\p{Lu}](?![\p{Lu}])/gu,Ft=/([\p{Alpha}\p{N}_]|$)/u,jt=/[_.\- ]+/,Gt=new RegExp("^"+jt.source),$t=new RegExp(jt.source+Ft.source,"gu"),Bt=new RegExp("\\d+"+Ft.source,"gu");function Wt(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},0===(e=Array.isArray(e)?e.map(e=>e.trim()).filter(e=>e.length).join("-"):e.trim()).length)return"";const n=!1===t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),r=!1===t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);if(1===e.length)return jt.test(e)?"":t.pascalCase?r(e):n(e);return e!==n(e)&&(e=((e,t,n,r)=>{let i=!1,s=!1,o=!1,l=!1;for(let a=0;a<e.length;a++){const u=e[a];l=!(a>2)||"-"===e[a-3],i&&qt.test(u)?(e=e.slice(0,a)+"-"+e.slice(a),i=!1,o=s,s=!0,a++):s&&o&&Lt.test(u)&&(!l||r)?(e=e.slice(0,a-1)+"-"+e.slice(a-1),o=s,s=!1,i=!0):(i=t(u)===u&&n(u)!==u,o=s,s=n(u)===u&&t(u)!==u)}return e})(e,n,r,t.preserveConsecutiveUppercase)),e=e.replace(Gt,""),e=t.preserveConsecutiveUppercase?((e,t)=>(Ht.lastIndex=0,e.replaceAll(Ht,e=>t(e))))(e,n):n(e),t.pascalCase&&(e=r(e.charAt(0))+e.slice(1)),((e,t)=>($t.lastIndex=0,Bt.lastIndex=0,e.replaceAll(Bt,(n,r,i)=>["_","-"].includes(e.charAt(i+n.length))?n:t(n)).replaceAll($t,(e,n)=>t(n))))(e,r)}class Vt extends Map{#e=0;#t=new Map;#n=new Map;#r;#i;#s;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.#r=e.maxSize,this.#i=e.maxAge||Number.POSITIVE_INFINITY,this.#s=e.onEviction}get __oldCache(){return this.#n}#o(e){if("function"==typeof this.#s)for(const[t,n]of e)this.#s(t,n.value)}#l(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof this.#s&&this.#s(e,t.value),this.delete(e))}#a(e,t){if(!1===this.#l(e,t))return t.value}#u(e,t){return t.expiry?this.#a(e,t):t.value}#c(e,t){const n=t.get(e);return this.#u(e,n)}#h(e,t){this.#t.set(e,t),this.#e++,this.#e>=this.#r&&(this.#e=0,this.#o(this.#n),this.#n=this.#t,this.#t=new Map)}#d(e,t){this.#n.delete(e),this.#h(e,t)}*#f(){for(const e of this.#n){const[t,n]=e;if(!this.#t.has(t)){!1===this.#l(t,n)&&(yield e)}}for(const e of this.#t){const[t,n]=e;!1===this.#l(t,n)&&(yield e)}}get(e){if(this.#t.has(e)){const t=this.#t.get(e);return this.#u(e,t)}if(this.#n.has(e)){const t=this.#n.get(e);if(!1===this.#l(e,t))return this.#d(e,t),t.value}}set(e,t,{maxAge:n=this.#i}={}){const r="number"==typeof n&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#t.has(e)?this.#t.set(e,{value:t,expiry:r}):this.#h(e,{value:t,expiry:r}),this}has(e){return this.#t.has(e)?!this.#l(e,this.#t.get(e)):!!this.#n.has(e)&&!this.#l(e,this.#n.get(e))}peek(e){return this.#t.has(e)?this.#c(e,this.#t):this.#n.has(e)?this.#c(e,this.#n):void 0}expiresIn(e){const t=this.#t.get(e)??this.#n.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){const t=this.#t.delete(e);return t&&this.#e--,this.#n.delete(e)||t}clear(){this.#t.clear(),this.#n.clear(),this.#e=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this.#f()],n=t.length-e;n<0?(this.#t=new Map(t),this.#n=new Map,this.#e=t.length):(n>0&&this.#o(t.slice(0,n)),this.#n=new Map(t.slice(n)),this.#t=new Map,this.#e=0),this.#r=e}evict(e=1){const t=Number(e);if(!t||t<=0)return;const n=[...this.#f()],r=Math.trunc(Math.min(t,Math.max(n.length-1,0)));r<=0||(this.#o(n.slice(0,r)),this.#n=new Map(n.slice(r)),this.#t=new Map,this.#e=0)}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.#t){const[t,n]=e;!1===this.#l(t,n)&&(yield[t,n.value])}for(const e of this.#n){const[t,n]=e;if(!this.#t.has(t)){!1===this.#l(t,n)&&(yield[t,n.value])}}}*entriesDescending(){let e=[...this.#t];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;!1===this.#l(r,i)&&(yield[r,i.value])}e=[...this.#n];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;if(!this.#t.has(r)){!1===this.#l(r,i)&&(yield[r,i.value])}}}*entriesAscending(){for(const[e,t]of this.#f())yield[e,t.value]}get size(){if(!this.#e)return this.#n.size;let e=0;for(const t of this.#n.keys())this.#t.has(t)||e++;return Math.min(this.#e+e,this.#r)}get maxSize(){return this.#r}get maxAge(){return this.#i}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[n,r]of this.entriesAscending())e.call(t,r,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}const zt=new Vt({maxSize:1e5}),Kt=e=>"object"==typeof e&&null!==e&&!(e=>ArrayBuffer.isView(e)||e instanceof Date||e instanceof RegExp||e instanceof Error||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof Promise)(e),Yt=(e,t={},n=new WeakMap,r)=>{if(!Kt(e))return e;if(n.has(e))return n.get(e);const{exclude:i,pascalCase:s=!1,stopPaths:o,deep:l=!1,preserveConsecutiveUppercase:a=!1}=t,u=new Set(o);if(Array.isArray(e)){const i=[];n.set(e,i);for(const s of e)i.push(Kt(s)?Yt(s,t,n,r):s);return i}const c={};n.set(e,c);const h=function(e,t,n){if(!xt(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);if(Array.isArray(e))throw new TypeError("Expected an object, got an array");return Mt(e,t,n)}(e,(d=r,(e,r)=>{if(l&&Kt(r)){const i=void 0===d?e:`${d}.${e}`;u.has(i)||(r=Array.isArray(r)?r.map(e=>Kt(e)?Yt(e,t,n,i):e):Yt(r,t,n,i))}if(!("string"!=typeof e||(e=>""!==e.trim()&&!Number.isNaN(Number(e)))(e)||i&&((e,t)=>e.some(e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t))))(i,e))){const t=s?`${e}_`:e;if(zt.has(t))e=zt.get(t);else{const n=e.match(/^[_$]*/)[0],r=Wt(e.slice(n.length),{pascalCase:s,locale:!1,preserveConsecutiveUppercase:a});(e=n+r).length<100&&zt.set(t,e)}}return[e,r]}),{deep:!1});var d;Object.assign(c,h);const f=Object.getOwnPropertySymbols(e);for(const i of f)c[i]=l&&Kt(e[i])?Yt(e[i],t,n,r):e[i];return c};function Xt(e,t){const n=new WeakMap;return Array.isArray(e)?e.map(e=>Kt(e)?Yt(e,t,n,void 0):e):Yt(e,t,n)}const Jt={wssServer:"wss://api.telegenta.com/sip/",eventServer:"wss://api.telegenta.com/es/",provisionToken:null,authorizationUsername:null,password:null,callToken:null,register:!0,iceGatherTimeout:3e3,playSignalTones:!0,logger:null,logLevel:3,connectEventService:!1,useCallDataInfoEvent:!1,toneVolume:.3,autoBusyIncoming:!0,autoRemoveSessionTime:3e3,playRingOnIncoming:!0,playCallInitializedTone:!1},Qt={1:[1209,697],2:[1336,697],3:[1477,697],a:[1633,697],4:[1209,770],5:[1336,770],6:[1477,770],b:[1633,770],7:[1209,852],8:[1336,852],9:[1477,852],c:[1633,852],"*":[1209,941],0:[1336,941],"#":[1477,941],d:[1633,941]},Zt=[{d:250,f1:425,f2:0,g:250}],en=[{d:500,f1:425,f2:0,g:500}],tn=[{d:333,f1:950,f2:0,g:0},{d:333,f1:1400,f2:0,g:0},{d:333,f1:1800,f2:0,g:1e3}],nn=[{d:200,f1:500,f2:0,g:0},{d:200,f1:700,f2:0,g:5e3}],rn=[{d:1e3,f1:425,f2:0,g:4e3}],sn=[{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:0},{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:0},{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:3e3}];class on extends a{constructor(e){super(),this._phone=e,this.log=e.log,this._callUUID=null,this._webRTCSession=null,this._sessionState=null,this._iceCandidateTimer=null,this._isOnHold=!1,this._isMuted=!1,this._isRecording=!1,this._recordingError=null,this._callBeginTime=null,this._callAnswerTime=null,this._callEndTime=null,this._durationUpdTimerObj=null,this._originatingNumber=null,this._destinationNumber=null,this._callDisposition=null,this._localNumberName=null,this._isListenCall=!1,this._whisperMode=null,this._manualDisposition=null,this._rtcpStatsTimer=null,this._currentReport=null,this._answerCallTimeout=0,this._answerCallTimer=null,this._mediaSwitch=null}newOutboundSession(e,t){this._callUUID=v(),this.log.debug(`Created new outbound session to: ${e} [${this._callUUID}]`),this.destinationNumber=e;let n={mediaConstraints:{audio:!0,video:!1},pcConfig:{iceServers:[{urls:["stun:stun.l.google.com:19302"]}]},extraHeaders:["X-Call-token: "+this._phone.options.callToken,"X-P-UUID: "+this._callUUID,"X-Max-cost: "+t.maximumCallCost]};if(t.explicitCallerId&&n.extraHeaders.push("X-CID-Number-Id: "+t.explicitCallerId),t.explicitShortCallerId&&n.extraHeaders.push("X-Short-CID-Id: "+t.explicitShortCallerId),t.metaInfo&&n.extraHeaders.push("X-Meta-Info: "+encodeURI(t.metaInfo.toString().substr(0,255))),t.record){if(isNaN(t.record))throw new f("Record parameter must be a number");this.log.debug(`Recording enabled and kept for ${t.record} days`),n.extraHeaders.push("X-Record: "+t.record),this._isRecording=!0}else this._isRecording=!1;if(this._isListenCall=t._isListenCall,t.mediaSwitchURI)this.log.debug("Requesting specific media switch "+t.mediaSwitchURI),n.extraHeaders.push("X-RMS: "+t.mediaSwitchURI);else{const e=this.getOtherSessions();e.length>0?e[0]._mediaSwitch?(this.log.debug("Requesting call grouping on media switch "+e[0]._mediaSwitch),n.extraHeaders.push("X-RMS: sip:"+e[0]._mediaSwitch)):this.log.warning("Other sessions exist but media switch address is invalid"):this.log.debug("No other active calls, no media switch grouping requested")}const r="sip:"+e+"@telegenta.com";try{this._initWebRTCSession(this._phone._UA.call(r,n))}catch(e){return this.log.error("Error starting call:",e),null}t.answerCallTimeout&&this._setAnswerCallTimeout(t.answerCallTimeout)}newInboundSession(e){this._callUUID=e.request.getHeader("X-P-UUID",0),this._destinationNumber=e.request.getHeader("X-DID",0),this._localNumberName=unescape(e.request.getHeader("X-DID-NAME",0)),this._originName=e.request.from.display_name,this._originatingNumber=e.request.from.uri.user,this.log.info(`Incoming call from ${this._originatingNumber} [${this._callUUID}]`),this.log.debug(e),this._mediaSwitch=e.request.getHeader("X-MS"),this.log.debug(`Media switch handling call: ${this._mediaSwitch}`),this._initWebRTCSession(e.session)}getOtherSessions(){const e=this._phone.sessions;let t=[];for(let n in e)e[n]&&e[n].__containerId!==this.__containerId&&t.push(e[n]);return t}_initWebRTCSession(e){this._webRTCSession=e,this._callBeginTime=Date.now();const t=this;this._webRTCSession.on("icecandidate",function(e){const n=e.candidate;t.log.debug(`Got ICE candidate: ${n.candidate}`),"srflx"===n.type&&null!==n.relatedAddress&&null!==n.relatedPort?(t.log.info(`Accepting ICE candidate: ${n.candidate}`),null!=t._iceCandidateTimer&&clearTimeout(t._iceCandidateTimer),e.ready()):(null!=t._iceCandidateTimer&&clearTimeout(t._iceCandidateTimer),t._iceCandidateTimer=setTimeout(function(e){t.log.debug(`ICE Timeout (${t._phone.options.iceGatherTimeout} ms) reached`),e.ready()},t._phone.options.iceGatherTimeout,e))}),this._webRTCSession.on("connecting",function(){t._startDurationUpdateTimer(),t._startRTCPStatsUpdateTimer(),t._setSessionState("INITIALIZING")}),this._webRTCSession.on("sending",function(){t._phone.options.playCallInitializedTone&&t._phone._startRepeatTone(nn),t._setSessionState("CALLING")}),this._webRTCSession.on("progress",function(e){"remote"===e.originator&&(t._setSessionState("PROGRESS",{code:e.response.status_code}),t._phone._endRepeatTone(),180===e.response.status_code&&t._phone._startRepeatTone(rn),t._answerCallTimeout&&(t._answerCallTimer=setTimeout(function(){t.log.info(`Answer call timeout after ${t._answerCallTimeout} seconds`);try{t.hangup()}catch(e){t.log.info("No active session, ignoring answer call timeout")}},1e3*t._answerCallTimeout)))}),this._webRTCSession.on("accepted",function(e){if(t._phone._endRepeatTone(),t._callAnswerTime=Date.now(),t._answerCallTimeout&&(clearTimeout(t._answerCallTimer),t._answerCallTimeout=0),"remote"===e.originator){"true"===e.response.getHeader("X-Recording")?t.log.debug("Call is being prerecorded"):t.log.debug("No call recording started yet"),t._mediaSwitch=e.response.getHeader("X-MS"),t.log.debug(`Media switch handling call: ${t._mediaSwitch}`)}}),this._webRTCSession.on("confirmed",function(){t._setSessionState("ACTIVE")}),this._webRTCSession.on("ended",function(){t._phone._endRepeatTone(),t._callEndTime=Date.now(),t._answerCallTimeout&&clearTimeout(t._answerCallTimer),t._setSessionState("TERMINATED")}),this._webRTCSession.on("failed",function(e){let n;t._phone._endRepeatTone(),t._callEndTime=Date.now(),t._answerCallTimeout&&clearTimeout(t._answerCallTimer),n=e.message?`${e.message.status_code} ${e.message.reason_phrase}`:"",t._setSessionState("FAILED",{cause:e.cause,message:n})}),this._webRTCSession.on("dtmf",function(e){t.log.debug("Session DTMF",e)}),this._webRTCSession.on("newInfo",function(e){t.log.debug("New session info",e)}),this._webRTCSession.on("hold",function(){t._isOnHold=!0,t._fireHoldStateEvent(),t._setSessionState("ON_HOLD")}),this._webRTCSession.on("unhold",function(){t._isOnHold=!1,t._fireHoldStateEvent(),t._setSessionState("ACTIVE")}),this._webRTCSession.on("muted",function(e){t.log.debug("Microphone muted",e),t._isMuted=!0,t._fireMuteStateEvent()}),this._webRTCSession.on("unmuted",function(e){t.log.debug("Microphone unmuted",e),t._isMuted=!1,t._fireMuteStateEvent()}),this._webRTCSession.on("reinvite",function(e){t.log.debug("Session reinvite",e)}),this._webRTCSession.on("update",function(e){t.log.debug("Session update",e)}),this._webRTCSession.on("getusermediafailed",function(e){t.log.error("Getusermedia failed",e)}),t._webRTCSession.connection&&t._handleRemoteAudio(t._webRTCSession),this.log.debug("WebRTCSession object:"),this.log.debug(this)}hangup(e=null){e?(this.log.info(`Hanging up call with disposition ${e}`),this._manualDisposition=e,this._webRTCSession.terminate({extraHeaders:["X-HDISP: "+e]})):(this.log.info("Hanging up call"),this._webRTCSession.terminate())}answer(e=null){let t={mediaConstraints:{audio:!0,video:!1},pcConfig:{iceServers:[{urls:["stun:stun.l.google.com:19302"]}]},extraHeaders:["X-Call-token: "+this._phone.options.callToken]};e&&t.extraHeaders.push("X-Meta-Info: "+encodeURI(e.toString().substr(0,255))),this._webRTCSession.answer(t),this._handleRemoteAudio(this._webRTCSession)}reject(e=603,t="Rejected call"){this.log.info("Rejecting call"),this._webRTCSession.terminate({status_code:e,reason_phrase:t})}get uuid(){return this._callUUID}get destinationNumber(){return this._destinationNumber}get localNumberName(){return this._localNumberName}get originatingNumber(){return this._originatingNumber}set destinationNumber(e){this.log.debug("Setting destination number to: "+e),this._destinationNumber=e}get state(){return this._sessionState}get direction(){return this._isListenCall?(this.log.debug("Call direction is LISTEN"),"LISTEN"):"incoming"===this._webRTCSession.direction?(this.log.debug("Call direction is INBOUND"),"INBOUND"):"outgoing"===this._webRTCSession.direction?(this.log.debug("Call direction is OUTBOUND"),"OUTBOUND"):(this.log.error("Unknown call direction: "+this._webRTCSession.direction),"UNKNOWN")}startRecording(){this.log.debug("Request start recording");const e=this;this._webRTCSession.once("newInfo",t=>{"local"===t.originator&&(t.info.on("succeeded",function(){e.log.info("Recording started successfully"),e._isRecording=!0;try{e.emit("recordingStateChange",{state:!0,error:null})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}}),t.info.on("failed",function(t){e._recordingError=t.response.reason_phrase,e.log.error("Recording start failed: "+e._recordingError),e._fireRecordingStateEvent()}))}),this._webRTCSession.sendInfo("application/info",null,{extraHeaders:["Record: on"]})}stopRecording(){this.log.debug("Request stop recording");const e=this;this._webRTCSession.once("newInfo",t=>{t.info.on("succeeded",function(){e.log.info("Recording stopped successfully"),e._isRecording=!1;try{e.emit("recordingStateChange",{state:!1,error:null})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}}),t.info.on("failed",function(t){e.log.error("Recording stopped failed: "+t.response.reason_phrase);try{e.emit("recordingStateChange",{state:e._isRecording,error:t.response.reason_phrase})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}})}),this._webRTCSession.sendInfo("application/info",null,{extraHeaders:["Record: off"]})}toggleRecording(){return this._isRecording?(this.stopRecording(),!1):(this.startRecording(),!0)}get isRecording(){return this._isRecording}muteMic(){this.log.info("Mute microphone"),this._webRTCSession.mute()}unmuteMic(){this.log.info("Unmute microphone"),this._webRTCSession.unmute()}toggleMute(){this._isMuted?this.unmuteMic():this.muteMic()}get isMuted(){return this._isMuted}hold(){this.log.info("Hold call"),this._webRTCSession.hold()}unhold(){this.log.info("Uncall call"),this._phone.holdAllCalls(),this._webRTCSession.unhold()}toggleHold(){this._isOnHold?this.unhold():this.hold()}get isOnHold(){return this._isOnHold}sendDTMF(e,t=!0){if(!(e in Qt))throw new f("Invalid DTMF code");if(this.log.info("Sending DTMF: "+e),this._webRTCSession.sendDTMF(e),t){const t=Qt[e];if(this._isMuted)this.log.debug("Mic already muted, just sending DTMF"),this._phone.playTone(500,t[0],t[1]);else{this.log.debug("Mute mic while sending DTMF"),this._webRTCSession.mute();const e=this;this._phone.playTone(500,t[0],t[1],function(){e.log.debug("Unmute mic after DTMF"),e._webRTCSession.unmute()})}}}transfer(e){this.log.info(`Transferring ${this.uuid} => ${e.uuid}`);const t=this._webRTCSession.refer(this._webRTCSession._request.ruri,{replaces:e._webRTCSession}),n=this;t.on("requestSucceeded",function(){n.log.info("Transfer completed successfully")}),t.on("requestFailed",function(e){n.log.error(`Transfer rejected: ${e}`)}),t.on("failed",function(e){n.log.error(`Transfer failed: ${e}`)})}playback(e,t=!1){if(!this._phone._options.connectEventService)throw new m("Event service not enabled");this.log.info(`Playback media file ${e} hangup after ${t}`);const n=this._phone._eventClient.fireEvent("call_command",{call_uuid:this.uuid,call_command:"playback",media_file_id:e,hangup_after:t});return t&&(this._phone._remoteAudioElement.srcObject=null,this._webRTCSession.mute(),n.then(()=>{this._setSessionState("PLAYBACK")})),n}setWhisperMode(e=0){if("LISTEN"===!this.direction)throw new m("Call is not correct type (listen)");if(e<0||e>2)throw new d("Invalid mode");let t;0===e&&(t=0),1===e&&(t=2),2===e&&(t=3),this.sendDTMF(t,!1),this._whisperMode=e,this._fireWhisperModeChangeEvent()}_startDurationUpdateTimer(){const e=this;this._durationUpdTimerObj||(this._durationUpdTimerObj=setInterval(function(){const t=e._callAnswerTime?Date.now()-e._callAnswerTime:null,n={uuid:e._callUUID,beginTime:e._callBeginTime,answerTime:e._callAnswerTime,endTime:e._callEndTime,duration:Date.now()-e._callBeginTime,durationStr:y(Date.now()-e._callBeginTime),activeDuration:t,activeDurationStr:t?y(t):""};try{e.emit("callDurationUpdate",n)}catch(n){e.log.error("Exception in call duration update event: "+n)}},1e3))}_startRTCPStatsUpdateTimer(){if(!this._rtcpStatsTimer){const e={outboundPacketsSent:0,outboundBytesSent:0,outboundPacketsLost:0,outboundJitter:0,inboundPacketsReceived:0,inboundBytesReceived:0,inboundPacketsLost:0,inboundJitter:0,roundTripTime:0};this._currentReport=Object.assign({},e),this._rtcpStatsTimer=setInterval(()=>{this._webRTCSession._connection.getStats().then(t=>{let n=Object.assign({},e),r=Object.assign({},e);for(let e of t.values())switch(e.type){case"outbound-rtp":n.outboundPacketsSent=e.packetsSent,r.outboundPacketsSent=e.packetsSent-this._currentReport.outboundPacketsSent,n.outboundBytesSent=e.bytesSent,r.outboundBytesSent=e.bytesSent-this._currentReport.outboundBytesSent;break;case"inbound-rtp":n.inboundPacketsReceived=e.packetsReceived,r.inboundPacketsReceived=e.packetsReceived-this._currentReport.inboundPacketsReceived,n.inboundBytesReceived=e.bytesReceived,r.inboundBytesReceived=e.bytesReceived-this._currentReport.inboundBytesReceived,n.inboundPacketsLost=e.packetsLost,r.inboundPacketsLost=e.packetsLost-this._currentReport.inboundPacketsLost,n.inboundJitter=1e3*e.jitter,r.inboundJitter=1e3*e.jitter;break;case"remote-inbound-rtp":n.outboundPacketsLost=e.packetsLost,r.outboundPacketsLost=e.packetsLost-this._currentReport.outboundPacketsLost,n.outboundJitter=1e3*e.jitter,r.outboundJitter=1e3*e.jitter,n.roundTripTime=1e3*e.roundTripTime,r.roundTripTime=1e3*e.roundTripTime}if(this._currentReport=this._calcReportMetrics(n),n.roundTripTime){const e={total:this._currentReport,delta:this._calcReportMetrics(r)};try{this.emit("callQualityReportUpdate",e)}catch(e){this.log.error("Exception in call quality report update event: "+e)}}})},5e3)}}_calcReportMetrics(e){e.outboundPacketLossPct=e.outboundPacketsLost/e.outboundPacketsSent,e.inboundPacketLossPct=e.inboundPacketsLost/e.inboundPacketsReceived,e.effectiveLatency=e.roundTripTime+(e.inboundJitter+e.outboundJitter)+10;const t=100*(e.outboundPacketLossPct+e.inboundPacketLossPct),n=95*t/(t+10),r=.1*e.effectiveLatency;switch(e.rFactor=Math.max(0,100-n-r),e.mos=1+.035*e.rFactor+7e-6*e.rFactor*(e.rFactor-60)*(100-e.rFactor),!0){case e.rFactor<50:e.qualityString="Bad";break;case e.rFactor<70:e.qualityString="Poor";break;case e.rFactor<80:e.qualityString="Fair";break;case e.rFactor<90:e.qualityString="Good";break;case e.rFactor<=100:e.qualityString="Excellent";break;default:e.qualityString="Error"}return e}_setSessionState(e,t=null){this.log.debug("Session state: "+e),t&&this.log.debug(t),this._sessionState=e;try{this.emit("sessionStateChange",Object.assign({state:e,uuid:this._callUUID},t))}catch(e){this.log.error("Exception in sessionStateChange event:"+e)}"TERMINATED"===e&&(this._callDisposition=this._manualDisposition||"NORMAL",this._callFinished()),"FAILED"===e&&("Unavailable"===t.cause&&(this._callDisposition="TEMP_UNAVAIL",this._phone.options.playSignalTones&&this._phone._startRepeatTone(Zt)),"Not Found"===t.cause&&(this._callDisposition="INVALID_NUMBER",this._phone.options.playSignalTones&&this._phone._startRepeatTone(tn)),"Canceled"===t.cause&&(this._callDisposition=this._manualDisposition||"NO_ANSWER"),"Rejected"===t.cause&&("INBOUND"===this.direction?this._callDisposition="REJECTED":this._callDisposition="BARRED"),"Busy"===t.cause&&(this._callDisposition="BUSY",this._phone.options.playSignalTones&&this._phone._startRepeatTone(en)),this._webRTCSession.direction,this._callFinished())}_callFinished(){this.log.info("Call finished"),this._fireCallEndedEvent(),clearInterval(this._durationUpdTimerObj),clearInterval(this._rtcpStatsTimer),this._phone._sessionTerminated(this)}_setAnswerCallTimeout(e){this.log.debug("Setting answer call timeout to: "+e),this._answerCallTimeout=e}_fireRecordingStateEvent(){try{this.emit("recordingStateChange",{state:this._isRecording,error:this._recordingError})}catch(e){this.log.error("Exception in recording state change event: "+e)}}_fireMuteStateEvent(){try{this.emit("muteStateChange",{state:this._isMuted})}catch(e){this.log.error("Exception in mute state change event: "+e)}}_fireHoldStateEvent(){try{this.emit("holdStateChange",{state:this._isOnHold})}catch(e){this.log.error("Exception in hold state change event: "+e)}}_fireWhisperModeChangeEvent(){try{this.emit("whisperModeChange",{mode:this._whisperMode})}catch(e){this.log.error("Exception in whisper mode change event: "+e)}}_fireCallEndedEvent(){let e;e={uuid:this._callUUID,direction:this.direction,disposition:this._callDisposition,originatingNumber:this._originatingNumber,destinationNumber:this._destinationNumber,duration:this._callEndTime-this._callBeginTime,answerDuration:this._callAnswerTime?this._callAnswerTime-this._callBeginTime:null,activeDuration:this._callAnswerTime?this._callEndTime-this._callAnswerTime:null,startTime:new Date(this._callBeginTime).toISOString(),endTime:new Date(this._callEndTime).toISOString(),answerTime:this._callAnswerTime?new Date(this._callAnswerTime).toISOString():null},e.durationStr=y(e.duration),e.answerDurationStr=e.answerDuration?y(e.answerDuration):"",e.activeDurationStr=e.activeDuration?y(e.activeDuration):"",e.callQualityReport=this._currentReport;try{this.emit("callEnded",e)}catch(e){this.log.error("Exception in callEnded event: "+e)}}_handleRemoteAudio(e){this._phone._endRepeatTone();const t=this;e.connection.ontrack=function(e){t.log.debug("Start media output (track):"),t.log.debug(e),t._phone._remoteAudioElement.srcObject=e.streams[0]}}}return e.EventClient=I,e.EventServiceNotConnected=g,e.InvalidMediaDevice=h,e.InvalidOptions=d,e.InvalidParameter=f,e.LOGLVL=n,e.LogHandler=t,e.MediaNotPrepared=u,e.NoActiveSession=_,e.NotAllowed=m,e.NotReady=c,e.Phone=class extends a{constructor(e=null){super(),this._mediaPermission=!1,this._mediaPermissionError=!1,this._UA=null,this._connectionState=null,this._isStarted=!1,this._eventClient=null,this._options=null,this._sessionCounter=0,this._activeSessions={},this._remoteAudioElement=document.createElement("AUDIO"),this._remoteAudioElement.autoplay=!0,this._toneAudioElement=document.createElement("AUDIO"),this._toneAudioElement.autoplay=!0,this._toneTimer=null,this._repeatToneActive=!1,this._repeatToneSequence=[],this._repeatToneSequencePos=0,this._toneGainProcessor=null,this._oscillator1=null,this._oscillator2=null,this.log=e||new t(n.INFO),this.log.level,n.DEBUG,Dt.debug.disable("JsSIP:*")}prepareMedia(){this.log.info("Get media permission");const e=this,t={audio:!0,video:!1};return new Promise(function(n,r){navigator.mediaDevices.getUserMedia(t).then(()=>{e._mediaPermission=!0,e._mediaPermissionError=!1,e.log.info("Media permission granted"),n()},t=>{e._mediaPermission=!1,e._mediaPermissionError=!0,e.log.error("Denied media permission: "+t),r(t)})})}start(e){if(this._checkMediaPermission(),this._isStarted&&(this.log.warning("Phone already started, stopping first"),this.stop()),this._options=Object.assign(Jt,e),this._initToneGenerator(),this._options.provisionToken){let e=null;try{e=JSON.parse(atob(this._options.provisionToken))}catch(e){throw new d("provisionToken","Invalid token")}this.log.info("Using provisioning token authorization"),this._options.wssServer=e.wss_server,this._options.eventServer=e.event_server,this._options.authorizationUsername=e.wss_username,this._options.password=e.wss_password,this._options.callToken=e.wss_token}else{if(this.log.info("Using manual specified credentials"),!this._options.authorizationUsername)throw new d("authorizationUsername","Missing username");if(!this._options.password)throw new d("password","Missing password");if(!this._options.callToken)throw new d("callToken","Missing call token")}this._options.useCallDataInfoEvent&&!this._options.connectEventService&&(this.log.info("Enabled event service because 'useCallDataInfoEvent' is enabled"),this._options.connectEventService=!0),this._options.connectEventService&&(this._eventClient=new I(this.log),this._eventClient.connect(this._options.eventServer).then(()=>{if(this.log.info("Connected to event server"),this._options.useCallDataInfoEvent){let e={event_name:"calldata_available",call_token:this._options.callToken};this._eventClient.subscribe(e,e=>{try{this.log.debug("Received remote call data info"),this.log.debug(e),this._fireCallDataInfoEvent(e)}catch(e){this.log.error("Event callback failed: "+e)}}).then(e=>{this.log.info(`Subscription successful ID = ${e}`)},e=>{this.log.error(`Subscribe failed: ${e}`)})}},e=>{this.log.error(`Unable to connect to event server: ${e}`)}));let t=null;try{t=new Dt.WebSocketInterface(this._options.wssServer)}catch(e){throw new p("Unable to connect phone websocket: "+e)}this.log.info("Starting phone"),this.log.debug(this._options),this._UA=new Dt.UA({sockets:[t],authorization_user:this._options.authorizationUsername,password:this._options.password,register:this._options.register,display_name:this._options.authorizationUsername,uri:this._options.authorizationUsername+"@telegenta.com",session_timers:!1});const n=this;this._UA.on("newRTCSession",function(e){if(n.log.debug("New RTCSession"),"remote"===e.originator){const t=new on(n);if(t.newInboundSession(e),n._options.playRingOnIncoming&&n._startRepeatTone(sn),n._options.autoBusyIncoming){if(Object.keys(n._activeSessions).length>0)return n.log.info(`Autorejecting incoming call ${t.uuid} because there is already active calls`),void t.reject(486,"Busy");n.log.debug("There are no other sessions, adding incoming call")}n._addSession(t),t._setSessionState("INCOMING"),n._fireIncomingCallEvent(t)}}),this._UA.on("connecting",function(){n._setConnectionState("CONNECTING")}),this._UA.on("connected",function(){n._setConnectionState("CONNECTED")}),this._UA.on("disconnected",function(){n._setConnectionState("DISCONNECTED")}),this._UA.on("registered",function(){n._setConnectionState("REGISTERED")}),this._UA.on("unregistered",function(){n._setConnectionState("UNREGISTERED")}),this._UA.on("registrationFailed",function(){n._setConnectionState("REGISTRATION_FAILED")}),this._UA.start(),this._isStarted=!0,this.log.info("Successfully started phone")}stop(){if(!this._isStarted)throw new c("Phone is not started");if(this._UA.removeAllListeners(),this._UA.stop(),delete this._UA,this._eventClient){try{this._eventClient.disconnect(),delete this._eventClient}catch(e){this.log.warning("Unable to disconnect event client")}this._isStarted=!1,this.log.info("Phone client successfully stopped")}else this.log.debug("Event client not running, not stopping")}call(e,t={}){if(!this._isStarted)throw new c("Phone is not started");if(this._checkForConnectingCalls())throw new m("Unable to make new calls while others are connecting");this.holdAllCalls();const n=Object.assign({record:!1,maximumCallCost:0,answerCallTimeout:0,explicitCallerId:null,explicitShortCallerId:null,metaInfo:null,_isListenCall:!1},t);e=e.trim().replace(/ |\(|\)/g,""),this.log.info("Calling number: "+e);let r=new on(this);return r.newOutboundSession(e,n),this._addSession(r),r}listen(e){const t=e.split("@");let n=t[0],r="sip:"+t[1];return this.log.debug("Initiating listen to call with uuid "+n+" on media switch "+r),this.call("listen-"+n,{mediaSwitchURI:r,_isListenCall:!0})}getSessionByUUID(e){for(let t in this._activeSessions)if(this._activeSessions.hasOwnProperty(t)&&this._activeSessions[t].uuid===e)return this._activeSessions[t];return null}get options(){return this._options}get sessions(){let e=[];for(let t in this._activeSessions)this._activeSessions.hasOwnProperty(t)&&e.push(this._activeSessions[t]);return e}get hasMediaPermission(){return this._mediaPermission}get hasMediaPermissionError(){return this._mediaPermissionError}get isStarted(){return this._isStarted}get browserSupported(){return b()||S()||T()||C()}get remoteAudioElement(){return this._remoteAudioElement}playTone(e,t,n=0,r=null){this.log.debug(`Playing tone ${t} / ${n} for ${e} ms`),this._oscillator1.frequency.value=t,this._oscillator2.frequency.value=n,this._toneGainProcessor.gain.value=this._options.toneVolume;const i=this;this._toneTimer=setTimeout(function(){i.stopTone(),r&&r()},e)}stopTone(){this._oscillator1.frequency.value=0,this._oscillator2.frequency.value=0,this._toneGainProcessor.gain.value=0,clearTimeout(this._toneTimer)}_startRepeatTone(e){this.log.info("Repeating tone sequence started"),this.log.debug(e),this._repeatToneSequence=e,this._repeatToneSequencePos=0,this._repeatToneActive=!0,this._doRepeatTone()}_doRepeatTone(){if(this._repeatToneActive){this.log.debug(`Playing repeated tone, pos = ${this._repeatToneSequencePos}`);let e=this._repeatToneSequence[this._repeatToneSequencePos];this._repeatToneSequencePos++,this._repeatToneSequencePos===this._repeatToneSequence.length&&(this._repeatToneSequencePos=0);const t=this;this.playTone(e.d,e.f1,e.f2,function(){setTimeout(t._doRepeatTone.bind(t),e.g)})}}_endRepeatTone(){this._repeatToneActive&&(this.log.info("Repeating tone stopped"),this._repeatToneActive=!1,this.stopTone())}_initToneGenerator(){const e=window.AudioContext||window.webkitAudioContext||!1;if(!e)throw new m("Audio API not supported by this browser");const t=new e;this._toneStreamNode=t.createMediaStreamDestination(),this._toneAudioElement.srcObject=this._toneStreamNode.stream,this._toneGainProcessor=t.createGain(),this._toneGainProcessor.gain.value=0,this._toneGainProcessor.connect(this._toneStreamNode),this._oscillator1=t.createOscillator(),this._oscillator1.connect(this._toneGainProcessor),this._oscillator1.frequency.value=0,this._oscillator1.start(),this._oscillator2=t.createOscillator(),this._oscillator2.connect(this._toneGainProcessor),this._oscillator2.frequency.value=0,this._oscillator2.start()}holdAllCalls(){if(this.log.info("Holding all active sessions"),this._checkForConnectingCalls())throw new m("A session is currently connecting");for(let e in this._activeSessions)if(this._activeSessions.hasOwnProperty(e)){let t=this._activeSessions[e];"ACTIVE"===t.state&&t.hold()}}_addSession(e){this._sessionCounter++,e.__containerId=this._sessionCounter,this.log.info(`Adding new session ${e.__containerId}: ${e.uuid}`),this._activeSessions[e.__containerId]=e,this.log.debug(`We now have ${Object.keys(this._activeSessions).length} sessions:`),this.log.debug(this._activeSessions);try{this.emit("sessionCreated",{session:e})}catch(e){this.log.error("Exception in sessionCreated event: "+e)}}_removeSession(e){this.log.info(`Removing session ${e.__containerId}: ${e.uuid}`);try{this.emit("sessionRemoved",{session:e})}catch(e){this.log.error("Exception in sessionRemoved event: "+e)}delete this._activeSessions[e.__containerId],this.log.debug(`We now have ${Object.keys(this._activeSessions).length} sessions`),this.log.debug(this._activeSessions),this._endRepeatTone()}_sessionTerminated(e){this.log.debug(`Session ${e.uuid} terminated, removing in ${this._options.autoRemoveSessionTime} ms`);const t=this;setTimeout(function(){t._removeSession(e)},this._options.autoRemoveSessionTime)}_checkForConnectingCalls(){for(let e in this._activeSessions)if(this._activeSessions.hasOwnProperty(e)){let t=this._activeSessions[e];if("INITIALIZING"===t.state||"CALLING"===t.state||"PROGRESS"===t.state||"INCOMING"===t.state)return!0}return!1}_setConnectionState(e){this.log.info("Connection state: "+e),this._connectionState=e;try{this.emit("connectionStateChange",{state:e})}catch(e){this.log.error("Exception in connectionStateChange event: "+e)}}_fireIncomingCallEvent(e){try{this.emit("incomingCall",e)}catch(e){this.log.error("Exception in incomingCall event: "+e)}}_fireCallDataInfoEvent(e=null){let t;t=Xt(e),t.recordings=Xt(e.recordings),t.duration=1e3*t.duration,t.answerDuration=1e3*t.answerDuration,t.activeDuration=1e3*t.activeDuration,t.durationStr=y(t.duration),t.answerDurationStr=t.answerDuration?y(t.answerDuration):"",t.activeDurationStr=t.activeDuration?y(t.activeDuration):"";try{this.emit("callDataInfo",t)}catch(t){this.log.error("Exception in callDataInfo event: "+t)}}_checkMediaPermission(){if(!this._mediaPermission)throw new u}},e.Request=E,e.Requestor=A,e.Session=on,e.UnableToConnect=p,e.browserIsChrome=b,e.browserIsEdge=function(){return-1!==navigator.userAgent.indexOf("Edge")},e.browserIsFirefox=S,e.browserIsOpera=T,e.browserIsSafari=C,e.compareObjects=function(e,t){if(!e||!t)return!1;const n=Object.keys(t);return Object.keys(e).every(function(r){return-1!==n.indexOf(r)&&e[r]===t[r]})},e.createDurationString=y,e.createUUID=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
1
|
+
var Telegenta=function(e){"use strict";class t{constructor(e=2,t=null){this.extHandler=t,this.level=e}debug(...e){this._doLog(n.DEBUG,e)}info(...e){this._doLog(n.INFO,e)}warn(...e){this._doLog(n.WARN,e)}warning(...e){this._doLog(n.WARN,e)}error(...e){this._doLog(n.ERROR,e)}_doLog(e,t){if(!(e>this.level))if(1===t.length&&(t=t[0]),this.extHandler)this.extHandler(r[e],t);else switch(e){case n.DEBUG:console.debug(t);break;case n.INFO:console.info(t);break;case n.WARN:console.warn(t);break;case n.ERROR:console.error(t);break;default:console.log(t)}}}const n={DEBUG:3,INFO:2,WARN:1,ERROR:0},r={3:"DEBUG",2:"INFO ",1:"WARN ",0:"ERROR"};function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s,o={exports:{}};function l(){if(s)return o.exports;s=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}o.exports=i,o.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,s),r(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}m(e,t,s,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&m(e,"error",t,n)}(e,i,{once:!0})})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var l=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function u(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,s,o,l;if(a(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=u(e))>0&&o.length>i&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,l=c,console&&console.warn&&console.warn(l)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=h.bind(r);return i.listener=n,r.wrapFn=i,i}function f(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function _(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function m(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(s){r.once&&e.removeEventListener(t,i),n(s)})}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return l},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");l=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return u(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,s=this._events;if(void 0!==s)i=i&&void 0===s.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var l=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw l.context=o,l}var a=s[e];if(void 0===a)return!1;if("function"==typeof a)n(a,this,t);else{var u=a.length,c=p(a,u);for(r=0;r<u;++r)n(c[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return a(t),this.on(e,d(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,d(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,i,s,o;if(a(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,s=Object.keys(n);for(r=0;r<s.length;++r)"removeListener"!==(i=s[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return f(this,e,!0)},i.prototype.rawListeners=function(e){return f(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):_.call(e,t)},i.prototype.listenerCount=_,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},o.exports}var a=i(l());class u extends Error{constructor(e){super(),this.name="MediaNotPrepared",this.message=e}}class c extends Error{constructor(e){super(),this.name="NotReady",this.message=e}}class h extends Error{constructor(e){super(),this.name="InvalidMediaDevice",this.message=e}}class d extends Error{constructor(e,t){super(),this.name="InvalidOptions",this.param=e,this.message=t}}class f extends Error{constructor(e){super(),this.name="InvalidParameter",this.message=e}}class _ extends Error{constructor(e){super(e),this.name="NoActiveSession"}}class p extends Error{constructor(){super(),this.name="UnableToConnect"}}class m extends Error{constructor(e){super(),this.name="NotAllowed",this.message=e}}class g extends Error{constructor(){super(),this.name="EventServiceNotConnected"}}function v(){let e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function y(e){const t=Math.floor(e/1e3);let n="";return t/86400>=1&&(n=n+Math.floor(t/86400)+"d "),t/3600>=1&&(n=n+Math.floor(t/3600)%24+"h "),t>=0?(n=n+("00"+Math.floor(t/60)%60).slice(-2)+":",n+=("00"+t%60).slice(-2)):n="00:00",n}function T(){return-1!==(navigator.userAgent.indexOf("Opera")||navigator.userAgent.indexOf("OPR"))}function b(){return-1!==navigator.userAgent.indexOf("Chrome")}function S(){return-1!==navigator.userAgent.indexOf("Firefox")}function C(){return-1!==navigator.userAgent.indexOf("Safari")}const E=/^[A-Za-z0-9\-.!%*_+`'~]+$/,A={"&":"&","<":"<",">":">",'"':""","'":"'","\r":" ","\n":" "};function w(e){if(!e)return[];if("object"!=typeof e||Array.isArray(e))throw new TypeError("Invalid setHeader argument: expected an object, got "+typeof e);return Object.entries(e).map(([e,t])=>{if(!E.test(e))throw new TypeError(`Invalid SIP header name: "${e}"`);return`${e}: ${String(t).replace(/[&<>"'\r\n]/g,e=>A[e])}`})}class R{constructor(e,t,n){this.socket=t,this._owner=e,this._request=n,this._handled=!1,this.data=n.data}resolve(e=null){this._assertSingleRequest();try{this.socket.send(JSON.stringify({type:"_ACK",id:this._request.id,data:e}))}catch(e){this._owner.log.warning(`Unable to resolve request ${this._request.id}: ${e}`)}}reject(e=null){this._assertSingleRequest();try{this.socket.send(JSON.stringify({type:"_NACK",id:this._request.id,reason:e}))}catch(e){this._owner.log.warning(`Unable to reject request ${this._request.id}: ${e}`)}}_assertSingleRequest(){if(this._handled)throw new m(`Request ${this._request.id} already fulfilled`);this._handled=!0}}class I extends a{constructor(e=null){super(),this.log=e||new t(n.INFO),this._pendingRequests=[]}receiveMessage(e,t){let n;this.log.debug("Received message: "+t);try{n=JSON.parse(t)}catch(e){return void this.log.warning("Unable to parse message: "+t)}if(n.hasOwnProperty("type")&&n.hasOwnProperty("id")){if("_ACK"===n.type||"_NACK"===n.type){const e=this.findPendingRequest(n.id);return e?("_ACK"===n.type?(this.log.debug(`Received ACK with id=${n.id}`),e.resolve(n.data)):"_NACK"===n.type&&(this.log.debug(`Received NACK with id=${n.id}`),e.reject(n.reason)),void this.removePendingRequest(n.id)):void this.log.warning(`Received message with invalid request id: ${n.id} - timed out?`)}if("_PING"===n.type)return this.log.debug("Received ping, sending pong (ACK)"),void e.send(JSON.stringify({type:"_ACK",id:n.id,data:"pong"}));this.log.debug(`Received new request of type '${n.type}' with id=${n.id}`),this.emit(n.type,new R(this,e,n))||(this.log.warning("Received request with no listeners, rejecting"),e.send(JSON.stringify({type:"_NACK",id:n.id,reason:"No handlers for that request type"})))}else this.log.warning(`Invalid message received: ${n} - missing type or id`)}sendRequest(e,t,n={}){if(!e||!t)throw new f("You must specify socket and request type");let r={type:t,id:v(),data:n};this.log.debug(`Sending request type '${t}' with id ${r.id}`);try{e.send(JSON.stringify(r))}catch(e){return this.log.warning(`Unable to send request ${r.id} socket error: ${e}`),new Promise(function(t,n){n(`Unable to send request: ${e}`)})}const i=this;return new Promise(function(e,t){i._pendingRequests.push({request:r,resolve:e,reject:t,timeoutObj:setTimeout(function(){i.log.info(`Timeout on request ${r.id}, rejecting!`),i.removePendingRequest(r.id),t("Request timed out")},1e4)})})}ping(e){return this.log.debug("Sending ping"),this.sendRequest(e,"_PING")}removePendingRequest(e){for(let t in this._pendingRequests)if(this._pendingRequests[t].request.id===e)return clearTimeout(this._pendingRequests[t].timeoutObj),this._pendingRequests.splice(t,1),this.log.debug(`Removed request id: ${e}`),!0;return this.log.warning(`Unable to remove request ${e} => not found`),!1}findPendingRequest(e){for(let t of this._pendingRequests)if(t.request.id===e)return t;return null}}const O=1+Math.random();class N{constructor(e,t,n){this.id=e,this.specification=t,this.callback=n}doCallback(e,t){return this.callback.apply(e,[t])}}class k{constructor(e=null){this._socket=null,this._previousSubscriptions=[],this._activeSubscriptions=[],this._pingTimerObj=null,this._autoReconnect=!1,this._reconnectRetrySeconds=O,this.log=e||new t(LOGLVL.ERROR),this._requestor=new I(this.log),this._requestor.on("event",e=>{this._handleIncomingEvent(e)})}connect(e=null){return e||(e="wss://esvc.telegenta.com/"),this._serverAddress=e,this._previousSubscriptions=[],this._activeSubscriptions=[],this._connectServer()}disconnect(){if(1!==this._socket.readyState)throw new g;this._activeSubscriptions=[],this._autoReconnect=!1,this._socket.close()}isConnected(){return!!this._socket&&1===this._socket.readyState}subscribe(e,t){if(!e||!t)throw new f("You must specify both event spec and callback function");if(!e.hasOwnProperty("event_name"))throw new f("Your event specification must contain event name");if(!this.isConnected())throw new g;const n=this;return new Promise(function(r,i){n._requestor.sendRequest(n._socket,"subscribe",e).then(function(i){n.log.debug(`Subscription to '${e.event_name}' was successful, ID = ${i}`),n._activeSubscriptions.push(new N(i,e,t)),r(i)},function(t){n.log.warning(`Subscription to '${e.event_name}' failed: ${t}`),i(t)})})}unsubscribe(e){if(!e)throw new f("You must specify subscription id");if(!this.isConnected())throw new g;this.log.info("Unsubscribe id: "+e);const t=this;return new Promise(function(n,r){t._requestor.sendRequest(t._socket,"unsubscribe",{id:e}).then(r=>{t.log.info(`Unsubscribe to '${e}' was successful`),t._removeSubscription(e),n(r)},n=>{t.log.warning(`Remote unsubscribe to '${e}' failed: ${n}`),r(n)})})}fireEvent(e,t){if(!this.isConnected())throw new g;return new Promise((n,r)=>{this._requestor.sendRequest(this._socket,e,t).then(t=>{this.log.info(`Event ${e} was successful`),n(t)},t=>{this.log.warning(`Event ${e} failed: ${t}`),r(t)})})}_removeSubscription(e){for(let t in this._activeSubscriptions)if(this._activeSubscriptions[t].id===e)return this.log.debug(`Removed local subscription: ${e}`),this._activeSubscriptions.splice(t,1),!0;return this.log.warning(`Unable to remove subscription ${e} locally, not found?`),!1}_connectServer(){this.log.info("Connecting to event server: "+this._serverAddress);const e=this;return new Promise(function(t,n){if(e._socket)switch(e._socket.readyState){case 0:return void n("Unable to connect, already connecting");case 1:return void n("Unable to connect, already connected");case 2:return void n("Unable to connect, socket is still closing")}e._socket=new WebSocket(e._serverAddress);let r=!1;e._socket.addEventListener("open",function(){e.log.info("Successfully connected to event service"),r=!0,e._autoReconnect=!0,e._reconnectRetrySeconds=O,e._socket.addEventListener("message",function(t){e._requestor.receiveMessage(e._socket,t.data)}),clearTimeout(e._pingTimerObj),e._pingTimerObj=setInterval(function(){e._requestor.ping(e._socket).then(function(){},function(t){e.log.warning("Ping failed: "+t),e._reconnectServer()})},5e4),e._previousSubscriptions=e._activeSubscriptions,e._activeSubscriptions=[];for(let t of e._previousSubscriptions)e.subscribe(t.specification,t.callback).catch(function(n){e.log.error(`Resubscribing to ${t.specification.event_name} failed: ${n}`)});t()}),e._socket.addEventListener("close",function(){e.log.info("Disconnected from event service"),clearTimeout(e._pingTimerObj),e._reconnectServer()}),e._socket.addEventListener("error",function(t){e.log.error("Websocket connection error"),r||n("Unable to connect: "+t)})})}_reconnectServer(){if(this._autoReconnect){const e=Math.floor(this._reconnectRetrySeconds);this.log.info(`Reconnecting in ${e} secs`);const t=this;setTimeout(function(){t._connectServer().then(function(){t.log.info("Reconnect attempt successful")},function(){t.log.warning("Reconnect attempt failed")}),t._reconnectRetrySeconds<=300&&(t._reconnectRetrySeconds=2*t._reconnectRetrySeconds)},1e3*t._reconnectRetrySeconds)}else this.log.info("Auto reconnect disabled (disconnecting?)")}_handleIncomingEvent(e){const t=e.data.subscription_id;for(let n of this._activeSubscriptions)if(n.id===t){this.log.debug(`Received event for subcription id ${n.id} payload: `+JSON.stringify(e.data.payload));try{n.callback(e.data.payload)}catch(t){this.log.warning(`Callback had unhandled exception ${t}`),e.resolve()}return void e.resolve()}e.reject(`Invalid subscription id for event: ${t}`)}}var D,x,U,P,M={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.1",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};function q(){if(x)return D;x=1;var e=M;return D={USER_AGENT:"".concat(e.title," ").concat(e.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}}function L(){if(P)return U;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if("function"!=typeof t&&null!==t)throw new 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&&l(e,t)}function r(t){var n=o();return function(){var r,i=a(t);if(n){var s=a(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)},i(e)}function s(e,t,n){return s=o()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&l(i,n.prototype),i},s.apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}function l(e,t){return l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},l(e,t)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}P=1;var u=function(e){n(s,e);var i=r(s);function s(e,n){var r;return t(this,s),(r=i.call(this)).code=1,r.name="CONFIGURATION_ERROR",r.parameter=e,r.value=n,r.message=r.value?"Invalid value ".concat(JSON.stringify(r.value),' for parameter "').concat(r.parameter,'"'):"Missing parameter: ".concat(r.parameter),r}return s}(i(Error)),c=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=2,n.name="INVALID_STATE_ERROR",n.status=e,n.message="Invalid status: ".concat(e),n}return s}(i(Error)),h=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=3,n.name="NOT_SUPPORTED_ERROR",n.message=e,n}return s}(i(Error)),d=function(e){n(s,e);var i=r(s);function s(e){var n;return t(this,s),(n=i.call(this)).code=4,n.name="NOT_READY_ERROR",n.message=e,n}return s}(i(Error));return U={ConfigurationError:u,InvalidStateError:c,NotSupportedError:h,NotReadyError:d}}var H,F,j,G,$,B,W,V={};function z(){if(F)return H;function e(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 t(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}F=1;var n=Y(),r=K();return H=function(){function e(t,r,i){if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!(t&&t instanceof n))throw new TypeError('missing or invalid "uri" parameter');for(var s in this._uri=t,this._parameters={},this.display_name=r,i)Object.prototype.hasOwnProperty.call(i,s)&&this.setParam(s,i[s])}return t(e,null,[{key:"parse",value:function(e){return-1!==(e=r.parse(e,"Name_Addr_Header"))?e:void 0}}]),t(e,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?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())}},{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?'"'.concat(this._quote(this._display_name),'" '):"";for(var t in e+="<".concat(this._uri.toString(),">"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(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=0===e?"0":e}}]),e}()}function K(){return G||(G=1,j=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:a,DIGIT:u,ALPHA:c,HEXDIG:h,WSP:d,OCTET:f,DQUOTE:_,SP:p,HTAB:m,alphanum:g,reserved:v,unreserved:y,mark:T,escaped:b,LWS:S,SWS:C,HCOLON:E,TEXT_UTF8_TRIM:A,TEXT_UTF8char:w,UTF8_NONASCII:R,UTF8_CONT:I,LHEX:function(){var e;null===(e=u())&&(/^[a-f]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-f]")));return e},token:O,token_nodot:N,separators:function(){var e;40===t.charCodeAt(i)?(e="(",i++):(e=null,l('"("'));null===e&&(41===t.charCodeAt(i)?(e=")",i++):(e=null,l('")"')),null===e&&(60===t.charCodeAt(i)?(e="<",i++):(e=null,l('"<"')),null===e&&(62===t.charCodeAt(i)?(e=">",i++):(e=null,l('">"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","')),null===e&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(92===t.charCodeAt(i)?(e="\\",i++):(e=null,l('"\\\\"')),null===e&&null===(e=_())&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(123===t.charCodeAt(i)?(e="{",i++):(e=null,l('"{"')),null===e&&(125===t.charCodeAt(i)?(e="}",i++):(e=null,l('"}"')),null===e&&null===(e=p())&&(e=m()))))))))))))))));return e},word:k,STAR:D,SLASH:x,EQUAL:U,LPAREN:P,RPAREN:M,RAQUOT:q,LAQUOT:L,COMMA:H,SEMI:F,COLON:j,LDQUOT:G,RDQUOT:$,comment:function e(){var t,n,r,s;if(s=i,null!==(t=P())){for(n=[],null===(r=B())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=B())&&null===(r=X())&&(r=e());null!==n&&null!==(r=M())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:B,quoted_string:W,quoted_string_clean:V,qdtext:K,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:ie,password:se,hostport:oe,host:le,hostname:ae,domainlabel:ue,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ge,uri_parameters:ve,uri_parameter:ye,transport_param:Te,user_param:be,method_param:Se,ttl_param:Ce,maddr_param:Ee,lr_param:Ae,other_param:we,pname:Re,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:xe,hvalue:Ue,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:Le,hier_part:He,net_path:Fe,abs_path:je,opaque_part:Ge,uric:$e,uric_no_slash:Be,path_segments:We,segment:Ve,param:ze,pchar:Ke,scheme:Ye,authority:Xe,srvr:Je,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:it,CANCELm:st,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:at,REFERm:ut,Method:ct,Status_Line:ht,Status_Code:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=H())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Call_ID:function(){var e,n,r,s,o,a;s=i,o=i,null!==(e=k())?(a=i,64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n&&null!==(r=k())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o);null!==e&&(e=function(e){jn=t.substring(i,e)}(s));null===e&&(i=s);return e},Contact:function(){var e,t,n,r,s,o,l;if(s=i,null===(e=D()))if(o=i,null!==(e=pt())){for(t=[],l=i,null!==(n=H())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=H())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e,t;for(t=jn.multi_header.length,e=0;e<t;e++)if(null===jn.multi_header[e].parsed){jn=null;break}jn=null!==jn?jn.multi_header:-1}());null===e&&(i=s);return e},contact_param:pt,name_addr:mt,display_name:gt,contact_params:vt,c_p_q:yt,c_p_expires:Tt,delta_seconds:bt,qvalue:St,generic_param:Ct,gen_value:Et,Content_Disposition:function(){var e,t,n,r,s,o;if(s=i,null!==(e=At())){for(t=[],o=i,null!==(n=F())&&null!==(r=wt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=wt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},disp_type:At,disp_param:wt,handling_param:Rt,Content_Encoding:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Content_Length:function(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(jn=parseInt(e.join(""))));null===e&&(i=n);return e},Content_Type:function(){var e,n;n=i,null!==(e=It())&&(e=function(e){jn=t.substring(i,e)}(n));null===e&&(i=n);return e},media_type:It,m_type:Ot,discrete_type:Nt,composite_type:kt,extension_token:Dt,x_token:xt,m_subtype:Ut,m_parameter:Pt,m_value:Mt,CSeq:function(){var e,t,n,r;r=i,null!==(e=qt())&&null!==(t=S())&&null!==(n=ct())?e=[e,t,n]:(e=null,i=r);return e},CSeq_value:qt,Expires:function(){var e,t;t=i,null!==(e=bt())&&(e=void(jn=e));null===e&&(i=t);return e},Event:function(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=Lt())){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(a=e[0],e=void(jn.event=a.join("").toLowerCase()));var a;null===e&&(i=s);return e},event_type:Lt,From:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=Ht())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ht())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),e&&jn.setParam("tag",e)}catch(e){jn=-1}}());null===e&&(i=s);return e},from_param:Ht,tag_param:Ft,Max_Forwards:function(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;null!==e&&(e=void(jn=parseInt(e.join(""))));null===e&&(i=n);return e},Min_Expires:function(){var e,t;t=i,null!==(e=bt())&&(e=void(jn=e));null===e&&(i=t);return e},Name_Addr_Header:function(){var e,t,n,r,s,o,l,a,u,c;a=i,u=i,e=[],t=gt();for(;null!==t;)e.push(t),t=gt();if(null!==e)if(null!==(t=L()))if(null!==(n=Q()))if(null!==(r=q())){for(s=[],c=i,null!==(o=F())&&null!==(l=Ct())?o=[o,l]:(o=null,i=c);null!==o;)s.push(o),c=i,null!==(o=F())&&null!==(l=Ct())?o=[o,l]:(o=null,i=c);null!==s?e=[e,t,n,r,s]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;else e=null,i=u;else e=null,i=u;null!==e&&(e=function(){try{jn=new Fn(jn.uri,jn.display_name,jn.params)}catch(e){jn=-1}}());null===e&&(i=a);return e},Proxy_Authenticate:function(){return jt()},challenge:jt,other_challenge:Gt,auth_param:$t,digest_cln:Bt,realm:Wt,realm_value:Vt,domain:zt,URI:Kt,nonce:Yt,nonce_value:Xt,opaque:Jt,stale:Qt,algorithm:Zt,qop_options:en,qop_value:tn,Proxy_Require:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Record_Route:function(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=nn())){for(t=[],l=i,null!==(n=H())&&null!==(r=nn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=H())&&null!==(r=nn())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e,t;for(t=jn.multi_header.length,e=0;e<t;e++)if(null===jn.multi_header[e].parsed){jn=null;break}jn=null!==jn?jn.multi_header:-1}());null===e&&(i=s);return e},rec_route:nn,Reason:function(){var e,n,r,s,o,a,u;o=i,a=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"'));null===e&&(e=O());if(null!==e){for(n=[],u=i,null!==(r=F())&&null!==(s=rn())?r=[r,s]:(r=null,i=u);null!==r;)n.push(r),u=i,null!==(r=F())&&null!==(s=rn())?r=[r,s]:(r=null,i=u);null!==n?e=[e,n]:(e=null,i=a)}else e=null,i=a;null!==e&&(e=function(e,t){if(jn.protocol=t.toLowerCase(),jn.params||(jn.params={}),jn.params.text&&'"'===jn.params.text[0]){var n=jn.params.text;jn.text=n.substring(1,n.length-1),delete jn.params.text}}(0,e[0]));null===e&&(i=o);return e},reason_param:rn,reason_cause:sn,Require:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Route:function(){var e,t,n,r,s,o;if(s=i,null!==(e=on())){for(t=[],o=i,null!==(n=H())&&null!==(r=on())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=on())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},route_param:on,Subscription_State:function(){var e,t,n,r,s,o;if(s=i,null!==(e=ln())){for(t=[],o=i,null!==(n=F())&&null!==(r=an())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=an())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},substate_value:ln,subexp_params:an,event_reason_value:un,Subject:function(){var e;return e=null!==(e=A())?e:""},Supported:function(){var e,t,n,r,s,o;if(s=i,null!==(e=O())){for(t=[],o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=O())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e=null!==e?e:""},To:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=cn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=cn())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){var e=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),e&&jn.setParam("tag",e)}catch(e){jn=-1}}());null===e&&(i=s);return e},to_param:cn,Via:function(){var e,t,n,r,s,o;if(s=i,null!==(e=hn())){for(t=[],o=i,null!==(n=H())&&null!==(r=hn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=H())&&null!==(r=hn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},via_param:hn,via_params:dn,via_ttl:fn,via_maddr:_n,via_received:pn,via_branch:mn,response_port:gn,rport:vn,sent_protocol:yn,protocol_name:Tn,transport:bn,sent_by:Sn,via_host:Cn,via_port:En,ttl:An,WWW_Authenticate:function(){return jt()},Session_Expires:function(){var e,t,n,r,s,o;if(s=i,null!==(e=wn())){for(t=[],o=i,null!==(n=F())&&null!==(r=Rn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Rn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},s_e_expires:wn,s_e_params:Rn,s_e_refresher:In,extension_header:function(){var e,t,n,r;r=i,null!==(e=O())&&null!==(t=E())&&null!==(n=On())?e=[e,t,n]:(e=null,i=r);return e},header_value:On,message_body:function(){var e,t;e=[],t=f();for(;null!==t;)e.push(t),t=f();return e},uuid_URI:function(){var e,n,r;r=i,"uuid:"===t.substr(i,5)?(e="uuid:",i+=5):(e=null,l('"uuid:"'));null!==e&&null!==(n=Nn())?e=[e,n]:(e=null,i=r);return e},uuid:Nn,hex4:kn,hex8:Dn,hex12:xn,Refer_To:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=J())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(){try{jn=new Fn(jn.uri,jn.display_name,jn.params)}catch(e){jn=-1}}());null===e&&(i=s);return e},Replaces:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Un())){for(t=[],o=i,null!==(n=F())&&null!==(r=Pn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Pn())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},call_id:Un,replaces_param:Pn,to_tag:Mn,from_tag:qn,early_flag:Ln};if(void 0!==n){if(void 0===r[n])throw new Error("Invalid rule name: "+e(n)+".")}else n="CRLF";var i=0,s=0,o=[];function l(e){i<s||(i>s&&(s=i,o=[]),o.push(e))}function a(){var e;return"\r\n"===t.substr(i,2)?(e="\r\n",i+=2):(e=null,l('"\\r\\n"')),e}function u(){var e;return/^[0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[0-9]")),e}function c(){var e;return/^[a-zA-Z]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-zA-Z]")),e}function h(){var e;return/^[0-9a-fA-F]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[0-9a-fA-F]")),e}function d(){var e;return null===(e=p())&&(e=m()),e}function f(){var e;return/^[\0-\xFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\0-\\xFF]")),e}function _(){var e;return/^["]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l('["]')),e}function p(){var e;return 32===t.charCodeAt(i)?(e=" ",i++):(e=null,l('" "')),e}function m(){var e;return 9===t.charCodeAt(i)?(e="\t",i++):(e=null,l('"\\t"')),e}function g(){var e;return/^[a-zA-Z0-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[a-zA-Z0-9]")),e}function v(){var e;return 59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))))),e}function y(){var e;return null===(e=g())&&(e=T()),e}function T(){var e;return 45===t.charCodeAt(i)?(e="-",i++):(e=null,l('"-"')),null===e&&(95===t.charCodeAt(i)?(e="_",i++):(e=null,l('"_"')),null===e&&(46===t.charCodeAt(i)?(e=".",i++):(e=null,l('"."')),null===e&&(33===t.charCodeAt(i)?(e="!",i++):(e=null,l('"!"')),null===e&&(126===t.charCodeAt(i)?(e="~",i++):(e=null,l('"~"')),null===e&&(42===t.charCodeAt(i)?(e="*",i++):(e=null,l('"*"')),null===e&&(39===t.charCodeAt(i)?(e="'",i++):(e=null,l('"\'"')),null===e&&(40===t.charCodeAt(i)?(e="(",i++):(e=null,l('"("')),null===e&&(41===t.charCodeAt(i)?(e=")",i++):(e=null,l('")"')))))))))),e}function b(){var e,n,r,s,o;return s=i,o=i,37===t.charCodeAt(i)?(e="%",i++):(e=null,l('"%"')),null!==e&&null!==(n=h())&&null!==(r=h())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=e.join("")),null===e&&(i=s),e}function S(){var e,t,n,r,s,o;for(r=i,s=i,o=i,e=[],t=d();null!==t;)e.push(t),t=d();if(null!==e&&null!==(t=a())?e=[e,t]:(e=null,i=o),null!==(e=null!==e?e:"")){if(null!==(n=d()))for(t=[];null!==n;)t.push(n),n=d();else t=null;null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return null!==e&&(e=" "),null===e&&(i=r),e}function C(){var e;return e=null!==(e=S())?e:""}function E(){var e,n,r,s,o;for(s=i,o=i,e=[],null===(n=p())&&(n=m());null!==n;)e.push(n),null===(n=p())&&(n=m());return null!==e?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=":"),null===e&&(i=s),e}function A(){var e,n,r,s,o,l,a;if(o=i,l=i,null!==(n=w()))for(e=[];null!==n;)e.push(n),n=w();else e=null;if(null!==e){for(n=[],a=i,r=[],s=S();null!==s;)r.push(s),s=S();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(n.push(r),a=i,r=[],s=S();null!==s;)r.push(s),s=S();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==n?e=[e,n]:(e=null,i=l)}else e=null,i=l;return null!==e&&(e=function(e){return t.substring(i,e)}(o)),null===e&&(i=o),e}function w(){var e;return/^[!-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[!-~]")),null===e&&(e=R()),e}function R(){var e;return/^[\x80-\uFFFF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\x80-\\uFFFF]")),e}function I(){var e;return/^[\x80-\xBF]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\x80-\\xBF]")),e}function O(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"'))))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function N(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"'))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function k(){var e,n,r;if(r=i,null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(i)?(n=">",i++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(i)?(n="\\",i++):(n=null,l('"\\\\"')),null===n&&null===(n=_())&&(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(i)?(n="[",i++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(i)?(n="]",i++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(i)?(n="{",i++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(i)?(n="}",i++):(n=null,l('"}"')))))))))))))))))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=g())&&(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null===n&&(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null===n&&(33===t.charCodeAt(i)?(n="!",i++):(n=null,l('"!"')),null===n&&(37===t.charCodeAt(i)?(n="%",i++):(n=null,l('"%"')),null===n&&(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null===n&&(95===t.charCodeAt(i)?(n="_",i++):(n=null,l('"_"')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(96===t.charCodeAt(i)?(n="`",i++):(n=null,l('"`"')),null===n&&(39===t.charCodeAt(i)?(n="'",i++):(n=null,l('"\'"')),null===n&&(126===t.charCodeAt(i)?(n="~",i++):(n=null,l('"~"')),null===n&&(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null===n&&(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null===n&&(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null===n&&(62===t.charCodeAt(i)?(n=">",i++):(n=null,l('">"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(92===t.charCodeAt(i)?(n="\\",i++):(n=null,l('"\\\\"')),null===n&&null===(n=_())&&(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null===n&&(91===t.charCodeAt(i)?(n="[",i++):(n=null,l('"["')),null===n&&(93===t.charCodeAt(i)?(n="]",i++):(n=null,l('"]"')),null===n&&(63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null===n&&(123===t.charCodeAt(i)?(n="{",i++):(n=null,l('"{"')),null===n&&(125===t.charCodeAt(i)?(n="}",i++):(n=null,l('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(e=function(e){return t.substring(i,e)}(r)),null===e&&(i=r),e}function D(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(42===t.charCodeAt(i)?(n="*",i++):(n=null,l('"*"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="*"),null===e&&(i=s),e}function x(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="/"),null===e&&(i=s),e}function U(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="="),null===e&&(i=s),e}function P(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(40===t.charCodeAt(i)?(n="(",i++):(n=null,l('"("')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="("),null===e&&(i=s),e}function M(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(41===t.charCodeAt(i)?(n=")",i++):(n=null,l('")"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=")"),null===e&&(i=s),e}function q(){var e,n,r,s;return r=i,s=i,62===t.charCodeAt(i)?(e=">",i++):(e=null,l('">"')),null!==e&&null!==(n=C())?e=[e,n]:(e=null,i=s),null!==e&&(e=">"),null===e&&(i=r),e}function L(){var e,n,r,s;return r=i,s=i,null!==(e=C())?(60===t.charCodeAt(i)?(n="<",i++):(n=null,l('"<"')),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(e="<"),null===e&&(i=r),e}function H(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=","),null===e&&(i=s),e}function F(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=";"),null===e&&(i=s),e}function j(){var e,n,r,s,o;return s=i,o=i,null!==(e=C())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=C())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=":"),null===e&&(i=s),e}function G(){var e,t,n,r;return n=i,r=i,null!==(e=C())&&null!==(t=_())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function $(){var e,t,n,r;return n=i,r=i,null!==(e=_())&&null!==(t=C())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function B(){var e;return/^[!-']/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[!-']")),null===e&&(/^[*-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[*-[]")),null===e&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\]-~]")),null===e&&null===(e=R())&&(e=S()))),e}function W(){var e,n,r,s,o,l;if(o=i,l=i,null!==(e=C()))if(null!==(n=_())){for(r=[],null===(s=K())&&(s=X());null!==s;)r.push(s),null===(s=K())&&(s=X());null!==r&&null!==(s=_())?e=[e,n,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(e=function(e){return t.substring(i,e)}(o)),null===e&&(i=o),e}function V(){var e,n,r,s,o,l;if(o=i,l=i,null!==(e=C()))if(null!==(n=_())){for(r=[],null===(s=K())&&(s=X());null!==s;)r.push(s),null===(s=K())&&(s=X());null!==r&&null!==(s=_())?e=[e,n,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(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)),null===e&&(i=o),e}function K(){var e;return null===(e=S())&&(33===t.charCodeAt(i)?(e="!",i++):(e=null,l('"!"')),null===e&&(/^[#-[]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[#-[]")),null===e&&(/^[\]-~]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[\\]-~]")),null===e&&(e=R())))),e}function X(){var e,n,r;return r=i,92===t.charCodeAt(i)?(e="\\",i++):(e=null,l('"\\\\"')),null!==e?(/^[\0-\t]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\0-\\t]")),null===n&&(/^[\x0B-\f]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\x0B-\\f]")),null===n&&(/^[\x0E-]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[\\x0E-]")))),null!==n?e=[e,n]:(e=null,i=r)):(e=null,i=r),e}function J(){var e,n,r,s,o,a;return o=i,a=i,null!==(e=Z())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,n,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port}catch(e){jn=-1}}()),null===e&&(i=o),e}function Q(){var e,r,s,o,a,u,c,h;return c=i,h=i,null!==(e=Z())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=null!==(s=ne())?s:"")&&null!==(o=oe())&&null!==(a=ve())&&null!==(u=null!==(u=ke())?u:"")?e=[e,r,s,o,a,u]:(e=null,i=h)):(e=null,i=h),null!==e&&(e=function(){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port,jn.uri_params,jn.uri_headers),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port,delete jn.uri_params,"SIP_URI"===n&&(jn=jn.uri)}catch(e){jn=-1}}()),null===e&&(i=c),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,n,r;return n=i,"sips"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"sips"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=n),e}function te(){var e,n,r;return n=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=n),e}function ne(){var e,n,r,s,o,a;return s=i,o=i,null!==(e=re())?(a=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=se())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?(64===t.charCodeAt(i)?(r="@",i++):(r=null,l('"@"')),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){jn.user=decodeURIComponent(t.substring(i-1,e))}(s)),null===e&&(i=s),e}function re(){var e,t;if(null===(t=y())&&null===(t=b())&&(t=ie()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&null===(t=b())&&(t=ie());else e=null;return e}function ie(){var e;return 38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","')),null===e&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"'))))))))),e}function se(){var e,n,r;for(r=i,e=[],null===(n=y())&&null===(n=b())&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')))))));null!==n;)e.push(n),null===(n=y())&&null===(n=b())&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')),null===n&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')))))));return null!==e&&(e=function(e){jn.password=t.substring(i,e)}(r)),null===e&&(i=r),e}function oe(){var e,n,r,s,o;return s=i,null!==(e=le())?(o=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=ge())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function le(){var e,n;return n=i,null===(e=ae())&&null===(e=pe())&&(e=he()),null!==e&&(e=function(e){return jn.host=t.substring(i,e).toLowerCase(),jn.host}(n)),null===e&&(i=n),e}function ae(){var e,n,r,s,o,a;for(s=i,o=i,e=[],a=i,null!==(n=ue())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r?n=[n,r]:(n=null,i=a)):(n=null,i=a);null!==n;)e.push(n),a=i,null!==(n=ue())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r?n=[n,r]:(n=null,i=a)):(n=null,i=a);return null!==e&&null!==(n=ce())?(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==(r=null!==r?r:"")?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){return jn.host_type="domain",t.substring(i,e)}(s)),null===e&&(i=s),e}function ue(){var e,n,r,s;if(s=i,null!==(e=g())){for(n=[],null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==r;)n.push(r),null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==n?e=[e,n]:(e=null,i=s)}else e=null,i=s;return e}function ce(){var e,n,r,s;if(s=i,null!==(e=c())){for(n=[],null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==r;)n.push(r),null===(r=g())&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(95===t.charCodeAt(i)?(r="_",i++):(r=null,l('"_"'))));null!==n?e=[e,n]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,n,r,s,o;return s=i,o=i,91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null!==e&&null!==(n=de())?(93===t.charCodeAt(i)?(r="]",i++):(r=null,l('"]"')),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){return jn.host_type="IPv6",t.substring(i,e)}(s)),null===e&&(i=s),e}function de(){var e,n,r,s,o,a,u,c,h,d,f,_,p,m,g,v;return m=i,g=i,null!==(e=fe())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?(58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=fe())?(58===t.charCodeAt(i)?(d=":",i++):(d=null,l('":"')),null!==d&&null!==(f=fe())?(58===t.charCodeAt(i)?(_=":",i++):(_=null,l('":"')),null!==_&&null!==(p=_e())?e=[e,n,r,s,o,a,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=fe())?(58===t.charCodeAt(i)?(f=":",i++):(f=null,l('":"')),null!==f&&null!==(_=_e())?e=[e,n,r,s,o,a,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=_e())?e=[e,n,r,s,o,a,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=_e())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=_e())?e=[e,n,r,s,o,a]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?(58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=_e())?e=[e,n,r,s]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=_e())?e=[e,n]:(e=null,i=g),null===e&&(g=i,"::"===t.substr(i,2)?(e="::",i+=2):(e=null,l('"::"')),null!==e&&null!==(n=fe())?e=[e,n]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===t.substr(i,2)?(n="::",i+=2):(n=null,l('"::"')),null!==n&&null!==(r=fe())?(58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=fe())?(58===t.charCodeAt(i)?(d=":",i++):(d=null,l('":"')),null!==d&&null!==(f=_e())?e=[e,n,r,s,o,a,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?("::"===t.substr(i,2)?(r="::",i+=2):(r=null,l('"::"')),null!==r&&null!==(s=fe())?(58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?(58===t.charCodeAt(i)?(h=":",i++):(h=null,l('":"')),null!==h&&null!==(d=_e())?e=[e,n,r,s,o,a,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?("::"===t.substr(i,2)?(s="::",i+=2):(s=null,l('"::"')),null!==s&&null!==(o=fe())?(58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?(58===t.charCodeAt(i)?(c=":",i++):(c=null,l('":"')),null!==c&&null!==(h=_e())?e=[e,n,r,s,o,a,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?("::"===t.substr(i,2)?(o="::",i+=2):(o=null,l('"::"')),null!==o&&null!==(a=fe())?(58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=_e())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?("::"===t.substr(i,2)?(a="::",i+=2):(a=null,l('"::"')),null!==a&&null!==(u=_e())?e=[e,n,r,s,o,a,u]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?(v=i,58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?a=[a,u]:(a=null,i=v),null!==(a=null!==a?a:"")?("::"===t.substr(i,2)?(u="::",i+=2):(u=null,l('"::"')),null!==u&&null!==(c=fe())?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(v=i,58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?n=[n,r]:(n=null,i=v),null!==(n=null!==n?n:"")?(v=i,58===t.charCodeAt(i)?(r=":",i++):(r=null,l('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=v),null!==(r=null!==r?r:"")?(v=i,58===t.charCodeAt(i)?(s=":",i++):(s=null,l('":"')),null!==s&&null!==(o=fe())?s=[s,o]:(s=null,i=v),null!==(s=null!==s?s:"")?(v=i,58===t.charCodeAt(i)?(o=":",i++):(o=null,l('":"')),null!==o&&null!==(a=fe())?o=[o,a]:(o=null,i=v),null!==(o=null!==o?o:"")?(v=i,58===t.charCodeAt(i)?(a=":",i++):(a=null,l('":"')),null!==a&&null!==(u=fe())?a=[a,u]:(a=null,i=v),null!==(a=null!==a?a:"")?(v=i,58===t.charCodeAt(i)?(u=":",i++):(u=null,l('":"')),null!==u&&null!==(c=fe())?u=[u,c]:(u=null,i=v),null!==(u=null!==u?u:"")?("::"===t.substr(i,2)?(c="::",i+=2):(c=null,l('"::"')),null!==c?e=[e,n,r,s,o,a,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(e=function(e){return jn.host_type="IPv6",t.substring(i,e)}(m)),null===e&&(i=m),e}function fe(){var e,t,n,r,s;return s=i,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,n,r,s;return s=i,null!==(e=fe())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n&&null!==(r=fe())?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),null===e&&(e=pe()),e}function pe(){var e,n,r,s,o,a,u,c,h;return c=i,h=i,null!==(e=me())?(46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null!==n&&null!==(r=me())?(46===t.charCodeAt(i)?(s=".",i++):(s=null,l('"."')),null!==s&&null!==(o=me())?(46===t.charCodeAt(i)?(a=".",i++):(a=null,l('"."')),null!==a&&null!==(u=me())?e=[e,n,r,s,o,a,u]:(e=null,i=h)):(e=null,i=h)):(e=null,i=h)):(e=null,i=h),null!==e&&(e=function(e){return jn.host_type="IPv4",t.substring(i,e)}(c)),null===e&&(i=c),e}function me(){var e,n,r,s;return s=i,"25"===t.substr(i,2)?(e="25",i+=2):(e=null,l('"25"')),null!==e?(/^[0-5]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[0-5]")),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,50===t.charCodeAt(i)?(e="2",i++):(e=null,l('"2"')),null!==e?(/^[0-4]/.test(t.charAt(i))?(n=t.charAt(i),i++):(n=null,l("[0-4]")),null!==n&&null!==(r=u())?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,49===t.charCodeAt(i)?(e="1",i++):(e=null,l('"1"')),null!==e&&null!==(n=u())&&null!==(r=u())?e=[e,n,r]:(e=null,i=s),null===e&&(s=i,/^[1-9]/.test(t.charAt(i))?(e=t.charAt(i),i++):(e=null,l("[1-9]")),null!==e&&null!==(n=u())?e=[e,n]:(e=null,i=s),null===e&&(e=u())))),e}function ge(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),null===e&&(i=o),e}function ve(){var e,n,r,s;for(e=[],s=i,59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=ye())?n=[n,r]:(n=null,i=s);null!==n;)e.push(n),s=i,59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null!==n&&null!==(r=ye())?n=[n,r]:(n=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=be())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=Ae())&&(e=we()),e}function Te(){var e,n,r,s,o;return r=i,s=i,"transport="===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"transport="')),null!==e?("udp"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"udp"')),null===n&&("tcp"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"tcp"')),null===n&&("sctp"===t.substr(i,4).toLowerCase()?(n=t.substr(i,4),i+=4):(n=null,l('"sctp"')),null===n&&("tls"===t.substr(i,3).toLowerCase()?(n=t.substr(i,3),i+=3):(n=null,l('"tls"')),null===n&&(n=O())))),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.transport=o.toLowerCase())),null===e&&(i=r),e}function be(){var e,n,r,s,o;return r=i,s=i,"user="===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"user="')),null!==e?("phone"===t.substr(i,5).toLowerCase()?(n=t.substr(i,5),i+=5):(n=null,l('"phone"')),null===n&&("ip"===t.substr(i,2).toLowerCase()?(n=t.substr(i,2),i+=2):(n=null,l('"ip"')),null===n&&(n=O())),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.user=o.toLowerCase())),null===e&&(i=r),e}function Se(){var e,n,r,s,o;return r=i,s=i,"method="===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"method="')),null!==e&&null!==(n=ct())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.method=o)),null===e&&(i=r),e}function Ce(){var e,n,r,s,o;return r=i,s=i,"ttl="===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"ttl="')),null!==e&&null!==(n=An())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.params||(jn.params={}),e=void(jn.params.ttl=o)),null===e&&(i=r),e}function Ee(){var e,n,r,s,o;return r=i,s=i,"maddr="===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"maddr="')),null!==e&&null!==(n=le())?e=[e,n]:(e=null,i=s),null!==e&&(o=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.maddr=o)),null===e&&(i=r),e}function Ae(){var e,n,r,s,o,a;return s=i,o=i,"lr"===t.substr(i,2).toLowerCase()?(e=t.substr(i,2),i+=2):(e=null,l('"lr"')),null!==e?(a=i,61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=O())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.lr=void 0)),null===e&&(i=s),e}function we(){var e,n,r,s,o,a,u,c;return s=i,o=i,null!==(e=Re())?(a=i,61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=Ie())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(u=e[0],c=e[1],jn.uri_params||(jn.uri_params={}),c=void 0===c?void 0:c[1],e=void(jn.uri_params[u.toLowerCase()]=c)),null===e&&(i=s),e}function Re(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Ie(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=y())&&(e=b()),e}function Ne(){var e;return 91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')))))))),e}function ke(){var e,n,r,s,o,a,u;if(a=i,63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null!==e)if(null!==(n=De())){for(r=[],u=i,38===t.charCodeAt(i)?(s="&",i++):(s=null,l('"&"')),null!==s&&null!==(o=De())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,38===t.charCodeAt(i)?(s="&",i++):(s=null,l('"&"')),null!==s&&null!==(o=De())?s=[s,o]:(s=null,i=u);null!==r?e=[e,n,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function De(){var e,n,r,s,o,a,u;return s=i,o=i,null!==(e=xe())?(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null!==n&&null!==(r=Ue())?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[0],u=e[2],a=a.join("").toLowerCase(),u=u.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(u):jn.uri_headers[a]=[u])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=Pe())&&null===(t=y())&&(t=b()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=y())&&(t=b());else e=null;return e}function Ue(){var e,t;for(e=[],null===(t=Pe())&&null===(t=y())&&(t=b());null!==t;)e.push(t),null===(t=Pe())&&null===(t=y())&&(t=b());return e}function Pe(){var e;return 91===t.charCodeAt(i)?(e="[",i++):(e=null,l('"["')),null===e&&(93===t.charCodeAt(i)?(e="]",i++):(e=null,l('"]"')),null===e&&(47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')))))))),e}function Me(){var e,t,n,r,s,o;return o=i,null!==(e=ct())&&null!==(t=p())&&null!==(n=qe())&&null!==(r=p())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function qe(){var e;return null===(e=Q())&&(e=Le()),e}function Le(){var e,n,r,s;return s=i,null!==(e=Ye())?(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null!==n?(null===(r=He())&&(r=Ge()),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function He(){var e,n,r,s,o;return s=i,null===(e=Fe())&&(e=je()),null!==e?(o=i,63===t.charCodeAt(i)?(n="?",i++):(n=null,l('"?"')),null!==n&&null!==(r=Ze())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function Fe(){var e,n,r,s;return s=i,"//"===t.substr(i,2)?(e="//",i+=2):(e=null,l('"//"')),null!==e&&null!==(n=Xe())&&null!==(r=null!==(r=je())?r:"")?e=[e,n,r]:(e=null,i=s),e}function je(){var e,n,r;return r=i,47===t.charCodeAt(i)?(e="/",i++):(e=null,l('"/"')),null!==e&&null!==(n=We())?e=[e,n]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Be())){for(t=[],n=$e();null!==n;)t.push(n),n=$e();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function $e(){var e;return null===(e=v())&&null===(e=y())&&(e=b()),e}function Be(){var e;return null===(e=y())&&null===(e=b())&&(59===t.charCodeAt(i)?(e=";",i++):(e=null,l('";"')),null===e&&(63===t.charCodeAt(i)?(e="?",i++):(e=null,l('"?"')),null===e&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))))),e}function We(){var e,n,r,s,o,a;if(o=i,null!==(e=Ve())){for(n=[],a=i,47===t.charCodeAt(i)?(r="/",i++):(r=null,l('"/"')),null!==r&&null!==(s=Ve())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,47===t.charCodeAt(i)?(r="/",i++):(r=null,l('"/"')),null!==r&&null!==(s=Ve())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function Ve(){var e,n,r,s,o,a;for(o=i,e=[],n=Ke();null!==n;)e.push(n),n=Ke();if(null!==e){for(n=[],a=i,59===t.charCodeAt(i)?(r=";",i++):(r=null,l('";"')),null!==r&&null!==(s=ze())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,59===t.charCodeAt(i)?(r=";",i++):(r=null,l('";"')),null!==r&&null!==(s=ze())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function ze(){var e,t;for(e=[],t=Ke();null!==t;)e.push(t),t=Ke();return e}function Ke(){var e;return null===(e=y())&&null===(e=b())&&(58===t.charCodeAt(i)?(e=":",i++):(e=null,l('":"')),null===e&&(64===t.charCodeAt(i)?(e="@",i++):(e=null,l('"@"')),null===e&&(38===t.charCodeAt(i)?(e="&",i++):(e=null,l('"&"')),null===e&&(61===t.charCodeAt(i)?(e="=",i++):(e=null,l('"="')),null===e&&(43===t.charCodeAt(i)?(e="+",i++):(e=null,l('"+"')),null===e&&(36===t.charCodeAt(i)?(e="$",i++):(e=null,l('"$"')),null===e&&(44===t.charCodeAt(i)?(e=",",i++):(e=null,l('","'))))))))),e}function Ye(){var e,n,r,s,o;if(s=i,o=i,null!==(e=c())){for(n=[],null===(r=c())&&null===(r=u())&&(43===t.charCodeAt(i)?(r="+",i++):(r=null,l('"+"')),null===r&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')))));null!==r;)n.push(r),null===(r=c())&&null===(r=u())&&(43===t.charCodeAt(i)?(r="+",i++):(r=null,l('"+"')),null===r&&(45===t.charCodeAt(i)?(r="-",i++):(r=null,l('"-"')),null===r&&(46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')))));null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){jn.scheme=t.substring(i,e)}(s)),null===e&&(i=s),e}function Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){var e,n,r,s;return r=i,s=i,null!==(e=ne())?(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n?e=[e,n]:(e=null,i=s)):(e=null,i=s),null!==(e=null!==e?e:"")&&null!==(n=oe())?e=[e,n]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,n;if(null===(n=y())&&null===(n=b())&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null===n&&(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"')))))))))),null!==n)for(e=[];null!==n;)e.push(n),null===(n=y())&&null===(n=b())&&(36===t.charCodeAt(i)?(n="$",i++):(n=null,l('"$"')),null===n&&(44===t.charCodeAt(i)?(n=",",i++):(n=null,l('","')),null===n&&(59===t.charCodeAt(i)?(n=";",i++):(n=null,l('";"')),null===n&&(58===t.charCodeAt(i)?(n=":",i++):(n=null,l('":"')),null===n&&(64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null===n&&(38===t.charCodeAt(i)?(n="&",i++):(n=null,l('"&"')),null===n&&(61===t.charCodeAt(i)?(n="=",i++):(n=null,l('"="')),null===n&&(43===t.charCodeAt(i)?(n="+",i++):(n=null,l('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=$e();null!==t;)e.push(t),t=$e();return e}function et(){var e,n,r,s,o,a,c,h;if(c=i,h=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"')),null!==e)if(47===t.charCodeAt(i)?(n="/",i++):(n=null,l('"/"')),null!==n){if(null!==(s=u()))for(r=[];null!==s;)r.push(s),s=u();else r=null;if(null!==r)if(46===t.charCodeAt(i)?(s=".",i++):(s=null,l('"."')),null!==s){if(null!==(a=u()))for(o=[];null!==a;)o.push(a),a=u();else o=null;null!==o?e=[e,n,r,s,o]:(e=null,i=h)}else e=null,i=h;else e=null,i=h}else e=null,i=h;else e=null,i=h;return null!==e&&(e=function(e){jn.sip_version=t.substring(i,e)}(c)),null===e&&(i=c),e}function tt(){var e;return"INVITE"===t.substr(i,6)?(e="INVITE",i+=6):(e=null,l('"INVITE"')),e}function nt(){var e;return"ACK"===t.substr(i,3)?(e="ACK",i+=3):(e=null,l('"ACK"')),e}function rt(){var e;return"OPTIONS"===t.substr(i,7)?(e="OPTIONS",i+=7):(e=null,l('"OPTIONS"')),e}function it(){var e;return"BYE"===t.substr(i,3)?(e="BYE",i+=3):(e=null,l('"BYE"')),e}function st(){var e;return"CANCEL"===t.substr(i,6)?(e="CANCEL",i+=6):(e=null,l('"CANCEL"')),e}function ot(){var e;return"REGISTER"===t.substr(i,8)?(e="REGISTER",i+=8):(e=null,l('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===t.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,l('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===t.substr(i,6)?(e="NOTIFY",i+=6):(e=null,l('"NOTIFY"')),e}function ut(){var e;return"REFER"===t.substr(i,5)?(e="REFER",i+=5):(e=null,l('"REFER"')),e}function ct(){var e,n;return n=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=it())&&null===(e=st())&&null===(e=ot())&&null===(e=lt())&&null===(e=at())&&null===(e=ut())&&(e=O()),null!==e&&(e=function(e){return jn.method=t.substring(i,e),jn.method}(n)),null===e&&(i=n),e}function ht(){var e,t,n,r,s,o;return o=i,null!==(e=et())&&null!==(t=p())&&null!==(n=dt())&&null!==(r=p())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=u())&&null!==(t=u())&&null!==(n=u())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,n,r;for(r=i,e=[],null===(n=v())&&null===(n=y())&&null===(n=b())&&null===(n=R())&&null===(n=I())&&null===(n=p())&&(n=m());null!==n;)e.push(n),null===(n=v())&&null===(n=y())&&null===(n=b())&&null===(n=R())&&null===(n=I())&&null===(n=p())&&(n=m());return null!==e&&(e=function(e){jn.reason_phrase=t.substring(i,e)}(r)),null===e&&(i=r),e}function pt(){var e,t,n,r,s,o,l;if(s=i,o=i,null===(e=J())&&(e=mt()),null!==e){for(t=[],l=i,null!==(n=F())&&null!==(r=vt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=vt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function mt(){var e,t,n,r,s;return s=i,null!==(e=null!==(e=gt())?e:"")&&null!==(t=L())&&null!==(n=Q())&&null!==(r=q())?e=[e,t,n,r]:(e=null,i=s),e}function gt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=O())){for(t=[],l=i,null!==(n=S())&&null!==(r=O())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=S())&&null!==(r=O())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null===e&&(e=V()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function vt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,n,r,s,o,a;return s=i,o=i,"q"===t.substr(i,1).toLowerCase()?(e=t.substr(i,1),i++):(e=null,l('"q"')),null!==e&&null!==(n=U())&&null!==(r=St())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,n,r,s,o,a;return s=i,o=i,"expires"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"expires"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function bt(){var e,t,n;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function St(){var e,n,r,s,o,a,c,h;return a=i,c=i,48===t.charCodeAt(i)?(e="0",i++):(e=null,l('"0"')),null!==e?(h=i,46===t.charCodeAt(i)?(n=".",i++):(n=null,l('"."')),null!==n&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")&&null!==(o=null!==(o=u())?o:"")?n=[n,r,s,o]:(n=null,i=h),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=c)):(e=null,i=c),null!==e&&(e=function(e){return parseFloat(t.substring(i,e))}(a)),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=O())?(o=i,null!==(t=U())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function Et(){var e;return null===(e=O())&&null===(e=le())&&(e=W()),e}function At(){var e;return"render"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"render"')),null===e&&("session"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"session"')),null===e&&("icon"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"icon"')),null===e&&("alert"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"alert"')),null===e&&(e=O())))),e}function wt(){var e;return null===(e=Rt())&&(e=Ct()),e}function Rt(){var e,n,r,s;return s=i,"handling"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"handling"')),null!==e&&null!==(n=U())?("optional"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"optional"')),null===r&&("required"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"required"')),null===r&&(r=O())),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),e}function It(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=x()))if(null!==(n=Ut())){for(r=[],a=i,null!==(s=F())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=F())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"text"')),null===e&&("image"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"image"')),null===e&&("audio"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"audio"')),null===e&&("video"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"video"')),null===e&&("application"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"application"')),null===e&&(e=Dt()))))),e}function kt(){var e;return"message"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"message"')),null===e&&("multipart"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"multipart"')),null===e&&(e=Dt())),e}function Dt(){var e;return null===(e=O())&&(e=xt()),e}function xt(){var e,n,r;return r=i,"x-"===t.substr(i,2).toLowerCase()?(e=t.substr(i,2),i+=2):(e=null,l('"x-"')),null!==e&&null!==(n=O())?e=[e,n]:(e=null,i=r),e}function Ut(){var e;return null===(e=Dt())&&(e=O()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=O())&&null!==(t=U())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=O())&&(e=W()),e}function qt(){var e,t,n,r;if(n=i,null!==(t=u()))for(e=[];null!==t;)e.push(t),t=u();else e=null;return null!==e&&(r=e,e=void(jn.value=parseInt(r.join("")))),null===e&&(i=n),e}function Lt(){var e,n,r,s,o,a;if(o=i,null!==(e=N())){for(n=[],a=i,46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r&&null!==(s=N())?r=[r,s]:(r=null,i=a);null!==r;)n.push(r),a=i,46===t.charCodeAt(i)?(r=".",i++):(r=null,l('"."')),null!==r&&null!==(s=N())?r=[r,s]:(r=null,i=a);null!==n?e=[e,n]:(e=null,i=o)}else e=null,i=o;return e}function Ht(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,n,r,s,o,a;return s=i,o=i,"tag"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,n,r,s,o,a,u,c;if(u=i,"digest"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"Digest"')),null!==e)if(null!==(n=S()))if(null!==(r=Bt())){for(s=[],c=i,null!==(o=H())&&null!==(a=Bt())?o=[o,a]:(o=null,i=c);null!==o;)s.push(o),c=i,null!==(o=H())&&null!==(a=Bt())?o=[o,a]:(o=null,i=c);null!==s?e=[e,n,r,s]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;else e=null,i=u;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=O()))if(null!==(t=S()))if(null!==(n=$t())){for(r=[],a=i,null!==(s=H())&&null!==(o=$t())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=H())&&null!==(o=$t())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function $t(){var e,t,n,r;return r=i,null!==(e=O())&&null!==(t=U())?(null===(n=O())&&(n=W()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Bt(){var e;return null===(e=Wt())&&null===(e=zt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=$t()),e}function Wt(){var e,n,r,s;return s=i,"realm"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"realm"')),null!==e&&null!==(n=U())&&null!==(r=Vt())?e=[e,n,r]:(e=null,i=s),e}function Vt(){var e,t,n;return t=i,null!==(e=V())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function zt(){var e,n,r,s,o,a,u,c,h;if(c=i,"domain"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"domain"')),null!==e)if(null!==(n=U()))if(null!==(r=G()))if(null!==(s=Kt())){if(o=[],h=i,null!==(u=p()))for(a=[];null!==u;)a.push(u),u=p();else a=null;for(null!==a&&null!==(u=Kt())?a=[a,u]:(a=null,i=h);null!==a;){if(o.push(a),h=i,null!==(u=p()))for(a=[];null!==u;)a.push(u),u=p();else a=null;null!==a&&null!==(u=Kt())?a=[a,u]:(a=null,i=h)}null!==o&&null!==(a=$())?e=[e,n,r,s,o,a]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;else e=null,i=c;return e}function Kt(){var e;return null===(e=Le())&&(e=je()),e}function Yt(){var e,n,r,s;return s=i,"nonce"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"nonce"')),null!==e&&null!==(n=U())&&null!==(r=Xt())?e=[e,n,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=V())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){var e,n,r,s,o,a;return s=i,o=i,"opaque"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"opaque"')),null!==e&&null!==(n=U())&&null!==(r=V())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.opaque=a)),null===e&&(i=s),e}function Qt(){var e,n,r,s,o;return s=i,"stale"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"stale"')),null!==e&&null!==(n=U())?(o=i,"true"===t.substr(i,4).toLowerCase()?(r=t.substr(i,4),i+=4):(r=null,l('"true"')),null!==r&&(r=void(jn.stale=!0)),null===r&&(i=o),null===r&&(o=i,"false"===t.substr(i,5).toLowerCase()?(r=t.substr(i,5),i+=5):(r=null,l('"false"')),null!==r&&(r=void(jn.stale=!1)),null===r&&(i=o)),null!==r?e=[e,n,r]:(e=null,i=s)):(e=null,i=s),e}function Zt(){var e,n,r,s,o,a;return s=i,o=i,"algorithm"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"algorithm"')),null!==e&&null!==(n=U())?("md5"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"MD5"')),null===r&&("md5-sess"===t.substr(i,8).toLowerCase()?(r=t.substr(i,8),i+=8):(r=null,l('"MD5-sess"')),null===r&&(r=O())),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,n,r,s,o,a,u,c,h,d;if(c=i,"qop"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"qop"')),null!==e)if(null!==(n=U()))if(null!==(r=G())){if(h=i,null!==(s=tn())){for(o=[],d=i,44===t.charCodeAt(i)?(a=",",i++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,i=d);null!==a;)o.push(a),d=i,44===t.charCodeAt(i)?(a=",",i++):(a=null,l('","')),null!==a&&null!==(u=tn())?a=[a,u]:(a=null,i=d);null!==o?s=[s,o]:(s=null,i=h)}else s=null,i=h;null!==s&&null!==(o=$())?e=[e,n,r,s,o]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;return e}function tn(){var e,n,r;return n=i,"auth-int"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"auth-int"')),null===e&&("auth"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"auth"')),null===e&&(e=O())),null!==e&&(r=e,jn.qop||(jn.qop=[]),e=void jn.qop.push(r.toLowerCase())),null===e&&(i=n),e}function nn(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=mt())){for(t=[],l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,n,r,s,o,a,c;if(o=i,a=i,"cause"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"cause"')),null!==e)if(null!==(n=U())){if(null!==(s=u()))for(r=[];null!==s;)r.push(s),s=u();else r=null;null!==r?e=[e,n,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=o),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=F())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,n;return n=i,"active"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"active"')),null===e&&("pending"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"pending"')),null===e&&("terminated"===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"terminated"')),null===e&&(e=O()))),null!==e&&(e=function(e){jn.state=t.substring(i,e)}(n)),null===e&&(i=n),e}function an(){var e,n,r,s,o,a,u,c;return s=i,o=i,"reason"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"reason"')),null!==e&&null!==(n=U())&&null!==(r=un())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),null===e&&(i=s),null===e&&(s=i,o=i,"expires"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"expires"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(c=e[2])&&(jn.expires=c))),null===e&&(i=s),null===e&&(s=i,o=i,"retry_after"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"retry_after"')),null!==e&&null!==(n=U())&&null!==(r=bt())?e=[e,n,r]:(e=null,i=o),null!==e&&(e=void(void 0!==(u=e[2])&&(jn.retry_after=u))),null===e&&(i=s),null===e&&(e=Ct()))),e}function un(){var e;return"deactivated"===t.substr(i,11).toLowerCase()?(e=t.substr(i,11),i+=11):(e=null,l('"deactivated"')),null===e&&("probation"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"probation"')),null===e&&("rejected"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"rejected"')),null===e&&("timeout"===t.substr(i,7).toLowerCase()?(e=t.substr(i,7),i+=7):(e=null,l('"timeout"')),null===e&&("giveup"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"giveup"')),null===e&&("noresource"===t.substr(i,10).toLowerCase()?(e=t.substr(i,10),i+=10):(e=null,l('"noresource"')),null===e&&("invariant"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"invariant"')),null===e&&(e=O()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=S()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=F())&&null!==(o=dn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=F())&&null!==(o=dn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=gn())&&(e=Ct()),e}function fn(){var e,n,r,s,o,a;return s=i,o=i,"ttl"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"ttl"')),null!==e&&null!==(n=U())&&null!==(r=An())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,n,r,s,o,a;return s=i,o=i,"maddr"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"maddr"')),null!==e&&null!==(n=U())&&null!==(r=le())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,n,r,s,o,a;return s=i,o=i,"received"===t.substr(i,8).toLowerCase()?(e=t.substr(i,8),i+=8):(e=null,l('"received"')),null!==e&&null!==(n=U())?(null===(r=pe())&&(r=de()),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,n,r,s,o,a;return s=i,o=i,"branch"===t.substr(i,6).toLowerCase()?(e=t.substr(i,6),i+=6):(e=null,l('"branch"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.branch=a)),null===e&&(i=s),e}function gn(){var e,n,r,s,o;return s=i,"rport"===t.substr(i,5).toLowerCase()?(e=t.substr(i,5),i+=5):(e=null,l('"rport"')),null!==e?(o=i,null!==(n=U())&&null!==(r=vn())?n=[n,r]:(n=null,i=o),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=s)):(e=null,i=s),e}function vn(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=x())&&null!==(n=O())&&null!==(r=x())&&null!==(s=bn())?e=[e,t,n,r,s]:(e=null,i=o),e}function Tn(){var e,n,r;return n=i,"sip"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"SIP"')),null===e&&(e=O()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=n),e}function bn(){var e,n,r;return n=i,"udp"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"UDP"')),null===e&&("tcp"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"TCP"')),null===e&&("tls"===t.substr(i,3).toLowerCase()?(e=t.substr(i,3),i+=3):(e=null,l('"TLS"')),null===e&&("sctp"===t.substr(i,4).toLowerCase()?(e=t.substr(i,4),i+=4):(e=null,l('"SCTP"')),null===e&&(e=O())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=n),e}function Sn(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=j())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,n;return n=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(e=function(e){jn.host=t.substring(i,e)}(n)),null===e&&(i=n),e}function En(){var e,t,n,r,s,o,l,a;return o=i,l=i,null!==(e=null!==(e=u())?e:"")&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")&&null!==(r=null!==(r=u())?r:"")&&null!==(s=null!==(s=u())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=u())&&null!==(t=null!==(t=u())?t:"")&&null!==(n=null!==(n=u())?n:"")?e=[e,t,n]:(e=null,i=s),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function wn(){var e,t,n;return t=i,null!==(e=bt())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function Rn(){var e;return null===(e=In())&&(e=Ct()),e}function In(){var e,n,r,s,o,a;return s=i,o=i,"refresher"===t.substr(i,9).toLowerCase()?(e=t.substr(i,9),i+=9):(e=null,l('"refresher"')),null!==e&&null!==(n=U())?("uac"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"uac"')),null===r&&("uas"===t.substr(i,3).toLowerCase()?(r=t.substr(i,3),i+=3):(r=null,l('"uas"'))),null!==r?e=[e,n,r]:(e=null,i=o)):(e=null,i=o),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=I())&&(t=S());null!==t;)e.push(t),null===(t=w())&&null===(t=I())&&(t=S());return e}function Nn(){var e,n,r,s,o,a,u,c,h,d,f;return d=i,f=i,null!==(e=Dn())?(45===t.charCodeAt(i)?(n="-",i++):(n=null,l('"-"')),null!==n&&null!==(r=kn())?(45===t.charCodeAt(i)?(s="-",i++):(s=null,l('"-"')),null!==s&&null!==(o=kn())?(45===t.charCodeAt(i)?(a="-",i++):(a=null,l('"-"')),null!==a&&null!==(u=kn())?(45===t.charCodeAt(i)?(c="-",i++):(c=null,l('"-"')),null!==c&&null!==(h=xn())?e=[e,n,r,s,o,a,u,c,h]:(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){jn=t.substring(i+5,e)}(d,e[0])),null===e&&(i=d),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=h())&&null!==(t=h())&&null!==(n=h())&&null!==(r=h())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Un(){var e,n,r,s,o,a;return s=i,o=i,null!==(e=k())?(a=i,64===t.charCodeAt(i)?(n="@",i++):(n=null,l('"@"')),null!==n&&null!==(r=k())?n=[n,r]:(n=null,i=a),null!==(n=null!==n?n:"")?e=[e,n]:(e=null,i=o)):(e=null,i=o),null!==e&&(e=function(e){jn.call_id=t.substring(i,e)}(s)),null===e&&(i=s),e}function Pn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Ct()),e}function Mn(){var e,n,r,s,o,a;return s=i,o=i,"to-tag"===t.substr(i,6)?(e="to-tag",i+=6):(e=null,l('"to-tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,n,r,s,o,a;return s=i,o=i,"from-tag"===t.substr(i,8)?(e="from-tag",i+=8):(e=null,l('"from-tag"')),null!==e&&null!==(n=U())&&null!==(r=O())?e=[e,n,r]:(e=null,i=o),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Ln(){var e,n;return n=i,"early-only"===t.substr(i,10)?(e="early-only",i+=10):(e=null,l('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=n),e}var Hn=Y(),Fn=z(),jn={};if(null===r[n]()||i!==t.length){var Gn=Math.max(i,s),$n=Gn<t.length?t.charAt(Gn):null,Bn=function(){for(var e=1,n=1,r=!1,o=0;o<Math.max(i,s);o++){var l=t.charAt(o);"\n"===l?(r||e++,n=1,r=!1):"\r"===l||"\u2028"===l||"\u2029"===l?(e++,n=1,r=!0):(n++,r=!1)}return{line:e,column:n}}();return new this.SyntaxError(function(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}(o),$n,Gn,Bn.line,Bn.column),-1}return jn},toSource:function(){return this._source},SyntaxError:function(t,n,r,i,s){this.name="SyntaxError",this.expected=t,this.found=n,this.message=function(t,n){var r;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"Expected "+r+" but "+(n?e(n):"end of input")+" found."}(t,n),this.offset=r,this.line=i,this.column=s}};return t.SyntaxError.prototype=Error.prototype,t}()),j}function Y(){if(B)return $;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(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 r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}B=1;var i=q(),s=X(),o=K();return $=function(){function t(e,n,r,s){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=e||i.SIP,this._user=n,this._host=r,this._port=s,o)Object.prototype.hasOwnProperty.call(o,a)&&this.setParam(a,o[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}return r(t,null,[{key:"parse",value:function(e){return-1!==(e=o.parse(e,"SIP_URI"))?e:void 0}}]),r(t,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?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())}},{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[s.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[s.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(s.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=s.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 t(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var t=[],n="".concat(this._scheme,":");for(var r in this._user&&(n+="".concat(s.escapeUser(this._user),"@")),n+=this._host,(this._port||0===this._port)&&(n+=":".concat(this._port)),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(n+=";".concat(r),null!==this._parameters[r]&&(n+="=".concat(this._parameters[r])));for(var i in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,i)){var o,l=e(this._headers[i]);try{for(l.s();!(o=l.n()).done;){var a=o.value;t.push("".concat(i,"=").concat(a))}}catch(e){l.e(e)}finally{l.f()}}return t.length>0&&(n+="?".concat(t.join("&"))),n}},{key:"toAor",value:function(e){var t="".concat(this._scheme,":");return this._user&&(t+="".concat(s.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(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=0===e?e:parseInt(e,10)||null}}]),t}(),$}function X(){if(W)return V;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}W=1;var r=q(),i=Y(),s=K();V.str_utf8_length=function(e){return unescape(encodeURIComponent(e)).length};var o=V.isFunction=function(e){return void 0!==e&&"[object Function]"===Object.prototype.toString.call(e)};V.isString=function(e){return void 0!==e&&"[object String]"===Object.prototype.toString.call(e)},V.isDecimal=function(e){return!isNaN(e)&&parseFloat(e)===parseInt(e,10)},V.isEmpty=function(e){return null===e||""===e||void 0===e||Array.isArray(e)&&0===e.length||"number"==typeof e&&isNaN(e)},V.hasMethods=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var i=0,s=n;i<s.length;i++){var l=s[i];if(o(e[l]))return!1}return!0};var l=V.createRandomToken=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t<e;t++)r+=(Math.random()*n|0).toString(n);return r};V.newTag=function(){return l(10)},V.newUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},V.hostType=function(e){if(e)return-1!==(e=s.parse(e,"host"))?e.host_type:void 0};var a=V.escapeUser=function(e){return encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")};return V.normalizeTarget=function(e,t){if(e){if(e instanceof i)return e;if("string"==typeof e){var n,s,o,l=e.split("@");switch(l.length){case 1:if(!t)return;n=e,s=t;break;case 2:n=l[0],s=l[1];break;default:n=l.slice(0,l.length-1).join("@"),s=l[l.length-1]}return n=n.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(n)&&(n=n.replace(/[-.()]/g,"")),e="".concat(r.SIP,":").concat(a(n),"@").concat(s),(o=i.parse(e))?o:void 0}}else;},V.headerize=function(e){var t,n={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},r=e.toLowerCase().replace(/_/g,"-").split("-"),i="",s=r.length;for(t=0;t<s;t++)0!==t&&(i+="-"),i+=r[t].charAt(0).toUpperCase()+r[t].substring(1);return n[i]&&(i=n[i]),i},V.sipErrorCause=function(e){for(var t in r.SIP_ERROR_CAUSES)if(-1!==r.SIP_ERROR_CAUSES[t].indexOf(e))return r.causes[t];return r.causes.SIP_FAILURE_CODE},V.getRandomTestNetIP=function(){return"192.0.2.".concat((e=1,t=254,Math.floor(Math.random()*(t-e+1)+e)));var e,t},V.calculateMD5=function(e){function t(e,t){return e<<t|e>>>32-t}function n(e,t){var n=2147483648&e,r=2147483648&t,i=1073741824&e,s=1073741824&t,o=(1073741823&e)+(1073741823&t);return i&s?2147483648^o^n^r:i|s?1073741824&o?3221225472^o^n^r:1073741824^o^n^r:o^n^r}function r(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,i,s),o),a)),n(t(e,l),r)}function i(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,i,s),o),a)),n(t(e,l),r)}function s(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,i,s),o),a)),n(t(e,l),r)}function o(e,r,i,s,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,i,s),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,d,f,_,p,m,g;for(a=function(e){for(var t,n=e.length,r=n+8,i=16*((r-r%64)/64+1),s=new Array(i-1),o=0,l=0;l<n;)o=l%4*8,s[t=(l-l%4)/4]=s[t]|e.charCodeAt(l)<<o,l++;return o=l%4*8,s[t=(l-l%4)/4]=s[t]|128<<o,s[i-2]=n<<3,s[i-1]=n>>>29,s}(e=function(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(63&r|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(63&r|128))}return t}(e)),_=1732584193,p=4023233417,m=2562383102,g=271733878,u=0;u<a.length;u+=16)c=_,h=p,d=m,f=g,_=r(_,p,m,g,a[u+0],7,3614090360),g=r(g,_,p,m,a[u+1],12,3905402710),m=r(m,g,_,p,a[u+2],17,606105819),p=r(p,m,g,_,a[u+3],22,3250441966),_=r(_,p,m,g,a[u+4],7,4118548399),g=r(g,_,p,m,a[u+5],12,1200080426),m=r(m,g,_,p,a[u+6],17,2821735955),p=r(p,m,g,_,a[u+7],22,4249261313),_=r(_,p,m,g,a[u+8],7,1770035416),g=r(g,_,p,m,a[u+9],12,2336552879),m=r(m,g,_,p,a[u+10],17,4294925233),p=r(p,m,g,_,a[u+11],22,2304563134),_=r(_,p,m,g,a[u+12],7,1804603682),g=r(g,_,p,m,a[u+13],12,4254626195),m=r(m,g,_,p,a[u+14],17,2792965006),_=i(_,p=r(p,m,g,_,a[u+15],22,1236535329),m,g,a[u+1],5,4129170786),g=i(g,_,p,m,a[u+6],9,3225465664),m=i(m,g,_,p,a[u+11],14,643717713),p=i(p,m,g,_,a[u+0],20,3921069994),_=i(_,p,m,g,a[u+5],5,3593408605),g=i(g,_,p,m,a[u+10],9,38016083),m=i(m,g,_,p,a[u+15],14,3634488961),p=i(p,m,g,_,a[u+4],20,3889429448),_=i(_,p,m,g,a[u+9],5,568446438),g=i(g,_,p,m,a[u+14],9,3275163606),m=i(m,g,_,p,a[u+3],14,4107603335),p=i(p,m,g,_,a[u+8],20,1163531501),_=i(_,p,m,g,a[u+13],5,2850285829),g=i(g,_,p,m,a[u+2],9,4243563512),m=i(m,g,_,p,a[u+7],14,1735328473),_=s(_,p=i(p,m,g,_,a[u+12],20,2368359562),m,g,a[u+5],4,4294588738),g=s(g,_,p,m,a[u+8],11,2272392833),m=s(m,g,_,p,a[u+11],16,1839030562),p=s(p,m,g,_,a[u+14],23,4259657740),_=s(_,p,m,g,a[u+1],4,2763975236),g=s(g,_,p,m,a[u+4],11,1272893353),m=s(m,g,_,p,a[u+7],16,4139469664),p=s(p,m,g,_,a[u+10],23,3200236656),_=s(_,p,m,g,a[u+13],4,681279174),g=s(g,_,p,m,a[u+0],11,3936430074),m=s(m,g,_,p,a[u+3],16,3572445317),p=s(p,m,g,_,a[u+6],23,76029189),_=s(_,p,m,g,a[u+9],4,3654602809),g=s(g,_,p,m,a[u+12],11,3873151461),m=s(m,g,_,p,a[u+15],16,530742520),_=o(_,p=s(p,m,g,_,a[u+2],23,3299628645),m,g,a[u+0],6,4096336452),g=o(g,_,p,m,a[u+7],10,1126891415),m=o(m,g,_,p,a[u+14],15,2878612391),p=o(p,m,g,_,a[u+5],21,4237533241),_=o(_,p,m,g,a[u+12],6,1700485571),g=o(g,_,p,m,a[u+3],10,2399980690),m=o(m,g,_,p,a[u+10],15,4293915773),p=o(p,m,g,_,a[u+1],21,2240044497),_=o(_,p,m,g,a[u+8],6,1873313359),g=o(g,_,p,m,a[u+15],10,4264355552),m=o(m,g,_,p,a[u+6],15,2734768916),p=o(p,m,g,_,a[u+13],21,1309151649),_=o(_,p,m,g,a[u+4],6,4149444226),g=o(g,_,p,m,a[u+11],10,3174756917),m=o(m,g,_,p,a[u+2],15,718787259),p=o(p,m,g,_,a[u+9],21,3951481745),_=n(_,c),p=n(p,h),m=n(m,d),g=n(g,f);return(l(_)+l(p)+l(m)+l(g)).toLowerCase()},V.closeMediaStream=function(n){if(n)try{if(n.getTracks){var r,i=t(n.getTracks());try{for(i.s();!(r=i.n()).done;){r.value.stop()}}catch(e){i.e(e)}finally{i.f()}}else{var s,o=t(n.getAudioTracks());try{for(o.s();!(s=o.n()).done;){s.value.stop()}}catch(e){o.e(e)}finally{o.f()}var l,a=t(n.getVideoTracks());try{for(a.s();!(l=a.n()).done;){l.value.stop()}}catch(e){a.e(e)}finally{a.f()}}}catch(t){"function"!=typeof n.stop&&"object"!==e(n.stop)||n.stop()}},V.cloneArray=function(e){return e&&e.slice()||[]},V.cloneObject=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t},V}var J,Q,Z,ee,te,ne,re,ie={exports:{}};function se(){if(Q)return J;Q=1;var e=1e3,t=60*e,n=60*t,r=24*n,i=7*r,s=365.25*r;function o(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}return J=function(l,a){a=a||{};var u=typeof l;if("string"===u&&l.length>0)return function(o){if((o=String(o)).length>100)return;var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!l)return;var a=parseFloat(l[1]);switch((l[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*s;case"weeks":case"week":case"w":return a*i;case"days":case"day":case"d":return a*r;case"hours":case"hour":case"hrs":case"hr":case"h":return a*n;case"minutes":case"minute":case"mins":case"min":case"m":return a*t;case"seconds":case"second":case"secs":case"sec":case"s":return a*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(l);if("number"===u&&isFinite(l))return a.long?function(i){var s=Math.abs(i);if(s>=r)return o(i,s,r,"day");if(s>=n)return o(i,s,n,"hour");if(s>=t)return o(i,s,t,"minute");if(s>=e)return o(i,s,e,"second");return i+" ms"}(l):function(i){var s=Math.abs(i);if(s>=r)return Math.round(i/r)+"d";if(s>=n)return Math.round(i/n)+"h";if(s>=t)return Math.round(i/t)+"m";if(s>=e)return Math.round(i/e)+"s";return i+"ms"}(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))},J}function oe(){return te||(te=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(ee||(ee=1,Z=function(e){function t(e){let r,i,s,o=null;function l(...e){if(!l.enabled)return;const n=l,i=Number(new Date),s=i-(r||i);n.diff=s,n.prev=r,n.curr=i,r=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,i)=>{if("%%"===r)return"%";o++;const s=t.formatters[i];if("function"==typeof s){const t=e[o];r=s.call(n,t),e.splice(o,1),o--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return l.namespace=e,l.useColors=t.useColors(),l.color=t.selectColor(e),l.extend=n,l.destroy=t.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(i!==t.namespaces&&(i=t.namespaces,s=t.enabled(e)),s),set:e=>{o=e}}),"function"==typeof t.init&&t.init(l),l}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,i=-1,s=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(i=r,s=n,r++):(n++,r++);else{if(-1===i)return!1;r=i+1,s++,n=s}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=se(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}),Z)(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ie,ie.exports)),ie.exports}function le(){if(re)return ne;function e(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)}}re=1;var t=oe(),n="JsSIP";return ne=function(){function r(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),e?(this._debug=t.default("".concat(n,":").concat(e)),this._warn=t.default("".concat(n,":WARN:").concat(e)),this._error=t.default("".concat(n,":ERROR:").concat(e))):(this._debug=t.default(n),this._warn=t.default("".concat(n,":WARN")),this._error=t.default("".concat(n,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}var i,s,o;return i=r,(s=[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}])&&e(i.prototype,s),o&&e(i,o),r}()}var ae,ue,ce,he,de,fe,_e,pe,me,ge,ve,ye,Te,be,Se,Ce,Ee,Ae,we,Re,Ie,Oe={},Ne={},ke={exports:{}};function De(){if(ae)return ke.exports;ae=1;var e=ke.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(e){return e.encoding?"rtpmap:%d %s/%s/%s":e.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(e){return null!=e.address?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(e){return null!=e.subtype?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(e){return"extmap:%d"+(e.direction?"/%s":"%v")+(e["encrypt-uri"]?" %s":"%v")+" %s"+(e.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(e){return null!=e.sessionConfig?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(e){var t="candidate:%s %d %s %d %s %d typ %s";return t+=null!=e.raddr?" raddr %s rport %d":"%v%v",t+=null!=e.tcptype?" tcptype %s":"%v",null!=e.generation&&(t+=" generation %d"),t+=null!=e["network-id"]?" network-id %d":"%v",t+=null!=e["network-cost"]?" network-cost %d":"%v"}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(e){var t="ssrc:%d";return null!=e.attribute&&(t+=" %s",null!=e.value&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(e){return null!=e.maxMessageSize?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(e){return e.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(e){return"imageattr:%s %s %s"+(e.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(e){return"simulcast:%s %s"+(e.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(e){return"ts-refclk:%s"+(null!=e.clksrcExt?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(e){var t="mediaclk:";return t+=null!=e.id?"id=%s %s":"%v%s",t+=null!=e.mediaClockValue?"=%s":"",t+=null!=e.rateNumerator?" rate=%s":"",t+=null!=e.rateDenominator?"/%s":""}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};return Object.keys(e).forEach(function(t){e[t].forEach(function(e){e.reg||(e.reg=/(.*)/),e.format||(e.format="%s")})}),ke.exports}function xe(){return ue||(ue=1,function(e){var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,r){var i=e.name&&e.names;e.push&&!n[e.push]?n[e.push]=[]:i&&!n[e.name]&&(n[e.name]={});var s=e.push?{}:i?n[e.name]:n;!function(e,n,r,i){if(i&&!r)n[i]=t(e[1]);else for(var s=0;s<r.length;s+=1)null!=e[s+1]&&(n[r[s]]=t(e[s+1]))}(r.match(e.reg),s,e.names,e.name),e.push&&n[e.push].push(s)},r=De(),i=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},s=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(i).forEach(function(e){var t=e[0],i=e.slice(2);"m"===t&&(s.push({rtp:[],fmtp:[]}),o=s[s.length-1]);for(var l=0;l<(r[t]||[]).length;l+=1){var a=r[t][l];if(a.reg.test(i))return n(a,o,i)}}),t.media=s,t};var s=function(e,n){var r=n.split(/=(.+)/,2);return 2===r.length?e[r[0]]=t(r[1]):1===r.length&&n.length>1&&(e[r[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(s,{})},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(s,{})})},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):(n=t(e.substring(1,e.length)),r=!0),{scid:n,paused:r}})})}}(Ne)),Ne}function Ue(){if(he)return ce;he=1;var e=De(),t=/%[sdv%]/g,n=function(e){var n=1,r=arguments,i=r.length;return e.replace(t,function(e){if(n>=i)return e;var t=r[n];switch(n+=1,e){case"%%":return"%";case"%s":return String(t);case"%d":return Number(t);case"%v":return""}})},r=function(e,t,r){var i=[e+"="+(t.format instanceof Function?t.format(t.push?r:r[t.name]):t.format)];if(t.names)for(var s=0;s<t.names.length;s+=1){var o=t.names[s];t.name?i.push(r[t.name][o]):i.push(r[t.names[s]])}else i.push(r[t.name]);return n.apply(null,i)},i=["v","o","s","i","u","e","p","c","b","t","r","z","a"],s=["i","c","b","a"];return ce=function(t,n){n=n||{},null==t.version&&(t.version=0),null==t.name&&(t.name=" "),t.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var o=n.outerOrder||i,l=n.innerOrder||s,a=[];return o.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(r(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(r(n,e,t))})})}),t.media.forEach(function(t){a.push(r("m",e.m[0],t)),l.forEach(function(n){e[n].forEach(function(e){e.name in t&&null!=t[e.name]?a.push(r(n,e,t)):e.push in t&&null!=t[e.push]&&t[e.push].forEach(function(t){a.push(r(n,e,t))})})})}),a.join("\r\n")+"\r\n"}}function Pe(){if(de)return Oe;de=1;var e=xe(),t=Ue(),n=De();return Oe.grammar=n,Oe.write=t,Oe.parse=e.parse,Oe.parseParams=e.parseParams,Oe.parseFmtpConfig=e.parseFmtpConfig,Oe.parsePayloads=e.parsePayloads,Oe.parseRemoteCandidates=e.parseRemoteCandidates,Oe.parseImageAttributes=e.parseImageAttributes,Oe.parseSimulcastStreamList=e.parseSimulcastStreamList,Oe}function Me(){if(_e)return fe;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}function n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}(e))||t&&e&&"number"==typeof e.length){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 new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(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 u(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}_e=1;var c=Pe(),h=le(),d=q(),f=X(),_=z(),p=K(),m=new h("SIPMessage"),g=function(){function e(t,n,r,i,s,o){if(l(this,e),!t||!n||!r)return null;i=i||{},this.ua=r,this.headers={},this.method=t,this.ruri=n,this.body=o,this.extraHeaders=f.cloneArray(s),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","<".concat(r.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",d.MAX_FORWARDS);var a=i.to_uri||n,u=i.to_tag?{tag:i.to_tag}:null,c=void 0!==i.to_display_name?i.to_display_name:null;this.to=new _(a,c,u),this.setHeader("to",this.to.toString());var h,p=i.from_uri||r.configuration.uri,m={tag:i.from_tag||f.newTag()};h=void 0!==i.from_display_name?i.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new _(p,h,m),this.setHeader("from",this.from.toString());var g=i.call_id||r.configuration.jssip_id+f.createRandomToken(15);this.call_id=g,this.setHeader("call-id",g);var v=i.cseq||Math.floor(1e4*Math.random());this.cseq=v,this.setHeader("cseq","".concat(v," ").concat(t))}return u(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r<this.extraHeaders.length;r++)n.test(this.extraHeaders[r])&&this.extraHeaders.splice(r,1);this.headers[f.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){var t=this.headers[f.headerize(e)];if(t){if(t[0])return t[0]}else{var n,r=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),i=s(this.extraHeaders);try{for(i.s();!(n=i.n()).done;){var o=n.value;if(r.test(o))return o.substring(o.indexOf(":")+1).trim()}}catch(e){i.e(e)}finally{i.f()}}}},{key:"getHeaders",value:function(e){var t=this.headers[f.headerize(e)],n=[];if(t){var r,i=s(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;n.push(o)}}catch(e){i.e(e)}finally{i.f()}return n}var l,a=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),u=s(this.extraHeaders);try{for(u.s();!(l=u.n()).done;){var c=l.value;a.test(c)&&n.push(c.substring(c.indexOf(":")+1).trim())}}catch(e){u.e(e)}finally{u.f()}return n}},{key:"hasHeader",value:function(e){if(this.headers[f.headerize(e)])return!0;var t,n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=s(this.extraHeaders);try{for(r.s();!(t=r.n()).done;){var i=t.value;if(n.test(i))return!0}}catch(e){r.e(e)}finally{r.f()}return!1}},{key:"parseSDP",value:function(e){return!e&&this.sdp||(this.sdp=c.parse(this.body||"")),this.sdp}},{key:"toString",value:function(){var e="".concat(this.method," ").concat(this.ruri," SIP/2.0\r\n");for(var t in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,t)){var n,r=s(this.headers[t]);try{for(r.s();!(n=r.n()).done;){var i=n.value;e+="".concat(t,": ").concat(i,"\r\n")}}catch(e){r.e(e)}finally{r.f()}}var o,l=s(this.extraHeaders);try{for(l.s();!(o=l.n()).done;){var a=o.value;e+="".concat(a.trim(),"\r\n")}}catch(e){l.e(e)}finally{l.f()}var u=[];switch(this.method){case d.REGISTER:u.push("path","gruu");break;case d.INVITE:this.ua.configuration.session_timers&&u.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&u.push("gruu"),u.push("ice","replaces");break;case d.UPDATE:this.ua.configuration.session_timers&&u.push("timer"),u.push("ice")}u.push("outbound");var c=this.ua.configuration.user_agent||d.USER_AGENT;if(e+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"),e+="Supported: ".concat(u,"\r\n"),e+="User-Agent: ".concat(c,"\r\n"),this.body){var h=f.str_utf8_length(this.body);e+="Content-Length: ".concat(h,"\r\n\r\n"),e+=this.body}else e+="Content-Length: 0\r\n\r\n";return e}},{key:"clone",value:function(){var t=new e(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(e){t.headers[e]=this.headers[e].slice()},this),t.body=this.body,t.extraHeaders=f.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}]),e}(),v=function(e){t(i,e);var n=r(i);function i(e,t,r,s,o){var a;return l(this,i),(a=n.call(this,d.INVITE,e,t,r,s,o)).transaction=null,a}return u(i,[{key:"cancel",value:function(e){this.transaction.cancel(e)}},{key:"clone",value:function(){var e=new i(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){e.headers[t]=this.headers[t].slice()},this),e.body=this.body,e.extraHeaders=f.cloneArray(this.extraHeaders),e.to=this.to,e.from=this.from,e.call_id=this.call_id,e.cseq=this.cseq,e.transaction=this.transaction,e}}]),i}(g),y=function(){function e(){l(this,e),this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}return u(e,[{key:"addHeader",value:function(e,t){var n={raw:t};e=f.headerize(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[f.headerize(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[f.headerize(e)],n=[];if(!t)return[];var r,i=s(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;n.push(o.raw)}}catch(e){i.e(e)}finally{i.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[f.headerize(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=f.headerize(e),this.headers[e]){if(!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var i=p.parse(r,e.replace(/-/g,"_"));return-1===i?(this.headers[e].splice(t,1),void m.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=i,i)}m.debug('not so many "'.concat(e,'" headers present'))}else m.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[f.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp||(this.sdp=c.parse(this.body||"")),this.sdp}},{key:"toString",value:function(){return this.data}}]),e}(),T=function(e){t(i,e);var n=r(i);function i(e){var t;return l(this,i),(t=n.call(this)).ua=e,t.headers={},t.ruri=null,t.transport=null,t.server_transaction=null,t}return u(i,[{key:"reply",value:function(e,t,n,r,i,o){var l=[],a=this.getHeader("To");if(t=t||null,!(e=e||null)||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||d.REASON_PHRASE[e]||"",n=f.cloneArray(n),this.ua.configuration.extra_headers&&(n=n.concat(this.ua.configuration.extra_headers));var u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===d.INVITE&&e>100&&e<=200){var c,h=s(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var _=c.value;u+="Record-Route: ".concat(_,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var p,m=s(this.getHeaders("via"));try{for(m.s();!(p=m.n()).done;){var g=p.value;u+="Via: ".concat(g,"\r\n")}}catch(e){m.e(e)}finally{m.f()}!this.to_tag&&e>100?a+=";tag=".concat(f.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(a+=";tag=".concat(this.to_tag)),u+="To: ".concat(a,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var v,y=s(n);try{for(y.s();!(v=y.n()).done;){var T=v.value;u+="".concat(T.trim(),"\r\n")}}catch(e){y.e(e)}finally{y.f()}switch(this.method){case d.INVITE:this.ua.configuration.session_timers&&l.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&l.push("gruu"),l.push("ice","replaces");break;case d.UPDATE:this.ua.configuration.session_timers&&l.push("timer"),r&&l.push("ice"),l.push("replaces")}if(l.push("outbound"),this.method===d.OPTIONS?(u+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(d.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(d.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(d.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(l,"\r\n"),r){var b=f.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(b,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,i,o)}},{key:"reply_sl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||d.REASON_PHRASE[e]||"";var r,i="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),o=s(n);try{for(o.s();!(r=o.n()).done;){var l=r.value;i+="Via: ".concat(l,"\r\n")}}catch(e){o.e(e)}finally{o.f()}var a=this.getHeader("To");if(!this.to_tag&&e>100?a+=";tag=".concat(f.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(a+=";tag=".concat(this.to_tag)),i+="To: ".concat(a,"\r\n"),i+="From: ".concat(this.getHeader("From"),"\r\n"),i+="Call-ID: ".concat(this.call_id,"\r\n"),i+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),this.ua.configuration.extra_headers){var u,c=s(this.ua.configuration.extra_headers);try{for(c.s();!(u=c.n()).done;){var h=u.value;i+="".concat(h.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}i+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(i)}}]),i}(y);return fe={OutgoingRequest:g,InitialOutgoingInviteRequest:v,IncomingRequest:T,IncomingResponse:function(e){t(i,e);var n=r(i);function i(){var e;return l(this,i),(e=n.call(this)).headers={},e.status_code=null,e.reason_phrase=null,e}return i}(y)}}function qe(){if(me)return pe;function e(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)}}me=1;var t=le(),n=X(),r=new t("DigestAuthentication");return pe=function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._credentials=e,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}var i,s,o;return i=t,s=[{key:"get",value:function(e){switch(e){case"realm":return this._realm;case"ha1":return this._ha1;default:return void r.warn('get() | cannot get "%s" parameter',e)}}},{key:"authenticate",value:function(e,t){var i=e.method,s=e.ruri,o=e.body,l=arguments.length>2&&void 0!==arguments[2]?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("MD5"!==this._algorithm)return r.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return r.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return r.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return r.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return r.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))return r.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=i,this._uri=s,this._cnonce=l||n.createRandomToken(12),this._nc+=1;var a,u,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=n.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(a="".concat(this._method,":").concat(this._uri),u=n.calculateMD5(a),r.debug('authenticate() | using qop=auth [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(u))):"auth-int"===this._qop?(a="".concat(this._method,":").concat(this._uri,":").concat(n.calculateMD5(o||"")),u=n.calculateMD5(a),r.debug('authenticate() | using qop=auth-int [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(u))):null===this._qop&&(a="".concat(this._method,":").concat(this._uri),u=n.calculateMD5(a),r.debug('authenticate() | using qop=null [a2:"%s"]',a),this._response=n.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(u))),r.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}],s&&e(i.prototype,s),o&&e(i,o),t}(),pe}function Le(){if(ve)return ge;ve=1;var e=500;return ge={T1:e,T2:4e3,T4:5e3,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4}}function He(){if(Te)return ye;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(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 r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new 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 o(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=u(t);if(n){var s=u(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return a(t)}(this,r)}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}Te=1;var c=l().EventEmitter,h=le(),d=q(),f=Me(),_=Le(),p=new h("NonInviteClientTransaction"),m=new h("InviteClientTransaction"),g=new h("AckClientTransaction"),v=new h("NonInviteServerTransaction"),y=new h("InviteServerTransaction"),T={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"};return ye={C:T,NonInviteClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).type=T.NON_INVITE_CLIENT,l.id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.ua=e,l.transport=r,l.request=i,l.eventHandlers=o;var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l.ua.newTransaction(a(l)),l}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(T.STATUS_TRYING),this.F=setTimeout(function(){e.timer_F()},_.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){p.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){p.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(T.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 T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e)}else switch(this.state){case T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_COMPLETED),clearTimeout(this.F),408===n?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(function(){t.timer_K()},_.TIMER_K)}}},{key:"C",get:function(){return T}}]),s}(c),InviteClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).type=T.INVITE_CLIENT,l.id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.ua=e,l.transport=r,l.request=i,l.eventHandlers=o,i.transaction=a(l);var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l.ua.newTransaction(a(l)),l}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(T.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!==T.STATUS_ACCEPTED&&(m.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){m.debug("Timer M expired for transaction ".concat(this.id)),this.state===T.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){m.debug("Timer B expired for transaction ".concat(this.id)),this.state===T.STATUS_CALLING&&(this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){m.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(e){var t=this,n=new f.OutgoingRequest(d.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===T.STATUS_PROCEEDING){var t=new f.OutgoingRequest(d.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 T.STATUS_CALLING:this.stateChanged(T.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case T.STATUS_CALLING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},_.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case T.STATUS_CALLING:case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case T.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return T}}]),s}(c),AckClientTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i,o){var l;t(this,s),(l=n.call(this)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.transport=r,l.request=i,l.eventHandlers=o;var a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return r(s,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){g.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return T}}]),s}(c),NonInviteServerTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i){var o;return t(this,s),(o=n.call(this)).type=T.NON_INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=a(o),o.state=T.STATUS_TRYING,e.newTransaction(a(o)),o}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_J",value:function(){v.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,v.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var i=this;if(100===e)switch(this.state){case T.STATUS_TRYING:this.stateChanged(T.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case T.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 T.STATUS_TRYING:case T.STATUS_PROCEEDING:this.stateChanged(T.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())}}},{key:"C",get:function(){return T}}]),s}(c),InviteServerTransaction:function(e){i(s,e);var n=o(s);function s(e,r,i){var o;return t(this,s),(o=n.call(this)).type=T.INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=a(o),o.state=T.STATUS_PROCEEDING,e.newTransaction(a(o)),o.resendProvisionalTimer=null,i.reply(100),o}return r(s,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){y.debug("Timer H expired for transaction ".concat(this.id)),this.state===T.STATUS_COMPLETED&&y.debug("ACK not received, dialog will be terminated"),this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){y.debug("Timer L expired for transaction ".concat(this.id)),this.state===T.STATUS_ACCEPTED&&(this.stateChanged(T.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,y.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(T.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&&this.state===T.STATUS_PROCEEDING)this.transport.send(t)||this.onTransportError(),this.last_response=t;if(e>100&&e<=199&&this.state===T.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){i.resend_provisional()},_.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case T.STATUS_PROCEEDING:this.stateChanged(T.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){i.timer_L()},_.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case T.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699&&this.state===T.STATUS_PROCEEDING)null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(T.STATUS_COMPLETED),this.H=setTimeout(function(){i.timer_H()},_.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}},{key:"C",get:function(){return T}}]),s}(c),checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case d.INVITE:if(n=r.ist[t.via_branch]){if(n.state===T.STATUS_PROCEEDING)n.transport.send(n.last_response);return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===T.STATUS_ACCEPTED)return!1;if(n.state===T.STATUS_COMPLETED)return n.state=T.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},_.TIMER_I),!0;break;case d.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==T.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case T.STATUS_TRYING:break;case T.STATUS_PROCEEDING:case T.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}}function Fe(){if(Se)return be;function e(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)}}Se=1;var t=le(),n=q(),r=qe(),i=He(),s=new t("RequestSender"),o={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}};return be=function(){function t(e,r,i){for(var s in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._ua=e,this._eventHandlers=i,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1,o)Object.prototype.hasOwnProperty.call(o,s)&&(this._eventHandlers[s]||(this._eventHandlers[s]=o[s]));e.status!==e.C.STATUS_USER_CLOSED||this._method===n.BYE&&this._method===n.ACK||this._eventHandlers.onTransportError()}var l,a,u;return l=t,(a=[{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 i.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new i.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new i.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,i=e.status_code;if(401!==i&&407!==i||null===this._ua.configuration.password&&null===this._ua.configuration.ha1)this._eventHandlers.onReceiveResponse(e);else{if(401===e.status_code?(t=e.parseHeader("www-authenticate"),n="authorization"):(t=e.parseHeader("proxy-authenticate"),n="proxy-authorization"),!t)return s.debug("".concat(e.status_code," with wrong or missing challenge, cannot authenticate")),void this._eventHandlers.onReceiveResponse(e);if(!this._challenged||!this._staled&&!0===t.stale){if(this._auth||(this._auth=new r({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),t.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(n,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(e)}}}])&&e(l.prototype,a),u&&e(l,u),t}()}function je(){if(Ee)return Ce;function e(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)}}Ee=1;var t=le(),n=X(),r=q(),i=Me(),s=Fe(),o=new t("Registrator");return Ce=function(){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._reg_id=1,this._ua=e,this._transport=r,this._registrar=e.configuration.registrar_server,this._expires=e.configuration.register_expires,this._call_id=n.createRandomToken(22),this._cseq=0,this._to_uri=e.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var l,a,u;return l=t,a=[{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+=";".concat(t),n&&(this._extraContactParams+="=".concat(n))}}},{key:"register",value:function(){var e=this;if(this._registering)o.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var l=new i.OutgoingRequest(r.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new s(this._ua,l,{onRequestTimeout:function(){e._registrationFailure(null,r.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,r.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(null!==e._registrationTimer&&(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")){o.debug("no Contact header in response to REGISTER, response ignored");break}var i=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),s=i.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(s||(s=i.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!s){o.debug("no Contact header pointing to us, response ignored");break}var l=s.getParam("expires");!l&&t.hasHeader("expires")&&(l=t.getHeader("expires")),l||(l=e._expires),(l=Number(l))<10&&(l=10);var a=l>64?1e3*l/2+Math.floor(1e3*(l/2-32)*Math.random()):1e3*l-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},a),s.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=s.getParam("temp-gruu").replace(/"/g,"")),s.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=s.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<10&&(e._expires=10),e.register()):(o.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,r.causes.SIP_FAILURE_CODE));break;default:var u=n.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});this._registering=!0,a.send()}}},{key:"unregister",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this._registered){this._registered=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var l=this._extraHeaders.slice();t.all?l.push("Contact: *".concat(this._extraContactParams)):l.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),l.push("Expires: 0");var a=new i.OutgoingRequest(r.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l);new s(this._ua,a,{onRequestTimeout:function(){e._unregistered(null,r.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,r.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 r=n.sipErrorCause(t.status_code);e._unregistered(t,r)}}}).send()}else o.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(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}}],a&&e(l.prototype,a),u&&e(l,u),t}(),Ce}function Ge(){if(we)return Ae;function e(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)}}we=1;var t=q(),n=He(),r=Fe(),i={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}};return Ae=function(){function s(e,t,n){for(var r in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),this._dialog=e,this._ua=e._ua,this._request=t,this._eventHandlers=n,this._reattempt=!1,this._reattemptTimer=null,i)Object.prototype.hasOwnProperty.call(i,r)&&(this._eventHandlers[r]||(this._eventHandlers[r]=i[r]))}var o,l,a;return o=s,(l=[{key:"send",value:function(){var e=this,i=new r(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)}});i.send(),(this._request.method===t.INVITE||this._request.method===t.UPDATE&&this._request.body)&&i.clientTransaction.state!==n.C.STATUS_TERMINATED&&(this._dialog.uac_pending_reply=!0,i.clientTransaction.on("stateChanged",function t(){i.clientTransaction.state!==n.C.STATUS_ACCEPTED&&i.clientTransaction.state!==n.C.STATUS_COMPLETED&&i.clientTransaction.state!==n.C.STATUS_TERMINATED||(i.clientTransaction.removeListener("stateChanged",t),e._dialog.uac_pending_reply=!1)}))}},{key:"_receiveResponse",value:function(e){var n=this;408===e.status_code||481===e.status_code?this._eventHandlers.onDialogError(e):e.method===t.INVITE&&491===e.status_code?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(){n._dialog.isTerminated()||(n._reattempt=!0,n.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(o.prototype,l),a&&e(o,a),s}()}function $e(){if(Ie)return Re;function e(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 t(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}Ie=1;var n=le(),r=Me(),i=q(),s=He(),o=Ge(),l=X(),a=new n("Dialog"),u={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};return Re=function(){function e(t,n,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:u.STATUS_CONFIRMED;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof r.IncomingResponse&&(s=n.status_code<200?u.STATUS_EARLY:u.STATUS_CONFIRMED);var o=n.parseHeader("contact");"UAS"===i?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):"UAC"===i&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a.debug("new ".concat(i," dialog created with status ").concat(this._state===u.STATUS_EARLY?"EARLY":"CONFIRMED"))}return t(e,null,[{key:"C",get:function(){return u}}]),t(e,[{key:"isTerminated",value:function(){return this._status===u.STATUS_TERMINATED}},{key:"update",value:function(e,t){this._state=u.STATUS_CONFIRMED,a.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=u.STATUS_TERMINATED}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=l.cloneArray(n.extraHeaders),i=l.cloneObject(n.eventHandlers),s=n.body||null,a=this._createRequest(e,r,s);return i.onAuthenticated=function(){t._local_seqnum+=1},new o(this,a,i).send(),a}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=l.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var s=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new r.OutgoingRequest(e,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseq<this._remote_seqnum){if(e.method!==i.ACK)return e.reply(500),!1;if(null===this._ack_seqnum||e.cseq!==this._ack_seqnum)return!1}else e.cseq>this._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==s.C.STATUS_ACCEPTED&&e.server_transaction.state!==s.C.STATUS_COMPLETED&&e.server_transaction.state!==s.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",n),t._uas_pending_reply=!1)})}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===s.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===s.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}(),Re}var Be,We,Ve,ze,Ke,Ye,Xe,Je,Qe,Ze,et,tt,nt,rt={exports:{}};function it(){if(Be)return rt.exports;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}Be=1;var s=l().EventEmitter,o=le(),a=q(),u=L(),c=X(),h=new o("RTCSession:DTMF"),d={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};return rt.exports=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(f,e);var i,s,o,l=r(f);function f(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,f),(t=l.call(this))._session=e,t._direction=null,t._tone=null,t._duration=null,t._request=null,t}return i=f,s=[{key:"send",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===e)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new u.InvalidStateError(this._session.status);var r=c.cloneArray(n.extraHeaders);if(this.eventHandlers=c.cloneObject(n.eventHandlers),"string"==typeof e)e=e.toUpperCase();else{if("number"!=typeof e)throw new TypeError("Invalid tone: ".concat(e));e=e.toString()}if(!e.match(/^[0-9A-DR#*]$/))throw new TypeError("Invalid tone: ".concat(e));this._tone=e,this._duration=n.duration,r.push("Content-Type: application/dtmf-relay");var i="Signal=".concat(this._tone,"\r\n");i+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(a.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("\n");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||(this._duration=d.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):h.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}],s&&t(i.prototype,s),o&&t(i,o),f}(s),rt.exports.C=d,rt.exports}function st(){if(Ve)return We;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}Ve=1;var s=l().EventEmitter,o=q(),a=L(),u=X();return We=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(h,e);var i,s,l,c=r(h);function h(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),(t=c.call(this))._session=e,t._direction=null,t._contentType=null,t._body=null,t}return i=h,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new a.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var i=u.cloneArray(r.extraHeaders);i.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(o.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}}],s&&t(i.prototype,s),l&&t(i,l),h}(s),We}function ot(){if(Ke)return ze;function e(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)}}Ke=1;var t=le(),n=q(),r=new t("RTCSession:ReferNotifier"),i="refer",s="message/sipfrag;version=2.0",o=300;return ze=function(){function t(e,n,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this._session=e,this._id=n,this._expires=r||o,this._active=!0,this.notify(100)}var l,a,u;return l=t,(a=[{key:"notify",value:function(e,t){var o;r.debug("notify()"),!1!==this._active&&(t=t||n.REASON_PHRASE[e]||"",o=e>=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(n.NOTIFY,{extraHeaders:["Event: ".concat(i,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(s)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&e(l.prototype,a),u&&e(l,u),t}()}function lt(){if(Xe)return Ye;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}Xe=1;var s=l().EventEmitter,o=le(),a=q(),u=K(),c=X(),h=new o("RTCSession:ReferSubscriber");return Ye=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(d,e);var i,s,o,l=r(d);function d(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,d),(t=l.call(this))._id=null,t._session=e,t}return i=d,s=[{key:"sendRefer",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};h.debug("sendRefer()");var r=c.cloneArray(n.extraHeaders),i=c.cloneObject(n.eventHandlers);for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&this.on(s,i[s]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=";to-tag=".concat(n.replaces._to_tag),o+=";from-tag=".concat(n.replaces._from_tag),o=encodeURIComponent(o));var l="Refer-To: <".concat(e).concat(o?"?Replaces=".concat(o):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var d=this._session.sendRequest(a.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,a.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,a.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,a.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,a.causes.DIALOG_ERROR)}}});this._id=d.cseq}},{key:"receiveNotify",value:function(e){if(h.debug("receiveNotify()"),e.body){var t=u.parse(e.body.trim().split("\r\n",1)[0],"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else h.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){h.debug("REFER succeeded"),h.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){h.debug("REFER failed"),h.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}},{key:"id",get:function(){return this._id}}],s&&t(i.prototype,s),o&&t(i,o),d}(s),Ye}function at(){if(Qe)return Je;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}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}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function o(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=a(t);if(n){var s=a(this).constructor;r=Reflect.construct(i,arguments,s)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}Qe=1;var u=l().EventEmitter,c=Pe(),h=le(),d=q(),f=L(),_=He(),p=X(),m=Le(),g=Me(),v=$e(),y=Fe(),T=it(),b=st(),S=ot(),C=lt(),E=Y(),A=new h("RTCSession"),w={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},R=["audio","video"];return Je=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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)}(r,e);var n=o(r);function r(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),A.debug("new"),(t=n.call(this))._id=null,t._ua=e,t._status=w.STATUS_NULL,t._dialog=null,t._earlyDialogs={},t._contact=null,t._from_tag=null,t._to_tag=null,t._connection=null,t._connectionPromiseQueue=Promise.resolve(),t._request=null,t._is_canceled=!1,t._cancel_reason="",t._is_confirmed=!1,t._late_sdp=!1,t._rtcOfferConstraints=null,t._rtcAnswerConstraints=null,t._localMediaStream=null,t._localMediaStreamLocallyGenerated=!1,t._rtcReady=!0,t._iceReady=!1,t._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},t._direction=null,t._local_identity=null,t._remote_identity=null,t._start_time=null,t._end_time=null,t._tones=null,t._audioMuted=!1,t._videoMuted=!1,t._localHold=!1,t._remoteHold=!1,t._sessionTimers={enabled:t._ua.configuration.session_timers,refreshMethod:t._ua.configuration.session_timers_refresh_method,defaultExpires:d.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},t._referSubscribers={},t._data={},t}return i(r,null,[{key:"C",get:function(){return w}}]),i(r,[{key:"isInProgress",value:function(){switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:case w.STATUS_INVITE_RECEIVED:case w.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case w.STATUS_ANSWERED:case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case w.STATUS_CANCELED:case w.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&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A.debug("connect()");var r=e,i=p.cloneObject(t.eventHandlers),s=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new f.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new f.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),i)Object.prototype.hasOwnProperty.call(i,h)&&this.on(h,i[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new E("sip","anonymous","anonymous.invalid"),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),s.push("Privacy: id")):t.fromUserName&&(m.from_uri=new E("sip",t.fromUserName,this._ua.configuration.uri.host),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),s.push("Contact: ".concat(this._contact)),s.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&s.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new g.InitialOutgoingInviteRequest(e,this._ua,m,s),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),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,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A.debug("init_incoming()");var i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==i?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,d.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,d.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("answer()");var r=this._request,i=p.cloneArray(n.extraHeaders),s=p.cloneObject(n.mediaConstraints),o=n.mediaStream||null,l=p.cloneObject(n.pcConfig,{iceServers:[]}),a=n.rtcConstraints||null,u=n.rtcAnswerConstraints||null,c=p.cloneObject(n.rtcOfferConstraints),h=!1,_=!1,m=!1,g=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=n.rtcOfferConstraints||null,this._data=n.data||this._data,"incoming"!==this._direction)throw new f.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new f.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),this._status=w.STATUS_ANSWERED,this._createDialog(r,"UAS")){clearTimeout(this._timers.userNoAnswerTimer),i.unshift("Contact: ".concat(this._contact));var v=r.parseSDP();Array.isArray(v.media)||(v.media=[v.media]);var y,T=t(v.media);try{for(T.s();!(y=T.n()).done;){var b=y.value;"audio"===b.type&&(h=!0,b.direction&&"sendrecv"!==b.direction||(m=!0)),"video"===b.type&&(_=!0,b.direction&&"sendrecv"!==b.direction||(g=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===s.audio){var S,C=t(o.getAudioTracks());try{for(C.s();!(S=C.n()).done;){var E=S.value;o.removeTrack(E)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===s.video){var R,I=t(o.getVideoTracks());try{for(I.s();!(R=I.n()).done;){var O=R.value;o.removeTrack(O)}}catch(e){I.e(e)}finally{I.f()}}o||void 0!==s.audio||(s.audio=m),o||void 0!==s.video||(s.video=g),o||h||c.offerToReceiveAudio||(s.audio=!1),o||_||c.offerToReceiveVideo||(s.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(s.audio||s.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r.reply(480),e._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),A.warn('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new 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:r.body};A.debug('emit "sdp"'),e.emit("sdp",t);var n=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(n)}).catch(function(t){throw r.reply(488),e._failed("system",null,d.causes.WEBRTC_ERROR),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(r),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(r,i),r.reply(200,null,i,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(r,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,d.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&A.warn(t)})}else r.reply(500,"Error creating dialog")}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("terminate()");var n,r=t.cause||d.causes.BYE,i=p.cloneArray(t.extraHeaders),s=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new f.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||d.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,d.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A.debug("rejecting session"),(o=o||480)<300||o>=700)throw new TypeError("Invalid status_code: ".concat(o));this._request.reply(o,l,i,s),this._failed("local",null,d.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A.debug("terminating session"),l=t.reason_phrase||d.REASON_PHRASE[o]||"",o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));if(o&&i.push("Reason: SIP ;cause=".concat(o,'; text="').concat(l,'"')),this._status===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===d.ACK&&(e.sendRequest(d.BYE,{extraHeaders:i,body:s}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(d.BYE,{extraHeaders:i,body:s}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(d.BYE,{extraHeaders:i,body:s}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};A.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,i=t.interToneGap||null,s=t.transportType||d.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_1XX_RECEIVED)throw new f.InvalidStateError(this._status);if(s!==d.DTMF_TRANSPORT.INFO&&s!==d.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(s));if("number"==typeof e&&(e=e.toString()),!e||"string"!=typeof e||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(e));if(r&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?r<T.C.MIN_DURATION?(A.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(T.C.MIN_DURATION," milliseconds")),r=T.C.MIN_DURATION):r>T.C.MAX_DURATION?(A.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,i&&!p.isDecimal(i))throw new TypeError("Invalid interToneGap: ".concat(i));if(i?i<T.C.MIN_INTER_TONE_GAP?(A.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(T.C.MIN_INTER_TONE_GAP," milliseconds")),i=T.C.MIN_INTER_TONE_GAP):i=Math.abs(i):i=T.C.DEFAULT_INTER_TONE_GAP,s!==d.DTMF_TRANSPORT.RFC2833)this._tones?this._tones+=e:(this._tones=e,function e(){var s,o=this;if(this._status===w.STATUS_TERMINATED||!this._tones||n>=this._tones.length)return void(this._tones=null);var l=this._tones[n];if(n+=1,","===l)s=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){o._tones=null}},a.send(l,t),s=r+i}setTimeout(e.bind(this),s)}.call(this));else{var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,i))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(A.debug("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_1XX_RECEIVED)throw new f.InvalidStateError(this._status);new b(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A.debug("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A.debug("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A.debug("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var i={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.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;A.debug("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var i=new C(this);i.sendRefer(e,t);var s=i.id;return this._referSubscribers[s]=i,i.on("requestFailed",function(){delete n._referSubscribers[s]}),i.on("accepted",function(){delete n._referSubscribers[s]}),i.on("failed",function(){delete n._referSubscribers[s]}),i}},{key:"sendRequest",value:function(e,t){return A.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A.debug("receiveRequest()"),e.method===d.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,d.causes.CANCELED));else switch(e.method){case d.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:d.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A.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:d.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case d.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,d.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,d.causes.BYE)):e.reply(403,"Wrong Status");break;case d.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case d.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==i?new b(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case d.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case d.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case d.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){A.warn("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.CONNECTION_ERROR,cause:d.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){A.warn("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:d.causes.REQUEST_TIMEOUT,cause:d.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){A.warn("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.DIALOG_ERROR,cause:d.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A.debug("_isReadyToReOffer() | session not established yet"),!1):(A.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A.debug("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){A.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=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),n<m.T2&&(n*=2)>m.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(d.BYE),e._ended("remote",null,d.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})}),A.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return A.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return A.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,A.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var i=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!i||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var s={originator:"local",type:e,sdp:r.localDescription.sdp};return A.debug('emit "sdp"'),n.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(function(t){var i,s,o=!1;n._iceReady=!1;var l=function(){if(!o){r.removeEventListener("icecandidate",i),r.removeEventListener("icegatheringstatechange",s),o=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};A.debug('emit "sdp"'),n.emit("sdp",l),t(l.sdp)}};r.addEventListener("icecandidate",i=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):l()}),r.addEventListener("icegatheringstatechange",s=function(){"complete"===r.iceGatheringState&&l()})})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,i="UAS"===t?e.from_tag:e.to_tag,s=e.call_id+r+i,o=this._earlyDialogs[s];if(n)return!!o||((o=new v(this,e,t,v.C.STATUS_EARLY)).error?(A.debug(o.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[s]=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[s],!0;var l=new v(this,e,t);return l.error?(A.debug(l.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",s=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,s)}.bind(this)},i=!1;if(this.emit("reinvite",r),!i){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){s.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return A.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&s.call(t,e)}).catch(function(e){A.warn(e)})}function s(t){var n=this,i=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,i),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,i,t,function(){n._status=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",s=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,s)}.bind(this)},i=!1;if(this.emit("update",r),!i)if(e.body){if("application/sdp"!==n)return A.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&s.call(t,e)}).catch(function(e){A.warn(e)})}else s.call(this,null);function s(t){var n=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),"function"==typeof r.callback&&r.callback()}}},{key:"_processInDialogSdpOffer",value:function(e){var n=this;A.debug("_processInDialogSdpOffer()");var r,i=e.parseSDP(),s=!1,o=t(i.media);try{for(o.s();!(r=o.n()).done;){var l=r.value;if(-1!==R.indexOf(l.type)){var a=l.direction||i.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){s=!1;break}s=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A.debug('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");return n._connection.setRemoteDescription(c).catch(function(t){throw e.reply(488),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),n.emit("peerconnection:setremotedescriptionfailed",t),t})}).then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");!0===n._remoteHold&&!1===s?(n._remoteHold=!1,n._onunhold("remote")):!1===n._remoteHold&&!0===s&&(n._remoteHold=!0,n._onhold("remote"))}).then(function(){if(n._status===w.STATUS_TERMINATED)throw new Error("terminated");return n._createLocalDescription("answer",n._rtcAnswerConstraints).catch(function(t){throw e.reply(500),A.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){A.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A.debug("receiveRefer()"),!e.refer_to)return A.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==d.SIP)return A.debug("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);function i(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new r(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var o=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));i.extraHeaders=p.cloneArray(i.extraHeaders),i.extraHeaders.push("Replaces: ".concat(o))}s.connect(e.refer_to.uri.toAor(),i,t)}function s(){n.notify(603)}A.debug('emit "refer"'),this.emit("refer",{request:e,accept:function(e,n){i.call(t,e,n)},reject:function(){s.call(t)}})}},{key:"_receiveNotify",value:function(e){if(A.debug("receiveNotify()"),e.event||e.reply(400),"refer"===e.event.event){var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200)}else e.reply(489)}},{key:"_receiveReplaces",value:function(e){var t=this;function n(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var i=new r(this._ua);i.on("confirmed",function(){n.terminate()}),i.init_incoming(e,t)}function i(){A.debug("Replaced INVITE rejected by the user"),e.reply(486)}A.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(e){n.call(t,e)},reject:function(){i.call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,i=new y(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(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),A.warn('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new 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,d.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),i.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&A.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;A.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(d.ACK);var n=new v(this,e,"UAC");return void 0!==n.error?void A.debug(n.error):(this.sendRequest(d.ACK),void this.sendRequest(d.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A.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){A.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=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,d.causes.MISSING_SDP),this._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var s={originator:"remote",type:"answer",sdp:e.body};A.debug('emit "sdp"'),this.emit("sdp",s);var o=new RTCSessionDescription({type:"answer",sdp:s.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if("stable"===t._connection.signalingState)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,d.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(d.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=!1;function o(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&(this.sendRequest(d.ACK),!s))if(this._handleSessionTimersInIncomingResponse(e),e.body)if(e.hasHeader("Content-Type")&&"application/sdp"===e.getHeader("Content-Type").toLowerCase()){var n={originator:"remote",type:"answer",sdp:e.body};A.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){l.call(t),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else l.call(this);else l.call(this)}function l(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};A.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(d.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){o.call(e,t),s=!0},onErrorResponse:function(t){l.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){l()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A.debug("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),s){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A.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){a.call(t),A.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};A.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(d.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(d.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A.debug("acceptAndTerminate()");var r=[];t&&(n=n||d.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(d.ACK),this.sendRequest(d.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=c.parse(e),this._localHold&&!this._remoteHold){A.debug("mangleOffer() | me on hold, mangling offer");var n,r=t(e.media);try{for(r.s();!(n=r.n()).done;){var i=n.value;-1!==R.indexOf(i.type)&&(i.direction?"sendrecv"===i.direction?i.direction="sendonly":"recvonly"===i.direction&&(i.direction="inactive"):i.direction="sendonly")}}catch(e){r.e(e)}finally{r.f()}}else if(this._localHold&&this._remoteHold){A.debug("mangleOffer() | both on hold, mangling offer");var s,o=t(e.media);try{for(o.s();!(s=o.n()).done;){var l=s.value;-1!==R.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A.debug("mangleOffer() | remote on hold, mangling offer");var a,u=t(e.media);try{for(u.s();!(a=u.n()).done;){var h=a.value;-1!==R.indexOf(h.type)&&(h.direction?"sendrecv"===h.direction?h.direction="recvonly":"recvonly"===h.direction&&(h.direction="inactive"):h.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return c.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){var n;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.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: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(n)),this._sessionTimers.refresher="uas"===n,this._runSessionTimer())}},{key:"_handleSessionTimersInIncomingResponse",value:function(e){var t;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{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!==w.STATUS_TERMINATED&&e._isReadyToReOffer()&&(A.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===d.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:d.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},1100*t)}},{key:"_toggleMuteAudio",value:function(e){var n,r=this._connection.getSenders().filter(function(e){return e.track&&"audio"===e.track.kind}),i=t(r);try{for(i.s();!(n=i.n()).done;){n.value.track.enabled=!e}}catch(e){i.e(e)}finally{i.f()}}},{key:"_toggleMuteVideo",value:function(e){var n,r=this._connection.getSenders().filter(function(e){return e.track&&"video"===e.track.kind}),i=t(r);try{for(i.s();!(n=i.n()).done;){n.value.track.enabled=!e}}catch(e){i.e(e)}finally{i.f()}}},{key:"_newRTCSession",value:function(e,t){A.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A.debug("session connecting"),A.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A.debug("session progress"),A.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A.debug("session accepted"),this._start_time=new Date,A.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A.debug("session confirmed"),this._is_confirmed=!0,A.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A.debug("session ended"),this._end_time=new Date,this._close(),A.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A.debug("session failed"),A.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A.debug("session onhold"),this._setLocalMediaStatus(),A.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A.debug("session onunhold"),this._setLocalMediaStatus(),A.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A.debug("session onmute"),this._setLocalMediaStatus(),A.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A.debug("session onunmute"),this._setLocalMediaStatus(),A.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return w}},{key:"causes",get:function(){return d.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}}]),r}(u),Je}function ut(){if(et)return Ze;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}et=1;var s=l().EventEmitter,o=le(),a=q(),u=Me(),c=X(),h=Fe(),d=L(),f=Y(),_=new o("Message");return Ze=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(p,e);var i,s,o,l=r(p);function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),(t=l.call(this))._ua=e,t._request=null,t._closed=!1,t._direction=null,t._local_identity=null,t._remote_identity=null,t._is_replied=!1,t._data={},t}return i=p,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var s=c.cloneArray(r.extraHeaders),o=c.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",d={};for(var _ in r.fromUserName&&(d.from_uri=new f("sip",r.fromUserName,this._ua.configuration.uri.host),s.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),r.fromDisplayName&&(d.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,_)&&this.on(_,o[_]);s.push("Content-Type: ".concat(l)),this._request=new u.OutgoingRequest(a.MESSAGE,e,this._ua,d,s),t&&(this._request.body=t);var p=new h(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),p.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&&void 0!==arguments[0]?arguments[0]:{},t=c.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=c.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(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=c.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,a.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,a.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){_.debug("MESSAGE failed"),this._close(),_.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){_.debug("MESSAGE succeeded"),this._close(),_.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}}],s&&t(i.prototype,s),o&&t(i,o),p}(s),Ze}function ct(){if(nt)return tt;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function r(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,s=i(t);if(n){var o=i(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,r)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}nt=1;var s=l().EventEmitter,o=le(),a=q(),u=Me(),c=X(),h=Fe(),d=L(),f=new o("Options");return tt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&n(e,t)}(_,e);var i,s,o,l=r(_);function _(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,_),(t=l.call(this))._ua=e,t._request=null,t._closed=!1,t._direction=null,t._local_identity=null,t._remote_identity=null,t._is_replied=!1,t._data={},t}return i=_,s=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var s=c.cloneArray(r.extraHeaders),o=c.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";for(var d in o)Object.prototype.hasOwnProperty.call(o,d)&&this.on(d,o[d]);s.push("Content-Type: ".concat(l)),this._request=new u.OutgoingRequest(a.OPTIONS,e,this._ua,null,s),t&&(this._request.body=t);var f=new h(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions("local",this._request),f.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&&void 0!==arguments[0]?arguments[0]:{},t=c.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=c.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(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=c.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,a.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,a.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){f.debug("OPTIONS failed"),this._close(),f.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){f.debug("OPTIONS succeeded"),this._close(),f.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}}],s&&t(i.prototype,s),o&&t(i,o),_}(s),tt}var ht,dt,ft,_t={};function pt(){if(ht)return _t;ht=1;var e=le(),t=X(),n=K(),r=new e("Socket");return _t.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return r.warn("undefined JsSIP.Socket instance"),!1;try{if(!t.isString(e.url))throw r.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!t.isString(e.via_transport))throw r.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===n.parse(e.sip_uri,"SIP_URI"))throw r.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(n){if(!t.isFunction(e[n]))throw r.warn("missing or invalid JsSIP.Socket method: ".concat(n)),new Error("Missing or invalid JsSIP.Socket method: ".concat(n))})}catch(e){return!1}return!0},_t}function mt(){if(ft)return dt;function e(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)}}ft=1;var t=le(),n=pt(),r=q(),i=new t("Transport"),s={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:r.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:r.CONNECTION_RECOVERY_MAX_INTERVAL}};return dt=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),i.debug("new()"),this.status=s.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){i.warn("cannot use TextDecoder: ".concat(e))}if(void 0===e)throw new TypeError("Invalid argument. undefined 'sockets' argument");e instanceof Array||(e=[e]),e.forEach(function(e){if(!n.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:s.SOCKET_STATUS_READY})},this),this._getSocket()}var r,o,l;return r=t,(o=[{key:"connect",value:function(){i.debug("connect()"),this.isConnected()?i.debug("Transport is already connected"):this.isConnecting()?i.debug("Transport is connecting"):(this.close_requested=!1,this.status=s.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(){i.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=s.STATUS_DISCONNECTED,null!==this.recovery_timer&&(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(i.debug("send()"),!this.isConnected())return i.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return i.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===s.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===s.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==s.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=s.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=s.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=s.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=s.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n\r\n"!==e)if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i.debug("received binary message failed to be converted into string, message discarded")}i.debug("received binary message:\n\n".concat(e,"\n"))}else i.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i.debug("received message with CRLF Keep Alive response");else{i.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(e){i.warn("error sending Keep Alive response: ".concat(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(r.prototype,o),l&&e(r,l),t}(),dt}var gt,vt,yt,Tt={};function bt(){if(gt)return Tt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}gt=1;var n=le(),r=K(),i=Me(),s=new n("Parser");function o(e,t){var n=t,r=0,i=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===r;){if(-1===(i=e.indexOf("\r\n",n)))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(t,n,s,o){var l,a=n.indexOf(":",s),u=n.substring(s,a).trim(),c=n.substring(a+1,o).trim();switch(u.toLowerCase()){case"via":case"v":t.addHeader("via",c),1===t.getHeaders("via").length?(l=t.parseHeader("Via"))&&(t.via=l,t.via_branch=l.branch):l=0;break;case"from":case"f":t.setHeader("from",c),(l=t.parseHeader("from"))&&(t.from=l,t.from_tag=l.getParam("tag"));break;case"to":case"t":t.setHeader("to",c),(l=t.parseHeader("to"))&&(t.to=l,t.to_tag=l.getParam("tag"));break;case"record-route":if(-1===(l=r.parse(c,"Record_Route")))l=void 0;else{var h,d=e(l);try{for(d.s();!(h=d.n()).done;){var f=h.value;t.addHeader("record-route",c.substring(f.possition,f.offset)),t.headers["Record-Route"][t.getHeaders("record-route").length-1].parsed=f.parsed}}catch(e){d.e(e)}finally{d.f()}}break;case"call-id":case"i":t.setHeader("call-id",c),(l=t.parseHeader("call-id"))&&(t.call_id=c);break;case"contact":case"m":if(-1===(l=r.parse(c,"Contact")))l=void 0;else{var _,p=e(l);try{for(p.s();!(_=p.n()).done;){var m=_.value;t.addHeader("contact",c.substring(m.possition,m.offset)),t.headers.Contact[t.getHeaders("contact").length-1].parsed=m.parsed}}catch(e){p.e(e)}finally{p.f()}}break;case"content-length":case"l":t.setHeader("content-length",c),l=t.parseHeader("content-length");break;case"content-type":case"c":t.setHeader("content-type",c),l=t.parseHeader("content-type");break;case"cseq":t.setHeader("cseq",c),(l=t.parseHeader("cseq"))&&(t.cseq=l.value),t instanceof i.IncomingResponse&&(t.method=l.method);break;case"max-forwards":t.setHeader("max-forwards",c),l=t.parseHeader("max-forwards");break;case"www-authenticate":t.setHeader("www-authenticate",c),l=t.parseHeader("www-authenticate");break;case"proxy-authenticate":t.setHeader("proxy-authenticate",c),l=t.parseHeader("proxy-authenticate");break;case"session-expires":case"x":t.setHeader("session-expires",c),(l=t.parseHeader("session-expires"))&&(t.session_expires=l.expires,t.session_expires_refresher=l.refresher);break;case"refer-to":case"r":t.setHeader("refer-to",c),(l=t.parseHeader("refer-to"))&&(t.refer_to=l);break;case"replaces":t.setHeader("replaces",c),(l=t.parseHeader("replaces"))&&(t.replaces=l);break;case"event":case"o":t.setHeader("event",c),(l=t.parseHeader("event"))&&(t.event=l);break;default:t.addHeader(u,c),l=0}return void 0!==l||{error:'error parsing header "'.concat(u,'"')}}return Tt.parseMessage=function(e,t){var n,a,u=e.indexOf("\r\n");if(-1!==u){var c=e.substring(0,u),h=r.parse(c,"Request_Response");if(-1!==h){h.status_code?((n=new i.IncomingResponse).status_code=h.status_code,n.reason_phrase=h.reason_phrase):((n=new i.IncomingRequest(t)).method=h.method,n.ruri=h.uri),n.data=e;for(var d=u+2;;){if(-2===(u=o(e,d))){a=d+2;break}if(-1===u)return void s.warn("parseMessage() | malformed message");if(!0!==(h=l(n,e,d,u)))return void s.warn("parseMessage() |",h.error);d=u+2}if(n.hasHeader("content-length")){var f=n.getHeader("content-length");n.body=e.substr(a,f)}else n.body=e.substring(a);return n}s.warn('parseMessage() | error parsing first line of SIP message: "'.concat(c,'"'))}else s.warn("parseMessage() | no CRLF found, not a SIP message")},Tt}function St(){if(yt)return vt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}yt=1;var n,r,i,s=le(),o=q(),l=Me(),a=X(),u=new s("sanityCheck"),c=[function(){for(var e=0,t=["from","to","call_id","cseq","via"];e<t.length;e++){var r=t[e];if(!n.hasHeader(r))return u.debug("missing mandatory header field : ".concat(r,", dropping the response")),!1}}],h=[function(){if("sip"!==n.s("to").uri.scheme)return f(416),!1},function(){if(!n.to_tag&&n.call_id.substr(0,5)===r.configuration.jssip_id)return f(482),!1},function(){var e=a.str_utf8_length(n.body),t=n.getHeader("content-length");if(e<t)return f(400),!1},function(){var e,t=n.from_tag,i=n.call_id,s=n.cseq;if(n.to_tag)return;if(n.method===o.INVITE){if(r._transactions.ist[n.via_branch])return!1;for(var l in r._transactions.ist)if(Object.prototype.hasOwnProperty.call(r._transactions.ist,l)&&(e=r._transactions.ist[l]).request.from_tag===t&&e.request.call_id===i&&e.request.cseq===s)return f(482),!1}else{if(r._transactions.nist[n.via_branch])return!1;for(var a in r._transactions.nist)if(Object.prototype.hasOwnProperty.call(r._transactions.nist,a)&&(e=r._transactions.nist[a]).request.from_tag===t&&e.request.call_id===i&&e.request.cseq===s)return f(482),!1}}],d=[function(){if(n.getHeaders("via").length>1)return u.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=a.str_utf8_length(n.body),t=n.getHeader("content-length");if(e<t)return u.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}];function f(t){var r,s,l=n.getHeaders("via"),u="SIP/2.0 ".concat(t," ").concat(o.REASON_PHRASE[t],"\r\n"),c=e(l);try{for(c.s();!(s=c.n()).done;){var h=s.value;u+="Via: ".concat(h,"\r\n")}}catch(e){c.e(e)}finally{c.f()}r=n.getHeader("To"),n.to_tag||(r+=";tag=".concat(a.newTag())),u+="To: ".concat(r,"\r\n"),u+="From: ".concat(n.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(n.call_id,"\r\n"),u+="CSeq: ".concat(n.cseq," ").concat(n.method,"\r\n"),u+="\r\n",i.send(u)}return vt=function(t,s,o){n=t,r=s,i=o;var a,u=e(c);try{for(u.s();!(a=u.n()).done;){if(!1===(0,a.value)())return!1}}catch(e){u.e(e)}finally{u.f()}if(n instanceof l.IncomingRequest){var f,_=e(h);try{for(_.s();!(f=_.n()).done;){if(!1===(0,f.value)())return!1}}catch(e){_.e(e)}finally{_.f()}}else if(n instanceof l.IncomingResponse){var p,m=e(d);try{for(m.s();!(p=m.n()).done;){if(!1===(0,p.value)())return!1}}catch(e){m.e(e)}finally{m.f()}}return!0}}var Ct,Et,At,wt,Rt,It,Ot,Nt={};function kt(){if(Ct)return Nt;function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0,s=function(){};return{s:s,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==r.return||r.return()}finally{if(a)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}Ct=1;var n=X(),r=q(),i=K(),s=Y(),o=pt(),l=L();Nt.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:r.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:r.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:r.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(n.createRandomToken(12),".invalid")};var a={mandatory:{sockets:function(t){var n=[];if(o.isSocket(t))n.push({socket:t});else{if(!Array.isArray(t)||!t.length)return;var r,i=e(t);try{for(i.s();!(r=i.n()).done;){var s=r.value;Object.prototype.hasOwnProperty.call(s,"socket")&&o.isSocket(s.socket)?n.push(s):o.isSocket(s)&&n.push({socket:s})}}catch(e){i.e(e)}finally{i.f()}}return n},uri:function(e){/^sip:/i.test(e)||(e="".concat(r.SIP,":").concat(e));var t=s.parse(e);return t&&t.user?t:void 0}},optional:{authorization_user:function(e){return-1===i.parse('"'.concat(e,'"'),"quoted_string")?void 0:e},authorization_jwt:function(e){if("string"==typeof e)return e},user_agent:function(e){if("string"==typeof e)return e},connection_recovery_max_interval:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},connection_recovery_min_interval:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if("string"==typeof e){var t=i.parse(e,"SIP_URI");if(-1!==t)return t}},display_name:function(e){return e},instance_id:function(e){return/^uuid:/i.test(e)&&(e=e.substr(5)),-1===i.parse(e,"uuid")?void 0:e},no_answer_timeout:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if("boolean"==typeof e)return e},session_timers_refresh_method:function(e){if("string"==typeof e&&((e=e.toUpperCase())===r.INVITE||e===r.UPDATE))return e},session_timers_force_refresher:function(e){if("boolean"==typeof e)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if("boolean"==typeof e)return e},register_expires:function(e){if(n.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(r.SIP,":").concat(e));var t=s.parse(e);return t?t.user?void 0:t:void 0},use_preloaded_route:function(e){if("boolean"==typeof e)return e},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var r,i=e(t);try{for(i.s();!(r=i.n()).done;){var s=r.value;"string"==typeof s&&n.push(s)}}catch(e){i.e(e)}finally{i.f()}return n}}}};return Nt.load=function(e,t){for(var r in a.mandatory){if(!t.hasOwnProperty(r))throw new l.ConfigurationError(r);var i=t[r],s=a.mandatory[r](i);if(void 0===s)throw new l.ConfigurationError(r,i);e[r]=s}for(var o in a.optional)if(t.hasOwnProperty(o)){var u=t[o];if(n.isEmpty(u))continue;var c=a.optional[o](u);if(void 0===c)throw new l.ConfigurationError(o,u);e[o]=c}},Nt}function Dt(){if(At)return Et;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(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 n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function i(t){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var r,i=o(t);if(n){var l=o(this).constructor;r=Reflect.construct(i,arguments,l)}else r=i.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;return s(t)}(this,r)}}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}At=1;var a=l().EventEmitter,u=le(),c=q(),h=je(),d=at(),f=ut(),_=ct(),p=He(),m=mt(),g=X(),v=L(),y=Y(),T=bt(),b=Me(),S=St(),C=kt(),E=new u("UA"),A={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};function w(e){this.emit("connecting",e)}function R(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 I(e){for(var t=0,n=["nict","ict","nist","ist"];t<n.length;t++){var r=n[t];for(var i in this._transactions[r])Object.prototype.hasOwnProperty.call(this._transactions[r],i)&&this._transactions[r][i].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 O(e){var t=e.transport,n=e.message;if((n=T.parseMessage(n,this))&&!(this._status===A.STATUS_USER_CLOSED&&n instanceof b.IncomingRequest)&&S(n,this,t))if(n instanceof b.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof b.IncomingResponse){var r;switch(n.method){case c.INVITE:(r=this._transactions.ict[n.via_branch])&&r.receiveResponse(n);break;case c.ACK:break;default:(r=this._transactions.nict[n.via_branch])&&r.receiveResponse(n)}}}return Et=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new 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&&r(e,t)}(o,e);var t=i(o);function o(e){var n;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),E.debug("new() [configuration:%o]",e),(n=t.call(this))._cache={credentials:{}},n._configuration=Object.assign({},C.settings),n._dynConfiguration={},n._dialogs={},n._applicants={},n._sessions={},n._transport=null,n._contact=null,n._status=A.STATUS_INIT,n._error=null,n._transactions={nist:{},nict:{},ist:{},ict:{}},n._data={},n._closeTimer=null,void 0===e)throw new TypeError("Not enough arguments");try{n._loadConfig(e)}catch(e){throw n._status=A.STATUS_NOT_READY,n._error=A.CONFIGURATION_ERROR,e}return n._registrator=new h(s(n)),n}return n(o,null,[{key:"C",get:function(){return A}}]),n(o,[{key:"start",value:function(){E.debug("start()"),this._status===A.STATUS_INIT?this._transport.connect():this._status===A.STATUS_USER_CLOSED?(E.debug("restarting UA"),null!==this._closeTimer&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=A.STATUS_INIT,this._transport.connect()):this._status===A.STATUS_READY?E.debug("UA is in READY status, not restarted"):E.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){E.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(e){E.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){E.debug("call()");var n=new d(this);return n.connect(e,t),n}},{key:"sendMessage",value:function(e,t,n){E.debug("sendMessage()");var r=new f(this);return r.send(e,t,n),r}},{key:"sendOptions",value:function(e,t,n){E.debug("sendOptions()");var r=new _(this);return r.send(e,t,n),r}},{key:"terminateSessions",value:function(e){for(var t in E.debug("terminateSessions()"),this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}},{key:"stop",value:function(){var e=this;if(E.debug("stop()"),this._dynConfiguration={},this._status!==A.STATUS_USER_CLOSED){this._registrator.close();var t=Object.keys(this._sessions).length;for(var n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){E.debug("closing session ".concat(n));try{this._sessions[n].terminate()}catch(e){}}for(var r in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,r))try{this._applicants[r].close()}catch(e){}this._status=A.STATUS_USER_CLOSED,0===Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length&&0===t?this._transport.disconnect():this._closeTimer=setTimeout(function(){e._closeTimer=null,e._transport.disconnect()},2e3)}else E.debug("UA already closed")}},{key:"normalizeTarget",value:function(e){return g.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:return void E.warn('get() | cannot get "%s" parameter in runtime',e)}}},{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 E.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)return E.debug("Request-URI does not point to us"),void(e.method!==c.ACK&&e.reply_sl(404));if(e.ruri.scheme!==c.SIPS){if(!p.checkTransaction(this,e)){if(t===c.INVITE?new p.InviteServerTransaction(this,this._transport,e):t!==c.ACK&&t!==c.CANCEL&&new p.NonInviteServerTransaction(this,this._transport,e),t===c.OPTIONS){if(0===this.listeners("newOptions").length)return void e.reply(200);new _(this).init_incoming(e)}else if(t===c.MESSAGE){if(0===this.listeners("newMessage").length)return void e.reply(405);new f(this).init_incoming(e)}else if(t===c.INVITE&&!e.to_tag&&0===this.listeners("newRTCSession").length)return void e.reply(405);var n,r;if(e.to_tag)(n=this._findDialog(e.call_id,e.from_tag,e.to_tag))?n.receiveRequest(e):t===c.NOTIFY?(r=this._findSession(e))?r.receiveRequest(e):(E.debug("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist")):t!==c.ACK&&e.reply(481);else switch(t){case c.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){var i=e.replaces;(n=this._findDialog(i.call_id,i.from_tag,i.to_tag))?(r=n.owner).isEnded()?e.reply(603):r.receiveRequest(e):e.reply(481)}else(r=new d(this)).init_incoming(e);else E.warn("INVITE received but WebRTC is not supported"),e.reply(488);break;case c.BYE:e.reply(481);break;case c.CANCEL:(r=this._findSession(e))?r.receiveRequest(e):E.debug("received CANCEL request for a non existent session");break;case c.ACK:break;case c.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;default:e.reply(405)}}}else e.reply_sl(416)}},{key:"_findSession",value:function(e){var t=e.call_id,n=e.from_tag,r=e.to_tag,i=t+n,s=this._sessions[i],o=t+r,l=this._sessions[o];return s||(l||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])||null)}},{key:"_loadConfig",value:function(e){try{C.load(this._configuration,e)}catch(e){throw e}0===this._configuration.display_name&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=g.newUUID()),this._configuration.jssip_id=g.createRandomToken(5);var t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new m(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=w.bind(this),this._transport.onconnect=R.bind(this),this._transport.ondisconnect=I.bind(this),this._transport.ondata=O.bind(this)}catch(e){throw E.warn(e),new v.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 y("sip",g.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&&void 0!==arguments[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+=">"}};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)&&(-1!==r.indexOf(i)?Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}));for(var s in E.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(C.settings,s))switch(s){case"uri":case"registrar_server":E.debug("- ".concat(s,": ").concat(this._configuration[s]));break;case"password":case"ha1":case"authorization_jwt":E.debug("- ".concat(s,": NOT SHOWN"));break;default:E.debug("- ".concat(s,": ").concat(JSON.stringify(this._configuration[s])))}}},{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}}]),o}(a),Et}function xt(){if(Rt)return wt;function e(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)}}Rt=1;var t=le(),n=K(),r=new t("WebSocketInterface");return wt=function(){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),r.debug('new() [url:"%s"]',e),this._url=e,this._sip_uri=null,this._via_transport=null,this._ws=null;var i=n.parse(e,"absoluteURI");if(-1===i)throw r.warn("invalid WebSocket URI: ".concat(e)),new TypeError("Invalid argument: ".concat(e));if("wss"!==i.scheme&&"ws"!==i.scheme)throw r.warn("invalid WebSocket URI scheme: ".concat(i.scheme)),new TypeError("Invalid argument: ".concat(e));this._sip_uri="sip:".concat(i.host).concat(i.port?":".concat(i.port):"",";transport=ws"),this._via_transport=i.scheme.toUpperCase()}var i,s,o;return i=t,(s=[{key:"connect",value:function(){if(r.debug("connect()"),this.isConnected())r.debug("WebSocket ".concat(this._url," is already connected"));else if(this.isConnecting())r.debug("WebSocket ".concat(this._url," is connecting"));else{this._ws&&this.disconnect(),r.debug("connecting to WebSocket ".concat(this._url));try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(e){this._onError(e)}}}},{key:"disconnect",value:function(){r.debug("disconnect()"),this._ws&&(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),this._ws=null)}},{key:"send",value:function(e){return r.debug("send()"),this.isConnected()?(this._ws.send(e),!0):(r.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(){r.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(e){var t=e.wasClean,n=e.code,i=e.reason;r.debug("WebSocket ".concat(this._url," closed")),!1===t&&r.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,i)}},{key:"_onMessage",value:function(e){var t=e.data;r.debug("received WebSocket message"),this.ondata(t)}},{key:"_onError",value:function(e){r.warn("WebSocket ".concat(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(i.prototype,s),o&&e(i,o),t}()}var Ut=function(){if(Ot)return It;Ot=1;var e=M,t=q(),n=L(),r=X(),i=Dt(),s=Y(),o=z(),l=K(),a=xt();return oe()("JsSIP")("version %s",e.version),It={C:t,Exceptions:n,Utils:r,UA:i,URI:s,NameAddrHeader:o,WebSocketInterface:a,Grammar:l,debug:oe(),get name(){return e.title},get version(){return e.version}}}(),Pt=i(Ut);const Mt=e=>"object"==typeof e&&null!==e,qt=e=>Mt(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date)&&!(globalThis.Blob&&e instanceof globalThis.Blob),Lt=Symbol("mapObjectSkip"),Ht=(e,t,n,r=new WeakMap)=>{if(n={deep:!1,target:{},...n},r.has(e))return r.get(e);r.set(e,n.target);const{target:i}=n;delete n.target;const s=e=>e.map(e=>qt(e)?Ht(e,t,n,r):e);if(Array.isArray(e))return s(e);for(const[o,l]of Object.entries(e)){const a=t(o,l,e);if(a===Lt)continue;let[u,c,{shouldRecurse:h=!0}={}]=a;"__proto__"!==u&&(n.deep&&h&&qt(c)&&(c=Array.isArray(c)?s(c):Ht(c,t,n,r)),i[u]=c)}return i};const Ft=/[\p{Lu}]/u,jt=/[\p{Ll}]/u,Gt=/^[\p{Lu}](?![\p{Lu}])/gu,$t=/([\p{Alpha}\p{N}_]|$)/u,Bt=/[_.\- ]+/,Wt=new RegExp("^"+Bt.source),Vt=new RegExp(Bt.source+$t.source,"gu"),zt=new RegExp("\\d+"+$t.source,"gu");function Kt(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},0===(e=Array.isArray(e)?e.map(e=>e.trim()).filter(e=>e.length).join("-"):e.trim()).length)return"";const n=!1===t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),r=!1===t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);if(1===e.length)return Bt.test(e)?"":t.pascalCase?r(e):n(e);return e!==n(e)&&(e=((e,t,n,r)=>{let i=!1,s=!1,o=!1,l=!1;for(let a=0;a<e.length;a++){const u=e[a];l=!(a>2)||"-"===e[a-3],i&&Ft.test(u)?(e=e.slice(0,a)+"-"+e.slice(a),i=!1,o=s,s=!0,a++):s&&o&&jt.test(u)&&(!l||r)?(e=e.slice(0,a-1)+"-"+e.slice(a-1),o=s,s=!1,i=!0):(i=t(u)===u&&n(u)!==u,o=s,s=n(u)===u&&t(u)!==u)}return e})(e,n,r,t.preserveConsecutiveUppercase)),e=e.replace(Wt,""),e=t.preserveConsecutiveUppercase?((e,t)=>(Gt.lastIndex=0,e.replaceAll(Gt,e=>t(e))))(e,n):n(e),t.pascalCase&&(e=r(e.charAt(0))+e.slice(1)),((e,t)=>(Vt.lastIndex=0,zt.lastIndex=0,e.replaceAll(zt,(n,r,i)=>["_","-"].includes(e.charAt(i+n.length))?n:t(n)).replaceAll(Vt,(e,n)=>t(n))))(e,r)}class Yt extends Map{#e=0;#t=new Map;#n=new Map;#r;#i;#s;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.#r=e.maxSize,this.#i=e.maxAge||Number.POSITIVE_INFINITY,this.#s=e.onEviction}get __oldCache(){return this.#n}#o(e){if("function"==typeof this.#s)for(const[t,n]of e)this.#s(t,n.value)}#l(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof this.#s&&this.#s(e,t.value),this.delete(e))}#a(e,t){if(!1===this.#l(e,t))return t.value}#u(e,t){return t.expiry?this.#a(e,t):t.value}#c(e,t){const n=t.get(e);return this.#u(e,n)}#h(e,t){this.#t.set(e,t),this.#e++,this.#e>=this.#r&&(this.#e=0,this.#o(this.#n),this.#n=this.#t,this.#t=new Map)}#d(e,t){this.#n.delete(e),this.#h(e,t)}*#f(){for(const e of this.#n){const[t,n]=e;if(!this.#t.has(t)){!1===this.#l(t,n)&&(yield e)}}for(const e of this.#t){const[t,n]=e;!1===this.#l(t,n)&&(yield e)}}get(e){if(this.#t.has(e)){const t=this.#t.get(e);return this.#u(e,t)}if(this.#n.has(e)){const t=this.#n.get(e);if(!1===this.#l(e,t))return this.#d(e,t),t.value}}set(e,t,{maxAge:n=this.#i}={}){const r="number"==typeof n&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#t.has(e)?this.#t.set(e,{value:t,expiry:r}):this.#h(e,{value:t,expiry:r}),this}has(e){return this.#t.has(e)?!this.#l(e,this.#t.get(e)):!!this.#n.has(e)&&!this.#l(e,this.#n.get(e))}peek(e){return this.#t.has(e)?this.#c(e,this.#t):this.#n.has(e)?this.#c(e,this.#n):void 0}expiresIn(e){const t=this.#t.get(e)??this.#n.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){const t=this.#t.delete(e);return t&&this.#e--,this.#n.delete(e)||t}clear(){this.#t.clear(),this.#n.clear(),this.#e=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this.#f()],n=t.length-e;n<0?(this.#t=new Map(t),this.#n=new Map,this.#e=t.length):(n>0&&this.#o(t.slice(0,n)),this.#n=new Map(t.slice(n)),this.#t=new Map,this.#e=0),this.#r=e}evict(e=1){const t=Number(e);if(!t||t<=0)return;const n=[...this.#f()],r=Math.trunc(Math.min(t,Math.max(n.length-1,0)));r<=0||(this.#o(n.slice(0,r)),this.#n=new Map(n.slice(r)),this.#t=new Map,this.#e=0)}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.#t){const[t,n]=e;!1===this.#l(t,n)&&(yield[t,n.value])}for(const e of this.#n){const[t,n]=e;if(!this.#t.has(t)){!1===this.#l(t,n)&&(yield[t,n.value])}}}*entriesDescending(){let e=[...this.#t];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;!1===this.#l(r,i)&&(yield[r,i.value])}e=[...this.#n];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;if(!this.#t.has(r)){!1===this.#l(r,i)&&(yield[r,i.value])}}}*entriesAscending(){for(const[e,t]of this.#f())yield[e,t.value]}get size(){if(!this.#e)return this.#n.size;let e=0;for(const t of this.#n.keys())this.#t.has(t)||e++;return Math.min(this.#e+e,this.#r)}get maxSize(){return this.#r}get maxAge(){return this.#i}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[n,r]of this.entriesAscending())e.call(t,r,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}const Xt=new Yt({maxSize:1e5}),Jt=e=>"object"==typeof e&&null!==e&&!(e=>ArrayBuffer.isView(e)||e instanceof Date||e instanceof RegExp||e instanceof Error||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof Promise)(e),Qt=(e,t={},n=new WeakMap,r)=>{if(!Jt(e))return e;if(n.has(e))return n.get(e);const{exclude:i,pascalCase:s=!1,stopPaths:o,deep:l=!1,preserveConsecutiveUppercase:a=!1}=t,u=new Set(o);if(Array.isArray(e)){const i=[];n.set(e,i);for(const s of e)i.push(Jt(s)?Qt(s,t,n,r):s);return i}const c={};n.set(e,c);const h=function(e,t,n){if(!Mt(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);if(Array.isArray(e))throw new TypeError("Expected an object, got an array");return Ht(e,t,n)}(e,(d=r,(e,r)=>{if(l&&Jt(r)){const i=void 0===d?e:`${d}.${e}`;u.has(i)||(r=Array.isArray(r)?r.map(e=>Jt(e)?Qt(e,t,n,i):e):Qt(r,t,n,i))}if(!("string"!=typeof e||(e=>""!==e.trim()&&!Number.isNaN(Number(e)))(e)||i&&((e,t)=>e.some(e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t))))(i,e))){const t=s?`${e}_`:e;if(Xt.has(t))e=Xt.get(t);else{const n=e.match(/^[_$]*/)[0],r=Kt(e.slice(n.length),{pascalCase:s,locale:!1,preserveConsecutiveUppercase:a});(e=n+r).length<100&&Xt.set(t,e)}}return[e,r]}),{deep:!1});var d;Object.assign(c,h);const f=Object.getOwnPropertySymbols(e);for(const i of f)c[i]=l&&Jt(e[i])?Qt(e[i],t,n,r):e[i];return c};function Zt(e,t){const n=new WeakMap;return Array.isArray(e)?e.map(e=>Jt(e)?Qt(e,t,n,void 0):e):Qt(e,t,n)}const en={wssServer:"wss://api.telegenta.com/sip/",eventServer:"wss://esvc.telegenta.com/",provisionToken:null,authorizationUsername:null,password:null,callToken:null,register:!0,iceGatherTimeout:3e3,playSignalTones:!0,logger:null,logLevel:3,connectEventService:!1,useCallDataInfoEvent:!1,toneVolume:.3,autoBusyIncoming:!0,autoRemoveSessionTime:3e3,playRingOnIncoming:!0,playCallInitializedTone:!1},tn={1:[1209,697],2:[1336,697],3:[1477,697],a:[1633,697],4:[1209,770],5:[1336,770],6:[1477,770],b:[1633,770],7:[1209,852],8:[1336,852],9:[1477,852],c:[1633,852],"*":[1209,941],0:[1336,941],"#":[1477,941],d:[1633,941]},nn=[{d:250,f1:425,f2:0,g:250}],rn=[{d:500,f1:425,f2:0,g:500}],sn=[{d:333,f1:950,f2:0,g:0},{d:333,f1:1400,f2:0,g:0},{d:333,f1:1800,f2:0,g:1e3}],on=[{d:200,f1:500,f2:0,g:0},{d:200,f1:700,f2:0,g:5e3}],ln=[{d:1e3,f1:425,f2:0,g:4e3}],an=[{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:0},{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:0},{d:150,f1:400,f2:0,g:0},{d:150,f1:600,f2:0,g:3e3}];class un extends a{constructor(e){super(),this._phone=e,this.log=e.log,this._callUUID=null,this._webRTCSession=null,this._sessionState=null,this._iceCandidateTimer=null,this._isOnHold=!1,this._isMuted=!1,this._isRecording=!1,this._recordingError=null,this._callBeginTime=null,this._callAnswerTime=null,this._callEndTime=null,this._durationUpdTimerObj=null,this._originatingNumber=null,this._destinationNumber=null,this._callDisposition=null,this._localNumberName=null,this._isListenCall=!1,this._whisperMode=null,this._manualDisposition=null,this._rtcpStatsTimer=null,this._currentReport=null,this._answerCallTimeout=0,this._answerCallTimer=null,this._mediaSwitch=null}newOutboundSession(e,t){this._callUUID=v(),this.log.debug(`Created new outbound session to: ${e} [${this._callUUID}]`),this.destinationNumber=e;let n,r={mediaConstraints:{audio:!0,video:!1},pcConfig:{iceServers:[{urls:["stun:stun.l.google.com:19302"]}]},extraHeaders:["X-Call-token: "+this._phone.options.callToken,"X-P-UUID: "+this._callUUID,"X-Max-cost: "+t.maximumCallCost]};if(t.explicitCallerId&&r.extraHeaders.push("X-CID-Number-Id: "+t.explicitCallerId),t.explicitShortCallerId&&r.extraHeaders.push("X-Short-CID-Id: "+t.explicitShortCallerId),t.metaInfo&&r.extraHeaders.push("X-Meta-Info: "+encodeURI(t.metaInfo.toString().substr(0,255))),t.record){if(isNaN(t.record))throw new f("Record parameter must be a number");this.log.debug(`Recording enabled and kept for ${t.record} days`),r.extraHeaders.push("X-Record: "+t.record),this._isRecording=!0}else this._isRecording=!1;if(this._isListenCall=t._isListenCall,t.mediaSwitchURI)this.log.debug("Requesting specific media switch "+t.mediaSwitchURI),r.extraHeaders.push("X-RMS: "+t.mediaSwitchURI);else{const e=this.getOtherSessions();e.length>0?e[0]._mediaSwitch?(this.log.debug("Requesting call grouping on media switch "+e[0]._mediaSwitch),r.extraHeaders.push("X-RMS: sip:"+e[0]._mediaSwitch)):this.log.warning("Other sessions exist but media switch address is invalid"):this.log.debug("No other active calls, no media switch grouping requested")}try{n=w(t.setHeader)}catch(e){if(e instanceof TypeError)throw new f(e.message);throw e}for(const e of n)this.log.debug("Adding custom header: "+e),r.extraHeaders.push(e);const i="sip:"+e+"@telegenta.com";try{this._initWebRTCSession(this._phone._UA.call(i,r))}catch(e){return this.log.error("Error starting call:",e),null}t.answerCallTimeout&&this._setAnswerCallTimeout(t.answerCallTimeout)}newInboundSession(e){this._callUUID=e.request.getHeader("X-P-UUID",0),this._destinationNumber=e.request.getHeader("X-DID",0),this._localNumberName=unescape(e.request.getHeader("X-DID-NAME",0)),this._originName=e.request.from.display_name,this._originatingNumber=e.request.from.uri.user,this.log.info(`Incoming call from ${this._originatingNumber} [${this._callUUID}]`),this.log.debug(e),this._mediaSwitch=e.request.getHeader("X-MS"),this.log.debug(`Media switch handling call: ${this._mediaSwitch}`),this._initWebRTCSession(e.session)}getOtherSessions(){const e=this._phone.sessions;let t=[];for(let n in e)e[n]&&e[n].__containerId!==this.__containerId&&t.push(e[n]);return t}_initWebRTCSession(e){this._webRTCSession=e,this._callBeginTime=Date.now();const t=this;this._webRTCSession.on("icecandidate",function(e){const n=e.candidate;t.log.debug(`Got ICE candidate: ${n.candidate}`),"srflx"===n.type&&null!==n.relatedAddress&&null!==n.relatedPort?(t.log.info(`Accepting ICE candidate: ${n.candidate}`),null!=t._iceCandidateTimer&&clearTimeout(t._iceCandidateTimer),e.ready()):(null!=t._iceCandidateTimer&&clearTimeout(t._iceCandidateTimer),t._iceCandidateTimer=setTimeout(function(e){t.log.debug(`ICE Timeout (${t._phone.options.iceGatherTimeout} ms) reached`),e.ready()},t._phone.options.iceGatherTimeout,e))}),this._webRTCSession.on("connecting",function(){t._startDurationUpdateTimer(),t._startRTCPStatsUpdateTimer(),t._setSessionState("INITIALIZING")}),this._webRTCSession.on("sending",function(){t._phone.options.playCallInitializedTone&&t._phone._startRepeatTone(on),t._setSessionState("CALLING")}),this._webRTCSession.on("progress",function(e){"remote"===e.originator&&(t._setSessionState("PROGRESS",{code:e.response.status_code}),t._phone._endRepeatTone(),180===e.response.status_code&&t._phone._startRepeatTone(ln),t._answerCallTimeout&&(t._answerCallTimer=setTimeout(function(){t.log.info(`Answer call timeout after ${t._answerCallTimeout} seconds`);try{t.hangup()}catch(e){t.log.info("No active session, ignoring answer call timeout")}},1e3*t._answerCallTimeout)))}),this._webRTCSession.on("accepted",function(e){if(t._phone._endRepeatTone(),t._callAnswerTime=Date.now(),t._answerCallTimeout&&(clearTimeout(t._answerCallTimer),t._answerCallTimeout=0),"remote"===e.originator){"true"===e.response.getHeader("X-Recording")?t.log.debug("Call is being prerecorded"):t.log.debug("No call recording started yet"),t._mediaSwitch=e.response.getHeader("X-MS"),t.log.debug(`Media switch handling call: ${t._mediaSwitch}`)}}),this._webRTCSession.on("confirmed",function(){t._setSessionState("ACTIVE")}),this._webRTCSession.on("ended",function(){t._phone._endRepeatTone(),t._callEndTime=Date.now(),t._answerCallTimeout&&clearTimeout(t._answerCallTimer),t._setSessionState("TERMINATED")}),this._webRTCSession.on("failed",function(e){let n;t._phone._endRepeatTone(),t._callEndTime=Date.now(),t._answerCallTimeout&&clearTimeout(t._answerCallTimer),n=e.message?`${e.message.status_code} ${e.message.reason_phrase}`:"",t._setSessionState("FAILED",{cause:e.cause,message:n})}),this._webRTCSession.on("dtmf",function(e){t.log.debug("Session DTMF",e)}),this._webRTCSession.on("newInfo",function(e){t.log.debug("New session info",e)}),this._webRTCSession.on("hold",function(){t._isOnHold=!0,t._fireHoldStateEvent(),t._setSessionState("ON_HOLD")}),this._webRTCSession.on("unhold",function(){t._isOnHold=!1,t._fireHoldStateEvent(),t._setSessionState("ACTIVE")}),this._webRTCSession.on("muted",function(e){t.log.debug("Microphone muted",e),t._isMuted=!0,t._fireMuteStateEvent()}),this._webRTCSession.on("unmuted",function(e){t.log.debug("Microphone unmuted",e),t._isMuted=!1,t._fireMuteStateEvent()}),this._webRTCSession.on("reinvite",function(e){t.log.debug("Session reinvite",e)}),this._webRTCSession.on("update",function(e){t.log.debug("Session update",e)}),this._webRTCSession.on("getusermediafailed",function(e){t.log.error("Getusermedia failed",e)}),t._webRTCSession.connection&&t._handleRemoteAudio(t._webRTCSession),this.log.debug("WebRTCSession object:"),this.log.debug(this)}hangup(e=null){e?(this.log.info(`Hanging up call with disposition ${e}`),this._manualDisposition=e,this._webRTCSession.terminate({extraHeaders:["X-HDISP: "+e]})):(this.log.info("Hanging up call"),this._webRTCSession.terminate())}answer(e=null){let t={mediaConstraints:{audio:!0,video:!1},pcConfig:{iceServers:[{urls:["stun:stun.l.google.com:19302"]}]},extraHeaders:["X-Call-token: "+this._phone.options.callToken]};e&&t.extraHeaders.push("X-Meta-Info: "+encodeURI(e.toString().substr(0,255))),this._webRTCSession.answer(t),this._handleRemoteAudio(this._webRTCSession)}reject(e=603,t="Rejected call"){this.log.info("Rejecting call"),this._webRTCSession.terminate({status_code:e,reason_phrase:t})}get uuid(){return this._callUUID}get destinationNumber(){return this._destinationNumber}get localNumberName(){return this._localNumberName}get originatingNumber(){return this._originatingNumber}set destinationNumber(e){this.log.debug("Setting destination number to: "+e),this._destinationNumber=e}get state(){return this._sessionState}get direction(){return this._isListenCall?(this.log.debug("Call direction is LISTEN"),"LISTEN"):"incoming"===this._webRTCSession.direction?(this.log.debug("Call direction is INBOUND"),"INBOUND"):"outgoing"===this._webRTCSession.direction?(this.log.debug("Call direction is OUTBOUND"),"OUTBOUND"):(this.log.error("Unknown call direction: "+this._webRTCSession.direction),"UNKNOWN")}getRTCStats(){if(!this._webRTCSession||!this._webRTCSession.connection)throw new _("no peer connection for this session");return this._webRTCSession.connection.getStats()}startRecording(){this.log.debug("Request start recording");const e=this;this._webRTCSession.once("newInfo",t=>{"local"===t.originator&&(t.info.on("succeeded",function(){e.log.info("Recording started successfully"),e._isRecording=!0;try{e.emit("recordingStateChange",{state:!0,error:null})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}}),t.info.on("failed",function(t){e._recordingError=t.response.reason_phrase,e.log.error("Recording start failed: "+e._recordingError),e._fireRecordingStateEvent()}))}),this._webRTCSession.sendInfo("application/info",null,{extraHeaders:["Record: on"]})}stopRecording(){this.log.debug("Request stop recording");const e=this;this._webRTCSession.once("newInfo",t=>{t.info.on("succeeded",function(){e.log.info("Recording stopped successfully"),e._isRecording=!1;try{e.emit("recordingStateChange",{state:!1,error:null})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}}),t.info.on("failed",function(t){e.log.error("Recording stopped failed: "+t.response.reason_phrase);try{e.emit("recordingStateChange",{state:e._isRecording,error:t.response.reason_phrase})}catch(t){e.log.error("Exception in recordingStateChange event: "+t)}})}),this._webRTCSession.sendInfo("application/info",null,{extraHeaders:["Record: off"]})}toggleRecording(){return this._isRecording?(this.stopRecording(),!1):(this.startRecording(),!0)}get isRecording(){return this._isRecording}muteMic(){this.log.info("Mute microphone"),this._webRTCSession.mute()}unmuteMic(){this.log.info("Unmute microphone"),this._webRTCSession.unmute()}toggleMute(){this._isMuted?this.unmuteMic():this.muteMic()}get isMuted(){return this._isMuted}hold(){this.log.info("Hold call"),this._webRTCSession.hold()}unhold(){this.log.info("Uncall call"),this._phone.holdAllCalls(),this._webRTCSession.unhold()}toggleHold(){this._isOnHold?this.unhold():this.hold()}get isOnHold(){return this._isOnHold}sendDTMF(e,t=!0){if(!(e in tn))throw new f("Invalid DTMF code");if(this.log.info("Sending DTMF: "+e),this._webRTCSession.sendDTMF(e),t){const t=tn[e];if(this._isMuted)this.log.debug("Mic already muted, just sending DTMF"),this._phone.playTone(500,t[0],t[1]);else{this.log.debug("Mute mic while sending DTMF"),this._webRTCSession.mute();const e=this;this._phone.playTone(500,t[0],t[1],function(){e.log.debug("Unmute mic after DTMF"),e._webRTCSession.unmute()})}}}transfer(e){this.log.info(`Transferring ${this.uuid} => ${e.uuid}`);const t=this._webRTCSession.refer(this._webRTCSession._request.ruri,{replaces:e._webRTCSession}),n=this;t.on("requestSucceeded",function(){n.log.info("Transfer completed successfully")}),t.on("requestFailed",function(e){n.log.error(`Transfer rejected: ${e}`)}),t.on("failed",function(e){n.log.error(`Transfer failed: ${e}`)})}playback(e,t=!1){if(!this._phone._options.connectEventService)throw new m("Event service not enabled");this.log.info(`Playback media file ${e} hangup after ${t}`);const n=this._phone._eventClient.fireEvent("call_command",{call_uuid:this.uuid,call_command:"playback",media_file_id:e,hangup_after:t});return t&&(this._phone._remoteAudioElement.srcObject=null,this._webRTCSession.mute(),n.then(()=>{this._setSessionState("PLAYBACK")})),n}setWhisperMode(e=0){if("LISTEN"===!this.direction)throw new m("Call is not correct type (listen)");if(e<0||e>2)throw new d("Invalid mode");let t;0===e&&(t=0),1===e&&(t=2),2===e&&(t=3),this.sendDTMF(t,!1),this._whisperMode=e,this._fireWhisperModeChangeEvent()}_startDurationUpdateTimer(){const e=this;this._durationUpdTimerObj||(this._durationUpdTimerObj=setInterval(function(){const t=e._callAnswerTime?Date.now()-e._callAnswerTime:null,n={uuid:e._callUUID,beginTime:e._callBeginTime,answerTime:e._callAnswerTime,endTime:e._callEndTime,duration:Date.now()-e._callBeginTime,durationStr:y(Date.now()-e._callBeginTime),activeDuration:t,activeDurationStr:t?y(t):""};try{e.emit("callDurationUpdate",n)}catch(n){e.log.error("Exception in call duration update event: "+n)}},1e3))}_startRTCPStatsUpdateTimer(){if(!this._rtcpStatsTimer){const e={outboundPacketsSent:0,outboundBytesSent:0,outboundPacketsLost:0,outboundJitter:0,inboundPacketsReceived:0,inboundBytesReceived:0,inboundPacketsLost:0,inboundJitter:0,roundTripTime:0};this._currentReport=Object.assign({},e),this._rtcpStatsTimer=setInterval(()=>{this._webRTCSession._connection.getStats().then(t=>{let n=Object.assign({},e),r=Object.assign({},e);for(let e of t.values())switch(e.type){case"outbound-rtp":n.outboundPacketsSent=e.packetsSent,r.outboundPacketsSent=e.packetsSent-this._currentReport.outboundPacketsSent,n.outboundBytesSent=e.bytesSent,r.outboundBytesSent=e.bytesSent-this._currentReport.outboundBytesSent;break;case"inbound-rtp":n.inboundPacketsReceived=e.packetsReceived,r.inboundPacketsReceived=e.packetsReceived-this._currentReport.inboundPacketsReceived,n.inboundBytesReceived=e.bytesReceived,r.inboundBytesReceived=e.bytesReceived-this._currentReport.inboundBytesReceived,n.inboundPacketsLost=e.packetsLost,r.inboundPacketsLost=e.packetsLost-this._currentReport.inboundPacketsLost,n.inboundJitter=1e3*e.jitter,r.inboundJitter=1e3*e.jitter;break;case"remote-inbound-rtp":n.outboundPacketsLost=e.packetsLost,r.outboundPacketsLost=e.packetsLost-this._currentReport.outboundPacketsLost,n.outboundJitter=1e3*e.jitter,r.outboundJitter=1e3*e.jitter,n.roundTripTime=1e3*e.roundTripTime,r.roundTripTime=1e3*e.roundTripTime}if(this._currentReport=this._calcReportMetrics(n),n.roundTripTime){const e={total:this._currentReport,delta:this._calcReportMetrics(r)};try{this.emit("callQualityReportUpdate",e)}catch(e){this.log.error("Exception in call quality report update event: "+e)}}})},5e3)}}_calcReportMetrics(e){e.outboundPacketLossPct=e.outboundPacketsLost/e.outboundPacketsSent,e.inboundPacketLossPct=e.inboundPacketsLost/e.inboundPacketsReceived,e.effectiveLatency=e.roundTripTime+(e.inboundJitter+e.outboundJitter)+10;const t=100*(e.outboundPacketLossPct+e.inboundPacketLossPct),n=95*t/(t+10),r=.1*e.effectiveLatency;switch(e.rFactor=Math.max(0,100-n-r),e.mos=1+.035*e.rFactor+7e-6*e.rFactor*(e.rFactor-60)*(100-e.rFactor),!0){case e.rFactor<50:e.qualityString="Bad";break;case e.rFactor<70:e.qualityString="Poor";break;case e.rFactor<80:e.qualityString="Fair";break;case e.rFactor<90:e.qualityString="Good";break;case e.rFactor<=100:e.qualityString="Excellent";break;default:e.qualityString="Error"}return e}_setSessionState(e,t=null){this.log.debug("Session state: "+e),t&&this.log.debug(t),this._sessionState=e;try{this.emit("sessionStateChange",Object.assign({state:e,uuid:this._callUUID},t))}catch(e){this.log.error("Exception in sessionStateChange event:"+e)}"TERMINATED"===e&&(this._callDisposition=this._manualDisposition||"NORMAL",this._callFinished()),"FAILED"===e&&("Unavailable"===t.cause&&(this._callDisposition="TEMP_UNAVAIL",this._phone.options.playSignalTones&&this._phone._startRepeatTone(nn)),"Not Found"===t.cause&&(this._callDisposition="INVALID_NUMBER",this._phone.options.playSignalTones&&this._phone._startRepeatTone(sn)),"Canceled"===t.cause&&(this._callDisposition=this._manualDisposition||"NO_ANSWER"),"Rejected"===t.cause&&("INBOUND"===this.direction?this._callDisposition="REJECTED":this._callDisposition="BARRED"),"Busy"===t.cause&&(this._callDisposition="BUSY",this._phone.options.playSignalTones&&this._phone._startRepeatTone(rn)),this._webRTCSession.direction,this._callFinished())}_callFinished(){this.log.info("Call finished"),this._fireCallEndedEvent(),clearInterval(this._durationUpdTimerObj),clearInterval(this._rtcpStatsTimer),this._phone._sessionTerminated(this)}_setAnswerCallTimeout(e){this.log.debug("Setting answer call timeout to: "+e),this._answerCallTimeout=e}_fireRecordingStateEvent(){try{this.emit("recordingStateChange",{state:this._isRecording,error:this._recordingError})}catch(e){this.log.error("Exception in recording state change event: "+e)}}_fireMuteStateEvent(){try{this.emit("muteStateChange",{state:this._isMuted})}catch(e){this.log.error("Exception in mute state change event: "+e)}}_fireHoldStateEvent(){try{this.emit("holdStateChange",{state:this._isOnHold})}catch(e){this.log.error("Exception in hold state change event: "+e)}}_fireWhisperModeChangeEvent(){try{this.emit("whisperModeChange",{mode:this._whisperMode})}catch(e){this.log.error("Exception in whisper mode change event: "+e)}}_fireCallEndedEvent(){let e;e={uuid:this._callUUID,direction:this.direction,disposition:this._callDisposition,originatingNumber:this._originatingNumber,destinationNumber:this._destinationNumber,duration:this._callEndTime-this._callBeginTime,answerDuration:this._callAnswerTime?this._callAnswerTime-this._callBeginTime:null,activeDuration:this._callAnswerTime?this._callEndTime-this._callAnswerTime:null,startTime:new Date(this._callBeginTime).toISOString(),endTime:new Date(this._callEndTime).toISOString(),answerTime:this._callAnswerTime?new Date(this._callAnswerTime).toISOString():null},e.durationStr=y(e.duration),e.answerDurationStr=e.answerDuration?y(e.answerDuration):"",e.activeDurationStr=e.activeDuration?y(e.activeDuration):"",e.callQualityReport=this._currentReport;try{this.emit("callEnded",e)}catch(e){this.log.error("Exception in callEnded event: "+e)}}_handleRemoteAudio(e){this._phone._endRepeatTone();const t=this;e.connection.ontrack=function(e){t.log.debug("Start media output (track):"),t.log.debug(e),t._phone._remoteAudioElement.srcObject=e.streams[0]}}}return e.EventClient=k,e.EventServiceNotConnected=g,e.InvalidMediaDevice=h,e.InvalidOptions=d,e.InvalidParameter=f,e.LOGLVL=n,e.LogHandler=t,e.MediaNotPrepared=u,e.NoActiveSession=_,e.NotAllowed=m,e.NotReady=c,e.Phone=class extends a{constructor(e=null){super(),this._mediaPermission=!1,this._mediaPermissionError=!1,this._UA=null,this._connectionState=null,this._isStarted=!1,this._eventClient=null,this._options=null,this._sessionCounter=0,this._activeSessions={},this._remoteAudioElement=document.createElement("AUDIO"),this._remoteAudioElement.autoplay=!0,this._toneAudioElement=document.createElement("AUDIO"),this._toneAudioElement.autoplay=!0,this._toneTimer=null,this._repeatToneActive=!1,this._repeatToneSequence=[],this._repeatToneSequencePos=0,this._toneGainProcessor=null,this._oscillator1=null,this._oscillator2=null,this.log=e||new t(n.INFO),this.log.level,n.DEBUG,Pt.debug.disable("JsSIP:*")}prepareMedia(){this.log.info("Get media permission");const e=this,t={audio:!0,video:!1};return new Promise(function(n,r){navigator.mediaDevices.getUserMedia(t).then(()=>{e._mediaPermission=!0,e._mediaPermissionError=!1,e.log.info("Media permission granted"),n()},t=>{e._mediaPermission=!1,e._mediaPermissionError=!0,e.log.error("Denied media permission: "+t),r(t)})})}start(e){if(this._checkMediaPermission(),this._isStarted&&(this.log.warning("Phone already started, stopping first"),this.stop()),this._options=Object.assign(en,e),this._initToneGenerator(),this._options.provisionToken){let e=null;try{e=JSON.parse(atob(this._options.provisionToken))}catch(e){throw new d("provisionToken","Invalid token")}this.log.info("Using provisioning token authorization"),this._options.wssServer=e.wss_server,this._options.eventServer=e.event_server,this._options.authorizationUsername=e.wss_username,this._options.password=e.wss_password,this._options.callToken=e.wss_token}else{if(this.log.info("Using manual specified credentials"),!this._options.authorizationUsername)throw new d("authorizationUsername","Missing username");if(!this._options.password)throw new d("password","Missing password");if(!this._options.callToken)throw new d("callToken","Missing call token")}this._options.useCallDataInfoEvent&&!this._options.connectEventService&&(this.log.info("Enabled event service because 'useCallDataInfoEvent' is enabled"),this._options.connectEventService=!0),this._options.connectEventService&&(this._eventClient=new k(this.log),this._eventClient.connect(this._options.eventServer).then(()=>{if(this.log.info("Connected to event server"),this._options.useCallDataInfoEvent){let e={event_name:"calldata_available",call_token:this._options.callToken};this._eventClient.subscribe(e,e=>{try{this.log.debug("Received remote call data info"),this.log.debug(e),this._fireCallDataInfoEvent(e)}catch(e){this.log.error("Event callback failed: "+e)}}).then(e=>{this.log.info(`Subscription successful ID = ${e}`)},e=>{this.log.error(`Subscribe failed: ${e}`)})}},e=>{this.log.error(`Unable to connect to event server: ${e}`)}));let t=null;try{t=new Pt.WebSocketInterface(this._options.wssServer)}catch(e){throw new p("Unable to connect phone websocket: "+e)}this.log.info("Starting phone"),this.log.debug(this._options),this._UA=new Pt.UA({sockets:[t],authorization_user:this._options.authorizationUsername,password:this._options.password,register:this._options.register,display_name:this._options.authorizationUsername,uri:this._options.authorizationUsername+"@telegenta.com",session_timers:!1});const n=this;this._UA.on("newRTCSession",function(e){if(n.log.debug("New RTCSession"),"remote"===e.originator){const t=new un(n);if(t.newInboundSession(e),n._options.playRingOnIncoming&&n._startRepeatTone(an),n._options.autoBusyIncoming){if(Object.keys(n._activeSessions).length>0)return n.log.info(`Autorejecting incoming call ${t.uuid} because there is already active calls`),void t.reject(486,"Busy");n.log.debug("There are no other sessions, adding incoming call")}n._addSession(t),t._setSessionState("INCOMING"),n._fireIncomingCallEvent(t)}}),this._UA.on("connecting",function(){n._setConnectionState("CONNECTING")}),this._UA.on("connected",function(){n._setConnectionState("CONNECTED")}),this._UA.on("disconnected",function(){n._setConnectionState("DISCONNECTED")}),this._UA.on("registered",function(){n._setConnectionState("REGISTERED")}),this._UA.on("unregistered",function(){n._setConnectionState("UNREGISTERED")}),this._UA.on("registrationFailed",function(){n._setConnectionState("REGISTRATION_FAILED")}),this._UA.start(),this._isStarted=!0,this.log.info("Successfully started phone")}stop(){if(!this._isStarted)throw new c("Phone is not started");if(this._UA.removeAllListeners(),this._UA.stop(),delete this._UA,this._eventClient){try{this._eventClient.disconnect(),delete this._eventClient}catch(e){this.log.warning("Unable to disconnect event client")}this._isStarted=!1,this.log.info("Phone client successfully stopped")}else this.log.debug("Event client not running, not stopping")}call(e,t={}){if(!this._isStarted)throw new c("Phone is not started");if(this._checkForConnectingCalls())throw new m("Unable to make new calls while others are connecting");this.holdAllCalls();const n=Object.assign({record:!1,maximumCallCost:0,answerCallTimeout:0,explicitCallerId:null,explicitShortCallerId:null,metaInfo:null,setHeader:null,_isListenCall:!1},t);e=e.trim().replace(/ |\(|\)/g,""),this.log.info("Calling number: "+e);let r=new un(this);return r.newOutboundSession(e,n),this._addSession(r),r}listen(e){const t=e.split("@");let n=t[0],r="sip:"+t[1];return this.log.debug("Initiating listen to call with uuid "+n+" on media switch "+r),this.call("listen-"+n,{mediaSwitchURI:r,_isListenCall:!0})}getSessionByUUID(e){for(let t in this._activeSessions)if(this._activeSessions.hasOwnProperty(t)&&this._activeSessions[t].uuid===e)return this._activeSessions[t];return null}get options(){return this._options}get sessions(){let e=[];for(let t in this._activeSessions)this._activeSessions.hasOwnProperty(t)&&e.push(this._activeSessions[t]);return e}get hasMediaPermission(){return this._mediaPermission}get hasMediaPermissionError(){return this._mediaPermissionError}get isStarted(){return this._isStarted}get browserSupported(){return b()||S()||T()||C()}get remoteAudioElement(){return this._remoteAudioElement}playTone(e,t,n=0,r=null){this.log.debug(`Playing tone ${t} / ${n} for ${e} ms`),this._oscillator1.frequency.value=t,this._oscillator2.frequency.value=n,this._toneGainProcessor.gain.value=this._options.toneVolume;const i=this;this._toneTimer=setTimeout(function(){i.stopTone(),r&&r()},e)}stopTone(){this._oscillator1.frequency.value=0,this._oscillator2.frequency.value=0,this._toneGainProcessor.gain.value=0,clearTimeout(this._toneTimer)}_startRepeatTone(e){this.log.info("Repeating tone sequence started"),this.log.debug(e),this._repeatToneSequence=e,this._repeatToneSequencePos=0,this._repeatToneActive=!0,this._doRepeatTone()}_doRepeatTone(){if(this._repeatToneActive){this.log.debug(`Playing repeated tone, pos = ${this._repeatToneSequencePos}`);let e=this._repeatToneSequence[this._repeatToneSequencePos];this._repeatToneSequencePos++,this._repeatToneSequencePos===this._repeatToneSequence.length&&(this._repeatToneSequencePos=0);const t=this;this.playTone(e.d,e.f1,e.f2,function(){setTimeout(t._doRepeatTone.bind(t),e.g)})}}_endRepeatTone(){this._repeatToneActive&&(this.log.info("Repeating tone stopped"),this._repeatToneActive=!1,this.stopTone())}_initToneGenerator(){const e=window.AudioContext||window.webkitAudioContext||!1;if(!e)throw new m("Audio API not supported by this browser");const t=new e;this._toneStreamNode=t.createMediaStreamDestination(),this._toneAudioElement.srcObject=this._toneStreamNode.stream,this._toneGainProcessor=t.createGain(),this._toneGainProcessor.gain.value=0,this._toneGainProcessor.connect(this._toneStreamNode),this._oscillator1=t.createOscillator(),this._oscillator1.connect(this._toneGainProcessor),this._oscillator1.frequency.value=0,this._oscillator1.start(),this._oscillator2=t.createOscillator(),this._oscillator2.connect(this._toneGainProcessor),this._oscillator2.frequency.value=0,this._oscillator2.start()}holdAllCalls(){if(this.log.info("Holding all active sessions"),this._checkForConnectingCalls())throw new m("A session is currently connecting");for(let e in this._activeSessions)if(this._activeSessions.hasOwnProperty(e)){let t=this._activeSessions[e];"ACTIVE"===t.state&&t.hold()}}_addSession(e){this._sessionCounter++,e.__containerId=this._sessionCounter,this.log.info(`Adding new session ${e.__containerId}: ${e.uuid}`),this._activeSessions[e.__containerId]=e,this.log.debug(`We now have ${Object.keys(this._activeSessions).length} sessions:`),this.log.debug(this._activeSessions);try{this.emit("sessionCreated",{session:e})}catch(e){this.log.error("Exception in sessionCreated event: "+e)}}_removeSession(e){this.log.info(`Removing session ${e.__containerId}: ${e.uuid}`);try{this.emit("sessionRemoved",{session:e})}catch(e){this.log.error("Exception in sessionRemoved event: "+e)}delete this._activeSessions[e.__containerId],this.log.debug(`We now have ${Object.keys(this._activeSessions).length} sessions`),this.log.debug(this._activeSessions),this._endRepeatTone()}_sessionTerminated(e){this.log.debug(`Session ${e.uuid} terminated, removing in ${this._options.autoRemoveSessionTime} ms`);const t=this;setTimeout(function(){t._removeSession(e)},this._options.autoRemoveSessionTime)}_checkForConnectingCalls(){for(let e in this._activeSessions)if(this._activeSessions.hasOwnProperty(e)){let t=this._activeSessions[e];if("INITIALIZING"===t.state||"CALLING"===t.state||"PROGRESS"===t.state||"INCOMING"===t.state)return!0}return!1}_setConnectionState(e){this.log.info("Connection state: "+e),this._connectionState=e;try{this.emit("connectionStateChange",{state:e})}catch(e){this.log.error("Exception in connectionStateChange event: "+e)}}_fireIncomingCallEvent(e){try{this.emit("incomingCall",e)}catch(e){this.log.error("Exception in incomingCall event: "+e)}}_fireCallDataInfoEvent(e=null){let t;t=Zt(e),t.recordings=Zt(e.recordings),t.duration=1e3*t.duration,t.answerDuration=1e3*t.answerDuration,t.activeDuration=1e3*t.activeDuration,t.durationStr=y(t.duration),t.answerDurationStr=t.answerDuration?y(t.answerDuration):"",t.activeDurationStr=t.activeDuration?y(t.activeDuration):"";try{this.emit("callDataInfo",t)}catch(t){this.log.error("Exception in callDataInfo event: "+t)}}_checkMediaPermission(){if(!this._mediaPermission)throw new u}},e.Request=R,e.Requestor=I,e.Session=un,e.UnableToConnect=p,e.browserIsChrome=b,e.browserIsEdge=function(){return-1!==navigator.userAgent.indexOf("Edge")},e.browserIsFirefox=S,e.browserIsOpera=T,e.browserIsSafari=C,e.buildCustomHeaders=w,e.compareObjects=function(e,t){if(!e||!t)return!1;const n=Object.keys(t);return Object.keys(e).every(function(r){return-1!==n.indexOf(r)&&e[r]===t[r]})},e.createDurationString=y,e.createUUID=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|