/* Minification failed. Returning unminified contents.
(9,255994-255995): run-time error JS1002: Syntax error: .
(9,255996-255997): run-time error JS1010: Expected identifier: .
(9,255998-255999): run-time error JS1004: Expected ';': )
(9,255999-256000): run-time error JS1004: Expected ';': {
(9,256057-256058): run-time error JS1195: Expected expression: .
(9,256058-256059): run-time error JS1010: Expected identifier: .
(9,256059-256060): run-time error JS1010: Expected identifier: .
(9,256061-256062): run-time error JS1004: Expected ';': )
(9,256063-256064): run-time error JS1195: Expected expression: ,
(9,256088-256089): run-time error JS1004: Expected ';': {
(9,256356-256357): run-time error JS1195: Expected expression: >
(9,256390-256391): run-time error JS1195: Expected expression: )
(9,256408-256409): run-time error JS1195: Expected expression: ,
(9,256427-256428): run-time error JS1004: Expected ';': {
(9,256504-256505): run-time error JS1195: Expected expression: ,
(9,256521-256522): run-time error JS1195: Expected expression: )
(9,256522-256523): run-time error JS1004: Expected ';': {
(9,256624-256625): run-time error JS1195: Expected expression: ,
(9,256646-256647): run-time error JS1195: Expected expression: )
(9,256647-256648): run-time error JS1004: Expected ';': {
(9,257405-257406): run-time error JS1195: Expected expression: ,
(9,257425-257426): run-time error JS1195: Expected expression: )
(9,257426-257427): run-time error JS1004: Expected ';': {
(9,257463-257464): run-time error JS1195: Expected expression: )
(9,258268-258269): run-time error JS1010: Expected identifier: {
(9,258282-258283): run-time error JS1195: Expected expression: =
(9,258308-258309): run-time error JS1004: Expected ';': {
(9,258395-258396): run-time error JS1002: Syntax error: }
(9,258398-258402): run-time error JS1197: Too many errors. The file might not be a JavaScript file: call
(9,258313-258337): run-time error JS1018: 'return' statement outside of function: return JSON.stringify(e)
(9,258347-258393): run-time error JS1018: 'return' statement outside of function: return"[UnexpectedJSONParseError]: "+e.message
(9,257431-257450): run-time error JS1018: 'return' statement outside of function: return localStorage
(9,256891-257404): run-time error JS1018: 'return' statement outside of function: 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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)
(9,256882-256890): run-time error JS1018: 'return' statement outside of function: return!1
(9,256753-256761): run-time error JS1018: 'return' statement outside of function: return!0
(9,256615-256623): run-time error JS1018: 'return' statement outside of function: return e
(9,256246-256252): run-time error JS1018: 'return' statement outside of function: return
(9,256000-256061): run-time error JS1018: 'return' statement outside of function: return"object"==typeof console&&console.log&&console.log(...e
(9,50061-50069): run-time error JS5017: Syntax error in regular expression: /^[#-[]/
(9,49071-49079): run-time error JS5017: Syntax error in regular expression: /^[*-[]/
 */
/*
 * JsSIP v3.6.1
 * the Javascript SIP library
 * Copyright: 2012-2020 José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)
 * Homepage: https://jssip.net
 * License: MIT
 */

!function (e) { if ("object" == typeof exports && "undefined" != typeof module) module.exports = e(); else if ("function" == typeof define && define.amd) define([], e); else { ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).JsSIP = e() } }(function () { return function () { return function e(t, n, r) { function s(o, l) { if (!n[o]) { if (!t[o]) { var u = "function" == typeof require && require; if (!l && u) return u(o, !0); if (i) return i(o, !0); var a = new Error("Cannot find module '" + o + "'"); throw a.code = "MODULE_NOT_FOUND", a } var c = n[o] = { exports: {} }; t[o][0].call(c.exports, function (e) { return s(t[o][1][e] || e) }, c, c.exports, e, t, n, r) } return n[o].exports } for (var i = "function" == typeof require && require, o = 0; o < r.length; o++)s(r[o]); return s } }()({ 1: [function (e, t, n) { "use strict"; function r(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 s(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 s(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 o, l = !0, u = !1; return { s: function () { n = e[Symbol.iterator]() }, n: function () { var e = n.next(); return l = e.done, e }, e: function (e) { u = !0, o = e }, f: function () { try { l || null == n.return || n.return() } finally { if (u) throw o } } } } function s(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 } var i = e("./Utils"), o = e("./Constants"), l = e("./Grammar"), u = e("./URI"), a = e("./Socket"), c = e("./Exceptions"); n.settings = { authorization_user: null, password: null, realm: null, ha1: null, display_name: null, uri: null, contact_uri: null, instance_id: null, use_preloaded_route: !1, session_timers: !0, session_timers_refresh_method: o.UPDATE, session_timers_force_refresher: !1, no_answer_timeout: 60, register: !0, register_expires: 600, registrar_server: null, sockets: null, connection_recovery_max_interval: o.CONNECTION_RECOVERY_MAX_INTERVAL, connection_recovery_min_interval: o.CONNECTION_RECOVERY_MIN_INTERVAL, via_host: "".concat(i.createRandomToken(12), ".invalid") }; var h = { mandatory: { sockets: function (e) { var t = []; if (a.isSocket(e)) t.push({ socket: e }); else { if (!Array.isArray(e) || !e.length) return; var n, s = r(e); try { for (s.s(); !(n = s.n()).done;) { var i = n.value; Object.prototype.hasOwnProperty.call(i, "socket") && a.isSocket(i.socket) ? t.push(i) : a.isSocket(i) && t.push({ socket: i }) } } catch (e) { s.e(e) } finally { s.f() } } return t }, uri: function (e) { /^sip:/i.test(e) || (e = "".concat(o.SIP, ":").concat(e)); var t = u.parse(e); return t && t.user ? t : void 0 } }, optional: { authorization_user: function (e) { return -1 === l.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 (i.isDecimal(e)) { var t = Number(e); if (t > 0) return t } }, connection_recovery_min_interval: function (e) { if (i.isDecimal(e)) { var t = Number(e); if (t > 0) return t } }, contact_uri: function (e) { if ("string" == typeof e) { var t = l.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 === l.parse(e, "uuid") ? void 0 : e }, no_answer_timeout: function (e) { if (i.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()) === o.INVITE || e === o.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 (i.isDecimal(e)) { var t = Number(e); if (t > 0) return t } }, registrar_server: function (e) { /^sip:/i.test(e) || (e = "".concat(o.SIP, ":").concat(e)); var t = u.parse(e); return t ? t.user ? void 0 : t : void 0 }, use_preloaded_route: function (e) { if ("boolean" == typeof e) return e } } }; n.load = function (e, t) { for (var n in h.mandatory) { if (!t.hasOwnProperty(n)) throw new c.ConfigurationError(n); var r = t[n], s = h.mandatory[n](r); if (void 0 === s) throw new c.ConfigurationError(n, r); e[n] = s } for (var o in h.optional) if (t.hasOwnProperty(o)) { var l = t[o]; if (i.isEmpty(l)) continue; var u = h.optional[o](l); if (void 0 === u) throw new c.ConfigurationError(o, l); e[o] = u } } }, { "./Constants": 2, "./Exceptions": 6, "./Grammar": 7, "./Socket": 20, "./URI": 25, "./Utils": 26 }], 2: [function (e, t, n) { "use strict"; var r = e("../package.json"); t.exports = { USER_AGENT: "".concat(r.title, " ").concat(r.version), SIP: "sip", SIPS: "sips", causes: { CONNECTION_ERROR: "Error de conexión", REQUEST_TIMEOUT: "Tiempo de espera excedido", SIP_FAILURE_CODE: "SIP Failure Code", INTERNAL_ERROR: "Error interno", BUSY: "Ocupada", REJECTED: "Rechazado", REDIRECTED: "Redireccionando", UNAVAILABLE: "Todas nuestras líneas están ocupadas, intenta en unos minutos por favor.", NOT_FOUND: "No encontrado", ADDRESS_INCOMPLETE: "Address Incomplete", INCOMPATIBLE_SDP: "Incompatible SDP", MISSING_SDP: "Missing SDP", AUTHENTICATION_ERROR: "Authentication Error", BYE: "Gracias por tu contacto, hasta pronto.", WEBRTC_ERROR: "WebRTC Error", CANCELED: "Hasta pronto y gracias por tu contacto.", NO_ANSWER: "Sin respuesta", EXPIRES: "Expiró", NO_ACK: "No ACK", DIALOG_ERROR: "Dialog Error", USER_DENIED_MEDIA_ACCESS:"Habilita tu micrófono en el transcurso de la llamada.",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}},{"../package.json":38}],3:[function(e,t,n){"use strict";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 s(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var i=e("./SIPMessage"),o=e("./Constants"),l=e("./Transactions"),u=e("./Dialog/RequestSender"),a=e("./Utils"),c=e("debug")("JsSIP:Dialog"),h={STATUS_EARLY:1,STATUS_CONFIRMED:2};t.exports=function(){function e(t,n,r){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:h.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 i.IncomingResponse&&(s=n.status_code<200?h.STATUS_EARLY:h.STATUS_CONFIRMED);var o=n.parseHeader("contact");"UAS"===r?(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"===r&&(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),c("new ".concat(r," dialog created with status ").concat(this._state===h.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return h}}]),s(e,[{key:"update",value:function(e,t){this._state=h.STATUS_CONFIRMED,c("dialog ".concat(this._id.toString(),"  changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){c("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this)}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=a.cloneArray(n.extraHeaders),s=a.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new u(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===o.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===o.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===o.CANCEL||e===o.ACK?this._local_seqnum:this._local_seqnum+=1;return new i.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseq<this._remote_seqnum){if(e.method!==o.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===o.INVITE||e.method===o.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!==l.C.STATUS_ACCEPTED&&e.server_transaction.state!==l.C.STATUS_COMPLETED&&e.server_transaction.state!==l.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===l.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===o.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===l.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}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,debug:30}],4:[function(e,t,n){"use strict";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)}}var s=e("../Constants"),i=e("../Transactions"),o=e("../RTCSession"),l=e("../RequestSender"),u={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}};t.exports=function(){function e(t,n,r){for(var s in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=r,this._reattempt=!1,this._reattemptTimer=null,u)Object.prototype.hasOwnProperty.call(u,s)&&(this._eventHandlers[s]||(this._eventHandlers[s]=u[s]))}var t,n,a;return t=e,(n=[{key:"send",value:function(){var e=this,t=new l(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)}});if(t.send(),(this._request.method===s.INVITE||this._request.method===s.UPDATE&&this._request.body)&&t.clientTransaction.state!==i.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;t.clientTransaction.on("stateChanged",function n(){t.clientTransaction.state!==i.C.STATUS_ACCEPTED&&t.clientTransaction.state!==i.C.STATUS_COMPLETED&&t.clientTransaction.state!==i.C.STATUS_TERMINATED||(t.clientTransaction.removeListener("stateChanged",n),e._dialog.uac_pending_reply=!1)})}}},{key:"_receiveResponse",value:function(e){var t=this;408===e.status_code||481===e.status_code?this._eventHandlers.onDialogError(e):e.method===s.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(){t._dialog.owner.status!==o.C.STATUS_TERMINATED&&(t._reattempt=!0,t._request_sender.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}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(e,t,n){"use strict";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)}}var s=e("./Utils"),i=e("debug")("JsSIP:DigestAuthentication"),o=e("debug")("JsSIP:ERROR:DigestAuthentication");o.log=console.warn.bind(console),t.exports=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}var t,n,l;return t=e,(n=[{key:"get",value:function(e){switch(e){case"realm":return this._realm;case"ha1":return this._ha1;default:return void o('get() | cannot get "%s" parameter',e)}}},{key:"authenticate",value:function(e,t){var n=e.method,r=e.ruri,l=e.body,u=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 o('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o('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 o('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=n,this._uri=r,this._cnonce=u||s.createRandomToken(12),this._nc+=1;var a,c,h=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-h.length)+h,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=s.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),c=s.calculateMD5(a),i('authenticate() | using qop=auth [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(a="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(a),i('authenticate() | using qop=auth-int [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(a="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(a),i('authenticate() | using qop=null [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(c))),i("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(", "))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Utils":26,debug:30}],6:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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&&c(e,t)}function o(e){var t=a();return function(){var n,s=h(e);if(t){var i=h(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=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 u(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function u(e,t,n){return(u=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var s=new(Function.bind.apply(e,r));return n&&c(s,n.prototype),s}).apply(null,arguments)}function a(){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 c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=function(e){i(n,l(Error));var t=o(n);function n(e,r){var i;return s(this,n),(i=t.call(this)).code=1,i.name="CONFIGURATION_ERROR",i.parameter=e,i.value=r,i.message=i.value?"Invalid value ".concat(JSON.stringify(i.value),' for parameter "').concat(i.parameter,'"'):"Missing parameter: ".concat(i.parameter),i}return n}(),d=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=2,r.name="INVALID_STATE_ERROR",r.status=e,r.message="Invalid status: ".concat(e),r}return n}(),_=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=3,r.name="NOT_SUPPORTED_ERROR",r.message=e,r}return n}(),p=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=4,r.name="NOT_READY_ERROR",r.message=e,r}return n}();t.exports={ConfigurationError:f,InvalidStateError:d,NotSupportedError:_,NotReadyError:p}},{}],7:[function(e,t,n){"use strict";t.exports=function(){function t(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 n={parse:function(n,r){var s={CRLF:c,DIGIT:h,ALPHA:f,HEXDIG:d,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:S,escaped:E,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:k,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-f]")));return e},token:N,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&a('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&a('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&a('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:D,STAR:x,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:W,LDQUOT:V,RDQUOT:B,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=K())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=$())&&(r=e());null!==n&&null!==(r=L())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:J,qdtext:z,quoted_pair:$,SIP_URI_noparams:X,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:fe,h16:de,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:Se,ttl_param:Ee,maddr_param:Ae,lr_param:be,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:Ue,hname:De,hvalue:xe,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:We,uric_no_slash:Ve,path_segments:Be,segment:Ke,param:Ye,pchar:Je,scheme:ze,authority:$e,srvr:Xe,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:st,CANCELm:it,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:ut,REFERm:at,Method:ct,Status_Line:ht,Status_Code:ft,extension_code:dt,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=j())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&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,t,r,s,l,u;s=i,l=i,null!==(e=D())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=D())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l);null!==e&&(c=s,e=void(jn=n.substring(i,c)));var c;null===e&&(i=s);return e},Contact:function(){var e,t,n,r,s,o,l;if(s=i,null===(e=x()))if(o=i,null!==(e=pt())){for(t=[],l=i,null!==(n=j())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=j())&&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(e){var t,n;for(n=jn.multi_header.length,t=0;t<n;t++)if(null===jn.multi_header[t].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:vt,contact_params:gt,c_p_q:yt,c_p_expires:Tt,delta_seconds:Ct,qvalue:St,generic_param:Et,gen_value:At,Content_Disposition:function(){var e,t,n,r,s,o;if(s=i,null!==(e=bt())){for(t=[],o=i,null!==(n=G())&&null!==(r=Rt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=Rt())?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:bt,disp_param:Rt,handling_param:wt,Content_Encoding:function(){var e,t,n,r,s,o;if(s=i,null!==(e=N())){for(t=[],o=i,null!==(n=j())&&null!==(r=N())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=N())?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=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;null!==e&&(e=void(jn=parseInt(e.join(""))));null===e&&(i=n);return e},Content_Type:function(){var e,t;t=i,null!==(e=It())&&(r=t,e=void(jn=n.substring(i,r)));var r;null===e&&(i=t);return e},media_type:It,m_type:Ot,discrete_type:kt,composite_type:Nt,extension_token:Ut,x_token:Dt,m_subtype:xt,m_parameter:Pt,m_value:Mt,CSeq:function(){var e,t,n,r;r=i,null!==(e=qt())&&null!==(t=A())&&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=Ct())&&(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=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(u=e[0],e=void(jn.event=u.join("").toLowerCase()));var u;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=X())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=Ht())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&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(e){var t=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),t&&jn.setParam("tag",t)}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=h()))for(e=[];null!==t;)e.push(t),t=h();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=Ct())&&(e=void(jn=e));null===e&&(i=t);return e},Name_Addr_Header:function(){var e,t,n,r,s,o,l,u,a,c;u=i,a=i,e=[],t=vt();for(;null!==t;)e.push(t),t=vt();if(null!==e)if(null!==(t=F()))if(null!==(n=Q()))if(null!==(r=H())){for(s=[],c=i,null!==(o=G())&&null!==(l=Et())?o=[o,l]:(o=null,i=c);null!==o;)s.push(o),c=i,null!==(o=G())&&null!==(l=Et())?o=[o,l]:(o=null,i=c);null!==s?e=[e,t,n,r,s]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;else e=null,i=a;else e=null,i=a;null!==e&&(e=function(e){try{jn=new Fn(jn.uri,jn.display_name,jn.params)}catch(e){jn=-1}}());null===e&&(i=u);return e},Proxy_Authenticate:function(){return jt()},challenge:jt,other_challenge:Gt,auth_param:Wt,digest_cln:Vt,realm:Bt,realm_value:Kt,domain:Yt,URI:Jt,nonce:zt,nonce_value:$t,opaque:Xt,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=N())){for(t=[],o=i,null!==(n=j())&&null!==(r=N())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=N())?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=j())&&null!==(r=nn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=j())&&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(e){var t,n;for(n=jn.multi_header.length,t=0;t<n;t++)if(null===jn.multi_header[t].parsed){jn=null;break}jn=null!==jn?jn.multi_header:-1}());null===e&&(i=s);return e},rec_route:nn,Reason:function(){var e,t,r,s,l,u,c;l=i,u=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"'));null===e&&(e=N());if(null!==e){for(t=[],c=i,null!==(r=G())&&null!==(s=rn())?r=[r,s]:(r=null,i=c);null!==r;)t.push(r),c=i,null!==(r=G())&&null!==(s=rn())?r=[r,s]:(r=null,i=c);null!==t?e=[e,t]:(e=null,i=u)}else e=null,i=u;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=l);return e},reason_param:rn,reason_cause:sn,Require:function(){var e,t,n,r,s,o;if(s=i,null!==(e=N())){for(t=[],o=i,null!==(n=j())&&null!==(r=N())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=N())?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=j())&&null!==(r=on())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&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=G())&&null!==(r=un())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=un())?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:un,event_reason_value:an,Subject:function(){var e;return e=null!==(e=w())?e:""},Supported:function(){var e,t,n,r,s,o;if(s=i,null!==(e=N())){for(t=[],o=i,null!==(n=j())&&null!==(r=N())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=N())?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=X())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=cn())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&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(e){var t=jn.tag;try{jn=new Fn(jn.uri,jn.display_name,jn.params),t&&jn.setParam("tag",t)}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=j())&&null!==(r=hn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&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:fn,via_ttl:dn,via_maddr:_n,via_received:pn,via_branch:mn,response_port:vn,rport:gn,sent_protocol:yn,protocol_name:Tn,transport:Cn,sent_by:Sn,via_host:En,via_port:An,ttl:bn,WWW_Authenticate:function(){return jt()},Session_Expires:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Rn())){for(t=[],o=i,null!==(n=G())&&null!==(r=wn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=wn())?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:Rn,s_e_params:wn,s_e_refresher:In,extension_header:function(){var e,t,n,r;r=i,null!==(e=N())&&null!==(t=R())&&null!==(n=On())?e=[e,t,n]:(e=null,i=r);return e},header_value:On,message_body:function(){var e,t;e=[],t=p();for(;null!==t;)e.push(t),t=p();return e},uuid_URI:function(){var e,t,r;r=i,"uuid:"===n.substr(i,5)?(e="uuid:",i+=5):(e=null,0===o&&a('"uuid:"'));null!==e&&null!==(t=kn())?e=[e,t]:(e=null,i=r);return e},uuid:kn,hex4:Nn,hex8:Un,hex12:Dn,Refer_To:function(){var e,t,n,r,s,o,l;s=i,o=i,null===(e=X())&&(e=mt());if(null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=Et())?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(e){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=xn())){for(t=[],o=i,null!==(n=G())&&null!==(r=Pn())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&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:xn,replaces_param:Pn,to_tag:Mn,from_tag:qn,early_flag:Ln};if(void 0!==r){if(void 0===s[r])throw new Error("Invalid rule name: "+t(r)+".")}else r="CRLF";var i=0,o=0,l=0,u=[];function a(e){i<l||(i>l&&(l=i,u=[]),u.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&a('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z]")),e}function d(){var e;return/^[0-9a-fA-F]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9a-fA-F]")),e}function _(){var e;return null===(e=v())&&(e=g()),e}function p(){var e;return/^[\0-\xFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&a('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&a('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function C(){var e;return null===(e=y())&&(e=S()),e}function S(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&a('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&a('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&a('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&a('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&a('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&a('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&a('"%"')),null!==e&&null!==(t=d())&&null!==(r=d())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function A(){var e,t,n,r,s,o;for(r=i,s=i,o=i,e=[],t=_();null!==t;)e.push(t),t=_();if(null!==e&&null!==(t=c())?e=[e,t]:(e=null,i=o),null!==(e=null!==e?e:"")){if(null!==(n=_()))for(t=[];null!==n;)t.push(n),n=_();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 b(){var e;return e=null!==(e=A())?e:""}function R(){var e,t,r,s,l;for(s=i,l=i,e=[],null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=v())&&(t=g());return null!==e?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function w(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(t=I()))for(e=[];null!==t;)e.push(t),t=I();else e=null;if(null!==e){for(t=[],u=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u)}null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-~]")),null===e&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function N(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function U(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function D(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function x(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="/"),null===e&&(i=s),e}function M(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="="),null===e&&(i=s),e}function q(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="("),null===e&&(i=s),e}function L(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=")"),null===e&&(i=s),e}function H(){var e,t,r,s;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null!==e&&null!==(t=b())?e=[e,t]:(e=null,i=s),null!==e&&(e=">"),null===e&&(i=r),e}function F(){var e,t,r,s;return r=i,s=i,null!==(e=b())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(e="<"),null===e&&(i=r),e}function j(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function G(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function W(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=b())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function B(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=b())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function K(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function Y(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=z())&&(s=$());null!==s;)r.push(s),null===(s=z())&&(s=$());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=n.substring(i,u)),null===e&&(i=o),e}function J(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=z())&&(s=$());null!==s;)r.push(s),null===(s=z())&&(s=$());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=(a=n.substring(i,u).trim()).substring(1,a.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function z(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,u;return l=i,u=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=u)):(e=null,i=u),null!==e&&(e=function(e){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=l),e}function Q(){var e,t,s,l,u,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(u=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,u,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){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"===r&&(jn=jn.uri)}catch(e){jn=-1}}()),null===e&&(i=h),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,t,r;return t=i,"sips"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"sips"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function te(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=re())?(u=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&a('"@"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.user=decodeURIComponent(n.substring(i-1,c)))),null===e&&(i=s),e}function re(){var e,t;if(null===(t=C())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));return null!==e&&(s=r,e=void(jn.password=n.substring(i,s))),null===e&&(i=r),e}function oe(){var e,t,r,s,l;return s=i,null!==(e=le())?(l=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ve())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function le(){var e,t,r;return t=i,null===(e=ue())&&null===(e=pe())&&(e=he()),null!==e&&(r=t,jn.host=n.substring(i,r).toLowerCase(),e=jn.host),null===e&&(i=t),e}function ue(){var e,t,r,s,l,u,c;for(s=i,l=i,e=[],u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);null!==t;)e.push(t),u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==(r=null!==r?r:"")?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,jn.host_type="domain",e=n.substring(i,c)),null===e&&(i=s),e}function ae(){var e,t,r,s;if(s=i,null!==(e=y())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ce(){var e,t,r,s;if(s=i,null!==(e=f())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,u;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&a('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=s,jn.host_type="IPv6",e=n.substring(i,u)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,u,c,h,f,d,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&a('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,u,c,h,f,d,_,p,m]:(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,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,f,d,_,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),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,f,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,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=_e())?e=[e,t,r,s,l,u]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=_e())?e=[e,t,r,s]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=_e())?e=[e,t]:(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=de())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,f,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?("::"===n.substr(i,2)?(r="::",i+=2):(r=null,0===o&&a('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,f,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?("::"===n.substr(i,2)?(s="::",i+=2):(s=null,0===o&&a('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?("::"===n.substr(i,2)?(l="::",i+=2):(l=null,0===o&&a('"::"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(u="::",i+=2):(u=null,0===o&&a('"::"')),null!==u&&null!==(c=_e())?e=[e,t,r,s,l,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&a('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,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)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?c=[c,h]:(c=null,i=y),null!==(c=null!==c?c:"")?("::"===n.substr(i,2)?(h="::",i+=2):(h=null,0===o&&a('"::"')),null!==h?e=[e,t,r,s,l,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)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(T=v,jn.host_type="IPv6",e=n.substring(i,T)),null===e&&(i=v),e}function de(){var e,t,n,r,s;return s=i,null!==(e=d())&&null!==(t=null!==(t=d())?t:"")&&null!==(n=null!==(n=d())?n:"")&&null!==(r=null!==(r=d())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(e=pe()),e}function pe(){var e,t,r,s,l,u,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(u=".",i++):(u=null,0===o&&a('"."')),null!==u&&null!==(c=me())?e=[e,t,r,s,l,u,c]:(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f),null!==e&&(d=h,jn.host_type="IPv4",e=n.substring(i,d)),null===e&&(i=h),e}function me(){var e,t,r,s;return s=i,"25"===n.substr(i,2)?(e="25",i+=2):(e=null,0===o&&a('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-5]")),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,50===n.charCodeAt(i)?(e="2",i++):(e=null,0===o&&a('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-4]")),null!==t&&null!==(r=h())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,49===n.charCodeAt(i)?(e="1",i++):(e=null,0===o&&a('"1"')),null!==e&&null!==(t=h())&&null!==(r=h())?e=[e,t,r]:(e=null,i=s),null===e&&(s=i,/^[1-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[1-9]")),null!==e&&null!==(t=h())?e=[e,t]:(e=null,i=s),null===e&&(e=h())))),e}function ve(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,u=parseInt(u.join("")),jn.port=u,e=u),null===e&&(i=o),e}function ge(){var e,t,r,s;for(e=[],s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);null!==t;)e.push(t),s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Ce())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&null===(e=be())&&(e=Re()),e}function Te(){var e,t,r,s,l;return r=i,s=i,"transport="===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&a('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tls"')),null===t&&(t=N())))),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.transport=l.toLowerCase())),null===e&&(i=r),e}function Ce(){var e,t,r,s,l;return r=i,s=i,"user="===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&a('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&a('"ip"')),null===t&&(t=N())),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.user=l.toLowerCase())),null===e&&(i=r),e}function Se(){var e,t,r,s,l;return r=i,s=i,"method="===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"method="')),null!==e&&null!==(t=ct())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.method=l)),null===e&&(i=r),e}function Ee(){var e,t,r,s,l;return r=i,s=i,"ttl="===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"ttl="')),null!==e&&null!==(t=bn())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.params||(jn.params={}),e=void(jn.params.ttl=l)),null===e&&(i=r),e}function Ae(){var e,t,r,s,l;return r=i,s=i,"maddr="===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"maddr="')),null!==e&&null!==(t=le())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.maddr=l)),null===e&&(i=r),e}function be(){var e,t,r,s,l,u;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"lr"')),null!==e?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.lr=void 0)),null===e&&(i=s),e}function Re(){var e,t,r,s,l,u,c,h;return s=i,l=i,null!==(e=we())?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=e[0],h=e[1],jn.uri_params||(jn.uri_params={}),h=void 0===h?void 0:h[1],e=void(jn.uri_params[c.toLowerCase()]=h)),null===e&&(i=s),e}function we(){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=ke())&&null===(e=C())&&(e=E()),e}function ke(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function Ne(){var e,t,r,s,l,u,c;if(u=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return e}function Ue(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=De())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=xe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[0],c=e[2],u=u.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[u]?jn.uri_headers[u].push(c):jn.uri_headers[u]=[c])),null===e&&(i=s),e}function De(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=E());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=E());return e}function Pe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function Me(){var e,t,n,r,s,o;return o=i,null!==(e=ct())&&null!==(t=v())&&null!==(n=qe())&&null!==(r=v())&&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,t,r,s;return s=i,null!==(e=ze())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t?(null===(r=He())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function He(){var e,t,r,s,l;return s=i,null===(e=Fe())&&(e=je()),null!==e?(l=i,63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null!==t&&null!==(r=Ze())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function Fe(){var e,t,r,s;return s=i,"//"===n.substr(i,2)?(e="//",i+=2):(e=null,0===o&&a('"//"')),null!==e&&null!==(t=$e())&&null!==(r=null!==(r=je())?r:"")?e=[e,t,r]:(e=null,i=s),e}function je(){var e,t,r;return r=i,47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null!==e&&null!==(t=Be())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=We();null!==n;)t.push(n),n=We();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function We(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function Ve(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function Be(){var e,t,r,s,l,u;if(l=i,null!==(e=Ke())){for(t=[],u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,u;for(l=i,e=[],t=Je();null!==t;)e.push(t),t=Je();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=Je();null!==t;)e.push(t),t=Je();return e}function Je(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))),e}function ze(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=f())){for(t=[],null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(u=s,e=void(jn.scheme=n.substring(i,u))),null===e&&(i=s),e}function $e(){var e;return null===(e=Xe())&&(e=Qe()),e}function Xe(){var e,t,r,s;return r=i,s=i,null!==(e=ne())?(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==(e=null!==e?e:"")&&null!==(t=oe())?e=[e,t]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,t;if(null===(t=C())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=We();null!==t;)e.push(t),t=We();return e}function et(){var e,t,r,s,l,u,c,f,d;if(c=i,f=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;if(null!==r)if(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s){if(null!==(u=h()))for(l=[];null!==u;)l.push(u),u=h();else l=null;null!==l?e=[e,t,r,s,l]:(e=null,i=f)}else e=null,i=f;else e=null,i=f}else e=null,i=f;else e=null,i=f;return null!==e&&(d=c,e=void(jn.sip_version=n.substring(i,d))),null===e&&(i=c),e}function tt(){var e;return"INVITE"===n.substr(i,6)?(e="INVITE",i+=6):(e=null,0===o&&a('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&a('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&a('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&a('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&a('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&a('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&a('"SUBSCRIBE"')),e}function ut(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&a('"NOTIFY"')),e}function at(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&a('"REFER"')),e}function ct(){var e,t,r;return t=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=st())&&null===(e=it())&&null===(e=ot())&&null===(e=lt())&&null===(e=ut())&&null===(e=at())&&(e=N()),null!==e&&(r=t,jn.method=n.substring(i,r),e=jn.method),null===e&&(i=t),e}function ht(){var e,t,n,r,s,o;return o=i,null!==(e=et())&&null!==(t=v())&&null!==(n=ft())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function ft(){var e,t,n;return t=i,null!==(e=dt())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function dt(){var e,t,n,r;return r=i,null!==(e=h())&&null!==(t=h())&&null!==(n=h())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,t,r,s;for(r=i,e=[],null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());return null!==e&&(s=r,e=void(jn.reason_phrase=n.substring(i,s))),null===e&&(i=r),e}function pt(){var e,t,n,r,s,o,l;if(s=i,o=i,null===(e=X())&&(e=mt()),null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=gt())?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=vt())?e:"")&&null!==(t=F())&&null!==(n=Q())&&null!==(r=H())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,u;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=A())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=N())?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=J()),null!==e&&(u=e,e=void(jn.display_name="string"==typeof u?u:u[1].reduce(function(e,t){return e+t[0]+t[1]},u[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,u;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&a('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.q=u)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,u;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=u)),null===e&&(i=s),e}function Ct(){var e,t,n;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function St(){var e,t,r,s,l,u,c,f,d;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")&&null!==(l=null!==(l=h())?l:"")?t=[t,r,s,l]:(t=null,i=f),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(d=u,e=parseFloat(n.substring(i,d))),null===e&&(i=u),e}function Et(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=At())?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],u=e[1],jn.params||(jn.params={}),u=void 0===u?void 0:u[1],e=void(jn.params[l.toLowerCase()]=u)),null===e&&(i=r),e}function At(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"alert"')),null===e&&(e=N())))),e}function Rt(){var e;return null===(e=wt())&&(e=Et()),e}function wt(){var e,t,r,s;return s=i,"handling"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"required"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function It(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=Ot()))if(null!==(t=P()))if(null!==(n=xt())){for(r=[],u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);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=kt())&&(e=Nt()),e}function kt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"application"')),null===e&&(e=Ut()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=N())&&(e=Dt()),e}function Dt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Ut())&&(e=N()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=N())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=N())&&(e=Y()),e}function qt(){var e,t,n,r;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(r=e,e=void(jn.value=parseInt(r.join("")))),null===e&&(i=n),e}function Lt(){var e,t,r,s,l,u;if(l=i,null!==(e=U())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ht(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,u;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.tag=u)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,u,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==s?e=[e,t,r,s]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=N()))if(null!==(t=A()))if(null!==(n=Wt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);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 Wt(){var e,t,n,r;return r=i,null!==(e=N())&&null!==(t=M())?(null===(n=N())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Bt())&&null===(e=Yt())&&null===(e=zt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Wt()),e}function Bt(){var e,t,r,s;return s=i,"realm"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Kt())?e=[e,t,r]:(e=null,i=s),e}function Kt(){var e,t,n;return t=i,null!==(e=J())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,u,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=Jt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=Jt())?u=[u,c]:(u=null,i=f);null!==u;){if(l.push(u),f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=Jt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=B())?e=[e,t,r,s,l,u]:(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 e}function Jt(){var e;return null===(e=Le())&&(e=je()),e}function zt(){var e,t,r,s;return s=i,"nonce"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"nonce"')),null!==e&&null!==(t=M())&&null!==(r=$t())?e=[e,t,r]:(e=null,i=s),e}function $t(){var e,t,n;return t=i,null!==(e=J())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,u;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=J())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.opaque=u)),null===e&&(i=s),e}function Qt(){var e,t,r,s,l;return s=i,"stale"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"stale"')),null!==e&&null!==(t=M())?(l=i,"true"===n.substr(i,4).toLowerCase()?(r=n.substr(i,4),i+=4):(r=null,0===o&&a('"true"')),null!==r&&(r=void(jn.stale=!0)),null===r&&(i=l),null===r&&(l=i,"false"===n.substr(i,5).toLowerCase()?(r=n.substr(i,5),i+=5):(r=null,0===o&&a('"false"')),null!==r&&(r=void(jn.stale=!1)),null===r&&(i=l)),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function Zt(){var e,t,r,s,l,u;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.algorithm=u.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,u,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=V())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=d);null!==u;)l.push(u),d=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=B())?e=[e,t,r,s,l]:(e=null,i=h)}else e=null,i=h;else e=null,i=h;else e=null,i=h;return e}function tn(){var e,t,r;return t=i,"auth-int"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"auth"')),null===e&&(e=N())),null!==e&&(r=e,jn.qop||(jn.qop=[]),e=void jn.qop.push(r.toLowerCase())),null===e&&(i=t),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=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=Et())?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=Et()),e}function sn(){var e,t,r,s,l,u,c;if(l=i,u=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"cause"')),null!==e)if(null!==(t=M())){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=Et())?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,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function un(){var e,t,r,s,l,u,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"reason"')),null!==e&&null!==(t=M())&&null!==(r=an())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(u=e[2])&&(jn.reason=u))),null===e&&(i=s),null===e&&(s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(h=e[2])&&(jn.expires=h))),null===e&&(i=s),null===e&&(s=i,l=i,"retry_after"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(c=e[2])&&(jn.retry_after=c))),null===e&&(i=s),null===e&&(e=Et()))),e}function an(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"invariant"')),null===e&&(e=N()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=Sn())){for(r=[],u=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=u);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 fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Et()),e}function dn(){var e,t,r,s,l,u;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.ttl=u)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,u;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.maddr=u)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,u;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"received"')),null!==e&&null!==(t=M())?(null===(r=pe())&&(r=fe()),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.received=u)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,u;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.branch=u)),null===e&&(i=s),e}function vn(){var e,t,r,s,l;return s=i,"rport"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"rport"')),null!==e?(l=i,null!==(t=M())&&null!==(r=gn())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function gn(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.rport=parseInt(u.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=P())&&null!==(n=N())&&null!==(r=P())&&null!==(s=Cn())?e=[e,t,n,r,s]:(e=null,i=o),e}function Tn(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null===e&&(e=N()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Cn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"SCTP"')),null===e&&(e=N())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Sn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=W())&&null!==(n=An())?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 En(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ue()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function An(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.port=parseInt(u.join("")))),null===e&&(i=o),e}function bn(){var e,t,n,r,s;return r=i,s=i,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")?e=[e,t,n]:(e=null,i=s),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function Rn(){var e,t,n;return t=i,null!==(e=Ct())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function wn(){var e;return null===(e=In())&&(e=Et()),e}function In(){var e,t,r,s,l,u;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.refresher=u.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=A());return e}function kn(){var e,t,r,s,l,u,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=Dn())?e=[e,t,r,s,l,u,c,h,f]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=d,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=d),e}function Nn(){var e,t,n,r,s;return s=i,null!==(e=d())&&null!==(t=d())&&null!==(n=d())&&null!==(r=d())?e=[e,t,n,r]:(e=null,i=s),e}function Un(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Dn(){var e,t,n,r;return r=i,null!==(e=Nn())&&null!==(t=Nn())&&null!==(n=Nn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=D())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=D())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.call_id=n.substring(i,c))),null===e&&(i=s),e}function Pn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,u;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&a('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.to_tag=u)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,u;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&a('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.from_tag=u)),null===e&&(i=s),e}function Ln(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&a('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Hn=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Wn=Gn<n.length?n.charAt(Gn):null,Vn=function(){for(var e=1,t=1,r=!1,s=0;s<Math.max(i,l);s++){var o=n.charAt(s);"\n"===o?(r||e++,t=1,r=!1):"\r"===o||"\u2028"===o||"\u2029"===o?(e++,t=1,r=!0):(t++,r=!1)}return{line:e,column:t}}();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}(u),Wn,Gn,Vn.line,Vn.column),-1}return jn},toSource:function(){return this._source},SyntaxError:function(e,n,r,s,i){this.name="SyntaxError",this.expected=e,this.found=n,this.message=function(e,n){var r;switch(e.length){case 0:r="end of input";break;case 1:r=e[0];break;default:r=e.slice(0,e.length-1).join(", ")+" or "+e[e.length-1]}return"Expected "+r+" but "+(n?t(n):"end of input")+" found."}(e,n),this.offset=r,this.line=s,this.column=i}};return n.SyntaxError.prototype=Error.prototype,n}()},{"./NameAddrHeader":10,"./URI":25}],8:[function(e,t,n){"use strict";var r=e("../package.json"),s=e("./Constants"),i=e("./Exceptions"),o=e("./Utils"),l=e("./UA"),u=e("./URI"),a=e("./NameAddrHeader"),c=e("./Grammar"),h=e("./WebSocketInterface");e("debug")("JsSIP")("version %s",r.version),t.exports={C:s,Exceptions:i,Utils:o,UA:l,URI:u,NameAddrHeader:a,WebSocketInterface:h,Grammar:c,debug:e("debug"),get name(){return r.title},get version(){return r.version}}},{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,debug:30}],9:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){var t=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 n,s=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var u=e("events").EventEmitter,a=e("./Constants"),c=e("./SIPMessage"),h=e("./Utils"),f=e("./RequestSender"),d=e("./Exceptions"),_=e("debug")("JsSIP:Message");t.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&&i(e,t)}(p,u);var t,n,r,l=o(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 t=p,(n=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=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(s));var i=h.cloneArray(r.extraHeaders),o=h.cloneObject(r.eventHandlers),l=r.contentType||"text/plain";for(var u in o)Object.prototype.hasOwnProperty.call(o,u)&&this.on(u,o[u]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(a.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var d=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),d.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=h.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=h.cloneArray(e.extraHeaders),s=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,s)}},{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=h.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){_("MESSAGE failed"),this._close(),_('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){_("MESSAGE succeeded"),this._close(),_('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.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,debug:30,events:29}],10:[function(e,t,n){"use strict";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 s(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}var i=e("./URI"),o=e("./Grammar");t.exports=function(){function e(t,n,r){if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!(t&&t instanceof i))throw new TypeError('missing or invalid "uri" parameter');for(var s in this._uri=t,this._parameters={},this.display_name=n,r)Object.prototype.hasOwnProperty.call(r,s)&&this.setParam(s,r[s])}return s(e,null,[{key:"parse",value:function(e){return-1!==(e=o.parse(e,"Name_Addr_Header"))?e:void 0}}]),s(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}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(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 s(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 s(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 o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(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}var i=e("./Grammar"),o=e("./SIPMessage"),l=e("debug")("JsSIP:ERROR:Parser");function u(e,t){var n=t,r=0,s=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===r;){if(-1===(s=e.indexOf("\r\n",n)))return s;!e.substring(s+2,s+4).match(/(^\r\n)/)&&e.charAt(s+2).match(/(^\s+)/)?n=s+2:r=s}return r}function a(e,t,n,s){var l,u=t.indexOf(":",n),a=t.substring(n,u).trim(),c=t.substring(u+1,s).trim();switch(a.toLowerCase()){case"via":case"v":e.addHeader("via",c),1===e.getHeaders("via").length?(l=e.parseHeader("Via"))&&(e.via=l,e.via_branch=l.branch):l=0;break;case"from":case"f":e.setHeader("from",c),(l=e.parseHeader("from"))&&(e.from=l,e.from_tag=l.getParam("tag"));break;case"to":case"t":e.setHeader("to",c),(l=e.parseHeader("to"))&&(e.to=l,e.to_tag=l.getParam("tag"));break;case"record-route":if(-1===(l=i.parse(c,"Record_Route")))l=void 0;else{var h,f=r(l);try{for(f.s();!(h=f.n()).done;){var d=h.value;e.addHeader("record-route",c.substring(d.possition,d.offset)),e.headers["Record-Route"][e.getHeaders("record-route").length-1].parsed=d.parsed}}catch(e){f.e(e)}finally{f.f()}}break;case"call-id":case"i":e.setHeader("call-id",c),(l=e.parseHeader("call-id"))&&(e.call_id=c);break;case"contact":case"m":if(-1===(l=i.parse(c,"Contact")))l=void 0;else{var _,p=r(l);try{for(p.s();!(_=p.n()).done;){var m=_.value;e.addHeader("contact",c.substring(m.possition,m.offset)),e.headers.Contact[e.getHeaders("contact").length-1].parsed=m.parsed}}catch(e){p.e(e)}finally{p.f()}}break;case"content-length":case"l":e.setHeader("content-length",c),l=e.parseHeader("content-length");break;case"content-type":case"c":e.setHeader("content-type",c),l=e.parseHeader("content-type");break;case"cseq":e.setHeader("cseq",c),(l=e.parseHeader("cseq"))&&(e.cseq=l.value),e instanceof o.IncomingResponse&&(e.method=l.method);break;case"max-forwards":e.setHeader("max-forwards",c),l=e.parseHeader("max-forwards");break;case"www-authenticate":e.setHeader("www-authenticate",c),l=e.parseHeader("www-authenticate");break;case"proxy-authenticate":e.setHeader("proxy-authenticate",c),l=e.parseHeader("proxy-authenticate");break;case"session-expires":case"x":e.setHeader("session-expires",c),(l=e.parseHeader("session-expires"))&&(e.session_expires=l.expires,e.session_expires_refresher=l.refresher);break;case"refer-to":case"r":e.setHeader("refer-to",c),(l=e.parseHeader("refer-to"))&&(e.refer_to=l);break;case"replaces":e.setHeader("replaces",c),(l=e.parseHeader("replaces"))&&(e.replaces=l);break;case"event":case"o":e.setHeader("event",c),(l=e.parseHeader("event"))&&(e.event=l);break;default:e.addHeader(a,c),l=0}return void 0!==l||{error:'error parsing header "'.concat(a,'"')}}l.log=console.warn.bind(console),n.parseMessage=function(e,t){var n,r,s=e.indexOf("\r\n");if(-1!==s){var c=e.substring(0,s),h=i.parse(c,"Request_Response");if(-1!==h){h.status_code?((n=new o.IncomingResponse).status_code=h.status_code,n.reason_phrase=h.reason_phrase):((n=new o.IncomingRequest(t)).method=h.method,n.ruri=h.uri),n.data=e;for(var f=s+2;;){if(-2===(s=u(e,f))){r=f+2;break}if(-1===s)return void l("parseMessage() | malformed message");if(!0!==(h=a(n,e,f,s)))return void l("parseMessage() |",h.error);f=s+2}if(n.hasHeader("content-length")){var d=n.getHeader("content-length");n.body=e.substr(r,d)}else n.body=e.substring(r);return n}l('parseMessage() | error parsing first line of SIP message: "'.concat(c,'"'))}else l("parseMessage() | no CRLF found, not a SIP message")}},{"./Grammar":7,"./SIPMessage":19,debug:30}],12:[function(e,t,n){"use strict";function r(e){return(r="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)}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 i(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 i(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},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,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(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 o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(e){var t=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 n,s=c(e);if(t){var i=c(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var h=e("events").EventEmitter,f=e("sdp-transform"),d=e("./Constants"),_=e("./Exceptions"),p=e("./Transactions"),m=e("./Utils"),v=e("./Timers"),g=e("./SIPMessage"),y=e("./Dialog"),T=e("./RequestSender"),C=e("./RTCSession/DTMF"),S=e("./RTCSession/Info"),E=e("./RTCSession/ReferNotifier"),A=e("./RTCSession/ReferSubscriber"),b=e("./URI"),R=e("debug")("JsSIP:RTCSession"),w=e("debug")("JsSIP:ERROR:RTCSession");w.log=console.warn.bind(console);var I={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},O=["audio","video"];t.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&&u(e,t)}(n,h);var t=a(n);function n(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),R("new"),(r=t.call(this))._id=null,r._ua=e,r._status=I.STATUS_NULL,r._dialog=null,r._earlyDialogs={},r._contact=null,r._from_tag=null,r._to_tag=null,r._connection=null,r._connectionPromiseQueue=Promise.resolve(),r._request=null,r._is_canceled=!1,r._cancel_reason="",r._is_confirmed=!1,r._late_sdp=!1,r._rtcOfferConstraints=null,r._rtcAnswerConstraints=null,r._localMediaStream=null,r._localMediaStreamLocallyGenerated=!1,r._rtcReady=!0,r._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},r._direction=null,r._local_identity=null,r._remote_identity=null,r._start_time=null,r._end_time=null,r._tones=null,r._audioMuted=!1,r._videoMuted=!1,r._localHold=!1,r._remoteHold=!1,r._sessionTimers={enabled:r._ua.configuration.session_timers,refreshMethod:r._ua.configuration.session_timers_refresh_method,defaultExpires:d.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},r._referSubscribers={},r._data={},r}return l(n,null,[{key:"C",get:function(){return I}}]),l(n,[{key:"isInProgress",value:function(){switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:case I.STATUS_INVITE_RECEIVED:case I.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case I.STATUS_ANSWERED:case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case I.STATUS_CANCELED:case I.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;R("connect()");var r=e,s=m.cloneObject(t.eventHandlers),i=m.cloneArray(t.extraHeaders),o=m.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=m.cloneObject(t.pcConfig,{iceServers:[]}),a=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!==I.STATUS_NULL)throw new _.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new _.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&m.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=m.newTag();var f=t.anonymous||!1,p={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:f,outbound:!0}),f&&(p.from_display_name="Anonymous",p.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")),i.push("Contact: ".concat(this._contact)),i.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&i.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,p,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(u,a),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;R("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;if(e.body&&"application/sdp"!==s)e.reply(415);else if(this._status=I.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=m.newTag(),this._createDialog(e,"UAS",!0)){if(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=I.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===I.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!==I.STATUS_TERMINATED){var i=["Contact: ".concat(this._contact)],o=this._ua.modes.ringing_header_mode;void 0!==o&&(Array.isArray(o)?i=i.concat(o):i.push(o)),e.reply(180,null,i),this._progress("local",null)}}else e.reply(500,"Missing Contact header field")}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("answer()");var n=this._request,r=m.cloneArray(t.extraHeaders),i=m.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=m.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=m.cloneObject(t.rtcOfferConstraints),h=!1,f=!1,p=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new _.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new _.InvalidStateError(this._status);if(this._sessionTimers.enabled&&m.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),this._status=I.STATUS_ANSWERED,this._createDialog(n,"UAS")){clearTimeout(this._timers.userNoAnswerTimer),r.unshift("Contact: ".concat(this._contact));var g=n.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);var y,T=s(g.media);try{for(T.s();!(y=T.n()).done;){var C=y.value;"audio"===C.type&&(h=!0,C.direction&&"sendrecv"!==C.direction||(p=!0)),"video"===C.type&&(f=!0,C.direction&&"sendrecv"!==C.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var S,E=s(o.getAudioTracks());try{for(E.s();!(S=E.n()).done;){var A=S.value;o.removeTrack(A)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var b,O=s(o.getVideoTracks());try{for(O.s();!(b=O.n()).done;){var k=b.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=p),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||f||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,u),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),w('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===I.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:n.body};R('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,d.causes.WEBRTC_ERROR),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",a).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=I.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,d.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w(t)})}else n.reply(500,"Error creating dialog")}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("terminate()");var n,r=t.cause||d.causes.BYE,s=m.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new _.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(R("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===I.STATUS_NULL||this._status===I.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===I.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=I.STATUS_CANCELED,this._failed("local",null,d.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(R("rejecting session"),(o=o||480)<300||o>=700)throw new TypeError("Invalid status_code: ".concat(o));this._request.reply(o,l,s,i),this._failed("local",null,d.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(R("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&&s.push("Reason: SIP ;cause=".concat(o,'; text="').concat(l,'"')),this._status===I.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==p.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===d.ACK&&(e.sendRequest(d.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===p.C.STATUS_TERMINATED&&(e.sendRequest(d.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(d.BYE,{extraHeaders:s,body:i}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||d.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new _.InvalidStateError(this._status);if(i!==d.DTMF_TRANSPORT.INFO&&i!==d.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(i));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&&!m.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?r<C.C.MIN_DURATION?(R('"duration" value is lower than the minimum allowed, setting it to '.concat(C.C.MIN_DURATION," milliseconds")),r=C.C.MIN_DURATION):r>C.C.MAX_DURATION?(R('"duration" value is greater than the maximum allowed, setting it to '.concat(C.C.MAX_DURATION," milliseconds")),r=C.C.MAX_DURATION):r=Math.abs(r):r=C.C.DEFAULT_DURATION,t.duration=r,s&&!m.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s<C.C.MIN_INTER_TONE_GAP?(R('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(C.C.MIN_INTER_TONE_GAP," milliseconds")),s=C.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=C.C.DEFAULT_INTER_TONE_GAP,i!==d.DTMF_TRANSPORT.RFC2833)this._tones?this._tones+=e:(this._tones=e,function e(){var i=this;var o;if(this._status===I.STATUS_TERMINATED||!this._tones||n>=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new C(this);t.eventHandlers={onFailed:function(){i._tones=null}},u.send(l,t),o=r+s}setTimeout(e.bind(this),o)}.call(this));else{var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,s))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(R("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new _.InvalidStateError(this._status);new S(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};R("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};R("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(R("hold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.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(R("unhold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.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;R("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={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:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(e,t){var n=this;R("refer()");var r=e;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new A(this);s.sendRefer(e,t);var i=s.id;return this._referSubscribers[i]=s,s.on("requestFailed",function(){delete n._referSubscribers[i]}),s.on("accepted",function(){delete n._referSubscribers[i]}),s.on("failed",function(){delete n._referSubscribers[i]}),s}},{key:"sendRequest",value:function(e,t){return R("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(R("receiveRequest()"),e.method===d.CANCEL)this._status!==I.STATUS_WAITING_FOR_ANSWER&&this._status!==I.STATUS_ANSWERED||(this._status=I.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,d.causes.CANCELED));else switch(e.method){case d.ACK:if(this._status!==I.STATUS_WAITING_FOR_ACK)return;if(this._status=I.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};R('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}),w('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===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,d.causes.BYE)):this._status===I.STATUS_INVITE_RECEIVED||this._status===I.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===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case d.INFO:if(this._status===I.STATUS_1XX_RECEIVED||this._status===I.STATUS_WAITING_FOR_ANSWER||this._status===I.STATUS_ANSWERED||this._status===I.STATUS_WAITING_FOR_ACK||this._status===I.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new C(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case d.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case d.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case d.NOTIFY:var i={event:e.event,request:e,taken:!1};if(this.emit("sipEvent",i),i.taken){e.reply(200);break}this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.CONNECTION_ERROR,cause:d.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:d.causes.REQUEST_TIMEOUT,cause:d.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.DIALOG_ERROR,cause:d.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){R("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){R("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||(R("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(R("_isReadyToReOffer() | session not established yet"),!1):(R("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(R("close()"),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R("close() | closing local MediaStream"),m.closeMediaStream(this._localMediaStream)),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=v.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),n<v.T2&&(n*=2)>v.T2&&(n=v.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===I.STATUS_WAITING_FOR_ACK&&(R("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(d.BYE),e._ended("remote",null,d.causes.NO_ACK))},v.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){var e=n._connection.iceConnectionState;if("failed"===e&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT}),void 0!==n._ua.modes.chrome_rtp_timeout_fix&&navigator.webkitGetUserMedia&&"disconnected"===e){var t=n._ua.modes.chrome_rtp_timeout_fix;R("AC: Chrome RTP timeout fix: iceConnectionState==disconnected: check that this will continue for "+t+" seconds...");!function e(){"disconnected"===n._connection.iceConnectionState?t-- >0?setTimeout(function(){return e()},1e3):(R("AC: Chrome RTP timeout fix: Hangup call"),n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})):R("AC: Chrome RTP timeout fix: iceConnectionState="+n._connection.iceConnectionState)}()}}),R('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(R("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 w('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w('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,w('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){if(!("complete"!==r.iceGatheringState||t&&t.iceRestart)){n._rtcReady=!0;var s={originator:"local",type:e,sdp:r.localDescription.sdp};return R('emit "sdp"'),n.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(function(t){var s,i,o=!1,l=function(){r.removeEventListener("icecandidate",s),r.removeEventListener("icegatheringstatechange",i),o=!0,n._rtcReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};R('emit "sdp"'),n.emit("sdp",l),t(l.sdp)};r.addEventListener("icecandidate",s=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):o||l()}),r.addEventListener("icegatheringstatechange",i=function(){"complete"!==r.iceGatheringState||o||l()}),void 0!==n._ua.modes.ice_timeout_fix&&setTimeout(function(){o||(R("AC: ICE gathering timeout fix"),l())},n._ua.modes.ice_timeout_fix)})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,s="UAS"===t?e.from_tag:e.to_tag,i=e.call_id+r+s,o=this._earlyDialogs[i];if(n)return!!o||((o=new y(this,e,t,y.C.STATUS_EARLY)).error?(R(o.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=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[i],!0;var l=new y(this,e,t);return l.error?(R(l.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;R("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]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=m.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("reinvite",r),!s){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){i.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return R("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w(e)})}function i(t){var n=this,s=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,s),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,s,t,function(){n._status=I.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;R("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]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=m.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return R("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w(e)})}else i.call(this,null);function i(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 t=this;R("_processInDialogSdpOffer()");var n,r=e.parseSDP(),i=!1,o=s(r.media);try{for(o.s();!(n=o.n()).done;){var l=n.value;if(-1!==O.indexOf(l.type)){var u=l.direction||r.direction||"sendrecv";if("sendonly"!==u&&"inactive"!==u){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var a={originator:"remote",type:"offer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",a);var c=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");!0===t._remoteHold&&!1===i?(t._remoteHold=!1,t._onunhold("remote")):!1===t._remoteHold&&!0===i&&(t._remoteHold=!0,t._onhold("remote"))}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),w('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(R("receiveRefer()"),!e.refer_to)return R("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==d.SIP)return R("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var r=new E(this,e.cseq);R('emit "refer"'),this.emit("refer",{request:e,accept:function(s,i){(function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var i=new n(this._ua);if(i.on("progress",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("accepted",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("_failed",function(e){var t=e.message,n=e.cause;t?r.notify(t.status_code,t.reason_phrase):r.notify(487,n)}),e.refer_to.uri.hasHeader("replaces")){var o=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));s.extraHeaders=m.cloneArray(s.extraHeaders),s.extraHeaders.push("Replaces: ".concat(o))}i.connect(e.refer_to.uri.toAor(),s,t)}).call(t,s,i)},reject:function(){(function(){r.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(R("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200);break;default:e.reply(489)}}},{key:"_receiveReplaces",value:function(e){var t=this;R("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(r){(function(t){var r=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var s=new n(this._ua);s.on("confirmed",function(){r.terminate()}),s.init_incoming(e,t)}).call(t,r)},reject:function(){(function(){R("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new T(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===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),w('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===I.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===I.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=I.STATUS_INVITE_SENT,R('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w(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;w("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(R("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 y(this,e,"UAC");return void 0!==n.error?void R(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===I.STATUS_INVITE_SENT||this._status===I.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=I.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){R("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=I.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",r);var s=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){return t._progress("remote",e)}).catch(function(e){w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.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 i={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",i);var o=new RTCSessionDescription({type:"answer",sdp:i.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),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=m.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]:{};R("sendReinvite()");var n=m.cloneArray(t.extraHeaders),r=m.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=!1;function o(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",s)}).then(function(t){var s={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R('emit "sdp"'),e.emit("sdp",s),e.sendRequest(d.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(d.ACK),i)return;if(this._handleSessionTimersInIncomingResponse(e),!e.body)return void o.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void o.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){o.call(t),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}).call(e,t),i=!0},onErrorResponse:function(t){o.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){o()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("sendUpdate()");var n=m.cloneArray(t.extraHeaders),r=m.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==I.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void u.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void u.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){u.call(t),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function u(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")),i?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",s)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R('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){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){u.call(e)})):this.sendRequest(d.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){R("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=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=f.parse(e),this._localHold&&!this._remoteHold){R("mangleOffer() | me on hold, mangling offer");var t,n=s(e.media);try{for(n.s();!(t=n.n()).done;){var r=t.value;-1!==O.indexOf(r.type)&&(r.direction?"sendrecv"===r.direction?r.direction="sendonly":"recvonly"===r.direction&&(r.direction="inactive"):r.direction="sendonly")}}catch(e){n.e(e)}finally{n.f()}}else if(this._localHold&&this._remoteHold){R("mangleOffer() | both on hold, mangling offer");var i,o=s(e.media);try{for(o.s();!(i=o.n()).done;){var l=i.value;-1!==O.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){R("mangleOffer() | remote on hold, mangling offer");var u,a=s(e.media);try{for(a.s();!(u=a.n()).done;){var c=u.value;-1!==O.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){a.e(e)}finally{a.f()}}return f.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!==I.STATUS_TERMINATED&&(R("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===d.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w("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 t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"audio"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_toggleMuteVideo",value:function(e){var t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"video"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_newRTCSession",value:function(e,t){R("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){R("session connecting"),R('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){R("session progress"),R('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){R("session accepted"),this._start_time=new Date,R('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){R("session confirmed"),this._is_confirmed=!0,R('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){R("session ended"),this._end_time=new Date,this._close(),R('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){R("session failed"),R('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),R('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){R("session onhold"),this._setLocalMediaStatus(),R('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){R("session onunhold"),this._setLocalMediaStatus(),R('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;R("session onmute"),this._setLocalMediaStatus(),R('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;R("session onunmute"),this._setLocalMediaStatus(),R('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{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}}]),n}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./URI":25,"./Utils":26,debug:30,events:29,"sdp-transform":35}],13:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){var t=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 n,s=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var u=e("events").EventEmitter,a=e("../Constants"),c=e("../Exceptions"),h=e("../Utils"),f=e("debug")("JsSIP:RTCSession:DTMF");e("debug")("JsSIP:ERROR:RTCSession:DTMF").log=console.warn.bind(console);var d={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};t.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&&i(e,t)}(_,u);var t,n,r,l=o(_);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))._session=e,t._direction=null,t._tone=null,t._duration=null,t._request=null,t}return t=_,(n=[{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 c.InvalidStateError(this._session.status);var r=h.cloneArray(n.extraHeaders);if(this.eventHandlers=h.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 s="Signal=".concat(this._tone,"\r\n");s+="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:s})}},{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}):f("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":26,debug:30,events:29}],14:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){var t=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 n,s=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var u=e("events").EventEmitter;e("debug")("JsSIP:ERROR:RTCSession:Info").log=console.warn.bind(console);var a=e("../Constants"),c=e("../Exceptions"),h=e("../Utils");t.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&&i(e,t)}(f,u);var t,n,r,l=o(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._contentType=null,t._body=null,t}return t=f,(n=[{key:"send",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",t&&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 c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);e&&s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(a.INFO,{extraHeaders:s,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.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":26,debug:30,events:29}],15:[function(e,t,n){"use strict";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)}}var s=e("../Constants"),i=e("debug")("JsSIP:RTCSession:ReferNotifier"),o={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};t.exports=function(){function e(t,n,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._session=t,this._id=n,this._expires=r||o.expires,this._active=!0,this.notify(100)}var t,n,l;return t=e,(n=[{key:"notify",value:function(e,t){if(i("notify()"),!1!==this._active){var n;t=t||s.REASON_PHRASE[e]||"",n=e>=200?"terminated;reason=noresource":"active;expires=".concat(this._expires);try{this._session.sendRequest(s.NOTIFY,{extraHeaders:["Event: ".concat(o.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(o.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}catch(e){i("send NOTIFY exception [ignored]")}}}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:30}],16:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){var t=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 n,s=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var u=e("events").EventEmitter,a=e("../Constants"),c=e("../Grammar"),h=e("../Utils"),f=e("debug")("JsSIP:RTCSession:ReferSubscriber");t.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&&i(e,t)}(d,u);var t,n,r,l=o(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 t=d,(n=[{key:"sendRefer",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};f("sendRefer()");var r=h.cloneArray(n.extraHeaders),s=h.cloneObject(n.eventHandlers);for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.on(i,s[i]);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):"",">");r.push(l);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 c=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=c.cseq}},{key:"receiveNotify",value:function(e){if(f("receiveNotify()"),e.body){var t=c.parse(e.body.trim(),"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 f('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f("REFER succeeded"),f('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f("REFER failed"),f('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}},{key:"id",get:function(){return this._id}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":26,debug:30,events:29}],17:[function(e,t,n){"use strict";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)}}var s=e("./Utils"),i=e("./Constants"),o=e("./SIPMessage"),l=e("./RequestSender"),u=e("debug")("JsSIP:Registrator");t.exports=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=s.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._contact+=";reg-id=".concat(1),this._contact+=';+sip.instance="<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"')}var t,n,a;return t=e,(n=[{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)u("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 n=new o.OutgoingRequest(i.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new l(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,i.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,i.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")){u("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]).find(function(t){return t.uri.user===e._ua.contact.uri.user});if(!n){u("no Contact header pointing to us, response ignored");break}var r=n.getParam("expires");!r&&t.hasHeader("expires")&&(r=t.getHeader("expires")),r||(r=e._expires),(r=Number(r))<10&&(r=10);var o=r>64?1e3*r/2+Math.floor(1e3*(r/2-32)*Math.random()):1e3*r-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},o),n.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=n.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()):(u("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var l=s.sipErrorCause(t.status_code);e._registrationFailure(t,l)}}});this._registering=!0,r.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 n=this._extraHeaders.slice();t.all?n.push("Contact: *".concat(this._extraContactParams)):n.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),n.push("Expires: 0");var r=new o.OutgoingRequest(i.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new l(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,i.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,i.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):e._unregistered(t);break;default:var n=s.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else u("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}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,debug:30}],18:[function(e,t,n){"use strict";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)}}var s=e("./Constants"),i=e("./DigestAuthentication"),o=e("./Transactions"),l=e("debug")("JsSIP:RequestSender"),u={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}};t.exports=function(){function e(t,n,r){for(var i in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._ua=t,this._eventHandlers=r,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1,u)Object.prototype.hasOwnProperty.call(u,i)&&(this._eventHandlers[i]||(this._eventHandlers[i]=u[i]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,a;return t=e,(n=[{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 o.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new o.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new o.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(e){var t,n,r=e.status_code;if(401!==r&&407!==r||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 l("".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 i({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)}}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,debug:30}],19:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(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&&i(e,t)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){var t=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 n,s=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(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 a(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 a(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},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 i,o=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){l=!0,i=e},f:function(){try{o||null==n.return||n.return()}finally{if(l)throw i}}}}function a(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 c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(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 f(e,t,n){return t&&h(e.prototype,t),n&&h(e,n),e}var d=e("sdp-transform"),_=e("./Constants"),p=e("./Utils"),m=e("./NameAddrHeader"),v=e("./Grammar"),g=e("debug")("JsSIP:SIPMessage"),y=function(){function e(t,n,r,s,i,o){if(c(this,e),!t||!n||!r)return null;s=s||{},this.ua=r,this.headers={},this.method=t,this.ruri=n,this.body=o,this.extraHeaders=p.cloneArray(i),s.route_set?this.setHeader("route",s.route_set):r.configuration.use_preloaded_route&&this.setHeader("route","<".concat(r.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,u=s.to_tag?{tag:s.to_tag}:null,a=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,a,u),this.setHeader("to",this.to.toString());var h,f=s.from_uri||r.configuration.uri,d={tag:s.from_tag||p.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new m(f,h,d),this.setHeader("from",this.from.toString());var v=s.call_id||r.configuration.jssip_id+p.createRandomToken(15);this.call_id=v,this.setHeader("call-id",v);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return f(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[p.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){var t=this.headers[p.headerize(e)];if(t){if(t[0])return t[0]}else{var n,r=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),s=u(this.extraHeaders);try{for(s.s();!(n=s.n()).done;){var i=n.value;if(r.test(i))return i.substring(i.indexOf(":")+1).trim()}}catch(e){s.e(e)}finally{s.f()}}}},{key:"getHeaders",value:function(e){var t=this.headers[p.headerize(e)],n=[];if(t){var r,s=u(t);try{for(s.s();!(r=s.n()).done;){var i=r.value;n.push(i)}}catch(e){s.e(e)}finally{s.f()}return n}var o,l=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),a=u(this.extraHeaders);try{for(a.s();!(o=a.n()).done;){var c=o.value;l.test(c)&&n.push(c.substring(c.indexOf(":")+1).trim())}}catch(e){a.e(e)}finally{a.f()}return n}},{key:"hasHeader",value:function(e){if(this.headers[p.headerize(e)])return!0;var t,n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=u(this.extraHeaders);try{for(r.s();!(t=r.n()).done;){var s=t.value;if(n.test(s))return!0}}catch(e){r.e(e)}finally{r.f()}return!1}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=d.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=u(this.headers[t]);try{for(r.s();!(n=r.n()).done;){var s=n.value;e+="".concat(t,": ").concat(s,"\r\n")}}catch(e){r.e(e)}finally{r.f()}}var i,o=u(this.extraHeaders);try{for(o.s();!(i=o.n()).done;){var l=i.value;e+="".concat(l.trim(),"\r\n")}}catch(e){o.e(e)}finally{o.f()}var a=[];switch(this.method){case _.REGISTER:a.push("path","gruu");break;case _.INVITE:this.ua.configuration.session_timers&&a.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&a.push("gruu"),a.push("ice","replaces");break;case _.UPDATE:this.ua.configuration.session_timers&&a.push("timer"),a.push("ice")}a.push("outbound");var c=this.ua.configuration.user_agent||_.USER_AGENT;if(e+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),e+="Supported: ".concat(a,"\r\n"),e+="User-Agent: ".concat(c,"\r\n"),this.body){var h=p.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=p.cloneArray(this.extraHeaders),t.to=this.to,t.from=this.from,t.call_id=this.call_id,t.cseq=this.cseq,t}}]),e}(),T=function(e){s(n,y);var t=o(n);function n(e,r,s,i,o){var l;return c(this,n),(l=t.call(this,_.INVITE,e,r,s,i,o)).transaction=null,l}return f(n,[{key:"cancel",value:function(e){this.transaction.cancel(e)}},{key:"clone",value:function(){var e=new n(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=p.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}}]),n}(),C=function(){function e(){c(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 f(e,[{key:"addHeader",value:function(e,t){var n={raw:t};e=p.headerize(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[p.headerize(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[p.headerize(e)],n=[];if(!t)return[];var r,s=u(t);try{for(s.s();!(r=s.n()).done;){var i=r.value;n.push(i.raw)}}catch(e){s.e(e)}finally{s.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[p.headerize(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=p.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 s=v.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void g('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}g('not so many "'.concat(e,'" headers present'))}else g('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[p.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=d.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,C);var t=o(n);function n(e){var r;return c(this,n),(r=t.call(this)).ua=e,r.headers={},r.ruri=null,r.transport=null,r.server_transaction=null,r}return f(n,[{key:"reply",value:function(e,t,n,r,s,i){var o=[],l=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||_.REASON_PHRASE[e]||"",n=p.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;a+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=u(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;a+="Via: ".concat(v,"\r\n")}}catch(e){m.e(e)}finally{m.f()}!this.to_tag&&e>100?l+=";tag=".concat(p.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),a+="To: ".concat(l,"\r\n"),a+="From: ".concat(this.getHeader("From"),"\r\n"),a+="Call-ID: ".concat(this.call_id,"\r\n"),a+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=u(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;a+="".concat(T.trim(),"\r\n")}}catch(e){y.e(e)}finally{y.f()}switch(this.method){case _.INVITE:this.ua.configuration.session_timers&&o.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&o.push("gruu"),o.push("ice","replaces");break;case _.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===_.OPTIONS?(a+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);a+="Content-Type: application/sdp\r\n",a+="Content-Length: ".concat(C,"\r\n\r\n"),a+=r}else a+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,a,s,i)}},{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||_.REASON_PHRASE[e]||"";var r,s="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),i=u(n);try{for(i.s();!(r=i.n()).done;){var o=r.value;s+="Via: ".concat(o,"\r\n")}}catch(e){i.e(e)}finally{i.f()}var l=this.getHeader("To");!this.to_tag&&e>100?l+=";tag=".concat(p.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),s+="To: ".concat(l,"\r\n"),s+="From: ".concat(this.getHeader("From"),"\r\n"),s+="Call-ID: ".concat(this.call_id,"\r\n"),s+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),s+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(s)}}]),n}(),E=function(e){s(n,C);var t=o(n);function n(){var e;return c(this,n),(e=t.call(this)).headers={},e.status_code=null,e.reason_phrase=null,e}return n}();t.exports={OutgoingRequest:y,InitialOutgoingInviteRequest:T,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,debug:30,"sdp-transform":35}],20:[function(e,t,n){"use strict";var r=e("./Utils"),s=e("./Grammar"),i=e("debug")("JsSIP:ERROR:Socket");i.log=console.warn.bind(console),n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return i("undefined JsSIP.Socket instance"),!1;try{if(!r.isString(e.url))throw i("missing or invalid JsSIP.Socket url property"),new Error;if(!r.isString(e.via_transport))throw i("missing or invalid JsSIP.Socket via_transport property"),new Error;if(-1===s.parse(e.sip_uri,"SIP_URI"))throw i("missing or invalid JsSIP.Socket sip_uri property"),new Error}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!r.isFunction(e[t]))throw i("missing or invalid JsSIP.Socket method: ".concat(t)),new Error})}catch(e){return!1}return!0}},{"./Grammar":7,"./Utils":26,debug:30}],21:[function(e,t,n){"use strict";var r=500;t.exports={T1:r,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}},{}],22:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function l(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&&u(e,t)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(e){var t=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 n,s=h(e);if(t){var i=h(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return c(e)}(this,n)}}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=e("events").EventEmitter,d=e("./Constants"),_=e("./SIPMessage"),p=e("./Timers"),m=e("debug")("JsSIP:NonInviteClientTransaction"),v=e("debug")("JsSIP:InviteClientTransaction"),g=e("debug")("JsSIP:AckClientTransaction"),y=e("debug")("JsSIP:NonInviteServerTransaction"),T=e("debug")("JsSIP:InviteServerTransaction"),C={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},S=function(e){l(n,f);var t=a(n);function n(e,r,i,o){var l;s(this,n),(l=t.call(this)).type=C.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(c(l)),l}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(C.STATUS_TRYING),this.F=setTimeout(function(){e.timer_F()},p.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){m("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){m("Timer F expired for transaction ".concat(this.id)),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(e){var t=this,n=e.status_code;if(n<200)switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e)}else switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED),clearTimeout(this.F),408===n?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(e),this.K=setTimeout(function(){t.timer_K()},p.TIMER_K);break;case C.STATUS_COMPLETED:}}},{key:"C",get:function(){return C}}]),n}(),E=function(e){l(n,f);var t=a(n);function n(e,r,i,o){var l;s(this,n),(l=t.call(this)).type=C.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=c(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(c(l)),l}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"send",value:function(){var e=this;this.stateChanged(C.STATUS_CALLING),this.B=setTimeout(function(){e.timer_B()},p.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==C.STATUS_ACCEPTED&&(v("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){v("Timer M expired for transaction ".concat(this.id)),this.state===C.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){v("Timer B expired for transaction ".concat(this.id)),this.state===C.STATUS_CALLING&&(this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){v("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(e){var t=this,n=new _.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()},p.TIMER_D),this.transport.send(n)}},{key:"cancel",value:function(e){if(this.state===C.STATUS_PROCEEDING){var t=new _.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 C.STATUS_CALLING:this.stateChanged(C.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return C}}]),n}(),A=function(e){l(n,f);var t=a(n);function n(e,r,i,o){var l;s(this,n),(l=t.call(this)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),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}return o(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){g("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return C}}]),n}(),b=function(e){l(n,f);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=C.NON_INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=C.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_J",value:function(){y("Timer J expired for transaction ".concat(this.id)),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,y("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case C.STATUS_TRYING:this.stateChanged(C.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case C.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=200&&e<=699)switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},p.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case C.STATUS_COMPLETED:}}},{key:"C",get:function(){return C}}]),n}(),R=function(e){l(n,f);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=C.INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=C.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){T("Timer H expired for transaction ".concat(this.id)),this.state===C.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===C.STATUS_ACCEPTED&&(this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T("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(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(e>=100&&e<=199)switch(this.state){case C.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===C.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},p.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},p.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case C.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case C.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(C.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return C}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:b,InviteServerTransaction:R,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case d.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case C.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case C.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===C.STATUS_ACCEPTED)return!1;if(n.state===C.STATUS_COMPLETED)return n.state=C.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},p.TIMER_I),!0;break;case d.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==C.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case C.STATUS_TRYING:break;case C.STATUS_PROCEEDING:case C.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":19,"./Timers":21,debug:30,events:29}],23:[function(e,t,n){"use strict";function r(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 s(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 s(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 o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(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 i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=e("./Socket"),l=e("debug")("JsSIP:Transport"),u=e("debug")("JsSIP:ERROR:Transport"),a=e("./Constants");u.log=console.warn.bind(console);var c={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:a.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:a.CONNECTION_RECOVERY_MAX_INTERVAL}};t.exports=function(){function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c.recovery_options;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l("new()"),this._ua=t,this.status=c.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=r,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1,void 0===n)throw new TypeError("Invalid argument. undefined 'sockets' argument");n instanceof Array||(n=[n]),n.forEach(function(e){if(!o.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:c.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l("connect()"),this.isConnected()?l("Transport is already connected"):this.isConnecting()?l("Transport is connecting"):(this.close_requested=!1,this.status=c.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(){l("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=c.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(l("send()"),!this.isConnected())return u("unable to send message, transport is not connected"),!1;var t=e.toString();return l("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===c.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===c.STATUS_CONNECTING}},{key:"_get_number_of_sbc",value:function(){return this.sockets.length}},{key:"_switch_sbc",value:function(){var e=this.ondisconnect;this.ondisconnect=function(){},this.disconnect(),this.ondisconnect=e,this.close_requested=!1,this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=c.SOCKET_STATUS_ERROR)},this),this._getSocket(),this.connect()}},{key:"_register_redirect",value:function(e){var t,n=null,s=r(this.sockets);try{for(s.s();!(t=s.n()).done;){var i=t.value;if(i.socket.url===e){n=i.socket;break}}}catch(e){s.e(e)}finally{s.f()}if(null===n&&!e.includes(":",6)){e+=":443";var o,l=r(this.sockets);try{for(l.s();!(o=l.n()).done;){var u=o.value;if(u.socket.url===e){n=u.socket;break}}}catch(e){l.e(e)}finally{l.f()}}if(null===n)return!1;var a=this.ondisconnect;return this.ondisconnect=function(){},this.disconnect(),this.ondisconnect=a,this.socket=n,this.connect(),!0}},{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),l("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!==c.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=c.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._ha_connect_time=void 0,this.status=c.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){var r=this.status;if(this.status=c.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),!this.close_requested){if(void 0!==this._ua.modes.sbc_ha_pairs_mode){if(r===c.STATUS_CONNECTED)return l("AC: SBC HA pairs mode: Reconnect to the same SBC "+this._ua.modes.sbc_ha_pairs_mode+" seconds left"),this._ha_connect_time=(new Date).getTime()+1e3*this._ua.modes.sbc_ha_pairs_mode,void this._connect2();if(void 0!==this._ha_connect_time){var s=this._ha_connect_time-(new Date).getTime();if(s>0)return l("AC: SBC HA pairs mode: Repeat "+s/1e3+" seconds left"),void this._connect2();l("AC: SBC HA pairs mode: Failed"),this._ha_connect_time=void 0}}this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=c.SOCKET_STATUS_ERROR)},this),this._reconnect()}}},{key:"_connect2",value:function(){var e=this,t=0;if(this._ha_last_connect){var n=(new Date).getTime()-this._ha_last_connect;t=n>500?0:500-n}this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._ha_last_connect=(new Date).getTime(),e.connect())},t)}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l("received binary message failed to be converted into string, message discarded")}l("received binary message:\n\n".concat(e,"\n"))}else l("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l("received message with CRLF Keep Alive response")}},{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}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Socket":20,debug:30}],24:[function(e,t,n){"use strict";function r(e){return(r="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)}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),e}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){var t=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 n,s=a(e);if(t){var i=a(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return u(e)}(this,n)}}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var c=e("events").EventEmitter,h=e("./Constants"),f=e("./Registrator"),d=e("./RTCSession"),_=e("./Message"),p=e("./Transactions"),m=e("./Transport"),v=e("./Utils"),g=e("./Exceptions"),y=e("./URI"),T=e("./Parser"),C=e("./SIPMessage"),S=e("./sanityCheck"),E=e("./Config"),A=e("debug")("JsSIP:UA"),b=e("debug")("JsSIP:ERROR:UA");b.log=console.warn.bind(console);var R={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};t.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&&o(e,t)}(n,c);var t=l(n);function n(e){var r;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),(r=t.call(this)).modes={},r._cache={credentials:{}},r._configuration=Object.assign({},E.settings),r._dynConfiguration={},r._dialogs={},r._applicants={},r._sessions={},r._transport=null,r._contact=null,r._status=R.STATUS_INIT,r._error=null,r._transactions={nist:{},nict:{},ist:{},ict:{}},r._data={},r._closeTimer=null,void 0===e)throw new TypeError("Not enough arguments");try{r._loadConfig(e)}catch(e){throw r._status=R.STATUS_NOT_READY,r._error=R.CONFIGURATION_ERROR,e}return r._registrator=new f(u(r)),r}return i(n,null,[{key:"C",get:function(){return R}}]),i(n,[{key:"start",value:function(){A("start()"),this._status===R.STATUS_INIT?this._transport.connect():this._status===R.STATUS_USER_CLOSED?(A("restarting UA"),null!==this._closeTimer&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=R.STATUS_INIT,this._transport.connect()):this._status===R.STATUS_READY?A("UA is in READY status, not restarted"):A("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){A("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(e){A("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){A("call()");var n=new d(this);return n.connect(e,t),n}},{key:"sendMessage",value:function(e,t,n){A("sendMessage()");var r=new _(this);return r.send(e,t,n),r}},{key:"terminateSessions",value:function(e){for(var t in A("terminateSessions()"),this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(e)}},{key:"stop",value:function(){var e=this;if(A("stop()"),this._dynConfiguration={},this._status!==R.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)){A("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=R.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 A("UA already closed")}},{key:"normalizeTarget",value:function(e){return v.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;default:return void b('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"display_name":this._configuration.display_name=t;break;default:return b('set() | cannot set "%s" parameter in runtime',e),!1}return!0}},{key:"registerRedirect",value:function(e){return this._transport._register_redirect(e)}},{key:"switchSBC",value:function(){this._transport._get_number_of_sbc()<2?A("switchSBC: ignored, no other SBC set"):(this._registrator._unregistered(null,h.causes.CONNECTION_ERROR),this._transport._switch_sbc())}},{key:"getNumberOfSBC",value:function(){return this._transport._get_number_of_sbc()}},{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:"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 A("Request-URI does not point to us"),void(e.method!==h.ACK&&e.reply_sl(404));if(e.ruri.scheme!==h.SIPS){if(!p.checkTransaction(this,e)){if(t===h.INVITE?new p.InviteServerTransaction(this,this._transport,e):t!==h.ACK&&t!==h.CANCEL&&new p.NonInviteServerTransaction(this,this._transport,e),t===h.OPTIONS)e.reply(200);else if(t===h.MESSAGE){if(0===this.listeners("newMessage").length)return void e.reply(405);new _(this).init_incoming(e)}else if(t===h.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===h.NOTIFY?(r=this._findSession(e))?r.receiveRequest(e):(A("received NOTIFY request for a non existent subscription"),e.reply(481,"Subscription does not exist")):t!==h.ACK&&e.reply(481);else switch(t){case h.INVITE:if(window.RTCPeerConnection)if(e.hasHeader("replaces")){var s=e.replaces;(n=this._findDialog(s.call_id,s.from_tag,s.to_tag))?(r=n.owner).isEnded()?e.reply(603):r.receiveRequest(e):e.reply(481)}else(r=new d(this)).init_incoming(e);else b("INVITE received but WebRTC is not supported"),e.reply(488);break;case h.BYE:e.reply(481);break;case h.CANCEL:(r=this._findSession(e))?r.receiveRequest(e):A("received CANCEL request for a non existent session");break;case h.ACK:break;case h.NOTIFY:this.emit("sipEvent",{event:e.event,request:e}),e.reply(200);break;default:e.reply(405)}}}else e.reply_sl(416)}},{key:"_findSession",value:function(e){var t=e.call_id,n=e.from_tag,r=e.to_tag,s=t+n,i=this._sessions[s],o=t+r,l=this._sessions[o];return i||(l||null)}},{key:"_findDialog",value:function(e,t,n){var r=e+t+n,s=this._dialogs[r];return s||(r=e+n+t,(s=this._dialogs[r])||null)}},{key:"_loadConfig",value:function(e){try{E.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=v.newUUID()),this._configuration.jssip_id=v.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,this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=function(e){this.emit("connecting",e)}.bind(this),this._transport.onconnect=function(e){if(this._status===R.STATUS_USER_CLOSED)return;this._status=R.STATUS_READY,this._error=null,this.emit("connected",e),this._dynConfiguration.register&&this._registrator.register()}.bind(this),this._transport.ondisconnect=function(e){for(var t=0,n=["nict","ict","nist","ist"];t<n.length;t++){var r=n[t];for(var s in this._transactions[r])Object.prototype.hasOwnProperty.call(this._transactions[r],s)&&this._transactions[r][s].onTransportError()}this.emit("disconnected",e),this._registrator.onTransportClosed(),this._status!==R.STATUS_USER_CLOSED&&(this._status=R.STATUS_NOT_READY,this._error=R.NETWORK_ERROR)}.bind(this),this._transport.ondata=function(e){var t=e.transport,n=e.message;if(!(n=T.parseMessage(n,this)))return;if(this._status===R.STATUS_USER_CLOSED&&n instanceof C.IncomingRequest)return;if(!S(n,this,t))return;if(n instanceof C.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof C.IncomingResponse){var r;switch(n.method){case h.INVITE:(r=this._transactions.ict[n.via_branch])&&r.receiveResponse(n);break;case h.ACK:break;default:(r=this._transactions.nict[n.via_branch])&&r.receiveResponse(n)}}}.bind(this)}catch(e){throw b(e),new g.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",v.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","display_name","register"];for(var s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(-1!==r.indexOf(s)?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));for(var i in A("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return R}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,debug:30,events:29}],25:[function(e,t,n){"use strict";function r(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 s(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 s(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 o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(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 i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}var l=e("./Constants"),u=e("./Utils"),a=e("./Grammar");t.exports=function(){function e(t,n,r,s){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},o=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,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||l.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,u)&&this.setParam(u,i[u]);for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.setHeader(a,o[a])}return o(e,null,[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}]),o(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:"setHeader",value:function(e,t){this._headers[u.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[u.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(u.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=u.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(u.escapeUser(this._user),"@")),t+=this._host,(this._port||0===this._port)&&(t+=":".concat(this._port)),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,n)&&(t+=";".concat(n),null!==this._parameters[n]&&(t+="=".concat(this._parameters[n])));for(var s in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,s)){var i,o=r(this._headers[s]);try{for(o.s();!(i=o.n()).done;){var l=i.value;e.push("".concat(s,"=").concat(l))}}catch(e){o.e(e)}finally{o.f()}}return e.length>0&&(t+="?".concat(e.join("&"))),t}},{key:"toAor",value:function(e){var t="".concat(this._scheme,":");return this._user&&(t+="".concat(u.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}}]),e}()},{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(e,t,n){"use strict";function r(e){return(r="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)}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 i(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 i(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},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,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(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}var o=e("./Constants"),l=e("./URI"),u=e("./Grammar");n.str_utf8_length=function(e){return unescape(encodeURIComponent(e)).length};var a=n.isFunction=function(e){return void 0!==e&&"[object Function]"===Object.prototype.toString.call(e)};n.isString=function(e){return void 0!==e&&"[object String]"===Object.prototype.toString.call(e)},n.isDecimal=function(e){return!isNaN(e)&&parseFloat(e)===parseInt(e,10)},n.isEmpty=function(e){return null===e||""===e||void 0===e||Array.isArray(e)&&0===e.length||"number"==typeof e&&isNaN(e)},n.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 s=0,i=n;s<i.length;s++){var o=i[s];if(a(e[o]))return!1}return!0};var c=n.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};n.newTag=function(){return c(10)},n.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)})},n.hostType=function(e){if(e)return-1!==(e=u.parse(e,"host"))?e.host_type:void 0};var h=n.escapeUser=function(e){return encodeURIComponent(decodeURIComponent(e)).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")};n.normalizeTarget=function(e,t){if(e){if(e instanceof l)return e;if("string"==typeof e){var n,r,s,i=e.split("@");switch(i.length){case 1:if(!t)return;n=e,r=t;break;case 2:n=i[0],r=i[1];break;default:n=i.slice(0,i.length-1).join("@"),r=i[i.length-1]}return n=n.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(n)&&(n=n.replace(/[-.()]/g,"")),e="".concat(o.SIP,":").concat(h(n),"@").concat(r),(s=l.parse(e))?s:void 0}}else;},n.headerize=function(e){var t,n={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},r=e.toLowerCase().replace(/_/g,"-").split("-"),s="",i=r.length;for(t=0;t<i;t++)0!==t&&(s+="-"),s+=r[t].charAt(0).toUpperCase()+r[t].substring(1);return n[s]&&(s=n[s]),s},n.sipErrorCause=function(e){for(var t in o.SIP_ERROR_CAUSES)if(-1!==o.SIP_ERROR_CAUSES[t].indexOf(e))return o.causes[t];return o.causes.SIP_FAILURE_CODE},n.getRandomTestNetIP=function(){return"192.0.2.".concat((e=1,t=254,Math.floor(Math.random()*(t-e+1)+e)));var e,t},n.calculateMD5=function(e){function t(e,t){return e<<t|e>>>32-t}function n(e,t){var n=2147483648&e,r=2147483648&t,s=1073741824&e,i=1073741824&t,o=(1073741823&e)+(1073741823&t);return s&i?2147483648^o^n^r:s|i?1073741824&o?3221225472^o^n^r:1073741824^o^n^r:o^n^r}function r(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),u)),n(t(e,l),r)}function s(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),u)),n(t(e,l),r)}function i(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),u)),n(t(e,l),r)}function o(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),u)),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 u,a,c,h,f,d,_,p,m,v;for(u=function(e){for(var t,n=e.length,r=n+8,s=16*((r-r%64)/64+1),i=new Array(s-1),o=0,l=0;l<n;)o=l%4*8,i[t=(l-l%4)/4]=i[t]|e.charCodeAt(l)<<o,l++;return o=l%4*8,i[t=(l-l%4)/4]=i[t]|128<<o,i[s-2]=n<<3,i[s-1]=n>>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");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,v=271733878,a=0;a<u.length;a+=16)c=_,h=p,f=m,d=v,_=r(_,p,m,v,u[a+0],7,3614090360),v=r(v,_,p,m,u[a+1],12,3905402710),m=r(m,v,_,p,u[a+2],17,606105819),p=r(p,m,v,_,u[a+3],22,3250441966),_=r(_,p,m,v,u[a+4],7,4118548399),v=r(v,_,p,m,u[a+5],12,1200080426),m=r(m,v,_,p,u[a+6],17,2821735955),p=r(p,m,v,_,u[a+7],22,4249261313),_=r(_,p,m,v,u[a+8],7,1770035416),v=r(v,_,p,m,u[a+9],12,2336552879),m=r(m,v,_,p,u[a+10],17,4294925233),p=r(p,m,v,_,u[a+11],22,2304563134),_=r(_,p,m,v,u[a+12],7,1804603682),v=r(v,_,p,m,u[a+13],12,4254626195),m=r(m,v,_,p,u[a+14],17,2792965006),_=s(_,p=r(p,m,v,_,u[a+15],22,1236535329),m,v,u[a+1],5,4129170786),v=s(v,_,p,m,u[a+6],9,3225465664),m=s(m,v,_,p,u[a+11],14,643717713),p=s(p,m,v,_,u[a+0],20,3921069994),_=s(_,p,m,v,u[a+5],5,3593408605),v=s(v,_,p,m,u[a+10],9,38016083),m=s(m,v,_,p,u[a+15],14,3634488961),p=s(p,m,v,_,u[a+4],20,3889429448),_=s(_,p,m,v,u[a+9],5,568446438),v=s(v,_,p,m,u[a+14],9,3275163606),m=s(m,v,_,p,u[a+3],14,4107603335),p=s(p,m,v,_,u[a+8],20,1163531501),_=s(_,p,m,v,u[a+13],5,2850285829),v=s(v,_,p,m,u[a+2],9,4243563512),m=s(m,v,_,p,u[a+7],14,1735328473),_=i(_,p=s(p,m,v,_,u[a+12],20,2368359562),m,v,u[a+5],4,4294588738),v=i(v,_,p,m,u[a+8],11,2272392833),m=i(m,v,_,p,u[a+11],16,1839030562),p=i(p,m,v,_,u[a+14],23,4259657740),_=i(_,p,m,v,u[a+1],4,2763975236),v=i(v,_,p,m,u[a+4],11,1272893353),m=i(m,v,_,p,u[a+7],16,4139469664),p=i(p,m,v,_,u[a+10],23,3200236656),_=i(_,p,m,v,u[a+13],4,681279174),v=i(v,_,p,m,u[a+0],11,3936430074),m=i(m,v,_,p,u[a+3],16,3572445317),p=i(p,m,v,_,u[a+6],23,76029189),_=i(_,p,m,v,u[a+9],4,3654602809),v=i(v,_,p,m,u[a+12],11,3873151461),m=i(m,v,_,p,u[a+15],16,530742520),_=o(_,p=i(p,m,v,_,u[a+2],23,3299628645),m,v,u[a+0],6,4096336452),v=o(v,_,p,m,u[a+7],10,1126891415),m=o(m,v,_,p,u[a+14],15,2878612391),p=o(p,m,v,_,u[a+5],21,4237533241),_=o(_,p,m,v,u[a+12],6,1700485571),v=o(v,_,p,m,u[a+3],10,2399980690),m=o(m,v,_,p,u[a+10],15,4293915773),p=o(p,m,v,_,u[a+1],21,2240044497),_=o(_,p,m,v,u[a+8],6,1873313359),v=o(v,_,p,m,u[a+15],10,4264355552),m=o(m,v,_,p,u[a+6],15,2734768916),p=o(p,m,v,_,u[a+13],21,1309151649),_=o(_,p,m,v,u[a+4],6,4149444226),v=o(v,_,p,m,u[a+11],10,3174756917),m=o(m,v,_,p,u[a+2],15,718787259),p=o(p,m,v,_,u[a+9],21,3951481745),_=n(_,c),p=n(p,h),m=n(m,f),v=n(v,d);return(l(_)+l(p)+l(m)+l(v)).toLowerCase()},n.closeMediaStream=function(e){if(e)try{if(e.getTracks){var t,n=s(e.getTracks());try{for(n.s();!(t=n.n()).done;){t.value.stop()}}catch(e){n.e(e)}finally{n.f()}}else{var i,o=s(e.getAudioTracks());try{for(o.s();!(i=o.n()).done;){i.value.stop()}}catch(e){o.e(e)}finally{o.f()}var l,u=s(e.getVideoTracks());try{for(u.s();!(l=u.n()).done;){l.value.stop()}}catch(e){u.e(e)}finally{u.f()}}}catch(t){"function"!=typeof e.stop&&"object"!==r(e.stop)||e.stop()}},n.cloneArray=function(e){return e&&e.slice()||[]},n.cloneObject=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(e,t,n){"use strict";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)}}var s=e("./Grammar"),i=e("debug")("JsSIP:WebSocketInterface"),o=e("debug")("JsSIP:ERROR:WebSocketInterface");o.log=console.warn.bind(console),t.exports=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=s.parse(t,"absoluteURI");if(-1===n)throw o("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if("wss"!==n.scheme&&"ws"!==n.scheme)throw o("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}var t,n,l;return t=e,(n=[{key:"connect",value:function(){if(i("connect()"),this.isConnected())i("WebSocket ".concat(this._url," is already connected"));else if(this.isConnecting())i("WebSocket ".concat(this._url," is connecting"));else{this._ws&&this.disconnect(),i("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(){i("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 i("send()"),this.isConnected()?(this._ws.send(e),!0):(o("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(){i("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(e){var t=e.wasClean,n=e.code,r=e.reason;i("WebSocket ".concat(this._url," closed")),!1===t&&i("WebSocket abrupt disconnection");var s={socket:this,error:!t,code:n,reason:r};this.ondisconnect(s)}},{key:"_onMessage",value:function(e){var t=e.data;i("received WebSocket message"),this.ondata(t)}},{key:"_onError",value:function(e){o("WebSocket ".concat(this._url," error: ").concat(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}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Grammar":7,debug:30}],28:[function(e,t,n){"use strict";function r(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 s(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 s(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 o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(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}var i,o,l,u=e("./Constants"),a=e("./SIPMessage"),c=e("./Utils"),h=e("debug")("JsSIP:sanityCheck"),f=[function(){for(var e=0,t=["from","to","call_id","cseq","via"];e<t.length;e++){var n=t[e];if(!i.hasHeader(n))return h("missing mandatory header field : ".concat(n,", dropping the response")),!1}}],d=[function(){if("sip"!==i.s("to").uri.scheme)return p(416),!1},function(){if(!i.to_tag&&i.call_id.substr(0,5)===o.configuration.jssip_id)return p(482),!1},function(){var e=c.str_utf8_length(i.body),t=i.getHeader("content-length");if(e<t)return p(400),!1},function(){var e,t=i.from_tag,n=i.call_id,r=i.cseq;if(i.to_tag)return;if(i.method===u.INVITE){if(o._transactions.ist[i.via_branch])return!1;for(var s in o._transactions.ist)if(Object.prototype.hasOwnProperty.call(o._transactions.ist,s)&&(e=o._transactions.ist[s]).request.from_tag===t&&e.request.call_id===n&&e.request.cseq===r)return p(482),!1}else{if(o._transactions.nist[i.via_branch])return!1;for(var l in o._transactions.nist)if(Object.prototype.hasOwnProperty.call(o._transactions.nist,l)&&(e=o._transactions.nist[l]).request.from_tag===t&&e.request.call_id===n&&e.request.cseq===r)return p(482),!1}}],_=[function(){if(i.getHeaders("via").length>1)return h("more than one Via header field present in the response, dropping the response"),!1},function(){var e=c.str_utf8_length(i.body),t=i.getHeader("content-length");if(e<t)return h("message body length is lower than the value in Content-Length header field, dropping the response"),!1}];function p(e){var t,n,s=i.getHeaders("via"),o="SIP/2.0 ".concat(e," ").concat(u.REASON_PHRASE[e],"\r\n"),a=r(s);try{for(a.s();!(n=a.n()).done;){var h=n.value;o+="Via: ".concat(h,"\r\n")}}catch(e){a.e(e)}finally{a.f()}t=i.getHeader("To"),i.to_tag||(t+=";tag=".concat(c.newTag())),o+="To: ".concat(t,"\r\n"),o+="From: ".concat(i.getHeader("From"),"\r\n"),o+="Call-ID: ".concat(i.call_id,"\r\n"),o+="CSeq: ".concat(i.cseq," ").concat(i.method,"\r\n"),o+="\r\n",l.send(o)}t.exports=function(e,t,n){i=e,o=t,l=n;var s,u=r(f);try{for(u.s();!(s=u.n()).done;){if(!1===(0,s.value)())return!1}}catch(e){u.e(e)}finally{u.f()}if(i instanceof a.IncomingRequest){var c,h=r(d);try{for(h.s();!(c=h.n()).done;){if(!1===(0,c.value)())return!1}}catch(e){h.e(e)}finally{h.f()}}else if(i instanceof a.IncomingResponse){var p,m=r(_);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}},{"./Constants":2,"./SIPMessage":19,"./Utils":26,debug:30}],29:[function(e,t,n){var r=Object.create||function(e){var t=function(){};return t.prototype=e,new t},s=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return n},i=Function.prototype.bind||function(e){var t=this;return function(){return t.apply(e,arguments)}};function o(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=r(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}t.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._maxListeners=void 0;var l,u=10;try{var a={};Object.defineProperty&&Object.defineProperty(a,"x",{value:0}),l=0===a.x}catch(e){l=!1}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function h(e,t,n,s){var i,o,l;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),l=o[t]):(o=e._events=r(null),e._eventsCount=0),l){if("function"==typeof l?l=o[t]=s?[n,l]:[l,n]:s?l.unshift(n):l.push(n),!l.warned&&(i=c(e))&&i>0&&l.length>i){l.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",u.name,u.message)}}else l=o[t]=n,++e._eventsCount;return e}function f(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},s=i.call(f,r);return s.listener=n,r.wrapFn=s,s}function _(e,t,n){var r=e._events;if(!r)return[];var s=r[t];return s?"function"==typeof s?n?[s.listener||s]:[s]: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}(s):m(s,s.length):[]}function p(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}l?Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||e!=e)throw new TypeError('"defaultMaxListeners" must be a positive number');u=e}}):o.defaultMaxListeners=u,o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){var t,n,r,s,i,o,l="error"===e;if(o=this._events)l=l&&null==o.error;else if(!l)return!1;if(l){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var u=new Error('Unhandled "error" event. ('+t+")");throw u.context=t,u}if(!(n=o[e]))return!1;var a="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,s=m(e,r),i=0;i<r;++i)s[i].call(n)}(n,a,this);break;case 2:!function(e,t,n,r){if(t)e.call(n,r);else for(var s=e.length,i=m(e,s),o=0;o<s;++o)i[o].call(n,r)}(n,a,this,arguments[1]);break;case 3:!function(e,t,n,r,s){if(t)e.call(n,r,s);else for(var i=e.length,o=m(e,i),l=0;l<i;++l)o[l].call(n,r,s)}(n,a,this,arguments[1],arguments[2]);break;case 4:!function(e,t,n,r,s,i){if(t)e.call(n,r,s,i);else for(var o=e.length,l=m(e,o),u=0;u<o;++u)l[u].call(n,r,s,i)}(n,a,this,arguments[1],arguments[2],arguments[3]);break;default:for(s=new Array(r-1),i=1;i<r;i++)s[i-1]=arguments[i];!function(e,t,n,r){if(t)e.apply(n,r);else for(var s=e.length,i=m(e,s),o=0;o<s;++o)i[o].apply(n,r)}(n,a,this,s)}return!0},o.prototype.addListener=function(e,t){return h(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return h(this,e,t,!0)},o.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,d(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,d(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,s,i,o,l;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(s=this._events))return this;if(!(n=s[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=r(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){l=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(var n=t,r=n+1,s=e.length;r<s;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i),1===n.length&&(s[e]=n[0]),s.removeListener&&this.emit("removeListener",e,l||t)}return this},o.prototype.removeAllListeners=function(e){var t,n,i;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=r(null),this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=r(null):delete n[e]),this;if(0===arguments.length){var o,l=s(n);for(i=0;i<l.length;++i)"removeListener"!==(o=l[i])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=r(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return _(this,e,!0)},o.prototype.rawListeners=function(e){return _(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],30:[function(e,t,n){(function(r){n.log=function(...e){return"object"==typeof console&&console.log&&console.log(...e)},n.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;e.splice(1,0,n,"color: inherit");let r=0,s=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))}),e.splice(s,0,n)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},n.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;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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},n.storage=function(){try{return localStorage}catch(e){}}(),n.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.exports=e("./common")(n);const{formatters:s}=t.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]}function r(e){let t;function o(...e){if(!o.enabled)return;const n=o,s=Number(new Date),i=s-(t||s);n.diff=i,n.prev=t,n.curr=s,t=s,e[0]=r.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let l=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,s)=>{if("%%"===t)return t;l++;const i=r.formatters[s];if("function"==typeof i){const r=e[l];t=i.call(n,r),e.splice(l,1),l--}return t}),r.formatArgs.call(n,e),(n.log||r.log).apply(n,e)}return o.namespace=e,o.enabled=r.enabled(e),o.useColors=r.useColors(),o.color=n(e),o.destroy=s,o.extend=i,"function"==typeof r.init&&r.init(o),r.instances.push(o),o}function s(){const e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function i(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return r.debug=r,r.default=r,r.coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){const e=[...r.names.map(o),...r.skips.map(o).map(e=>"-"+e)].join(",");return r.enable(""),e},r.enable=function(e){let t;r.save(e),r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),s=n.length;for(t=0;t<s;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")));for(t=0;t<r.instances.length;t++){const e=r.instances[t];e.enabled=r.enabled(e.namespace)}},r.enabled=function(e){if("*"===e[e.length-1])return!0;let t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=e("ms"),Object.keys(t).forEach(e=>{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:32}],32:[function(e,t,n){var r=1e3,s=60*r,i=60*s,o=24*i,l=7*o,u=365.25*o;function a(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}t.exports=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*u;case"weeks":case"week":case"w":return n*l;case"days":case"day":case"d":return n*o;case"hours":case"hour":case"hrs":case"hr":case"h":return n*i;case"minutes":case"minute":case"mins":case"min":case"m":return n*s;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=o)return a(e,t,o,"day");if(t>=i)return a(e,t,i,"hour");if(t>=s)return a(e,t,s,"minute");if(t>=r)return a(e,t,r,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=o)return Math.round(e/o)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=s)return Math.round(e/s)+"m";if(t>=r)return Math.round(e/r)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],33:[function(e,t,n){var r,s,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function l(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(e){r=o}try{s="function"==typeof clearTimeout?clearTimeout:l}catch(e){s=l}}();var a,c=[],h=!1,f=-1;function d(){h&&a&&(h=!1,a.length?c=a.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=u(d);h=!0;for(var t=c.length;t;){for(a=c,c=[];++f<t;)a&&a[f].run();f=-1,t=c.length}a=null,h=!1,function(e){if(s===clearTimeout)return clearTimeout(e);if((s===l||!s)&&clearTimeout)return s=clearTimeout,clearTimeout(e);try{s(e)}catch(t){try{return s.call(null,e)}catch(t){return s.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new p(e,t)),1!==c.length||h||u(_)},p.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],34:[function(e,t,n){var r=t.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(e){return e.encoding?"rtpmap:%d %s/%s/%s":e.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(e){return 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:%d 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"]}]};Object.keys(r).forEach(function(e){r[e].forEach(function(e){e.reg||(e.reg=/(.*)/),e.format||(e.format="%s")})})},{}],35:[function(e,t,n){var r=e("./parser"),s=e("./writer");n.write=s,n.parse=r.parse,n.parseParams=r.parseParams,n.parseFmtpConfig=r.parseFmtpConfig,n.parsePayloads=r.parsePayloads,n.parseRemoteCandidates=r.parseRemoteCandidates,n.parseImageAttributes=r.parseImageAttributes,n.parseSimulcastStreamList=r.parseSimulcastStreamList},{"./parser":36,"./writer":37}],36:[function(e,t,n){var r=function(e){return String(Number(e))===e?Number(e):e},s=function(e,t,n){var s=e.name&&e.names;e.push&&!t[e.push]?t[e.push]=[]:s&&!t[e.name]&&(t[e.name]={});var i=e.push?{}:s?t[e.name]:t;!function(e,t,n,s){if(s&&!n)t[s]=r(e[1]);else for(var i=0;i<n.length;i+=1)null!=e[i+1]&&(t[n[i]]=r(e[i+1]))}(n.match(e.reg),i,e.names,e.name),e.push&&t[e.push].push(i)},i=e("./grammar"),o=RegExp.prototype.test.bind(/^([a-z])=(.*)/);n.parse=function(e){var t={},n=[],r=t;return e.split(/(\r\n|\r|\n)/).filter(o).forEach(function(e){var t=e[0],o=e.slice(2);"m"===t&&(n.push({rtp:[],fmtp:[]}),r=n[n.length-1]);for(var l=0;l<(i[t]||[]).length;l+=1){var u=i[t][l];if(u.reg.test(o))return s(u,r,o)}}),t.media=n,t};var l=function(e,t){var n=t.split(/=(.+)/,2);return 2===n.length?e[n[0]]=r(n[1]):1===n.length&&t.length>1&&(e[n[0]]=void 0),e};n.parseParams=function(e){return e.split(/;\s?/).reduce(l,{})},n.parseFmtpConfig=n.parseParams,n.parsePayloads=function(e){return e.toString().split(" ").map(Number)},n.parseRemoteCandidates=function(e){for(var t=[],n=e.split(" ").map(r),s=0;s<n.length;s+=3)t.push({component:n[s],ip:n[s+1],port:n[s+2]});return t},n.parseImageAttributes=function(e){return e.split(" ").map(function(e){return e.substring(1,e.length-1).split(",").reduce(l,{})})},n.parseSimulcastStreamList=function(e){return e.split(";").map(function(e){return e.split(",").map(function(e){var t,n=!1;return"~"!==e[0]?t=r(e):(t=r(e.substring(1,e.length)),n=!0),{scid:t,paused:n}})})}},{"./grammar":34}],37:[function(e,t,n){var r=e("./grammar"),s=/%[sdv%]/g,i=function(e,t,n){var r=[e+"="+(t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format)];if(t.names)for(var i=0;i<t.names.length;i+=1){var o=t.names[i];t.name?r.push(n[t.name][o]):r.push(n[t.names[i]])}else r.push(n[t.name]);return function(e){var t=1,n=arguments,r=n.length;return e.replace(s,function(e){if(t>=r)return e;var s=n[t];switch(t+=1,e){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})}.apply(null,r)},o=["v","o","s","i","u","e","p","c","b","t","r","z","a"],l=["i","c","b","a"];t.exports=function(e,t){t=t||{},null==e.version&&(e.version=0),null==e.name&&(e.name=" "),e.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var n=t.outerOrder||o,s=t.innerOrder||l,u=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})}),e.media.forEach(function(e){u.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})})}),u.join("\r\n")+"\r\n"}},{"./grammar":34}],38:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.6.1",homepage:"https://jssip.net",author:"José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo <ibc@aliax.net> (https://github.com/ibc)"],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/debug":"^4.1.5","@types/node":"^14.0.6",debug:"^4.1.1",events:"^3.1.0","sdp-transform":"^2.14.0"},devDependencies:{"@babel/core":"^7.9.6","@babel/preset-env":"^7.9.6","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:"gulp lint",test:"gulp test",prepublishOnly:"gulp babel"}}},{}]},{},[8])(8)});

"use strict";
/*
 * AudioCodes WebRTC API v1.13.0
 * © 2020 AudioCodes Ltd. All rights reserved.
 */class AudioCodesUA { constructor() { return this._isInitialized = !1, this.serverConfig = {}, this.account = { user: null, userAuth: null, displayName: null, password: null, registerExpires: 600, useSessionTimer: !1 }, this.constraints = { chrome: { audio: !0, video: !0 }, firefox: { audio: !0, video: !0 }, safari: { audio: !0, video: !0 }, ios_safari: { audio: !0, video: !0 }, other: { audio: !0, video: !0 } }, this.chromiumBased = [{ n: "Edge", s: "edg/" }, { n: "Opera", s: "opr/" }, { n: "Samsung", s: "samsungbrowser/" }, { n: "Yandex", s: "yabrowser/" }], this.modes = { video_call_audio_answer_fix: !0, ice_timeout_fix: 2e3, chrome_rtp_timeout_fix: 13, sbc_ha_pairs_mode: void 0, ringing_header_mode: void 0 }, this.listeners = {}, this.registerExtraHeaders = null, this.jssipUA = null, this.browser = "", this.browserVersion = 0, this.browserName = "", this.reconnectMin = 2, this.reconnectMax = 30, this.u17 = void 0, this.wsSocket = null, this.wsOnMessage = null, this.wsPingTask = null, this.wsPongTask = null, this.wsPingMs = 0, this.wsPongMs = 0, this.wsWasPong = !1, this.wsPongStats = 0, this.wsPongStatNum = 0, this.wsPongStatTime = 0, this.wsPongStatDelayMin = 1e6, this.wsPongStatDelayMax = 0, this.wsPongStatDist = null, this.dtmfUseWebRTC = !0, this.dtmfDuration = 250, this.dtmfInterToneGap = 250, this.enableAddVideo = !1, this.oauthToken = null, this.oauthTokenUseInInvite = !0, AudioCodesUA.ac_log = console.log, AudioCodesUA.instance, AudioCodesUA.instance = this, this._detectBrowser(), this.webrtcapi = AudioCodesWebRTCWrapper, this.replacedCall = null, this.AUDIO = Symbol("audio"), this.VIDEO = Symbol("video"), this.RECVONLY_VIDEO = Symbol("recvonly_video"), AudioCodesUA.instance } version() { return "1.13.0" } getBrowserName() { return this.browserName } getBrowser() { return this.browser } getBrowserVersion() { return this.browserVersion } getWR() { return this.webrtcapi } checkAvailableDevices() { return this.getWR().checkAvailableDevices() } getServerAddress() { if (null === this.wsSocket) return null; let e = this.wsSocket.url; return e.endsWith("/") && (e = e.slice(0, -1)), e } setOAuthToken(e, s = !0) { this.oauthToken = e, this.oauthTokenUseInInvite = s, this.setRegisterExtraHeaders(this.registerExtraHeaders) } setUserAgent(e) { this.u17 = e } setChromeAudioConstraints(e) { AudioCodesUA.ac_log("AC: setChromeAudioConstraints= " + e); let s, t = e.split(",").map(e => e.trim()).filter(e => e.length > 0); if (0 === t.length) s = !0; else { s = {}; for (let e of t) s[e] = !0 } this.setConstraints("chrome", "audio", s) } setConstraints(e, s, t) { if (AudioCodesUA.ac_log("AC: setConstraints " + e + " " + s, t), void 0 === this.constraints[e]) throw "Unsupported browser: " + e; if (void 0 === this.constraints[e][s]) throw "Wrong type: " + s; this.constraints[e][s] = t } setBrowsersConstraints(e) { for (let s of Object.keys(e)) { let t = e[s]; void 0 !== t.audio && this.setConstraints(s, "audio", t.audio), void 0 !== t.video && this.setConstraints(s, "video", t.video) } } setServerConfig(e, s, t = []) { this.serverConfig = { addresses: e, domain: s, iceServers: this._convertIceList(t) }, AudioCodesUA.ac_log("AC: setServerConfig()", this.serverConfig) } setReconnectIntervals(e, s) { AudioCodesUA.ac_log("AC: setReconnectIntervals min=" + e + " max=" + s), this.reconnectMin = e, this.reconnectMax = s } setAccount(e, s, t, i) { void 0 !== s && null !== s && 0 !== s.length || (s = void 0), void 0 !== i && null !== i && 0 !== i.length || (i = e); let o = this.account; o.user = e, o.displayName = s, o.password = t, o.authUser = i } setRegisterExpires(e) { AudioCodesUA.ac_log("AC: setRegisterExpires=" + e), this.account.registerExpires = e } setUseSessionTimer(e) { AudioCodesUA.ac_log("AC: setUseSessionTimer=" + e), this.account.useSessionTimer = e } setDtmfOptions(e, s = null, t = null) { AudioCodesUA.ac_log(`AC: setDtmfOptions useWebRTC=${e} duration=${s} interToneGap=${t}`), this.dtmfUseWebRTC = e, null !== s && (this.dtmfDuration = s), null !== t && (this.dtmfInterToneGap = t) } setEnableAddVideo(e) { AudioCodesUA.ac_log("AC: setEnableAddVideo=" + e), this.enableAddVideo = e } getEnableAddVideo() { return this.enableAddVideo } getAccount() { return this.account } setListeners(e) { AudioCodesUA.ac_log("AC: setListeners()"); for (let s of ["loginStateChanged", "outgoingCallProgress", "callTerminated", "callConfirmed", "callShowStreams", "incomingCall", "callHoldStateChanged"]) if (!(s in e)) throw "listener missed method: " + s; this.listeners = e } static getSessionStatusName(e) { switch (e) { case 0: return "NULL (0)"; case 1: return "INVITE_SENT (1)"; case 2: return "1XX_RECEIVED (2)"; case 3: return "INVITE_RECEIVED (3)"; case 4: return "WAITING_FOR_ANSWER (4)"; case 5: return "ANSWERED (5)"; case 6: return "WAITING_FOR_ACK (6)"; case 7: return "CANCELED (7)"; case 8: return "TERMINATED (8)"; case 9: return "CONFIRMED (9)"; default: return "Unknown (" + e + ")" } } setJsSipLogger(e) { JsSIP.debug.log = e } setAcLogger(e) { AudioCodesUA.ac_log = e } isInitialized() { return this._isInitialized } setModes(e = {}) { AudioCodesUA.ac_log("AC: setModes() " + JSON.stringify(e)), Object.assign(this.modes, e), this._normalizeModes() } _normalizeModes() { function e(e, s) { return "number" == typeof e && e <= s ? void 0 : e } let s = this.modes; s.sbc_ha_pairs_mode = e(s.sbc_ha_pairs_mode, 0), s.chrome_rtp_timeout_fix = e(s.chrome_rtp_timeout_fix, 0) } init(e = !0) { if (AudioCodesUA.ac_log("AC: init() autoLogin=" + e), this._isInitialized) return; this._isInitialized = !0, JsSIP.debug.enable("JsSIP:*"), JsSIP.debug.formatArgs = function () { }; let s = []; for (let e of this.serverConfig.addresses) e instanceof Array ? s.push({ socket: new JsSIP.WebSocketInterface(e[0]), weight: e[1] }) : s.push(new JsSIP.WebSocketInterface(e)); let t = { sockets: s, uri: "sip:" + this.account.user + "@" + this.serverConfig.domain, contact_uri: "sip:" + this.account.user + "@" + this._randomToken(12) + ".invalid;transport=ws", authorization_user: this.account.authUser, password: this.account.password, register: e, session_timers: this.account.useSessionTimer, register_expires: this.account.registerExpires, user_agent: this.u17, connection_recovery_min_interval: this.reconnectMin, connection_recovery_max_interval: this.reconnectMax }; this.account.displayName && this.account.displayName.length > 0 && (t.display_name = this.account.displayName), this.jssipUA = new JsSIP.UA(t), this.setRegisterExtraHeaders(this.registerExtraHeaders), this._setUACallbacks(), AudioCodesUA.ac_log("AC: applied SDK modes: " + JSON.stringify(this.modes, (e, s) => void 0 === s ? "<undefined>" : s)), this.jssipUA.modes = this.modes, this.jssipUA.start() } deinit() { this._isInitialized = !1, this.jssipUA && this.jssipUA.stop() } setRegisterExtraHeaders(e) { if (this.registerExtraHeaders = e, this.jssipUA) { let s = null !== e ? e : []; null !== this.oauthToken && (s = s.slice()).push("Authorization: Bearer " + this.oauthToken), this.jssipUA.registrator().setExtraHeaders(s) } } login() { AudioCodesUA.ac_log("AC: login()"), this.jssipUA.register() } logout() { AudioCodesUA.ac_log("AC: logout()"), this.jssipUA.isRegistered() && this.jssipUA.unregister() } switchSBC() { AudioCodesUA.ac_log("AC: switchSBC()"), this.jssipUA.switchSBC() } getNumberOfSBC() { return this.jssipUA.getNumberOfSBC() } setWebSocketKeepAlive(e, s = 0, t = 0, i = !1) { AudioCodesUA.ac_log("AC: setWebSocketKeepAlive ping=" + e + " pong=" + s + " stats=" + t + " dist=" + i), this.wsPingMs = 1e3 * e, this.wsPongMs = 1e3 * s, this.wsPongStats = t, i && (this.wsPongStatDist = new Array(4 * s).fill(0)) } _onMessageHook(e) { "\r\n" === e.data ? this._onPong() : this.wsOnMessage(e) } _onPong() { if (0 !== this.wsPongMs && (clearTimeout(this.wsPongTask), this.wsPongTask = null, this.wsWasPong || (AudioCodesUA.ac_log("AC: keep-alive: Server supports CRLF pong"), this.wsWasPong = !0), this.wsPongStats > 0)) { let e = Date.now() - this.wsPongStatTime; if (e < this.wsPongStatDelayMin && (this.wsPongStatDelayMin = e), e > this.wsPongStatDelayMax && (this.wsPongStatDelayMax = e), null !== this.wsPongStatDist) { let s = Math.floor(e / 250); s >= this.wsPongStatDist.length && (s = this.wsPongStatDist.length - 1), this.wsPongStatDist[s]++ } if (this.wsPongStatNum++ , this.wsPongStatNum == this.wsPongStats) { let e = ""; if (null !== this.wsPongStatDist) { e = "\r\n"; for (let s = 0; s < this.wsPongStatDist.length; s++)e += this.wsPongStatDist[s].toString(), s !== this.wsPongStatDist.length - 1 && (e += (s + 1) % 4 == 0 ? "," : " "); this.wsPongStatDist.fill(0) } AudioCodesUA.ac_log("AC: keep-alive: stats: pongs=%d delay=%d..%d ms" + e, this.wsPongStatNum, this.wsPongStatDelayMin, this.wsPongStatDelayMax), this.wsPongStatNum = 0, this.wsPongStatDelayMin = 1e6, this.wsPongStatDelayMax = 0 } } } _onPongTimeout() { if (this.wsPongTask = null, !this.wsWasPong) return AudioCodesUA.ac_log("AC: keep-alive: Server does not support CRLF pong."), void (this.wsPongMs = 0); AudioCodesUA.ac_log("AC: keep-alive: Pong timeout. Connection is failed"), this._stopWsKeepAlive(); try { this.wsSocket.close() } catch (e) { AudioCodesUA.ac_log("AC: close socket error", e) } } _startWsKeepAlive(e) { this.wsSocket = e, 0 !== this.wsPingMs && (this.wsOnMessage = e.onmessage, e.onmessage = this._onMessageHook.bind(this), this._stopWsKeepAlive(), this.wsPingTask = setInterval(function () { try { let s = AudioCodesUA.instance; s.wsPongMs > 0 && null === s.wsPongTask && (s.wsPongStats > 0 && (s.wsPongStatTime = Date.now()), s.wsPongTask = setTimeout(s._onPongTimeout.bind(s), s.wsPongMs)), e.readyState === WebSocket.OPEN ? e.send("\r\n\r\n") : AudioCodesUA.ac_log("AC: Warning: Cannot send Ping, websocket state=" + e.readyState) } catch (e) { AudioCodesUA.ac_log("AC: send keep-alive ping, error", e) } }, this.wsPingMs)) } _stopWsKeepAlive() { null !== this.wsPingTask && (clearInterval(this.wsPingTask), this.wsPingTask = null), null !== this.wsPongTask && (clearTimeout(this.wsPongTask), this.wsPongTask = null) } _setUACallbacks() { this.jssipUA.on("connected", e => { AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=false "connected"'), this._startWsKeepAlive(e.socket.socket._ws), this.listeners.loginStateChanged(!1, "connected", null) }), this.jssipUA.on("disconnected", e => { this._stopWsKeepAlive(), AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=false "disconnected"'), this.listeners.loginStateChanged(!1, "disconnected", null) }), this.jssipUA.on("registered", e => { AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=true "login"'), this.listeners.loginStateChanged(!0, "login", null) }), this.jssipUA.on("unregistered", e => { AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=false "logout"'), this.listeners.loginStateChanged(!1, "logout", null) }), this.jssipUA.on("registrationFailed", e => { if (e.response && e.response.status_code >= 300 && e.response.status_code < 400) if (this.jssipUA.registerRedirect) { let s = e.response.parseHeader("contact"); if (s) { let e = s.uri, t = "wss://" + e.host; if (e.port && 443 !== e.port && (t += ":" + e.port.toString()), AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=false "redirection" ' + t), this.jssipUA.registerRedirect(t)) return; AudioCodesUA.ac_log("AC: redirect url missed in server addresses, please see setServerConfig()") } else AudioCodesUA.ac_log('AC: 3xx response without "Contact" is ignored') } else AudioCodesUA.ac_log("AC: REGISTER 3xx redirection is not supported in the original JsSIP"); AudioCodesUA.ac_log('AC>>: loginStateChanged: isLogin=false "login failed"'), this.listeners.loginStateChanged(!1, "login failed", e.response ? e.response : null) }), this.jssipUA.on("newMessage", e => { "remote" === e.originator && (AudioCodesUA.ac_log("AC>>: incomingMessage", e), this.listeners.incomingMessage && this.listeners.incomingMessage(null, AudioCodesUA.instance._get_from(e.request), AudioCodesUA.instance._get_content_type(e.request), e.request.body, e.request)) }), this.jssipUA.on("sipEvent", e => { this.listeners.incomingNotify && (AudioCodesUA.ac_log("AC>>: incoming out of dialog NOTIFY", e), this.listeners.incomingNotify(null, e.event ? e.event.event : null, AudioCodesUA.instance._get_from(e.request), AudioCodesUA.instance._get_content_type(e.request), e.request.body, e.request)) }), this.jssipUA.on("newRTCSession", function (e) { AudioCodesUA.ac_log(`AC: event ${"remote" === e.originator ? "incoming" : "outgoing"} "newRTCSession"`, e); let s, t = new AudioCodesSession(e.session); if (t.js_session.on("sipEvent", function (e) { if (!AudioCodesUA.instance.listeners.incomingNotify) return; let s = this.data.ac_session; AudioCodesUA.ac_log("AC>>: incoming NOTIFY", s, e), e.taken = AudioCodesUA.instance.listeners.incomingNotify(s, e.event ? e.event.event : null, AudioCodesUA.instance._get_from(e.request), AudioCodesUA.instance._get_content_type(e.request), e.request.body, e.request) }), t.js_session.on("newInfo", function (e) { if (!AudioCodesUA.instance.listeners.incomingInfo) return; if ("local" === e.originator) return; let s = this.data.ac_session; AudioCodesUA.ac_log("AC>>: incoming INFO", s, e), AudioCodesUA.instance.listeners.incomingInfo(s, AudioCodesUA.instance._get_from(e.request), AudioCodesUA.instance._get_content_type(e.request), e.request.body, e.request) }), t.js_session.on("replaces", function (e) { AudioCodesUA.instance.replacedCall = this.data.ac_session, AudioCodesUA.ac_log("AC>>: incoming INVITE with Replaces. This call will be replaced:", this.data.ac_session), e.accept() }), t.js_session.on("sdp", function (e) { AudioCodesUA.instance._sdp_checking(this, e) }), t.js_session.on("connecting", function (e) { let s = this.data.ac_session, t = s.data._answer_set_video_transceiver; if (void 0 !== t) { delete s.data._answer_set_video_transceiver, AudioCodesUA.ac_log("AC: Answer. Set video transceiver direction", s); let e = AudioCodesUA.instance.getWR().connection.getTransceiver(this.connection, "video"); null !== e && AudioCodesUA.instance.getWR().transceiver.setDirection(e, t) } }), t.js_session.on("reinvite", function (e) { if (!AudioCodesUA.instance.listeners.callIncomingReinvite) return; let s = this.data.ac_session; AudioCodesUA.ac_log("AC>>: callIncomingReinvite start"), AudioCodesUA.instance.listeners.callIncomingReinvite(s, !0, e.request), e.callback = function () { AudioCodesUA.ac_log("AC>>: callIncomingIncomingReinvite end"), AudioCodesUA.instance.listeners.callIncomingReinvite(s, !1, null) } }), t.js_session.on("hold", function (e) { let s = this.data.ac_session, t = "remote" === e.originator; AudioCodesUA.ac_log(`AC>>: callHoldStateChanged isHold=true isRemote=${t} session:`, s), AudioCodesUA.instance.listeners.callHoldStateChanged(s, !0, t) }), t.js_session.on("unhold", function (e) { let s = this.data.ac_session, t = "remote" === e.originator; AudioCodesUA.ac_log(`AC>>: callHoldStateChanged isHold=false isRemote=${t} session:`, s), AudioCodesUA.instance.listeners.callHoldStateChanged(s, !1, t) }), t.js_session.on("progress", function (e) { if ("remote" === e.originator) { let s = this.data.ac_session; AudioCodesUA.ac_log("AC>>: outgoingCallProgress", s), AudioCodesUA.instance.listeners.outgoingCallProgress(s, e.response) } }), t.js_session.on("failed", function (e) { let s = this.data.ac_session, t = null; if ("Redirected" === e.cause && e.message && e.message.headers) { let s = e.message.parseHeader("Contact"); s && (t = s.uri.toString()) } AudioCodesUA.ac_log("AC>>: callTerminated (failed)", s, e.cause, t), AudioCodesUA.instance.listeners.callTerminated(s, e.message, e.cause, t) }), t.js_session.on("accepted", function (e) { let s = this.data.ac_session; s.data._accepted = !0, "remote" === e.originator && (s.data._ok_response = e.response) }), "remote" === e.originator && null !== AudioCodesUA.instance.replacedCall && t.js_session.removeAllListeners("confirmed"), t.js_session.on("confirmed", function (e) { let s, i = this.data.ac_session, o = null; "_ok_response" in i.data ? (o = i.data._ok_response, delete i.data._ok_response, s = "ACK sent") : s = "ACK received", t.data._video_call_audio_answer && "firefox" === AudioCodesUA.instance.browser && (t.data._video_call_audio_answer = !1, AudioCodesUA.ac_log("AC: [video call/audio answer] Send re-INVITE"), t.sendReInvite({ showStreams: !0 })), AudioCodesUA.ac_log("AC>>: callConfirmed", i, s), AudioCodesUA.instance.listeners.callConfirmed(i, o, s) }), t.js_session.on("ended", function (e) { let s = this.data.ac_session; AudioCodesUA.ac_log("AC>>: callTerminated (ended)", s, e.cause), AudioCodesUA.instance.listeners.callTerminated(s, e.message, e.cause) }), t.js_session.on("refer", function (e) { if (AudioCodesUA.instance.listeners.transfereeCreatedCall) { let s, t = this.data.ac_session; if (s = !AudioCodesUA.instance.listeners.transfereeRefer || AudioCodesUA.instance.listeners.transfereeRefer(t, e.request)) { AudioCodesUA.ac_log("AC>>: incoming REFER accepted"); let s = AudioCodesUA.instance._callOptions(t.hasSendVideo(), !0); e.accept(e => { e.data._created_by_refer = t }, s) } else AudioCodesUA.ac_log("AC>>: incoming REFER rejected"), e.reject() } else AudioCodesUA.ac_log("AC>>: incoming REFER rejected, because transfereeCreatedCall is not set"), e.reject() }), t._setEnabledReceiveVideo(AudioCodesUA.instance.enableAddVideo), t.js_session.connection ? (AudioCodesUA.instance._set_connection_listener(t), AudioCodesUA.ac_log('AC: connection exists, set "track" listener')) : (AudioCodesUA.ac_log("AC: peer connection does not exist, wait creation"), t.js_session.on("peerconnection", e => { AudioCodesUA.instance._set_connection_listener(t), AudioCodesUA.ac_log('AC: [event connection] connection created, set "track" listener') })), s = "remote" === e.originator ? e.request.from : e.request.to, t.data._user = s.uri.user, t.data._host = s.uri.host, t.data._display_name = s.display_name, t.data._create_time = new Date, "remote" === e.originator) { let s, i, o, n, a = null; if (null !== AudioCodesUA.instance.replacedCall && (a = AudioCodesUA.instance.replacedCall, AudioCodesUA.instance.replacedCall = null), e.request.body) { n = !0; let t = new AudioCodesSDP(e.request.body);[s, i, o] = t.getMediaDirection("video", !0) } else n = !1, o = "", s = i = !0, AudioCodesUA.ac_log("AC: warning incoming INVITE without SDP"); t._setVideoState(s, i), AudioCodesUA.ac_log(`AC>>: incomingCall ${t.hasVideo() ? "video" : "audio"} from "${t.data._display_name}" ${t.data._user}`, t, a), AudioCodesUA.instance.listeners.incomingCall(t, e.request, a, n) } else t.js_session.data._created_by_refer ? (AudioCodesUA.ac_log("AC>>: outgoing call created by REFER"), t.data._created_by_refer = t.js_session.data._created_by_refer, AudioCodesUA.instance.listeners.transfereeCreatedCall(t)) : AudioCodesUA.ac_log("AC>>: outgoing call created by phone.call()") }) } _get_from(e) { return { user: e.from.uri.user, host: e.from.uri.host, displayName: e.from.display_name ? e.from.display_name : null } } _get_content_type(e) { let s = e.headers["Content-Type"]; return s && s.length > 0 ? s[0].parsed : null } _set_connection_listener(e) { AudioCodesUA.instance.getWR().connection.addEventListener(e.js_session.connection, "track", s => { if (AudioCodesUA.ac_log('AC>>: "track"  event kind: ' + s.track.kind, s), s.streams.length > 0) { let t = s.streams[0]; AudioCodesUA.ac_log("AC: set call remote stream: " + t.id, e), e.data._remoteMediaStream = t } else AudioCodesUA.ac_log('AC: Warning "track" event without stream'); if ("video" === s.track.kind) { if (!e.hasEnabledReceiveVideo()) { e.data._video_call_audio_answer && ["safari", "ios_safari"].includes(AudioCodesUA.instance.browser) && (s.track.onmute = (() => { AudioCodesUA.ac_log('AC: [video call/audio answer] Fired video track "mute" event.  Call callShowStream'), s.track.onmute = null; let t = e.getRTCLocalStream(), i = e.getRTCRemoteStream(); AudioCodesUA.ac_log("AC>>: callShowStreams", e, t, i), AudioCodesUA.instance.listeners.callShowStreams(e, t, i) }), AudioCodesUA.ac_log('AC: [video call/audio answer] Set video track "mute" event listener'), e.data._video_call_audio_answer = !1), AudioCodesUA.ac_log('AC>>: event "track" video and !hasEnabledReceiveVideo therefore change transceiver direction.', e); let t = AudioCodesUA.instance.getWR().connection.getTransceiver(e.js_session.connection, "video"); if (null !== t) { let s = e.hasEnabledSendVideo() ? "sendonly" : "inactive"; AudioCodesUA.instance.getWR().transceiver.setDirection(t, s) } } return } let t = e.getRTCLocalStream(), i = e.getRTCRemoteStream(); AudioCodesUA.ac_log("AC>>: callShowStreams", e, t, i), AudioCodesUA.instance.listeners.callShowStreams(e, t, i) }) } _sdp_checking(e, s) { let t, i, o, n = s.originator + " " + s.type, a = e.data.ac_session; try { t = new AudioCodesSDP(s.sdp), [i, o] = t.getMediaDirection("video", "remote" === s.originator) } catch (s) { return void AudioCodesUA.ac_log("AC: cannot parse SDP", s) } let r = a.data._initial; switch ("answer" === s.type && (a.data._initial = !1), AudioCodesUA.ac_log(`AC: Event "sdp" ${r ? "initial" : ""} ${n}   Session state:${AudioCodesUA.getSessionStatusName(e._status)}`), n) { case "remote offer": break; case "remote answer": if (a.isLocalHold() || a.isRemoteHold()) break; a._setVideoState(i, o); break; case "local offer": break; case "local answer": if (a.isLocalHold() || a.isRemoteHold()) break; a._setVideoState(i, o) } } _convertIceList(e) { let s = []; for (let t of e) "string" == typeof t && (t = { urls: "stun:" + t }), s.push(t); return s } _randomToken(e) { let s = ""; for (let t = 0; t < e; t++)s += Math.floor(36 * Math.random()).toString(36); return s } _detectBrowser() { try { let e = navigator.userAgent; if (this.browser = "other", this.browserName = e, this.browserVersion = 0, navigator.mozGetUserMedia) this.browser = "firefox", this.browserName = e.match(/Firefox\/([.\d]+)$/)[0], this.browserVersion = parseInt(e.match(/Firefox\/(\d+)\./)[1], 10); else if (navigator.webkitGetUserMedia) { this.browser = "chrome", this.browserName = e.match(/Chrom(e|ium)\/([.\d]+)/)[0], this.browserVersion = parseInt(e.match(/Chrom(e|ium)\/(\d+)\./)[2], 10); let s = e.toLowerCase(); for (let e = 0; e < this.chromiumBased.length; e++) { let t = this.chromiumBased[e].s, i = s.indexOf(t); if (-1 !== i) { let o = s.substring(i + t.length).match(/([.\d]+)/)[1]; this.browserName += " (" + this.chromiumBased[e].n + "/" + o + ")"; break } } } else window.safari ? (this.browser = "safari", this.browserName = "Safari/" + e.match(/Version\/([.\d]+)/)[1], this.browserVersion = parseInt(e.match(/Version\/(\d+)\./)[1], 10)) : -1 !== e.indexOf("Edge/") && (this.browser = "other", this.browserName = e.match(/Edge\/([.\d]+)/)[0], this.browserVersion = parseInt(e.match(/Edge\/(\d+).(\d+)$/)[2], 10)); /iPad|iPhone|iPod/.test(e) && (this.browser = "ios_safari", this.browserName = e, this.browserVersion = 0) } catch (e) { AudioCodesUA.ac_log("AC: Browser detection error", e), this.browser = "other", this.browserName = navigator.userAgent, this.browserVersion = 0 } } _callOptions(e, s, t = null, i = null) { let o = {}; return null !== i && Object.assign(o, i), o.mediaConstraints = { audio: this.constraints[this.browser].audio }, e && (o.mediaConstraints.video = this.constraints[this.browser].video), void 0 === o.pcConfig && (o.pcConfig = {}), o.pcConfig.iceServers = this.serverConfig.iceServers, null !== t && (t = t.slice()), null !== this.oauthToken && this.oauthTokenUseInInvite && s && (null === t && (t = []), t.push("Authorization: Bearer " + this.oauthToken)), null !== t && (o.extraHeaders = t), o } call(e, s, t = null, i = null) { if (!1 === e ? e = AudioCodesUA.instance.AUDIO : !0 === e && (e = AudioCodesUA.instance.VIDEO), "symbol" != typeof e || ![AudioCodesUA.instance.AUDIO, AudioCodesUA.instance.VIDEO].includes(e)) throw "Illegal videoOption=" + e.toString(); AudioCodesUA.ac_log(`AC: call ${e.description} to ${s}`); let o = this._callOptions(e === AudioCodesUA.instance.VIDEO, !0, t, i), n = this.jssipUA.call(s, o); o.mediaStream && (n._localMediaStreamLocallyGenerated = !0); let a = n.data.ac_session; return a._setEnabledSendVideo(e === AudioCodesUA.instance.VIDEO), e === AudioCodesUA.instance.VIDEO && a._setEnabledReceiveVideo(!0), a } sendMessage(e, s, t = "text/plain") { return AudioCodesUA.ac_log(`AC: sendMessage to: ${e} "${s}"`), new Promise((i, o) => { let n = { contentType: t, eventHandlers: { succeeded: e => i(e), failed: e => o(e) } }; this.jssipUA.sendMessage(e, s, n) }) } } class AudioCodesSession { constructor(e) { this.js_session = e, this.data = { _user: null, _display_name: null, _create_time: null, _initial: !0, _remoteMediaStream: null, _wasUsedSendVideo: !1, _screenSharing: null, _video: { send: !1, receive: !1, enabledSend: !1, enabledReceive: !1 } }, e.data.ac_session = this } getRTCPeerConnection() { return this.js_session.connection } getRTCLocalStream() { return this.js_session._localMediaStream } getRTCRemoteStream() { return this.data._remoteMediaStream } isEstablished() { return this.js_session.isEstablished() } isTerminated() { return this.js_session.isEnded() } isOutgoing() { return "outgoing" === this.js_session.direction } isAudioMuted() { return this.js_session.isMuted().audio } isVideoMuted() { return this.js_session.isMuted().video } wasAccepted() { return !0 === this.data._accepted } getReplacesHeader() { if (!this.js_session.isEstablished() || !this.js_session._dialog) return AudioCodesUA.ac_log("getReplacesHeader(): call is not established"), null; let e = this.js_session._dialog.id; return `${e.call_id};to-tag=${e.remote_tag};from-tag=${e.local_tag}` } muteAudio(e) { AudioCodesUA.ac_log(`AC: muteAudio() arg=${e} `), e ? this.js_session.mute({ audio: !0, video: !1 }) : this.js_session.unmute({ audio: !0, video: !1 }) } muteVideo(e) { AudioCodesUA.ac_log(`AC: muteVideo() arg=${e} `), e ? this.js_session.mute({ audio: !1, video: !0 }) : this.js_session.unmute({ audio: !1, video: !0 }) } sendDTMF(e) { let s = AudioCodesUA.instance.dtmfUseWebRTC;["safari", "ios_safari"].includes(AudioCodesUA.instance.browser) && (s = !1), AudioCodesUA.ac_log(`AC: sendDTMF() tone=${e} ${s ? "[RFC2833]" : "[INFO]"}`); let t = { duration: AudioCodesUA.instance.dtmfDuration, interToneGap: AudioCodesUA.instance.dtmfInterToneGap, transportType: s ? "RFC2833" : "INFO" }; this.js_session.sendDTMF(e, t) } sendInfo(e, s, t = null) { AudioCodesUA.ac_log("AC: sendInfo()", e, s, t); let i = null !== t ? { extraHeaders: t } : void 0; this.js_session.sendInfo(s, e, i) } duration() { let e = this.js_session.start_time; if (!e) return 0; let s = this.js_session.end_time; return s || (s = new Date), Math.floor((s.getTime() - e.getTime()) / 1e3) } hasSendVideo() { return this.data._video.send } hasReceiveVideo() { return this.data._video.receive } hasVideo() { return this.hasSendVideo() && this.hasReceiveVideo() } getVideoState() { return this.hasSendVideo() && this.hasReceiveVideo() ? "sendrecv" : this.hasSendVideo() ? "sendonly" : this.hasReceiveVideo() ? "recvonly" : "inactive" } _setVideoState(e, s) { AudioCodesUA.ac_log(`AC: _setVideoState(send=${e}, receive=${s})`), this.data._video.send = e, this.data._video.receive = s } hasEnabledSendVideo() { return this.data._video.enabledSend } hasEnabledReceiveVideo() { return this.data._video.enabledReceive } getEnabledVideoState() { return this.hasEnabledSendVideo() && this.hasEnabledReceiveVideo() ? "sendrecv" : this.hasEnabledSendVideo() ? "sendonly" : this.hasEnabledReceiveVideo() ? "recvonly" : "inactive" } _setEnabledSendVideo(e) { AudioCodesUA.ac_log(`AC: _setEnabledSendVideo(${e})`), this.data._video.enabledSend = e } _setEnabledReceiveVideo(e) { AudioCodesUA.ac_log(`AC: _setEnabledReceiveVideo(${e})`), this.data._video.enabledReceive = e } answer(e, s = null, t = null) { if (this.data._answer_called) return void AudioCodesUA.ac_log("AC: answer() is already called. [Ignored]"); if (this.data._answer_called = !0, !1 === e ? e = AudioCodesUA.instance.AUDIO : !0 === e && (e = AudioCodesUA.instance.VIDEO), "symbol" != typeof e || ![AudioCodesUA.instance.AUDIO, AudioCodesUA.instance.RECVONLY_VIDEO, AudioCodesUA.instance.VIDEO].includes(e)) throw "Illegal videoOption=" + e.toString(); switch (AudioCodesUA.ac_log(`AC: ${e.description} answer`), this.hasVideo() || e !== AudioCodesUA.instance.RECVONLY_VIDEO && e !== AudioCodesUA.instance.VIDEO || (AudioCodesUA.ac_log('AC: incoming INVITE without video, so answer can be only "audio"'), e = AudioCodesUA.instance.AUDIO), this.hasVideo() && (e === AudioCodesUA.instance.AUDIO ? (this.data._answer_set_video_transceiver = "inactive", AudioCodesUA.instance.modes.video_call_audio_answer_fix && ["safari", "ios_safari", "firefox"].includes(AudioCodesUA.instance.browser) && (this.data._video_call_audio_answer = !0)) : e === AudioCodesUA.instance.RECVONLY_VIDEO && (this.data._answer_set_video_transceiver = "recvonly")), e) { case AudioCodesUA.instance.AUDIO: this._setEnabledSendVideo(!1), this._setEnabledReceiveVideo(!this.hasVideo() && AudioCodesUA.instance.enableAddVideo), this._setVideoState(!1, !1); break; case AudioCodesUA.instance.VIDEO: this._setEnabledSendVideo(!0), this._setEnabledReceiveVideo(!0), this._setVideoState(!0, !0); break; case AudioCodesUA.instance.RECVONLY_VIDEO: this._setEnabledSendVideo(!1), this._setEnabledReceiveVideo(!0), this._setVideoState(!1, !0) }let i = AudioCodesUA.instance._callOptions(e === AudioCodesUA.instance.VIDEO, !1, s, t); AudioCodesUA.instance.getWR().getUserMedia(i.mediaConstraints).then(e => { i.mediaStream = e, this.js_session._localMediaStreamLocallyGenerated = !0, AudioCodesUA.ac_log("AC: answer options:", i), this.js_session.answer(i) }).catch(e => { AudioCodesUA.ac_log("AC: getUserMedia failure", e), this.reject(488) }) } reject(e = 486, s = null) { AudioCodesUA.ac_log("AC: reject()"); try { let t = { status_code: e }; s && (t.extraHeaders = s), this.js_session.terminate(t) } catch (e) { AudioCodesUA.ac_log("AC: call reject error:", e) } } terminate() { AudioCodesUA.ac_log("AC: terminate()"); try { this.js_session.terminate() } catch (e) { AudioCodesUA.ac_log("AC: call terminate error:", e) } } redirect(e, s = 302, t = null) { AudioCodesUA.ac_log("AC: redirect() callTo=%s", e); try { let i = { status_code: s, extraHeaders: ["Contact: " + AudioCodesUA.instance.jssipUA.normalizeTarget(e)] }; t && i.extraHeaders.push(...t), this.js_session.terminate(i) } catch (e) { AudioCodesUA.ac_log("AC: call redirect error:", e) } } isLocalHold() { return this.js_session.isOnHold().local } isRemoteHold() { return this.js_session.isOnHold().remote } isReadyToReOffer() { return this.js_session._isReadyToReOffer() } hold(e) { return AudioCodesUA.ac_log(`AC: hold(${e})`), new Promise((s, t) => { (e ? this.js_session.hold : this.js_session.unhold).call(this.js_session, {}, () => { AudioCodesUA.ac_log("AC: hold()/unhold() is completed"), s() }) || (AudioCodesUA.ac_log("AC: hold()/unhold() failed"), t()) }) } async startSendingVideo(e = {}) { let s, t = e && !1 !== e.enabledReceiveVideo; if (this.hasEnabledSendVideo()) throw AudioCodesUA.ac_log("AC: startSendingVideo(). Already started"), Error("video already started"); AudioCodesUA.ac_log("AC: startSendingVideo()"); try { s = await AudioCodesUA.instance.getWR().getUserMedia({ video: !0 }) } catch (e) { throw AudioCodesUA.ac_log("AC: startSendingVideo() getUserMedia failure", e), e } let i = s.getVideoTracks()[0]; this.getRTCLocalStream().addTrack(i), this._setEnabledSendVideo(!0), this._setEnabledReceiveVideo(t); let o = this.data._wasUsedSendVideo; try { await AudioCodesUA.instance.getWR().connection.addVideo(this.getRTCPeerConnection(), this.getRTCLocalStream(), i, this.hasEnabledReceiveVideo(), o) } catch (e) { throw AudioCodesUA.ac_log("AC: startSendingVideo(). Adding video error", e), e } await this._renegotiate(e) } async stopSendingVideo(e = {}) { if (!this.hasEnabledSendVideo()) throw AudioCodesUA.ac_log("AC: stopSendingVideo(). Already stopped"), Error("video already stopped"); AudioCodesUA.ac_log("AC: stopSendingVideo()"); try { await AudioCodesUA.instance.getWR().connection.removeVideo(this.getRTCPeerConnection(), this.getRTCLocalStream()) } catch (e) { throw AudioCodesUA.ac_log("AC: stopSendingVideo(). Remove video error", e), e } this._setEnabledSendVideo(!1), this.data._wasUsedSendVideo = !0, await this._renegotiate(e) } _doRenegotiate(e) { return new Promise((s, t) => { this.js_session.isEnded() && t(), this.js_session.renegotiate(e, () => s(!0)) || s(!1) }) } async _renegotiate({ repeat: e = 30, delay: s = 500, ...t }) { let i = 0; for (; ;) { if (AudioCodesUA.ac_log("AC: Renegotiate" + (0 === i ? "" : ` try ${i + 1}`)), await this._doRenegotiate(t)) return; if ((i += 1) >= e) { AudioCodesUA.ac_log("AC: Renegotiation failed. Terminated."); break } AudioCodesUA.ac_log("AC: Renegotiation failed."), await new Promise(e => setTimeout(e, s)) } throw "Renegotiation failed. Terminated" } async sendReInvite(e = {}) { if (AudioCodesUA.ac_log("AC: sendReInvite()"), await this._renegotiate(e), e.showStreams) { let e = this.getRTCLocalStream(), s = this.getRTCRemoteStream(); AudioCodesUA.ac_log("AC>>: [after send re-INVITE] callShowStreams", this, e, s), AudioCodesUA.instance.listeners.callShowStreams(this, e, s) } } async startScreenSharing() { if (AudioCodesUA.ac_log("AC: startScreenSharing"), !AudioCodesUA.instance.getWR().hasDisplayMedia()) throw AudioCodesUA.ac_log("AC: startScreenSharing: screen sharing is not supported in the browser"), "Screen sharing is not supported"; let e, s; try { s = (e = await AudioCodesUA.instance.getWR().getDisplayMedia()).getVideoTracks()[0] } catch (e) { throw AudioCodesUA.ac_log("AC: startScreenSharing() error", e), e } s.onended = this._onEndedScreenSharing.bind(this), this.data._screenSharing = { track: s, hadSendVideo: this.hasSendVideo() }; let t, i = this.data._wasUsedSendVideo; try { t = await AudioCodesUA.instance.getWR().connection.addVideo(this.getRTCPeerConnection(), this.getRTCLocalStream(), s, this.hasEnabledReceiveVideo(), i) } catch (e) { throw AudioCodesUA.ac_log("AC: startScreenSharing() error", e), this.data._screenSharing = null, e } this._setEnabledSendVideo(!0); await this._renegotiate({ extraHeaders: ["X-Screen-Sharing: on"] }) } stopScreenSharing() { AudioCodesUA.ac_log("AC: stopScreenSharing"); let e = this.data._screenSharing; e && (e.track.stop(), e.track.dispatchEvent(new Event("ended"))) } async _onEndedScreenSharing() { AudioCodesUA.ac_log("AC>>: onended screen-sharing video track", this); let e = this.data._screenSharing; if (this.data._screenSharing = null, this.isTerminated()) return; let s = this.getRTCPeerConnection(), t = this.getRTCLocalStream(), i = { extraHeaders: ["X-Screen-Sharing: off"] }; e.hadSendVideo ? (AudioCodesUA.ac_log("AC: screen sharing stopped - restore previously sending video track"), AudioCodesUA.instance.getWR().connection.replaceSenderTrack(s, "video", t), await this._renegotiate(i)) : (AudioCodesUA.ac_log("AC: screen sharing stopped - stop send video"), await this.stopSendingVideo(i)), AudioCodesUA.instance.listeners.callScreenSharingEnded && AudioCodesUA.instance.listeners.callScreenSharingEnded(this) } setRemoteHoldState() { this.js_session._remoteHold = !0 } sendRefer(e, s = null) { if (!AudioCodesUA.instance.listeners.transferorNotification) throw "transferorNotification missed in phone.setListeners()"; let t = this, i = { eventHandlers: { requestSucceeded() { AudioCodesUA.ac_log("AC>>: transferorNotification progress [REFER accepted]"), AudioCodesUA.instance.listeners.transferorNotification(t, 0) }, requestFailed() { AudioCodesUA.ac_log("AC>>: transferorNotification failed [REFER failed]"), AudioCodesUA.instance.listeners.transferorNotification(t, -1) }, trying() { AudioCodesUA.ac_log("AC>>: transferorNotification progress [NOTIFY 1xx]"), AudioCodesUA.instance.listeners.transferorNotification(t, 0) }, progress() { AudioCodesUA.ac_log("AC>>: transferorNotification progress [NOTIFY 1xx]"), AudioCodesUA.instance.listeners.transferorNotification(t, 0) }, accepted() { AudioCodesUA.ac_log("AC>>: transferorNotification success [NOTIFY 2xx]"), AudioCodesUA.instance.listeners.transferorNotification(t, 1) }, failed() { AudioCodesUA.ac_log("AC>>: transferorNotification failed [NOTIFY >= 300]"), AudioCodesUA.instance.listeners.transferorNotification(t, -1) } } }; null !== s && (i.replaces = s.js_session), this.js_session.refer(e, i) } } class AudioCodesSDP { constructor(e) { this.start = [], this.media = []; let s = e.split("\n").map(e => e.trim()).filter(e => e.length > 0), t = this.start; for (let e of s) e.startsWith("m=") && (t = [], this.media.push(t)), t.push(e) } getMedia(e) { for (let s of this.media) if (s.length > 0 && s[0].startsWith("m=" + e)) return s; return null } checkSendRecv(e) { switch (e) { case "a=sendrecv": return "sendrecv"; case "a=sendonly": return "sendonly"; case "a=recvonly": return "recvonly"; case "a=inactive": return "inactive"; default: return null } } getMediaDirectionValue(e) { let s, t = this.getMedia(e); if (null === t) return null; let i = "sendrecv"; for (let e of this.start) if (null !== (s = this.checkSendRecv(e))) { i = s; break } for (let e of t) if (null !== (s = this.checkSendRecv(e))) { i = s; break } return i } getMediaDirection(e, s) { let t = this.getMediaDirectionValue(e); switch (t) { case "sendrecv": return [!0, !0, t]; case "sendonly": return s ? [!1, !0, t] : [!0, !1, t]; case "recvonly": return s ? [!0, !1, t] : [!1, !0, t]; case null: case "inactive": return [!1, !1, t] } } toString() { let e = this.start; for (let s of this.media) e = e.concat(s); return e.join("\r\n") + "\r\n" } } let AudioCodesWebRTCWrapper = { getUserMedia: e => (AudioCodesUA.ac_log("[webrtc] getUserMedia constraints", e), navigator.mediaDevices.getUserMedia(e)), hasDisplayMedia: () => navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia, getDisplayMedia: () => (AudioCodesUA.ac_log("[webrtc] getDisplayMedia"), navigator.mediaDevices.getDisplayMedia({ video: !0 })), checkAvailableDevices() { if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) return Promise.reject("WebRTC is not supported"); let e = !1, s = !1, t = !1; return navigator.mediaDevices.enumerateDevices().then(i => (i.forEach(function (i) { switch (i.kind) { case "videoinput": e = !0; break; case "audioinput": s = !0; break; case "audiooutput": t = !0 } }), void 0 === navigator.webkitGetUserMedia && (t = !0), t ? s ? Promise.resolve(e) : Promise.reject("¡Falta un micrófono! Conecta uno y vuelve a intentar") : Promise.reject("¡Falta un altavoz! Conecta uno y vuelve a intentar")))},transceiver:{setDirection(e,s){let t="";null!==e.sender.track?t=e.sender.track.kind:null!==e.receiver.track&&(t=e.receiver.track.kind),AudioCodesUA.ac_log(`[webrtc] set ${t} transceiver direction=${s}`),e.direction=s}},stream:{getInfo(e){function s(e){return e.length>0?e[0].enabled.toString():"-"}return null===e?Promise.resolve("stream is null"):Promise.resolve(`audio: ${s(e.getAudioTracks())} video: ${s(e.getVideoTracks())}`)}},connection:{getTransceiversInfo(e){function s(e){return null===e?"none":`d=${e.direction} c=${e.currentDirection}`}let t=e.getTransceivers(),i=AudioCodesUA.instance.getWR().connection.getTransceiver(e,"audio"),o=AudioCodesUA.instance.getWR().connection.getTransceiver(e,"video");return Promise.resolve(`(${t.length}) audio ${s(i)} video ${s(o)}`)},getTransceiver(e,s){for(let t of e.getTransceivers()){if(null!==t.sender&&null!==t.sender.track&&t.sender.track.kind===s)return t;if(null!==t.receiver&&null!==t.receiver.track&&t.receiver.track.kind===s)return t}return null},addEventListener:(e,s,t)=>(AudioCodesUA.ac_log("[webrtc] Connection addEventListener "+s),"track"!==s?Promise.reject("Wrong event name: "+s):(e.addEventListener(s,t),Promise.resolve())),sendDTMF:(e,s,t,i)=>(AudioCodesUA.ac_log("[webrtc] Connection sendDTMF "+s),new Promise((o,n)=>{try{let a=null,r=e.getSenders();for(let e of r)if(null!==e.track&&"audio"===e.track.kind){a=e;break}null===a&&n("No audio sender in the connection"),a.dtmf.insertDTMF(s,t,i),o(!0)}catch(e){n(e)}})),async addVideo(e,s,t,i,o){AudioCodesUA.ac_log("[webrtc] Connection addVideo");let n=AudioCodesUA.instance.getWR().connection.getTransceiver(e,"video");if(null!==n){let e=i?"sendrecv":"sendonly";AudioCodesUA.instance.getWR().transceiver.setDirection(n,e)}return null===n||null===n.sender.track&&!o?(AudioCodesUA.ac_log("[webrtc] addVideo (connection addTrack)"),e.addTrack(t,s),!0):(AudioCodesUA.ac_log("[webrtc] addVideo (video transceiver sender replaceTrack)"),await n.sender.replaceTrack(t),!1)},async removeVideo(e,s){AudioCodesUA.ac_log("[webrtc] Connection removeVideo");let t=AudioCodesUA.instance.getWR().connection.getTransceiver(e,"video");if(null===t)throw"no video transceiver found";if(e.removeTrack(t.sender),s)for(let e of s.getVideoTracks())s.removeTrack(e),e.stop()},replaceSenderTrack(e,s,t){AudioCodesUA.ac_log("[webrtc] ReplaceSenderTrack "+s);let i=null;for(let t of e.getSenders())if(null!==t.track&&t.track.kind===s){i=t;break}if(null===i)return Promise.reject(`No ${s} sender`);let o="audio"===s?t.getAudioTracks():t.getVideoTracks();return 0===o.length?Promise.reject(`No ${s} track`):i.replaceTrack(o[0])},getStats(e,s){let t="";return e.getStats(null).then(e=>(e.forEach(e=>{if(s.includes(e.type)){t+=" {";let s=!0;for(let i of Object.keys(e))s?s=!1:t+=",",t+=i+"="+e[i];t+="} \r\n"}}),t))}}};
;
'use strict';
/*
 * Download & decode sound from site
 * Generate sound by pattern (ring-tone, busy-tone, special, DTMF, ...)
 * Play sound to speaker or to stream
 *
 * For modern browsers only and for secure connection.
 * Used AudioContext API.
 * Can be used in Chrome, Firefox, Safari, iOS Safari
 *  
 * Igor Kolosov AudioCodes Ltd 2020
 */
class AudioPlayer {
    constructor(createCtx = true) {
        this.logger = console.log; // by default.
        this.audioCtx = null;
        this.sounds = {};
        this.source = null;
        this.resolve = null;
        this.gain = null;
        this.streamDestination = null;
        this.dtmfTones = {
            '1': [{ f: [697, 1209], t: 0.2 }],
            '2': [{ f: [697, 1336], t: 0.2 }],
            '3': [{ f: [697, 1477], t: 0.2 }],
            '4': [{ f: [770, 1209], t: 0.2 }],
            '5': [{ f: [770, 1336], t: 0.2 }],
            '6': [{ f: [770, 1477], t: 0.2 }],
            '7': [{ f: [852, 1209], t: 0.2 }],
            '8': [{ f: [852, 1336], t: 0.2 }],
            '9': [{ f: [852, 1477], t: 0.2 }],
            '*': [{ f: [941, 1209], t: 0.2 }],
            '0': [{ f: [941, 1336], t: 0.2 }],
            '#': [{ f: [941, 1477], t: 0.2 }],
            'A': [{ f: [697, 1633], t: 0.2 }],
            'B': [{ f: [770, 1633], t: 0.2 }],
            'C': [{ f: [852, 1633], t: 0.2 }],
            'D': [{ f: [941, 1633], t: 0.2 }]
        };

        this.browser = this._browser();
        this.encodings = {
            chrome: ['mp3', 'aac', 'ogg'],
            firefox: ['mp3', 'aac', 'ogg'],
            safari: ['mp3', 'aac'],
            ios_safari: ['mp3', 'aac'],
            other: ['mp3', 'aac', 'ogg']
        }[this.browser];

        if (createCtx) {
            this.createCtx();
            if (this.isDisabled()) {
                console.log('AudioPlayer: AudioContext is suspended [Autoplay Policy]');
            }
        }
    }

    _browser() {
        if (/iPad|iPhone|iPod/.test(navigator.userAgent))
            return 'ios_safari'; 
        if (navigator.mozGetUserMedia)
            return 'firefox';
        if (navigator.webkitGetUserMedia) // Work only for secure connection
            return 'chrome';
        if (window.safari)
            return 'safari';
        return 'other';
    }

    createCtx() {
        try {
            this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
        } catch (e) {
            this.logger('AudioPlayer: cannot create audioContext', e);
        }
    }

    init(logger, audioCtx = undefined) {
        this.logger = logger;
        this.logger(`AudioPlayer: init  (${this.browser})`);

        if (audioCtx !== undefined)
            this.audioCtx = audioCtx;

        if (this.browser === 'safari' || this.browser === 'ios_safari')
            this._setDecodeAudioDataShim(this.audioCtx);
    }

    // for Safari
    _setDecodeAudioDataShim(audioCtx) {
        let origDecodeAudioData = audioCtx.decodeAudioData;
        audioCtx.decodeAudioData = (data) => new Promise((resolve, reject) => {
            origDecodeAudioData.call(audioCtx, data, (d) => resolve(d), (e) => reject(e))
        });
    }

    // for Safari
    _setStartRenderingShim(offlineCtx) {
        let origStartRendering = offlineCtx.startRendering;
        offlineCtx.startRendering = () => new Promise((resolve) => {
            offlineCtx.oncomplete = (e) => { resolve(e.renderedBuffer); }
            origStartRendering.call(offlineCtx);
        });
    }

    // Check if context is disabled by audio auto-play policy.
    // Chrome implementation of audio auto-play policy is not compatible with Firefox,
    // where audio context after creation is also suspended during short time.
    isDisabled() {
        switch (this.browser) {
            case 'chrome':
            case 'safari':
            case 'ios_safari':
                return this.isSuspended();
            default:
                return false;
        }
    }

    enable() {
        switch (this.browser) {
            case 'chrome':
            case 'safari':
            case 'ios_safari':
                return this.resume();
            default:
                return Promise.resolve();
        }
    }

    isSuspended() {
        return this.audioCtx.state === 'suspended';
    }

    resume() {
        return this.audioCtx.resume();
    }

    suspend() {
        return this.audioCtx.suspend();
    }

    /**
     * Play sound
     * @param options
     *   name  sound clip name (must be set)
     *
     *   volume = 0..1.0   (1.0 by default)
     *
     *   Loop options:
     *     loop = true/false (false by default) Endless loop
     *     repeat =  repeat N times (undefined by default) Set automatically loop=true
     *
     *     duration seconds (undefined by default) Can be used with or without loop=true
     *
     *   If we want use part of downloaded sound, can be used:
     *
     *   clipStart (undefined by default)
     *   clipEnd  (undefined by default)
     *
     *   streamDestination (undefined by default), value mediaStreamDestination.
     *   Assign output to audio stream (dest.stream) instead of speaker.
     *
     *   startDelay  (0 by default).
     *   Before start delay some time.
     *
     * dropDisabled returns immediately when audioContext is suspended.
     * @returns Promise to check when playing is finished.
     */
    play(options) {
        if (!this.audioCtx)
            return Promise.reject('No audio context');

        if (this.isDisabled() && options.dropDisabled) { // To prevent sound defect after enabling.
            return Promise.resolve('drop sound for disabled');
        }

        return new Promise((resolve, reject) => {
            this.stop();
            this.resolve = resolve;
            try {
                let buf = this.sounds[options.name];
                if (!buf) {
                    this.logger('AudioPlayer: no sound: ' + options.name);
                    reject('No sound');
                    return;
                }
                this.logger('AudioPlayer: play:', options);
                this.source = this.audioCtx.createBufferSource();
                this.source.buffer = buf;

                this.source.onended = (e) => {
                    this.logger('AudioPlayer: onended ' + options.name);
                    resolve(true);
                }
                this.source.onerror = (e) => {
                    this.logger('AudioPlayer: onerror callback', e);
                    this._releaseResources();
                    reject('onerror callback');
                }

                this.gain = this.audioCtx.createGain();
                let volume = options.volume ? options.volume : 1.0;
                this.gain.gain.setValueAtTime(volume, this.audioCtx.currentTime);
                this.source.connect(this.gain);
                if (options.streamDestination) {
                    this.streamDestination = options.streamDestination;
                    this.gain.connect(this.streamDestination);
                } else {
                    this.streamDestination = null;
                    this.gain.connect(this.audioCtx.destination);
                }

                let clipStart = options.clipStart ? options.clipStart : 0;
                let clipEnd = options.clipEnd ? options.clipEnd : null;
                if (options.loop === true || options.repeat) {
                    this.source.loop = true;
                    this.source.loopStart = clipStart;
                    if (clipEnd)
                        this.source.loopEnd = clipEnd;
                }

                let duration = null;
                if (options.duration) {
                    duration = options.duration;
                } else if (options.repeat) {
                    if (clipEnd === null) clipEnd = this.source.buffer.duration;
                    duration = (clipEnd - clipStart) * options.repeat;
                } else if (clipEnd !== null) {
                    duration = clipEnd - clipStart;
                }

                let startDelay = 0;
                if (options.startDelay) {
                    startDelay = this.audioCtx.currentTime + options.startDelay;
                    if (duration)
                        duration += options.startDelay;
                }
                this.source.start(startDelay, clipStart);
                if (duration)
                    this.source.stop(this.audioCtx.currentTime + duration);
            } catch (e) {
                this.logger('AudioPlayer: play error', e);
                reject(e);
            }
        });
    }

    _releaseResources() {
        if (this.source)
            this.logger('AudioPlayer: release resources');

        try {
            this.source && this.source.stop();
        } catch (e) {
        }

        try {
            this.gain && this.gain.disconnect();
            this.source && this.source.disconnect();
            this.streamDestination && this.streamDestination.disconnect();
            this.gain = null;
            this.source = null;
            this.streamDestination = null;
        } catch (e) {
            this.logger('AudioPlayer: release resources error', e);
        }
    }

    /**
     * Stop playing (if was)
     */
    stop() {
        this._releaseResources();
        // Chrome bug workaround: source.stop does not lead to a call "onended"
        if (this.resolve) {
            this.resolve('stopped externally');
            this.resolve = null;
        }
    }

    /*
        Download set of sounds & decoding

        The same sound should be saved in site in different encodings: mp3, ogg, acc.

        For each browser set preferred encoding sequence:
        for Chrome, Firefox used ['mp3', 'acc', 'ogg'],
        for Safari used ['mp3', 'acc']
        At the first the function try to download and decode mp3 format,
        if there no such file or encoding error occured, will be used next encoding from the list.

        For modern browsers, it is enough to use MP3 sound encoding,
        without backup encoding formats.
        Usage example: download('sounds/', ['ring', 'bell'])
                       download('sounds/', [{ring: 'ring2'}, 'bell'])

        The download of sound stop after successull decoding, to check all encodings formats
        in some browser let use test=true
    */
    async downloadSounds(path, soundList, encodings = this.encodings, test = false) {
        this.logger('AudioPlayer: downloadSounds', soundList);
        for (let sound of soundList) {
            await this.downloadSound(path, sound, encodings, test);
        }
    }

    /*
       Download & decode sound. 
       Mostly used mp3 encoding, may be used also aac and ogg.
       Argument sound define sound file and corresponding sound name.
       Defined as string, if used the same name for file and sound.
          E.g. 'ring' Download file ring.mp3 and save as sound 'ring'
       Defined as object, if used diffrent names for file and sound.
          E.g. {ring: 'ring2'} Download file ring2.mp3 and save as sound 'ring'
     */
    async downloadSound(path, sound, encodings = this.encodings, test = false) {
        let decodedData = null;
        let soundName, fileName;
        if (sound instanceof Object) {
            soundName = Object.keys(sound)[0];
            fileName = sound[soundName];
        } else {
            soundName = fileName = sound;
        }
        for (let ext of encodings) {
            let file = fileName + '.' + ext;
            let data = null;
            let downloadStart = Date.now();
            try {
                let response = await fetch(path + file, { credentials: 'same-origin' });
                data = await response.arrayBuffer();
            } catch (e) {
                continue;
            }

            let decodingStart = Date.now();
            try {
                decodedData = await this.audioCtx.decodeAudioData(data);
                if (!test)
                    break;
                let decodingEnd = Date.now();
                this.logger('AudioPlayer [test] ' + file + ' is downloaded (%s) and decoded (%s)',
                    ((decodingStart - downloadStart) / 1000).toFixed(3), ((decodingEnd - decodingStart) / 1000).toFixed(3));
            } catch (e) {
                this.logger('AudioPlayer: decoding error: ' + fileName, e);
                continue;
            }
        }
        if (decodedData !== null) {
            this.sounds[soundName] = decodedData;
        } else {
            this.logger('AudioPlayer: Cannot download & decode: ' + fileName);
        }
        return decodedData;
    }

    /*  Phone ringing, busy and other tones vary in different countries, see:
     *  https://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
     *
     *  Most can be easily generated, other can be downloaded as recorded sound.
     *
     *  France:
     *           Ringing tone - 440 1.5 on 3.5 off
     *           Busy tone - 440 0.5 on 0.5 off
     *
     *  Germany:
     *           Ringing tone - 425 1.0 on 4.0 off
     *           Busy tone - 425 0.48 on 0.48 off
     *           Special information tone - 900/1400/1800 3x0.33 on 1.0 off
     *
     *  Great Britain
     *          Ringing tone - 400+450  0.4 on 0.2 off 0.4 on 2.0 off  (simplified)
     *          Busy tone -  400 0.375 on 0.375 off
     *
     *  toneDefinition argument describe tone generation, as sequence of steps:
     *  here f - frequency, t - time.
     *
     *  Germany ringing [{f:425, t:1.0},  {t:4.0}]
     *  Germany busy    [{f:425, t:0.48}, {t:0.48}]
     *  Germany special [{f:900, t:0.33}, {f:1400, t:0.33}, {f:1800, t:0.33}, {t:1.0}]
     *  DTMF for '#'    [{f:[941, 1477], 0.2}]
     *  Great Britain ringing [{f:[400,450], t:0.4}, {t:0.2}, {f:[400, 450], t:0.4}, {t:2.0}]
     */
    generateTone(toneName, toneDefinition) {
        function getArray(e) {
            if (e === undefined) return [];
            if (Array.isArray(e)) return e;
            return [e];
        }

        try {
            let duration = 0;
            let oscillatorNumber = 0;
            for (let step of toneDefinition) {
                duration += step.t;
                oscillatorNumber = Math.max(oscillatorNumber, getArray(step.f).length);
            }
            let channels = 1;
            let sampleRate = this.audioCtx.sampleRate;
            let frameCount = sampleRate * duration;
            let offlineCtx = new (window.OfflineAudioContext || window.webkitOfflineAudioContext)(channels, frameCount, sampleRate);
            if (this.browser === 'safari' || this.browser === 'ios_safari')
                this._setStartRenderingShim(offlineCtx);

            let oscillators = new Array(oscillatorNumber);
            for (let i = 0; i < oscillators.length; i++) {
                oscillators[i] = offlineCtx.createOscillator();
                oscillators[i].connect(offlineCtx.destination);
            }

            let time = 0;
            for (let i = 0, num = toneDefinition.length; i < num; i++) {
                let step = toneDefinition[i];
                let frequencies = getArray(step.f);
                for (let j = 0; j < oscillators.length; j++) {
                    let f = (j < frequencies.length) ? frequencies[j] : 0;
                    oscillators[j].frequency.setValueAtTime(f, offlineCtx.currentTime + time);
                }
                time += step.t;
            }

            for (let o of oscillators) {
                o.start(0);
                o.stop(offlineCtx.currentTime + duration);
            }

            return offlineCtx.startRendering()
                .then(renderedBuffer => {
                    for (let o of oscillators)
                        o.disconnect();
                    this.sounds[toneName] = renderedBuffer;
                });
        } catch (e) {
            this.logger('AudioPlayer: cannot generate tone', e);
            return Promise.reject(e);
        }
    }

    async generateTonesSuite(suite) {
        for (const tone in suite) {
            await this.generateTone(tone, suite[tone]);
        }
    }

    generateTones(ringingTone, busyTone) {
        return this.generateTonesSuite(Object.assign({ 'ringingTone': ringingTone, 'busyTone': busyTone }, this.dtmfSuite));
    }
};
let c2c_serverConfig = {
    domain: 'webrtc.bcp.com.bo',                 // SBC domain name, used to build SIP headers From/To
    addresses: ['wss://webrtc.bcp.com.bo:10081'],  // AudioCodes SBC secure web socket address (can be multiple)
    iceServers: [],                        // Optional STUN or TURN servers. Don't set TURN server password here. It's unsecure !  
    /* TURN server usage example 
       iceServers: [
           { urls: 'turn:ik.l5.ca',
             //username: 'xxx',     Note: username and credential is better set not here but in c2c.js code 
             //credential: 'yyy',
           }
        ],
        iceTransportPolicyRelay: false      // Optional. For TURN server debugging. If true will be used only 'relay' ice candidate
    */
};

let c2c_config = {
    // Call
    call: '5555', // Call to this user name (or phone number).
    caller: '4990', // Caller user name (One word according SIP RFC 3261). 
    callerDN: 'WEB', // Caller display name (words sequence).
    type: 'audio',         // 'audio' or 'video'
    videoSize: { width: '480px', height: '360px' }, // video size (for video call) can be used default {width: '', height: ''}
    callAutoStart: 'no',  // Start call automatically after page loading. Values: 'yes' (start if autoplay policy enabled) 'yes force' (start always), 'no' (don't start call automatically)                                      
    messageDisplayTime: 5, // A message will be displayed during this time (seconds).
    restoreCallMaxDelay: 20, // After page reloading, call can be restored within the time interval (seconds).

    // Test call used to check line quality.
    testCallEnabled: false,    // If test call enabled (show test call GUI)
    testCallSBCScore: true,   // Test call voice quality score calculated by SBC API (true) or browser API (false).
    testCallUser: '5995',     // Call to this user for test call (It's special test call user in SBC that auto answer and play sound prompt)
    testCallAutoStart: false,  // Start test call automatically after page loading when auto play policy enable play sound or when for test call used microphone.
    testCallUseMicrophone: false, // Send microphone sound (true) or generated tone/download sound (false).
    testCallVolume: 0.0,     // 1.0 .. 0.0. Hear or not test call audio prompt received from SBC
    testCallMinDuration: 10,  // For browser quality score: remote-inbound-rtp provided only after 5..10 seconds delay (Chrome) or 11..16 seconds (Firefox).
    testCallMaxDuration: 20,  // Call will terminated after testCallMinDuration if received remote-inbound-rtp and always after testCallMaxDuration.
    testCallQualityText: {    // Mapping SBC "color" voice quality score with corresponding text message.
        'green': 'Good', 'yellow': 'Fair', 'red': 'Low', 'gray': 'N/A'
    },

    // Websocket keep alive.
    keepAlivePing: 15,        // To detect websocket disconnection and and keep alive NAT connection, send CRLF ping interval (seconds) 
    keepAlivePong: 15,        // Wait pong response interval (seconds)
    keepAliveStats: 60,       // Each n pongs print to console log min and max pong delay
    keepAliveDist: false,     // Print to console log also pong distribution.

    // SDK modes. 
    modes: {
        ice_timeout_fix: 2000,             // ICE gathering timeout (milliseconds)
        chrome_rtp_timeout_fix: 13,        // Workaround of https://bugs.chromium.org/p/chromium/issues/detail?id=982793
    }
};

let c2c_soundConfig = {
    generateTones: {
        // Phone ringing, busy and other tones vary in different countries.
        // Please see: https://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
        ringingTone: [{ f: 400, t: 1.5 }, { t: 3.5 }],
        busyTone: [{ f: 400, t: 0.5 }, { t: 0.5 }],
        disconnectTone: [{ f: 400, t: 0.5 }, { t: 0.5 }],
        // test_call_sound is sending during test call. Specified as tones sequence.
        test_call_sound: [{ f: 400, t: 1.0 }, { f: 300, t: 0.5 }]
    },
    downloadSounds: [
        // test_call_sound Can be specified as mp3 instead of tone sequence.
        // { test_call_sound: 'flowing_stream' }
    ],
    play: {
        outgoingCallProgress: { name: 'ringingTone', loop: true, volume: 0.2 },
        busy: { name: 'busyTone', volume: 0.2, repeat: 4 },
        disconnect: { name: 'disconnectTone', volume: 0.2, repeat: 3 },
    },
};;
'use strict';

/*
   Click to Call Widget for SDK 1.13.0

   Added:
     optional test call quality score (SBC or browser) and connection speed information.
     optional URL arguments - call, delay, dtmf.
     audio or video call (according "type" variable in config.js)
   
   Can be used only in HTTPS server (or in secure environement from local file)
   
   Igor Kolosov AudioCodes Ltd 2020

 */
const c2c_userAgent = 'AudioCodes Click-to-Call';
const c2c_sbcDisconnectCounterMax = 5;
const c2c_sbcDisconnectDelay = 60;   // After call termination keep SBC connection the time interval (seconds)
let c2c_phone = new AudioCodesUA(); // phone API
let c2c_audioPlayer = new AudioPlayer();
let c2c_activeCall = null; // not null, if exists active call
let c2c_restoreCall = null;
let c2c_sbcDisconnectCounter = 0;
let c2c_sbcDisconnectTimer = null;
let c2c_messageId = 0;
let c2c_streamDest = null;      // Audio player stream destination (to play recorded sound during test call)
let c2c_usedTurnServer = false; // If TURN server set in configuration ?
let c2c_isRegularCall = true;   // Regular or test call ?
let c2c_isWsConnected = false;  // Is websocket connected to SBC ? 
let c2c_isStartCall = false;    // start call after SBC connection.
let c2c_dtmfSequence = null;    // send DTMF sequence after connection.
let c2c_dtmfDelay = 2000;       // delay (milliseconds) before DTMF sending.
let c2c_callButtonHandler = function () {};
let c2c_testButtonHandler = function () {};
var ci=null;
var sw=false;

// Start click to call c2c_phone.
async function c2c_init() {
    c2c_phone.setAcLogger(c2c_ac_log);
    c2c_phone.setJsSipLogger(c2c_js_log);
    c2c_ac_log('------ Date: %s -------', new Date().toDateString());
    c2c_ac_log('Browser: ' + c2c_phone.getBrowserName() + ' Internal name: ' + c2c_phone.getBrowser());
    c2c_ac_log('SIP: %s', JsSIP.C.USER_AGENT);
    c2c_ac_log('AudioCodes API: %s', c2c_phone.version());

    c2c_phone.setUserAgent(c2c_userAgent + ' ' + c2c_phone.version());

    // Optional url parameters: user to call or DTMF sequence
    // let caller = c2c_getStrUrlParameter('caller');
    
    let caller = document.getElementById('web').value;
    console.log(" prueba "+caller)

	if (caller) {
        c2c_config.caller = c2c_stringDropCharacters(caller, ' -');
    }
	let call = document.getElementById('web').value;
    
    if (call) {
        c2c_config.call = c2c_stringDropCharacters(call, ' -');
    }
    let dtmf = document.getElementById('web').value;
    if (dtmf) {
        c2c_dtmfSequence = c2c_stringDropCharacters(dtmf, ' -');
    }
    c2c_dtmfDelay = c2c_getIntUrlParameter('delay', c2c_dtmfDelay);
    if (call || dtmf) {
        c2c_ac_log(`URL parameters: call=${call} dtmf=${dtmf} delay=${c2c_dtmfDelay}`
            + `\nAfter filtering: call=${c2c_config.call}  dtmf=${c2c_dtmfSequence}`);
    }

    // In iMAC and iOS Safari getStats() missed "remote-inbound-rtp".
    let browser = c2c_phone.getBrowser();
    let isSafari = browser === 'safari' || browser === 'ios_safari';
    //if (c2c_config.testCallEnabled && !c2c_config.testCallSBCScore && isSafari) {
    //    c2c_ac_log('Disable test call for iMac/iOS Safari browser, because getStats() implementation missed remote-inbound-rtp report');
    //    c2c_config.testCallEnabled = false;
    //}
    function getScreenWidth() {
        return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    }

    // Calcula el ancho de la ventana modal 
    function calculateModalWidth() {
        const screenWidth = getScreenWidth();
        if (screenWidth >= 768) {
            return '35%'; // Pantallas grandes, 100% 
        } else {
            return '90%'; // Dispositivos móviles (celulares), 80% 
        }
    }

    // Obtén el ancho calculado 
    const modalWidth = calculateModalWidth();
    // Set buttons handlers
    document.getElementById('c2c_call_btn').onclick = async function () {
        try {
            console.log("entra al boton de llamada con CI");
            if (sw == false) {
                console.log("switch valor falso");
                /*     ci = prompt('Por favor introduzca su CI, para la llamada');*/
                const { value: ci1 } = await Swal.fire({                    

                    html: `<div style="text-align: -webkit-center;">
                            <h1 style="font-size:21px;">Por favor introduzca su CI, para la llamada</h1>
                             <input style="margin-top: -12px;margin-bottom: 13px;width:255px;transition: border-color .3s,box-shadow .3s; border: 2px solid #9dc0e5;border-radius: .1875em;background: inherit;box-shadow: inset 0 1px 1px rgba(0,0,0,.06);" type="text" class="form-control5" id="numero" name="numero" placeholder="Documento de identidad" oninput="this.value = this.value.replace(/[^0-9]/g, '').substring(0,10)" inputmode="numeric" maxlength="10">
                            <div style="font-size:13px;text-align:left;line-height: 17px;">
                                <p style="margin-bottom:5px!important;"> TEN EN CUENTA ESTAS RECOMENDACIONES PARA EVITAR QUE TU LLAMADA WEB SE CORTE:    </br>
                                       <ul class="punto1">
                                            <li>USA UNA CONEXIÓN ESTABLE DE INTERNET DURANTE LA LLAMADA.</li>
                                            <li>SI LLAMAS DE TU CELULAR, EVITA EL BLOQUEO DE TU PANTALLA.</li>
                                            <li>DEBES MANTENERTE EN LA PÁGINA DONDE INICIASTE LA LLAMADA.</li>
                                            </ul>
                                   <div style="margin-top:-20px">¡CONTIGO BCP!</div></p>
                                <br>
                            </div>
                        </div>
                        `,
                    showCancelButton: true,
                    confirmButtonText: 'Aceptar',
                    cancelButtonText: 'Cancelar',
                    customClass: {
                        validationMessage: 'validation-message-class',
                        popup:'custom-alert-popup',
                    },
                    preConfirm: () => {
                        const nuevoNumero = document.getElementById('numero');
                        if (nuevoNumero.value.length<3) {
                            Swal.showValidationMessage('Por favor, indroduzca un carnet válido.');

                        }
                        return nuevoNumero.value;
                        console.log(nuevoNumero.value);
                    }
                });
                if (ci1) {
                    console.log('numero: ' + ci1);
                    document.getElementById('web').value = ci1;
                    ci = ci1;
                    console.log('carnet: ' + ci);
                    c2c_ac_log('phone>> call button onclick event');
                    await c2c_enableSound()
                    c2c_callButtonHandler();
                    sw = true;
                }

            } else {
                sw = false;
                c2c_ac_log('phone>> call button onclick event');
                await c2c_enableSound()
                c2c_callButtonHandler();

            }



            // let ci=prompt('Por favor intriduzca su CI, para la llamada'); 
            // document.getElementById('web').value = ci; 
            // c2c_ac_log('phone>> call button onclick event'); 
            // await c2c_enableSound() 
            // c2c_callButtonHandler(); 

        } catch (e) {
            c2c_ac_log('call_btn handler exception', e);
        }
    }

   
    // Check WebRTC support    
    if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
        c2c_info('No WebRTC');
        c2c_guiState_WidgetDisabled('WebRTC API is not supported in this browser !');
        return;
    }

    // Check supported browsers.
    // We can check that used known browser or try use all.
    /*
    let browser = c2c_phone.getBrowser();
    if (browser !== 'chrome' && browser !== 'firefox' && browser !== 'safari' && browser !== 'ios_safari') {
        c2c_info('Unsupported browser');
        c2c_guiState_WidgetDisabled(bd.browser + ' is not supported. Please use Chrome, Firefox or Safari');
        return;
    }
    */

    if (location.protocol !== 'https:' && location.protocol !== 'file:') {
        c2c_ac_log('Warning: for the URL used "' + location.protocol + '" protocol');
    }

    // simple symmetric letter substitution cipher
    const rot13 = s => s.replace(/[a-z]/gi, c => String.fromCharCode(c.charCodeAt() + 13 - 26 * /[n-z]/i.test(c)));

    // Check if used TURN
    for (let server of c2c_serverConfig.iceServers) {
        if (typeof server === 'string')
            continue;
        let url = Array.isArray(server.urls) ? server.urls[0] : server.urls;
        if (url.startsWith('turn:')) {
            c2c_usedTurnServer = true;
            // It's better than set username and credential in config.js, but still unsecure.
            // Please replace user name and credential to yours TURN server settings.
            // Think about better TURN server authorization: e.g.configure TURN security rule that one connection leg must be used SBC IP, and other any IP.
            if (server.username === undefined) { // Don't override value if already set in config.js
                server.username = 'some-username';
            }
            if (server.credential === undefined) {  // Don't override value if already set in config.js
                server.credential = rot13('nhgu-gbxra'); // rot13 of 'nhgu-gbxra' returns 'auth-token'
            }
        }
    }

    // Prepare restore call data c2c_restoreCall
    let data = localStorage.getItem('c2c_restoreCall');
    if (data !== null) {
        localStorage.removeItem('c2c_restoreCall');

        c2c_restoreCall = JSON.parse(data);
        let delay = Math.ceil(Math.abs(c2c_restoreCall.time - new Date().getTime()) / 1000);
        if (delay > c2c_config.c2c_restoreCallMaxDelay) {
            c2c_ac_log('No restore call, delay is too long (' + delay + ' seconds)');
            c2c_restoreCall = null;
        }
    }

    // Gui initialization
    window.addEventListener('beforeunload', c2c_onBeforeUnload);
    
    c2c_guiState_Ready();

    // Prepare audio player
    c2c_audioPlayer.init(c2c_ac_log);

    // Download sounds if need.
    if (c2c_soundConfig.downloadSounds) {
        await c2c_audioPlayer.downloadSounds('../sounds/', c2c_soundConfig.downloadSounds)
    }

    // Generate tones.
    await c2c_audioPlayer.generateTonesSuite(c2c_soundConfig.generateTones);

    c2c_ac_log('audioPlayer: sounds are ready:', c2c_audioPlayer.sounds);
    

    if (c2c_restoreCall === null) {
        /* Try start test call automatically */
        let callAutoStart = !!c2c_config.callAutoStart ? c2c_config.callAutoStart.toLowerCase() : 'no';
        if ((callAutoStart === 'yes force') || (callAutoStart === 'yes' && !c2c_audioPlayer.isDisabled())) {
            if (c2c_audioPlayer.isDisabled()) {
                c2c_ac_log('Start call automatically. Warning: audio player is disabled. So you cannot hear beeps!');
            } else {
                c2c_ac_log('Start call automatically');
            }
            c2c_call(true);
        }
    }

    // Restore call after page reload
    if (c2c_restoreCall !== null) {
        c2c_ac_log('Trying to restore call', c2c_restoreCall);
        c2c_call(true);
    }
}

// Get URL parameters
function c2c_getStrUrlParameter(name, defValue = null) {
    // let s = window.location.search.split('&' + name + '=')[1];
    // if (!s) s = window.location.search.split('?' + name + '=')[1];
    let s = document.getElementById('web').value;
    // return s !== undefined ? decodeURIComponent(s.split('&')[0]) : defValue;
    
    
    // let s = document.getElementById('caller');
    
   
     return s ;
}

function c2c_getIntUrlParameter(name, defValue = null) {
    let s = document.getElementById('web').value;
    console.log("plplp " +s)
    // let s = window.location.search.split('&' + name + '=')[1];
    // if (!s) s = window.location.search.split('?' + name + '=')[1];
    return s ;
}

// Filter for URL parameters values (e.g. to remove '-' characters)
function c2c_stringDropCharacters(text, removeChars) {
    console.log("texto " + text.value);
    let result = '';

    if(text.value != '')
    {
        for (let c of text.value) {
            if (!removeChars.includes(c))
                result += c;
        }
    }

    return result;
}

function c2c_delay(ms) { return new Promise((r) => { setTimeout(() => r(), ms); }); }

function c2c_timestamp() {
    let date = new Date();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    let ms = date.getMilliseconds();
    return ((h < 10) ? '0' + h : h) + ':' + ((m < 10) ? '0' + m : m) + ':' + ((s < 10) ? '0' + s : s) + '.' + ('00' + ms).slice(-3) + ' ';
}

function c2c_ac_log() {
    let args = [].slice.call(arguments);
    console.log.apply(console, [c2c_timestamp() + ' c2c: %c' + args[0]].concat(['color: BlueViolet;'], args.slice(1)));
}

function c2c_js_log() {
    let args = [].slice.call(arguments);
    console.log.apply(console, [c2c_timestamp() + ' jssip: ' + args[0]].concat(args.slice(1)));
}

// Search server address in array of addresses
function c2c_searchServerAddress(addresses, searchAddress) {
    searchAddress = searchAddress.toLowerCase();
    for (let ix = 0; ix < addresses.length; ix++) {
        let data = addresses[ix]; // can be address or [address, priority]
        let address = data instanceof Array ? data[0] : data;
        if (address.toLowerCase() === searchAddress)
            return ix;
    }
    return -1;
}

// Connect to SBC server, don't send REGISTER
function c2c_initStack(account) {
    // restore previosly connected SBC after page reloading.
    if (c2c_restoreCall !== null) {
        let ix = c2c_searchServerAddress(c2c_serverConfig.addresses, c2c_restoreCall.address);
        if (ix !== -1) {
            c2c_ac_log('Page reloading, raise priority of previously connected server: "' + c2c_restoreCall.address + '"');
            c2c_serverConfig.addresses[ix] = [c2c_restoreCall.address, 1000];
        } else {
            c2c_ac_log('Cannot find previously connected server: ' + c2c_restoreCall.address + ' in configuration');
        }
    }
    c2c_phone.setServerConfig(c2c_serverConfig.addresses, c2c_serverConfig.domain, c2c_serverConfig.iceServers);
    c2c_phone.setAccount(account.user, account.displayName, account.password);
    c2c_phone.setWebSocketKeepAlive(c2c_config.keepAlivePing, c2c_config.keepAlivePong, c2c_config.keepAliveStats, c2c_config.keepAliveDist);

    // Set c2c_phone API listeners
    c2c_phone.setListeners({
        loginStateChanged: function (isLogin, cause) {
            switch (cause) {
                case 'connected':
                    c2c_ac_log('phone>>> loginStateChanged: connected');
                    c2c_isWsConnected = true;
                    if (c2c_activeCall !== null) {
                        c2c_ac_log('phone: active call exists (SBC might have switched over to secondary)');
                        break;
                    }
                    if (c2c_restoreCall !== null) {
                        c2c_ac_log('send INVITE with Replaces to restore call');
                        c2c_makeCall(c2c_restoreCall.callTo,
                            c2c_restoreCall.video === 'sendrecv' || c2c_restoreCall.video === 'sendonly' ? c2c_phone.VIDEO : c2c_phone.AUDIO
                            , ['Replaces: ' + c2c_restoreCall.replaces]);
                    } else if (c2c_isStartCall) {
                        c2c_startCall();
                    }
                    break;

                case 'disconnected':
                    c2c_ac_log('phone>>> loginStateChanged: disconnected');
                    c2c_isWsConnected = false;
                    if (c2c_phone.isInitialized()) {
                        if (c2c_sbcDisconnectCounter++ >= c2c_sbcDisconnectCounterMax && c2c_activeCall === null) {
                            c2c_ac_log('phone: too many disconnections.');
                            c2c_info('La conexi�n fall�', true);
                            c2c_phone.deinit();
                        }
                    }
                    break;

                case 'login failed':
                    c2c_ac_log('phone>>> loginStateChanged: login failed');
                    break;

                case 'login':
                    c2c_ac_log('phone>>> loginStateChanged: login');
                    break;

                case 'logout':
                    c2c_ac_log('phone>>> loginStateChanged: logout');
                    break;
            }
        },

        outgoingCallProgress: function (call, response) {
            c2c_ac_log('phone>>> outgoing call progress');
            if (c2c_isRegularCall) {
                c2c_guiState_HangupButton();
                c2c_info('Llamando', true);
                c2c_audioPlayer.play(c2c_soundConfig.play.outgoingCallProgress);
            }
        },

        callTerminated: function (call, message, cause, redirectTo) {
            c2c_ac_log('phone>>> call terminated callback, cause=%o', cause);
            c2c_activeCall = null;
            if (cause === 'Redirected') {
                c2c_ac_log('Redirect call to %s', redirectTo);
                c2c_makeCall(redirectTo, c2c_config.type === 'video' ? c2c_phone.VIDEO : c2c_phone.AUDIO);
                return;
            }

            c2c_audioPlayer.stop();
            if (c2c_isRegularCall) {
                let terminatedInfo = cause;  // '<span style="font-weight:bold">' + c2c_config.call + '</span> ' + cause;
                c2c_info(terminatedInfo, true);
                if (call.isOutgoing() && !call.wasAccepted()) {
                    // Busy tone.
                    c2c_audioPlayer.play(c2c_soundConfig.play.busy);
                } else {
                    // Disconnect tone.
                    c2c_audioPlayer.play(c2c_soundConfig.play.disconnect);
                }

                c2c_guiState_StopCalling();
                c2c_guiState_Ready();
                c2c_guiState_WidgetInCall(false);
            } else {
                if (!call.wasAccepted()) { // sent or received SIP 2xx response
                    c2c_ac_log('Warning: Test call is failed !');
                    c2c_info('La l�nea de prueba fall�');
                } else if (c2c_config.testCallSBCScore) {
                    // Get BYE X-VoiceQuality header.
                    try {
                        if (!message)
                            throw 'No BYE message';
                        if (!message.hasHeader('X-VoiceQuality'))
                            throw 'BYE message does not contain header: "X-VoiceQuality"';
                        let voiceQuality = message.getHeader('X-VoiceQuality');

                        let vq = voiceQuality.trim().split(' ');
                        if (vq.length !== 2)
                            throw 'X-VoiceQuality should contain 2 tokens.';
                        let mosScore = parseFloat(vq[0]);
                        let mosColor = vq[1].trim().toLowerCase();
                        let mosText = c2c_config.testCallQualityText[mosColor];
                        c2c_ac_log(`X-VoiceQuality header: score="${mosScore}", color="${mosColor}", text="${mosText}"`);

                        let qualityElt = document.getElementById('c2c_quality_span');
                        qualityElt.innerHTML = '&nbsp;Quality test: <span style="color:' +
                            mosColor + ';font-weight:bold">' +
                            mosText + '</span>';
                        c2c_info('Test passed', true);
                    } catch (e) {
                        c2c_ac_log('Warning: cannot take SBC voice quality information', e)
                        c2c_info('Test failed', true);
                    }
                }
            }
            document.getElementById('c2c_call_btn').disabled = false;

            if (c2c_sbcDisconnectDelay === 0) {
                c2c_phone.deinit();
            } else {
                c2c_sbcDisconnectTimer = setTimeout(() => {
                    c2c_ac_log('The time interval between the end of the call and SBC disconnection is over');
                    c2c_phone.deinit();
                }, c2c_sbcDisconnectDelay * 1000);
            }
            // Hide black rectangle after video call
            c2c_setRemoteVideoVisibility(false);
            c2c_restoreCall = null;
        },

        callConfirmed: async function (call, message, cause) {
            c2c_ac_log('phone>>> callConfirmed');
            c2c_audioPlayer.stop();

            // Display or hide remote video element
            c2c_setRemoteVideoVisibility(c2c_activeCall.hasReceiveVideo());

            if (c2c_isRegularCall) {
                c2c_guiState_StopCalling();
                c2c_guiState_HangupButton();
                c2c_guiState_WidgetInCall(true);
                c2c_info('Gracias por su llamada, ajuste el volumen a su requerimiento.', true);

                if (c2c_restoreCall !== null && c2c_restoreCall.hold.includes('remote')) {
                    c2c_ac_log('Restore remote hold');
                    c2c_info('Espera');
                    c2c_activeCall.setRemoteHoldState();
                }

                if (c2c_dtmfSequence !== null && c2c_restoreCall === null) {
                    if (c2c_dtmfDelay > 0) {
                        c2c_ac_log(`Wait ${c2c_dtmfDelay}ms before DTMF sending...`);
                        await c2c_delay(c2c_dtmfDelay);
                    }
                    
                    //c2c_phone.setDtmfOptions(true, 250, 250);
                    c2c_ac_log(`Send DTMF sequence: ${c2c_dtmfSequence}`);
                    for (let key of c2c_dtmfSequence) {
                        c2c_activeCall.sendDTMF(key);
                    }
                }
            } else {
                await c2c_voiceQualityTesting();
            }
        },

        callShowStreams: function (call, localStream, remoteStream) {
            c2c_ac_log('phone>>> callShowStreams');
            c2c_audioPlayer.stop();
            let remoteVideo = document.getElementById('c2c_remote_video');
            remoteVideo.srcObject = remoteStream;
            remoteVideo.volume = c2c_isRegularCall ? 1.0 : c2c_config.testCallVolume;
        },

        incomingCall: function (call, invite) {
            c2c_ac_log('phone>>> incomingCall');
            call.reject();
        },

        callHoldStateChanged: function (call, isHold, isRemote) {
            c2c_ac_log('phone>>> callHoldStateChanged');
            if (call.isRemoteHold()) {
                c2c_info('Espera');
            } else {
                c2c_info('Reanudar', true);
            }
        },

        callIncomingReinvite: function (call, start, request) {
            if (start)
                return;
            // Display or hide remote video element
            c2c_setRemoteVideoVisibility(call.hasReceiveVideo());
        },

        incomingNotify: function (call, eventName, from, contentType, body, request) {
            c2c_ac_log(`phone>>> incoming NOTIFY "${eventName}"`, call, from, contentType, body);
            /*
            if (call !== null)
                return false; // skip in of dialog NOTIFY.
            if (eventName !== 'call_quality')
                return false; // skip unsupported events
            */
            return true;
        }
    });

    c2c_sbcDisconnectCounter = 0;

    // Other side cannot switch audio call to video (for audio call)
    c2c_phone.setEnableAddVideo(c2c_config.type === 'video');

    c2c_phone.setModes(c2c_config.modes);
    c2c_phone.init(false);
}

// Prepare restore call after page reload.
function c2c_onBeforeUnload() {
    c2c_ac_log('phone>>> beforeunload event');
    if (c2c_phone === null || !c2c_phone.isInitialized())
        return;
    if (c2c_activeCall !== null && c2c_isRegularCall) {
        if (c2c_activeCall.isEstablished()) {
            let data = {
                callTo: c2c_activeCall.data['_user'],
                video: c2c_activeCall.getVideoState(), // sendrecv, sendonly, recvonly, inactive
                replaces: c2c_activeCall.getReplacesHeader(),
                time: new Date().getTime(),
                hold: `${c2c_activeCall.isLocalHold() ? 'local' : ''}${c2c_activeCall.isRemoteHold() ? 'remote' : ''}`,
                address: c2c_phone.getServerAddress()
            }
            localStorage.setItem('c2c_restoreCall', JSON.stringify(data));
        } else {
            c2c_activeCall.terminate(); // send BYE or CANCEL
        }
    }
}

// Set button look for call
function c2c_guiState_Ready() {
    let button = document.getElementById('c2c_call_btn');
    c2c_callButtonHandler = function () { c2c_call(true); }
    button.className = 'c2c_call_btn_ready';
    //button.querySelector('span').innerText = 'Call';
    button.querySelector('svg').setAttribute('class', 'c2c_call_svg_ready');
}

// Set button look for hangup
function c2c_guiState_HangupButton() {
    let button = document.getElementById('c2c_call_btn');
    c2c_callButtonHandler = c2c_hangupCall;
    button.className = 'c2c_call_btn_hangup';
    //button.querySelector('span').innerText = 'Hangup';
}

// Call is in progress. Ignore button click
function c2c_guiState_Calling() {
    let button = document.getElementById('c2c_call_btn');
    c2c_callButtonHandler = () => {
        button.className = 'c2c_call_btn_hangup';
        c2c_ac_log('ignored [call already pressed]');
    };
    button.querySelector('svg').setAttribute('class', 'c2c_call_svg_calling');
}

function c2c_guiState_StopCalling() {
    document.querySelector('#c2c_call_btn svg').setAttribute('class', 'c2c_call_svg_hangup');
}

function c2c_guiState_WidgetInCall(isOpen) {
    document.getElementById('c2c_widget').className = isOpen ? 'c2c_widget_incall' : '';
}

function c2c_guiState_WidgetDisabled(logMsg) {
    c2c_ac_log(logMsg);
    document.getElementById('c2c_call_btn').disabled = true;
    document.getElementById('c2c_widget').className = 'c2c_widget_disabled';
    document.querySelector('#c2c_call_btn svg').setAttribute('class', 'c2c_call_svg_disabled')
}

// Display message, and optionally clean it after delay.
function c2c_info(text, clear = false) {
    let span = document.getElementById('c2c_message');
    span.innerHTML = text;
    span.dataset.id = ++c2c_messageId;
    if (clear) {
        (function (id) {
            setTimeout(() => {
                if (span.dataset.id === id) {
                    span.innerHTML = '';
                }
            }, c2c_config.messageDisplayTime * 1000);
        })(span.dataset.id);
    }
}

async function c2c_call(isRegular) {
    if (c2c_sbcDisconnectTimer !== null) {
        clearTimeout(c2c_sbcDisconnectTimer);
        c2c_sbcDisconnectTimer = null;
    }
    if (isRegular) {
        c2c_guiState_Calling();
    } else {
        document.getElementById('c2c_quality_span').innerHTML = '';
        document.getElementById('c2c_call_btn').disabled = true;
    }
    c2c_isRegularCall = isRegular;
    c2c_isStartCall = true;
    c2c_audioPlayer.stop();

    if (!c2c_phone.isInitialized()) {
        try {
            // the call will start when the sbc is connected
            await c2c_sbc_connect_sequence();
        } catch (e) {
            c2c_ac_log('Check available devices error:', e);
            c2c_info(e);
            if (isRegular) {
                c2c_guiState_Ready();
            }
            document.getElementById('c2c_call_btn').disabled = false;
        }
    } else if (c2c_isWsConnected) {
        c2c_startCall();
    } else {
        c2c_ac_log('SIP is already initialized. websocket is disconnected. Wait connection...');
    }
}

async function c2c_sbc_connect_sequence() {
    c2c_info('Conectando', true);
    await c2c_phone.checkAvailableDevices();
    c2c_initStack({ user: ci, displayName: c2c_config.callerDN, password: '' });
    console.log("carnet "+ci);
    console.log("Conectando "+c2c_config.caller);
}

function c2c_startCall() {
    c2c_isStartCall = false;
    if (c2c_isRegularCall) {
        c2c_makeCall(c2c_config.call, c2c_config.type === 'video' ? c2c_phone.VIDEO : c2c_phone.AUDIO);
    } else {
        c2c_makeCall(c2c_config.testCallUser, c2c_phone.AUDIO);
    }
}

function c2c_makeCall(callTo, videoMode, extraHeaders = null) {
    if (c2c_activeCall !== null)
        throw 'Ya existe una llamada activa';
    c2c_info('Llamando', true);
    let extraOptions = null;
    if (c2c_serverConfig.iceTransportPolicyRelay && c2c_usedTurnServer) {
        c2c_ac_log("Used TURN debugging iceTransportPolicy: 'relay'");
        extraOptions = { pcConfig: { iceTransportPolicy: 'relay' } };
    }
    if (!c2c_isRegularCall && !c2c_config.testCallUseMicrophone) {
        // prepare media stream to play recorded sound.
        if (!extraOptions)
            extraOptions = {};
        c2c_streamDest = c2c_audioPlayer.audioCtx.createMediaStreamDestination();
        extraOptions.mediaStream = c2c_streamDest.stream;
    }
    if (!c2c_isRegularCall && c2c_config.testCallSBCScore) {
        if (extraHeaders === null) {
            extraHeaders = [];
        }
        extraHeaders.push('X-AC-Action: test-voice-quality');
        callTo = `${callTo}@${c2c_serverConfig.domain};duration=${c2c_config.testCallMinDuration * 1000}`;
    }
    c2c_activeCall = c2c_phone.call(videoMode, callTo, extraHeaders, extraOptions);
}

function c2c_hangupCall() {
    if (c2c_activeCall !== null) {
        c2c_activeCall.terminate();
        c2c_activeCall = null;
    }
}

function c2c_enableSound() {
    if (!c2c_audioPlayer.isDisabled())
        return Promise.resolve();
    c2c_ac_log('Let enable sound...');
    return c2c_audioPlayer.enable()
        .then(() => {
            c2c_ac_log('Sound is enabled')
        })
        .catch((e) => {
            c2c_ac_log('Cannot enable sound', e);
        });
}

// In most of browsers enough to set style.display='block' or 'none'
// In iMac Safari if set 'none' HTMLVideoElement stop playing audio.
// To bypass the issue we have instead change video element sizes (zero or not zero)
function c2c_setRemoteVideoVisibility(isVisible) {
    let video = document.getElementById('c2c_remote_video');
    let vs = video.style;
    vs.display = 'block';
    if(isVisible) {
        vs.width = c2c_config.videoSize.width;
        vs.height = c2c_config.videoSize.height;
    } else {
        vs.width = vs.height = 0;
    }
}

//---------------------------------------------------------------
//-------------- Test call. Voice quality testing ---------------
//---------------------------------------------------------------
async function c2c_voiceQualityTesting() {
    c2c_ac_log('Test call is established');
    if (c2c_config.testCallUseMicrophone) {
        c2c_ac_log('Test call plays microphone sound');
    } else {
        c2c_ac_log('Test call plays recorded sound');
        c2c_audioPlayer.play({
            name: 'test_call_sound',
            streamDestination: c2c_streamDest,
            volume: 1.0,
            loop: true
        });
    }

    c2c_info('Comprobaci�n de la calidad de la l�nea...');
    if (c2c_config.testCallSBCScore) {
        await c2c_sbcVoiceQualityTesting();
    } else {
        await c2c_browserVoiceQualityTesting();
    }
}

//--------------- Voice quality SBC test ----------------------
// SBC works with RTP/RTCP statistics and send report as special BYE header
async function c2c_sbcVoiceQualityTesting() {
    c2c_ac_log('Checking line quality (SBC test)...');
}

//--------------- Voice quality browser test ------------------
// RTP/RTCP statistics checked by browser getStats() method.
// Works in Chrome and Firefox. Don't work in Safari.
async function c2c_browserVoiceQualityTesting() {
    c2c_ac_log('Checking line quality (browser test)...');
    // Testing call quality.
    let qualityScore = undefined;
    try {
        qualityScore = await c2c_get_browser_voice_quality_score();
    } catch (e) {
        c2c_ac_log('call quality testing exception', e);
    }

    let qualityElt = document.getElementById('c2c_quality_span');

    if (qualityScore === undefined) {
        qualityElt.innerHTML = '&nbsp;Quality test:<span style="color: red;font-weight:bold">Failed</span>'
        c2c_info('Test failed');
    } else {
        c2c_info('Test passed', true);
        let scoreInterval = c2c_get_browser_score_interval(qualityScore);
        if (scoreInterval) {
            qualityElt.innerHTML = '&nbsp;Quality test: <span style="color:' +
                scoreInterval.color + ';font-weight:bold">' +
                scoreInterval.text + '</span>';
        } else {
            qualityElt.innerHTML = '&nbsp;Quality test:<span style="color: red;font-weight:bold">Cannot calculate interval</span>'
        }
    }
    // Hangup test call.
    c2c_ac_log('Testing RTP quality is finished');
    c2c_activeCall.terminate();
}

/* 
   Get getStats() reports every second.
   Stop after testCallMinDuration seconds if obtained score data.
   Stop after testCallMaxDuration seconds in any case. 
*/
async function c2c_get_browser_voice_quality_score() {
    let lastScore = undefined;
    let conn = c2c_activeCall.getRTCPeerConnection();
    let startTimeMs = Date.now();
    for (let i = 0; i < c2c_config.testCallMaxDuration; i++) {
        await c2c_delay(1000);
        let stats = await conn.getStats(null);
        let elapsedTime = (Date.now() - startTimeMs) / 1000;
        let reports = c2c_createReports(stats, ['inbound-rtp', 'remote-inbound-rtp', 'outbound-rtp', 'track', 'codec']);
        try {
            lastScore = c2c_calculateG711QualityScore(reports, elapsedTime);
        } catch (e) {
            c2c_ac_log(`time: ${Math.floor(elapsedTime)}s cannot calculate score: ` + e);
        }
        if (elapsedTime >= c2c_config.testCallMinDuration && lastScore !== undefined)
            break;
    }
    // Debugging. Print complete stats provided by the browser.
    let stats = await conn.getStats(null);
    let reports = c2c_createReports(stats);
    c2c_ac_log('Reports', reports);

    // Debugging. Print used audio codec if can be detected by stats.
    let audioCodecs = c2c_getAudioCodecString(reports);
    if (audioCodecs) {
        c2c_ac_log('Tested audio codecs=' + audioCodecs);
    }
    return lastScore;
}

// Working with RTCPeerConnection.getStats object.
function c2c_createReports(stats, typesList = undefined) {
    let reports = {};
    stats.forEach(entry => {
        let type = entry.type;
        if (typesList !== undefined && !typesList.includes(type))
            return;
        if (!reports[type])
            reports[type] = [];
        reports[type].push(Object.assign({}, entry));
    });
    return reports;
}

// Get codecs using RTCPeerConnection getStats report.
// Note: don't work in Firefox, because missed "codec" report
function c2c_getCodec(reports, isOut, isAudio) {
    // out or in ?
    let type = isOut ? 'outbound-rtp' : 'inbound-rtp';
    let rtps = reports[type];
    if (!rtps)
        throw `No "${type}" stats`;
    // audio or video ?
    let foundRtp = null;
    let mediaType = isAudio ? 'audio' : 'video';
    for (let rtp of rtps) {
        if (rtp.mediaType === mediaType) {
            foundRtp = rtp;
            break;
        }
    }
    if (!foundRtp) {
        return undefined;
    }
    let codecId = foundRtp.codecId;

    // search codec by codecId
    let codecs = reports['codec'];
    if (!codecs)
        throw 'No "codec" stats';
    for (let codec of codecs) {
        if (codec.id === codecId)
            return codec;
    }
    throw `No "codec" stats with id=="${codecId}"`;
}

// Get audio codec string if possible using getStats() reports.
function c2c_getAudioCodecString(reports) {
    let outAudio, inAudio;
    try {
        let outAudioCodec = c2c_getCodec(reports, true, true)
        let inAudioCodec = c2c_getCodec(reports, false, true);
        if (outAudioCodec === undefined)
            throw 'Stats: no outbound-rtp for audio';
        if (inAudioCodec === undefined)
            throw 'Stats: no inbound-rtp for audio';
        outAudio = outAudioCodec.mimeType.toUpperCase();
        inAudio = inAudioCodec.mimeType.toUpperCase();
        if (outAudio.startsWith('AUDIO/'))
            outAudio = outAudio.substring(6);
        if (inAudio.startsWith('AUDIO/'))
            inAudio = inAudio.substring(6);
    } catch (e) {
        c2c_ac_log('Exception during codecs detection', e);
        return undefined;
    }
    if (outAudio === inAudio)
        return outAudio;
    return 'out=' + outAudio + ' in=' + inAudio;
}

function c2c_getBoundRtp(reports, type, isAudio) {
    let kind = isAudio ? 'audio' : 'video';
    let rtps = reports[type];
    if (!rtps)
        throw `No "${type}" stats`;
    for (let rtp of rtps) {
        if (rtp.kind === kind)
            return rtp;
    }
    throw `No "${type}" with kind==${kind}`;
}

function c2c_getTrack(reports, boundRtp) {
    let id = boundRtp.trackId;
    let tracks = reports['track'];
    if (!tracks)
        throw 'No "track" stats';
    for (let track of tracks)
        if (track.id === id)
            return track;
    throw 'No track with id=' + id
}

function c2c_calculateG711QualityScore(reports, elapsedTime) {
    // get reports if exists (remote-inbound-rtp missed at start)
    let inboundRtp = c2c_getBoundRtp(reports, 'inbound-rtp', true);
    let remoteInboundRtp = c2c_getBoundRtp(reports, 'remote-inbound-rtp', true);

    let irPacketsReceived = inboundRtp.packetsReceived;
    let irPacketsLost = inboundRtp.packetsLost;
    let rirPacketsLost = remoteInboundRtp.packetsLost;
    let rirJitter = remoteInboundRtp.jitter;
    let rirRoundTripTime = remoteInboundRtp.roundTripTime;

    if (irPacketsReceived === undefined) throw 'packetsReceived is undefined';
    if (irPacketsLost === undefined) throw 'packetsLost is undefined';
    if (rirPacketsLost === undefined) throw 'packetsLost is undefined';
    if (rirJitter === undefined) throw 'jitter is undefined';
    if (rirRoundTripTime === undefined) throw 'roundTripTime is undefined';

    let track = undefined;
    let totalSamplesDuration;
    try {
        track = c2c_getTrack(reports, inboundRtp);
        totalSamplesDuration = track.totalSamplesDuration;
    } catch (e) {
        let packetDuration = elapsedTime / (irPacketsReceived + irPacketsLost);
        totalSamplesDuration = packetDuration * irPacketsReceived;
        //c2c_ac_log(`Warning: No "track" stats. Calculated packet duration= + ${packetDuration} totalSamplesDuration=${totalSamplesDuration}`);
    }
    if (totalSamplesDuration === undefined) throw 'totalSamplesDuration is undefined';
    let lossPercent = 100 * irPacketsLost / (irPacketsLost + irPacketsReceived);
    let delayMs = (rirJitter + rirRoundTripTime / 2 + totalSamplesDuration / irPacketsReceived) * 1000;
    let { score, info } = c2c_getG711QualityScore(lossPercent, delayMs);
    c2c_ac_log(`time: ${Math.floor(elapsedTime)}s inbound-rtp: packetsReceived=${irPacketsReceived} packetsLost=${irPacketsLost} remote-inbound-rtp: packetsLost=${rirPacketsLost} jitter=${rirJitter} roundTripTime=${rirRoundTripTime} ${track ? 'track:' : ' calculated:'} totalSamplesDuration=${totalSamplesDuration}\n${info}`);
    return score;
}

function c2c_get_browser_score_interval(score) {
    for (let scoreInterval of c2c_qualityScoreIntervals) {
        if (score < scoreInterval.score) {
            return scoreInterval;
        }
    }
    return undefined;
}

function c2c_getG711QualityScore(loss, delay) {
    let percentIndex = Math.floor(loss / 2)
    if (percentIndex >= c2c_qualityScoreMatrix.length) {
        percentIndex = c2c_qualityScoreMatrix.length - 1; // > 98% used the last line ==98%
    }
    let row = c2c_qualityScoreMatrix[percentIndex];
    let delayIndex = Math.floor(delay / 20);
    if (delayIndex >= row.length) {
        return { score: 0, info: `delay ${delay} is too big (out of matrix range 0..500ms), set score=0` };
    }
    let score = row[delayIndex];
    return { score: score, info: `qualityScore(loss=${loss.toFixed(1)}%, delay=${delay.toFixed(1)}ms) => scoreMatrix[${percentIndex},${delayIndex}] = ${score}` };
}

// Split quality scores to intervals.
const c2c_qualityScoreIntervals = [
    { score: 2.7,  color: 'Red', text: 'Poor' },
    { score: 3.2, color: 'Orange', text: 'Fair'},
    { score: 3.7, color: 'Lightgreen', text: 'Good'},
    { score: 5, color: 'DarkGreen', text: 'Excellent' }
];

// Quality score matrix for G711 codec. Horizontal delay 0, 20, 40... 500 ms  Vertical packet loss percent 0, 2, 4, ...98
// Result is quality score (3=fair, 2=poor, threshold at 2.7)
const c2c_qualityScoreMatrix = [
    [4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.1, 4.1, 4.1, 4.1, 4, 3.9, 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.2, 3.1, 3, 2.9, 2.8, 2.8, 2.7],
    [4.1, 4.1, 4.1, 4, 4, 4, 4, 4, 3.9, 3.9, 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1, 3, 2.9, 2.8, 2.7, 2.6, 2.6, 2.5, 2.4],
    [3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.8, 3.8, 3.8, 3.7, 3.7, 3.5, 3.4, 3.3, 3.2, 3.1, 2.9, 2.8, 2.7, 2.7, 2.6, 2.5, 2.4, 2.3, 2.3, 2.2],
    [3.8, 3.8, 3.8, 3.7, 3.7, 3.7, 3.7, 3.7, 3.6, 3.6, 3.4, 3.3, 3.2, 3.1, 3, 2.8, 2.7, 2.6, 2.5, 2.4, 2.4, 2.3, 2.2, 2.1, 2, 2],
    [3.7, 3.6, 3.6, 3.6, 3.6, 3.6, 3.5, 3.5, 3.4, 3.4, 3.3, 3.2, 3, 2.9, 2.8, 2.6, 2.5, 2.4, 2.3, 2.2, 2.2, 2.1, 2, 1.9, 1.9, 1.8],
    [3.5, 3.5, 3.4, 3.4, 3.4, 3.4, 3.4, 3.3, 3.3, 3.3, 3.1, 3, 2.9, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2, 1.9, 1.8, 1.8, 1.7, 1.7],
    [3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.2, 3.2, 3.1, 3, 2.8, 2.7, 2.6, 2.4, 2.3, 2.2, 2.1, 2, 1.9, 1.8, 1.8, 1.7, 1.6, 1.6, 1.5],
    [3.2, 3.2, 3.2, 3.2, 3.1, 3.1, 3.1, 3.1, 3, 2.9, 2.8, 2.7, 2.6, 2.4, 2.3, 2.2, 2, 2, 1.9, 1.8, 1.7, 1.6, 1.6, 1.5, 1.5, 1.4],
    [3.1, 3.1, 3.1, 3, 3, 3, 3, 3, 2.9, 2.8, 2.7, 2.6, 2.4, 2.3, 2.2, 2, 1.9, 1.8, 1.8, 1.7, 1.6, 1.5, 1.5, 1.4, 1.4, 1.3],
    [3, 2.9, 2.9, 2.9, 2.9, 2.9, 2.8, 2.8, 2.8, 2.7, 2.6, 2.4, 2.3, 2.2, 2, 1.9, 1.8, 1.7, 1.6, 1.6, 1.5, 1.4, 1.4, 1.3, 1.3, 1.2],
    [2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.7, 2.7, 2.6, 2.6, 2.4, 2.3, 2.2, 2.1, 1.9, 1.8, 1.7, 1.6, 1.5, 1.5, 1.4, 1.4, 1.3, 1.3, 1.2, 1.2],
    [2.7, 2.7, 2.7, 2.7, 2.7, 2.6, 2.6, 2.6, 2.5, 2.5, 2.3, 2.2, 2.1, 2, 1.8, 1.7, 1.6, 1.5, 1.5, 1.4, 1.3, 1.3, 1.2, 1.2, 1.2, 1.1],
    [2.6, 2.6, 2.6, 2.6, 2.6, 2.5, 2.5, 2.5, 2.4, 2.4, 2.2, 2.1, 2, 1.9, 1.8, 1.6, 1.5, 1.5, 1.4, 1.3, 1.3, 1.2, 1.2, 1.2, 1.1, 1.1],
    [2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.4, 2.4, 2.3, 2.3, 2.1, 2, 1.9, 1.8, 1.7, 1.5, 1.5, 1.4, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1.1],
    [2.5, 2.4, 2.4, 2.4, 2.4, 2.4, 2.3, 2.3, 2.3, 2.2, 2.1, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1.1, 1],
    [2.4, 2.4, 2.3, 2.3, 2.3, 2.3, 2.3, 2.2, 2.2, 2.1, 2, 1.8, 1.8, 1.6, 1.5, 1.4, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1.1, 1, 1],
    [2.3, 2.3, 2.3, 2.2, 2.2, 2.2, 2.2, 2.2, 2.1, 2, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1, 1, 1, 1],
    [2.2, 2.2, 2.2, 2.2, 2.1, 2.1, 2.1, 2.1, 2, 2, 1.8, 1.8, 1.6, 1.5, 1.4, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1],
    [2.2, 2.1, 2.1, 2.1, 2.1, 2.1, 2, 2, 2, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1, 1, 1, 1, 1],
    [2.1, 2.1, 2.1, 2, 2, 2, 2, 2, 1.9, 1.8, 1.8, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1.1, 1, 1, 1, 1, 1, 1],
    [2, 2, 2, 2, 2, 1.9, 1.9, 1.9, 1.8, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1],
    [2, 2, 1.9, 1.9, 1.9, 1.9, 1.9, 1.8, 1.8, 1.8, 1.6, 1.5, 1.4, 1.3, 1.3, 1.2, 1.1, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1],
    [1.9, 1.9, 1.9, 1.9, 1.8, 1.8, 1.8, 1.8, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.9, 1.9, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.7, 1.7, 1.5, 1.4, 1.4, 1.3, 1.2, 1.1, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.7, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.8, 1.8, 1.8, 1.8, 1.7, 1.7, 1.7, 1.7, 1.6, 1.6, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.8, 1.8, 1.7, 1.7, 1.7, 1.7, 1.7, 1.6, 1.6, 1.5, 1.4, 1.4, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.7, 1.7, 1.7, 1.7, 1.7, 1.6, 1.6, 1.6, 1.5, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.7, 1.7, 1.7, 1.6, 1.6, 1.6, 1.6, 1.6, 1.5, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.7, 1.6, 1.6, 1.6, 1.6, 1.6, 1.5, 1.5, 1.5, 1.4, 1.4, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.6, 1.6, 1.6, 1.6, 1.5, 1.5, 1.5, 1.5, 1.5, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.6, 1.6, 1.6, 1.5, 1.5, 1.5, 1.5, 1.5, 1.4, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.6, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.4, 1.4, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.4, 1.4, 1.3, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.5, 1.5, 1.5, 1.5, 1.5, 1.4, 1.4, 1.4, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.5, 1.5, 1.5, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.5, 1.5, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.4, 1.4, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.3, 1.2, 1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.3, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    [1.3, 1.3, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
;
